diff --git a/db/upgrade.php b/db/upgrade.php index 3c656f5f..fb110052 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -500,6 +500,58 @@ function xmldb_plagiarism_turnitin_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2021081301, 'plagiarism', 'turnitin'); } + if ($oldversion < 2021101800) { + // Set userid to be NOT NULL. + $table = new xmldb_table('plagiarism_turnitin_users'); + $index = new xmldb_index('userid', XMLDB_INDEX_UNIQUE, array('userid')); + $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'id'); + if ($dbman->field_exists($table, $field)) { + // Double-check that there is no records with a NULL value. + if ($DB->count_records_select('plagiarism_turnitin_users', 'userid IS NULL') == 0) { + // Drop and then recreate unique index, otherwise Moodle will throw dependency exception. + if ($dbman->index_exists($table, $index)) { + $dbman->drop_index($table, $index); + } + $dbman->change_field_notnull($table, $field); + $dbman->add_index($table, $index); + } + } + + // Set courseid to be NOT NULL. + $table = new xmldb_table('plagiarism_turnitin_courses'); + $index = new xmldb_index('courseid', XMLDB_INDEX_UNIQUE, array('courseid')); + $field = new xmldb_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'id'); + if ($dbman->field_exists($table, $field)) { + // Double-check that there is no records with a NULL value. + if ($DB->count_records_select('plagiarism_turnitin_courses', 'courseid IS NULL') == 0) { + // Drop and then recreate unique index, otherwise Moodle will throw dependency exception. + if ($dbman->index_exists($table, $index)) { + $dbman->drop_index($table, $index); + } + $dbman->change_field_notnull($table, $field); + $dbman->add_index($table, $index); + } + } + + upgrade_plugin_savepoint(true, 2021101800, 'plagiarism', 'turnitin'); + } + + if ($oldversion < 2021121600) { + $table = new xmldb_table('plagiarism_turnitin_config'); + // Delete index if exists. + $index = new xmldb_index('config_hash', XMLDB_INDEX_UNIQUE, array('config_hash')); + if ($dbman->index_exists($table, $index)) { + $dbman->drop_index($table, $index); + } + // Set config_hash to be NOT NULL, also set precision 255. + $field = new xmldb_field('config_hash', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'value'); + if ($dbman->field_exists($table, $field)) { + $dbman->change_field_notnull($table, $field); + } + + upgrade_plugin_savepoint(true, 2021121600, 'plagiarism', 'turnitin'); + } + return $result; } diff --git a/version.php b/version.php index c0e71b8c..427e2ca1 100644 --- a/version.php +++ b/version.php @@ -19,7 +19,7 @@ * @copyright 2012 iParadigms LLC */ -$plugin->version = 2021091501; +$plugin->version = 2021121600; $plugin->release = "3.5+"; $plugin->requires = 2018051700; $plugin->component = 'plagiarism_turnitin';