I’m building a Java app to import courses into Moodle 3.0.5+ automatically. However, categories appear only after manual admin updates. How can I trigger this update programmatically?
I’ve dealt with this issue before in my Moodle development work. One approach that’s worked for me is to implement a custom cron task that periodically calls the refresh_course_content() function. This function is part of Moodle’s core library and can be triggered programmatically.
You’ll need to set up a scheduled task in Moodle’s task scheduler, then write a PHP script that executes the refresh. Make sure you have the necessary permissions set up for the task to run.
Another option is to directly update the database after course imports. This is riskier and less recommended, but it can work if you’re careful. You’d need to update the ‘timemodified’ field in the ‘course_categories’ table.
Remember to test thoroughly in a non-production environment first. Moodle’s database structure can be complex, and unexpected issues may arise.
hey there, i had a similar issue. have u tried using moodle’s web services api? theres a function called core_course_get_categories that might help refresh categories. u could call it after importing courses. might need to tweak some settings tho. good luck!