From f02c60f567fbf15b6563d7010a84459fab800062 Mon Sep 17 00:00:00 2001 From: Laurent David Date: Mon, 10 Feb 2025 12:38:26 +0100 Subject: [PATCH] MDL-84131 core_analytics: Remove indicator for chat and suvey * When chat and survey are actually not installed, remove them from the course_dropout target indicator. --- lib/db/upgrade.php | 56 ++++++++++++++++++++++++++++++++++------------ version.php | 2 +- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 7d861ec2637..d8e10bdb99c 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1574,20 +1574,6 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2025030600.08); } - // Overall step to remove chat and survey. - if ($oldversion < 2025031100.01) { - if (!file_exists($CFG->dirroot . "/mod/survey/version.php")) { - uninstall_plugin('mod', 'survey'); - $DB->delete_records('adminpresets_plug', ['plugin' => 'mod', 'name' => 'survey']); - } - if (!file_exists($CFG->dirroot . "/mod/chat/version.php")) { - uninstall_plugin('mod', 'chat'); - $DB->delete_records('adminpresets_plug', ['plugin' => 'mod', 'name' => 'chat']); - } - // Main savepoint reached. - upgrade_main_savepoint(true, 2025031100.01); - } - if ($oldversion < 2025031800.00) { // Add index for querying delegated sections. $table = new xmldb_table('course_sections'); @@ -1632,5 +1618,47 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2025031800.04); } + // Remove chat and survey and respective analytics indicators. + if ($oldversion < 2025032800.01) { + $indicatorstoremove = []; + $sqllikes = []; + $sqlparams = []; + + if (!file_exists($CFG->dirroot . "/mod/survey/version.php")) { + uninstall_plugin('mod', 'survey'); + $DB->delete_records('adminpresets_plug', ['plugin' => 'mod', 'name' => 'survey']); + $indicatorstoremove['survey'] = [ + '\mod_survey\analytics\indicator\cognitive_depth', + '\mod_survey\analytics\indicator\social_breadth', + ]; + $sqlparams['surveypluginname'] = '%' . $DB->sql_like_escape('mod_survey') . '%'; + $sqllikes['survey'] = $DB->sql_like('indicators', ':surveypluginname'); + } + if (!file_exists($CFG->dirroot . "/mod/chat/version.php")) { + uninstall_plugin('mod', 'chat'); + $DB->delete_records('adminpresets_plug', ['plugin' => 'mod', 'name' => 'chat']); + $indicatorstoremove['chat'] = [ + '\mod_chat\analytics\indicator\cognitive_depth', + '\mod_chat\analytics\indicator\social_breadth', + ]; + $sqlparams['chatpluginname'] = '%' . $DB->sql_like_escape('mod_chat') . '%'; + $sqllikes['chat'] = $DB->sql_like('indicators', ':chatpluginname'); + } + + foreach ($indicatorstoremove as $module => $indicators) { + $models = $DB->get_recordset_select('analytics_models', $sqllikes[$module], $sqlparams); + foreach ($models as $model) { + $currentindicators = json_decode($model->indicators, true); + if (!empty($indicators) && !empty($currentindicators)) { + $newindicators = array_values(array_diff($currentindicators, $indicators)); + $model->indicators = json_encode($newindicators); + $DB->update_record('analytics_models', $model); + } + } + $models->close(); + } + // Main savepoint reached. + upgrade_main_savepoint(true, 2025032800.01); + } return true; } diff --git a/version.php b/version.php index 7fb431ad347..95773d0d518 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2025032800.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2025032800.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '5.0dev+ (Build: 20250328)'; // Human-friendly version name