Permalink
Browse files

Store application URL in settings, closes #1404

  • Loading branch information...
1 parent e982c84 commit 90ee3311d8070bdf411a3520d88cc2064b37750f @ginatrapani ginatrapani committed Dec 18, 2012
View
@@ -575,4 +575,24 @@ public function testGetTablesToInstall(){
'plugins', 'post_errors', 'posts', 'stream_data', 'stream_procs', 'user_errors', 'users');
$this->assertIdentical($tables, $expected_tables);
}
+
+ public function testStoreServerName() {
+ $option_dao = DAOFactory::getDAO('OptionDAO');
+ $current_stored_server_name = $option_dao->getOptionByName(OptionDAO::APP_OPTIONS, 'server_name');
+ $this->assertNull($current_stored_server_name);
+
+ $_SERVER['HTTP_HOST'] = 'mytestthinkup';
+ Installer::storeServerName();
+ $current_stored_server_name = $option_dao->getOptionByName(OptionDAO::APP_OPTIONS, 'server_name');
+ $this->assertNotNull($current_stored_server_name);
+ $this->assertEqual($current_stored_server_name->option_value, 'mytestthinkup');
+ $this->assertEqual($current_stored_server_name->option_name, 'server_name');
+
+ $_SERVER['SERVER_NAME'] = 'myreallygoodtest';
+ Installer::storeServerName();
+ $current_stored_server_name = $option_dao->getOptionByName(OptionDAO::APP_OPTIONS, 'server_name');
+ $this->assertNotNull($current_stored_server_name);
+ $this->assertEqual($current_stored_server_name->option_value, 'myreallygoodtest');
+ $this->assertEqual($current_stored_server_name->option_name, 'server_name');
+ }
}
@@ -565,9 +565,14 @@ public function testFreshInstallStep3SuccessfulInstall() {
$this->assertTrue(isset($controller));
$result = $controller->go();
$this->debug($result);
- $this->assertPattern('/ThinkUp has been
-installed successfully. Check your email account; an account activation
-message has been sent./', $result);
+ $this->assertPattern('/ThinkUp has been installed successfully./', $result);
+
+ $option_dao = DAOFactory::getDAO('OptionDAO');
+ $current_stored_server_name = $option_dao->getOptionByName(OptionDAO::APP_OPTIONS, 'server_name');
+ $this->assertNotNull($current_stored_server_name);
+ $this->assertEqual($current_stored_server_name->option_value, 'http://example.com');
+ $this->assertEqual($current_stored_server_name->option_name, 'server_name');
+
$this->restoreConfigFile();
//echo $result;
}
@@ -117,9 +117,17 @@ public function testRunUpdate() {
public function testRanUpdate() {
$this->simulateLogin('me@example.com', true);
+ $_SERVER['SERVER_NAME'] = 'http://example.com';
$_GET['ran_update'] = true;
$controller = new MockUpgradeApplicationController(true);
$results = $controller->go();
+
+ $option_dao = DAOFactory::getDAO('OptionDAO');
+ $current_stored_server_name = $option_dao->getOptionByName(OptionDAO::APP_OPTIONS, 'server_name');
+ $this->assertNotNull($current_stored_server_name);
+ $this->assertEqual($current_stored_server_name->option_value, 'http://example.com');
+ $this->assertEqual($current_stored_server_name->option_name, 'server_name');
+
$this->assertPattern('/Success! You\'re running the latest version of ThinkUp./', $results);
}
View
@@ -30,7 +30,7 @@
require_once THINKUP_WEBAPP_PATH.'_lib/extlib/simpletest/autorun.php';
require_once THINKUP_WEBAPP_PATH.'config.inc.php';
-class TestOfUtils extends ThinkUpBasicUnitTestCase {
+class TestOfUtils extends ThinkUpUnitTestCase {
public function testgetPluginViewDirectory() {
$config = Config::getInstance();
@@ -219,11 +219,19 @@ public function testGetSiteRootPathFromFileSystem() {
}
public function testGetApplicationURL() {
+ $cfg = Config::getInstance();
+ $cfg->setValue('site_root_path', '/my/path/to/thinkup/');
+
+ //no $_SERVER vars set, but with application setting set
+ $builder = FixtureBuilder::build('options', array('namespace'=>'application_options',
+ 'option_name'=>'server_name', 'option_value'=>'testservername') );
+ $utils_url = Utils::getApplicationURL();
+ $expected_url = 'http://testservername/my/path/to/thinkup/';
+ $this->assertEqual($utils_url, $expected_url);
+
//no SSL
$_SERVER['HTTP_HOST'] = "mytestthinkup";
$_SERVER['HTTPS'] = null;
- $cfg = Config::getInstance();
- $cfg->setValue('site_root_path', '/my/path/to/thinkup/');
$utils_url = Utils::getApplicationURL();
$expected_url = 'http://mytestthinkup/my/path/to/thinkup/';
$this->assertEqual($utils_url, $expected_url);
@@ -756,4 +756,20 @@ public function getTablesToInstall() {
}
return $table_names;
}
+
+ /**
+ * Store the application's server name in application settings as last-resort use by command-line scripts.
+ */
+ public static function storeServerName() {
+ $server_name = empty($_SERVER['SERVER_NAME']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
+ if ($server_name != '') {
+ $option_dao = DAOFactory::getDAO('OptionDAO');
+ $current_stored_server_name = $option_dao->getOptionByName(OptionDAO::APP_OPTIONS, 'server_name');
+ if ($current_stored_server_name) {
+ $option_dao->updateOption($current_stored_server_name->option_id, $server_name);
+ } else {
+ $option_dao->insertOption(OptionDAO::APP_OPTIONS, 'server_name', $server_name);
+ }
+ }
+ }
}
@@ -299,7 +299,16 @@ public static function getSiteRootPathFromFileSystem() {
* @return str
*/
public static function getApplicationURL($replace_localhost_with_ip = false) {
+ //First attempt to get the host name without querying the database
$server = empty($_SERVER['SERVER_NAME']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
+ //Then fall back to stored application setting set by Installer::storeServerName
+ if ($server == '') {
+ $option_dao = DAOFactory::getDAO('OptionDAO');
+ $server_app_setting = $option_dao->getOptionByName(OptionDAO::APP_OPTIONS, 'server_name');
+ if (isset($server_app_setting)) {
+ $server = $server_app_setting->option_value;
+ }
+ }
if ($replace_localhost_with_ip) {
$server = ($server == 'localhost')?'127.0.0.1':$server;
}
@@ -361,6 +361,9 @@ private function step3() {
// if empty, we're ready to populate the database with ThinkUp tables
$this->installer->populateTables($db_config);
+ //Set the application server name in app settings for access by command-line scripts
+ Installer::storeServerName();
+
$owner_dao = DAOFactory::getDAO('OwnerDAO', $db_config);
if ( !$owner_dao->doesAdminExist() && !$owner_dao->doesOwnerExist($email)) { // create admin if not exists
$activation_code = $owner_dao->createAdmin($email, $password, $full_name);
@@ -51,6 +51,9 @@ public function authControl() {
$this->addErrorMessage($e->getMessage(), null, true);
}
} else if (isset($_GET['ran_update'])) {
+ //Update the application server name in app settings for access by command-line scripts
+ Installer::storeServerName();
+
//Clear Smarty's compiled templates and cache to start fresh with newly upgraded app
$this->view_mgr->clear_compiled_tpl();
$this->view_mgr->clear_all_cache();

0 comments on commit 90ee331

Please sign in to comment.