MDL-49329 admin: Add ability to cancel upgrade of the plugin

If there is an available archived zip with the version of the plugin
currently installed, we can use it to cancel/abort the upgrade of the
plugin. This is internally handled as the installation of the archived
zip and goes through all the validation and confirmation.

Additionally, some other parts were improved. Most notably, renderer no
longer decides itself if some installation can be cancelled but it
always asks the controller (plugin manager).

The button for installation was moved to the left so there should be
first buttons to add things, and then buttons to cancel things (which is
common in normal forms).
This commit is contained in:
David Mudrák
2015-10-09 18:07:28 +02:00
parent 80c3c6501d
commit c20e9ae836
7 changed files with 217 additions and 76 deletions

View File

@@ -1941,12 +1941,17 @@ class core_plugin_manager {
/**
* Can the installation of the new plugin be cancelled?
*
* Subplugins can be cancelled only via their parent plugin, not separately
* (they are considered as implicit requirements if distributed together
* with the main package).
*
* @param \core\plugininfo\base $plugin
* @return bool
*/
public function can_cancel_plugin_installation(\core\plugininfo\base $plugin) {
if (empty($plugin) or $plugin->is_standard() or !$this->is_plugin_folder_removable($plugin->component)) {
if (empty($plugin) or $plugin->is_standard() or $plugin->is_subplugin()
or !$this->is_plugin_folder_removable($plugin->component)) {
return false;
}
@@ -1957,6 +1962,32 @@ class core_plugin_manager {
return false;
}
/**
* Can the upgrade of the existing plugin be cancelled?
*
* Subplugins can be cancelled only via their parent plugin, not separately
* (they are considered as implicit requirements if distributed together
* with the main package).
*
* @param \core\plugininfo\base $plugin
* @return bool
*/
public function can_cancel_plugin_upgrade(\core\plugininfo\base $plugin) {
if (empty($plugin) or $plugin->is_standard() or $plugin->is_subplugin()
or !$this->is_plugin_folder_removable($plugin->component)) {
return false;
}
if ($plugin->get_status() === self::PLUGIN_STATUS_UPGRADE) {
if ($this->get_code_manager()->get_archived_plugin_version($plugin->component, $plugin->versiondb)) {
return true;
}
}
return false;
}
/**
* Removes the plugin code directory if it is not installed yet.
*
@@ -1978,17 +2009,22 @@ class core_plugin_manager {
}
/**
* Cancels installation of all new additional plugins.
* Returns plugins, the installation of which can be cancelled.
*
* @return array [(string)component] => (\core\plugininfo\base)plugin
*/
public function cancel_all_plugin_installations() {
public function list_cancellable_installations() {
$cancellable = array();
foreach ($this->get_plugins() as $type => $plugins) {
foreach ($plugins as $plugin) {
if ($this->can_cancel_plugin_installation($plugin)) {
$this->cancel_plugin_installation($plugin->component);
$cancellable[$plugin->component] = $plugin;
}
}
}
return $cancellable;
}
/**
@@ -2001,6 +2037,29 @@ class core_plugin_manager {
return $this->get_code_manager()->archive_plugin_version($plugin->rootdir, $plugin->component, $plugin->versiondisk);
}
/**
* Returns list of all archives that can be installed to cancel the plugin upgrade.
*
* @return array [(string)component] => {(string)->component, (string)->zipfilepath}
*/
public function list_restorable_archives() {
$codeman = $this->get_code_manager();
$restorable = array();
foreach ($this->get_plugins() as $type => $plugins) {
foreach ($plugins as $plugin) {
if ($this->can_cancel_plugin_upgrade($plugin)) {
$restorable[$plugin->component] = (object)array(
'component' => $plugin->component,
'zipfilepath' => $codeman->get_archived_plugin_version($plugin->component, $plugin->versiondb)
);
}
}
}
return $restorable;
}
/**
* Reorders plugin types into a sequence to be displayed
*