Skip to content

Commit

Permalink
MDL-80337 availability: more robust checking for plugin class presence.
Browse files Browse the repository at this point in the history
Co-authored-by: Dustin Brisebois <dustin.brisebois@lambdasolutions.net>
  • Loading branch information
paulholden and dustinbrisebois committed Jun 25, 2024
1 parent ad7fc69 commit 38ee489
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions availability/classes/frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public static function include_all_javascript($course, \cm_info $cm = null,
foreach ($enabled as $plugin => $info) {
// Create plugin front-end object.
$class = '\availability_' . $plugin . '\frontend';
if (!class_exists($class)) {
continue;
}

/** @var \core_availability\frontend $frontend */
$frontend = new $class();

// Add to array of required YUI modules.
Expand Down
5 changes: 2 additions & 3 deletions availability/classes/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,11 +792,10 @@ public static function completion_value_used($course, $cmid) {
// plugin could also rely on the completion plugin.
$pluginmanager = \core_plugin_manager::instance();
$enabled = $pluginmanager->get_enabled_plugins('availability');
$componentparams = new \stdClass();
foreach ($enabled as $plugin => $info) {
// Use the static method.
/** @var \core_availability\condition $class */
$class = '\availability_' . $plugin . '\condition';
if ($class::completion_value_used($course, $cmid)) {
if (class_exists($class) && $class::completion_value_used($course, $cmid)) {
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions availability/classes/tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ public function __construct($structure, $lax = false, $root = true) {

// First see if it's a condition. These have a defined type.
if (isset($child->type)) {
// Look for a plugin of this type.
/** @var \core_availability\condition $classname */
$classname = '\availability_' . $child->type . '\condition';
if (!array_key_exists($child->type, $enabled)) {
if (!array_key_exists($child->type, $enabled) || !class_exists($classname)) {
if ($lax) {
// On load of existing settings, ignore if class
// doesn't exist.
Expand Down

0 comments on commit 38ee489

Please sign in to comment.