Skip to content

Commit

Permalink
PM-42468 fixed visibility update function
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-kialo committed Sep 8, 2023
1 parent 5cbb73e commit 778385f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
9 changes: 5 additions & 4 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use core\plugininfo\mod;

/**
* Return if the plugin supports $feature.
*
Expand Down Expand Up @@ -153,11 +151,14 @@ function kialo_update_visibility_depending_on_accepted_terms(): void {

$visible = get_config('mod_kialo', 'acceptterms') ? 1 : 0;

if (function_exists('mod::enable_plugin')) {
if (class_exists('core\plugininfo\mod') && method_exists('core\plugininfo\mod', 'enable_plugin')) {
// Moodle 4.0+.
mod::enable_plugin("kialo", $visible);
\core\plugininfo\mod::enable_plugin("kialo", $visible);
} else {
// Moodle 3.9 and older.
$DB->set_field('modules', 'visible', $visible, ['name' => 'kialo']);

// Ensure that the plugin status (Enabled/Disabled) is updated correctly in Plugins overview.
\core_plugin_manager::instance()->reset_caches();
}
}
4 changes: 4 additions & 0 deletions tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ public function test_enable_module_when_terms_have_been_accepted(): void {
set_config('acceptterms', true, 'mod_kialo');
kialo_update_visibility_depending_on_accepted_terms();
$this->assertEquals(1, $DB->get_field('modules', 'visible', ['name' => 'kialo']));

$this->assertContains('kialo', \core_plugin_manager::instance()->get_enabled_plugins('mod'));
}

/**
Expand All @@ -216,5 +218,7 @@ public function test_disable_module_when_terms_have_not_been_accepted(): void {
set_config('acceptterms', false, 'mod_kialo');
kialo_update_visibility_depending_on_accepted_terms();
$this->assertEquals(0, $DB->get_field('modules', 'visible', ['name' => 'kialo']));

$this->assertNotContains('kialo', \core_plugin_manager::instance()->get_enabled_plugins('mod'));
}
}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

/** @var stdClass $plugin */
$plugin->component = 'mod_kialo';
$plugin->release = '1.0.10';
$plugin->version = 2023090701;
$plugin->release = '1.0.11';
$plugin->version = 2023090801;

// Officially we require PHP 7.4. The first Moodle version that requires this as a minimum is Moodle 4.1.
// But technically this plugin also runs on older Moodle versions, as long as they run on PHP 7.4,
Expand Down

0 comments on commit 778385f

Please sign in to comment.