Skip to content

Commit

Permalink
Fixes for code review #84
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsommer committed Jan 15, 2015
1 parent b144a92 commit 791466b
Show file tree
Hide file tree
Showing 26 changed files with 347 additions and 304 deletions.
9 changes: 9 additions & 0 deletions airtime_mvc/application/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require_once "Auth.php";
require_once __DIR__ . '/forms/helpers/ValidationTypes.php';
require_once __DIR__ . '/controllers/plugins/RabbitMqPlugin.php';
require_once __DIR__ . '/upgrade/Upgrades.php';

require_once (APPLICATION_PATH . "logging/Logging.php");
Logging::setLogPath('/var/log/airtime/zendphp.log');
Expand Down Expand Up @@ -76,6 +77,14 @@ private function _initTranslationGlobals($view) {
$view->headScript()->appendScript("var USER_MANUAL_URL = '" . USER_MANUAL_URL . "';");
$view->headScript()->appendScript("var COMPANY_NAME = '" . COMPANY_NAME . "';");
}

protected function _initUpgrade() {
Logging::info("Checking if upgrade is needed...");
if (AIRTIME_CODE_VERSION > Application_Model_Preference::GetAirtimeVersion()) {
$upgradeManager = new UpgradeManager();
$upgradeManager->runUpgrades(array(new AirtimeUpgrader252()), (__DIR__ . "/controllers"));
}
}

