Skip to content

Commit

Permalink
More app upgrader UX tweaks and bugfixes
Browse files Browse the repository at this point in the history
* Update user messages
* Fix ZIPARCHIVE::CREATE
* Fix upgrade links
  • Loading branch information
ginatrapani committed Mar 14, 2012
1 parent e4724e1 commit fcb0740
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 42 deletions.
8 changes: 5 additions & 3 deletions tests/TestOfUpgradeApplicationController.php
Expand Up @@ -87,7 +87,7 @@ public function testRunUpdate() {
$controller = new MockUpgradeApplicationController(true);
MockUpgradeApplicationController::$current_exception = false;
$results = $controller->go();
$this->assertEqual($controller->redirect_destination, '/install/update-application.php?ran_update=1');
$this->assertEqual($controller->redirect_destination, '/install/upgrade-application.php?ran_update=1');
}

public function testRanUpdate() {
Expand All @@ -96,7 +96,7 @@ public function testRanUpdate() {
$controller = new MockUpgradeApplicationController(true);
MockUpgradeApplicationController::$current_exception = 'Stuff Happened';
$results = $controller->go();
$this->assertPattern('/ThinkUp Install Has Been Updated/', $results);
$this->assertPattern('/Success! You\'re running the latest version of ThinkUp./', $results);
}

public function testAvailableFileSpace() {
Expand Down Expand Up @@ -128,7 +128,9 @@ public function testPermissions() {
$upgrade_controller->runUpdate();
$this->fail("Should throw an exception...");
} catch(Exception $e) {
$this->assertPattern('/is not writable. Unable to continue update./', $e->getMessage());
$this->assertPattern(
'/ThinkUp is unable to upgrade itself because of incorrect folder permissions. To fix this problem/',
$e->getMessage());
}
chmod( THINKUP_WEBAPP_PATH . 'index.php', 0644 ); // make a file writeable
}
Expand Down
14 changes: 9 additions & 5 deletions webapp/_lib/controller/class.UpgradeApplicationController.php
Expand Up @@ -44,11 +44,15 @@ public function __construct($session_started=false) {

public function authControl() {
if (isset($_GET['run_update'])) {
$backup_info = $this->runUpdate();
//var_dump($backup_info);
$site_root_path = Config::getInstance()->getValue('site_root_path');
$redir = $site_root_path . 'install/update-application.php?ran_update=1';
$this->redirect($redir);
try {
$backup_info = $this->runUpdate();
//var_dump($backup_info);
$site_root_path = Config::getInstance()->getValue('site_root_path');
$redir = $site_root_path . 'install/upgrade-application.php?ran_update=1';
$this->redirect($redir);
} catch(Exception $e) {
$this->addErrorMessage($e->getMessage(), null, true);
}
} else if (isset($_GET['ran_update'])) {
$this->addToView('updated',true);
} else {
Expand Down
2 changes: 1 addition & 1 deletion webapp/_lib/controller/class.UpgradeDatabaseController.php
Expand Up @@ -119,7 +119,7 @@ public function authControl() {
$this->snowflakeSession(false, true);
} else {
$this->setPageTitle('Upgrade the ThinkUp Database Structure');
$this->setViewTemplate('install.upgrade.tpl');
$this->setViewTemplate('install.upgrade-database.tpl');
if (version_compare($db_version, $thinkup_db_version, '<')) {
## get migrations we need to run...
$migrations = $this->getMigrationList($db_version);
Expand Down
39 changes: 18 additions & 21 deletions webapp/_lib/model/class.AppUpgraderDiskUtil.php
Expand Up @@ -121,7 +121,7 @@ public function setDiskSpaceNeeded($bytes) {
public function backUpInstall() {
$backupzip = new ZipArchive();
$backup_zipfile = $this->getBackupFilename();
if ($backupzip->open($backup_zipfile, ZipArchive::create)!==true) {
if ($backupzip->open($backup_zipfile, ZIPARCHIVE::CREATE)!==true) {
throw new Exception("Unable to open backup file to export: $backup_zipfile");
}
$files = $this->findAllFiles($this->app_dir);
Expand Down Expand Up @@ -164,16 +164,7 @@ public function backUpInstall() {
public function findAllFiles($file) {
if (!is_writable($file)) {
//throw new Exception("File permissions prevent writing to the ".$file."/ directory.");
$config = Config::getInstance();
$whoami = @exec('whoami');
if (empty($whoami)) {
$whoami = 'nobody';
}
throw new Exception("<b>Oops!</b> ThinkUp is unable to upgrade itself because of incorrect folder ".
"permissions. To fix this problem, run<br><br><code>chown -R $whoami ".
$config->getValue('source_root_path')."</code><br><br>on your server, using root (or sudo), and then ".
"reload this page to continue.<br /><br /> If you don't have root access, use the following command ".
"instead:<br><br> <code>chmod -R 664 ".$config->getValue('source_root_path')."</code><br><br>");
throw new Exception(self::getInadequateFilePermissionsException());
}
$root = scandir($file);
foreach($root as $value) {
Expand Down Expand Up @@ -258,17 +249,23 @@ public function validateUpdatePermissions($app_path) {
foreach($app_files as $file) {
if (!is_writable($file)) {
//throw new Exception("File $file is not writable. Unable to continue update.");
$config = Config::getInstance();
$whoami = @exec('whoami');
if (empty($whoami)) {
$whoami = 'nobody';
}
throw new Exception("<b>Oops!</b> ThinkUp is unable to upgrade itself because of incorrect folder ".
"permissions. To fix this problem, run<br><br><code>chown -R $whoami ".
$config->getValue('source_root_path')."</code><br><br>on your server, using root (or sudo), and then ".
"reload this page to continue.<br /><br /> If you don't have root access, use the following command ".
"instead:<br><br> <code>chmod -R 664 ".$config->getValue('source_root_path')."</code><br><br>");
throw new Exception(self::getInadequateFilePermissionsException());
}
}
}
/**
* Get detailed file permissions user error text.
* @return str
*/
private function getInadequateFilePermissionsException() {
$whoami = @exec('whoami');
if (empty($whoami)) {
$whoami = 'nobody';
}
return "<b>Oops!</b> ThinkUp is unable to upgrade itself because of incorrect folder permissions. ".
"To fix this problem, run<br><br><code>chown -R $whoami ". THINKUP_WEBAPP_PATH."</code><br><br>".
"on your server, using root (or sudo). If you don't have root access, try the following: ".
"<br><br> <code>chmod -R 777 ".THINKUP_WEBAPP_PATH."</code><br><br><br>".
'<div><a href="#" class="linkbutton emphasized">Okay, done. Try Again&rarr;</a></div><br><br>';
}
}
23 changes: 17 additions & 6 deletions webapp/_lib/view/install.upgrade-application.tpl
Expand Up @@ -2,25 +2,36 @@
{include file="_statusbar.tpl"}

<div class="container_24 thinkup-canvas round-all clearfix" style="margin-top : 10px;">

<div class="prepend_20">
<h1>Upgrade ThinkUp's Application Code</h1>
</div>

<div class="clearfix prepend_20 append_20">

{include file="_usermessage.tpl"}

{if $updateable}
<div class="grid_22 push_1 clearfix alert stats">
<p>Ready to upgrade {if $latest_version} to version <b>{$latest_version}</b>{/if}.</p>
<p>
<a href="{$site_root_path}install/update-application.php?run_update=1" onclick="$('#update-spinner').show();">
Upgrade ThinkUp</a>
</p>
<p><a href="{$site_root_path}install/upgrade-application.php?run_update=1" onclick="$('#update-spinner').show();">
Upgrade ThinkUp</a></p>
<p id="update-spinner" style="text-align: center; display: none;">
<img src="{$site_root_path}assets/img/loading.gif" width="31" height="31" />
</p>
</div>
{/if}
{if $updated}
<h1>Success! ThinkUp's Application Code Has Been Upgraded</h1>
<p><a href="{$site_root_path}install/upgrade-database.php">Upgrade your database.</a></p>
<div class="alert helpful">
<p>
<span class="ui-icon ui-icon-check" style="float: left; margin:.3em 0.3em 0 0;"></span>
Success! You're running the latest version of ThinkUp.
</p>
</div>
<br>
<div>
<p><a href="{$site_root_path}install/upgrade-database.php" class="linkbutton emphasized">One more thing: Upgrade ThinkUp's database&rarr;</a></p>
</div>
{/if}
</div>
</div>
Expand Down
13 changes: 7 additions & 6 deletions webapp/_lib/view/install.upgrade-database.tpl
Expand Up @@ -8,8 +8,7 @@
</div>

<div class="prepend_20">
<h1>Upgrade ThinkUp</h1>
<br><br>
<h1>Upgrade ThinkUp's Database</h1>
</div>

{if $high_table_row_count}
Expand All @@ -32,12 +31,14 @@
<div class="alert helpful" style="margin: 20px 0px; padding: 0.5em 0.7em;">
<p>
<span class="ui-icon ui-icon-check" style="float: left; margin:.3em 0.3em 0 0;"></span>
Your database is up to date. <a href="{$site_root_path}">Continue using ThinkUp</a>, or <a href="backup.php">back up your database.</a>
{if $version_updated}
<p>Your application database version has been updated to reflect the latest installed version of ThinkUp.</p>
{/if}
Sweet! Your database is up to date.</a>
</p>
</div>
<br>
<div>
<p><a href="{$site_root_path}" class="linkbutton emphasized">Start using your shiny new ThinkUp&rarr;</a></p>
</div>

{else}
<div id="info-parent" class="alert urgent" style="margin: 0px 50px 0px 50px; padding: 0.5em 0.7em;">
<div id="migration-info">
Expand Down

0 comments on commit fcb0740

Please sign in to comment.