Browse Source

Fix:Problem on deletion of a game and restore a course

MOODLE_20_STABLE
Vasilis Daloukas 10 years ago
parent
commit
2ae9e83f7c
  1. 4
      backup/moodle2/restore_game_stepslib.php
  2. 85
      lib.php
  3. 4
      version.php

4
backup/moodle2/restore_game_stepslib.php

@ -80,6 +80,8 @@ class restore_game_activity_structure_step extends restore_activity_structure_st
$data = (object)$data;
$data->id = $this->get_new_parentid('game');
if( $data->id == 0)
return;
$DB->insert_record('game_export_html', $data);
}
@ -90,6 +92,8 @@ class restore_game_activity_structure_step extends restore_activity_structure_st
$data = (object)$data;
$data->id = $this->get_new_parentid('game');
if( $data->id == 0)
return;
$DB->insert_record('game_export_javame', $data);
}

85
lib.php

@ -189,60 +189,53 @@ function game_before_add_or_update(&$game) {
function game_delete_instance($gameid) {
global $DB;
$result = true;
# Delete any dependent records here #
if( ($recs = $DB->get_records( 'game_attempts', array( 'gameid' => $gameid))) != false){
$ids = '';
$count = 0;
$aids = array();
foreach( $recs as $rec){
$ids .= ','.$rec->id;
if( ++$count > 10){
$count = 0;
$aids[] = $ids;
$ids = '';
}
}
if( $ids != ''){
$aids[] = $ids;
}
foreach( $aids as $ids){
if( $result == false){
break;
}
$tables = array( 'game_hangman', 'game_cross', 'game_cryptex', 'game_millionaire', 'game_bookquiz', 'game_sudoku', 'game_snakes');
foreach( $tables as $t){
$sql = "DELETE FROM {".$t."} WHERE id IN (".substr( $ids, 1).')';
if (! $DB->execute( $sql)) {
$result = false;
break;
}
}
}
$aids = array();
if( ($recs = $DB->get_records( 'game_attempts', array( 'gameid' => $gameid))) != false)
{
$ids = '';
$count = 0;
foreach( $recs as $rec)
{
$ids .= ( $ids == '' ? $rec->id : ','.$rec->id);
if( ++$count > 10)
{
$aids[] = $ids;
$count = 0;
$ids = '';
}
}
if( $ids != '')
$aids[] = $ids;
}
foreach( $aids as $ids)
{
$tables = array( 'game_hangman', 'game_cross', 'game_cryptex', 'game_millionaire', 'game_bookquiz', 'game_sudoku', 'game_snakes');
foreach( $tables as $t)
{
$sql = "DELETE FROM {".$t."} WHERE id IN (".$ids.')';
if (! $DB->execute( $sql))
return false;
}
}
$tables = array( 'game_attempts', 'game_grades', 'game_bookquiz_questions', 'game_queries', 'game_repetitions');
foreach( $tables as $t){
if( $result == false){
break;
}
if (! $DB->delete_records( $t, array( 'gameid' => $gameid))) {
$result = false;
}
}
foreach( $tables as $t)
{
if (! $DB->delete_records( $t, array( 'gameid' => $gameid)))
return false;
}
if( $result){
$tables = array( 'game_export_javame', 'game_export_html', 'game');
if (!$DB->delete_records( 'game', array( 'id' => $gameid))) {
$result = false;
}
$tables = array( 'game_export_javame', 'game_export_html', 'game');
foreach( $tables as $table)
{
if (!$DB->delete_records( $table, array( 'id' => $gameid)))
return false;
}
return $result;
return true;
}
/**

4
version.php

@ -22,10 +22,10 @@ if( !isset( $plugin))
$useplugin = 2;
$plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics)
$plugin->version = 2014122801; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2014122901; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2010112400; // Requires Moodle 2.0
$plugin->cron = 0; // Period for cron to check this module (secs)
$plugin->release = '3.24.28';
$plugin->release = '3.24.29';
if( $useplugin != 2)
$module = $plugin;

Loading…
Cancel
Save