From 9c0edd12126b159f9045b012e85205d69a267835 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Tue, 23 Apr 2019 01:22:19 +0200 Subject: [PATCH] MDL-65248 analytics: Replace upgrade script to apply for all moves While strictly we don't nedd to provide an upgrade path for master, any dev/integration site already using some of the 3.7 new tagets in models will break (class rename/move) if we don't perform the update of all them. This commit takes rid of the previous upgrade step, only performing the update of a couple of targets and now supports all the (5) targets: - course_dropout - course_competencies - course_completion - course_gradetopass - no_teaching --- lib/db/upgrade.php | 29 ++++++++++++----------------- version.php | 2 +- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 0999e3ce272..d3b002820f3 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -3184,28 +3184,23 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2019041800.01); } - if ($oldversion < 2019041900.00) { - - $params = [ - 'target' => '\core\analytics\target\no_teaching', + if ($oldversion < 2019042000.00) { + + // 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', ]; - $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); + foreach ($targets as $oldclass => $newclass) { + $DB->set_field('analytics_models', 'target', $newclass, ['target' => $oldclass]); } // Main savepoint reached. - upgrade_main_savepoint(true, 2019041900.00); + upgrade_main_savepoint(true, 2019042000.00); } return true; diff --git a/version.php b/version.php index b3d5697d7bf..7d65d3b8fc8 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2019041900.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2019042000.00; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. -- 2.43.0