MDL-61605 quiz report: add missing index/key
authorTim Hunt <T.J.Hunt@open.ac.uk>
Sun, 18 Mar 2018 20:40:43 +0000 (20:40 +0000)
committerTim Hunt <T.J.Hunt@open.ac.uk>
Sun, 18 Mar 2018 20:40:43 +0000 (20:40 +0000)
Thanks to Patryk Szuta for the suggestion

mod/quiz/report/overview/db/install.xml
mod/quiz/report/overview/db/upgrade.php
mod/quiz/report/overview/version.php

index 28ab2be..6eb80f6 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="mod/quiz/report/overview/db" VERSION="20120122" COMMENT="XMLDB file for Moodle mod/quiz/report/overview"
+<XMLDB PATH="mod/quiz/report/overview/db" VERSION="20180319" COMMENT="XMLDB file for Moodle mod/quiz/report/overview"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../../../../lib/xmldb/xmldb.xsd"
 >
@@ -16,6 +16,7 @@
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+        <KEY NAME="questionusageid-slot" TYPE="foreign-unique" FIELDS="questionusageid, slot" REFTABLE="question_attempts" REFFIELDS="questionusageid, slot"/>
       </KEYS>
     </TABLE>
   </TABLES>
index 0ea300d..6a50540 100644 (file)
@@ -29,7 +29,9 @@ defined('MOODLE_INTERNAL') || die();
  * @param number $oldversion
  */
 function xmldb_quiz_overview_upgrade($oldversion) {
-    global $CFG;
+    global $DB;
+
+    $dbman = $DB->get_manager();
 
     // Automatically generated Moodle v3.2.0 release upgrade line.
     // Put any upgrade step following this.
@@ -40,5 +42,18 @@ function xmldb_quiz_overview_upgrade($oldversion) {
     // Automatically generated Moodle v3.4.0 release upgrade line.
     // Put any upgrade step following this.
 
+    if ($oldversion < 2018021800) {
+
+        // Define key questionusageid-slot (foreign-unique) to be added to quiz_overview_regrades.
+        $table = new xmldb_table('quiz_overview_regrades');
+        $key = new xmldb_key('questionusageid-slot', XMLDB_KEY_FOREIGN_UNIQUE, array('questionusageid', 'slot'), 'question_attempts', array('questionusageid', 'slot'));
+
+        // Launch add key questionusageid-slot.
+        $dbman->add_key($table, $key);
+
+        // Overview savepoint reached.
+        upgrade_plugin_savepoint(true, 2018021800, 'quiz', 'overview');
+    }
+
     return true;
 }
index 47cbc55..7bb9bab 100644 (file)
@@ -24,6 +24,6 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version  = 2017111300;
+$plugin->version  = 2018021800;
 $plugin->requires = 2017110800;
 $plugin->component = 'quiz_overview';