Skip to content

Commit

Permalink
Detect when a module fails to upgrade properly and put up an
Browse files Browse the repository at this point in the history
informative message to help the user know that she needs to get a
newer copy of the module.  Fixes ticket #1189.
  • Loading branch information
bharat committed Sep 9, 2010
1 parent d7edbc2 commit 391a90e
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 20 deletions.
12 changes: 10 additions & 2 deletions modules/gallery/controllers/upgrader.php
Expand Up @@ -39,10 +39,12 @@ public function index() {
}
}

$failed = Input::instance()->get("failed");
$view = new View("upgrader.html");
$view->can_upgrade = identity::active_user()->admin || $session->get("can_upgrade");
$view->upgrade_token = $upgrade_token;
$view->available = module::available();
$view->failed = $failed ? explode(",", $failed) : array();
$view->done = $available_upgrades == 0;
print $view;
}
Expand All @@ -65,20 +67,26 @@ public function upgrade() {
}

// Then upgrade the rest
$failed = array();
foreach (module::available() as $id => $module) {
if ($id == "gallery") {
continue;
}

if ($module->active && $module->code_version != $module->version) {
module::upgrade($id);
try {
module::upgrade($id);
} catch (Exception $e) {
// @todo assume it's MODULE_FAILED_TO_UPGRADE for now
$failed[] = $id;
}
}
}

if (php_sapi_name() == "cli") {
print "Upgrade complete\n";
} else {
url::redirect("upgrader");
url::redirect("upgrader?failed=" . join(",", $failed));
}
}
}
28 changes: 28 additions & 0 deletions modules/gallery/css/upgrader.css
Expand Up @@ -58,6 +58,10 @@ tr.upgradeable td.gallery {
color: #00d;
}

tr.failed td {
color: red;
}

p {
font-size: .9em;
}
Expand Down Expand Up @@ -120,12 +124,28 @@ div#dialog div {
opacity: 0.5;
}

.failed {
color: red;
}

pre {
display: inline;
margin: 0px;
padding: 0px;
}

div#upgrade_button {
margin-bottom: 20px;
}

div#welcome_message {
margin-left: 30px;
}

#logo {
margin-left: 14px;
}

.rtl {
direction: rtl;
}
Expand Down Expand Up @@ -153,3 +173,11 @@ pre {
.rtl div#dialog a.close {
float: left;
}

.rtl div#welcome_message {
padding-right: 30px;
}

.rtl #logo {
padding-right: 12px;
}
6 changes: 5 additions & 1 deletion modules/gallery/helpers/module.php
Expand Up @@ -214,10 +214,10 @@ private static function _remove_from_path($module_name) {
static function upgrade($module_name) {
$version_before = module::get_version($module_name);
$installer_class = "{$module_name}_installer";
$available = module::available();
if (method_exists($installer_class, "upgrade")) {
call_user_func_array(array($installer_class, "upgrade"), array($version_before));
} else {
$available = module::available();
if (isset($available->$module_name->code_version)) {
module::set_version($module_name, $available->$module_name->code_version);
} else {
Expand All @@ -234,6 +234,10 @@ static function upgrade($module_name) {
"version_before" => $version_before,
"version_after" => $version_after)));
}

if ($version_after != $available->$module_name->code_version) {
throw new Exception("@todo MODULE_FAILED_TO_UPGRADE");
}
}

/**
Expand Down
53 changes: 36 additions & 17 deletions modules/gallery/views/upgrader.html.php
Expand Up @@ -10,7 +10,7 @@
</head>
<body<? if (locales::is_rtl()) { echo ' class="rtl"'; } ?>>
<div id="outer">
<img src="<?= url::file("modules/gallery/images/gallery.png") ?>" />
<img id="logo" src="<?= url::file("modules/gallery/images/gallery.png") ?>" />
<div id="inner">
<? if ($can_upgrade): ?>
<div id="dialog" style="visibility: hidden">
Expand All @@ -31,6 +31,12 @@
array("url" => html::mark_clean(url::base()))) ?>
</p>
</div>
<div id="failed" style="display: none">
<h1> <?= t("Some modules failed to upgrade!") ?> </h1>
<p>
<?= t("Failed modules are <span class=\"failed\">highlighted</span>. Try getting newer versions or <a href=\"%admin_modules\">deactivating those modules</a>.", array("admin_modules" => url::site("admin/modules"))) ?>
</p>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
Expand All @@ -41,6 +47,10 @@
<? if ($done): ?>
show_done();
<? endif ?>

<? if ($failed): ?>
show_failed();
<? endif ?>
});

var show_busy = function() {
Expand All @@ -55,10 +65,31 @@
$("#done").show();
$("#dialog_close_link").show();
}

var show_failed = function() {
$("#dialog").css("visibility", "visible");
$("#failed").show();
$("#dialog_close_link").show();
}
</script>
<p class="<?= $done ? "muted" : "" ?>">
<?= t("Welcome to the Gallery upgrader. One click and you're done!") ?>
</p>
<div id="welcome_message">
<p class="<?= $done ? "muted" : "" ?>">
<?= t("Welcome to the Gallery upgrader. One click and you're done!") ?>
</p>
</div>

<? if ($done): ?>
<div id="upgrade_button" class="button muted">
<?= t("Upgrade all") ?>
</div>
<? else: ?>
<div id="upgrade_button" class="button button-active">
<a id="upgrade_link" href="<?= url::site("upgrader/upgrade") ?>">
<?= t("Upgrade all") ?>
</a>
</div>
<? endif ?>

<table>
<tr class="<?= $done ? "muted" : "" ?>">
<th class="name"> <?= t("Module name") ?> </th>
Expand All @@ -68,7 +99,7 @@

<? foreach ($available as $id => $module): ?>
<? if ($module->active): ?>
<tr class="<?= $module->version == $module->code_version ? "current" : "upgradeable" ?>" >
<tr class="<?= $module->version == $module->code_version ? "current" : "upgradeable" ?> <?= in_array($id, $failed) ? "failed" : "" ?>" >
<td class="name <?= $id ?>">
<?= t($module->name) ?>
</td>
Expand All @@ -85,18 +116,6 @@
<? endforeach ?>
</table>

<? if ($done): ?>
<div class="button muted">
<?= t("Upgrade all") ?>
</div>
<? else: ?>
<div class="button button-active">
<a id="upgrade_link" href="<?= url::site("upgrader/upgrade") ?>">
<?= t("Upgrade all") ?>
</a>
</div>
<? endif ?>

<? if (@$inactive): ?>
<p class="<?= $done ? "muted" : "" ?>">
<?= t("The following modules are inactive and don't require an upgrade.") ?>
Expand Down

0 comments on commit 391a90e

Please sign in to comment.