MDL-36914: Assignment upgrade. Clean up patch to include outcomes in the upgrade
authorDamyon Wiese <damyon@moodle.com>
Thu, 29 Nov 2012 08:07:20 +0000 (16:07 +0800)
committerDamyon Wiese <damyon@moodle.com>
Thu, 29 Nov 2012 08:11:04 +0000 (16:11 +0800)
Thanks to Nathan Mares for reporting this issue.

mod/assign/upgradelib.php

index 344cea5..8e7df84 100644 (file)
@@ -229,9 +229,11 @@ class assign_upgrade_manager {
 
             $newassignment->update_calendar($newcoursemodule->id);
 
-            // reassociate grade_items from the old assignment instance to the new assign instance. This includes outcome linked grade_items
-            $sql = "UPDATE {grade_items} SET itemmodule = 'assign', iteminstance = ? WHERE itemmodule = 'assignment' AND iteminstance = ?";
-            $DB->execute($sql, array($newassignment->get_instance()->id, $oldassignment->id));
+            // Reassociate grade_items from the old assignment instance to the new assign instance.
+            // This includes outcome linked grade_items.
+            $params = array('assign', $newassignment->get_instance()->id, 'assignment', $oldassignment->id);
+            $sql = 'UPDATE {grade_items} SET itemmodule = ?, iteminstance = ? WHERE itemmodule = ? AND iteminstance = ?';
+            $DB->execute($sql, $params);
 
             $gradesdone = true;
 
@@ -243,9 +245,10 @@ class assign_upgrade_manager {
         if ($rollback) {
             // roll back the grades changes
             if ($gradesdone) {
-                // reassociate grade_items from the new assign instance to the old assignment instance
-                $sql = "UPDATE {grade_items} SET itemmodule = 'assign', iteminstance = ? WHERE itemmodule = 'assignment' AND iteminstance = ?";
-                $DB->execute($sql, array($oldassignment->id, $newassignment->get_instance()->id));
+                // Reassociate grade_items from the new assign instance to the old assignment instance.
+                $params = array('assignment', $oldassignment->id, 'assign', $newassignment->get_instance()->id);
+                $sql = 'UPDATE {grade_items} SET itemmodule = ?, iteminstance = ? WHERE itemmodule = ? AND iteminstance = ?';
+                $DB->execute($sql, $params);
             }
             // roll back the completion changes
             if ($completiondone) {