From b0fc789878f07bc53ed553f48ef0c0dc03b7b3bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Fri, 9 Oct 2015 22:23:52 +0200 Subject: [PATCH] MDL-49329 admin: Clean up disabling of plugins code management features The admin setting updateautodeploy no longer exists. The two existing config.php flags $CFG->disableupdateautodeploy and $CFG->disableonclickaddoninstall merged into a single one. --- admin/index.php | 14 ++++++++- admin/settings/server.php | 4 --- admin/tool/installaddon/index.php | 2 +- admin/tool/installaddon/permcheck.php | 2 +- admin/tool/installaddon/settings.php | 2 +- config-dist.php | 13 +++------ lang/en/admin.php | 2 -- lib/classes/plugin_manager.php | 42 ++++++++++++++++++++++++++- lib/db/upgrade.php | 7 +++++ lib/setup.php | 5 ++++ lib/upgradelib.php | 6 +++- version.php | 2 +- 12 files changed, 79 insertions(+), 22 deletions(-) diff --git a/admin/index.php b/admin/index.php index b2ccf8c99ec..6c3469fa8fd 100644 --- a/admin/index.php +++ b/admin/index.php @@ -120,6 +120,18 @@ $installupdateversion = optional_param('installupdateversion', null, PARAM_INT); $installupdatex = optional_param('installupdatex', false, PARAM_BOOL); // Install all available plugin updates. $confirminstallupdate = optional_param('confirminstallupdate', false, PARAM_BOOL); // Available update(s) install confirmed? +if (!empty($CFG->disableupdateautodeploy)) { + // Invalidate all requests to install plugins via the admin UI. + $newaddonreq = null; + $installdep = null; + $installdepx = false; + $abortupgrade = null; + $abortupgradex = null; + $installupdate = null; + $installupdateversion = null; + $installupdatex = false; +} + // Set up PAGE. $url = new moodle_url('/admin/index.php'); $url->param('cache', $cache); @@ -130,7 +142,7 @@ $PAGE->set_url($url); unset($url); // Are we returning from an add-on installation request at moodle.org/plugins? -if ($newaddonreq and !$cache and empty($CFG->disableonclickaddoninstall)) { +if ($newaddonreq and !$cache and empty($CFG->disableupdateautodeploy)) { $target = new moodle_url('/admin/tool/installaddon/index.php', array( 'installaddonrequest' => $newaddonreq, 'confirm' => 0)); diff --git a/admin/settings/server.php b/admin/settings/server.php index 4b3b11e85e9..cc43e70275b 100644 --- a/admin/settings/server.php +++ b/admin/settings/server.php @@ -215,10 +215,6 @@ if (empty($CFG->disableupdatenotifications)) { $temp = new admin_settingpage('updatenotifications', new lang_string('updatenotifications', 'core_admin')); $temp->add(new admin_setting_configcheckbox('updateautocheck', new lang_string('updateautocheck', 'core_admin'), new lang_string('updateautocheck_desc', 'core_admin'), 1)); - if (empty($CFG->disableupdateautodeploy)) { - $temp->add(new admin_setting_configcheckbox('updateautodeploy', new lang_string('updateautodeploy', 'core_admin'), - new lang_string('updateautodeploy_desc', 'core_admin'), 0)); - } $temp->add(new admin_setting_configselect('updateminmaturity', new lang_string('updateminmaturity', 'core_admin'), new lang_string('updateminmaturity_desc', 'core_admin'), MATURITY_STABLE, array( diff --git a/admin/tool/installaddon/index.php b/admin/tool/installaddon/index.php index 7bbe5600a27..cd6e7f43e92 100644 --- a/admin/tool/installaddon/index.php +++ b/admin/tool/installaddon/index.php @@ -28,7 +28,7 @@ require_once($CFG->libdir.'/adminlib.php'); admin_externalpage_setup('tool_installaddon_index'); -if (!empty($CFG->disableonclickaddoninstall)) { +if (!empty($CFG->disableupdateautodeploy)) { notice(get_string('featuredisabled', 'tool_installaddon')); } diff --git a/admin/tool/installaddon/permcheck.php b/admin/tool/installaddon/permcheck.php index e271b07483e..8df27d08e58 100644 --- a/admin/tool/installaddon/permcheck.php +++ b/admin/tool/installaddon/permcheck.php @@ -36,7 +36,7 @@ if (!has_capability('moodle/site:config', context_system::instance())) { die(); } -if (!empty($CFG->disableonclickaddoninstall)) { +if (!empty($CFG->disableupdateautodeploy)) { header('HTTP/1.1 403 Forbidden'); die(); } diff --git a/admin/tool/installaddon/settings.php b/admin/tool/installaddon/settings.php index 422930fef65..17f0d51e91d 100644 --- a/admin/tool/installaddon/settings.php +++ b/admin/tool/installaddon/settings.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -if ($hassiteconfig and empty($CFG->disableonclickaddoninstall)) { +if ($hassiteconfig and empty($CFG->disableupdateautodeploy)) { $ADMIN->add('modules', new admin_externalpage('tool_installaddon_index', get_string('installaddons', 'tool_installaddon'), diff --git a/config-dist.php b/config-dist.php index 453a8dc9859..beb9ac347b1 100644 --- a/config-dist.php +++ b/config-dist.php @@ -447,18 +447,13 @@ $CFG->admin = 'admin'; // // $CFG->disableupdatenotifications = true; // -// Use the following flag to completely disable the Automatic updates deployment -// feature and hide it from the server administration UI. -// TODO: drop this flag and use disableonclickaddoninstall instead. +// Use the following flag to completely disable the installation of plugins +// (new plugins, available updates and missing dependencies) and related +// features (such as cancelling the plugin installation or upgrade) via the +// server administration web interface. // // $CFG->disableupdateautodeploy = true; // -// Use the following flag to completely disable the installation of plugins -// (new plugins, available updates and missing dependencies) via the server -// administration UI. -// -// $CFG->disableonclickaddoninstall = true; -// // Use the following flag to disable modifications to scheduled tasks // whilst still showing the state of tasks. // diff --git a/lang/en/admin.php b/lang/en/admin.php index 6cb33d4c0ca..c4bae4ee374 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -1093,8 +1093,6 @@ $string['updatenotificationfooter'] = 'Your Moodle site {$a->siteurl} is configu $string['updatenotificationsubject'] = 'Moodle updates are available ({$a->siteurl})'; $string['updateautocheck'] = 'Automatically check for available updates'; $string['updateautocheck_desc'] = 'If enabled, your site will automatically check for available updates for both Moodle code and all additional plugins. If there is a new update available, a notification will be sent to site admins.'; -$string['updateautodeploy'] = 'Enable updates deployment'; -$string['updateautodeploy_desc'] = 'If enabled, you will be able to download and install available updates directly from Moodle administration pages. Note that your web server process has to have write access into folders with Moodle installation to make this work. That can be seen as a potential security risk.'; $string['updateminmaturity'] = 'Required code maturity'; $string['updateminmaturity_desc'] = 'Notify about available updates only if the available code has the selected maturity level at least. Updates for plugins that do not declare their code maturity level are always reported regardless this setting.'; $string['updatenotifybuilds'] = 'Notify about new builds'; diff --git a/lib/classes/plugin_manager.php b/lib/classes/plugin_manager.php index 8d0be1e0ba5..49fdcf5113a 100644 --- a/lib/classes/plugin_manager.php +++ b/lib/classes/plugin_manager.php @@ -946,7 +946,7 @@ class core_plugin_manager { global $CFG; // Make sure the feature is not disabled. - if (!empty($CFG->disableonclickaddoninstall)) { + if (!empty($CFG->disableupdateautodeploy)) { $reason = 'disabled'; return false; } @@ -998,7 +998,11 @@ class core_plugin_manager { * @return array */ public function filter_installable($remoteinfos) { + global $CFG; + if (!empty($CFG->disableupdateautodeploy)) { + return array(); + } if (empty($remoteinfos)) { return array(); } @@ -1072,6 +1076,11 @@ class core_plugin_manager { * @return string|bool full path to the file, false on error */ public function get_remote_plugin_zip($url, $md5) { + global $CFG; + + if (!empty($CFG->disableupdateautodeploy)) { + return false; + } return $this->get_code_manager()->get_remote_plugin_zip($url, $md5); } @@ -1235,6 +1244,10 @@ class core_plugin_manager { public function install_plugins(array $plugins, $confirmed, $silent) { global $CFG, $OUTPUT; + if (!empty($CFG->disableupdateautodeploy)) { + return false; + } + if (empty($plugins)) { return false; } @@ -1949,6 +1962,11 @@ class core_plugin_manager { * @return bool */ public function can_cancel_plugin_installation(\core\plugininfo\base $plugin) { + global $CFG; + + if (!empty($CFG->disableupdateautodeploy)) { + return false; + } if (empty($plugin) or $plugin->is_standard() or $plugin->is_subplugin() or !$this->is_plugin_folder_removable($plugin->component)) { @@ -1973,6 +1991,13 @@ class core_plugin_manager { * @return bool */ public function can_cancel_plugin_upgrade(\core\plugininfo\base $plugin) { + global $CFG; + + if (!empty($CFG->disableupdateautodeploy)) { + // Cancelling the plugin upgrade is actually installation of the + // previously archived version. + return false; + } if (empty($plugin) or $plugin->is_standard() or $plugin->is_subplugin() or !$this->is_plugin_folder_removable($plugin->component)) { @@ -1998,6 +2023,11 @@ class core_plugin_manager { * @param string $component */ public function cancel_plugin_installation($component) { + global $CFG; + + if (!empty($CFG->disableupdateautodeploy)) { + return false; + } $plugin = $this->get_plugin_info($component); @@ -2014,6 +2044,11 @@ class core_plugin_manager { * @return array [(string)component] => (\core\plugininfo\base)plugin */ public function list_cancellable_installations() { + global $CFG; + + if (!empty($CFG->disableupdateautodeploy)) { + return array(); + } $cancellable = array(); foreach ($this->get_plugins() as $type => $plugins) { @@ -2043,6 +2078,11 @@ class core_plugin_manager { * @return array [(string)component] => {(string)->component, (string)->zipfilepath} */ public function list_restorable_archives() { + global $CFG; + + if (!empty($CFG->disableupdateautodeploy)) { + return false; + } $codeman = $this->get_code_manager(); $restorable = array(); diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 4fd7aeae008..3b343c0bb0c 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -4599,5 +4599,12 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2015100600.00); } + if ($oldversion < 2015100800.01) { + // The only flag for preventing all plugins installation features is + // now $CFG->disableupdateautodeploy in config.php. + unset_config('updateautodeploy'); + upgrade_main_savepoint(true, 2015100800.01); + } + return true; } diff --git a/lib/setup.php b/lib/setup.php index 4a63ba88a88..3175bb1cc3a 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -364,6 +364,11 @@ $CFG->yuipatchlevel = 0; $CFG->yuipatchedmodules = array( ); +if (!empty($CFG->disableonclickaddoninstall)) { + // This config.php flag has been merged into another one. + $CFG->disableupdateautodeploy = true; +} + // Store settings from config.php in array in $CFG - we can use it later to detect problems and overrides. if (!isset($CFG->config_php_settings)) { $CFG->config_php_settings = (array)$CFG; diff --git a/lib/upgradelib.php b/lib/upgradelib.php index f3786754473..7832ce18123 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -2384,12 +2384,16 @@ function check_upgrade_key($upgradekeyhash) { * @param moodle_url|string|null $return URL to go back on cancelling at the validation screen */ function upgrade_install_plugins(array $installable, $confirmed, $heading='', $continue=null, $return=null) { - global $PAGE; + global $CFG, $PAGE; if (empty($return)) { $return = $PAGE->url; } + if (!empty($CFG->disableupdateautodeploy)) { + redirect($return); + } + if (empty($installable)) { redirect($return); } diff --git a/version.php b/version.php index f810c839d18..c78bc6a6330 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2015100800.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2015100800.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes.