Skip to content

Commit

Permalink
Merge pull request #4 from catalyst/fix-issue-517-and-482
Browse files Browse the repository at this point in the history
Fix issue turnitin#517 and turnitin#482 (cherry-pick turnitin#585 and turnitin#611
  • Loading branch information
TomoTsuyuki committed Jan 12, 2022
2 parents 58b088b + c64c7a4 commit df0b1e8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 52 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit df0b1e8

Please sign in to comment.