Skip to content

Commit

Permalink
Web Based Updater
Browse files Browse the repository at this point in the history
* update thinkup via the web
* added beta path update/json/version config option
* added docs
  • Loading branch information
Mark Wilkie authored and ginatrapani committed Mar 12, 2012
1 parent 62796fc commit 0fa667c
Show file tree
Hide file tree
Showing 25 changed files with 891 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,7 +1,7 @@
webapp/config.inc.php
webapp/config.inc.bak.php
webapp/data/
data/
./data/
tests/config.tests.inc.php
.*
extras/cron/config
Expand Down
1 change: 1 addition & 0 deletions docs/source/install/index.rst
Expand Up @@ -10,6 +10,7 @@ everything you need to know to get ThinkUp up and running on your web server.
quickstart
install
advancedconfig
update
upgrade
backup
perms
Expand Down
23 changes: 23 additions & 0 deletions docs/source/install/update.rst
@@ -0,0 +1,23 @@
Web Based Update Guide
===============================

The following is a general tutorial for how to update ThinkUp
to the latest version using the web based update tools

Prerequisites
-------------
- All of your ThinkUp application files and directories must be writable by the web server user.
- You must have at least 100 Megabytes of free disk space available to perform a web based update.

Run the web based update
------------------------
To run the web based update you just need to navigate to the update url form within tyour ThinkUP instance:
http://younstall.exampl.com/youthinkuppath/install/update.php

Troubleshooting
------------------------
The update tool should alert you to any issues you may have while trying to perform a web based update.
The two most common issue most likely to occur are:

- Invalid file permissions: Your ThinkUp install directory and all its files must be writeable by the web server user.
- Not enough free file space: You will need to have at least 100 megabytes of free space to perform a web based update.
7 changes: 5 additions & 2 deletions extras/scripts/generate-distribution
Expand Up @@ -8,6 +8,9 @@ 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 @@ -24,7 +27,7 @@ rm -rf build/thinkup/_lib/extlib/simpletest/
rm -rf build/thinkup/test_installer/
rm -rf build/thinkup/data/*
cp -R webapp/data/README.md build/thinkup/data/.
rm build/thinkup/config.inc.php
rm -rf build/thinkup/config.inc.php

# Clean out dev/alpha plugins which shouldn't go to users
rm -rf build/thinkup/plugins/hellothinkup/
Expand All @@ -34,4 +37,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
115 changes: 115 additions & 0 deletions tests/TestOfUpdateController.php
@@ -0,0 +1,115 @@
<?php
/**
*
* ThinkUp/tests/TestOfUpdateController.php
*
* Copyright (c) 2009-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/>.
*
*
* TestOfUpgradeController
*
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2012 Mark Wilkie
* @author Mark Wilkie <mwilkie[at]gmail[dot]com>
*
*/
require_once dirname(__FILE__).'/init.tests.php';
require_once THINKUP_WEBAPP_PATH.'_lib/extlib/simpletest/autorun.php';
require_once THINKUP_WEBAPP_PATH.'config.inc.php';
require_once THINKUP_WEBAPP_PATH.'_lib/extlib/simpletest/web_tester.php';

