feat(legacy): consolidate constants (#1558)

* remove unused file

* fix paths leading slash

* remove useless imports

* refactor(legacy): use constants everywhere

* fix path leading slash

* remove useless import

* consolidate legacy contants

* format code

* reuse LIBRETIME_CONFIG_DIR

* fix test config path

* remove ci legacy log dir creation

* some logs improvements
This commit is contained in:
Jonas L 2022-02-04 11:00:41 +01:00 committed by GitHub
parent e106858fd8
commit 729a7b99e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 133 additions and 257 deletions

View File

@ -72,7 +72,6 @@ jobs:
runs-on: ${{ matrix.runs-on }} runs-on: ${{ matrix.runs-on }}
env: env:
ENVIRONMENT: testing ENVIRONMENT: testing
LIBRETIME_LOG_DIR: /tmp/log/libretime
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -103,10 +102,7 @@ jobs:
${{ runner.os }}-composer- ${{ runner.os }}-composer-
- name: Run tests - name: Run tests
run: | run: make test
sudo mkdir -p "$LIBRETIME_LOG_DIR"
sudo chown runner:runner "$LIBRETIME_LOG_DIR"
make test
working-directory: legacy working-directory: legacy
# Start lint the code without failing the entire workflow, should be merged # Start lint the code without failing the entire workflow, should be merged

View File

@ -1,24 +1,23 @@
<?php <?php
require_once CONFIG_PATH . 'conf.php'; require_once 'preload.php';
$CC_CONFIG = Config::getConfig(); $CC_CONFIG = Config::getConfig();
require_once CONFIG_PATH . 'ACL.php'; require_once CONFIG_PATH . '/ACL.php';
// Since we initialize the database during the configuration check, // Since we initialize the database during the configuration check,
// check the $configRun global to avoid reinitializing unnecessarily // check the $configRun global to avoid reinitializing unnecessarily
if (!isset($configRun) || !$configRun) { if (!isset($configRun) || !$configRun) {
Propel::init(CONFIG_PATH . 'airtime-conf-production.php'); Propel::init(PROPEL_CONFIG_FILEPATH);
} }
require_once CONFIG_PATH . 'constants.php'; Logging::setLogPath(LIBRETIME_LOG_FILEPATH);
Logging::setLogPath(LIBRETIME_LOG_DIR . '/legacy.log');
Zend_Session::setOptions(['strict' => true]); Zend_Session::setOptions(['strict' => true]);
Config::setAirtimeVersion(); Config::setAirtimeVersion();
require_once CONFIG_PATH . 'navigation.php'; require_once CONFIG_PATH . '/navigation.php';
Zend_Validate::setDefaultNamespaces('Zend'); Zend_Validate::setDefaultNamespaces('Zend');

View File

@ -27,56 +27,46 @@ function exception_error_handler($errno, $errstr, $errfile, $errline)
set_error_handler('exception_error_handler'); set_error_handler('exception_error_handler');
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
defined('VERBOSE_STACK_TRACE')
|| define('VERBOSE_STACK_TRACE', (getenv('VERBOSE_STACK_TRACE') ? getenv('VERBOSE_STACK_TRACE') : true));
// Ensure library/ is on include_path // Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, [ set_include_path(implode(PATH_SEPARATOR, [
get_include_path(), get_include_path(),
realpath(LIB_PATH), realpath(LIB_PATH),
])); ]));
set_include_path(APPLICATION_PATH . 'common' . PATH_SEPARATOR . get_include_path()); set_include_path(APPLICATION_PATH . '/common' . PATH_SEPARATOR . get_include_path());
set_include_path(APPLICATION_PATH . 'common/enum' . PATH_SEPARATOR . get_include_path()); set_include_path(APPLICATION_PATH . '/common/enum' . PATH_SEPARATOR . get_include_path());
set_include_path(APPLICATION_PATH . 'common/interface' . PATH_SEPARATOR . get_include_path()); set_include_path(APPLICATION_PATH . '/common/interface' . PATH_SEPARATOR . get_include_path());
//Propel classes. //Propel classes.
set_include_path(APPLICATION_PATH . 'models' . PATH_SEPARATOR . get_include_path()); set_include_path(APPLICATION_PATH . '/models' . PATH_SEPARATOR . get_include_path());
//Controller plugins. //Controller plugins.
set_include_path(APPLICATION_PATH . 'controllers' . PATH_SEPARATOR . get_include_path()); set_include_path(APPLICATION_PATH . '/controllers' . PATH_SEPARATOR . get_include_path());
//Controller plugins. //Controller plugins.
set_include_path(APPLICATION_PATH . 'controllers/plugins' . PATH_SEPARATOR . get_include_path()); set_include_path(APPLICATION_PATH . '/controllers/plugins' . PATH_SEPARATOR . get_include_path());
//Services. //Services.
set_include_path(APPLICATION_PATH . '/services/' . PATH_SEPARATOR . get_include_path()); set_include_path(APPLICATION_PATH . '/services' . PATH_SEPARATOR . get_include_path());
//cloud storage directory //cloud storage directory
set_include_path(APPLICATION_PATH . '/cloud_storage' . PATH_SEPARATOR . get_include_path()); set_include_path(APPLICATION_PATH . '/cloud_storage' . PATH_SEPARATOR . get_include_path());
//Upgrade directory //Upgrade directory
set_include_path(APPLICATION_PATH . '/upgrade/' . PATH_SEPARATOR . get_include_path()); set_include_path(APPLICATION_PATH . '/upgrade' . PATH_SEPARATOR . get_include_path());
//Common directory //Common directory
set_include_path(APPLICATION_PATH . '/common/' . PATH_SEPARATOR . get_include_path()); set_include_path(APPLICATION_PATH . '/common' . PATH_SEPARATOR . get_include_path());
//Composer's autoloader
require_once 'autoload.php';
/** Zend_Application */ /** Zend_Application */
$application = new Zend_Application( $application = new Zend_Application(
APPLICATION_ENV, APPLICATION_ENV,
CONFIG_PATH . 'application.ini', CONFIG_PATH . '/application.ini',
true true
); );
require_once APPLICATION_PATH . 'logging/Logging.php'; require_once APPLICATION_PATH . '/logging/Logging.php';
Logging::setLogPath(LIBRETIME_LOG_DIR . '/legacy.log'); Logging::setLogPath(LIBRETIME_LOG_FILEPATH);
Logging::setupParseErrorLogging(); Logging::setupParseErrorLogging();
// Create application, bootstrap, and run // Create application, bootstrap, and run

