require_once $update_to_v2;
$ok = $ok && hotpot_update_to_v2_1_18();
}
+ if ($oldversion < 2006083101) {
+ require_once $update_to_v2;
+ $ok = $ok && hotpot_update_to_v2_2();
+ }
return $ok;
}
require_once $update_to_v2;
$ok = $ok && hotpot_update_to_v2_1_21();
}
+ if ($oldversion < 2006083101) {
+ require_once $update_to_v2;
+ $ok = $ok && hotpot_update_to_v2_2();
+ }
return $ok;
}
<?PHP
+function hotpot=update_to_v2_2() {
+ global $CFG;
+ $ok = true;
+
+ // remove the index on hotpot_questions.name
+ $table = 'hotpot_questions';
+ $field = 'name';
+ $index = "{$table}_{$field}_idx";
+ if (strtolower($CFG->dbtype)=='postgres7') {
+ $index = "{$CFG->prefix}$index";
+ }
+ hotpot_db_delete_index("{$CFG->prefix}$table", $index);
+
+ // add new hotpot_questions.md5key field (and index)
+ $table = 'hotpot_questions';
+ $field = 'md5key';
+ $ok = $ok && hotpot_db_update_field_type($table, '', $field, 'VARCHAR', 32, '', 'NOT NULL', '', 'name');
+ $ok = $ok && hotpot_db_add_index($table, $field);
+
+ // add new values hotpot_questions.md5key
+ $table = 'hotpot_questions';
+ if ($records = get_records($table)) {
+ foreach ($records as $record) {
+ $ok = $ok && set_field($table, 'md5key', md5($record->name), 'id', $record->id);
+ }
+ }
+
+ // remove the index on hotpot_strings.string
+ $table = 'hotpot_strings';
+ $field = 'string';
+ $index = "{$table}_{$field}_idx";
+ if (strtolower($CFG->dbtype)=='postgres7') {
+ $index = "{$CFG->prefix}$index";
+ }
+ hotpot_db_delete_index("{$CFG->prefix}$table", $index);
+
+ // add new hotpot_strings.md5key field (and index)
+ $table = 'hotpot_strings';
+ $field = 'md5key';
+ $ok = $ok && hotpot_db_update_field_type($table, '', $field, 'VARCHAR', 32, '', 'NOT NULL', '', 'string');
+ $ok = $ok && hotpot_db_add_index($table, $field);
+
+ // add new values hotpot_strings.md5key
+ $table = 'hotpot_strings';
+ if ($records = get_records($table)) {
+ foreach ($records as $record) {
+ $ok = $ok && set_field($table, 'md5key', md5($record->string), 'id', $record->id);
+ }
+ }
+
+ return $ok;
+}
function hotpot_update_to_v2_1_21() {
global $CFG;
$ok = true;
$questionname = $question->name;
}
- if (!$question->id = get_field('hotpot_questions', 'id', 'name', $question->name, 'hotpot', $attempt->hotpot)) {
+ $question->md5key = md5($question->name);
+ if (!$question->id = get_field('hotpot_questions', 'id', 'hotpot', $attempt->hotpot, 'md5key', $question->md5key, 'name', $question->name)) {
// add question record
if (!$question->id = insert_record('hotpot_questions', $question)) {
error("Could not add question record (attempt_id=$attempt->id): ".$db->ErrorMsg(), $next_url);
if (isset($str) && $str<>'') {
// get the id from the table if it is already there
- if (!$id = get_field('hotpot_strings', 'id', 'string', $str)) {
+ $md5key = md5($str);
+ if (!$id = get_field('hotpot_strings', 'id', 'md5key', $md5key, 'string', $str)) {
// create a string record
- $record = NULL;
+ $record = new stdClass();
$record->string = $str;
+ $record->md5key = $md5key;
// try and add the new string record
if (!$id = insert_record('hotpot_strings', $record)) {
}
}
- // update secondary keys, if any
+ // update foreign keys, if any
$ok = true;
foreach ($foreign_keys as $key=>$value) {
if (is_numeric($value)) {
}
}
+ // set md5 keys if necessary (restoring from Moodle<1.6)
+ if ($table=='hotpot_questions' && empty($record->md5key)) {
+ $record->md5key = md5($record->name);
+ }
+ if ($table=='hotpot_strings' && empty($record->md5key)) {
+ $record->md5key = md5($record->string);
+ }
+
// check all "not null" fields have been set
foreach ($table_columns[$table] as $column) {
if ($column->not_null) {
/// Code fragment to define the version of hotpot
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////
-$module->version = 2006083100; // release date of this version (see note below)
+$module->version = 2006083101; // release date of this version (see note below)
$module->release = 'v2.2.0'; // human-friendly version name (used in mod/hotpot/lib.php)
$module->requires = 2006080900; // Requires this Moodle version
$module->cron = 0; // period for cron to check this module (secs)