protected function _initHeadLink()
{
Expand Down
3 changes: 0 additions & 3 deletions airtime_mvc/application/configs/conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ public static function loadConfig() {

$CC_CONFIG['cache_ahead_hours'] = $values['general']['cache_ahead_hours'];

$CC_CONFIG['monit_user'] = $values['monit']['monit_user'];
$CC_CONFIG['monit_password'] = $values['monit']['monit_password'];

// Database config
$CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
$CC_CONFIG['dsn']['password'] = $values['database']['dbpass'];
Expand Down
34 changes: 12 additions & 22 deletions airtime_mvc/application/controllers/UpgradeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,25 @@ public function indexAction()
array_push($upgraders, new AirtimeUpgrader254());
*/
$didWePerformAnUpgrade = false;
try
{
for ($i = 0; $i < count($upgraders); $i++)
{
$upgrader = $upgraders[$i];
if ($upgrader->checkIfUpgradeSupported())
{
// pass __DIR__ to the upgrades, since __DIR__ returns parent dir of file, not executor
$upgrader->upgrade(__DIR__); //This will throw an exception if the upgrade fails.
$didWePerformAnUpgrade = true;
$this->getResponse()
->setHttpResponseCode(200)
->appendBody("Upgrade to Airtime " . $upgrader->getNewVersion() . " OK<br>");
$i = 0; //Start over, in case the upgrade handlers are not in ascending order.
}
}
try {
$upgradeManager = new UpgradeManager();
$didWePerformAnUpgrade = $upgradeManager->runUpgrades($upgraders, __DIR__);

if (!$didWePerformAnUpgrade)
{
if (!$didWePerformAnUpgrade) {
$this->getResponse()
->setHttpResponseCode(200)
->appendBody("No upgrade was performed. The current Airtime version is " . AirtimeUpgrader::getCurrentVersion() . ".<br>");
} else {
$this->getResponse()
->setHttpResponseCode(200)
->appendBody("No upgrade was performed. The current Airtime version is " . AirtimeUpgrader::getCurrentVersion() . ".<br>");
->setHttpResponseCode(200)
->appendBody("Upgrade to Airtime " . $upgrader->getNewVersion() . " OK<br>");
}
}
catch (Exception $e)
{
$this->getResponse()
->setHttpResponseCode(400)
->appendBody($e->getMessage());
->setHttpResponseCode(400)
->appendBody($e->getMessage());
}
}

Expand Down
6 changes: 6 additions & 0 deletions airtime_mvc/application/models/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ public function fetch($key, $isUserValue, $userId = null) {
//$cacheKey = self::createCacheKey($key, $isUserValue, $userId);
return false; //apc_fetch($cacheKey);
}

public static function clear() {
// Disabled on SaaS
// apc_clear_cache('user');
// apc_clear_cache();
}
}
6 changes: 3 additions & 3 deletions airtime_mvc/application/models/Systemstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ class Application_Model_Systemstatus
public static function GetMonitStatus($p_ip)
{
$CC_CONFIG = Config::getConfig();
$monit_user = $CC_CONFIG['monit_user'];
$monit_password = $CC_CONFIG['monit_password'];
// $monit_user = $CC_CONFIG['monit_user'];
// $monit_password = $CC_CONFIG['monit_password'];

$url = "http://$p_ip:2812/_status?format=xml";

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "$monit_user:$monit_password");
// curl_setopt($ch, CURLOPT_USERPWD, "$monit_user:$monit_password");
//wait a max of 3 seconds before aborting connection attempt
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
$result = curl_exec($ch);
Expand Down
27 changes: 27 additions & 0 deletions airtime_mvc/application/upgrade/Upgrades.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
<?php

class UpgradeManager {

/**
* Run a given set of upgrades
*
* @param array $upgraders the upgrades to perform
* @param string $dir the directory containing the upgrade sql
* @return boolean whether or not an upgrade was performed
*/
public function runUpgrades($upgraders, $dir) {
$upgradePerformed;

for($i = 0; $i < count($upgraders); $i++) {
$upgrader = $upgraders[$i];
if ($upgrader->checkIfUpgradeSupported()) {
// pass the given directory to the upgrades, since __DIR__ returns parent dir of file, not executor
$upgrader->upgrade($dir); // This will throw an exception if the upgrade fails.
$upgradePerformed = true;
$i = 0; // Start over, in case the upgrade handlers are not in ascending order.
}
}

return $upgradePerformed;
}

}

abstract class AirtimeUpgrader
{
/** Versions that this upgrader class can upgrade from (an array of version strings). */
Expand Down
8 changes: 4 additions & 4 deletions airtime_mvc/build/airtime-setup/forms/database-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@
<div class="form-group">
<label class="control-label" for="dbUser">Username</label>
<input required class="form-control" type="text" name="dbUser" id="dbUser" placeholder="Username"
value=<?php echo (isset($db) ? $db["dbuser"] : "airtime"); ?>/>
value="<?php echo (isset($db) ? $db["dbuser"] : "airtime"); ?>" />
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
</div>
<div class="form-group">
<label class="control-label" for="dbPass">Password</label>
<input required class="form-control" type="password" name="dbPass" id="dbPass" placeholder="Password"
value=<?php echo (isset($db) ? $db["dbpass"] : "airtime"); ?>/>
value="<?php echo (isset($db) ? $db["dbpass"] : "airtime"); ?>" />
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
</div>
<div class="form-group">
<label class="control-label" for="dbName">Name</label>
<input required class="form-control" type="text" name="dbName" id="dbName" placeholder="Name"
value=<?php echo (isset($db) ? $db["dbname"] : "airtime"); ?>/>
value="<?php echo (isset($db) ? $db["dbname"] : "airtime"); ?>" />
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
</div>
<div class="form-group">
<label class="control-label" for="dbHost">Host</label>
<input required class="form-control" type="text" name="dbHost" id="dbHost" placeholder="Host"
value=<?php echo (isset($db) ? $db["host"] : "localhost"); ?>/>
value="<?php echo (isset($db) ? $db["host"] : "localhost"); ?>" />
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
</div>
<input class="form-control" type="hidden" name="dbErr" id="dbErr" aria-describedby="helpBlock"/>
Expand Down
4 changes: 0 additions & 4 deletions airtime_mvc/build/airtime-setup/forms/finish-settings.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<?php
$tempConfigPath = "/etc/airtime/airtime.conf.tmp";
if (file_exists($tempConfigPath)) {
rename($tempConfigPath, "/etc/airtime/airtime.conf.bak");
}
?>

<form action="#" role="form" id="finishSettingsForm">
Expand Down
10 changes: 5 additions & 5 deletions airtime_mvc/build/airtime-setup/forms/rabbitmq-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
<div class="form-group">
<label class="control-label" for="rmqUser">Username</label>
<input required class="form-control" type="text" name="rmqUser" id="rmqUser" placeholder="Username"
value=<?php echo (isset($rmq) ? $rmq["user"] : "airtime"); ?>/>
value="<?php echo (isset($rmq) ? $rmq["user"] : "airtime"); ?>" />
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
</div>
<div class="form-group">
<label class="control-label" for="rmqPass">Password</label>
<input class="form-control" type="password" name="rmqPass" id="rmqPass" placeholder="Password"
value=<?php echo (isset($rmq) ? $rmq["password"] : "airtime"); ?>/>
value="<?php echo (isset($rmq) ? $rmq["password"] : "airtime"); ?>" />
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
<span id="rmqHelpBlock" class="help-block">
You probably want to change this!
Expand All @@ -40,19 +40,19 @@
<div class="form-group">
<label class="control-label" for="rmqHost">Host</label>
<input required class="form-control" type="text" name="rmqHost" id="rmqHost" placeholder="Host"
value=<?php echo (isset($rmq) ? $rmq["host"] : "127.0.0.1"); ?>/>
value="<?php echo (isset($rmq) ? $rmq["host"] : "127.0.0.1"); ?>" />
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
</div>
<div class="form-group">
<label class="control-label" for="rmqPort">Port</label>
<input required class="form-control" type="text" name="rmqPort" id="rmqPort" placeholder="Port"
value=<?php echo (isset($rmq) ? $rmq["port"] : "5672"); ?>/>
value="<?php echo (isset($rmq) ? $rmq["port"] : "5672"); ?>" />
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
</div>
<div class="form-group">
<label class="control-label" for="rmqVHost">Virtual Host</label>
<input required class="form-control" type="text" name="rmqVHost" id="rmqVHost" placeholder="VHost"
value=<?php echo (isset($rmq) ? $rmq["vhost"] : "/airtime"); ?>/>
value="<?php echo (isset($rmq) ? $rmq["vhost"] : "/airtime"); ?>" />
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
</div>
<input class="form-control" type="hidden" name="rmqErr" id="rmqErr" aria-describedby="helpBlock"/>
Expand Down
Loading

0 comments on commit 791466b

Please sign in to comment.