Run a scheduled task immediately

To run a scheduled task immediately, navigate to Site administration, Server, Scheduled Tasks.

Edit the relevant task and adjust the Minute / Hour to * so that the Next run changes to ASAP.

When the cron is next run the scheduled task will also be run. You might also need to manually trigger the cron depending on how that is set up.


Site stuck at upgrade running

For example you might see this message:

!!! Site is being upgraded, please retry later. !!!

Whenever a site upgrade is triggered, an entry is added into the database in the mdl_config table:

name=upgraderunning value=unixtimestamp that the upgrade was started

This is by design and deliberate to prevent changes to the site while things are being upgraded.

However if you ever have a site stuck indefinitely on upgrade, you might need to clear this out of the DB. At least check for the value in mdl_config but be careful here, you may break things if you clear out an upgrade that is still running somewhere in the background.

Don’t forget to clear your moodle cache if you do make a change to the mdl_config table.


Verify your Moodle Database Schema against XMLDB

There is a very handy CLI tool admin/cli/check_database_schema.php which compares the structure of your Moodle database against the XMLDB metadata and looks for any issues.

These might includes issues such as:

  • Missing tables – they exist in XMLDB but not in your DB (not good!)
  • Unexpected tables – tables in your database not defined in XMLDB (e.g. created outside of Moodle)
  • Mismatches between table column definitions in the database and XMLDB

Some things may be acceptable to ignore, but it pays to do a check, particularly after an upgrade to make sure the upgrade process worked correctly and in particular you aren’t missing any core or plugin database tables that are defined in XMLDB, as these will pop up as database errors in your application sooner or later (e.g. “Error reading from database”).

If you need to build any missing core tables, remember they are defined under Developer > XMLDB Editor. From here find lib/db (core database tables) and choose Load, followed by Edit. Find the table you need and choose Edit. You can then use View SQL code to get the relevant SQL commands to create the table if it is missing from your database.

Also as a developer, make sure you are correctly utilising XMLDB for defining your plugin’s database tables. Taking shortcuts such as directly creating tables in the database without defining them in XMLDB will mean that they will pop up as unexpected when checking the database schema.