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:
parent
e106858fd8
commit
729a7b99e0
34 changed files with 133 additions and 257 deletions
|
@ -1,24 +1,23 @@
|
|||
<?php
|
||||
|
||||
require_once CONFIG_PATH . 'conf.php';
|
||||
require_once 'preload.php';
|
||||
|
||||
$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,
|
||||
// check the $configRun global to avoid reinitializing unnecessarily
|
||||
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_DIR . '/legacy.log');
|
||||
Logging::setLogPath(LIBRETIME_LOG_FILEPATH);
|
||||
|
||||
Zend_Session::setOptions(['strict' => true]);
|
||||
Config::setAirtimeVersion();
|
||||
|
||||
require_once CONFIG_PATH . 'navigation.php';
|
||||
require_once CONFIG_PATH . '/navigation.php';
|
||||
|
||||
Zend_Validate::setDefaultNamespaces('Zend');
|
||||
|
||||
|
|
|
@ -27,56 +27,46 @@ function exception_error_handler($errno, $errstr, $errfile, $errline)
|
|||
|
||||
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
|
||||
set_include_path(implode(PATH_SEPARATOR, [
|
||||
get_include_path(),
|
||||
realpath(LIB_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/interface' . 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/interface' . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
//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.
|
||||
set_include_path(APPLICATION_PATH . 'controllers' . PATH_SEPARATOR . get_include_path());
|
||||
set_include_path(APPLICATION_PATH . '/controllers' . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
//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.
|
||||
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
|
||||
set_include_path(APPLICATION_PATH . '/cloud_storage' . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
//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
|
||||
set_include_path(APPLICATION_PATH . '/common/' . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
//Composer's autoloader
|
||||
require_once 'autoload.php';
|
||||
set_include_path(APPLICATION_PATH . '/common' . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
/** Zend_Application */
|
||||
$application = new Zend_Application(
|
||||
APPLICATION_ENV,
|
||||
CONFIG_PATH . 'application.ini',
|
||||
CONFIG_PATH . '/application.ini',
|
||||
true
|
||||
);
|
||||
|
||||
require_once APPLICATION_PATH . 'logging/Logging.php';
|
||||
Logging::setLogPath(LIBRETIME_LOG_DIR . '/legacy.log');
|
||||
require_once APPLICATION_PATH . '/logging/Logging.php';
|
||||
Logging::setLogPath(LIBRETIME_LOG_FILEPATH);
|
||||
Logging::setupParseErrorLogging();
|
||||
|
||||
// Create application, bootstrap, and run
|
||||
|
|
|
@ -17,7 +17,7 @@ class ProxyStorageBackend extends StorageBackend
|
|||
{
|
||||
$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
|
||||
// right backend object dynamically:
|
||||
if ($storageBackend == 'file') {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
/* 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.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
|
|
@ -1,29 +1,18 @@
|
|||
<?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
|
||||
{
|
||||
private static $CC_CONFIG;
|
||||
private static $rootDir;
|
||||
|
||||
public static function loadConfig()
|
||||
{
|
||||
self::$rootDir = __DIR__ . '/../..';
|
||||
$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';
|
||||
|
||||
$filename = $_SERVER['LIBRETIME_CONFIG_FILEPATH'] ?? LIBRETIME_CONFIG_FILEPATH;
|
||||
$values = parse_ini_file($filename, true);
|
||||
|
||||
$CC_CONFIG = [];
|
||||
|
||||
// Name of the web server user
|
||||
$CC_CONFIG['webServerUser'] = $values['general']['web_server_user'];
|
||||
$CC_CONFIG['rabbitmq'] = $values['rabbitmq'];
|
||||
|
@ -97,7 +86,7 @@ class Config
|
|||
|
||||
public static function setAirtimeVersion()
|
||||
{
|
||||
$version = @file_get_contents(self::$rootDir . '/../VERSION');
|
||||
$version = @file_get_contents(dirname(ROOT_PATH) . '/VERSION');
|
||||
if (!$version) {
|
||||
// fallback to constant from constants.php if no other info is available
|
||||
$version = LIBRETIME_MAJOR_VERSION;
|
||||
|
|
|
@ -140,7 +140,7 @@ $result = $r1 && $r2;
|
|||
?>">
|
||||
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
|
||||
<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
|
||||
}
|
||||
?>
|
||||
|
@ -158,7 +158,7 @@ $result = $r1 && $r2;
|
|||
<?php
|
||||
} 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>
|
||||
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.
|
||||
|
|
|
@ -1,5 +1,34 @@
|
|||
<?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_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
|
||||
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
|
||||
define('DEFAULT_LOGO_PLACEHOLDER', 1);
|
||||
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_BLOCK_SESSNAME', 'BLOCK');*/
|
||||
|
||||
//Sentry error logging
|
||||
define('SENTRY_CONFIG_PATH', LIBRETIME_CONF_DIR . '/sentry.airtime_web.ini');
|
||||
|
||||
//TuneIn integration
|
||||
define('TUNEIN_API_URL', 'http://air.radiotime.com/Playing.ashx');
|
||||
|
||||
|
|
|
@ -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();
|
|
@ -241,7 +241,7 @@ class PageLayoutInitPlugin extends Zend_Controller_Plugin_Abstract
|
|||
protected function _initViewHelpers()
|
||||
{
|
||||
$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()
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
<?php echo _("Dashboard") ?>
|
||||
</a>
|
||||
</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 ?>">
|
||||
<a href="<?php echo $subnavPrefix; ?>#podcasts">
|
||||
<span class="selector-name"><i class='icon-headphones icon-white'></i><?php echo _("Podcasts") ?></span>
|
||||
|
|
|
@ -8,7 +8,7 @@ class Rest_PodcastController extends Zend_Rest_Controller
|
|||
|
||||
// Remove reliance on .phtml files to render requests
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
$this->view->setScriptPath(APPLICATION_PATH . 'views/scripts/');
|
||||
$this->view->setScriptPath(APPLICATION_PATH . '/views/scripts/');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
7
legacy/application/preload.php
Normal file
7
legacy/application/preload.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__ . '/configs/constants.php';
|
||||
|
||||
require_once VENDOR_PATH . '/autoload.php';
|
||||
|
||||
require_once CONFIG_PATH . '/conf.php';
|
|
@ -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 class="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>
|
||||
<?php echo $this->csrf ?>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue