Skip to content

Commit

Permalink
MDL-82359 Install: Allow removal of modules from core analytics models
Browse files Browse the repository at this point in the history
  • Loading branch information
sammarshallou committed Jul 2, 2024
1 parent a48f599 commit 82ecfd3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions analytics/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,27 @@ public static function load_default_models_for_component(string $componentname):
} else {
$model['enabled'] = clean_param($model['enabled'], PARAM_BOOL);
}

// For the core models only, automatically remove references to modules that do not
// exist. This allows you to install without error if there are missing plugins.
if ($componentname === 'moodle') {
$updatedindicators = [];
$allmodules = [];
foreach ($model['indicators'] as $indicator) {
if (preg_match('~^\\\\mod_([^\\\\]+)\\\\~', $indicator, $matches)) {
if (!$allmodules) {
// The first time, get all modules.
$allmodules = \core\plugin_manager::instance()->get_plugins_of_type('mod');
}
if (!array_key_exists($matches[1], $allmodules)) {
// Module does not exist, so skip indicator.
continue;
}
}
$updatedindicators[] = $indicator;
}
$model['indicators'] = $updatedindicators;
}
}

static::validate_models_declaration($models);
Expand Down

0 comments on commit 82ecfd3

Please sign in to comment.