View File

@ -17,7 +17,7 @@ class ProxyStorageBackend extends StorageBackend
{ {
$CC_CONFIG = Config::getConfig(); $CC_CONFIG = Config::getConfig();
// The storage backend in the airtime.conf directly corresponds to // The storage backend in the config file directly corresponds to
// the name of the class that implements it, so we can create the // the name of the class that implements it, so we can create the
// right backend object dynamically: // right backend object dynamically:
if ($storageBackend == 'file') { if ($storageBackend == 'file') {

View File

@ -5,7 +5,7 @@
/* The original name of this file is airtime-conf.php but since we need to make custom changes /* The original name of this file is airtime-conf.php but since we need to make custom changes
* to it I've renamed it so that our changes aren't removed everytime we regenerate a database schema. * to it I've renamed it so that our changes aren't removed everytime we regenerate a database schema.
* our custom changes requires the database parameters to be loaded from /etc/airtime/airtime.conf so * our custom changes requires the database parameters to be loaded from the config file so
* that the user can customize these. * that the user can customize these.
*/ */

View File

@ -1,29 +1,18 @@
<?php <?php
/* THIS FILE IS NOT MEANT FOR CUSTOMIZING.
* PLEASE EDIT THE FOLLOWING TO CHANGE YOUR CONFIG:
* LIBRETIME_CONF_DIR/airtime.conf
*/
require_once __DIR__ . '/constants.php'; // THIS FILE IS NOT MEANT FOR CUSTOMIZING.
class Config class Config
{ {
private static $CC_CONFIG; private static $CC_CONFIG;
private static $rootDir;
public static function loadConfig() public static function loadConfig()
{ {
self::$rootDir = __DIR__ . '/../..'; $filename = $_SERVER['LIBRETIME_CONFIG_FILEPATH'] ?? LIBRETIME_CONFIG_FILEPATH;
$CC_CONFIG = [
// ================================================ storage configuration
'rootDir' => self::$rootDir,
];
//In the unit testing environment, LIBRETIME_CONF_DIR will our local airtime.conf in legacy/application/test/conf:
$filename = isset($_SERVER['AIRTIME_CONF']) ? $_SERVER['AIRTIME_CONF'] : LIBRETIME_CONF_DIR . '/airtime.conf';
$values = parse_ini_file($filename, true); $values = parse_ini_file($filename, true);
$CC_CONFIG = [];
// Name of the web server user // Name of the web server user
$CC_CONFIG['webServerUser'] = $values['general']['web_server_user']; $CC_CONFIG['webServerUser'] = $values['general']['web_server_user'];
$CC_CONFIG['rabbitmq'] = $values['rabbitmq']; $CC_CONFIG['rabbitmq'] = $values['rabbitmq'];
@ -97,7 +86,7 @@ class Config
public static function setAirtimeVersion() public static function setAirtimeVersion()
{ {
$version = @file_get_contents(self::$rootDir . '/../VERSION'); $version = @file_get_contents(dirname(ROOT_PATH) . '/VERSION');
if (!$version) { if (!$version) {
// fallback to constant from constants.php if no other info is available // fallback to constant from constants.php if no other info is available
$version = LIBRETIME_MAJOR_VERSION; $version = LIBRETIME_MAJOR_VERSION;

View File

@ -140,7 +140,7 @@ $result = $r1 && $r2;
?>"> ?>">
Make sure you aren't missing any of the Postgres dependencies in the table above. Make sure you aren't missing any of the Postgres dependencies in the table above.
If your dependencies check out, make sure your database configuration settings in If your dependencies check out, make sure your database configuration settings in
<code>/etc/airtime.conf</code> are correct and the Airtime database was installed correctly. <code><?php echo LIBRETIME_CONFIG_FILEPATH; ?></code> are correct and the Airtime database was installed correctly.
<?php <?php
} }
?> ?>
@ -158,7 +158,7 @@ $result = $r1 && $r2;
<?php <?php
} else { } else {
?>"> ?>">
Make sure RabbitMQ is installed correctly, and that your settings in /etc/airtime/airtime.conf Make sure RabbitMQ is installed correctly, and that your settings in <?php echo LIBRETIME_CONFIG_FILEPATH; ?>
are correct. Try using <code>sudo rabbitmqctl list_users</code> and <code>sudo rabbitmqctl list_vhosts</code> are correct. Try using <code>sudo rabbitmqctl list_users</code> and <code>sudo rabbitmqctl list_vhosts</code>
to see if the airtime user (or your custom RabbitMQ user) exists, then checking that to see if the airtime user (or your custom RabbitMQ user) exists, then checking that
<code>sudo rabbitmqctl list_exchanges</code> contains entries for airtime-pypo and airtime-uploads. <code>sudo rabbitmqctl list_exchanges</code> contains entries for airtime-pypo and airtime-uploads.

View File

@ -1,5 +1,34 @@
<?php <?php
// Path constants
define('ROOT_PATH', dirname(__DIR__, 2));
define('LIB_PATH', ROOT_PATH . '/library');
define('BUILD_PATH', ROOT_PATH . '/build');
define('SETUP_PATH', BUILD_PATH . '/airtime-setup');
define('APPLICATION_PATH', ROOT_PATH . '/application');
define('CONFIG_PATH', APPLICATION_PATH . '/configs');
define('VENDOR_PATH', ROOT_PATH . '/vendor');
define('SAMPLE_CONFIG_FILEPATH', BUILD_PATH . '/airtime.example.conf');
define('PROPEL_CONFIG_FILEPATH', CONFIG_PATH . '/airtime-conf-production.php');
// Define application environment
defined('APPLICATION_ENV') || define('APPLICATION_ENV', getenv('APPLICATION_ENV') ?: 'production');
defined('VERBOSE_STACK_TRACE') || define('VERBOSE_STACK_TRACE', getenv('VERBOSE_STACK_TRACE') ?? true);
// Project constants
define('LIBRETIME_LOG_DIR', getenv('LIBRETIME_LOG_DIR') ?: '/var/log/libretime');
define('LIBRETIME_LOG_FILEPATH', getenv('LIBRETIME_LOG_FILEPATH') ?: LIBRETIME_LOG_DIR . '/legacy.log');
define('LIBRETIME_CONFIG_DIR', getenv('LIBRETIME_CONFIG_DIR') ?: '/etc/airtime');
define('LIBRETIME_CONF_DIR', LIBRETIME_CONFIG_DIR); // Deprecated
define('LIBRETIME_CONFIG_FILEPATH', getenv('LIBRETIME_CONFIG_FILEPATH') ?: LIBRETIME_CONFIG_DIR . '/airtime.conf');
// Installer
define('INSTALLER_CONFIG_FILEPATH', LIBRETIME_CONFIG_DIR . '/airtime.conf.temp');
define('INSTALLER_DEFAULT_STORAGE_PATH', '/srv/libretime/storage');
// Legacy constants
define('PRODUCT_NAME', 'LibreTime'); define('PRODUCT_NAME', 'LibreTime');
define('PRODUCT_SITE_URL', 'http://libretime.org'); define('PRODUCT_SITE_URL', 'http://libretime.org');
@ -34,10 +63,6 @@ define('AIRTIME_API_VERSION', '1.1');
// XXX: it's important that we upgrade this on major version bumps, usually users get more exact info from VERSION in airtime root dir // XXX: it's important that we upgrade this on major version bumps, usually users get more exact info from VERSION in airtime root dir
define('LIBRETIME_MAJOR_VERSION', '3'); define('LIBRETIME_MAJOR_VERSION', '3');
// grab values from env (i'll do this everywhere with a small function if we like it)
define('LIBRETIME_CONF_DIR', getenv('LIBRETIME_CONF_DIR') ? getenv('LIBRETIME_CONF_DIR') : '/etc/airtime');
define('LIBRETIME_LOG_DIR', getenv('LIBRETIME_LOG_DIR') ? getenv('LIBRETIME_LOG_DIR') : '/var/log/libretime');
// Defaults // Defaults
define('DEFAULT_LOGO_PLACEHOLDER', 1); define('DEFAULT_LOGO_PLACEHOLDER', 1);
define('DEFAULT_LOGO_FILE', 'images/airtime_logo.png'); define('DEFAULT_LOGO_FILE', 'images/airtime_logo.png');
@ -106,9 +131,6 @@ define('UI_PLAYLISTCONTROLLER_OBJ_SESSNAME', 'PLAYLISTCONTROLLER_OBJ');
/*define('UI_PLAYLIST_SESSNAME', 'PLAYLIST'); /*define('UI_PLAYLIST_SESSNAME', 'PLAYLIST');
define('UI_BLOCK_SESSNAME', 'BLOCK');*/ define('UI_BLOCK_SESSNAME', 'BLOCK');*/
//Sentry error logging
define('SENTRY_CONFIG_PATH', LIBRETIME_CONF_DIR . '/sentry.airtime_web.ini');
//TuneIn integration //TuneIn integration
define('TUNEIN_API_URL', 'http://air.radiotime.com/Playing.ashx'); define('TUNEIN_API_URL', 'http://air.radiotime.com/Playing.ashx');

View File

@ -1,10 +0,0 @@
<?php
/* This file is only needed during upgrades when we need the database parameters from /etc/airtime/airtime.conf.
* The reason we don't just use conf.php is because conf.php may try to load configuration parameters that aren't
* yet available because airtime.conf hasn't been updated yet. This situation ends up throwing a lot of errors to stdout.
* airtime*/
require_once 'conf.php';
$CC_CONFIG = Config::getConfig();

View File

@ -241,7 +241,7 @@ class PageLayoutInitPlugin extends Zend_Controller_Plugin_Abstract
protected function _initViewHelpers() protected function _initViewHelpers()
{ {
$view = $this->_bootstrap->getResource('view'); $view = $this->_bootstrap->getResource('view');
$view->addHelperPath(APPLICATION_PATH . 'views/helpers', 'Airtime_View_Helper'); $view->addHelperPath(APPLICATION_PATH . '/views/helpers', 'Airtime_View_Helper');
} }
protected function _initTitle() protected function _initTitle()

View File

@ -64,7 +64,7 @@
<?php echo _("Dashboard") ?> <?php echo _("Dashboard") ?>
</a> </a>
</div> </div>
<?php $subnavPrefix = "/showbuilder"; require_once APPLICATION_PATH . "views/scripts/partialviews/dashboard-sub-nav.php"; ?> <?php $subnavPrefix = "/showbuilder"; require_once APPLICATION_PATH . "/views/scripts/partialviews/dashboard-sub-nav.php"; ?>
<div class="media_type_selector dashboard_sub_nav" data-selection-id="<?php echo MediaType::PODCAST ?>"> <div class="media_type_selector dashboard_sub_nav" data-selection-id="<?php echo MediaType::PODCAST ?>">
<a href="<?php echo $subnavPrefix; ?>#podcasts"> <a href="<?php echo $subnavPrefix; ?>#podcasts">
<span class="selector-name"><i class='icon-headphones icon-white'></i><?php echo _("Podcasts") ?></span> <span class="selector-name"><i class='icon-headphones icon-white'></i><?php echo _("Podcasts") ?></span>

View File

@ -8,7 +8,7 @@ class Rest_PodcastController extends Zend_Rest_Controller
// Remove reliance on .phtml files to render requests // Remove reliance on .phtml files to render requests
$this->_helper->viewRenderer->setNoRender(true); $this->_helper->viewRenderer->setNoRender(true);
$this->view->setScriptPath(APPLICATION_PATH . 'views/scripts/'); $this->view->setScriptPath(APPLICATION_PATH . '/views/scripts/');
} }
/** /**

View File

@ -0,0 +1,7 @@
<?php
require_once __DIR__ . '/configs/constants.php';
require_once VENDOR_PATH . '/autoload.php';
require_once CONFIG_PATH . '/conf.php';

View File

@ -1,7 +1,7 @@
<div><!-- jQuery UI changes the styling on the outermost div; use a blank div so as not to break the .wrapper styling--> <div><!-- jQuery UI changes the styling on the outermost div; use a blank div so as not to break the .wrapper styling-->
<div class="wrapper"> <div class="wrapper">
<div id="media_selector_wrapper"> <div id="media_selector_wrapper">
<?php $subnavPrefix = ""; require_once APPLICATION_PATH . "views/scripts/partialviews/dashboard-sub-nav.php"; ?> <?php $subnavPrefix = ""; require_once APPLICATION_PATH . "/views/scripts/partialviews/dashboard-sub-nav.php"; ?>
</div> </div>
<?php echo $this->csrf ?> <?php echo $this->csrf ?>

View File

@ -1,9 +1,9 @@
<?php <?php
$tempConfigPath = '/etc/airtime/airtime.conf.tmp'; $tempConfigPath = INSTALLER_CONFIG_FILEPATH;
if (file_exists($tempConfigPath)) { if (file_exists($tempConfigPath)) {
$airtimeConfig = parse_ini_file($tempConfigPath, true); $airtimeConfig = parse_ini_file($tempConfigPath, true);
$db = $airtimeConfig['database']; $db = $airtimeConfig['database'];
} }
?> ?>
<form action="#" role="form" id="dbSettingsForm"> <form action="#" role="form" id="dbSettingsForm">

View File

@ -11,16 +11,16 @@
sudo systemctl start libretime-api sudo systemctl start libretime-api
sudo systemctl start libretime-celery sudo systemctl start libretime-celery
sudo systemctl start libretime-liquidsoap sudo systemctl start libretime-liquidsoap
sudo systemctl start libretime-playout</pre sudo systemctl start libretime-playout</pre>
<p> <p>
Click "Done!" to bring up the Libretime configuration checklist; if your configuration is all green, Click "Done!" to bring up the Libretime configuration checklist; if your configuration is all green,
you're ready to get started with your personal Libretime station! you're ready to get started with your personal Libretime station!
</p> </p>
<p> <p>
If you need to re-run the web installer, just remove <code>/etc/airtime/airtime.conf</code>. If you need to re-run the web installer, just remove <code><?php echo LIBRETIME_CONFIG_FILEPATH; ?></code>.
</p> </p>
<div> <div>
<input type="submit" formtarget="finishSettingsForm" class="btn btn-primary btn-next" value="Done!"/> <input type="submit" formtarget="finishSettingsForm" class="btn btn-primary btn-next" value="Done!" />
</div> </div>
</form> </form>

View File

@ -1,9 +1,9 @@
<?php <?php
$tempConfigPath = '/etc/airtime/airtime.conf.tmp'; $tempConfigPath = INSTALLER_CONFIG_FILEPATH;
if (file_exists($tempConfigPath)) { if (file_exists($tempConfigPath)) {
$airtimeConfig = parse_ini_file($tempConfigPath, true); $airtimeConfig = parse_ini_file($tempConfigPath, true);
$rmq = $airtimeConfig['rabbitmq']; $rmq = $airtimeConfig['rabbitmq'];
} }
?> ?>
<form action="#" role="form" id="rmqSettingsForm"> <form action="#" role="form" id="rmqSettingsForm">

View File

@ -92,7 +92,7 @@ function checkDatabaseConfiguration()
*/ */
function configureDatabase() function configureDatabase()
{ {
Propel::init(CONFIG_PATH . 'airtime-conf-production.php'); Propel::init(PROPEL_CONFIG_FILEPATH);
} }
/** /**
@ -102,11 +102,11 @@ function configureDatabase()
*/ */
function checkRMQConnection() function checkRMQConnection()
{ {
// Check for airtime.conf in /etc/airtime/ first, then check in the build directory, // Check for installed config file first, then check in the build directory,
if (file_exists(AIRTIME_CONFIG_STOR . AIRTIME_CONFIG)) { if (file_exists(LIBRETIME_CONFIG_FILEPATH)) {
$ini = parse_ini_file(AIRTIME_CONFIG_STOR . AIRTIME_CONFIG, true); $ini = parse_ini_file(LIBRETIME_CONFIG_FILEPATH, true);
} else { } else {
$ini = parse_ini_file(BUILD_PATH . 'airtime.example.conf', true); $ini = parse_ini_file(SAMPLE_CONFIG_FILEPATH, true);
} }
$conn = new \PhpAmqpLib\Connection\AMQPStreamConnection( $conn = new \PhpAmqpLib\Connection\AMQPStreamConnection(

View File

@ -1,4 +1,7 @@
<?php <?php
require_once dirname(__DIR__, 2) . '/application/preload.php';
?> ?>
<html> <html>
@ -23,27 +26,27 @@
<div class="form-slider"> <div class="form-slider">
<div id="databaseSettings" class="form-wrapper"> <div id="databaseSettings" class="form-wrapper">
<?php <?php
require_once SETUP_PATH . 'forms/database-settings.php'; require_once SETUP_PATH . '/forms/database-settings.php';
?> ?>
</div> </div>
<div id="rabbitmqSettings" class="form-wrapper"> <div id="rabbitmqSettings" class="form-wrapper">
<?php <?php
require_once SETUP_PATH . 'forms/rabbitmq-settings.php'; require_once SETUP_PATH . '/forms/rabbitmq-settings.php';
?> ?>
</div> </div>
<div id="generalSettings" class="form-wrapper"> <div id="generalSettings" class="form-wrapper">
<?php <?php
require_once SETUP_PATH . 'forms/general-settings.php'; require_once SETUP_PATH . '/forms/general-settings.php';
?> ?>
</div> </div>
<div id="mediaSettings" class="form-wrapper"> <div id="mediaSettings" class="form-wrapper">
<?php <?php
require_once SETUP_PATH . 'forms/media-settings.php'; require_once SETUP_PATH . '/forms/media-settings.php';
?> ?>
</div> </div>
<div id="finishSettings" class="form-wrapper"> <div id="finishSettings" class="form-wrapper">
<?php <?php
require_once SETUP_PATH . 'forms/finish-settings.php'; require_once SETUP_PATH . '/forms/finish-settings.php';
?> ?>
</div> </div>
</div> </div>

View File

@ -1,5 +1,7 @@
<?php <?php
require_once dirname(__DIR__) . '/application/preload.php';
$configRun = false; $configRun = false;
$extensions = get_loaded_extensions(); $extensions = get_loaded_extensions();
$airtimeSetup = false; $airtimeSetup = false;
@ -13,7 +15,7 @@ function showConfigCheckPage()
checkConfiguration(); checkConfiguration();
} }
require_once CONFIG_PATH . 'config-check.php'; require_once CONFIG_PATH . '/config-check.php';
exit(); exit();
} }
@ -25,38 +27,20 @@ function isApiCall()
return strpos($path, 'api') !== false; return strpos($path, 'api') !== false;
} }
// Define application path constants
define('ROOT_PATH', dirname(__DIR__) . '/');
define('LIB_PATH', ROOT_PATH . 'library/');
define('BUILD_PATH', ROOT_PATH . 'build/');
define('SETUP_PATH', BUILD_PATH . 'airtime-setup/');
define('APPLICATION_PATH', ROOT_PATH . 'application/');
define('CONFIG_PATH', APPLICATION_PATH . 'configs/');
define('VENDOR_PATH', ROOT_PATH . 'vendor/');
define('REST_MODULE_CONTROLLER_PATH', APPLICATION_PATH . 'modules/rest/controllers/');
define('AIRTIME_CONFIG_STOR', '/etc/airtime/');
define('AIRTIME_CONFIG', 'airtime.conf');
//Rest Module Controllers - for custom Rest_RouteController.php //Rest Module Controllers - for custom Rest_RouteController.php
set_include_path(REST_MODULE_CONTROLLER_PATH . PATH_SEPARATOR . get_include_path()); set_include_path(APPLICATION_PATH . '/modules/rest/controllers/' . PATH_SEPARATOR . get_include_path());
// Vendors (Composer, zend-loader is explicitly specified due to https://github.com/zf1/zend-application/pull/2#issuecomment-102599655) // Vendors (Composer, zend-loader is explicitly specified due to https://github.com/zf1/zend-application/pull/2#issuecomment-102599655)
set_include_path(VENDOR_PATH . PATH_SEPARATOR . VENDOR_PATH . 'zf1s/zend-loader/library/' . PATH_SEPARATOR . get_include_path()); set_include_path(VENDOR_PATH . PATH_SEPARATOR . VENDOR_PATH . '/zf1s/zend-loader/library/' . PATH_SEPARATOR . get_include_path());
// Ensure library/ is on include_path // Ensure library/ is on include_path
set_include_path(LIB_PATH . PATH_SEPARATOR . get_include_path()); set_include_path(LIB_PATH . PATH_SEPARATOR . get_include_path());
require_once VENDOR_PATH . 'autoload.php';
if (!class_exists('Propel')) { if (!class_exists('Propel')) {
exit('Error: Propel not found. Did you install Airtime\'s third-party dependencies with composer? (Check the README.)'); exit('Error: Propel not found. Did you install Airtime\'s third-party dependencies with composer? (Check the README.)');
} }
require_once CONFIG_PATH . 'conf.php'; require_once SETUP_PATH . '/load.php';
require_once SETUP_PATH . 'load.php';
// This allows us to pass ?config as a parameter to any page // This allows us to pass ?config as a parameter to any page
// and get to the config checklist. // and get to the config checklist.
@ -64,16 +48,13 @@ if (array_key_exists('config', $_GET)) {
showConfigCheckPage(); showConfigCheckPage();
} }
$filename = isset($_SERVER['AIRTIME_CONF']) ?
$_SERVER['AIRTIME_CONF'] : AIRTIME_CONFIG_STOR . AIRTIME_CONFIG;
// If a configuration file exists, forward to our boot script // If a configuration file exists, forward to our boot script
if (file_exists($filename)) { if (file_exists(LIBRETIME_CONFIG_FILEPATH)) {
require_once APPLICATION_PATH . 'airtime-boot.php'; require_once APPLICATION_PATH . '/airtime-boot.php';
} }
// Otherwise, we'll need to run our configuration setup // Otherwise, we'll need to run our configuration setup
else { else {
$airtimeSetup = true; $airtimeSetup = true;
require_once SETUP_PATH . 'setup-config.php'; require_once SETUP_PATH . '/setup-config.php';
} }

View File

@ -8,7 +8,7 @@
*/ */
class DatabaseSetup extends Setup class DatabaseSetup extends Setup
{ {
// airtime.conf section header // config file section header
protected static $_section = '[database]'; protected static $_section = '[database]';
// Constant form field names for passing errors back to the front-end // Constant form field names for passing errors back to the front-end
@ -17,7 +17,7 @@ class DatabaseSetup extends Setup
public const DB_NAME = 'dbName'; public const DB_NAME = 'dbName';
public const DB_HOST = 'dbHost'; public const DB_HOST = 'dbHost';
// Array of key->value pairs for airtime.conf // Array of key->value pairs for the config file
protected static $_properties; protected static $_properties;
/** /**
@ -294,6 +294,6 @@ class DatabaseSetup extends Setup
*/ */
private function updateDjangoTables() private function updateDjangoTables()
{ {
shell_exec('LIBRETIME_CONFIG_FILEPATH=/etc/airtime/airtime.conf.temp libretime-api migrate'); shell_exec('LIBRETIME_CONFIG_FILEPATH=' . INSTALLER_CONFIG_FILEPATH . ' libretime-api migrate');
} }
} }

View File

@ -1,25 +1,5 @@
<?php <?php
define('CONFIG_PATH', dirname(__DIR__, 2) . '/application/configs/');
require_once dirname(__DIR__, 2) . '/vendor/jooola/propel1/runtime/lib/Propel.php';
require_once CONFIG_PATH . 'conf.php';
require_once dirname(__DIR__, 2) . '/application/models/airtime/CcPref.php';
require_once dirname(__DIR__, 2) . '/application/models/airtime/CcPrefPeer.php';
require_once dirname(__DIR__, 2) . '/application/models/airtime/CcPrefQuery.php';
require_once dirname(__DIR__, 2) . '/application/models/airtime/map/CcPrefTableMap.php';
require_once dirname(__DIR__, 2) . '/application/models/airtime/om/BaseCcPref.php';
require_once dirname(__DIR__, 2) . '/application/models/airtime/om/BaseCcPrefPeer.php';
require_once dirname(__DIR__, 2) . '/application/models/airtime/om/BaseCcPrefQuery.php';
/** /**
* User: sourcefabric * User: sourcefabric
* Date: 08/12/14. * Date: 08/12/14.
@ -30,10 +10,10 @@ require_once dirname(__DIR__, 2) . '/application/models/airtime/om/BaseCcPrefQue
*/ */
class GeneralSetup extends Setup class GeneralSetup extends Setup
{ {
// airtime.conf section header // config file section header
protected static $_section = '[general]'; protected static $_section = '[general]';
// Array of key->value pairs for airtime.conf // Array of key->value pairs for the config file
protected static $_properties; protected static $_properties;
// Constant form field names for passing errors back to the front-end // Constant form field names for passing errors back to the front-end
@ -86,8 +66,8 @@ class GeneralSetup extends Setup
public function setupCorsUrl() public function setupCorsUrl()
{ {
try { try {
$_SERVER['AIRTIME_CONF'] = AIRTIME_CONF_TEMP_PATH; $_SERVER['LIBRETIME_CONFIG_FILEPATH'] = INSTALLER_CONFIG_FILEPATH;
Propel::init(CONFIG_PATH . 'airtime-conf-production.php'); Propel::init(PROPEL_CONFIG_FILEPATH);
$con = Propel::getConnection(); $con = Propel::getConnection();
} catch (Exception $e) { } catch (Exception $e) {
self::$message = "Failed to insert Cors URL; database isn't configured properly!"; self::$message = "Failed to insert Cors URL; database isn't configured properly!";
@ -104,7 +84,6 @@ class GeneralSetup extends Setup
try { try {
Application_Model_Preference::SetAllowedCorsUrls(self::$cors_url); Application_Model_Preference::SetAllowedCorsUrls(self::$cors_url);
Propel::close(); Propel::close();
//unset($_SERVER['AIRTIME_CONF']);
} catch (Exception $e) { } catch (Exception $e) {
self::$message = 'Failed to insert ' . self::$cors_url . ' into cc_pref' . $e; self::$message = 'Failed to insert ' . self::$cors_url . ' into cc_pref' . $e;
self::$errors[] = self::CORS_URL; self::$errors[] = self::CORS_URL;

View File

@ -1,26 +1,5 @@
<?php <?php
define('CONFIG_PATH', dirname(__DIR__, 2) . '/application/configs/');
define('DEFAULT_STOR_DIR', '/srv/airtime/stor/');
require_once dirname(__DIR__, 2) . '/vendor/jooola/propel1/runtime/lib/Propel.php';
require_once CONFIG_PATH . 'conf.php';
require_once dirname(__DIR__, 2) . '/application/models/airtime/map/CcMusicDirsTableMap.php';
require_once dirname(__DIR__, 2) . '/application/models/airtime/om/BaseCcMusicDirsQuery.php';
require_once dirname(__DIR__, 2) . '/application/models/airtime/CcMusicDirsQuery.php';
require_once dirname(__DIR__, 2) . '/application/models/airtime/om/BaseCcMusicDirs.php';
require_once dirname(__DIR__, 2) . '/application/models/airtime/CcMusicDirs.php';
require_once dirname(__DIR__, 2) . '/application/models/airtime/om/BaseCcMusicDirsPeer.php';
require_once dirname(__DIR__, 2) . '/application/models/airtime/CcMusicDirsPeer.php';
/** /**
* Author: sourcefabric * Author: sourcefabric
* Date: 08/12/14. * Date: 08/12/14.
@ -32,7 +11,6 @@ require_once dirname(__DIR__, 2) . '/application/models/airtime/CcMusicDirsPeer.
class MediaSetup extends Setup class MediaSetup extends Setup
{ {
public const MEDIA_FOLDER = 'mediaFolder'; public const MEDIA_FOLDER = 'mediaFolder';
public const LIBRETIME_CONF_FILE_NAME = 'airtime.conf';
public static $path; public static $path;
public static $message; public static $message;
@ -50,9 +28,9 @@ class MediaSetup extends Setup
{ {
// If the path passed in is empty, set it to the default // If the path passed in is empty, set it to the default
if (strlen(self::$path) == 0) { if (strlen(self::$path) == 0) {
self::$path = DEFAULT_STOR_DIR; self::$path = INSTALLER_DEFAULT_STORAGE_PATH;
if (!file_exists(DEFAULT_STOR_DIR)) { if (!file_exists(INSTALLER_DEFAULT_STORAGE_PATH)) {
mkdir(DEFAULT_STOR_DIR, 0755, true); mkdir(INSTALLER_DEFAULT_STORAGE_PATH, 0755, true);
} }
} }
@ -68,10 +46,10 @@ class MediaSetup extends Setup
self::$errors[] = self::MEDIA_FOLDER; self::$errors[] = self::MEDIA_FOLDER;
} }
// Finalize and move airtime.conf.temp // Finalize and move installer config file to libretime config file
if (file_exists('/etc/airtime/')) { if (file_exists(LIBRETIME_CONFIG_DIR)) {
if (!$this->moveAirtimeConfig()) { if (!$this->moveAirtimeConfig()) {
self::$message = 'Error moving airtime.conf or deleting /tmp/airtime.conf.temp!'; self::$message = 'Error moving or deleting the installer config!';
self::$errors[] = 'ERR'; self::$errors[] = 'ERR';
} }
@ -80,7 +58,7 @@ class MediaSetup extends Setup
* airtime.conf to airtime.conf.tmp during the setup process. Now that we're done, * airtime.conf to airtime.conf.tmp during the setup process. Now that we're done,
* we can rename it to airtime.conf.bak to avoid confusion. * we can rename it to airtime.conf.bak to avoid confusion.
*/ */
$fileName = LIBRETIME_CONF_DIR . '/' . self::LIBRETIME_CONF_FILE_NAME; $fileName = LIBRETIME_CONFIG_FILEPATH;
$tmpFile = $fileName . '.tmp'; $tmpFile = $fileName . '.tmp';
$bakFile = $fileName . '.bak'; $bakFile = $fileName . '.bak';
if (file_exists($tmpFile)) { if (file_exists($tmpFile)) {
@ -104,8 +82,8 @@ class MediaSetup extends Setup
*/ */
public function moveAirtimeConfig() public function moveAirtimeConfig()
{ {
return copy(AIRTIME_CONF_TEMP_PATH, LIBRETIME_CONF_DIR . '/' . self::LIBRETIME_CONF_FILE_NAME) return copy(INSTALLER_CONFIG_FILEPATH, LIBRETIME_CONFIG_FILEPATH)
&& unlink(AIRTIME_CONF_TEMP_PATH); && unlink(INSTALLER_CONFIG_FILEPATH);
} }
/** /**
@ -115,8 +93,8 @@ class MediaSetup extends Setup
public function setupMusicDirectory() public function setupMusicDirectory()
{ {
try { try {
$_SERVER['AIRTIME_CONF'] = AIRTIME_CONF_TEMP_PATH; $_SERVER['LIBRETIME_CONFIG_FILEPATH'] = INSTALLER_CONFIG_FILEPATH;
Propel::init(CONFIG_PATH . 'airtime-conf-production.php'); Propel::init(PROPEL_CONFIG_FILEPATH);
$con = Propel::getConnection(); $con = Propel::getConnection();
} catch (Exception $e) { } catch (Exception $e) {
self::$message = "Failed to insert media folder; database isn't configured properly!"; self::$message = "Failed to insert media folder; database isn't configured properly!";

View File

@ -1,13 +1,6 @@
<?php <?php
define('BUILD_PATH', dirname(__DIR__, 2) . '/build/'); require_once dirname(__DIR__, 2) . '/application/preload.php';
define('AIRTIME_CONF_TEMP_PATH', '/etc/airtime/airtime.conf.temp');
define('RMQ_INI_TEMP_PATH', '/tmp/rabbitmq.ini.tmp');
// load autoloader since this files is an entry path see
// the end of the file for the "server" that is being
// executed.
require_once __DIR__ . '/../../vendor/autoload.php';
/** /**
* Class Setup. * Class Setup.
@ -36,11 +29,11 @@ abstract class Setup
*/ */
protected function writeToTemp() protected function writeToTemp()
{ {
if (!file_exists(AIRTIME_CONF_TEMP_PATH)) { if (!file_exists(INSTALLER_CONFIG_FILEPATH)) {
copy(BUILD_PATH . 'airtime.example.conf', AIRTIME_CONF_TEMP_PATH); copy(SAMPLE_CONFIG_FILEPATH, INSTALLER_CONFIG_FILEPATH);
} }
//Logging::info(AIRTIME_CONF_TEMP_PATH); //Logging::info(CONFIG_TEMP_FILEPATH);
$this->_write(AIRTIME_CONF_TEMP_PATH); $this->_write(INSTALLER_CONFIG_FILEPATH);
} }
protected function _write($filePath) protected function _write($filePath)

View File

@ -2,19 +2,7 @@
error_reporting(E_ALL | E_STRICT); error_reporting(E_ALL | E_STRICT);
// load composer autoloader require_once dirname(__DIR__, 2) . '/application/preload.php';
require_once __DIR__ . '/../../vendor/autoload.php';
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application/'));
// Define path to configs directory
define('CONFIG_PATH', APPLICATION_PATH . '/configs/');
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing'));
// Ensure library/ is on include_path // Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, [ set_include_path(implode(PATH_SEPARATOR, [
@ -46,9 +34,7 @@ set_include_path(implode(PATH_SEPARATOR, [
realpath(APPLICATION_PATH . '/../../install_minimal/include'), realpath(APPLICATION_PATH . '/../../install_minimal/include'),
])); ]));
require_once CONFIG_PATH . '/constants.php'; Logging::setLogPath(LIBRETIME_LOG_FILEPATH);
Logging::setLogPath(LIBRETIME_LOG_DIR . '/legacy.log');
set_include_path(APPLICATION_PATH . '/common' . PATH_SEPARATOR . get_include_path()); set_include_path(APPLICATION_PATH . '/common' . PATH_SEPARATOR . get_include_path());
@ -76,8 +62,6 @@ set_include_path(APPLICATION_PATH . '/../tests/application/helpers' . PATH_SEPAR
//cloud storage files //cloud storage files
set_include_path(APPLICATION_PATH . '/cloud_storage' . PATH_SEPARATOR . get_include_path()); set_include_path(APPLICATION_PATH . '/cloud_storage' . PATH_SEPARATOR . get_include_path());
require_once APPLICATION_PATH . '/configs/conf.php';
require_once 'jooola/propel1/runtime/lib/Propel.php'; require_once 'jooola/propel1/runtime/lib/Propel.php';
Propel::init('../application/configs/airtime-conf-production.php'); Propel::init('../application/configs/airtime-conf-production.php');

View File

@ -1,7 +1,5 @@
<?php <?php
require_once '../application/configs/conf.php';
/** /**
* @internal * @internal
* @coversNothing * @coversNothing

View File

@ -130,7 +130,7 @@ class TestHelper
public static function setupZendBootstrap() public static function setupZendBootstrap()
{ {
$application = new Zend_Application(APPLICATION_ENV, CONFIG_PATH . 'application.ini'); $application = new Zend_Application(APPLICATION_ENV, CONFIG_PATH . '/application.ini');
$application->bootstrap(); $application->bootstrap();
return $application; return $application;

View File

@ -1,7 +1,5 @@
<?php <?php
//require_once "../application/configs/conf.php";
/** /**
* @internal * @internal
* @coversNothing * @coversNothing

View File

@ -1,7 +1,5 @@
<?php <?php
require_once '../application/configs/conf.php';
/** /**
* @internal * @internal
* @coversNothing * @coversNothing

View File

@ -1,7 +1,5 @@
<?php <?php
//require_once "../application/configs/conf.php";
/** /**
* @internal * @internal
* @coversNothing * @coversNothing

View File

@ -1,28 +0,0 @@
[database]
host = localhost
dbname = libretime_test
dbuser = libretime
dbpass = libretime
[rabbitmq]
host = 127.0.0.1
port = 5672
user = airtime_tests
password = airtime_tests
vhost = /airtime_tests
[general]
dev_env = testing
api_key = H2NRICX6CM8F50CU123C
web_server_user = www-data
airtime_dir = /usr/share/airtime
base_url = localhost
base_port = 80
base_dir = /
cache_ahead_hours = 1
station_id = teststation
[monit]
monit_user = guest
monit_password = airtime

View File

@ -16,8 +16,9 @@
<php> <php>
<env name="ENVIRONMENT" value="testing" /> <env name="ENVIRONMENT" value="testing" />
<env name="AIRTIME_UNIT_TEST" value="1" /> <env name="APPLICATION_ENV" value="testing" />
<env name="LIBRETIME_CONF_DIR" value="./conf" /> <env name="LIBRETIME_UNIT_TEST" value="1" />
<env name="LIBRETIME_CONFIG_DIR" value="./config" />
<env name="LIBRETIME_LOG_DIR" value="./log" /> <env name="LIBRETIME_LOG_DIR" value="./log" />
</php> </php>

View File

@ -26,7 +26,7 @@ export RABBITMQ_USER
export RABBITMQ_PASSWORD export RABBITMQ_PASSWORD
export RABBITMQ_VHOST export RABBITMQ_VHOST
export AIRTIME_UNIT_TEST="1" export LIBRETIME_UNIT_TEST="1"
#Change the working directory to this script's directory #Change the working directory to this script's directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" && pwd)" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" && pwd)"