Merge branch 'MDL-54802-master' of git://github.com/lameze/moodle
authorDan Poltawski <dan@moodle.com>
Mon, 3 Oct 2016 13:46:43 +0000 (14:46 +0100)
committerDan Poltawski <dan@moodle.com>
Mon, 3 Oct 2016 13:46:43 +0000 (14:46 +0100)
1  2 
mod/quiz/db/upgrade.php
mod/quiz/version.php

@@@ -193,32 -193,30 +193,54 @@@ function xmldb_quiz_upgrade($oldversion
      // Moodle v3.1.0 release upgrade line.
      // Put any upgrade step following this.
  
 -    // Moodle v3.2.0 release upgrade line.
 -    // Put any upgrade step following this.
 +    if ($oldversion < 2016092000) {
 +        // Define new fields to be added to quiz.
 +        $table = new xmldb_table('quiz');
 +
 +        $field = new xmldb_field('allowofflineattempts', XMLDB_TYPE_INTEGER, '1', null, null, null, 0, 'completionpass');
 +        // Conditionally launch add field allowofflineattempts.
 +        if (!$dbman->field_exists($table, $field)) {
 +            $dbman->add_field($table, $field);
 +        }
 +        // Quiz savepoint reached.
 +        upgrade_mod_savepoint(true, 2016092000, 'quiz');
 +    }
 +
 +    if ($oldversion < 2016092001) {
 +        // New field for quiz_attemps.
 +        $table = new xmldb_table('quiz_attempts');
 +
 +        $field = new xmldb_field('timemodifiedoffline', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, 0, 'timemodified');
 +        // Conditionally launch add field timemodifiedoffline.
 +        if (!$dbman->field_exists($table, $field)) {
 +            $dbman->add_field($table, $field);
 +        }
 +
 +        // Quiz savepoint reached.
 +        upgrade_mod_savepoint(true, 2016092001, 'quiz');
 +    }
  
 -    if ($oldversion < 2016052301) {
++    if ($oldversion < 2016100300) {
+         // Find quizzes with the combination of require passing grade and grade to pass 0.
+         $quizzes = $DB->get_records_sql("
+             SELECT gi.id, gi.iteminstance
 -                    FROM {quiz} q
++              FROM {quiz} q
+         INNER JOIN {course_modules} cm ON q.id = cm.instance
+         INNER JOIN {grade_items} gi ON q.id = gi.iteminstance
 -                   WHERE q.completionpass = 1
++             WHERE q.completionpass = 1
+                AND gi.gradepass = 0
+                AND cm.completiongradeitemnumber IS NULL");
+         if ($quizzes) {
+             foreach ($quizzes as $quiz) {
+                 $DB->execute("UPDATE {course_modules}
+                                  SET completiongradeitemnumber = :gradeitemid
+                                WHERE instance = :quizid",
+                     array('gradeitemid' => $quiz->id, 'quizid' => $quiz->iteminstance));
+             }
+         }
+         // Quiz savepoint reached.
 -        upgrade_mod_savepoint(true, 2016052301, 'quiz');
++        upgrade_mod_savepoint(true, 2016100300, 'quiz');
+     }
      return true;
  }
@@@ -24,7 -24,7 +24,7 @@@
  
  defined('MOODLE_INTERNAL') || die();
  
- $plugin->version   = 2016092001;
 -$plugin->version   = 2016052301;
++$plugin->version   = 2016100300;
  $plugin->requires  = 2016051900;
  $plugin->component = 'mod_quiz';
  $plugin->cron      = 60;