From e5b715291d984307625975d1abdbd650015ae0f4 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 13 Nov 2024 10:14:37 +0800 Subject: [PATCH 1/2] MDL-83704 core: Stop loading subplugins files to fetch caps This information is heavily cached in the component class. This should be used wherever possible rather than checking on disk. --- lib/classes/context/module.php | 10 +--------- lib/tests/context/module_test.php | 9 ++++++--- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/classes/context/module.php b/lib/classes/context/module.php index e1db534868f..6322a34cbb9 100644 --- a/lib/classes/context/module.php +++ b/lib/classes/context/module.php @@ -170,15 +170,7 @@ class module extends context { $subcaps = array(); $modulepath = "{$CFG->dirroot}/mod/{$module->name}"; - if (file_exists("{$modulepath}/db/subplugins.json")) { - $subplugins = (array) json_decode(file_get_contents("{$modulepath}/db/subplugins.json"))->plugintypes; - } else if (file_exists("{$modulepath}/db/subplugins.php")) { - debugging('Use of subplugins.php has been deprecated. ' . - 'Please update your plugin to provide a subplugins.json file instead.', - DEBUG_DEVELOPER); - $subplugins = array(); // Should be redefined in the file. - include("{$modulepath}/db/subplugins.php"); - } + $subplugins = \core\component::get_subplugins("mod_{$module->name}"); if (!empty($subplugins)) { foreach (array_keys($subplugins) as $subplugintype) { diff --git a/lib/tests/context/module_test.php b/lib/tests/context/module_test.php index 033d3ea895b..6aadffaa06b 100644 --- a/lib/tests/context/module_test.php +++ b/lib/tests/context/module_test.php @@ -189,13 +189,16 @@ class module_test extends \advanced_testcase { $this->resetAfterTest(); $course = $this->getDataGenerator()->create_course(); - $page = $this->getDataGenerator()->create_module('page', ['course' => $course->id, 'name' => 'Pokus']); - $context = module::instance($page->cmid); + $mod = $this->getDataGenerator()->create_module('book', ['course' => $course->id, 'name' => 'Pokus']); + $context = module::instance($mod->cmid); $capabilities = $context->get_capabilities(); $capabilities = convert_to_array($capabilities); $capabilities = array_column($capabilities, 'name'); - $this->assertContains('mod/page:view', $capabilities); + + $this->assertContains('mod/book:read', $capabilities); + $this->assertContains('booktool/exportimscp:export', $capabilities); + $this->assertContains('booktool/importhtml:import', $capabilities); $this->assertNotContains('mod/url:view', $capabilities); $this->assertNotContains('moodle/course:view', $capabilities); $this->assertNotContains('moodle/category:manage', $capabilities); From 9fe9652c1667f172bed6c4a0744eef668c94d23a Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 13 Nov 2024 10:23:25 +0800 Subject: [PATCH 2/2] MDL-83704 core: Stop loading subplugins files to uninstall The list of subplugin types was loaded from the json/php subplugins file, but then the actual list of subplugins was loaded from the cache in the component, rendering any benefit of using the source json/php as pointless. --- lib/adminlib.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/lib/adminlib.php b/lib/adminlib.php index fb51e34ea3c..426d7046f2c 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -139,17 +139,7 @@ function uninstall_plugin($type, $name) { $subplugintypes = core_component::get_plugin_types_with_subplugins(); if (isset($subplugintypes[$type])) { $base = core_component::get_plugin_directory($type, $name); - - $subpluginsfile = "{$base}/db/subplugins.json"; - if (file_exists($subpluginsfile)) { - $subplugins = (array) json_decode(file_get_contents($subpluginsfile))->plugintypes; - } else if (file_exists("{$base}/db/subplugins.php")) { - debugging('Use of subplugins.php has been deprecated. ' . - 'Please update your plugin to provide a subplugins.json file instead.', - DEBUG_DEVELOPER); - $subplugins = []; - include("{$base}/db/subplugins.php"); - } + $subplugins = \core\component::get_subplugins("{$type}_{$name}"); if (!empty($subplugins)) { foreach (array_keys($subplugins) as $subplugintype) {