From 93cbf7c0426af55f2af90853882f3002d61d329d Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Mon, 24 May 2021 13:18:04 +1000 Subject: [PATCH 1/2] Set userid and courseid columns to be NOT NULL --- db/upgrade.php | 36 ++++++++++++++++++++++++++++++++++++ version.php | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/db/upgrade.php b/db/upgrade.php index 3c656f5f..cf619daa 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -500,6 +500,42 @@ 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'); + } + return $result; } diff --git a/version.php b/version.php index c0e71b8c..abfff5ff 100644 --- a/version.php +++ b/version.php @@ -19,7 +19,7 @@ * @copyright 2012 iParadigms LLC */ -$plugin->version = 2021091501; +$plugin->version = 2021101800; $plugin->release = "3.5+"; $plugin->requires = 2018051700; $plugin->component = 'plagiarism_turnitin'; From c64c7a418ad5c0c14707166d093e41740f181ebd Mon Sep 17 00:00:00 2001 From: Tomo Tsuyuki Date: Thu, 16 Dec 2021 15:27:10 +1100 Subject: [PATCH 2/2] Fix issue#482 plagiarism_turnitin_config --- db/upgrade.php | 16 ++++++++++++++++ version.php | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/db/upgrade.php b/db/upgrade.php index cf619daa..fb110052 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -536,6 +536,22 @@ function xmldb_plagiarism_turnitin_upgrade($oldversion) { 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 abfff5ff..427e2ca1 100644 --- a/version.php +++ b/version.php @@ -19,7 +19,7 @@ * @copyright 2012 iParadigms LLC */ -$plugin->version = 2021101800; +$plugin->version = 2021121600; $plugin->release = "3.5+"; $plugin->requires = 2018051700; $plugin->component = 'plagiarism_turnitin';