Merge branch 'MDL-61041-master' of git://github.com/damyon/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 1 Aug 2018 14:36:12 +0000 (16:36 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 1 Aug 2018 14:36:12 +0000 (16:36 +0200)
1  2 
lib/db/upgrade.php
version.php

@@@ -2269,29 -2269,12 +2269,37 @@@ function xmldb_main_upgrade($oldversion
      }
  
      if ($oldversion < 2018072500.00) {
 -        upgrade_main_savepoint(true, 2018072500.00);
 +        // Find all duplicate top level categories per context.
 +        $duplicates = $DB->get_records_sql("SELECT qc1.*
 +                                              FROM {question_categories} qc1
 +                                              JOIN {question_categories} qc2
 +                                                ON qc1.contextid = qc2.contextid AND qc1.id <> qc2.id
 +                                             WHERE qc1.parent = 0 AND qc2.parent = 0
 +                                          ORDER BY qc1.contextid, qc1.id");
 +
 +        // For each context, let the first top category to remain as top category and make the rest its children.
 +        $currentcontextid = 0;
 +        $chosentopid = 0;
 +        foreach ($duplicates as $duplicate) {
 +            if ($currentcontextid != $duplicate->contextid) {
 +                $currentcontextid = $duplicate->contextid;
 +                $chosentopid = $duplicate->id;
 +            } else {
 +                $DB->set_field('question_categories', 'parent', $chosentopid, ['id' => $duplicate->id]);
 +            }
 +        }
 +
 +        // Main savepoint reached.
 +        upgrade_main_savepoint(true, 2018072500.00);
 +    }
 +
++    if ($oldversion < 2018073000.00) {
+         // Main savepoint reached.
+         if (!file_exists($CFG->dirroot . '/admin/tool/assignmentupgrade/version.php')) {
+             unset_all_config_for_plugin('tool_assignmentupgrade');
+         }
++        upgrade_main_savepoint(true, 2018073000.00);
+     }
      return true;
  }
diff --cc version.php
@@@ -29,7 -29,7 +29,7 @@@
  
  defined('MOODLE_INTERNAL') || die();
  
- $version  = 2018072700.00;              // YYYYMMDD      = weekly release date of this DEV branch.
 -$version  = 2018072500.00;              // YYYYMMDD      = weekly release date of this DEV branch.
++$version  = 2018073000.00;              // YYYYMMDD      = weekly release date of this DEV branch.
                                          //         RR    = release increments - 00 in DEV branches.
                                          //           .XX = incremental changes.