Skip to content

Commit 10454d2

Browse files
committed
upgrade: remove subplugin folders if subplugins already uninstalled
1 parent cb31d0e commit 10454d2

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

classes/plugininfo/lifecycletrigger.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,18 @@ class lifecycletrigger extends base {
4141
/**
4242
* Should there be a way to uninstall the plugin via the administration UI.
4343
*
44-
* By default uninstallation is not allowed, plugin developers must enable it explicitly!
44+
* By default, uninstallation is not allowed. Plugin developers must enable it explicitly!
4545
*
4646
* @return bool
47+
* @throws \dml_exception
4748
*/
4849
public function is_uninstall_allowed() {
4950
if ($this->is_standard()) {
5051
return false;
5152
}
5253
$lib = lib_manager::get_trigger_lib($this->name);
5354
if ($lib->has_multiple_instances()) {
54-
// Only allow uninstall, if no active workflow for the trigger is present.
55+
// Only allow to uninstall if no active workflow for the trigger is present.
5556
$triggers = trigger_manager::get_instances($this->name);
5657
foreach ($triggers as $trigger) {
5758
if (workflow_manager::is_active($trigger->workflowid)) {

db/upgrade.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2323
*/
2424

25+
use tool_lifecycle\local\manager\lib_manager;
26+
use tool_lifecycle\local\manager\trigger_manager;
27+
use tool_lifecycle\local\manager\workflow_manager;
28+
2529
/**
2630
* Fix any gaps in the workflows sortindex.
2731
*/
@@ -36,6 +40,24 @@ function tool_lifecycle_fix_workflow_sortindex() {
3640
}
3741
}
3842

43+
/**
44+
* Removes a directory from filesystem
45+
* @param string $dir
46+
* @return void
47+
*/
48+
function tool_lifecycle_upgrade_removeDir(string $dir): void {
49+
$it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS);
50+
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
51+
foreach($files as $file) {
52+
if ($file->isDir()){
53+
rmdir($file->getPathname());
54+
} else {
55+
unlink($file->getPathname());
56+
}
57+
}
58+
rmdir($dir);
59+
}
60+
3961
/**
4062
* Update script for tool_lifecycle.
4163
* @param int $oldversion Version id of the previously installed version.
@@ -259,13 +281,13 @@ function xmldb_tool_lifecycle_upgrade($oldversion) {
259281
}
260282

261283
if ($oldversion < 2018022005) {
262-
$workflows = \tool_lifecycle\local\manager\workflow_manager::get_active_workflows();
284+
$workflows = workflow_manager::get_active_workflows();
263285
foreach ($workflows as $workflow) {
264286
if ($workflow->manual === null) {
265-
$trigger = \tool_lifecycle\local\manager\trigger_manager::get_triggers_for_workflow($workflow->id)[0];
266-
$lib = \tool_lifecycle\local\manager\lib_manager::get_trigger_lib($trigger->subpluginname);
287+
$trigger = trigger_manager::get_triggers_for_workflow($workflow->id)[0];
288+
$lib = lib_manager::get_trigger_lib($trigger->subpluginname);
267289
$workflow->manual = $lib->is_manual_trigger();
268-
\tool_lifecycle\local\manager\workflow_manager::insert_or_update($workflow);
290+
workflow_manager::insert_or_update($workflow);
269291
}
270292
}
271293
// Lifecycle savepoint reached.
@@ -571,6 +593,14 @@ function xmldb_tool_lifecycle_upgrade($oldversion) {
571593
$dbman->add_field($table, $field);
572594
}
573595

596+
if ($dir = core_component::get_plugin_directory('lifecycletrigger', 'sitecourse')) {
597+
tool_lifecycle_upgrade_removeDir($dir);
598+
}
599+
600+
if ($dir = core_component::get_plugin_directory('lifecycletrigger', 'delayedcourses')) {
601+
tool_lifecycle_upgrade_removeDir($dir);
602+
}
603+
574604
upgrade_plugin_savepoint(true, 2025041600, 'tool', 'lifecycle');
575605

576606
}

0 commit comments

Comments
 (0)