Hide
Assumptions
- Your DB sever is "postgres".
- Your DB server host is "localhost"
Set up external table inside your Moodle DB:
Create table
CREATE TABLE my_courses (
|
fullname VARCHAR(300),
|
shortname VARCHAR(300),
|
idnumber VARCHAR(100),
|
startdate date,
|
enddate date);
|
Insert Data
INSERT INTO my_courses (fullname, shortname, idnumber, startdate, enddate)
|
VALUES
|
('Course one', 'c1', '', '2025-Jan-08', '2026-Jan-08'),
|
('Course two', 'c2', '', NULL, NULL),
|
('Course three', 'c3', '', '2025-Jan-18', '2024-Jan-08'),
|
('Course four', 'c4', '', NULL, '2021-Jan-08'),
|
('Course five', 'c5', '', '2027-Jan-08', NULL),
|
('Course six', 'c6', '', NULL, '2027-Jan-08')
|
;
|
Set up Enrolment plugin
php admin/cli/cfg.php --component=enrol_database --name=dbtype --set=postgres
|
php admin/cli/cfg.php --component=enrol_database --name=dbhost --set=localhost
|
php admin/cli/cfg.php --component=enrol_database --name=dbuser --set=<your_db_username>
|
php admin/cli/cfg.php --component=enrol_database --name=dbpass --set=<your_db_password>
|
php admin/cli/cfg.php --component=enrol_database --name=dbname --set=<yourdbname>
|
php admin/cli/cfg.php --component=enrol_database --name=newcoursetable --set=my_courses
|
php admin/cli/cfg.php --component=enrol_database --name=newcoursestartdate --set=startdate
|
php admin/cli/cfg.php --component=enrol_database --name=newcourseenddate --set=enddate
|
php admin/cli/cfg.php --component=moodlecourse --name=courseduration --set=31536000
|
Enable plugin
Navigate to /admin/settings.php?section=manageenrols and enable External database
Navigate to /enrol/test_settings.php?enrol=database and make sure that your configuration is correct.
Note, that message "External enrolment table not specified." is ok as we are not testing any enrolments.
Testing
1. Execute following CLI
php admin/cli/scheduled_task.php --execute="\enrol_database\task\sync_enrolments"
|
2. Confirm that you see following output:
Starting course synchronisation...
|
can not insert new course, the end date must be after the start date: c3
|
can not insert new course, the end date must be after the start date: c4
|
creating course: 14, Course five, c5, , 1
|
creating course: 15, Course two, c2, , 1
|
creating course: 16, Course one, c1, , 1
|
creating course: 17, Course six, c6, , 1
|
|
4. Navigate to /course/management.php and confirm you can see Course one, Course two, Course five and Course six
5. Check configuration of Course one and confirm start date = 2025-Jan-08 & end date = 2026-Jan-08
6. Check configuration of Course two and confirm start date = today date & end date = today date + 1 year
7. Check configuration of Course five and confirm start date = 2027-Jan-08 & end date = 2028-Jan-08
8. Check configuration of Course six and confirm start date = today date & end date = 2027-Jan-08
Show
Assumptions
Your DB sever is " postgres ".
Your DB server host is " localhost "
Set up external table inside your Moodle DB:
Create table
CREATE TABLE my_courses (
fullname VARCHAR( 300 ),
shortname VARCHAR( 300 ),
idnumber VARCHAR( 100 ),
startdate date,
enddate date);
Insert Data
INSERT INTO my_courses (fullname, shortname, idnumber, startdate, enddate)
VALUES
( 'Course one' , 'c1' , '' , '2025-Jan-08' , '2026-Jan-08' ),
( 'Course two' , 'c2' , '' , NULL, NULL),
( 'Course three' , 'c3' , '' , '2025-Jan-18' , '2024-Jan-08' ),
( 'Course four' , 'c4' , '' , NULL, '2021-Jan-08' ),
( 'Course five' , 'c5' , '' , '2027-Jan-08' , NULL),
( 'Course six' , 'c6' , '' , NULL, '2027-Jan-08' )
;
Set up Enrolment plugin
php admin/cli/cfg.php --component=enrol_database --name=dbtype --set=postgres
php admin/cli/cfg.php --component=enrol_database --name=dbhost --set=localhost
php admin/cli/cfg.php --component=enrol_database --name=dbuser --set=<your_db_username>
php admin/cli/cfg.php --component=enrol_database --name=dbpass --set=<your_db_password>
php admin/cli/cfg.php --component=enrol_database --name=dbname --set=<yourdbname>
php admin/cli/cfg.php --component=enrol_database --name=newcoursetable --set=my_courses
php admin/cli/cfg.php --component=enrol_database --name=newcoursestartdate --set=startdate
php admin/cli/cfg.php --component=enrol_database --name=newcourseenddate --set=enddate
php admin/cli/cfg.php --component=moodlecourse --name=courseduration --set= 31536000
Enable plugin
Navigate to /admin/settings.php?section=manageenrols and enable External database
Navigate to /enrol/test_settings.php?enrol=database and make sure that your configuration is correct.
Note, that message "External enrolment table not specified." is ok as we are not testing any enrolments.
Testing
1. Execute following CLI
php admin/cli/scheduled_task.php --execute= "\enrol_database\task\sync_enrolments"
2. Confirm that you see following output:
Starting course synchronisation...
can not insert new course, the end date must be after the start date: c3
can not insert new course, the end date must be after the start date: c4
creating course: 14 , Course five, c5, , 1
creating course: 15 , Course two, c2, , 1
creating course: 16 , Course one, c1, , 1
creating course: 17 , Course six, c6, , 1
4. Navigate to /course/management.php and confirm you can see Course one, Course two, Course five and Course six
5. Check configuration of Course one and confirm start date = 2025-Jan-08 & end date = 2026-Jan-08
6. Check configuration of Course two and confirm start date = today date & end date = today date + 1 year
7. Check configuration of Course five and confirm start date = 2027-Jan-08 & end date = 2028-Jan-08
8. Check configuration of Course six and confirm start date = today date & end date = 2027-Jan-08