Merge branch 'MDL-48235-assign-reopen-until-pass' of git://github.com/mpetrowi/moodle
[moodle.git] / mod / assign / locallib.php
index 0c02287..3fb608a 100644 (file)
@@ -1882,20 +1882,14 @@ class assign {
             // Set it to the default.
             $grade->attemptnumber = 0;
         }
-        $result = $DB->update_record('assign_grades', $grade);
+        $DB->update_record('assign_grades', $grade);
 
-        // If the conditions are met, allow another attempt.
         $submission = null;
         if ($this->get_instance()->teamsubmission) {
             $submission = $this->get_group_submission($grade->userid, 0, false);
         } else {
             $submission = $this->get_user_submission($grade->userid, false);
         }
-        if ($submission && $submission->attemptnumber == $grade->attemptnumber) {
-            $this->reopen_submission_if_required($grade->userid,
-                                                 $submission,
-                                                 $reopenattempt);
-        }
 
         // Only push to gradebook if the update is for the latest attempt.
         // Not the latest attempt.
@@ -1903,11 +1897,16 @@ class assign {
             return true;
         }
 
-        if ($result) {
-            $this->gradebook_item_update(null, $grade);
-            \mod_assign\event\submission_graded::create_from_grade($this, $grade)->trigger();
+        $this->gradebook_item_update(null, $grade);
+
+        // If the conditions are met, allow another attempt.
+        if ($submission) {
+            $this->reopen_submission_if_required($grade->userid,
+                    $submission,
+                    $reopenattempt);
         }
-        return $result;
+        \mod_assign\event\submission_graded::create_from_grade($this, $grade)->trigger();
+        return true;
     }
 
     /**
@@ -6631,7 +6630,8 @@ class assign {
             if ($gradeitem) {
                 $gradegrade = grade_grade::fetch(array('userid' => $userid, 'itemid' => $gradeitem->id));
 
-                if ($gradegrade && !$gradegrade->is_passed()) {
+                // Do not reopen if is_passed returns null, e.g. if there is no pass criterion set.
+                if ($gradegrade && ($gradegrade->is_passed() === false)) {
                     $shouldreopen = true;
                 }
             }