Show
Configuration
Configure integration
On you moodle DB run following SQL to create a new table
CREATE TABLE integration (moodle_user varchar( 10 ), moodle_course varchar( 10 ), moodle_role varchar( 10 ));
# Go to /admin/settings.php?section=manageenrols and enable External database method
Go to /admin/settings.php?section=enrolsettingsdatabase and set following settings:
dbtype = your DB type (e.g. if using PostgreSQL, choose "Postgres" )
dbhost = value of $CFG->dbhost from your config.php
dbuser = value of $CFG->dbuser from your config.php
dbpass = value of $CFG->dbpass from your config.php
dbname = value of $CFG->dbname from your config.php
localcoursefield = shortname
localuserfield = username
localrolefield = shortname
remoteenroltable = integration
remotecoursefield = moodle_course
remoteuserfield = moodle_user
remoterolefield = moodle_role
Create user with username "student"
Create 3 courses with short names "course1", "course2" and "course3".
Configure WS
Navigate to /admin/roles/define.php?action=edit&roleid=7 (Admin > Users > Define roles > Edit Authenticated users) and allow " webservice/rest:use "" permission
Navigate to /admin/search.php?query=enablewebservices (Admin > Advanced features) and Enable web services
Navigate to /admin/settings.php?section=webserviceprotocols (Admin > Server > Web services > Manage protocols) and enable REST protocol
Navigate to /admin/settings.php?section=externalservices (Admin > Server > Web services > External services), create a service "Test service" with shortname 'testservice' and enable it.
On the next screen add block_recentlyaccesseditems_get_recent_items function to that service
Navigate to /admin/webservice/tokens.php (Admin > Server > Web services > Manage tokens) and Create a token for Student user for Test service.
Note that token as it will be used in tests later.
Configure RSS
Navigate to /admin/search.php?query=enablerssfeeds and enable RSS feeds globally and for Forum (You need to save to enable RSS feeds globally then after the reload, you can enable RSS fields for Forum)
Navigate to course3 and Navigate to Announcements forum activity settings.
Set RSS feed for this activity to Discussion
Number of RSS recent articles = 50
Save settings
Add a new discussion
Navigate to the student's profile page. We'll come back to this later.
Testing
Web login
Run following SQL to inset an enrolment record
INSERT INTO integration VALUES( 'student' , 'course1' , 'student' );
Login as student in a different browser (incognito session).
Confirm that student was successfully enrolled into the course1 using External database method.
View course1's "Announcements" forum
Run following SQLs to update enrolments:
INSERT INTO integration VALUES( 'student' , 'course2' , 'student' );
INSERT INTO integration VALUES( 'student' , 'course3' , 'student' );
DELETE FROM integration WHERE moodle_course = 'course1' ;
Log out
Log in as student again.
Confirm that student is not enrolled into the course1.
Confirm that student is now enrolled into the course2 and course3 using External database method.
View course2's and course3's "Announcements" forums
WS login
Run following SQL
DELETE FROM integration;
Open a terminal and run
curl '<YOUR_MOODLE_URL>/webservice/rest/server.php?wstoken=<TOKEN>&wsfunction=block_recentlyaccesseditems_get_recent_items&moodlewsrestformat=json' | python -m json.tool
Confirm that you get an empty array
Run following SQL
INSERT INTO integration VALUES('student', 'course1', 'student');
Run the curl command again
Confirm that user you still get an empty array
Add the following in config.php
$CFG->enrolments_sync_interval = 10;
Wait for at least 10 seconds.
Run the curl command again
Confirm that course1's announcements forum is returned, but not course2's and course3's.
Run following SQL
DELETE FROM integration WHERE moodle_course = 'course1';
INSERT INTO integration VALUES('student', 'course2', 'student');
Make sure at least 10 seconds have passed
Run the curl command again
Confirm that course2's announcements forum is returned, but not course1's and course3's.
Run following SQL
DELETE FROM integration WHERE moodle_course = 'course2';
INSERT INTO integration VALUES('student', 'course3', 'student');
Set $CFG->enrolments_sync_interval = 3600;
Run the curl command again
Confirm that course2's announcements forum is returned, but still not course1's and course3's.
Login to get token
Navigate to /login/token.php?username=student&password=<PASSWORD>&service=testservice
Confirm that the student's web service token is returned.
Back on the admin's browser window reload the student's profile page
Confirm that user is enrolled only in course3
RSS login
Back on the student's browser window, navigate to Course 3 and Announcements forum activity
Click on " RSS feed of discussions "" and note the URL (you will use it for testing).
Logout as student
Set $CFG->enrolments_sync_interval = 10;
Run following SQL
DELETE FROM integration;
Navigate to RSS URL from step 2
Confirm that the XML contains an error like "Your RSS link does not contain a valid authentication token."
On the admin's browser, reload the student's profile page and Confirm that the student is not enrolled in course1, course2 and course3
Comment out $CFG->enrolments_sync_interval = 10; or set it to 3600
Run following SQL
INSERT INTO integration VALUES('student', 'course1', 'student');
Navigate to RSS URL from step 2
On the admin's browser, reload the student's profile page and Confirm that the student is not enrolled in course1, course2 and course3
Set $CFG->enrolments_sync_interval = 10;
Navigate to RSS URL from step 2
On the admin's browser, reload the student's profile page and Confirm that the student is now enrolled in course1, but not in course2 and course3
Run following SQL
DELETE FROM integration WHERE moodle_course = 'course1';
INSERT INTO integration VALUES('student', 'course2', 'student');
Navigate to RSS URL from step 2
Confirm that user is not enrolled in course1
Confirm that user is enrolled in course2
Run following SQL
DELETE FROM integration WHERE moodle_course = 'course2';
INSERT INTO integration VALUES('student', 'course3', 'student');
Set $CFG->enrolments_sync_interval = 3600;
Navigate to RSS URL from step 2
Confirm that user is still enrolled in course2
Confirm that user is still not enrolled in course3
Scheduled task
Continuing from the previous step, run the curl command in the terminal.
Confirm that course2's Announcements forum is returned.
Run the database enrolment sync scheduled task:
php admin/cli/scheduled_task.php --execute="\\enrol_database\\task\\sync_enrolments"
Run the curl command again.
Confirm that course3's Announcements forum is returned this time and not course2's.