MDL-40095 SCORM: Fixed DML error when saving with completion options locked
authorMatteo Scaramuccia <moodle@matteoscaramuccia.com>
Sun, 9 Jun 2013 13:21:35 +0000 (15:21 +0200)
committerMatteo Scaramuccia <moodle@matteoscaramuccia.com>
Mon, 10 Jun 2013 19:10:07 +0000 (21:10 +0200)
Regression caused by MDL-38315.

mod/scorm/mod_form.php

index e3ffb34..b97d29e 100644 (file)
@@ -499,18 +499,22 @@ class mod_scorm_mod_form extends moodleform_mod {
             return false;
         }
 
+        // Convert completionstatusrequired to a proper integer, if any.
+        $total = 0;
+        if (isset($data->completionstatusrequired) && is_array($data->completionstatusrequired)) {
+            foreach (array_keys($data->completionstatusrequired) as $state) {
+                $total |= $state;
+            }
+            $data->completionstatusrequired = $total;
+        }
+
         if (!empty($data->completionunlocked)) {
-            // Turn off completion settings if the checkboxes aren't ticked
+            // Turn off completion settings if the checkboxes aren't ticked.
             $autocompletion = isset($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
 
-            if (isset($data->completionstatusrequired) &&
-                    is_array($data->completionstatusrequired) && $autocompletion) {
-                $total = 0;
-                foreach (array_keys($data->completionstatusrequired) as $state) {
-                    $total |= $state;
-                }
-
-                $data->completionstatusrequired = $total;
+            if (isset($data->completionstatusrequired) && $autocompletion) {
+                // Do nothing: completionstatusrequired has been already converted
+                //             into a correct integer representation.
             } else {
                 $data->completionstatusrequired = null;
             }