MDL-49329 admin: Require confirmation before cancelling plugin install
This commit is contained in:
+42
-12
@@ -352,16 +352,30 @@ if (!$cache and $version > $CFG->version) { // upgrade
|
||||
|
||||
$pluginman = core_plugin_manager::instance();
|
||||
|
||||
// Cancel all plugin installations.
|
||||
if ($abortinstallx) {
|
||||
// No sesskey support guaranteed here, because sessions might not work yet.
|
||||
$pluginman->cancel_all_plugin_installations();
|
||||
redirect($PAGE->url);
|
||||
if ($confirmabortinstall) {
|
||||
$pluginman->cancel_all_plugin_installations();
|
||||
redirect($PAGE->url);
|
||||
} else {
|
||||
$continue = new moodle_url($PAGE->url, array('abortinstallx' => $abortinstallx, 'confirmabortinstall' => 1));
|
||||
echo $output->upgrade_confirm_abort_install_page(true, $continue);
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
// Cancel single plugin installation.
|
||||
if ($abortinstall) {
|
||||
// No sesskey support guaranteed here, because sessions might not work yet.
|
||||
$pluginman->cancel_plugin_installation($abortinstall);
|
||||
redirect($PAGE->url);
|
||||
if ($confirmabortinstall) {
|
||||
$pluginman->cancel_plugin_installation($abortinstall);
|
||||
redirect($PAGE->url);
|
||||
} else {
|
||||
$continue = new moodle_url($PAGE->url, array('abortinstall' => $abortinstall, 'confirmabortinstall' => 1));
|
||||
echo $output->upgrade_confirm_abort_install_page($abortinstall, $continue);
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
// Install all available missing dependencies.
|
||||
@@ -387,7 +401,7 @@ if (!$cache and $version > $CFG->version) { // upgrade
|
||||
}
|
||||
}
|
||||
|
||||
// Install all avilable updates.
|
||||
// Install all available updates.
|
||||
if ($installupdatex) {
|
||||
// No sesskey support guaranteed here, because sessions might not work yet.
|
||||
$installable = $pluginman->filter_installable($pluginman->available_updates());
|
||||
@@ -458,8 +472,13 @@ if (!$cache and moodle_needs_upgrading()) {
|
||||
|
||||
if (!$PAGE->headerprinted) {
|
||||
// means core upgrade or installation was not already done
|
||||
|
||||
/** @var core_plugin_manager $pluginman */
|
||||
$pluginman = core_plugin_manager::instance();
|
||||
|
||||
/** @var core_admin_renderer $output */
|
||||
$output = $PAGE->get_renderer('core', 'admin');
|
||||
|
||||
if (!$confirmplugins) {
|
||||
$strplugincheck = get_string('plugincheck');
|
||||
|
||||
@@ -468,16 +487,30 @@ if (!$cache and moodle_needs_upgrading()) {
|
||||
$PAGE->set_heading($strplugincheck);
|
||||
$PAGE->set_cacheable(false);
|
||||
|
||||
// Cancel all plugin installations.
|
||||
if ($abortinstallx) {
|
||||
require_sesskey();
|
||||
$pluginman->cancel_all_plugin_installations();
|
||||
redirect($PAGE->url);
|
||||
if ($confirmabortinstall) {
|
||||
$pluginman->cancel_all_plugin_installations();
|
||||
redirect($PAGE->url);
|
||||
} else {
|
||||
$continue = new moodle_url($PAGE->url, array('abortinstallx' => $abortinstallx, 'confirmabortinstall' => 1));
|
||||
echo $output->upgrade_confirm_abort_install_page(true, $continue);
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
// Cancel single plugin installation.
|
||||
if ($abortinstall) {
|
||||
require_sesskey();
|
||||
$pluginman->cancel_plugin_installation($abortinstall);
|
||||
redirect($PAGE->url);
|
||||
if ($confirmabortinstall) {
|
||||
$pluginman->cancel_plugin_installation($abortinstall);
|
||||
redirect($PAGE->url);
|
||||
} else {
|
||||
$continue = new moodle_url($PAGE->url, array('abortinstall' => $abortinstall, 'confirmabortinstall' => 1));
|
||||
echo $output->upgrade_confirm_abort_install_page($abortinstall, $continue);
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
if ($fetchupdates) {
|
||||
@@ -536,9 +569,6 @@ if (!$cache and moodle_needs_upgrading()) {
|
||||
}
|
||||
}
|
||||
|
||||
/** @var core_admin_renderer $output */
|
||||
$output = $PAGE->get_renderer('core', 'admin');
|
||||
|
||||
// Show plugins info.
|
||||
echo $output->upgrade_plugin_check_page($pluginman, \core\update\checker::instance(),
|
||||
$version, $showallplugins,
|
||||
|
||||
+56
-8
@@ -228,6 +228,58 @@ class core_admin_renderer extends plugin_renderer_base {
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a page to confirm plugin installation cancelation.
|
||||
*
|
||||
* @param bool|string $plugin true if cancelling all, component name otherwsie
|
||||
* @param moodle_url $continue
|
||||
* @return string
|
||||
*/
|
||||
public function upgrade_confirm_abort_install_page($plugin, moodle_url $continue) {
|
||||
|
||||
$pluginman = core_plugin_manager::instance();
|
||||
$abortable = array();
|
||||
|
||||
if ($plugin === true) {
|
||||
foreach ($pluginman->get_plugins() as $type => $pluginfos) {
|
||||
foreach ($pluginfos as $pluginfo) {
|
||||
if ($pluginman->can_cancel_plugin_installation($pluginfo)) {
|
||||
$abortable[] = $pluginfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$pluginfo = $pluginman->get_plugin_info($plugin);
|
||||
if ($pluginman->can_cancel_plugin_installation($pluginfo)) {
|
||||
$abortable[] = $pluginfo;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($abortable)) {
|
||||
// The UI should not allow this.
|
||||
throw new moodle_exception('err_no_plugin_install_abortable', 'core_plugin');
|
||||
}
|
||||
|
||||
$out = $this->output->header();
|
||||
$out .= $this->output->heading(get_string('cancelinstallhead', 'core_plugin'), 3);
|
||||
$out .= $this->output->container(get_string('cancelinstallinfo', 'core_plugin'), 'cancelinstallinfo');
|
||||
|
||||
foreach ($abortable as $pluginfo) {
|
||||
$out .= $this->output->heading($pluginfo->displayname.' ('.$pluginfo->component.')', 4);
|
||||
$out .= $this->output->container(get_string('cancelinstallinfodir', 'core_plugin', $pluginfo->rootdir));
|
||||
if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
|
||||
$out .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
|
||||
'uninstalldeleteconfirmexternal');
|
||||
}
|
||||
}
|
||||
|
||||
$out .= $this->plugins_management_confirm_buttons($continue, $this->page->url);
|
||||
$out .= $this->output->footer();
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the admin notifications page.
|
||||
* @param int $maturity
|
||||
@@ -1026,22 +1078,18 @@ class core_admin_renderer extends plugin_renderer_base {
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the continue / cancel widgets for the plugins validation page.
|
||||
* Display the continue / cancel widgets for the plugins management pages.
|
||||
*
|
||||
* @param null|moodle_url $continue URL for the continue button, should it be displayed
|
||||
* @param string $label explicit label for the continue button
|
||||
* @param moodle_url $cancel URL for the cancel link, defaults to the current page
|
||||
* @return string HTML
|
||||
*/
|
||||
public function install_plugins_buttons(moodle_url $continue=null, $label=null, moodle_url $cancel=null) {
|
||||
public function plugins_management_confirm_buttons(moodle_url $continue=null, moodle_url $cancel=null) {
|
||||
|
||||
$out = html_writer::start_div('install-remote-plugins-buttons');
|
||||
$out = html_writer::start_div('plugins-management-confirm-buttons');
|
||||
|
||||
if (!empty($continue)) {
|
||||
if (empty($label)) {
|
||||
$label = get_string('continue');
|
||||
}
|
||||
$out .= $this->output->single_button($continue, $label, 'post', array('class' => 'continue'));
|
||||
$out .= $this->output->single_button($continue, get_string('continue'), 'post', array('class' => 'continue'));
|
||||
}
|
||||
|
||||
if (empty($cancel)) {
|
||||
|
||||
@@ -29,6 +29,9 @@ $string['actions'] = 'Actions';
|
||||
$string['availability'] = 'Availability';
|
||||
$string['cancelinstallall'] = 'Cancel new installations ({$a})';
|
||||
$string['cancelinstallone'] = 'Cancel installation';
|
||||
$string['cancelinstallhead'] = 'Cancelling installation of plugins';
|
||||
$string['cancelinstallinfo'] = 'Following plugins are not fully installed yet and their installation can be cancelled. To do so, the plugin folder must be removed from your server now. Make sure that is really what you want to prevent accidental data loss (such as your own code modifications).';
|
||||
$string['cancelinstallinfodir'] = 'Folder to be deleted: {$a}';
|
||||
$string['checkforupdates'] = 'Check for available updates';
|
||||
$string['checkforupdateslast'] = 'Last check done on {$a}';
|
||||
$string['detectedmisplacedplugin'] = 'Plugin "{$a->component}" is installed in incorrect location "{$a->current}", expected location is "{$a->expected}"';
|
||||
|
||||
@@ -1911,6 +1911,25 @@ class core_plugin_manager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the installation of the new plugin be cancelled?
|
||||
*
|
||||
* @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)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($plugin->get_status() === self::PLUGIN_STATUS_NEW) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the plugin code directory if it is not installed yet.
|
||||
*
|
||||
@@ -1925,12 +1944,13 @@ class core_plugin_manager {
|
||||
|
||||
$plugin = $this->get_plugin_info($component);
|
||||
|
||||
if (empty($plugin) or $plugin->is_standard() or $plugin->get_status() !== self::PLUGIN_STATUS_NEW
|
||||
or !$this->is_plugin_folder_removable($plugin->component)) {
|
||||
return false;
|
||||
if ($this->can_cancel_plugin_installation($plugin)) {
|
||||
if ($this->archive_plugin_version($plugin)) {
|
||||
return remove_dir($plugin->rootdir);
|
||||
}
|
||||
}
|
||||
|
||||
return remove_dir($plugin->rootdir);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1940,14 +1960,24 @@ class core_plugin_manager {
|
||||
|
||||
foreach ($this->get_plugins() as $type => $plugins) {
|
||||
foreach ($plugins as $plugin) {
|
||||
if (!$plugin->is_standard() and $plugin->get_status() === self::PLUGIN_STATUS_NEW
|
||||
and $this->is_plugin_folder_removable($plugin->component)) {
|
||||
if ($this->can_cancel_plugin_installation($plugin)) {
|
||||
$this->cancel_plugin_installation($plugin->component);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Archive the current on-disk plugin code.
|
||||
*
|
||||
* @param \core\plugiinfo\base $plugin
|
||||
* @return bool
|
||||
*/
|
||||
public function archive_plugin_version(\core\plugininfo\base $plugin) {
|
||||
// TODO use code_manager to do it.
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorders plugin types into a sequence to be displayed
|
||||
*
|
||||
|
||||
+2
-2
@@ -2414,9 +2414,9 @@ function upgrade_install_plugins(array $installable, $confirmed, $heading='', $c
|
||||
$validated = $pluginman->install_plugins($installable, false, false);
|
||||
echo html_writer::end_tag('pre');
|
||||
if ($validated) {
|
||||
echo $output->install_plugins_buttons($continue, null, $return);
|
||||
echo $output->plugins_management_confirm_buttons($continue, $return);
|
||||
} else {
|
||||
echo $output->install_plugins_buttons(null, null, $return);
|
||||
echo $output->plugins_management_confirm_buttons(null, $return);
|
||||
}
|
||||
echo $output->footer();
|
||||
die();
|
||||
|
||||
@@ -760,7 +760,7 @@ img.iconsmall {
|
||||
}
|
||||
}
|
||||
|
||||
.install-remote-plugins-buttons {
|
||||
.plugins-management-confirm-buttons {
|
||||
> div {
|
||||
display: inline-block;
|
||||
margin: 1em 1em 1em 0;
|
||||
@@ -773,6 +773,12 @@ img.iconsmall {
|
||||
}
|
||||
}
|
||||
|
||||
.uninstalldeleteconfirmexternal {
|
||||
background-color: @warningBackground;
|
||||
padding: 0.5em 1em;
|
||||
margin: 5px 0 10px 0;
|
||||
}
|
||||
|
||||
#page-admin-index .upgradepluginsinfo {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user