Permalink
Browse files

MDL-7218 workshop: remove orphaned assessments on upgrade

  • Loading branch information...
1 parent 7f6c2d1 commit 94e4101a689c75a58fdc5a4113d5d59df69df652 @mudrd8mz mudrd8mz committed Nov 12, 2009
Showing with 23 additions and 28 deletions.
  1. +22 −27 mod/workshop/db/upgrade.php
  2. +1 −1 mod/workshop/version.php
@@ -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.
-
-/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
-/// $result = result of "/lib/ddllib.php" function calls
-/// }
+ //===== 1.9.0 upgrade line ======//
+
+ 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;
}
View
@@ -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;

0 comments on commit 94e4101

Please sign in to comment.