The upgrade.php
file provides code to upgrade our module as we release new versions of Moodle. It is only necessary if we have deployed our module to users and subsequently make updates that require the database to be changed.
The recommended method of updating an activity's database is to use the XMLDB editor. It provides a GUI that you can use to update the database, including adding new tables. The editor will output both a complete new install.xml
file and the PHP code needed for our upgrade.php
file.
This function is called by Moodle core when a new version of the module is detected. The version in Moodle's configuration database is compared to the value found in the module's version.php
file. Following is a sample section of code generated from the XMLDB editor. It illustrates the code needed to add a scale field to the foo
table.
Our if
condition indicates that the upgrade should be run...