class TestOfUpdateController extends ThinkUpUnitTestCase {

public function setUp(){
parent::setUp();
}

public function tearDown(){
parent::tearDown();
Update::$current_exception = false;
}

/**
* Test controller for non-logged in user
* @TODO Possibly load the resulting markup as a DOM object and test various children in it;
* this would enforce valid markup
*/
public function testControlNotLoggedIn() {
$config = Config::getInstance();
$controller = new UpdateController(true);
$results = $controller->go();
$v_mgr = $controller->getViewManager();
$config = Config::getInstance();
$this->assertEqual('You must <a href="'.$config->getValue('site_root_path').
'session/login.php">log in</a> to do this.', $v_mgr->getTemplateDataItem('error_msg'));
}

public function testException() {
$this->simulateLogin('me@example.com', true);
$controller = new UpdateController(true);

}

public function testReadyToUpdate() {
$this->simulateLogin('me@example.com', true);
$controller = new UpdateController(true);
Update::$current_exception = 'Stuff Happened';
$results = $controller->go();
$this->assertPattern('/Stuff Happened/', $results);

$controller = new UpdateController(true);
Update::$current_exception = false;
$results = $controller->go();
$v_mgr = $controller->getViewManager();
$this->assertTrue($v_mgr->getTemplateDataItem('updateable'));
}

public function testRunUpdate() {
$this->simulateLogin('me@example.com', true);
$_GET['run_update'] = true;
$controller = new UpdateController(true);
Update::$current_exception = 'Stuff Happened';
$results = $controller->go();
$this->assertPattern('/Stuff Happened/', $results);

$controller = new UpdateController(true);
Update::$current_exception = false;
$results = $controller->go();
$this->assertEqual($controller->redirect_destination, '/install/update.php?ran_update=1');
}

public function testRanUpdate() {
$this->simulateLogin('me@example.com', true);
$_GET['ran_update'] = true;
$controller = new UpdateController(true);
Update::$current_exception = 'Stuff Happened';
$results = $controller->go();
$this->assertPattern('/ThinkUp Install Has Been Updated/', $results);
}
}

class Update {
static $current_exception = false;
public function run_update() {
if(self::$current_exception == true) {
throw new Exception(self::$current_exception);
} else {
return array('backup' => '/bla/backup-zipfile.zip', 'config' => '/bla/config.inc.backup.php');
}
}
}
Empty file modified tests/data/URLProcessor/instagr_am_p_oyQ6 100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions tests/data/update/bad_update_info.txt
@@ -0,0 +1 @@
this is not valid json
1 change: 1 addition & 0 deletions tests/data/update/new_update_info_bad_url.txt
@@ -0,0 +1 @@
{"version":"100.1", "url":"./webapp/nothing.not"}
1 change: 1 addition & 0 deletions tests/data/update/new_update_info_bad_zip.txt
@@ -0,0 +1 @@
{"version":"100.1", "url":"/Users/mark/projects/thinktank/webapp/update/class.TUUpdate.php"}
1 change: 1 addition & 0 deletions tests/data/update/old_update_info.txt
@@ -0,0 +1 @@
{"version":"0.1", "url":"https://github.com/downloads/ginatrapani/ThinkUp/thinkup_0.1.zip"}
140 changes: 140 additions & 0 deletions tests/update/TestOfUpdate.php
@@ -0,0 +1,140 @@
<?php
/**
*
* ThinkUp/tests/update/TestOfUpdate.php
*
* Copyright (c) 2009-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/>.
*
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2012 Mark Wilkie
* @author Mark Wilkie <mwilkie[at]gmail[dot]com>
*
*/

require_once dirname(__FILE__).'/../init.tests.php';
require_once THINKUP_WEBAPP_PATH.'_lib/extlib/simpletest/autorun.php';
require_once THINKUP_WEBAPP_PATH.'config.inc.php';
require_once THINKUP_WEBAPP_PATH.'_lib/extlib/simpletest/web_tester.php';

