MDL-7218 workshop: remove orphaned assessments on upgrade

This commit is contained in:
David Mudrak
2009-11-12 15:47:08 +00:00
parent 7f6c2d125d
commit 94e4101a68
2 changed files with 21 additions and 26 deletions
+20 -25
View File
@@ -1,36 +1,31 @@
<?php //$Id$
// This file keeps track of upgrades to
// the workshop module
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installtion to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// The commands in here will all be database-neutral,
// using the functions defined in lib/ddllib.php
<?php
/**
* Performs upgrade of the database structure and data
*
* @param int $oldversion the version we are upgrading from
* @return bool result
*/
function xmldb_workshop_upgrade($oldversion=0) {
global $CFG, $THEME, $db;
$result = true;
/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.
//===== 1.9.0 upgrade line ======//
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of "/lib/ddllib.php" function calls
/// }
if ($result && $oldversion < 2007101510) {
$orphans = get_records_sql("SELECT wa.id
FROM {$CFG->prefix}workshop_assessments wa
LEFT JOIN {$CFG->prefix}workshop_submissions ws ON wa.submissionid = ws.id
WHERE ws.id IS NULL");
if (!empty($orphans)) {
notify('Orphaned assessment records found - cleaning...');
foreach (array_keys($orphans) as $waid) {
$result = $result && delete_records('workshop_assessments', 'id', $waid);
}
}
}
return $result;
}
+1 -1
View File
@@ -5,7 +5,7 @@
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
$module->version = 2007101509;
$module->version = 2007101510;
$module->requires = 2007101509; // Requires this Moodle version
$module->cron = 60;