Merge branch 'MDL-65248' of git://github.com/stronk7/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 23 Apr 2019 11:56:06 +0000 (13:56 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 23 Apr 2019 11:56:06 +0000 (13:56 +0200)
1  2 
lib/db/upgrade.php
version.php

@@@ -3184,43 -3184,24 +3184,38 @@@ function xmldb_main_upgrade($oldversion
          upgrade_main_savepoint(true, 2019041800.01);
      }
  
-     if ($oldversion < 2019041900.00) {
-         $params = [
-             'target' => '\core\analytics\target\no_teaching',
-         ];
-         $models = $DB->get_records('analytics_models', $params);
-         foreach ($models as $model) {
-             $model->target = '\core_course\analytics\target\no_teaching';
-             $DB->update_record('analytics_models', $model);
-         }
-         $params = [
-             'target' => '\core\analytics\target\course_dropout',
-         ];
-         $models = $DB->get_records('analytics_models', $params);
-         foreach ($models as $model) {
-             $model->target = '\core_course\analytics\target\course_dropout';
-             $DB->update_record('analytics_models', $model);
-         }
-         // Main savepoint reached.
-         upgrade_main_savepoint(true, 2019041900.00);
-     }
 -    if ($oldversion < 2019042000.00) {
 +    if ($oldversion < 2019042200.01) {
 +
 +        // Define table role_sortorder to be dropped.
 +        $table = new xmldb_table('role_sortorder');
 +
 +        // Conditionally launch drop table for role_sortorder.
 +        if ($dbman->table_exists($table)) {
 +            $dbman->drop_table($table);
 +        }
 +
 +        // Main savepoint reached.
 +        upgrade_main_savepoint(true, 2019042200.01);
 +    }
 +
++    if ($oldversion < 2019042200.02) {
+         // Let's update all (old core) targets to their new (core_course) locations.
+         $targets = [
+             '\core\analytics\target\course_competencies' => '\core_course\analytics\target\course_competencies',
+             '\core\analytics\target\course_completion' => '\core_course\analytics\target\course_completion',
+             '\core\analytics\target\course_dropout' => '\core_course\analytics\target\course_dropout',
+             '\core\analytics\target\course_gradetopass' => '\core_course\analytics\target\course_gradetopass',
+             '\core\analytics\target\no_teaching' => '\core_course\analytics\target\no_teaching',
+         ];
+         foreach ($targets as $oldclass => $newclass) {
+             $DB->set_field('analytics_models', 'target', $newclass, ['target' => $oldclass]);
+         }
+         // Main savepoint reached.
 -        upgrade_main_savepoint(true, 2019042000.00);
++        upgrade_main_savepoint(true, 2019042200.02);
+     }
      return true;
  }
diff --cc version.php
@@@ -29,7 -29,7 +29,7 @@@
  
  defined('MOODLE_INTERNAL') || die();
  
- $version  = 2019042200.01;              // YYYYMMDD      = weekly release date of this DEV branch.
 -$version  = 2019042000.00;              // YYYYMMDD      = weekly release date of this DEV branch.
++$version  = 2019042200.02;              // YYYYMMDD      = weekly release date of this DEV branch.
                                          //         RR    = release increments - 00 in DEV branches.
                                          //           .XX = incremental changes.