Skip to content

Commit

Permalink
App upgrader fixes: don't redownload zip files in WebTestOfUpgradeDat…
Browse files Browse the repository at this point in the history
…abase, clean up after test_installer files to avoid permissions problems
  • Loading branch information
ginatrapani committed Mar 14, 2012
1 parent f71d3d7 commit 59f1d15
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 14 deletions.
5 changes: 1 addition & 4 deletions extras/scripts/generate-distribution
Expand Up @@ -8,9 +8,6 @@ if [ ! -d "$build" ]; then
mkdir build
fi

# clean up old data
rm -rf build/*

# Copy the webapp folder to build
cp -R webapp build/.

Expand All @@ -37,4 +34,4 @@ rm -rf build/thinkup/plugins/twitterrealtime/
cd build/
zip -r thinkup.zip thinkup
zip -d thinkup.zip __MACOSX* *.DS_Store *.ecoder_permissions_check.txt
rm -rf thinkup
rm -rf thinkup
1 change: 1 addition & 0 deletions tests/TestOfTestController.php
Expand Up @@ -80,6 +80,7 @@ public function testControl() {
public function testCacheKeyNoRequestParams() {
$config = Config::getInstance();
$config->setValue('cache_pages', true);
$this->debug($config->getValue('datadir_path'));
$controller = new TestController(true);
$results = $controller->go();

Expand Down
5 changes: 4 additions & 1 deletion tests/TestOfUpgradeApplicationController.php
Expand Up @@ -35,6 +35,8 @@ class TestOfUpgradeApplicationController extends ThinkUpUnitTestCase {

public function setUp(){
parent::setUp();
//make sure test_installer files are gone to prevent permissions problems
@exec('rm -rf ' . THINKUP_WEBAPP_PATH.'test_installer' . '/*');
}

public function tearDown(){
Expand Down Expand Up @@ -123,13 +125,14 @@ public function testNotEnoughAvailableFileSpace() {

public function testPermissions() {
chmod( THINKUP_WEBAPP_PATH . 'index.php', 0444 ); // make a file not writeable
$this->debug(THINKUP_WEBAPP_PATH.'index.php');
$upgrade_controller = new UpgradeApplicationController(true);
try {
$upgrade_controller->runUpdate();
$this->fail("Should throw an exception...");
} catch(Exception $e) {
$this->assertPattern(
'/ThinkUp is unable to upgrade itself because of incorrect folder permissions. To fix this problem/',
'/ThinkUp can\'t upgrade itself because it doesn\'t have the right file permissions. To fix this problem/',
$e->getMessage());
}
chmod( THINKUP_WEBAPP_PATH . 'index.php', 0644 ); // make a file writeable
Expand Down
3 changes: 0 additions & 3 deletions tests/TestOfUpgradeDatabaseController.php
Expand Up @@ -422,9 +422,6 @@ public function testNotLoggedInNoTAdminGensAndAuthsToken() {
$results = $controller->go();
$this->assertFalse( file_exists($this->token_file) );
$this->assertPattern('/<!-- no upgrade needed -->/', $results);

// NOTE: this will only happen when our db versions are out of sync
$this->assertPattern('/database version has been updated to reflect the latest installed version/', $results);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions tests/WebTestOfUpgradeDatabase.php
Expand Up @@ -68,7 +68,7 @@ public function setUp() {

public function tearDown() {
//Clean up test installation files
exec('rm -rf ' . THINKUP_WEBAPP_PATH.'test_installer' . '/*');
@exec('rm -rf ' . THINKUP_WEBAPP_PATH.'test_installer' . '/*');

// Delete test database created during installation process
require THINKUP_WEBAPP_PATH.'config.inc.php';
Expand Down Expand Up @@ -161,11 +161,13 @@ private function setUpApp($version, $MIGRATIONS) {
require THINKUP_WEBAPP_PATH.'config.inc.php';
//install beta 1
$zipfile = $this->getInstall($zip_url, $version, $this->installs_dir);
$whoami = @exec('whoami');
//Extract into test_installer directory and set necessary folder permissions
chdir(dirname(__FILE__) . '/../');
exec('cp ' . $zipfile . ' webapp/test_installer/.;'.
'cd webapp/test_installer/;'.
'unzip ' . $zipfile . ';mkdir -p thinkup/data/compiled_view;chmod -R 777 thinkup;');
'unzip ' . $zipfile . ';chown -R '.$whoami.' *; chmod -R 777 thinkup;');

//Config file doesn't exist
$this->assertFalse(file_exists($THINKUP_CFG['source_root_path'].
'webapp/test_installer/thinkup/config.inc.php'));
Expand Down Expand Up @@ -336,10 +338,12 @@ private function runMigrations($TMIGRATIONS, $base_version, $fail = false) {
$token_url = $this->url.'/test_installer/thinkup/install/upgrade.php?upgrade_token=' . $file_token;
$this->get($token_url);
$content = $this->getBrowser()->getContent();
//$this->debug($content);
preg_match("/sql_array = (\[.*?}])/", $content, $matches);
if (isset($matches[1])) {
$json_array = json_decode($matches[1]);
}
//$this->debug(Utils::varDumpToString($json_array));
$cnt = 0;
if (isset($json_array)) {
foreach($json_array as $json_migration) {
Expand Down
4 changes: 1 addition & 3 deletions webapp/_lib/model/class.AppUpgraderDiskUtil.php
Expand Up @@ -163,7 +163,6 @@ public function backUpInstall() {
*/
public function findAllFiles($file) {
if (!is_writable($file)) {
//throw new Exception("File permissions prevent writing to the ".$file."/ directory.");
throw new Exception(self::getInadequateFilePermissionsException());
}
$root = scandir($file);
Expand Down Expand Up @@ -248,7 +247,6 @@ public function validateUpdatePermissions($app_path) {
$app_files = $this->findAllFiles($app_path);
foreach($app_files as $file) {
if (!is_writable($file)) {
//throw new Exception("File $file is not writable. Unable to continue update.");
throw new Exception(self::getInadequateFilePermissionsException());
}
}
Expand All @@ -262,7 +260,7 @@ private function getInadequateFilePermissionsException() {
if (empty($whoami)) {
$whoami = 'nobody';
}
return "<b>Oops!</b> ThinkUp is unable to upgrade itself because of incorrect folder permissions. ".
return "<b>Oops!</b> ThinkUp can't upgrade itself because it doesn't have the right file 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>".
Expand Down
2 changes: 1 addition & 1 deletion webapp/install/upgrade-database.php
@@ -1,7 +1,7 @@
<?php
/**
*
* ThinkUp/webapp/install/upgrade.php
* ThinkUp/webapp/install/upgrade-database.php
*
* Copyright (c) 2009-2012 Mark Wilkie
*
Expand Down
31 changes: 31 additions & 0 deletions webapp/install/upgrade.php
@@ -0,0 +1,31 @@
<?php
/**
*
* ThinkUp/webapp/install/upgrade.php
*
* Copyright (c) 2012 Mark Wilkie
*
* LICENSE:
*
* This file is part of ThinkUp (http://thinkupapp.com).
*
* ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any
* later version.
*
* ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see
* <http://www.gnu.org/licenses/>.
*
* This file provided for backwards-compatibility and testing.
*
*
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2012 Mark Wilkie
* @author Mark Wilkie <mwilkie[at]gmail[dot]com>
*
*/
require_once('upgrade-database.php');

0 comments on commit 59f1d15

Please sign in to comment.