catalyst / moodle-local_cohortauto Goto Github PK
View Code? Open in Web Editor NEWAutomatically add users into cohorts. (Previously moodle-auth_mcae.)
Home Page: https://moodle.org/plugins/local_cohortauto
Automatically add users into cohorts. (Previously moodle-auth_mcae.)
Home Page: https://moodle.org/plugins/local_cohortauto
With the latest version of the plugin for Moodle 4.3 weekly, and PHP 8.1, we have encountered this deprecation warning:
++ The cron_setup_user() function is deprecated. Please use \core\cron::setup_user() and reset_user_cache() as appropriate instead. ++
* line 3298 of /lib/deprecatedlib.php: call to debugging()
* line 37 of /local/cohortauto/cli/sync_users.php: call to cron_setup_user()
Beginning user cohort sync...
- User ....
[...]
We'll try to add a PR to fix this on master branch.
Thanks for the work.
Jordi
For example lets say I have 3 cohorts employee, partners and customers.
I want all abcCompany.com people to go into the employee cohort.
I can specify the different partner domains to direct all to the partners cohort
But then I want all others not listed above to go into a customer cohort.
Is this possible?
Use cases to deal with this issue:
profile.name_custom_profile
, and not visible into profile_field_name_custom_profile
.These use cases are necessary to deal with more flexible all profile fields in our case.
We will contribut with a PR in short.
After installing this plugin, I'm getting an error when I try to login with an OAuth2 account. I'm not sure if this plugin is causing the error, but it is referenced in the error output:
Coding problem: $PAGE->context was not set. You may have forgotten to call require_login() or $PAGE->set_context(). The page may not display correctly as a result
line 503 of /lib/pagelib.php: call to debugging()
line 830 of /lib/pagelib.php: call to moodle_page->magic_get_context()
line 1456 of /lib/weblib.php: call to moodle_page->__get()
line 214 of /local/cohortauto/lib.php: call to format_string()
line 60 of /local/cohortauto/classes/observer.php: call to local_cohortauto_handler->user_profile_hook()
line ? of unknownfile: call to local_cohortauto_observer::user_updated()
line 155 of /lib/classes/event/manager.php: call to call_user_func()
line 75 of /lib/classes/event/manager.php: call to core\event\manager::process_buffers()
line 834 of /lib/classes/event/base.php: call to core\event\manager::dispatch()
line 209 of /user/lib.php: call to core\event\base->trigger()
line 352 of /auth/oauth2/classes/auth.php: call to user_update_user()
line 480 of /auth/oauth2/classes/auth.php: call to auth_oauth2\auth->update_user()
line 49 of /auth/oauth2/login.php: call to auth_oauth2\auth->complete_login()
I get this error message immediately after logging in, however, I can click 'Continue' and access the site normally.
The URL of the page this error appears on is: /auth/oauth2/login.php?wantsurl=...&sesskey=...&id=...&oauth2code=...
(I've removed the actual values of the query string)
In our institution we are using SAML2 plugin for SSO logins.
In conjunction with that, I have reached to see this warning:
Coding problem: $PAGE->context was not set. You may have forgotten to call require_login() or $PAGE->set_context(). The page may not display correctly as a result
line 572 of /lib/pagelib.php: call to debugging()
line 967 of /lib/pagelib.php: call to moodle_page->magic_get_context()
line 1550 of /lib/weblib.php: call to moodle_page->__get()
line 209 of /local/cohortauto/lib.php: call to format_string()
line 60 of /local/cohortauto/classes/observer.php: call to local_cohortauto_handler->user_profile_hook()
line ? of unknownfile: call to local_cohortauto_observer::user_updated()
line 155 of /lib/classes/event/manager.php: call to call_user_func()
line 75 of /lib/classes/event/manager.php: call to core\event\manager::process_buffers()
line 835 of /lib/classes/event/base.php: call to core\event\manager::dispatch()
line 218 of /user/lib.php: call to core\event\base->trigger()
line 1055 of /auth/saml2/classes/auth.php: call to user_update_user()
line 812 of /auth/saml2/classes/auth.php: call to auth_saml2\auth->update_user_profile_fields()
line 635 of /auth/saml2/classes/auth.php: call to auth_saml2\auth->saml_login_complete()
line 43 of /auth/saml2/login.php: call to auth_saml2\auth->saml_login()
By itself, I cannot reach to know how to solve it.
However, looking at the process, it finally invokes the "strip_tags" function. And in the same line I have seen some of the last changes on this plugin. I would suggest to invoke also strip_tags instead of format_string on the lib.php to build the cohort name.
I will try to build a patch for it tomorrow.
Hi,
This is to ask you suport and consider in your plugin that empty email may exist.
In our institution we run user sincronization from Moodle against several sources. Not all of these systems are able to require email as mandatory for users. So, it is probable that some cases passes through the systems and arrives into Moodle with user accounts without email.
We are making every now and then pedagogy of the use of those systems to set up always email addresses.
But, it is difficult to remove this problem.
We love this plugin and commits to the task we ask it perfectly. However, the cli/sync_users.php process throws a lot of warnings related to empty email addresses, from its lib.php, when consider de domain name of the email address.
We see these lines for every single user that has no email:
PHP Warning: Undefined array key 1 in /var/www/html/local/cohortauto/lib.php on line 218
Warning: Undefined array key 1 in /var/www/html/local/cohortauto/lib.php on line 218
PHP Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /var/www/html/local/cohortauto/lib.php on line 221
Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /var/www/html/local/cohortauto/lib.php on line 221
Consider that empty email may happen and proceed the same way, but with empty strings in all those cases.
In particular, we have this patch in our institution:
diff --git a/local/cohortauto/lib.php b/local/cohortauto/lib.php
index 166b7fe4b91..45b46fc794c 100644
--- a/local/cohortauto/lib.php
+++ b/local/cohortauto/lib.php
@@ -214,23 +214,32 @@ class local_cohortauto_handler {
profile_load_custom_fields($user);
$userprofiledata = cohortauto_prepare_profile_data($user, $this->config->secondrule_fld);
- // Additional values for email.
- list($emailusername, $emaildomain) = explode("@", $userprofiledata['email']);
-
- // Email root domain.
- $emaildomainarray = explode('.', $emaildomain);
- if (count($emaildomainarray) > 2) {
- $emailrootdomain = $emaildomainarray[count($emaildomainarray) - 2].'.'.
- $emaildomainarray[count($emaildomainarray) - 1];
+ if (empty($userprofiledata['email'])) {
+ $userprofiledata['email'] = array(
+ 'full' => '',
+ 'username' => '',
+ 'domain' => '',
+ 'rootdomain' => '',
+ );
} else {
- $emailrootdomain = $emaildomain;
+ // Additional values for email.
+ list($emailusername, $emaildomain) = explode("@", $userprofiledata['email']);
+
+ // Email root domain.
+ $emaildomainarray = explode('.', $emaildomain);
+ if (count($emaildomainarray) > 2) {
+ $emailrootdomain = $emaildomainarray[count($emaildomainarray) - 2] . '.' .
+ $emaildomainarray[count($emaildomainarray) - 1];
+ } else {
+ $emailrootdomain = $emaildomain;
+ }
+ $userprofiledata['email'] = array(
+ 'full' => $userprofiledata['email'],
+ 'username' => $emailusername,
+ 'domain' => $emaildomain,
+ 'rootdomain' => $emailrootdomain
+ );
}
- $userprofiledata['email'] = array(
- 'full' => $userprofiledata['email'],
- 'username' => $emailusername,
- 'domain' => $emaildomain,
- 'rootdomain' => $emailrootdomain
- );
// Set delimiter in use.
$delimiter = $this->config->delim;
We have applied locally this patch and works like a charm:
# time php local/cohortauto/cli/sync_users.php
Beginning user cohort sync...
Sync for 79055 users finished.
real 6m52.500s
user 4m36.288s
sys 0m10.032s
And it does not present any warning about empty email.
If you consider this, we are pleased to provide a PR with it.
Let us know.
Hello teams,
Do you think this plugin will be compatible with moodle 4.X ? Will you make update for the next release ?
Thank you in advance,
Best regards :)
From what I can understand, this plugin updates cohorts when a user logs in (for that user). Is there any way that we can run a one-off task that performs a bulk sync of all users? We have set-up 13 templates that we'd like to use to sync cohorts, and we have a couple thousand users, but we'd like users to show up in a course gradebook even if they haven't logged in (right now they won't show up until they login because they aren't yet in the cohort). Any ideas?
Will there be supporting Moodle 3.11
Hi,
I guess the field to reference is {{ timecreated }}
, but then I'm not entirely sure how.
What is required is to create cohorts based on Month or bi-min they were created e.g.:
etc
Some pointesr would be awsome
In some cases it would be useful to allow the admin to modify the cohort name after it is created - we should look at using the idnumber field for matching the data so that the display name of the cohort can change.
Hello
We have migrated from 3.7 to 3.9 and the plugin has failed to generate any of the cohorts as it did before.
We don't get anything created.
Use old AUTH_MCAE - User logs in - creates the cohort
Convert is using the tool to Auto-Cohort,
Log out learner and log in again, user remains in cohort, doesnt create a new version of the AUTH_MCAE cohort
Kindest Regards
John
https://tracker.moodle.org/browse/MDL-77058
https://moodle.org/mod/forum/discuss.php?d=443384
From Moodle 4.1+ onwards, the idnumber column needs to be "string" type. Cohorts created by the plugin has the value NULL for idnumber column, which results in error.
Hi,
We use this plugin in our production site, with almost 79000 users, and it produces a very long output (file, email, whatever).
The version we used before, this output was not produced. Really, I like the idea of showing debugging information with the username being processed. However, for a normal execution, it is an unnecessary output, in my opinion.
I propose you to have a plugin setting, like "Enable sync debug", a checkbox, so that if enabled, this usernames listing is shown, and if disabled, it is not shown.
I mean:
Beginning user cohort sync...
- User 'username1' ...done.
- User 'username2' ...done.
[...]
- User 'username78693' ...done.
Sync for 78693 users finished.
Beginning user cohort sync...
Sync for 78693 users finished.
This way, with "Enable sync debug: No", it is really clear that it was processed and all was ok. Otherwise, some output will be shown with the exception being thrown.
If we need at some time know really which users were processed, we can then "Enable sync debug: Yes" and then follow the output and verify if the username appears on the list.
Related to this, it can also be interesting to have some field informing the last time the user's cohorts were synced. It could be a user preference, for instance, of configurable on the plugin settings allowing to define a user field (user field or custom profile field), so if it is defined, it is set just after processing the user, or just triggering an event informing that the user was processed by the plugin.
If you are interested in the first part or also the second part, we could provide a patch.
Thanks,
Jordi
With Moodle 4 on Apache, MySQL, PHP 8, debug turned on, the following message displayed Deprecated: Required parameter $result follows optional parameter $prefix in /local/cohortauto/lib.php on line 80
Hi,
This plugin can not be translated in AMOS.
String concatenation is not allowed.
Please check the plugins checklist for strings at https://docs.moodle.org/dev/index.php?title=Plugin_contribution_checklist&redirect=no#Strings .
Thanks in advance.
Do not know where to post this elsewhere but I need some support with the plugin.
I have tried using this with OpenID Connect but it does not seem to work. Does the plugin listen to every login as well or only if a profile gets created/updated?
We have the following superstructure in the company and want to put users into cohorts based on the domain:
So in my case, if I understand how the plugin works correctly I would write I would write
{{ email.domain) }} in the (mainrule_fld
) right
and then in (replace_arr
)
I would say okay:
companyname.com|Internal
external.companyname.com|Partner
partner.companyname.com|External
Would that make sense?
However, I cannot even find where to modify the plugin after the initial installation. Have not worked with Moodle as much yet so sorry for the inconvenience.
Hi, I've set up the plug in and it is working great for new accounts but when I run sync_users.php in terminal I get the following error:
!!! error/generalexceptionmessage !!!
I'm using moodle 4 and php 7.4
Any ideas?
After user is created from
https://github.com/moodle/moodle/blob/MOODLE_311_STABLE/lib/tests/report_helper_test.php#L87
it triggers event
https://github.com/catalyst/moodle-local_cohortauto/blob/main/classes/observer.php#L40
in between output is wiped out and $output
returns an empty string
https://github.com/moodle/moodle/blob/MOODLE_311_STABLE/lib/tests/report_helper_test.php#L100
And makes this unit test fail:
vendor/bin/phpunit --filter report_helper_test
Moodle 3.11.8+ (Build: 20220722), 417e0252f4e39b28c02d069f35ab5055c8ce39db
Php: 7.4.30, mysqli: 5.7.39, OS: Linux 5.15.0-41-generic x86_64
PHPUnit 9.5.13 by Sebastian Bergmann and contributors.
..F 3 / 3 (100%)
Time: 00:02.022, Memory: 328.00 MB
There was 1 failure:
1) core\report_helper_test::test_print_report_selector
Failed asserting that '' contains "<option value="/report/log/index.php?id=118000" selected>Logs</option>".
/var/www/cpa-311/lib/tests/report_helper_test.php:107
/var/www/cpa-311/lib/phpunit/classes/advanced_testcase.php:80
phpvfscomposer:///var/www/cpa-311/vendor/phpunit/phpunit/phpunit:97
FAILURES!
Tests: 3, Assertions: 5, Failures: 1.
Since upgrading to moodle 4, we are experiencing extreme server loads from Cohort_Auto. Is there a way we can make an adjustment to reduce server the server load?
It was set to 15 minutes but takes 12-13 minutes to complete so the server is not recovering, we have changed it to 30 minutes but wondered if we can make any other changes. For example, is changing it to 60 minutes ok? Can we do anything to reduce the server load on the 12 mins run? Does it support Redis?
Hi!
Is there a roadmap for 4.x compatibility or it's still not on the menu?
In case you need dev help or help testing functionality let me know!
Filippo
Even though it has a settings.php, it is curious that the link to the settings page for the plugin is not listed on the local plugins sections. Instead, I have to look for "cohortauto" on the search box and then I can see the other two admin pages and also de settings page, with the correct breadcrumb.
I'll try to look into it and try to provide a patch.
It is very strange behavior to cut profile fields. %split function suggests long lists in user's profile, so it is doubtfully.
moodle-local_cohortauto/lib.php
Line 53 in f598df6
Most, if not all, of our auto-generated cohorts are duplicated with some but not complete overlap in membership.
In some cases, I could see it if there is a multi-value field. But I'm not sure that is the case. What are the reasons cohorts would be duplicated?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.