|
|
@ -41,6 +41,29 @@ |
|
|
|
|
|
|
|
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 |
|
|
|
* |
|
|
@ -1556,7 +1579,7 @@ function xmldb_game_upgrade($oldversion) { |
|
|
|
$dbman->change_field_type($table, $field); |
|
|
|
} |
|
|
|
|
|
|
|
if ($oldversion < ($ver = 2017061604)) { |
|
|
|
if ($oldversion < ($ver = 2017062002)) { |
|
|
|
$table = new xmldb_table('game_cross'); |
|
|
|
$field = new xmldb_field('usedrows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); |
|
|
|
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'); |
|
|
|
if ($dbman->field_exists($table, $field)) { |
|
|
|
$sql = "UPDATE {$CFG->prefix}game_cross SET usedrows=rows"; |
|
|
|
$DB->execute( $sql); |
|
|
|
mpgame_db_copy_string_to_int( 'game_cross', 'rows', 'usedrows'); |
|
|
|
$dbman->drop_field($table, $field); |
|
|
|
} else { |
|
|
|
$dbman->add_field($table, $field); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ($oldversion < ($ver = 2017061604)) { |
|
|
|
if ($oldversion < ($ver = 2017062002)) { |
|
|
|
$table = new xmldb_table('game_cross'); |
|
|
|
$field = new xmldb_field('usedcols', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); |
|
|
|
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'); |
|
|
|
if ($dbman->field_exists($table, $field)) { |
|
|
|
$sql = "UPDATE {$CFG->prefix}game_cross SET usedcols=cols"; |
|
|
|
$DB->execute( $sql); |
|
|
|
mpgame_db_copy_string_to_int( 'game_cross', 'cols', 'usedcols'); |
|
|
|
$dbman->drop_field($table, $field); |
|
|
|
} else { |
|
|
|
$dbman->add_field($table, $field); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ($oldversion < ($ver = 2017061901)) { |
|
|
|
if ($oldversion < ($ver = 2017062002)) { |
|
|
|
$table = new xmldb_table('game_snakes_database'); |
|
|
|
$field = new xmldb_field('usedrows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); |
|
|
|
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'); |
|
|
|
if ($dbman->field_exists($table, $field)) { |
|
|
|
$sql = "UPDATE {$CFG->prefix}game_snakes_database SET usedrows=rows"; |
|
|
|
$DB->execute( $sql); |
|
|
|
mpgame_db_copy_string_to_int( 'game_snakes_database', 'rows', 'usedrows'); |
|
|
|
$dbman->drop_field($table, $field); |
|
|
|
} else { |
|
|
|
$dbman->add_field($table, $field); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ($oldversion < ($ver = 2017061901)) { |
|
|
|
if ($oldversion < ($ver = 2017062002)) { |
|
|
|
$table = new xmldb_table('game_snakes_database'); |
|
|
|
$field = new xmldb_field('usedcols', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id'); |
|
|
|
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'); |
|
|
|
if ($dbman->field_exists($table, $field)) { |
|
|
|
$sql = "UPDATE {$CFG->prefix}game_snakes_database SET usedcols=cols"; |
|
|
|
$DB->execute( $sql); |
|
|
|
mpgame_db_copy_string_to_int( 'game_snakes_database', 'cols', 'usedcols'); |
|
|
|
$dbman->drop_field($table, $field); |
|
|
|
} else { |
|
|
|
$dbman->add_field($table, $field); |
|
|
@ -1626,3 +1645,4 @@ function xmldb_game_upgrade($oldversion) { |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|