Skip to content

Commit

Permalink
MDL-35238 Warn the admin if they are about to overwrite a SCM checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrd8mz committed Nov 8, 2012
1 parent 292dbea commit 08c3bc0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
12 changes: 7 additions & 5 deletions admin/renderer.php
Expand Up @@ -255,7 +255,7 @@ public function upgrade_plugin_confirm_deploy_page(available_update_deployer $de

$output = '';
$output .= $this->header();
$output .= $this->container_start('generalbox', 'notice');
$output .= $this->container_start('generalbox updateplugin', 'notice');

$a = new stdClass();
if (get_string_manager()->string_exists('pluginname', $updateinfo->component)) {
Expand All @@ -272,10 +272,12 @@ public function upgrade_plugin_confirm_deploy_page(available_update_deployer $de
$a->url = $updateinfo->download;

$output .= $this->output->heading(get_string('updatepluginconfirm', 'core_plugin'));
$output .= $this->output->container(format_text(
get_string('updatepluginconfirminfo', 'core_plugin', $a) . PHP_EOL . PHP_EOL .
get_string('updatepluginconfirmwarning', 'core_plugin')
));
$output .= $this->output->container(format_text(get_string('updatepluginconfirminfo', 'core_plugin', $a)), 'updatepluginconfirminfo');
$output .= $this->output->container(get_string('updatepluginconfirmwarning', 'core_plugin', 'updatepluginconfirmwarning'));

if ($repotype = $deployer->plugin_external_source($data['updateinfo'])) {
$output .= $this->output->container(get_string('updatepluginconfirmexternal', 'core_plugin', $repotype), 'updatepluginconfirmexternal');
}

$widget = $deployer->make_execution_widget($data['updateinfo']);
$output .= $this->output->render($widget);
Expand Down
1 change: 1 addition & 0 deletions lang/en/plugin.php
Expand Up @@ -133,6 +133,7 @@
$string['updateavailable_release'] = 'Release {$a}';
$string['updatepluginconfirm'] = 'Plugin update confirmation';
$string['updatepluginconfirminfo'] = 'You are about to install a new version of the plugin <strong>{$a->name}</strong>. A zip package with version {$a->version} of the plugin will be downloaded from <a href="{$a->url}">{$a->url}</a> and extracted to your Moodle installation so it can upgrade your installation.';
$string['updatepluginconfirmexternal'] = 'It appears that the current version of the plugin has been obtained via source code management system ({$a}) checkout. If you install this update, you will no longer be able to obtain plugin updates from the source code management system. Please ensure that you definitely want to update the plugin before continuing.';
$string['updatepluginconfirmwarning'] = 'Please note that Moodle will not automatically make a backup of your database before the upgrade. We strongly recommend that you make a full snapshot backup now, to cope with the rare case that the new code has bugs that make your site unavailable or even corrupts your database. Proceed at your own risk.';
$string['uninstall'] = 'Uninstall';
$string['version'] = 'Version';
Expand Down
27 changes: 27 additions & 0 deletions lib/pluginlib.php
Expand Up @@ -1543,6 +1543,33 @@ public function can_deploy(available_update_info $info) {
return true;
}

/**
* Check to see if the current version of the plugin seems to be a checkout of an external repository.
*
* @param available_update_info $info
* @return false|string
*/
public function plugin_external_source(available_update_info $info) {

$paths = get_plugin_types(true);
list($plugintype, $pluginname) = normalize_component($info->component);
$pluginroot = $paths[$plugintype].'/'.$pluginname;

if (is_dir($pluginroot.'/.git')) {
return 'git';
}

if (is_dir($pluginroot.'/CVS')) {
return 'cvs';
}

if (is_dir($pluginroot.'/.svn')) {
return 'svn';
}

return false;
}

/**
* Prepares a renderable widget to confirm installation of an available update.
*
Expand Down
5 changes: 5 additions & 0 deletions theme/base/style/admin.css
Expand Up @@ -102,6 +102,11 @@
#page-admin-index .adminwarning.availableupdatesinfo .moodleupdateinfo a {padding-right:1em;}
#page-admin-index .adminwarning.availableupdatesinfo .moodleupdateinfo .separator {border-left:1px dotted #333;}

#page-admin-index .updateplugin div,
#page-admin-plugins .updateplugin div {margin-bottom:0.5em;}
#page-admin-index .updateplugin .updatepluginconfirmexternal,
#page-admin-plugins .updateplugin .updatepluginconfirmexternal {padding:1em;background-color:#ffd3d9;border:1px solid #EEAAAA}

#page-admin-user-user_bulk #users .fgroup {white-space: nowrap;}
#page-admin-report-stats-index .graph {text-align: center;margin-bottom: 1em;}
#page-admin-report-courseoverview-index .graph {text-align: center;margin-bottom: 1em;}
Expand Down

0 comments on commit 08c3bc0

Please sign in to comment.