Does cohort sync work with cohorts created by the cohort external database plugin?

Does cohort sync work with cohorts created by the cohort external database plugin?

by Barbara Lawrence -
Number of replies: 10

I've installed the  Cohort external database plugin,  and have one cohort with 3 members in the linked external database table.  When I add or remove members of the cohort in the external database, the changes are reflected correctly in the moodle cohort_members table.

I have used the cohort sync method to enrol members of this cohort to a course.  However when I add or remove members of the cohort in the external database , the changes are not reflected in the course enrolments.  This still shows the original members of the cohort when I first created it.

On another course I've enrolled users using the cohort sync method, but this time with a manually created cohort.  In this case as soon as I add or remove a member of the cohort, the enrolments in the course are changed accordingly.

I'm using Moodle 3.3.

Am i missing out a step? or maybe misunderstanding the way it's all supposed to work?

Average of ratings: -
In reply to Barbara Lawrence

Re: Does cohort sync work with cohorts created by the cohort external database plugin?

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

the external sync relies on a scheduled task which by default runs once daily. (as long as you have set up cron correcrlty)

You can change it's schedule or trigger a manual run by going to Admin > server > scheduled tasks and find the tool_cohortdatabase task - more information here: https://docs.moodle.org/en/Scheduled_tasks

There could be a bug with the code not triggering the events required by the cohort enrolment plugin to trigger an enrolment sync at the same time as the cohorts - I'll take a look at that this week.

In reply to Dan Marsden

Re: Does cohort sync work with cohorts created by the cohort external database plugin?

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
The old code relied on 2 tasks running regularly.

1) the tool_cohortdatabase sync - set to run daily by default.
2) the enrol_cohort_sync cron - set to run every 1 hr. 

I've just pushed through a patch to github that will hopefully trigger the enrolment cohort sync when the user is added or removed from the cohort using the tool_cohortdatabase sync task so that it doesn't need to wait for the 2nd task to run before the user enrolment is active.

If you get a chance to test it let us know how you go!

thanks,

In reply to Dan Marsden

Re: Does cohort sync work with cohorts created by the cohort external database plugin?

by Barbara Lawrence -

Hi Dan 

Thanks for looking at this so quickly.

I installed your patch but unfortunately it's not had an effect.

I've been running the tool_cohortdatabase sync manually.  I also tried running sync cohort role assignments hoping that would sync the cohort enrolments in the course , but I'm not sure if that's the same thing as enrol_cohort_sync . There isn't anything else in the list which looks likely. 


When I added a member to my user input cohort, the enrolments synchronised instantly so i didn't think cron was involved.

Barbara


Kind regards

Barbara

In reply to Barbara Lawrence

Re: Does cohort sync work with cohorts created by the cohort external database plugin?

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

the enrol_cohortsync method doesn't use the scheduled tasks from memory - it uses the older standard cron api in Moodle - you should be running cron regularly on this system and see if that helps. (enrol_cohortsync is only configured to run hourly.)

this does work on the system we are using here - let us know if you manage to track down what is going wrong for you.

In reply to Dan Marsden

Re: Does cohort sync work with cohorts created by the cohort external database plugin?

by Barbara Lawrence -
Yay! - cron wasn't running (it's a test server), I thought I could get away with running the tasks manually, but clearly I wasn't running the right task. Now I've set cron going the enrol_cohort sync task has run and my added users are now appearing in the course.


Would that explain why your patched version didn't work for me?

I'm still puzzled why the cohort that I set up manually sync'ed correctly when I added a user even though cron was not running at the time...

Thanks Dan for your explanation and help.



In reply to Barbara Lawrence

Re: Does cohort sync work with cohorts created by the cohort external database plugin?

by Formation ornitho Natagora -

Hello Barbara,

Thanks a lot for your question, I'm working with cohort enrolment so I'm interested in this plugin!

But I can't find the "Cohort external database plugin" : could you please give me the link to this interessant plugin ?

Thanks a lot!

Sophie

In reply to Formation ornitho Natagora

Re: Does cohort sync work with cohorts created by the cohort external database plugin?

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

It's a 3rd party plugin available from the plugins database here:

https://moodle.org/plugins/tool_cohortdatabase

Average of ratings: Useful (1)
In reply to Dan Marsden

Re: Does cohort sync work with cohorts created by the cohort external database plugin?

by Jon Witts -
Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Dan,

This plugin looks like what I have been wanting from Cohorts since they first appeared!

Can I just run a couple of questions about the plugin past you?

  1. Can I connect this to any database backend which Moodle can connect to?
  2. Can I have this keep my site-wide cohorts synced with my external database at regular points through the day?
  3. If a user leaves a cohort what happens to any materials they have in courses this cohort was linked to?
  4. Why is this not in core? wink

Cheers,

Jon

In reply to Jon Witts

Re: Does cohort sync work with cohorts created by the cohort external database plugin?

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

1) yes - uses same code as existing db enrol/auth external database plugins.
2) yes.
3) depends how you use cohorts. If you are using enrol cohort sync plugin it will enrol/unenrol the users as they are added/removed using standard api normal core processes.
4) Core already maintains a massive code-base and plugins are easy to install - why does everything need to be in core? (I'd be happy for core to take on maintenance though!) smile

In reply to Dan Marsden

Re: Does cohort sync work with cohorts created by the cohort external database plugin?

by Jon Witts -
Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Thanks Dan.

I think I am going to try this out on our test site and see if it will do what we need. big grin

Jon