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. 87
      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 = (object)$data;
$data->id = $this->get_new_parentid('game'); $data->id = $this->get_new_parentid('game');
if( $data->id == 0)
return;
$DB->insert_record('game_export_html', $data); $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 = (object)$data;
$data->id = $this->get_new_parentid('game'); $data->id = $this->get_new_parentid('game');
if( $data->id == 0)
return;
$DB->insert_record('game_export_javame', $data); $DB->insert_record('game_export_javame', $data);
} }

87
lib.php

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

4
version.php

@ -22,10 +22,10 @@ if( !isset( $plugin))
$useplugin = 2; $useplugin = 2;
$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 = 2014122801; // The current module version (Date: YYYYMMDDXX) $plugin->version = 2014122901; // 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 = '3.24.28'; $plugin->release = '3.24.29';
if( $useplugin != 2) if( $useplugin != 2)
$module = $plugin; $module = $plugin;

Loading…
Cancel
Save