Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

removed all references to obsolete indexes on "hotpot_questions.name"…

… and "hotpot_strings.string"
  • Loading branch information...
commit 85b05f3784d9e324dbbdd877418945630caa2c45 1 parent cd49109
gbateson authored

Showing 1 changed file with 24 additions and 61 deletions. Show diff stats Hide diff stats

  1. +24 61 mod/hotpot/db/update_to_v2.php
85 mod/hotpot/db/update_to_v2.php
@@ -6,10 +6,11 @@ function hotpot_update_to_v2_2() {
6 6 // remove the index on hotpot_questions.name
7 7 $table = 'hotpot_questions';
8 8 $field = 'name';
9   - $index = "{$table}_{$field}_idx";
10 9 if (strtolower($CFG->dbtype)=='postgres7') {
11   - $index = "{$CFG->prefix}$index";
12   - }
  10 + $index = "{$CFG->prefix}{$table}_{$field}_idx";
  11 + } else {
  12 + $index = "{$table}_{$field}_idx";
  13 + }
13 14 hotpot_db_delete_index("{$CFG->prefix}$table", $index);
14 15
15 16 // add new hotpot_questions.md5key field (and index)
@@ -29,10 +30,11 @@ function hotpot_update_to_v2_2() {
29 30 // remove the index on hotpot_strings.string
30 31 $table = 'hotpot_strings';
31 32 $field = 'string';
32   - $index = "{$table}_{$field}_idx";
33 33 if (strtolower($CFG->dbtype)=='postgres7') {
34   - $index = "{$CFG->prefix}$index";
35   - }
  34 + $index = "{$CFG->prefix}{$table}_{$field}_idx";
  35 + } else {
  36 + $index = "{$table}_{$field}_idx";
  37 + }
