Browse Source

Change name of game_snakes_databases.cols to usedcols

MOODLE_20_STABLE
bdaloukas 8 years ago
parent
commit
c8f99fa305
  1. 3
      CHANGES.md
  2. 44
      db/upgrade.php
  3. 2
      version.php

3
CHANGES.md

@ -1,3 +1,6 @@
Changes in version 2017-06-20 (20170620)
- Fix conversation of columns (cols,rows) from string to int
Changes in version 2017-06-19 (20170619) Changes in version 2017-06-19 (20170619)
- Change field name game_snakes_database.cols => usedcols - Change field name game_snakes_database.cols => usedcols
- Change field name game_snakes_database.rows => usedrows - Change field name game_snakes_database.rows => usedrows

44
db/upgrade.php

@ -41,6 +41,29 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
/**
* Copies a string field to int field
*
* @param int $oldversion
*/
function mpgame_db_copy_string_to_int( $table, $from, $to) {
global $CFG, $DB;
$sql = "SELECT id,$from,$to FROM {$CFG->prefix}$table";
$recs = $DB->get_records_sql( $sql);
foreach ($recs as $rec) {
$val = intval( $rec->$from);
if ($rec->$to == $val) {
continue;
}
$updrec = new stdClass;
$updrec->id = $rec->id;
$updrec->$to = $val;
$DB->update_record( $table, $updrec);
}
}
/** /**
* Upgrades database * Upgrades database
* *
@ -1556,7 +1579,7 @@ function xmldb_game_upgrade($oldversion) {
$dbman->change_field_type($table, $field); $dbman->change_field_type($table, $field);
} }
if ($oldversion < ($ver = 2017061604)) { if ($oldversion < ($ver = 2017062002)) {
$table = new xmldb_table('game_cross'); $table = new xmldb_table('game_cross');
$field = new xmldb_field('usedrows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); $field = new xmldb_field('usedrows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id');
if (!$dbman->field_exists($table, $field)) { if (!$dbman->field_exists($table, $field)) {
@ -1565,15 +1588,14 @@ function xmldb_game_upgrade($oldversion) {
$field = new xmldb_field('rows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); $field = new xmldb_field('rows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id');
if ($dbman->field_exists($table, $field)) { if ($dbman->field_exists($table, $field)) {
$sql = "UPDATE {$CFG->prefix}game_cross SET usedrows=rows"; mpgame_db_copy_string_to_int( 'game_cross', 'rows', 'usedrows');
$DB->execute( $sql);
$dbman->drop_field($table, $field); $dbman->drop_field($table, $field);
} else { } else {
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
} }
} }
if ($oldversion < ($ver = 2017061604)) { if ($oldversion < ($ver = 2017062002)) {
$table = new xmldb_table('game_cross'); $table = new xmldb_table('game_cross');
$field = new xmldb_field('usedcols', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); $field = new xmldb_field('usedcols', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id');
if (!$dbman->field_exists($table, $field)) { if (!$dbman->field_exists($table, $field)) {
@ -1582,15 +1604,14 @@ function xmldb_game_upgrade($oldversion) {
$field = new xmldb_field('cols', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); $field = new xmldb_field('cols', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id');
if ($dbman->field_exists($table, $field)) { if ($dbman->field_exists($table, $field)) {
$sql = "UPDATE {$CFG->prefix}game_cross SET usedcols=cols"; mpgame_db_copy_string_to_int( 'game_cross', 'cols', 'usedcols');
$DB->execute( $sql);
$dbman->drop_field($table, $field); $dbman->drop_field($table, $field);
} else { } else {
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
} }
} }
if ($oldversion < ($ver = 2017061901)) { if ($oldversion < ($ver = 2017062002)) {
$table = new xmldb_table('game_snakes_database'); $table = new xmldb_table('game_snakes_database');
$field = new xmldb_field('usedrows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); $field = new xmldb_field('usedrows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id');
if (!$dbman->field_exists($table, $field)) { if (!$dbman->field_exists($table, $field)) {
@ -1599,15 +1620,14 @@ function xmldb_game_upgrade($oldversion) {
$field = new xmldb_field('rows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); $field = new xmldb_field('rows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id');
if ($dbman->field_exists($table, $field)) { if ($dbman->field_exists($table, $field)) {
$sql = "UPDATE {$CFG->prefix}game_snakes_database SET usedrows=rows"; mpgame_db_copy_string_to_int( 'game_snakes_database', 'rows', 'usedrows');
$DB->execute( $sql);
$dbman->drop_field($table, $field); $dbman->drop_field($table, $field);
} else { } else {
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
} }
} }
if ($oldversion < ($ver = 2017061901)) { if ($oldversion < ($ver = 2017062002)) {
$table = new xmldb_table('game_snakes_database'); $table = new xmldb_table('game_snakes_database');
$field = new xmldb_field('usedcols', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); $field = new xmldb_field('usedcols', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id');
if (!$dbman->field_exists($table, $field)) { if (!$dbman->field_exists($table, $field)) {
@ -1616,8 +1636,7 @@ function xmldb_game_upgrade($oldversion) {
$field = new xmldb_field('cols', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); $field = new xmldb_field('cols', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id');
if ($dbman->field_exists($table, $field)) { if ($dbman->field_exists($table, $field)) {
$sql = "UPDATE {$CFG->prefix}game_snakes_database SET usedcols=cols"; mpgame_db_copy_string_to_int( 'game_snakes_database', 'cols', 'usedcols');
$DB->execute( $sql);
$dbman->drop_field($table, $field); $dbman->drop_field($table, $field);
} else { } else {
$dbman->add_field($table, $field); $dbman->add_field($table, $field);
@ -1626,3 +1645,4 @@ function xmldb_game_upgrade($oldversion) {
return true; return true;
} }

2
version.php

@ -35,7 +35,7 @@ if (!isset( $plugin)) {
} }
$plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics). $plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics).
$plugin->version = 2017061901; // The current module version (Date: YYYYMMDDXX). $plugin->version = 2017062002; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2010112400; // Requires Moodle 2.0. $plugin->requires = 2010112400; // Requires Moodle 2.0.
$plugin->cron = 0; // Period for cron to check this module (secs). $plugin->cron = 0; // Period for cron to check this module (secs).
$plugin->release = '2017-06-19'; $plugin->release = '2017-06-19';

Loading…
Cancel
Save