Skip to content

MDL-83766 mod_bigbluebuttonbn: for compatibility with MDL-84799 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: MDL-83766
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions mod/bigbluebuttonbn/classes/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use mod_bigbluebuttonbn\local\extension\mod_instance_helper;
use stdClass;
use core_plugin_manager;
use core_component;

/**
* Generic subplugin management helper
Expand Down Expand Up @@ -80,8 +81,7 @@ public static function action_url_addons(
*/
protected static function get_instances_implementing(string $classname, ?array $newparameters = []): array {
$classes = self::get_classes_implementing($classname);
sort($classes); // Make sure all extension classes are returned in the same order. This is arbitrarily in
// alphabetical order and depends on the classname but this one way to ensure consistency across calls.
ksort($classes); // Make sure all extension classes are returned in the correct order.
return array_map(function($targetclassname) use ($newparameters) {
// If $newparameters is null, the constructor will be called without parameters.
return new $targetclassname(...$newparameters);
Expand All @@ -100,6 +100,8 @@ protected static function get_classes_implementing(string $classname): array {
$classbasename = end($classnamecomponents);
$allsubs = core_plugin_manager::instance()->get_plugins_of_type(self::BBB_EXTENSION_PLUGIN_NAME);
$extensionclasses = [];
$sortedlist = self::get_sorted_plugins_list();
$sortedlist = array_flip($sortedlist);
foreach ($allsubs as $sub) {
if (!$sub->is_enabled()) {
continue;
Expand All @@ -112,11 +114,41 @@ protected static function get_classes_implementing(string $classname): array {
debugging("The class $targetclassname should extend $classname in the subplugin {$sub->name}. Ignoring.");
continue;
}
$extensionclasses[] = $targetclassname;
if (!isset($sortedlist[$sub->name])) {
debugging("The class $targetclassname does not belong to an existing subplugin. Ignoring");
continue;
}
// Return all extension classes based on subplugin order on manage extension page.
$sortorder = $sortedlist[$sub->name];
$extensionclasses[$sortorder] = $targetclassname;
}
return $extensionclasses;
}

/**
* Return plugin list sorted according to order from admin extension manager.
* @return array The sorted list of plugins
*/
public static function get_sorted_plugins_list(): array {
// Get all subplugins of bigbluebuttonbn.
$extensionnames = \core_component::get_plugin_list(self::BBB_EXTENSION_PLUGIN_NAME);

// Sort the plugins according to the sortorder.
$result = [];
foreach ($names as $name => $path) {
$idx = get_config(self::BBB_EXTENSION_PLUGIN_NAME . '_' . $name, 'sortorder');
if (!$idx) {
$idx = 0;
}
while (array_key_exists($idx, $result)) {
$idx += 1;
}
$result[$idx] = $name;
}
ksort($result);
return $result;
}

/**
* Get all custom_completion addons classes.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,7 @@ private function print_header(): void {
* @return array The list of plugins
*/
public function get_sorted_plugins_list(): array {
$names = core_component::get_plugin_list(extension::BBB_EXTENSION_PLUGIN_NAME);

$result = [];

foreach ($names as $name => $path) {
$idx = get_config(extension::BBB_EXTENSION_PLUGIN_NAME . '_' . $name, 'sortorder');
if (!$idx) {
$idx = 0;
}
while (array_key_exists($idx, $result)) {
$idx += 1;
}
$result[$idx] = $name;
}
ksort($result);

return $result;
return extension::get_sorted_plugins_list();
}

/**
Expand Down
47 changes: 47 additions & 0 deletions mod/bigbluebuttonbn/tests/local/extension_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,53 @@ public static function classes_implementing_class(): array {
];
}

/**
* Test the get_sorted_plugins_list
* @param array $sortorders
* @param array $expected
* @return void
* @dataProvider sorted_plugins_list_data_provider
* @covers \mod_bigbluebuttonbn\extension::get_sorted_plugins_list
*/
public function test_get_sorted_plugins_list(array $sortorders, array $expected): void {
$this->resetAfterTest();
// Enable plugin.
$this->enable_plugins(true);
// Create list of plugins we will then sort.
$pluginlist = [
'simpleone' => '/path/to/simpleone',
'simpletwo' => '/path/to/simpletwo',
];
// Set sortorder.
foreach ($sortorders as $plugin => $sortorder) {
set_config('sortorder', $sortorder, 'bbbext_' . $plugin);
}
$sortedlist = extension::get_sorted_plugins_list($pluginlist);
$this->assertSame($expected, $sortedlist);
}

/**
* Data provider for testing get_sorted_plugins_list
*
* @return array[]
*/
public static function sorted_plugins_list_data_provider(): array {
return [
'no sortorder' => [
[],
['simpleone', 'simpletwo'],
],
'default sortorder' => [
['simpleone' => 0, 'simpletwo' => 1],
['simpleone', 'simpletwo'],
],
'changed sortorder' => [
['simpleone' => 1, 'simpletwo' => 0],
['simpletwo', 'simpleone'],
],
];
}

/**
* Enable plugins
*
Expand Down