|
@ -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; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|