MDL-49329 admin: If unable to install a plugin, display the reason

This commit is contained in:
David Mudrák 2015-10-05 14:08:00 +02:00
parent f65d337089
commit 36977a6d08
5 changed files with 44 additions and 12 deletions

View File

@ -1233,13 +1233,18 @@ class core_admin_renderer extends plugin_renderer_base {
$info .= html_writer::div(html_writer::link($plugin->version->downloadurl, get_string('download')), 'misdepdownload');
if ($pluginman->is_remote_plugin_installable($plugin->component, $plugin->version->version)) {
if ($pluginman->is_remote_plugin_installable($plugin->component, $plugin->version->version, $reason)) {
$info .= $this->output->single_button(
new moodle_url($this->page->url, array('installdep' => $plugin->component)),
get_string('dependencyinstall', 'core_plugin'),
'post',
array('class' => 'singlebutton dependencyinstall')
);
} else {
$reasonhelp = $this->info_remote_plugin_not_installable($reason);
if ($reasonhelp) {
$info .= html_writer::div($reasonhelp, 'reasonhelp dependencyinstall');
}
}
$info .= $this->output->container_end(); // .actions
@ -1256,6 +1261,25 @@ class core_admin_renderer extends plugin_renderer_base {
return html_writer::table($table);
}
/**
* Explain why {@link core_plugin_manager::is_remote_plugin_installable()} returned false.
*
* @param string $reason the reason code as returned by the plugin manager
* @return string
*/
protected function info_remote_plugin_not_installable($reason) {
if ($reason === 'notwritableplugintype' or $reason === 'notwritableplugin') {
return $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin'));
}
if ($reason === 'remoteunavailable') {
return $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin'));
}
return false;
}
/**
* Formats the information that needs to go in the 'Requires' column.
* @param \core\plugininfo\base $plugin the plugin we are rendering the row for.

View File

@ -62,10 +62,7 @@ $string['notdownloadable'] = 'Can not download the package';
$string['notdownloadable_help'] = 'ZIP package with the update can not be downloaded automatically. Please refer to the documentation page for more help.';
$string['notdownloadable_link'] = 'admin/mdeploy/notdownloadable';
$string['notwritable'] = 'Plugin files not writable';
$string['notwritable_help'] = 'You have enabled automatic updates deployment and there is an available update for this plugin. However, the plugin files are not writable by the web server so the update cannot be installed automatically.
You need to make the plugin folder and all its contents writable to be able to install the available update automatically.';
$string['notwritable_link'] = 'admin/mdeploy/notwritable';
$string['notwritable_help'] = 'Plugin files are not writable by the web server. The web server process has to have write access to the plugin folder and all its contents. Write access to the root folder of the given plugin type may be required, too.';
$string['numtotal'] = 'Installed: {$a}';
$string['numdisabled'] = 'Disabled: {$a}';
$string['numextension'] = 'Additional: {$a}';

View File

@ -935,26 +935,33 @@ class core_plugin_manager {
/**
* Can the given plugin version be installed via the admin UI?
*
* This check should be used whenever attempting to install a plugin from
* the plugins directory (new install, available update, missing dependency).
*
* @param string $component
* @param int $version version number
* $param string $reason returned code of the reason why it is not
* @return boolean
*/
public function is_remote_plugin_installable($component, $version) {
public function is_remote_plugin_installable($component, $version, &$reason=null) {
global $CFG;
// Make sure the feature is not disabled.
if (!empty($CFG->disableonclickaddoninstall)) {
$reason = 'disabled';
return false;
}
// Make sure we know there is some version available.
// Make sure the version is available.
if (!$this->is_remote_plugin_available($component, $version, true)) {
$reason = 'remoteunavailable';
return false;
}
// Make sure the plugin type root directory is writable.
list($plugintype, $pluginname) = core_component::normalize_component($component);
if (!$this->is_plugintype_writable($plugintype)) {
$reason = 'notwritableplugintype';
return false;
}
@ -963,13 +970,17 @@ class core_plugin_manager {
if ($localinfo) {
// If the plugin is already present, prevent downgrade.
if ($current->versiondb > $remoteinfo->version->version) {
if ($localinfo->versiondb > $remoteinfo->version->version) {
$reason = 'cannotdowngrade';
return false;
}
// Make sure we have write access to all the existing code.
if (!$this->is_plugin_folder_removable($component)) {
return false;
if (is_dir($localinfo->rootdir)) {
if (!$this->is_plugin_folder_removable($component)) {
$reason = 'notwritableplugin';
return false;
}
}
}

View File

@ -685,7 +685,7 @@ img.iconsmall {
display: inline-block;
margin-right: 1em;
}
.singlebutton {
.dependencyinstall {
display: block;
margin: 5px 0;
padding: 0;

File diff suppressed because one or more lines are too long