36 38 hotpot_db_delete_index("{$CFG->prefix}$table", $index);
37 39
38 40 // add new hotpot_strings.md5key field (and index)
@@ -174,33 +176,23 @@ function hotpot_update_to_v2_1_16() {
174 176 global $CFG;
175 177 $ok = true;
176 178
177   - // settings for the "hotpot_questions_name_idx" index
178   - $length = 20;
179   - $field = 'name';
180   - $table = 'hotpot_questions';
181   - $index = "{$table}_{$field}_idx";
182   -
183   - // remove the index
184   - hotpot_db_delete_index("{$CFG->prefix}$table", $index);
185   - hotpot_db_delete_index("{$CFG->prefix}$table", "{$CFG->prefix}$index");
  179 + // remove the questions name index
  180 + hotpot_db_delete_index("{$CFG->prefix}hotpot_questions", "hotpot_questions_name_idx");
  181 + hotpot_db_delete_index("{$CFG->prefix}hotpot_questions", "{$CFG->prefix}hotpot_questions_name_idx");
186 182
187 183 // make sure type of 'name' is a text field (not varchar 255)
188   - $ok = $ok && hotpot_db_update_field_type($table, $field, $field, 'TEXT', '', '', 'NOT NULL', '');
189   -
190   - // restore the index
191   - $ok = $ok && hotpot_db_add_index($table, $field, $length);
  184 + $ok = $ok && hotpot_db_update_field_type('hotpot_questions', 'name', 'name', 'TEXT', '', '', 'NOT NULL', '');
192 185
193 186 if (strtolower($CFG->dbtype)=='mysql') {
194 187
195 188 // set default values on certain VARCHAR(255) fields
196   - $varchar_fields = array(
197   - 'hotpot.studentfeedbackurl',
198   - 'hotpot_responses.correct',
199   - 'hotpot_responses.wrong',
200   - 'hotpot_responses.ignored'
  189 + $fields = array(
  190 + 'hotpot' => 'studentfeedbackurl',
  191 + 'hotpot_responses' => 'correct',
  192 + 'hotpot_responses' => 'wrong',
  193 + 'hotpot_responses' => 'ignored'
201 194 );
202   - foreach ($varchar_fields as $varchar_field) {
203   - list ($table, $field) = explode('.', $varchar_field);
  195 + foreach ($fields as $table=>$field) {
204 196 execute_sql("UPDATE {$CFG->prefix}$table SET $field='' WHERE $field IS NULL");
205 197 $ok = $ok && hotpot_db_update_field_type($table, $field, $field, 'VARCHAR', 255, '', 'NOT NULL', '');
206 198 }
@@ -210,19 +202,16 @@ function hotpot_update_to_v2_1_16() {
210 202 $ok = $ok && hotpot_index_remove_prefix('hotpot_attempts', 'userid');
211 203 $ok = $ok && hotpot_index_remove_prefix('hotpot_details', 'attempt');
212 204 $ok = $ok && hotpot_index_remove_prefix('hotpot_questions', 'hotpot');
213   - //$ok = $ok && hotpot_index_remove_prefix('hotpot_questions', 'name', 20);
214 205 $ok = $ok && hotpot_index_remove_prefix('hotpot_responses', 'attempt');
215 206 $ok = $ok && hotpot_index_remove_prefix('hotpot_responses', 'question');
216   - $ok = $ok && hotpot_index_remove_prefix('hotpot_strings', 'string', 20);
217 207 }
218 208 return $ok;
219 209 }
220   -function hotpot_index_remove_prefix($table, $field, $length=0) {
  210 +function hotpot_index_remove_prefix($table, $field) {
221 211 global $CFG;
222   - $index = "{$table}_{$field}_idx";
223   - hotpot_db_delete_index("{$CFG->prefix}$table", "{$CFG->prefix}$index");
224   - hotpot_db_delete_index("{$CFG->prefix}$table", $index);
225   - return hotpot_db_add_index($table, $field, $length);
  212 + hotpot_db_delete_index("{$CFG->prefix}$table", "{$CFG->prefix}{$table}_{$field}_idx");
  213 + hotpot_db_delete_index("{$CFG->prefix}$table", "{$table}_{$field}_idx");
  214 + return hotpot_db_add_index($table, $field);
226 215 }
227 216
228 217 function hotpot_update_to_v2_1_8() {
@@ -261,22 +250,6 @@ function hotpot_update_to_v2_1_6() {
261 250 if (hotpot_db_field_exists($table, 'microreportid') && !hotpot_db_field_exists($table, 'clickreportid')) {
262 251 $ok = $ok && hotpot_db_update_field_type($table, 'microreportid', 'clickreportid', 'INTEGER', 10, 'UNSIGNED', 'NULL');
263 252 }
264   -
265   - // hotpot_questions (add index on question "name")
266   - $table = 'hotpot_questions';
267   - $field = 'name';
268   - $index = "{$table}_{$field}_idx";
269   - if (!hotpot_db_index_exists("{$CFG->prefix}$table", "{$CFG->prefix}$index")) {
270   - hotpot_db_add_index($table, $field, '20');
271   - }
272   -
273   - // hotpot_strings (add index on "string")
274   - $table = "hotpot_strings";
275   - $field = 'string';
276   - $index = "{$table}_{$field}_idx";
277   - if (!hotpot_db_index_exists("{$CFG->prefix}$table", "{$CFG->prefix}$index")) {
278   - hotpot_db_add_index($table, $field, '20');
279   - }
280 253 }
281 254
282 255 return $ok;
@@ -414,11 +387,9 @@ function hotpot_update_to_v2_1() {
414 387 $ok = $ok && hotpot_db_add_index('hotpot_attempts', 'hotpot');
415 388 $ok = $ok && hotpot_db_add_index('hotpot_attempts', 'userid');
416 389 $ok = $ok && hotpot_db_add_index('hotpot_details', 'attempt');
417   - $ok = $ok && hotpot_db_add_index('hotpot_questions', 'name', 20);
418 390 $ok = $ok && hotpot_db_add_index('hotpot_questions', 'hotpot');
419 391 $ok = $ok && hotpot_db_add_index('hotpot_responses', 'attempt');
420 392 $ok = $ok && hotpot_db_add_index('hotpot_responses', 'question');
421   - $ok = $ok && hotpot_db_add_index('hotpot_strings', 'string', 20);
422 393 // hotpot_string: correct double-encoded HTML entities
423 394 $ok = $ok && execute_sql("
424 395 UPDATE {$CFG->prefix}hotpot_strings
@@ -1016,18 +987,10 @@ function hotpot_db_add_index($table, $field, $length='') {
1016 987
1017 988 switch (strtolower($CFG->dbtype)) {
1018 989 case 'mysql' :
1019   - $field = "`$field`";
1020   - if ($length) {
1021   - $field = "$field ($length)";
1022   - }
1023   - $ok = $ok && $db->Execute("ALTER TABLE `$table` ADD INDEX `$index` ($field)");
  990 + $ok = $ok && $db->Execute("ALTER TABLE `$table` ADD INDEX `$index` (`$field`)");
1024 991 break;
1025 992 case 'postgres7' :
1026   - $field = '"'.$field.'"';
1027   - if ($length) {
1028   - $field = "SUBSTR($field,$length)";
1029   - }
1030   - $ok = $ok && $db->Execute("CREATE INDEX $index ON $table ($field)");
  993 + $ok = $ok && $db->Execute("CREATE INDEX $index ON $table (\"$field\")");
1031 994 break;
1032 995 default: // unknown database type
1033 996 $ok = false;

0 comments on commit 85b05f3

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