class TestOfUpdate extends ThinkUpUnitTestCase {

public function setUp() {
parent::setUp();
}


public function tearDown() {

}

public function testAvailableFileSPace() {
$this->assertTrue(true);
UpdateDiskUtil::$DISK_SPACE_NEEDED = 107374182400 * 10; // 10,000 megs
$tu_update = new Update();
try {
$tu_update->run_update();
$this->fail("Should throw an exception...");
} catch(Exception $e) {
$this->assertPattern('/There is not enough free disk space to perform an update/', $e->getMessage());
}
UpdateDiskUtil::$DISK_SPACE_NEEDED = 107374182400; // set back to 100 megs
$this->assertFalse(0);
}

public function testPermissions() {
chmod( THINKUP_WEBAPP_PATH . 'index.php', 0444 ); // make a file not writeable
$tu_update = new Update();
try {
$tu_update->run_update();
$this->fail("Should throw an exception...");
} catch(Exception $e) {
$this->assertPattern('/We do not have permissions to write the file/', $e->getMessage());
}
chmod( THINKUP_WEBAPP_PATH . 'index.php', 0644 ); // make a file writeable
}

public function testGetLatestInfo() {
$tu_update = new Update();
$valid_url = UpdateClient::$UPDATE_URL;

error_reporting( E_ERROR | E_USER_ERROR ); // turn off warning messages

// bad url, or bad response...
UpdateClient::$UPDATE_URL = '/badurl/nofile';
try {
$tu_update->run_update();
$this->fail("Should throw an exception...");
} catch(Exception $e) {
$this->assertEqual('Unable to load latest update info from /badurl/nofile', $e->getMessage());
}

// bad json in response data
UpdateClient::$UPDATE_URL = THINKUP_WEBAPP_PATH . '../tests/data/update/bad_update_info.txt';
try {
$tu_update->run_update();
$this->fail("Should throw an exception...");
} catch(Exception $e) {
$this->assertEqual('Invalid data received from update server: this is not valid json', $e->getMessage());
}

// we do not need to update
UpdateClient::$UPDATE_URL = THINKUP_WEBAPP_PATH . '../tests/data/update/old_update_info.txt';
try {
$tu_update->run_update();
$this->fail("Should throw an exception...");
} catch(Exception $e) {
$this->assertEqual('Thinkup is up to date', $e->getMessage());
}
// reset
UpdateClient::$UPDATE_URL = $valid_url;
error_reporting( $error_reporting ); // reset error reporting
}

public function testGetLatestUpdateFile() {
$tu_update = new Update();
$valid_url = UpdateClient::$UPDATE_URL;

error_reporting( E_ERROR | E_USER_ERROR ); // turn off warning messages
// we do need to update, but have an bad download url
UpdateClient::$UPDATE_URL = THINKUP_WEBAPP_PATH . '../tests/data/update/new_update_info_bad_url.txt';
try {
$tu_update->run_update();
$this->fail("Should throw an exception...");
} catch(Exception $e) {
$this->assertEqual('Unable to download latest update file ./webapp/nothing.not', $e->getMessage());
}

// we do need to update, but have an bad zip file
UpdateClient::$UPDATE_URL = THINKUP_WEBAPP_PATH . '../tests/data/update/new_update_info_bad_zip2.txt';

file_put_contents(UpdateClient::$UPDATE_URL,
'{"version":"100.1", "url":"' . THINKUP_WEBAPP_PATH . '_lib/model/update/class.Update.php"}');
try {
$tu_update->run_update();
$this->fail("Should throw an exception...");
} catch(Exception $e) {
$this->assertPattern('/Unable to open update zip file, corrupted zip file?/', $e->getMessage());
}
unlink(UpdateClient::$UPDATE_URL);

// reset
UpdateClient::$UPDATE_URL = $valid_url;
error_reporting( $error_reporting ); // reset error reporting
}

}
2 changes: 1 addition & 1 deletion webapp/_lib/controller/class.ThinkUpAuthController.php
Expand Up @@ -36,7 +36,7 @@ public function __construct($session_started=false) {

public function control() {
$response = $this->preAuthControl();
if (!$response) {
if (!$response) {
if ($this->isLoggedIn()) {
return $this->authControl();
} else {
Expand Down
1 change: 1 addition & 0 deletions webapp/_lib/controller/class.ThinkUpController.php
Expand Up @@ -302,6 +302,7 @@ protected function redirect($destination=null) {
if (!isset($destination)) {
$destination = Utils::getSiteRootPathFromFileSystem();
}
$this->redirect_destination = $destination; //for validation
if ( !headers_sent() ) {
header('Location: '.$destination);
return true;
Expand Down

0 comments on commit 0fa667c

Please sign in to comment.