MDL-66119 core: Add check for uninstalling plugins from the admin gui
author[Peter Burnett] <[peterburnett@catalyst-au.net]>
Fri, 19 Jul 2019 00:31:52 +0000 (10:31 +1000)
committer[Peter Burnett] <[peterburnett@catalyst-au.net]>
Thu, 25 Jul 2019 23:27:32 +0000 (09:27 +1000)
config-dist.php
lib/classes/plugin_manager.php

index ac73012..5e4ae97 100644 (file)
@@ -620,6 +620,12 @@ $CFG->admin = 'admin';
 //
 //      $CFG->debugsessionlock = 5;
 //
+// Uninstall plugins from CLI only. This stops admins from uninstalling plugins from the graphical admin
+// user interface, and forces plugins to be uninstalled from the Command Line tool only, found at
+// admin/cli/plugin_uninstall.php.
+//
+//      $CFG->uninstallclionly = true;
+//
 //=========================================================================
 // 7. SETTINGS FOR DEVELOPMENT SERVERS - not intended for production use!!!
 //=========================================================================
index ce5442f..564bd9e 100644 (file)
@@ -2233,6 +2233,11 @@ class core_plugin_manager {
      * @return bool
      */
     protected function common_uninstall_check(\core\plugininfo\base $pluginfo) {
+        global $CFG;
+        // Check if uninstall is allowed from the GUI.
+        if (!empty($CFG->uninstallclionly) && (!CLI_SCRIPT)) {
+            return false;
+        }
 
         if (!$pluginfo->is_uninstall_allowed()) {
             // The plugin's plugininfo class declares it should not be uninstalled.