Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-59986

Make the external database enrolment sync a scheduled task

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      Setup the external database (mysql)

      1. Make sure you have mysql set up and running locally.
      2. Make sure you have the mysqli extension installed for php.
      3. Now, open a connection via your mysql cli client:

      mysql -u USERNAME -p PASSWORD
      

      replacing username and password with the appropriate values.
      4. Now, create a new database for enrol and use it:

      create database enrol;
      use enrol;
      

      5. Next, create the required tables:

      create table enrolment(courseidnumber varchar(100), useridnumber varchar(100), rolename varchar(255));
      create table course(fullname varchar(255), shortname varchar(100), idnumber varchar(100));
      

      6. Now, insert some dummy data into them:

      insert into enrolment(courseidnumber, useridnumber, rolename) values('c1','u1','student'); 
      insert into course(fullname, shortname, idnumber) values('REMOTE COURSE', 'remote course', 'c1');
      

      7. Now, assuming you've got a few moodle users set up (if not, create a new one), go to Users > Browse list of users
      8. Edit a user's profile and set their idnumber to 'u1' (hint: it's under the 'Optional' section down the bottom of the form).

      Testing the synchronisation task 

      1. Install a new instance or update the one you have
      2. Log in as admin and enable the database enrolment plugin
      3. Go to 'Site administration | Server | System paths' and set the 'Path to PHP CLI' to the proper value in your instance
      4. Go to 'Site administration | Server | Scheduled tasks' list and make sure there is a 'Synchronise external database enrolments task [\enrol_database\task\sync_enrolments]' for the database plugin (make sure it is not the same as the one for the LDAP plugin)
      5. Click on the cog icon to edit the task and enable it
      6. Make sure you see the "Run now" link and copy it for later
      7. Confirm that when you 'Run now' the synchronization is made (courses are created and users enrolled)
      8. Go to command line and on the Moodle root dir execute

        php enrol/database/cli/sync.php 

      9. Confirm you see both messages "The sync enrolments cron script has been deprecated. Please use the scheduled task instead." and "The scheduled task sync_enrolments is enabled, the cron execution has been aborted."
      10. Log in as admin and disable the database enrolment plugin
      11. Go to 'Site administration | Server | Scheduled tasks' and make sure there is no link to "Run now" in the "Synchronise external database enrolments task" row and it says "Plugin disabled"
      12. Get the URL you copied from the "Run now" link before and open it on a new tab/window
      13. Click the submit button to run the task now and make sure you see "Plugin not enabled ... used 0,5 dbqueries" - it will depend on Moodle database setup. On Postgres lib/classes/lock/postgres_lock_factory.php is different and counts 5 queries while in MySQL and MariaDB it will make no queries.
      Show
      Setup the external database (mysql) 1. Make sure you have mysql set up and running locally. 2. Make sure you have the mysqli extension installed for php. 3. Now, open a connection via your mysql cli client: mysql -u USERNAME -p PASSWORD replacing username and password with the appropriate values. 4. Now, create a new database for enrol and use it: create database enrol; use enrol; 5. Next, create the required tables: create table enrolment(courseidnumber varchar(100), useridnumber varchar(100), rolename varchar(255)); create table course(fullname varchar(255), shortname varchar(100), idnumber varchar(100)); 6. Now, insert some dummy data into them: insert into enrolment(courseidnumber, useridnumber, rolename) values('c1','u1','student'); insert into course(fullname, shortname, idnumber) values('REMOTE COURSE', 'remote course', 'c1'); 7. Now, assuming you've got a few moodle users set up (if not, create a new one), go to Users > Browse list of users 8. Edit a user's profile and set their idnumber to 'u1' (hint: it's under the 'Optional' section down the bottom of the form). Testing the synchronisation task  Install a new instance or update the one you have Log in as admin and enable the database enrolment plugin Go to ' Site administration | Server | System paths ' and set the ' Path to PHP CLI' to the proper value in your instance Go to ' Site administration | Server | Scheduled tasks ' list and make sure there is a ' Synchronise external database enrolments task [\enrol_database\task\sync_enrolments] ' for the database plugin (make sure it is not the same as the one for the LDAP plugin) Click on the cog icon to edit the task and enable it Make sure you see the "Run now" link and copy it for later Confirm that when you ' Run now ' the synchronization is made (courses are created and users enrolled) Go to command line and on the Moodle root dir execute php enrol/database/cli/sync.php Confirm you see both messages "The sync enrolments cron script has been deprecated. Please use the scheduled task instead." and "The scheduled task sync_enrolments is enabled, the cron execution has been aborted." Log in as admin and disable the database enrolment plugin Go to ' Site administration | Server | Scheduled tasks ' and make sure there is no link to "Run now" in the "Synchronise external database enrolments task" row and it says "Plugin disabled" Get the URL you copied from the "Run now" link before and open it on a new tab/window Click the submit button to run the task now and make sure you see "Plugin not enabled ... used 0,5 dbqueries" - it will depend on Moodle database setup. On Postgres lib/classes/lock/postgres_lock_factory.php is different and counts 5 queries while in MySQL and MariaDB it will make no queries.
    • Affected Branches:
      MOODLE_32_STABLE, MOODLE_35_STABLE, MOODLE_36_STABLE
    • Fixed Branches:
      MOODLE_37_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-59986-master

      Description

      Moodle switched to using scheduled task for all other scheduled jobs but this is still not a scheduled task & can only be run as a cron job: enrol/database/cli/sync.php

      LDAP syncing & flat file enrolments are scheduled tasks but not the external database enrolments so I am assuming it is an oversight rather than a system limitation.

       

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                5 Vote for this issue
                Watchers:
                17 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  20/May/19

                  Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 4 hours
                  4h