diff --git a/classes/assess_type.php b/classes/assess_type.php index 0ac8888..e144c6f 100644 --- a/classes/assess_type.php +++ b/classes/assess_type.php @@ -108,10 +108,9 @@ public static function is_summative(int $cmid): bool { */ public static function is_locked(int $cmid): bool { global $DB; - if ($r = $DB->get_record('local_assess_type', ['cmid' => $cmid])) { - return $r->locked; - } - return false; + $record = $DB->get_record('local_assess_type', ['cmid' => $cmid], 'locked'); + + return (bool) ($record->locked ?? false); } /** diff --git a/db/install.xml b/db/install.xml index b7b3f2c..33b900f 100644 --- a/db/install.xml +++ b/db/install.xml @@ -1,5 +1,5 @@ - @@ -8,10 +8,10 @@ - - - - + + + + diff --git a/db/upgrade.php b/db/upgrade.php new file mode 100644 index 0000000..06043a8 --- /dev/null +++ b/db/upgrade.php @@ -0,0 +1,67 @@ +. + +/** + * Plugin upgrade steps are defined here. + * + * @package local_assess_type + * @category upgrade + * @copyright 2024 onwards University College London {@link https://www.ucl.ac.uk/} + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author Alex Yeung + */ + +/** + * Execute local_assess_type upgrade from the given old version. + * + * @param int $oldversion + * @return bool + */ +function xmldb_local_assess_type_upgrade($oldversion) { + global $DB; + $dbman = $DB->get_manager(); + + if ($oldversion < 2024091300) { + $table = new xmldb_table('local_assess_type'); + + $field = new xmldb_field('cmid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'courseid'); + // Launch change of nullability for field cmid. + $dbman->change_field_notnull($table, $field); + // Launch change of default for field cmid. + $dbman->change_field_default($table, $field); + + $field = new xmldb_field('gradeitemid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'cmid'); + // Launch change of nullability for field gradeitemid. + $dbman->change_field_notnull($table, $field); + // Launch change of default for field gradeitemid. + $dbman->change_field_default($table, $field); + + $field = new xmldb_field('type', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, 'gradeitemid'); + // Launch change of nullability for field type. + $dbman->change_field_notnull($table, $field); + + $field = new xmldb_field('locked', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'type'); + // Launch change of nullability for field locked. + $dbman->change_field_notnull($table, $field); + // Launch change of default for field locked. + $dbman->change_field_default($table, $field); + + // Assess_type savepoint reached. + upgrade_plugin_savepoint(true, 2024091300, 'local', 'assess_type'); + } + + return true; +} diff --git a/version.php b/version.php index fa69475..dae8b9b 100644 --- a/version.php +++ b/version.php @@ -27,6 +27,6 @@ $plugin->component = 'local_assess_type'; $plugin->release = '1.0'; -$plugin->version = 2024080600; // YYYYMMDD. +$plugin->version = 2024091300; // YYYYMMDD. $plugin->requires = 2023100900; $plugin->maturity = MATURITY_STABLE;