moodle-an-hochschulen / moodle-local_profilecohort

Moodle plugin which lets admins manage cohort memberships based on users' custom profile fields
GNU General Public License v3.0
23 stars 19 forks source link

Updating members in cohorts automatically #14

Closed fran-inserver closed 5 years ago

fran-inserver commented 6 years ago

Hi,

First of all, thanks a lot for your amazing job with this plugin. Is really usefull for some large installations we are building.

Is there any way to run a task that match the users with their cohort? We only achieve to do the match when the user lo g in the platform but we would like to check that the user belongs to the cohort as soon as hi/she match the rule.

Thanks a lot!

abias commented 6 years ago

Hi Francisco,

there are two triggers which update a cohort membership within the plugin:

  1. The cohort memberships of a certain user are updated when a user logs in
  2. The cohort memberships of all users are updated with a scheduled task which runs every 5 minutes by default (see https://github.com/moodleuulm/moodle-local_profilecohort/blob/master/db/tasks.php)

This should be explained quite well on https://github.com/moodleuulm/moodle-local_profilecohort#how-this-plugin-works.

If you need the user to be member of a given cohort instantly as soon as he fulfills the cohort's membership criteria, you can:

  1. Run the existing scheduled task up to every minute by changing the task's cron configuration on Site Administration -> Server -> Scheduled tasks. However, this won't always help as checking a large number of users can take more than one minute and as Moodle only runs one instance of a task at a time, you might have to wait more than one minute anyway for the cohort membership to be updates.
  2. Implement another event listener similar to https://github.com/moodleuulm/moodle-local_profilecohort/blob/master/db/events.php in your local instance of the plugin which listens to an event fired after your user's criteria has changed, for example core\event\user_updated. Please note that this change is out of scope of our published plugin.

Thanks, Alex

fran-inserver commented 6 years ago

Hi Alexander,

Thanks for your answer.

Here are you are our solution just in case you consider add it to a new version of the plugin.

We are set two new events acting like triggers in events.php

$observers = [ [ 'eventname' => '\core\event\user_loggedin', 'callback' => '\local_profilecohort\profilecohort::set_cohorts_from_profile' ],

Also, we have changed a function in line 196 of profile.php, in order to make new events work:

if ($event) { $userid = $event->userid; } For:

if ($event) {

Would you consider make the changes in a new version of the plugin? Otherwise we would add it to our local copy of the plugin.

Best regards!

2017-12-28 8:32 GMT+01:00 Alexander Bias notifications@github.com:

Closed #14 https://github.com/moodleuulm/moodle-local_profilecohort/issues/14.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/moodleuulm/moodle-local_profilecohort/issues/14#event-1403260234, or mute the thread https://github.com/notifications/unsubscribe-auth/AhRvnQUuG3tz0aQRn6vleWDowSllUEQXks5tE0QXgaJpZM4RNrm0 .

-- Fran Moodle Developer

​E-LEARNING THAT WORKS Calle Henri Dunant, 15 - 28036 - Madrid https://mailtrack.io/trace/link/dd574b27e7452c6909ad11835ca0b5b8044e955f?url=https%3A%2F%2Fmaps.google.com%2F%3Fq%3DCalle%2BHenri%2BDunant%2C%2B15%2B-%2B28036%2B-%2BMadrid%26entry%3Dgmail%26source%3Dg&userId=1061015&signature=3962445e1bb080d5 www.inserver.es https://mailtrack.io/trace/link/bee161143198d0168d368665409c89afb73023b6?url=http%3A%2F%2Fwww.inserver.es&userId=1061015&signature=883c2a9b35b2b6c6


Advertencia legal: Este mensaje y, en su caso, los ficheros anexos ​​ son confidenciales, especialmente en lo que respecta a los datos personales, y se dirigen exclusivamente al destinatario referenciado. Si usted no lo es y lo ha recibido por error o tiene conocimiento del mismo por cualquier motivo, le rogamos que nos lo comunique por este medio y proceda a destruirlo o borrarlo, y que en todo caso se abstenga de utilizar, reproducir, alterar, archivar o comunicar a terceros el presente mensaje y ficheros anexos, todo ello bajo pena de incurrir en responsabilidades legales. Las opiniones contenidas en este mensaje y en los archivos adjuntos, pertenecen exclusivamente a su remitente y no representan la opinión de la empresa salvo que se diga expresamente y el remitente esté autorizado para ello. El emisor no garantiza la integridad, rapidez o seguridad del presente correo, ni se responsabiliza de posibles perjuicios derivados de la captura, incorporaciones de virus o cualesquiera otras manipulaciones efectuadas por terceros.


abias commented 6 years ago

Hi Francisco,

thank you for your code change suggestion.

After reading the ticket once more, we have decided to evaluate if we can add it to the plugin. Stay tuned.

Thanks, Alex

fran-inserver commented 6 years ago

Thanks.

Sure we'll stay :)

2018-01-22 12:58 GMT+01:00 Alexander Bias notifications@github.com:

Reopened #14 https://github.com/moodleuulm/moodle-local_profilecohort/issues/14.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/moodleuulm/moodle-local_profilecohort/issues/14#event-1434966974, or mute the thread https://github.com/notifications/unsubscribe-auth/AhRvnWrwbFnQzzPgHMwqu7Xb8fdLB1_mks5tNHfcgaJpZM4RNrm0 .

-- Fran Ventas T: +34 622 570 378

​E-LEARNING THAT WORKS Calle Henri Dunant, 15 - 28036 - Madrid https://mailtrack.io/trace/link/dd574b27e7452c6909ad11835ca0b5b8044e955f?url=https%3A%2F%2Fmaps.google.com%2F%3Fq%3DCalle%2BHenri%2BDunant%2C%2B15%2B-%2B28036%2B-%2BMadrid%26entry%3Dgmail%26source%3Dg&userId=1061015&signature=3962445e1bb080d5 www.inserver.es https://mailtrack.io/trace/link/bee161143198d0168d368665409c89afb73023b6?url=http%3A%2F%2Fwww.inserver.es&userId=1061015&signature=883c2a9b35b2b6c6

Advertencia legal: Este mensaje y, en su caso, los ficheros anexos ​​ son confidenciales, especialmente en lo que respecta a los datos personales, y se dirigen exclusivamente al destinatario referenciado. Si usted no lo es y lo ha recibido por error o tiene conocimiento del mismo por cualquier motivo, le rogamos que nos lo comunique por este medio y proceda a destruirlo o borrarlo, y que en todo caso se abstenga de utilizar, reproducir, alterar, archivar o comunicar a terceros el presente mensaje y ficheros anexos, todo ello bajo pena de incurrir en responsabilidades legales. Las opiniones contenidas en este mensaje y en los archivos adjuntos, pertenecen exclusivamente a su remitente y no representan la opinión de la empresa salvo que se diga expresamente y el remitente esté autorizado para ello. El emisor no garantiza la integridad, rapidez o seguridad del presente correo, ni se responsabiliza de posibles perjuicios derivados de la captura, incorporaciones de virus o cualesquiera otras manipulaciones efectuadas por terceros.

ingoauhagen commented 5 years ago

Hi Alex, after activating the plugin on our 3.5 platform and testing it several times we still have the problem, that the assignment of a user to the cohort isn´t started and fulfilled by the cronjob, but only after the login of the corresponding user. Have you any idea, what could lead to this problem? Thanks in advance and best regards, Ingo

abias commented 5 years ago

Hi @fran-inserver,

I am happy that we have finally added these additional event listeners to the plugin on https://github.com/moodleuulm/moodle-local_profilecohort/commit/85302ded374f7bf704814de521cc2e319c78a094.

According to our tests, there were no real downsides for these additional event listeners in terms of performance.

Hi @ingoauhagen,

I have the impression that the problem you are mentioning might either be solved by this commit or should be tackled in a separate issue. Please test the latest code and create a separate issue if you still encounter problems.

Cheers, Alex