Skip to content
Browse files

replace MySQL-only indexes on text fields (hotpot_question.name + hot…

…pot_strings.string) with two new md5key fields (hotpot_question.md5key + hotpot_strings.md5key), which are the MD5 hash of the respective text fields. Microincrement version number to 2006083101
  • Loading branch information...
1 parent 5f941d1 commit 1897e3ef9543c3bef9425be9a534bf9080190d14 gbateson committed Sep 1, 2006
View
4 mod/hotpot/db/mysql.php
@@ -37,6 +37,10 @@ function hotpot_upgrade($oldversion) {
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;
}
View
4 mod/hotpot/db/postgres7.php
@@ -45,6 +45,10 @@ function hotpot_upgrade($oldversion) {
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;
}
View
52 mod/hotpot/db/update_to_v2.php
@@ -1,4 +1,56 @@
<?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;
View
9 mod/hotpot/lib.php
@@ -1962,7 +1962,8 @@ function hotpot_add_response(&$attempt, &$question, &$response) {
$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);
@@ -2133,11 +2134,13 @@ function hotpot_string_id($str) {
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)) {
View
10 mod/hotpot/restorelib.php
@@ -299,7 +299,7 @@ function hotpot_restore_record(&$restore, $status, &$xml, $table, $foreign_keys,
}
}
- // update secondary keys, if any
+ // update foreign keys, if any
$ok = true;
foreach ($foreign_keys as $key=>$value) {
if (is_numeric($value)) {
@@ -336,6 +336,14 @@ function hotpot_restore_record(&$restore, $status, &$xml, $table, $foreign_keys,
}
}
+ // 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) {
View
2 mod/hotpot/version.php
@@ -3,7 +3,7 @@
/// 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)

0 comments on commit 1897e3e

Please sign in to comment.
Something went wrong with that request. Please try again.