From 494120b198f36ef6622eaa731d256bbdaf93657e Mon Sep 17 00:00:00 2001 From: Jamie Snape Date: Wed, 26 Aug 2015 17:56:33 -0400 Subject: [PATCH] Move all settings to database and ensure settings are cast to the correct type --- core/AppController.php | 33 ++- core/Bootstrap.php | 227 +++++++++++------- core/GlobalController.php | 46 ++-- core/configs/application.ini | 34 +-- core/controllers/AdminController.php | 64 ++--- core/controllers/DownloadController.php | 2 +- core/controllers/ErrorController.php | 25 +- core/controllers/InstallController.php | 25 +- core/controllers/UploadController.php | 9 +- core/controllers/UserController.php | 36 ++- .../components/ApisystemComponent.php | 16 +- .../components/AuthenticationComponent.php | 2 +- core/controllers/components/DateComponent.php | 51 ++-- .../InternationalizationComponent.php | 29 ++- .../components/MIDAS2MigrationComponent.php | 4 +- .../components/NotifyErrorComponent.php | 8 +- .../components/UpgradeComponent.php | 1 - .../components/UploadComponent.php | 6 +- .../components/UtilityComponent.php | 43 ++-- core/controllers/forms/AdminForm.php | 34 ++- core/database/upgrade/3.4.1.php | 35 ++- core/layouts/layout.phtml | 13 +- core/models/base/AssetstoreModelBase.php | 2 +- core/models/base/PendingUserModelBase.php | 2 +- core/models/base/SettingModelBase.php | 24 ++ core/models/base/UserModelBase.php | 15 +- core/tests/controllers/UserControllerTest.php | 15 +- .../controllers/api/RestKeyControllerTest.php | 4 + core/tests/databaseDataset/default.xml | 14 +- core/views/admin/index.phtml | 47 ++-- core/views/install/step3.phtml | 5 +- .../tests/controllers/KeyControllerTest.php | 4 + .../components/KWBatchmakeComponent.php | 2 +- modules/demo/Notification.php | 2 +- .../controllers/CallbackController.php | 4 +- .../controllers/UploadController.php | 12 +- modules/mail/Notification.php | 6 +- modules/mfa/Notification.php | 2 +- modules/mfa/controllers/LoginController.php | 2 +- modules/oai/library/oai/oaidp-util.php | 2 +- .../oauth/controllers/AuthorizeController.php | 2 +- modules/remoteprocessing/Notification.php | 2 +- .../controllers/components/SolrComponent.php | 2 +- .../components/ReportComponent.php | 7 +- .../components/ImagemagickComponent.php | 2 +- .../controllers/components/ApiComponent.php | 4 +- modules/visualize/Notification.php | 4 +- .../controllers/ParaviewController.php | 36 +-- .../visualize/controllers/TxtController.php | 2 +- .../controllers/components/MainComponent.php | 20 +- 50 files changed, 562 insertions(+), 426 deletions(-) diff --git a/core/AppController.php b/core/AppController.php index bad231838..412f50942 100644 --- a/core/AppController.php +++ b/core/AppController.php @@ -63,8 +63,10 @@ public function preDispatch() Zend_Registry::set('webroot', $this->view->webroot); Zend_Registry::set('coreWebroot', $this->view->coreWebroot); - $this->view->title = Zend_Registry::get('configGlobal')->application->name; - $this->view->metaDescription = Zend_Registry::get('configGlobal')->application->description; + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + $this->view->title = $settingModel->getValueByNameWithDefault('title', 'Midas Platform - Digital Archiving System'); + $this->view->metaDescription = $settingModel->getValueByNameWithDefault('description', ''); // Set the version $version = UtilityComponent::getCurrentModuleVersion('core'); @@ -82,7 +84,7 @@ public function preDispatch() // log in when testing $testingUserId = $this->getParam('testingUserId'); - if (Zend_Registry::get('configGlobal')->environment == 'testing' && isset($testingUserId) + if (Zend_Registry::get('configGlobal')->get('environment', 'production') === 'testing' && isset($testingUserId) ) { $user = new Zend_Session_Namespace('Auth_User_Testing'); @@ -94,7 +96,7 @@ public function preDispatch() } } else { $user = new Zend_Session_Namespace('Auth_User'); - $user->setExpirationSeconds(60 * Zend_Registry::get('configGlobal')->session->lifetime); + $user->setExpirationSeconds(60 * (int) Zend_Registry::get('configGlobal')->get('session_lifetime', 20)); } /** @var Zend_Controller_Request_Http $request */ @@ -193,7 +195,11 @@ public function preDispatch() // init notifier Zend_Registry::set('notifier', new MIDAS_Notifier($this->logged, $this->userSession)); - $this->view->lang = Zend_Registry::get('configGlobal')->application->lang; + if ((int) Zend_Registry::get('configGlobal')->get('internationalization', 0) === 1) { + $this->view->lang = $settingModel->getValueByNameWithDefault('language', 'en'); + } else { + $this->view->lang = 'en'; + } $this->view->isStartingGuide = $this->isStartingGuide(); $this->view->isDynamicHelp = $this->isDynamicHelp(); @@ -205,7 +211,7 @@ public function preDispatch() 'logged' => $this->logged, 'needToLog' => false, 'currentUri' => $this->getRequest()->REQUEST_URI, - 'lang' => Zend_Registry::get('configGlobal')->application->lang, + 'lang' => $this->view->lang, 'dynamichelp' => $this->isDynamicHelp(), 'dynamichelpAnimate' => $this->isDynamicHelp() && isset($_GET['first']), 'startingGuide' => $this->isStartingGuide(), @@ -336,7 +342,7 @@ public function preDispatch() } // If there is an outbound HTTP proxy configured on this server, set it up here - $httpProxy = Zend_Registry::get('configGlobal')->httpproxy; + $httpProxy = Zend_Registry::get('configGlobal')->get('http_proxy', false); if ($httpProxy) { $opts = array('http' => array('proxy' => $httpProxy)); stream_context_set_default($opts); @@ -351,15 +357,18 @@ public function preDispatch() public function isDynamicHelp() { try { - $dynamichelp = Zend_Registry::get('configGlobal')->dynamichelp; - if ($dynamichelp && $this->userSession != null) { + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + $dynamicHelp = $settingModel->getValueByNameWithDefault('dynamic_help', 0); + + if ($dynamicHelp && $this->userSession != null) { $userDao = $this->userSession->Dao; if ($userDao != null && $userDao instanceof UserDao) { return $userDao->getDynamichelp() == 1; } } - return $dynamichelp == 1; + return $dynamicHelp == 1; } catch (Zend_Exception $exc) { $this->getLogger()->warn($exc->getMessage()); @@ -404,7 +413,7 @@ public function getServerURL() */ public function isTestingEnv() { - return Zend_Registry::get('configGlobal')->environment == 'testing'; + return Zend_Registry::get('configGlobal')->get('environment', 'production') === 'testing'; } /** @@ -474,7 +483,7 @@ public function postDispatch() { parent::postDispatch(); $this->view->json = JsonComponent::encode($this->view->json); - if (Zend_Registry::get('configGlobal')->environment != 'testing') { + if (Zend_Registry::get('configGlobal')->get('environment', 'production') !== 'testing') { header('Content-Type: text/html; charset=UTF-8'); } if ($this->progressDao != null) { diff --git a/core/Bootstrap.php b/core/Bootstrap.php index 557741dd4..6d062822e 100644 --- a/core/Bootstrap.php +++ b/core/Bootstrap.php @@ -40,85 +40,153 @@ protected function _initDoctype() */ protected function _initConfig() { - // init language $configGlobal = new Zend_Config_Ini(APPLICATION_CONFIG, 'global', true); - if (isset($_COOKIE[MIDAS_LANGUAGE_COOKIE_NAME])) { - $configGlobal->application->lang = $_COOKIE[MIDAS_LANGUAGE_COOKIE_NAME]; - } - - if (isset($_GET['lang'])) { - $language = $_GET['lang']; - if ($language !== 'en' && $language !== 'fr') { - $language = 'en'; - } - $configGlobal->application->lang = $language; - $date = new DateTime(); - $interval = new DateInterval('P1M'); - setcookie( - MIDAS_LANGUAGE_COOKIE_NAME, - $language, - $date->add($interval)->getTimestamp(), - '/', - !empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'], - (int) $configGlobal->get('cookie_secure', 1) === 1, - true - ); - } - Zend_Registry::set('configGlobal', $configGlobal); $configCore = new Zend_Config_Ini(CORE_CONFIG, 'global', true); Zend_Registry::set('configCore', $configCore); - // check if internationalization enabled - if (isset($configCore->internationalization) && $configCore->internationalization == '0') { - $configGlobal->application->lang = 'en'; - } - - $config = new Zend_Config_Ini(APPLICATION_CONFIG, $configGlobal->environment, true); + $config = new Zend_Config_Ini(APPLICATION_CONFIG, $configGlobal->get('environment', 'production'), true); Zend_Registry::set('config', $config); - date_default_timezone_set($configGlobal->default->timezone); - // InitDatabase - $configDatabase = new Zend_Config_Ini(DATABASE_CONFIG, $configGlobal->environment, true); - if (empty($configDatabase->database->params->driver_options)) { + return $config; + } + + /** + * Initialize the database. + * + * @return false|Zend_Db_Adapter_Abstract + * @throws Zend_Exception + */ + protected function _initDatabase() + { + $this->bootstrap('Config'); + $config = new Zend_Config_Ini(DATABASE_CONFIG, Zend_Registry::get('configGlobal')->get('environment', 'production'), true); + Zend_Registry::set('configDatabase', $config); + + if (empty($config->database->params->driver_options)) { $driverOptions = array(); } else { - $driverOptions = $configDatabase->database->params->driver_options->toArray(); + $driverOptions = $config->database->params->driver_options->toArray(); } - if ($configDatabase->database->adapter == 'PDO_SQLITE') { + if ($config->database->adapter === 'PDO_SQLITE') { $params = array( - 'dbname' => $configDatabase->database->params->dbname, + 'dbname' => $config->database->params->dbname, 'driver_options' => $driverOptions, ); } else { - if ($configDatabase->database->adapter == 'PDO_MYSQL') { + if ($config->database->adapter === 'PDO_MYSQL') { $driverOptions[PDO::MYSQL_ATTR_USE_BUFFERED_QUERY] = true; } $params = array( - 'dbname' => $configDatabase->database->params->dbname, - 'username' => $configDatabase->database->params->username, - 'password' => $configDatabase->database->params->password, + 'dbname' => $config->database->params->dbname, + 'username' => $config->database->params->username, + 'password' => $config->database->params->password, 'driver_options' => $driverOptions, ); - if (empty($configDatabase->database->params->unix_socket)) { - $params['host'] = $configDatabase->database->params->host; - $params['port'] = $configDatabase->database->params->port; + if (empty($config->database->params->unix_socket)) { + $params['host'] = $config->database->params->host; + $params['port'] = $config->database->params->port; } else { - $params['unix_socket'] = $configDatabase->database->params->unix_socket; + $params['unix_socket'] = $config->database->params->unix_socket; } } - $db = Zend_Db::factory($configDatabase->database->adapter, $params); - Zend_Db_Table::setDefaultAdapter($db); - Zend_Registry::set('dbAdapter', $db); - Zend_Registry::set('configDatabase', $configDatabase); + $database = Zend_Db::factory($config->database->adapter, $params); + Zend_Db_Table::setDefaultAdapter($database); + Zend_Registry::set('dbAdapter', $database); + Zend_Registry::set('models', array()); + + if (file_exists(LOCAL_CONFIGS_PATH.'/database.local.ini')) { + return $database; + } - // Init log - if ($configGlobal->environment == 'production') { + return false; + } + + /** Initialize the error handler. */ + protected function _initErrorHandle() + { + $this->bootstrap(array('Config', 'Logger')); + $logger = $this->getResource('Logger'); + + Zend_Registry::set('components', array()); + $notifyErrorComponent = MidasLoader::loadComponent('NotifyError'); + + //ini_set('display_errors', 0); + register_shutdown_function(array($notifyErrorComponent, 'fatalError'), $logger); + set_error_handler(array($notifyErrorComponent, 'warningError'), E_NOTICE | E_WARNING); + } + + /** + * Initialize internationalization. + * + * @throws Zend_Exception + */ + protected function _initInternationalization() + { + $this->bootstrap(array('Config', 'Database')); + $database = $this->getResource('Database'); + + if ((int) Zend_Registry::get('configGlobal')->get('internationalization', 0) === 1) { + $language = 'en'; + + if (isset($_COOKIE[MIDAS_LANGUAGE_COOKIE_NAME])) { + $language = $_COOKIE[MIDAS_LANGUAGE_COOKIE_NAME]; + } + + if (isset($_GET['lang'])) { + $language = $_GET['lang']; + if ($language !== 'en' && $language !== 'fr') { + $language = 'en'; + } + + $date = new DateTime(); + $interval = new DateInterval('P1M'); + setcookie( + MIDAS_LANGUAGE_COOKIE_NAME, + $language, + $date->add($interval)->getTimestamp(), + '/', + !empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'], + (int) Zend_Registry::get('configGlobal')->get('cookie_secure', + 1) === 1, + true + ); + } + + if ($database !== false) { + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + $settingModel->setConfig('language', $language); + } + } + + if ($database !== false) { + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + $timeZone = $settingModel->getValueByNameWithDefault('time_zone', 'UTC'); + } else { + $timeZone = 'UTC'; + } + + date_default_timezone_set($timeZone); + } + + /** + * Initialize the logger. + * + * @return Zend_Log + * @throws Zend_Log_Exception + */ + protected function _initLogger() + { + $this->bootstrap('Config'); + + if (Zend_Registry::get('configGlobal')->get('environment', 'production') === 'production') { Zend_Loader_Autoloader::getInstance()->suppressNotFoundWarnings(true); $priority = Zend_Log::WARN; } else { @@ -127,7 +195,7 @@ protected function _initConfig() } if (is_writable(LOGS_PATH)) { - $stream = LOGS_PATH.'/'.$configGlobal->environment.'.log'; + $stream = LOGS_PATH.'/'.Zend_Registry::get('configGlobal')->get('environment', 'production').'.log'; $logger = Zend_Log::factory( array( array( @@ -151,39 +219,24 @@ protected function _initConfig() ) ); } - if (file_exists(LOCAL_CONFIGS_PATH.'/database.local.ini')) { - $columnMapping = array('priority' => 'priority', 'message' => 'message', 'module' => 'module'); - $writer = new Zend_Log_Writer_Db($db, 'errorlog', $columnMapping); - if ($configGlobal->environment == 'production') { - $priority = Zend_Log::INFO; - } else { - $priority = Zend_Log::DEBUG; - } - $filter = new Zend_Log_Filter_Priority($priority); - $writer->addFilter($filter); - $logger->addWriter($writer); - } $logger->setEventItem('module', 'core'); $logger->registerErrorHandler(); Zend_Registry::set('logger', $logger); - // Init error handler - require_once BASE_PATH.'/core/controllers/components/NotifyErrorComponent.php'; - $notifyErrorComponent = new NotifyErrorComponent(); - ini_set('display_errors', 0); - register_shutdown_function(array($notifyErrorComponent, 'fatalError'), $logger); - set_error_handler(array($notifyErrorComponent, 'warningError'), E_NOTICE | E_WARNING); - - return $config; + return $logger; } - /** Display the debug toolbar, if enabled. */ + /** + * Display the debug toolbar, if enabled. + * + * @throws Zend_Exception + */ protected function _initZFDebug() { $this->bootstrap(array('Config', 'FrontController')); $zfDebugPath = BASE_PATH.'/vendor/jokkedk/zfdebug/library'; - if (Zend_Registry::get('configGlobal')->debug_toolbar === '1' && file_exists($zfDebugPath)) { + if ((int) Zend_Registry::get('configGlobal')->get('debug_toolbar', 0) === 1 && file_exists($zfDebugPath)) { set_include_path(get_include_path().PATH_SEPARATOR.$zfDebugPath); $options = array( @@ -198,11 +251,7 @@ protected function _initZFDebug() $debug = new ZFDebug_Controller_Plugin_Debug($options); $frontController = $this->getResource('FrontController'); $frontController->registerPlugin($debug); - - return $debug; } - - return false; } /** Register the module directories. */ @@ -217,12 +266,16 @@ protected function _initFrontModules() } } - /** Initialize the SASS compiler. */ + /** + * Initialize the SASS compiler. + * + * @throws Zend_Exception + */ protected function _initSass() { - $this->bootstrap('Config'); + $this->bootstrap(array('Config', 'Logger')); $config = Zend_Registry::get('configGlobal'); - $logger = Zend_Registry::get('logger'); + $logger = $this->getResource('Logger'); if ($config->environment == 'development') { $directory = new RecursiveDirectoryIterator(BASE_PATH); $iterator = new RecursiveIteratorIterator( @@ -279,7 +332,7 @@ protected function _initSass() */ protected function _initRouter() { - $this->bootstrap(array('Config', 'FrontController')); + $this->bootstrap(array('Config', 'Database', 'FrontController')); $frontController = $this->getResource('FrontController'); $frontController->addControllerDirectory(BASE_PATH.'/core/controllers'); @@ -295,9 +348,13 @@ protected function _initRouter() if (isset(Zend_Registry::get('configDatabase')->version) === false) { Zend_Registry::set('models', array()); - /** @var ModuleModel $moduleModel */ - $moduleModel = MidasLoader::loadModel('Module'); - $moduleDaos = $moduleModel->getEnabled(); + try { + /** @var ModuleModel $moduleModel */ + $moduleModel = MidasLoader::loadModel('Module'); + $moduleDaos = $moduleModel->getEnabled(); + } catch (Zend_Db_Exception $exception) { + $moduleDaos = array(); + } /** @var ModuleDao $moduleDao */ foreach ($moduleDaos as $moduleDao) { diff --git a/core/GlobalController.php b/core/GlobalController.php index 72ecc3924..f54523297 100644 --- a/core/GlobalController.php +++ b/core/GlobalController.php @@ -52,27 +52,31 @@ public function preDispatch() UtilityComponent::setTimeLimit(0); $enabledModules = Zend_Registry::get('modulesEnable'); - if (Zend_Registry::get('configGlobal')->application->lang != 'en') { - $translate = new Zend_Translate('csv', BASE_PATH.'/core/translation/fr-main.csv', 'en'); - Zend_Registry::set('translator', $translate); - $translators = array(); + if ((int) Zend_Registry::get('configGlobal')->get('internationalization', 0) === 1) { + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + if ($settingModel->getValueByNameWithDefault('language', 'en') === 'fr') { + $translate = new Zend_Translate('csv', BASE_PATH.'/core/translation/fr-main.csv', 'en'); + Zend_Registry::set('translator', $translate); + $translators = array(); - foreach ($enabledModules as $enabledModule) { - if (file_exists(BASE_PATH.'/modules/'.$enabledModule.'/translation/fr-main.csv')) { - $translators[$enabledModule] = new Zend_Translate( - 'csv', - BASE_PATH.'/modules/'.$enabledModule.'/translation/fr-main.csv', - 'en' - ); - } elseif (file_exists(BASE_PATH.'/privateModules/'.$enabledModule.'/translation/fr-main.csv')) { - $translators[$enabledModule] = new Zend_Translate( - 'csv', - BASE_PATH.'/privateModules/'.$enabledModule.'/translation/fr-main.csv', - 'en' - ); - } + foreach ($enabledModules as $enabledModule) { + if (file_exists(BASE_PATH.'/modules/'.$enabledModule.'/translation/fr-main.csv')) { + $translators[$enabledModule] = new Zend_Translate( + 'csv', + BASE_PATH.'/modules/'.$enabledModule.'/translation/fr-main.csv', + 'en' + ); + } elseif (file_exists(BASE_PATH.'/privateModules/'.$enabledModule.'/translation/fr-main.csv')) { + $translators[$enabledModule] = new Zend_Translate( + 'csv', + BASE_PATH.'/privateModules/'.$enabledModule.'/translation/fr-main.csv', + 'en' + ); + } - Zend_Registry::set('translatorsModules', $translators); + Zend_Registry::set('translatorsModules', $translators); + } } } @@ -240,7 +244,7 @@ public function loadElements() */ public function isDebug() { - return Zend_Registry::get('configGlobal')->environment !== 'production'; + return Zend_Registry::get('configGlobal')->get('environment', 'production') !== 'production'; } /** @@ -250,7 +254,7 @@ public function isDebug() */ public function getEnvironment() { - return Zend_Registry::get('configGlobal')->environment; + return Zend_Registry::get('configGlobal')->get('environment', 'production'); } /** diff --git a/core/configs/application.ini b/core/configs/application.ini index f22d31eef..384df6fe6 100644 --- a/core/configs/application.ini +++ b/core/configs/application.ini @@ -1,35 +1,21 @@ ; Midas Server. Copyright Kitware SAS. Licensed under the Apache License 2.0. [global] -; environment ("development" or "production") -environment = "production" -; name of the application -application.name = "Midas Platform - Digital Archiving System" -; description of the application -application.description = -; language of the application ("en" or "fr") -application.lang = "en" -; session lifetime (minutes) -session.lifetime = "20" -; default time zone -default.timezone = "America/New_York" -; default license -defaultlicense = "1" -; enable dynamic help -dynamichelp = "1" -; entry for password prefix (dynamically generated at install time) -password.prefix = -; outbound HTTP proxy to be used by PHP (empty for none) -httpproxy = -; allow password reset -allow_password_reset = "1" ; require secure cookies cookie_secure = "0" ; show debug toolbar debug_toolbar = "0" - -[production] +; environment ("development" or "production") +environment = "production" +; outbound HTTP proxy to be used by PHP (empty for none) +http_proxy = "" +; entry for password prefix (dynamically generated at install time) +password_prefix = "" +; session lifetime (minutes) +session_lifetime = "20" [development] +[production] + [testing] diff --git a/core/controllers/AdminController.php b/core/controllers/AdminController.php index 961bfbdf7..14059139c 100644 --- a/core/controllers/AdminController.php +++ b/core/controllers/AdminController.php @@ -29,9 +29,6 @@ class AdminController extends AppController /** init the controller */ public function init() { - $config = Zend_Registry::get('configGlobal'); // set admin part to english - $config->application->lang = 'en'; - Zend_Registry::set('configGlobal', $config); if ($this->isDemoMode()) { $this->disableView(); @@ -69,33 +66,19 @@ public function indexAction() $this->requireAdminPrivileges(); $this->view->header = 'Administration'; - $config = new Zend_Config_Ini(APPLICATION_CONFIG, null, true); - $configForm = $this->Form->Admin->createConfigForm(); $formArray = $this->getFormAsArray($configForm); - $formArray['description']->setValue($config->global->application->description); - $formArray['lang']->setValue($config->global->application->lang); - $formArray['name']->setValue($config->global->application->name); - $formArray['timezone']->setValue($config->global->default->timezone); - - if (isset($config->global->allow_password_reset)) { - $formArray['allow_password_reset']->setValue($config->global->allow_password_reset); - } - if (isset($config->global->closeregistration)) { - $formArray['closeregistration']->setValue($config->global->closeregistration); - } - if (isset($config->global->dynamichelp)) { - $formArray['dynamichelp']->setValue($config->global->dynamichelp); - } - if (isset($config->global->gravatar)) { - $formArray['gravatar']->setValue($config->global->gravatar); - } - if (isset($config->global->httpproxy)) { - $formArray['httpProxy']->setValue($config->global->httpproxy); - } + $formArray['title']->setValue($this->Setting->getValueByName('title')); + $formArray['description']->setValue($this->Setting->getValueByName('description')); + $formArray['language']->setValue($this->Setting->getValueByNameWithDefault('language', 'en')); + $formArray['time_zone']->setValue($this->Setting->getValueByNameWithDefault('time_zone', 'UTC')); + $formArray['dynamic_help']->setValue((int) $this->Setting->getValueByNameWithDefault('dynamic_help', 0)); + $formArray['allow_password_reset']->setValue((int) $this->Setting->getValueByNameWithDefault('allow_password_reset', 0)); + $formArray['close_registration']->setValue((int) $this->Setting->getValueByNameWithDefault('close_registration', 1)); + $formArray['gravatar']->setValue((int) $this->Setting->getValueByNameWithDefault('gravatar', 0)); $this->view->configForm = $formArray; - $this->view->selectedLicense = $config->global->defaultlicense; + $this->view->selectedLicense = (int) $this->Setting->getValueByNameWithDefault('default_license', 1); try { $this->view->allLicenses = $this->License->getAll(); } catch (Exception $e) { @@ -111,21 +94,15 @@ public function indexAction() $submitConfig = $this->getParam('submitConfig'); $submitModule = $this->getParam('submitModule'); if (isset($submitConfig)) { - $config->global->application->name = $this->getParam('name'); - $config->global->application->description = $this->getParam('description'); - $config->global->application->lang = $this->getParam('lang'); - $config->global->default->timezone = $this->getParam('timezone'); - $config->global->defaultlicense = $this->getParam('licenseSelect'); - $config->global->allow_password_reset = $this->getParam('allow_password_reset'); - $config->global->closeregistration = $this->getParam('closeregistration'); - $config->global->dynamichelp = $this->getParam('dynamichelp'); - $config->global->gravatar = $this->getParam('gravatar'); - $config->global->httpproxy = $this->getParam('httpProxy'); - - $writer = new Zend_Config_Writer_Ini(); - $writer->setConfig($config); - $writer->setFilename(APPLICATION_CONFIG); - $writer->write(); + $this->Setting->setConfig('title', $this->getParam('title')); + $this->Setting->setConfig('description', $this->getParam('description')); + $this->Setting->setConfig('language', $this->getParam('language')); + $this->Setting->setConfig('time_zone', $this->getParam('time_zone')); + $this->Setting->setConfig('dynamic_help', (int) $this->getParam('dynamic_help')); + $this->Setting->setConfig('allow_password_reset', (int) $this->getParam('allow_password_reset')); + $this->Setting->setConfig('close_registration', (int) $this->getParam('close_registration')); + $this->Setting->setConfig('gravatar', (int) $this->getParam('gravatar')); + $this->Setting->setConfig('default_license', (int) $this->getParam('licenseSelect')); echo JsonComponent::encode(array(true, 'Changes saved')); } if (isset($submitModule)) { @@ -174,11 +151,6 @@ public function indexAction() foreach ($assetstores as $key => $assetstore) { $assetstores[$key]->default = true; $this->Setting->setConfig('default_assetstore', $assetstores[$key]->getKey()); - - $writer = new Zend_Config_Writer_Ini(); - $writer->setConfig($config); - $writer->setFilename(APPLICATION_CONFIG); - $writer->write(); break; } } diff --git a/core/controllers/DownloadController.php b/core/controllers/DownloadController.php index b1a97dfc1..54593da43 100644 --- a/core/controllers/DownloadController.php +++ b/core/controllers/DownloadController.php @@ -47,7 +47,7 @@ public function indexAction() $folderIds = $this->getParam('folders'); $bitsreamid = $this->getParam('bitstream'); $sessionUser = $this->userSession->Dao; - $testingMode = Zend_Registry::get('configGlobal')->environment == 'testing'; + $testingMode = Zend_Registry::get('configGlobal')->get('environment', 'production') === 'testing'; if ($sessionUser != null) { // Make sure this is a copy and not a reference $sessionUser = $this->User->load($sessionUser->getKey()); diff --git a/core/controllers/ErrorController.php b/core/controllers/ErrorController.php index 636360ebd..d73644d3c 100644 --- a/core/controllers/ErrorController.php +++ b/core/controllers/ErrorController.php @@ -38,9 +38,8 @@ public function init() return; } $session = new Zend_Session_Namespace('Auth_User'); - $db = Zend_Registry::get('dbAdapter'); - $environment = Zend_Registry::get('configGlobal')->environment; + $environment = Zend_Registry::get('configGlobal')->get('environment', 'production'); $this->_environment = $environment; $this->Component->NotifyError->initNotifier($environment, $error, $session, $_SERVER); @@ -55,7 +54,9 @@ public function errorAction() { $error = $this->getParam('error_handler'); if (!isset($error) || empty($error)) { - $this->view->message = 'Page not found'; + $this->getResponse()->setHttpResponseCode(404); + $this->view->header = 'Error 404 - Not Found'; + $this->view->message = 'The requested page was not found on this server.'; return; } @@ -64,35 +65,37 @@ public function errorAction() $controller = $controller['controller']; if ($controller != 'install' && !file_exists(LOCAL_CONFIGS_PATH.'/database.local.ini') ) { - $this->view->message = "Midas is not installed. Please go the install page."; + $this->view->message = "Midas Server is not installed. Please go the install page."; return; } switch ($this->_error->type) { - case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: + case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: + case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE: $this->getResponse()->setHttpResponseCode(404); - $this->view->message = 'Page not found'; + $this->view->header = 'Error 404 - Not Found'; + $this->view->message = 'The requested page was not found on this server.'; break; default: $code = $this->_error->exception->getCode(); $this->view->code = $code; $this->view->exceptionText = $this->_error->exception->getMessage(); - if ($code == 0) { - $this->getResponse()->setHttpResponseCode(500); - } elseif ($code >= 400 && $code <= 417) { + if ($code >= 400 && $code <= 417) { $this->getResponse()->setHttpResponseCode($code); if ($code == 403) { if ($this->logged) { - $this->view->header = 'Access Denied'; + $this->view->header = 'Error 403 - Access Denied'; } else { $this->haveToBeLogged(); return; } } elseif ($code == 404) { - $this->view->header = 'Not Found'; + $this->view->header = 'Error 404 - Not Found'; } + } else { + $this->getResponse()->setHttpResponseCode(500); } $this->_applicationError(); break; diff --git a/core/controllers/InstallController.php b/core/controllers/InstallController.php index 5d0b10af1..9270d9ee8 100644 --- a/core/controllers/InstallController.php +++ b/core/controllers/InstallController.php @@ -190,7 +190,6 @@ public function step2Action() $moduleDao->setName('core'); $moduleDao->setUuid(str_replace('-', '', $configCore->get('uuid'))); $moduleDao->setCurrentVersion($version); - $moduleDao->setEnabled(1); $moduleModel->save($moduleDao); require_once BASE_PATH.'/core/controllers/components/UpgradeComponent.php'; @@ -238,15 +237,14 @@ public function step3Action() $this->redirect('/install/index'); } - $config = new Zend_Config_Ini(APPLICATION_CONFIG, null, true); - $form = $this->Form->Install->createConfigForm(); $formArray = $this->getFormAsArray($form); - $formArray['description']->setValue($config->global->application->description); - $formArray['lang']->setValue($config->global->application->lang); - $formArray['name']->setValue($config->global->application->name); - $formArray['timezone']->setValue($config->global->default->timezone); + $formArray['description']->setValue(''); + $formArray['lang']->setValue('en'); + $formArray['name']->setValue('Midas Platform - Digital Archiving System'); + $formArray['timezone']->setValue('UTC'); $this->view->form = $formArray; + $this->view->databaseType = Zend_Registry::get('configDatabase')->database->adapter; $assetstores = $this->Assetstore->getAll(); @@ -260,10 +258,13 @@ public function step3Action() } } - $config->global->application->description = $form->getValue('description'); - $config->global->application->lang = $form->getValue('lang'); - $config->global->application->name = $form->getValue('name'); - $config->global->default->timezone = $form->getValue('timezone'); + $this->Setting->setConfig('title', $form->getValue('name')); + $this->Setting->setConfig('description', $form->getValue('description')); + $this->Setting->setConfig('language', $form->getValue('lang')); + $this->Setting->setConfig('time_zone', $form->getValue('timezone')); + $this->Setting->setConfig('default_assetstore', $assetstores[0]->getKey()); + + $config = new Zend_Config_Ini(APPLICATION_CONFIG, null, true); $config->global->environment = 'production'; $writer = new Zend_Config_Writer_Ini(); @@ -271,8 +272,6 @@ public function step3Action() $writer->setFilename(APPLICATION_CONFIG); $writer->write(); - $this->Setting->setConfig('default_assetstore', $assetstores[0]->getKey()); - $this->redirect('/admin#tabs-modules'); } } diff --git a/core/controllers/UploadController.php b/core/controllers/UploadController.php index 3504a1c07..49e98a546 100644 --- a/core/controllers/UploadController.php +++ b/core/controllers/UploadController.php @@ -64,7 +64,10 @@ public function simpleuploadAction() $this->disableLayout(); $this->view->form = $this->getFormAsArray($this->Form->Upload->createUploadLinkForm()); $this->userSession->filePosition = null; - $this->view->selectedLicense = Zend_Registry::get('configGlobal')->defaultlicense; + + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + $this->view->selectedLicense = $settingModel->getValueByNameWithDefault('default_license', 1); $this->view->allLicenses = $this->License->getAll(); $this->view->defaultUploadLocation = ''; @@ -114,7 +117,9 @@ public function revisionAction() // Check if the revision exists and if it does, we send its license ID to // the view. If it does not exist we use our default license if ($itemRevision === false) { - $this->view->selectedLicense = Zend_Registry::get('configGlobal')->defaultlicense; + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + $this->view->selectedLicense = $settingModel->getValueByNameWithDefault('default_license', 1); } else { $this->view->selectedLicense = $itemRevision->getLicenseId(); } diff --git a/core/controllers/UserController.php b/core/controllers/UserController.php index 50bfdf34b..8eb73c927 100644 --- a/core/controllers/UserController.php +++ b/core/controllers/UserController.php @@ -87,7 +87,7 @@ public function recoverpasswordAction() throw new Zend_Exception('Shouldn\'t be logged in'); } - if ((int) Zend_Registry::get('configGlobal')->get('allow_password_reset', 0) === 0) { + if ((int) $this->Setting->getValueByNameWithDefault('allow_password_reset', 0) === 0) { throw new Zend_Exception('Password reset is disabled'); } @@ -209,10 +209,7 @@ public function ajaxregisterAction() } $this->disableView(); $this->disableLayout(); - if (!$adminCreate && isset(Zend_Registry::get('configGlobal')->closeregistration) && Zend_Registry::get( - 'configGlobal' - )->closeregistration == '1' - ) { + if (!$adminCreate && (int) $this->Setting->getValueByNameWithDefault('close_registration', 1) === 1) { echo JsonComponent::encode(array('status' => 'error', 'message' => 'New user registration is disabled.')); return; @@ -257,9 +254,9 @@ public function ajaxregisterAction() } $email = strtolower(trim($form->getValue('email'))); - $addressVerification = $this->Setting->getValueByName('address_verification', 'mail'); + $addressVerification = (int) $this->Setting->getValueByName('address_verification', 'mail'); - if ($adminCreate || $addressVerification != '1') { + if ($adminCreate || $addressVerification !== 1) { $newUser = $this->User->createUser( $email, $form->getValue('password1'), @@ -346,10 +343,7 @@ public function ajaxregisterAction() /** Register a user */ public function registerAction() { - if (isset(Zend_Registry::get('configGlobal')->closeregistration) && Zend_Registry::get( - 'configGlobal' - )->closeregistration == '1' - ) { + if ((int) $this->Setting->getValueByNameWithDefault('close_registration', 1) === 1) { throw new Zend_Exception('New user registration is disabled.'); } $form = $this->Form->User->createRegisterForm(); @@ -360,9 +354,9 @@ public function registerAction() throw new Zend_Exception('User already exists.'); } - $addressVerification = $this->Setting->getValueByName('address_verification', 'mail'); + $addressVerification = (int) $this->Setting->getValueByName('address_verification', 'mail'); - if ($addressVerification != '1') { + if ($addressVerification !== 1) { if (!headers_sent()) { session_start(); } @@ -485,7 +479,7 @@ public function ajaxloginAction() return; } - $instanceSalt = Zend_Registry::get('configGlobal')->password->prefix; + $instanceSalt = Zend_Registry::get('configGlobal')->get('password_prefix'); $passwordHash = hash($userDao->getHashAlg(), $instanceSalt.$userDao->getSalt().$form->getValue('password')); if ($this->User->hashExists($passwordHash)) { @@ -517,7 +511,7 @@ public function ajaxloginAction() ); Zend_Session::start(); $user = new Zend_Session_Namespace('Auth_User'); - $user->setExpirationSeconds(60 * Zend_Registry::get('configGlobal')->session->lifetime); + $user->setExpirationSeconds(60 * (int) Zend_Registry::get('configGlobal')->get('session_lifetime', 20)); $user->Dao = $userDao; $user->lock(); $this->getLogger()->debug(__METHOD__.' Log in : '.$userDao->getFullName()); @@ -566,7 +560,7 @@ public function loginAction() } } - $instanceSalt = Zend_Registry::get('configGlobal')->password->prefix; + $instanceSalt = Zend_Registry::get('configGlobal')->get('password_prefix'); $currentVersion = UtilityComponent::getCurrentModuleVersion('core'); if ($currentVersion === false) { throw new Zend_Exception('Core version is undefined.'); @@ -627,7 +621,7 @@ public function loginAction() ); Zend_Session::start(); $user = new Zend_Session_Namespace('Auth_User'); - $user->setExpirationSeconds(60 * Zend_Registry::get('configGlobal')->session->lifetime); + $user->setExpirationSeconds(60 * (int) Zend_Registry::get('configGlobal')->get('session_lifetime', 20)); $user->Dao = $userDao; $user->lock(); } @@ -652,8 +646,8 @@ public function loginAction() } } - $this->view->allowPasswordReset = (int) Zend_Registry::get('configGlobal')->get('allow_password_reset', 0) === 1; - $this->view->closeRegistration = (int) Zend_Registry::get('configGlobal')->get('closeregistration', 0) === 1; + $this->view->allowPasswordReset = (int) $this->Setting->getValueByNameWithDefault('allow_password_reset', 0) === 1; + $this->view->closeRegistration = (int) $this->Setting->getValueByNameWithDefault('close_registration', 1) === 1; } /** Term of service */ @@ -780,7 +774,7 @@ public function settingsAction() $this->User->convertLegacyPasswordHash($userDao, $oldPass); } $newPass = $this->getParam('newPassword'); - $instanceSalt = Zend_Registry::get('configGlobal')->password->prefix; + $instanceSalt = Zend_Registry::get('configGlobal')->get('password_prefix'); $hashedPasswordOld = hash($userDao->getHashAlg(), $instanceSalt.$userDao->getSalt().$oldPass); if ((!$userDao->isAdmin() && $this->userSession->Dao->isAdmin()) || $this->User->hashExists( @@ -1026,7 +1020,7 @@ public function settingsAction() $this->Component->Sortdao->order = 'asc'; usort($communities, array($this->Component->Sortdao, 'sortByName')); - $this->view->useGravatar = Zend_Registry::get('configGlobal')->gravatar; + $this->view->useGravatar = (int) $this->Setting->getValueByNameWithDefault('gravatar', 0); $this->view->isGravatar = $this->User->getGravatarUrl($userDao->getEmail()); $this->view->communities = $communities; diff --git a/core/controllers/components/ApisystemComponent.php b/core/controllers/components/ApisystemComponent.php index 2a27efcd2..0299c4874 100644 --- a/core/controllers/components/ApisystemComponent.php +++ b/core/controllers/components/ApisystemComponent.php @@ -94,8 +94,12 @@ public function resourcesList($args) */ public function info($args) { - $appFields = Zend_Registry::get('configGlobal')->application; - $serverFields = array('name' => $appFields->name, 'description' => $appFields->description); + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + $serverFields = array( + 'name' => $settingModel->getValueByName('title'), + 'description' => $settingModel->getValueByName('description'), + ); return array_merge( $this->version($args), @@ -203,7 +207,7 @@ public function userApikeyDefault($args) } } - $prefix = Zend_Registry::get('configGlobal')->password->prefix; + $prefix = Zend_Registry::get('configGlobal')->get('password_prefix'); if ($hasAuthenticationModule || $userModel->hashExists( hash($userDao->getHashAlg(), $prefix.$userDao->getSalt().$password) ) @@ -441,7 +445,7 @@ public function uploadGeneratetoken($args) /** @var HttpuploadComponent $uploadComponent */ $uploadComponent = MidasLoader::loadComponent('Httpupload'); $apiSetup = $apihelperComponent->getApiSetup(); - $uploadComponent->setTestingMode(Zend_Registry::get('configGlobal')->environment === 'testing'); + $uploadComponent->setTestingMode(Zend_Registry::get('configGlobal')->get('environment', 'production') === 'testing'); return $uploadComponent->generateToken($args, $userDao->getKey().'/'.$item->getKey()); } @@ -519,7 +523,7 @@ public function uploadPerform($args) /** @var HttpuploadComponent $httpUploadComponent */ $httpUploadComponent = MidasLoader::loadComponent('Httpupload'); $apiSetup = $apihelperComponent->getApiSetup(); - $httpUploadComponent->setTestingMode(Zend_Registry::get('configGlobal')->environment === 'testing'); + $httpUploadComponent->setTestingMode(Zend_Registry::get('configGlobal')->get('environment', 'production') === 'testing'); if (array_key_exists('testingmode', $args)) { $httpUploadComponent->setTestingMode(true); @@ -623,7 +627,7 @@ public function uploadGetoffset($args) /** @var ApihelperComponent $apihelperComponent */ $apihelperComponent = MidasLoader::loadComponent('Apihelper'); $apiSetup = $apihelperComponent->getApiSetup(); - $uploadComponent->setTestingMode(Zend_Registry::get('configGlobal')->environment === 'testing'); + $uploadComponent->setTestingMode(Zend_Registry::get('configGlobal')->get('environment', 'production') === 'testing'); return $uploadComponent->getOffset($args); } diff --git a/core/controllers/components/AuthenticationComponent.php b/core/controllers/components/AuthenticationComponent.php index 75661e1cd..09570cf2c 100644 --- a/core/controllers/components/AuthenticationComponent.php +++ b/core/controllers/components/AuthenticationComponent.php @@ -74,7 +74,7 @@ public function getUser($args, $sessionDao) session_start(); } $userSession = new Zend_Session_Namespace('Auth_User'); - $userSession->setExpirationSeconds(60 * Zend_Registry::get('configGlobal')->session->lifetime); + $userSession->setExpirationSeconds(60 * (int) Zend_Registry::get('configGlobal')->get('session_lifetime', 20)); $userSession->Dao = $userDao; Zend_Registry::set('notifier', new MIDAS_Notifier(true, $userSession)); session_write_close(); diff --git a/core/controllers/components/DateComponent.php b/core/controllers/components/DateComponent.php index 5f955ad46..a8e60bf04 100644 --- a/core/controllers/components/DateComponent.php +++ b/core/controllers/components/DateComponent.php @@ -35,11 +35,17 @@ public static function formatDate($timestamp) return ''; } } - if (Zend_Registry::get('configGlobal')->application->lang == 'fr') { - return date('d', $timestamp).'/'.date('m', $timestamp).'/'.date('Y', $timestamp); - } else { - return date('m', $timestamp).'/'.date('d', $timestamp).'/'.date('Y', $timestamp); + + if ((int) Zend_Registry::get('configGlobal')->get('internationalization', 0) === 1) { + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + + if ($settingModel->getValueByNameWithDefault('language', 'en') === 'fr') { + return date('d', $timestamp).'/'.date('m', $timestamp).'/'.date('Y', $timestamp); + } } + + return date('m', $timestamp).'/'.date('d', $timestamp).'/'.date('Y', $timestamp); } /** @@ -72,20 +78,24 @@ public static function ago($timestamp, $onlyTime = false) } } - if ($onlyTime) { - if (Zend_Registry::get('configGlobal')->application->lang == 'fr') { - return $difference.' '.$periodsFr[$j]; - } else { - return $difference.' '.$periods[$j]; + if ((int) Zend_Registry::get('configGlobal')->get('internationalization', 0) === 1) { + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + + if ($settingModel->getValueByNameWithDefault('language', 'en') === 'fr') { + if ($onlyTime) { + return $difference.' '.$periodsFr[$j]; + } + + return 'Il y a '.$difference.' '.$periodsFr[$j]; } } - if (Zend_Registry::get('configGlobal')->application->lang == 'fr') { - $text = 'Il y a '.$difference.' '.$periodsFr[$j]; - } else { - $text = $difference.' '.$periods[$j].' ago'; + + if ($onlyTime) { + return $difference.' '.$periods[$j]; } - return $text; + return $difference.' '.$periods[$j].' ago'; } /** @@ -121,12 +131,15 @@ public static function duration($timestamp) $difference = $timestamp; } - if (Zend_Registry::get('configGlobal')->application->lang == 'fr') { - $text = $difference.' '.$periodsFr[$j]; - } else { - $text = $difference.' '.$periods[$j]; + if ((int) Zend_Registry::get('configGlobal')->get('internationalization', 0) === 1) { + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + + if ($settingModel->getValueByNameWithDefault('language', 'en') === 'fr') { + return $difference.' '.$periodsFr[$j]; + } } - return $text; + return $difference.' '.$periods[$j]; } } diff --git a/core/controllers/components/InternationalizationComponent.php b/core/controllers/components/InternationalizationComponent.php index e5d90094f..95670714d 100644 --- a/core/controllers/components/InternationalizationComponent.php +++ b/core/controllers/components/InternationalizationComponent.php @@ -46,20 +46,25 @@ public static function getInstance() */ public static function translate($text) { - if (Zend_Registry::get('configGlobal')->application->lang != 'en') { - $translate = Zend_Registry::get('translator'); - $new_text = $translate->_($text); - if ($new_text == $text) { - $translators = Zend_Registry::get('translatorsModules'); - foreach ($translators as $t) { - $new_text = $t->_($text); - if ($new_text != $text) { - break; + if ((int) Zend_Registry::get('configGlobal')->get('internationalization', 0) === 1) { + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + + if ($settingModel->getValueByNameWithDefault('language', 'en') === 'fr') { + $translate = Zend_Registry::get('translator'); + $new_text = $translate->_($text); + if ($new_text == $text) { + $translators = Zend_Registry::get('translatorsModules'); + foreach ($translators as $t) { + $new_text = $t->_($text); + if ($new_text != $text) { + break; + } } } - } - return $new_text; + return $new_text; + } } return $text; @@ -72,6 +77,6 @@ public static function translate($text) */ public static function isDebug() { - return Zend_Registry::get('configGlobal')->environment !== 'production'; + return Zend_Registry::get('configGlobal')->get('environment', 'production') !== 'production'; } } diff --git a/core/controllers/components/MIDAS2MigrationComponent.php b/core/controllers/components/MIDAS2MigrationComponent.php index 24718ade4..87f28270c 100644 --- a/core/controllers/components/MIDAS2MigrationComponent.php +++ b/core/controllers/components/MIDAS2MigrationComponent.php @@ -532,7 +532,7 @@ public function migrate($userid) $this->userId = $userid; // Check that we are in development mode - if (Zend_Registry::get('configGlobal')->environment != 'development') { + if (Zend_Registry::get('configGlobal')->get('environment', 'production') !== 'development') { throw new Zend_Exception("Please set your environment config variable to be 'development'."); } @@ -547,7 +547,7 @@ public function migrate($userid) } // Check that the password prefix is not defined - if (Zend_Registry::get('configGlobal')->password->prefix != '') { + if (Zend_Registry::get('configGlobal')->get('password_prefix', '') !== '') { throw new Zend_Exception("Password prefix cannot be set because MIDAS2 doesn't use salt."); } diff --git a/core/controllers/components/NotifyErrorComponent.php b/core/controllers/components/NotifyErrorComponent.php index dc934e540..cd41bc318 100644 --- a/core/controllers/components/NotifyErrorComponent.php +++ b/core/controllers/components/NotifyErrorComponent.php @@ -59,7 +59,7 @@ public function fatalError($logger) { if (!is_null(error_get_last())) { $e = error_get_last(); - $environment = Zend_Registry::get('configGlobal')->environment; + $environment = Zend_Registry::get('configGlobal')->get('environment', 'production'); switch ($environment) { case 'production': $message = 'The system has encountered the following error:

'; @@ -145,14 +145,14 @@ public function fatalError($logger) */ public function warningError($errno, $errstr, $errfile, $errline) { - if ($errno == E_WARNING && Zend_Registry::get('configGlobal')->environment != 'production' + if ($errno == E_WARNING && Zend_Registry::get('configGlobal')->get('environment', 'production') !== 'production' ) { $message = 'Warning: '.htmlspecialchars($errstr, ENT_QUOTES, 'UTF-8')."
\n on line ".htmlspecialchars($errline, ENT_QUOTES, 'UTF-8').' in file '.htmlspecialchars($errfile, ENT_QUOTES, 'UTF-8')."
\n"; $this->getLogger()->warn($message); echo $message; } - if ($errno == E_NOTICE && Zend_Registry::get('configGlobal')->environment != 'production' + if ($errno == E_NOTICE && Zend_Registry::get('configGlobal')->get('environment', 'production') !== 'production' ) { $message = 'Notice : '.htmlspecialchars($errstr, ENT_QUOTES, 'UTF-8')."
\non line ".htmlspecialchars($errline, ENT_QUOTES, 'UTF-8').' in file '.htmlspecialchars($errfile, ENT_QUOTES, 'UTF-8')."
\n"; $this->getLogger()->warn($message); @@ -167,7 +167,7 @@ public function warningError($errno, $errstr, $errfile, $errline) */ public function curPageURL() { - if (Zend_Registry::get('configGlobal')->environment == 'testing') { + if (Zend_Registry::get('configGlobal')->get('environment', 'production') === 'testing') { return 'http://localhost'; } $pageURL = 'http'; diff --git a/core/controllers/components/UpgradeComponent.php b/core/controllers/components/UpgradeComponent.php index 27452d0e1..1dbe1a86a 100644 --- a/core/controllers/components/UpgradeComponent.php +++ b/core/controllers/components/UpgradeComponent.php @@ -202,7 +202,6 @@ public function upgrade($currentVersion = false, $testing = false) if ($migration['version'] > $currentVersion) { $this->_processFile($migration); $versionText = $migration['versionText']; - Zend_Registry::get('logger')->info($versionText); } } diff --git a/core/controllers/components/UploadComponent.php b/core/controllers/components/UploadComponent.php index 4429b3862..ceccf33f0 100644 --- a/core/controllers/components/UploadComponent.php +++ b/core/controllers/components/UploadComponent.php @@ -271,7 +271,9 @@ public function createUploadedItem( $changes = 'Initial revision'; if ($license === null) { - $license = Zend_Registry::get('configGlobal')->defaultlicense; + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + $license = (int) $settingModel->getValueByNameWithDefault('default_license', 1); } $folderModel->addItem($parent, $itemDao); @@ -286,7 +288,7 @@ public function createUploadedItem( /** @var ItemRevisionDao $itemRevisionDao */ $itemRevisionDao = MidasLoader::newDao('ItemRevisionDao'); $itemRevisionDao->setChanges($changes); - $itemRevisionDao->setUser_id($userDao->getKey()); + $itemRevisionDao->setUserId($userDao->getKey()); $itemRevisionDao->setDate(date('Y-m-d H:i:s')); $itemRevisionDao->setLicenseId($license); $itemModel->addRevision($itemDao, $itemRevisionDao); diff --git a/core/controllers/components/UtilityComponent.php b/core/controllers/components/UtilityComponent.php index adedcb44d..6ea00a433 100644 --- a/core/controllers/components/UtilityComponent.php +++ b/core/controllers/components/UtilityComponent.php @@ -319,26 +319,35 @@ public static function fileSize($path) public static function formatSize($sizeInBytes, $separator = ',') { $suffix = 'B'; - if (Zend_Registry::get('configGlobal')->application->lang == 'fr') { - $suffix = 'o'; + if ((int) Zend_Registry::get('configGlobal')->get('internationalization', 0) === 1) { + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + if ($settingModel->getValueByNameWithDefault('language', 'en') === 'fr') { + $suffix = 'o'; + } } + if ($sizeInBytes >= 1073741824000) { $sizeInBytes = number_format($sizeInBytes / 1099511627776, 1, '.', $separator); return $sizeInBytes.' T'.$suffix; - } elseif ($sizeInBytes >= 1048576000) { + } + + if ($sizeInBytes >= 1048576000) { $sizeInBytes = number_format($sizeInBytes / 1073741824, 1, '.', $separator); return $sizeInBytes.' G'.$suffix; - } elseif ($sizeInBytes >= 1024000) { + } + + if ($sizeInBytes >= 1024000) { $sizeInBytes = number_format($sizeInBytes / 1048576, 1, '.', $separator); return $sizeInBytes.' M'.$suffix; - } else { - $sizeInBytes = number_format($sizeInBytes / 1024, 1, '.', $separator); - - return $sizeInBytes.' K'.$suffix; } + + $sizeInBytes = number_format($sizeInBytes / 1024, 1, '.', $separator); + + return $sizeInBytes.' K'.$suffix; } /** @@ -397,12 +406,16 @@ public static function run_sql_from_file($db, $sqlfile) public static function getCurrentModuleVersion($moduleName) { if (isset(Zend_Registry::get('configDatabase')->version) === false) { - /** @var ModuleModel $moduleModel */ - $moduleModel = MidasLoader::loadModel('Module'); - $moduleDao = $moduleModel->getByName($moduleName); + try { + /** @var ModuleModel $moduleModel */ + $moduleModel = MidasLoader::loadModel('Module'); + $moduleDao = $moduleModel->getByName($moduleName); - if ($moduleDao !== false) { - return $moduleDao->getCurrentVersion(); + if ($moduleDao !== false) { + return $moduleDao->getCurrentVersion(); + } + } catch (Zend_Db_Exception $exception) { + return false; } } @@ -641,7 +654,7 @@ public function installModule($moduleName) $path = false; } if ($path !== false && file_exists($path)) { - copy($path, LOCAL_CONFIGS_PATH.'/'.$moduleName.'local.ini'); + copy($path, LOCAL_CONFIGS_PATH.'/'.$moduleName.'.local.ini'); } } @@ -795,7 +808,7 @@ public static function sendEmail($to, $subject, $body) */ public static function getServerURL() { - if (Zend_Registry::get('configGlobal')->environment == 'testing') { + if (Zend_Registry::get('configGlobal')->get('environment', 'production') === 'testing') { return 'http://localhost'; } $currentPort = ''; diff --git a/core/controllers/forms/AdminForm.php b/core/controllers/forms/AdminForm.php index 4689eeede..50b521695 100644 --- a/core/controllers/forms/AdminForm.php +++ b/core/controllers/forms/AdminForm.php @@ -25,16 +25,18 @@ class AdminForm extends AppForm public function createConfigForm() { $form = new Zend_Form(); - $form->setAction($this->webroot.'/admin/index')->setMethod('post'); - $lang = new Zend_Form_Element_Select('lang'); - $lang->addMultiOptions(array('en' => 'English', 'fr' => 'French')); + $title = new Zend_Form_Element_Text('title'); + $title->setRequired(true)->addValidator('NotEmpty', true); $description = new Zend_Form_Element_Textarea('description'); - $timezone = new Zend_Form_Element_Select('timezone'); - $timezone->addMultiOptions( + $language = new Zend_Form_Element_Select('language'); + $language->addMultiOptions(array('en' => 'English', 'fr' => 'French')); + + $timeZone = new Zend_Form_Element_Select('time_zone'); + $timeZone->addMultiOptions( array( 'America/Anchorage' => 'America/Anchorage', 'America/Chicago' => 'America/Chicago', @@ -49,31 +51,25 @@ public function createConfigForm() ) ); - $name = new Zend_Form_Element_Text('name'); - $name->setRequired(true)->addValidator('NotEmpty', true); - - $dynamichelp = new Zend_Form_Element_Checkbox('dynamichelp'); - $gravatar = new Zend_Form_Element_Checkbox('gravatar'); + $dynamicHelp = new Zend_Form_Element_Checkbox('dynamic_help'); $allowPasswordReset = new Zend_Form_Element_Checkbox('allow_password_reset'); - $closeRegistration = new Zend_Form_Element_Checkbox('closeregistration'); - - $httpProxy = new Zend_Form_Element_Text('httpProxy'); + $gravatar = new Zend_Form_Element_Checkbox('gravatar'); + $closeRegistration = new Zend_Form_Element_Checkbox('close_registration'); $submit = new Zend_Form_Element_Submit('submitConfig'); $submit->setLabel('Save configuration'); $form->addElements( array( - $dynamichelp, + $title, $description, - $timezone, - $gravatar, - $lang, - $name, + $language, + $timeZone, + $dynamicHelp, $allowPasswordReset, $closeRegistration, + $gravatar, $submit, - $httpProxy, ) ); diff --git a/core/database/upgrade/3.4.1.php b/core/database/upgrade/3.4.1.php index 013a81d2e..827246a42 100644 --- a/core/database/upgrade/3.4.1.php +++ b/core/database/upgrade/3.4.1.php @@ -121,7 +121,7 @@ public function postUpgrade() $moduleDao->setCurrentVersion($moduleConfig->get('version', '0.0.0')); } - $moduleDao->setEnabled($value == 1 ? 1 : 0); + $moduleDao->setEnabled((int) $value === 1 ? 1 : 0); $moduleModel->save($moduleDao); if ($uuid && $localConfig) { @@ -129,9 +129,42 @@ public function postUpgrade() } } + /** @var Zend_Config_Ini $applicationConfigGlobal */ + $applicationConfigGlobal = Zend_Registry::get('configGlobal'); + + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + $settingModel->setConfig('allow_password_reset', (int) $applicationConfigGlobal->allow_password_reset); + $settingModel->setConfig('description', $applicationConfigGlobal->application->description); + $settingModel->setConfig('language', $applicationConfigGlobal->application->lang); + $settingModel->setConfig('title', $applicationConfigGlobal->application->name); + $settingModel->setConfig('close_registration', (int) $applicationConfigGlobal->closeregistration); + $settingModel->setConfig('time_zone', $applicationConfigGlobal->default->timezone); + $settingModel->setConfig('default_license', (int) $applicationConfigGlobal->defaultlicense); + $settingModel->setConfig('dynamic_help', (int) $applicationConfigGlobal->dynamichelp); + $settingModel->setConfig('gravatar', (int) $applicationConfigGlobal->gravatar); + $applicationConfig = new Zend_Config_Ini(APPLICATION_CONFIG, null, true); + $applicationConfig->global->http_proxy = $applicationConfig->global->httpproxy; + $applicationConfig->global->password_prefix = $applicationConfig->global->password->prefix; + $applicationConfig->global->session_lifetime = $applicationConfig->global->session->lifetime; + + unset($applicationConfig->global->allow_password_reset); + unset($applicationConfig->global->application->description); + unset($applicationConfig->global->application->lang); + unset($applicationConfig->global->application->name); + unset($applicationConfig->global->closeregistration); + unset($applicationConfig->global->default->timezone); + unset($applicationConfig->global->defaultlicense); + unset($applicationConfig->global->dynamichelp); + unset($applicationConfig->global->gravatar); + unset($applicationConfig->global->httpproxy); + unset($applicationConfig->global->password->prefix); + unset($applicationConfig->global->session->lifetime); unset($applicationConfig->module); + copy(APPLICATION_CONFIG, str_replace('.local.ini', '.old.local.ini', APPLICATION_CONFIG)); + $applicationWriter = new Zend_Config_Writer_Ini(); $applicationWriter->setConfig($applicationConfig); $applicationWriter->setFilename(APPLICATION_CONFIG); diff --git a/core/layouts/layout.phtml b/core/layouts/layout.phtml index 8f28aacb4..58cd9d616 100644 --- a/core/layouts/layout.phtml +++ b/core/layouts/layout.phtml @@ -157,10 +157,10 @@ echo $this->doctype().PHP_EOL; if ($this->logged) { echo ' '.$this->t('Logout').''; } else { - if (!isset(Zend_Registry::get('configGlobal')->closeregistration) || Zend_Registry::get( - 'configGlobal' - )->closeregistration == "0" - ) { + + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + if ((int) $settingModel->getValueByNameWithDefault('close_registration', 1) === 0) { echo ' '.$this->t('Register').''; } } @@ -171,10 +171,7 @@ echo $this->doctype().PHP_EOL; internationalization) || Zend_Registry::get( - 'configCore' - )->internationalization == "1" - ) { + if ((int) Zend_Registry::get('configCore')->get('internationalization', 0) === 1) { ?>
  • diff --git a/core/models/base/AssetstoreModelBase.php b/core/models/base/AssetstoreModelBase.php index 8bbcaaed2..31fd5f8f1 100644 --- a/core/models/base/AssetstoreModelBase.php +++ b/core/models/base/AssetstoreModelBase.php @@ -157,7 +157,7 @@ public function getDefault() /** @var AssetstoreModel $assetstoreModel */ $assetstoreModel = MidasLoader::loadModel('Assetstore'); - $defaultAssetstoreId = $settingModel->getValueByName('default_assetstore'); + $defaultAssetstoreId = (int) $settingModel->getValueByName('default_assetstore'); $defaultAssetstore = false; diff --git a/core/models/base/PendingUserModelBase.php b/core/models/base/PendingUserModelBase.php index a96819dc0..058224c34 100644 --- a/core/models/base/PendingUserModelBase.php +++ b/core/models/base/PendingUserModelBase.php @@ -56,7 +56,7 @@ abstract public function getAllByParams($params); public function createPendingUser($email, $firstName, $lastName, $password) { $email = strtolower($email); - $instanceSalt = Zend_Registry::get('configGlobal')->password->prefix; + $instanceSalt = Zend_Registry::get('configGlobal')->get('password_prefix'); /** @var RandomComponent $randomComponent */ $randomComponent = MidasLoader::loadComponent('Random'); diff --git a/core/models/base/SettingModelBase.php b/core/models/base/SettingModelBase.php index 506d52a2f..21f5ad2a6 100644 --- a/core/models/base/SettingModelBase.php +++ b/core/models/base/SettingModelBase.php @@ -68,6 +68,30 @@ public function getValueByName($name, $module = 'core') return $settingDao->getValue(); } + /** + * Return the value of a configuration setting given its name and module + * name or the given default value if not found. + * + * @param string $name configuration setting name + * @param bool|int|float|string $default configuration setting default value + * @param string $module module name + * @return bool|int|float|string configuration setting value or the given default value if not found + * @throws Zend_Exception + */ + public function getValueByNameWithDefault($name, $default, $module = 'core') + { + try { + $settingDao = $this->getDaoByName($name, $module); + if ($settingDao === false) { + return $default; + } + + return $settingDao->getValue(); + } catch (Zend_Db_Exception $exception) { + return $default; + } + } + /** Set Configuration value. */ /** diff --git a/core/models/base/UserModelBase.php b/core/models/base/UserModelBase.php index 66d139792..1f7a66f75 100644 --- a/core/models/base/UserModelBase.php +++ b/core/models/base/UserModelBase.php @@ -216,7 +216,7 @@ public function delete($user) // Remove references to this user as the uploader of item revisions (replace with superadmin) /** @var SettingModel $settingModel */ $settingModel = MidasLoader::loadModel('Setting'); - $adminId = $settingModel->getValueByName('adminuser'); + $adminId = (int) $settingModel->getValueByName('adminuser'); /** @var ItemRevisionModel $itemRevisionModel */ $itemRevisionModel = MidasLoader::loadModel('ItemRevision'); @@ -257,7 +257,7 @@ public function convertLegacyPasswordHash($userDao, $password) /** @var RandomComponent $randomComponent */ $randomComponent = MidasLoader::loadComponent('Random'); $userSalt = $randomComponent->generateString(32); - $instanceSalt = Zend_Registry::get('configGlobal')->password->prefix; + $instanceSalt = Zend_Registry::get('configGlobal')->get('password_prefix'); $hashedPassword = hash('sha256', $instanceSalt.$userSalt.$password); $this->storePasswordHash($hashedPassword); $userDao->setHashAlg('sha256'); @@ -272,7 +272,7 @@ public function convertLegacyPasswordHash($userDao, $password) */ public function changePassword($userDao, $password) { - $instanceSalt = Zend_Registry::get('configGlobal')->password->prefix; + $instanceSalt = Zend_Registry::get('configGlobal')->get('password_prefix'); /** @var RandomComponent $randomComponent */ $randomComponent = MidasLoader::loadComponent('Random'); @@ -313,7 +313,7 @@ public function createUser($email, $password, $firstname, $lastname, $admin = 0, throw new Zend_Exception('You must not pass a salt if you pass a plaintext password'); } // Generate a random salt for this new user - $instanceSalt = Zend_Registry::get('configGlobal')->password->prefix; + $instanceSalt = Zend_Registry::get('configGlobal')->get('password_prefix'); /** @var RandomComponent $randomComponent */ $randomComponent = MidasLoader::loadComponent('Random'); @@ -330,8 +330,11 @@ public function createUser($email, $password, $firstname, $lastname, $admin = 0, $this->save($userDao); // save the record before Gravatar lookup to shorten critical section // check Gravatar - $useGravatar = Zend_Registry::get('configGlobal')->gravatar; - if ($useGravatar) { + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + + $useGravatar = (int) $settingModel->getValueByNameWithDefault('gravatar', 0); + if ($useGravatar === 1) { $gravatarUrl = $this->getGravatarUrl($email); if ($gravatarUrl != false) { $userDao->setThumbnail($gravatarUrl); diff --git a/core/tests/controllers/UserControllerTest.php b/core/tests/controllers/UserControllerTest.php index 5a156d779..10e4d6280 100644 --- a/core/tests/controllers/UserControllerTest.php +++ b/core/tests/controllers/UserControllerTest.php @@ -42,6 +42,10 @@ public function testIndexAction() /** test register */ public function testRegisterAction() { + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + $settingModel->setConfig('close_registration', 0); + $this->dispatchUrl('/user/register'); $this->assertController('user'); $this->assertAction('register'); @@ -122,6 +126,11 @@ public function testTermofserviceAction() public function testRecoverpasswordAction() { $this->resetAll(); + + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + $settingModel->setConfig('allow_password_reset', 1); + $this->dispatchUrl('/user/recoverpassword', null, false); $this->assertQuery('form#recoverPasswordForm'); @@ -233,7 +242,7 @@ public function testSettingsAction() $this->assertQuery('div#tabsSettings'); $this->assertQuery('li.settingsCommunityList'); - $instanceSalt = Zend_Registry::get('configGlobal')->password->prefix; + $instanceSalt = Zend_Registry::get('configGlobal')->get('password_prefix'); // By changing password we will update the salt and hash $this->resetAll(); $this->params = array(); @@ -439,7 +448,7 @@ public function testDeleteUserAction() /** @var ItemModel $itemModel */ $itemModel = MidasLoader::loadModel('Item'); - $adminuserSetting = $settingModel->getValueByName('adminuser'); + $adminuserSetting = (int) $settingModel->getValueByName('adminuser'); $usersFile = $this->loadData('User', 'default'); $commFile = $this->loadData('Community', 'default'); $itemFile = $this->loadData('Item', 'default'); @@ -509,7 +518,7 @@ public function testDeleteSelfAction() $communityModel = MidasLoader::loadModel('Community'); $folderModel = MidasLoader::loadModel('Folder'); $itemModel = MidasLoader::loadModel('Item'); - $adminuserSetting = $settingModel->getValueByName('adminuser'); + $adminuserSetting = (int) $settingModel->getValueByName('adminuser'); $usersFile = $this->loadData('User', 'default'); $commFile = $this->loadData('Community', 'default'); $itemFile = $this->loadData('Item', 'default'); diff --git a/core/tests/controllers/api/RestKeyControllerTest.php b/core/tests/controllers/api/RestKeyControllerTest.php index d3da93547..3a87ac2f3 100644 --- a/core/tests/controllers/api/RestKeyControllerTest.php +++ b/core/tests/controllers/api/RestKeyControllerTest.php @@ -61,6 +61,10 @@ public function testChangePasswordChangesDefaultApiKey() /** Make sure adding a new user adds a default api key */ public function testNewUserGetsDefaultApiKey() { + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + $settingModel->setConfig('close_registration', 0); + // Register a new user $this->params['email'] = 'some.user@example.org'; $this->params['password1'] = 'midas'; diff --git a/core/tests/databaseDataset/default.xml b/core/tests/databaseDataset/default.xml index e7af67aa9..5809e15a3 100644 --- a/core/tests/databaseDataset/default.xml +++ b/core/tests/databaseDataset/default.xml @@ -1,5 +1,16 @@ + + + + + + + + + + @@ -125,9 +136,6 @@ - - - headScript()->appendFile($this->coreWebroot.'/public/js/jquery/jquery.clu echo "

    Configuration:

    -
    - - {$this->configForm['name']} +
    + + {$this->configForm['title']}
    -
    +
    {$this->configForm['description']}
    -
    - - ".$this->configForm['httpProxy']." -
    -
    internationalization) && Zend_Registry::get( - 'configCore' - )->internationalization == "0" - ) { + get('internationalization', 0) === 0) { echo " style='display:none;' "; } echo "> - - {$this->configForm['lang']} + + {$this->configForm['language']}
    -
    - - {$this->configForm['timezone']} +
    + + {$this->configForm['time_zone']}
    -
    - - {$this->configForm['dynamichelp']} +
    + + {$this->configForm['dynamic_help']}
    -
    +
    {$this->configForm['allow_password_reset']}
    -
    - - {$this->configForm['closeregistration']} +
    + + {$this->configForm['close_registration']}
    -
    +
    {$this->configForm['gravatar']}
    -
    +
    ".$this->element('license')."
    diff --git a/core/views/install/step3.phtml b/core/views/install/step3.phtml index 1c6127f5c..4f5ecb06e 100644 --- a/core/views/install/step3.phtml +++ b/core/views/install/step3.phtml @@ -37,10 +37,7 @@ $this->headScript()->appendFile($this->coreWebroot.'/public/js/install/install.s {$this->form['description']}
    internationalization) && Zend_Registry::get( - 'configCore' - )->internationalization == "0" - ) { + if ((int) Zend_Registry::get('configCore')->get('internationalization', 0) === 0) { echo " style='display:none;' "; } echo "> diff --git a/modules/api/tests/controllers/KeyControllerTest.php b/modules/api/tests/controllers/KeyControllerTest.php index 920162d59..58e72ed8a 100644 --- a/modules/api/tests/controllers/KeyControllerTest.php +++ b/modules/api/tests/controllers/KeyControllerTest.php @@ -62,6 +62,10 @@ public function testChangePasswordChangesDefaultApiKey() /** Make sure adding a new user adds a default api key */ public function testNewUserGetsDefaultApiKey() { + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + $settingModel->setConfig('close_registration', 0); + // Register a new user $this->params['email'] = 'some.user@server.com'; $this->params['password1'] = 'midas'; diff --git a/modules/batchmake/controllers/components/KWBatchmakeComponent.php b/modules/batchmake/controllers/components/KWBatchmakeComponent.php index ceff8ac94..035aff930 100644 --- a/modules/batchmake/controllers/components/KWBatchmakeComponent.php +++ b/modules/batchmake/controllers/components/KWBatchmakeComponent.php @@ -156,7 +156,7 @@ public function loadConfigProperties($alternateConfig = null, $batchmakeOnly = t if (isset($alternateConfig)) { $rawConfig = array(); $globalProps = array(); - } elseif (Zend_Registry::get('configGlobal')->environment == 'testing' + } elseif (Zend_Registry::get('configGlobal')->get('environment', 'production') === 'testing' ) { // it is acceptable not to be able to load a config if we are in // testing mode, can get the config from the Zend_Registry set diff --git a/modules/demo/Notification.php b/modules/demo/Notification.php index b85e64a1d..58dbd7b5f 100644 --- a/modules/demo/Notification.php +++ b/modules/demo/Notification.php @@ -29,7 +29,7 @@ public function init() { $fc = Zend_Controller_Front::getInstance(); $this->webroot = $fc->getBaseUrl(); - if ($this->Setting->getValueByName('enabled', $this->moduleName)) { + if ((int) $this->Setting->getValueByName('enabled', $this->moduleName) === 1) { $this->addCallBack('CALLBACK_CORE_GET_FOOTER_LAYOUT', 'getFooterLayout'); } } diff --git a/modules/googleauth/controllers/CallbackController.php b/modules/googleauth/controllers/CallbackController.php index b9bda9b6f..35802b06c 100644 --- a/modules/googleauth/controllers/CallbackController.php +++ b/modules/googleauth/controllers/CallbackController.php @@ -169,8 +169,8 @@ protected function _createOrGetUser($info) $user = $this->User->getByEmail($info['email']); if (!$user) { // Only create new user this way if registration is not closed. - $closeRegistration = Zend_Registry::get('configGlobal')->closeregistration; - if ($closeRegistration == '1') { + $closeRegistration = (int) $this->Setting->getValueByNameWithDefault('close_registration', 1); + if ($closeRegistration === 1) { throw new Zend_Exception( 'Access to this instance is by invitation '.'only, please contact an administrator.' ); diff --git a/modules/javauploaddownload/controllers/UploadController.php b/modules/javauploaddownload/controllers/UploadController.php index e92976d6c..8afb44a05 100644 --- a/modules/javauploaddownload/controllers/UploadController.php +++ b/modules/javauploaddownload/controllers/UploadController.php @@ -74,7 +74,7 @@ public function indexAction() $this->view->host = 'localhost'; } - $this->view->selectedLicense = Zend_Registry::get('configGlobal')->defaultlicense; + $this->view->selectedLicense = (int) $this->Setting->getValueByNameWithDefault('default_license', 1); $this->view->allLicenses = $this->License->getAll(); $this->view->defaultUploadLocation = ''; $this->view->defaultUploadLocationText = $this->t('You must select a folder'); @@ -140,7 +140,7 @@ public function revisionAction() if ($itemRevision) { $this->view->selectedLicense = $itemRevision->getLicenseId(); } else { - $this->view->selectedLicense = Zend_Registry::get('configGlobal')->defaultlicense; + $this->view->selectedLicense = (int) $this->Setting->getValueByNameWithDefault('default_license', 1); } $this->view->allLicenses = $this->License->getAll(); @@ -205,10 +205,10 @@ public function javadestinationfolderAction() $this->disableView(); $this->disableLayout(); - if (Zend_Registry::get('configGlobal')->environment != 'testing') { + if (Zend_Registry::get('configGlobal')->get('environment', 'production') !== 'testing') { // give a three day session cookie in case the download lasts a long time session_start(); - $this->userSession->setExpirationSeconds(60 * max(60 * 24 * 3, Zend_Registry::get('configGlobal')->session->lifetime)); + $this->userSession->setExpirationSeconds(60 * max(60 * 24 * 3, (int) Zend_Registry::get('configGlobal')->get('session_lifetime', 20))); session_write_close(); } @@ -332,7 +332,7 @@ public function processjavauploadAction() throw new Zend_Exception('You are attempting to upload into the incorrect parent folder'); } - $testingMode = Zend_Registry::get('configGlobal')->environment == 'testing'; + $testingMode = Zend_Registry::get('configGlobal')->get('environment', 'production') === 'testing'; $this->Component->Httpupload->setTestingMode($testingMode); $this->Component->Httpupload->setTokenParamName('uploadUniqueIdentifier'); $data = $this->Component->Httpupload->process($params); @@ -429,7 +429,7 @@ public function processjavarevisionuploadAction() throw new Zend_Exception('You are attempting to upload into the incorrect parent item'); } - $testingMode = Zend_Registry::get('configGlobal')->environment == 'testing'; + $testingMode = Zend_Registry::get('configGlobal')->get('environment', 'production') === 'testing'; $this->Component->Httpupload->setTestingMode($testingMode); $this->Component->Httpupload->setTokenParamName('uploadUniqueIdentifier'); $data = $this->Component->Httpupload->process($params); diff --git a/modules/mail/Notification.php b/modules/mail/Notification.php index 3e8754f6f..75d5bdad1 100644 --- a/modules/mail/Notification.php +++ b/modules/mail/Notification.php @@ -53,8 +53,8 @@ public function handleSendMailMessage($params) $transport = new Midas_Mail_Transport_Service($service); } elseif ($provider === MAIL_PROVIDER_SMTP) { $host = $this->Setting->getValueByName(MAIL_SMTP_HOST_KEY, $this->moduleName); - $port = $this->Setting->getValueByName(MAIL_SMTP_PORT_KEY, $this->moduleName); - $ssl = $this->Setting->getValueByName(MAIL_SMTP_USE_SSL_KEY, $this->moduleName); + $port = (int) $this->Setting->getValueByName(MAIL_SMTP_PORT_KEY, $this->moduleName); + $ssl = (int) $this->Setting->getValueByName(MAIL_SMTP_USE_SSL_KEY, $this->moduleName); $username = $this->Setting->getValueByName(MAIL_SMTP_USERNAME_KEY, $this->moduleName); $password = $this->Setting->getValueByName(MAIL_SMTP_PASSWORD_KEY, $this->moduleName); $config = array(); @@ -63,7 +63,7 @@ public function handleSendMailMessage($params) $config['port'] = $port; } - if ($ssl === '1') { + if ($ssl === 1) { $config['ssl'] = 'tls'; } diff --git a/modules/mfa/Notification.php b/modules/mfa/Notification.php index a5a6e3ede..7dd41b2b5 100644 --- a/modules/mfa/Notification.php +++ b/modules/mfa/Notification.php @@ -70,7 +70,7 @@ public function authIntercept($params) // write temp user into session for asynchronous confirmation Zend_Session::start(); $userSession = new Zend_Session_Namespace('Mfa_Temp_User'); - $userSession->setExpirationSeconds(60 * min(10, Zend_Registry::get('configGlobal')->session->lifetime)); // "limbo" state should invalidate after 10 minutes + $userSession->setExpirationSeconds(60 * min(10, (int) Zend_Registry::get('configGlobal')->get('session_lifetime', 20))); // "limbo" state should invalidate after 10 minutes $userSession->Dao = $user; $userSession->lock(); diff --git a/modules/mfa/controllers/LoginController.php b/modules/mfa/controllers/LoginController.php index bc82e587a..07c69a623 100644 --- a/modules/mfa/controllers/LoginController.php +++ b/modules/mfa/controllers/LoginController.php @@ -80,7 +80,7 @@ public function submitAction() if ($valid) { session_start(); $authUser = new Zend_Session_Namespace('Auth_User'); - $authUser->setExpirationSeconds(60 * Zend_Registry::get('configGlobal')->session->lifetime); + $authUser->setExpirationSeconds(60 * (int) Zend_Registry::get('configGlobal')->get('session_lifetime', 20)); $authUser->Dao = $user; $authUser->lock(); $this->getLogger()->debug(__METHOD__.' Log in : '.$user->getFullName()); diff --git a/modules/oai/library/oai/oaidp-util.php b/modules/oai/library/oai/oaidp-util.php index 7cfa5ebe3..838c0086b 100644 --- a/modules/oai/library/oai/oaidp-util.php +++ b/modules/oai/library/oai/oaidp-util.php @@ -402,7 +402,7 @@ function oai_exit() global $request; global $errors; - $environment = Zend_Registry::get('configGlobal')->environment; + $environment = Zend_Registry::get('configGlobal')->get('environment', 'production'); if ($environment != 'testing') { header('Content-Type: text/plain'); } diff --git a/modules/oauth/controllers/AuthorizeController.php b/modules/oauth/controllers/AuthorizeController.php index 47ce1f643..32b07d132 100644 --- a/modules/oauth/controllers/AuthorizeController.php +++ b/modules/oauth/controllers/AuthorizeController.php @@ -148,7 +148,7 @@ public function submitAction() return; } - $instanceSalt = Zend_Registry::get('configGlobal')->password->prefix; + $instanceSalt = Zend_Registry::get('configGlobal')->get('password_prefix'); $passwordHash = hash($userDao->getHashAlg(), $instanceSalt.$userDao->getSalt().$password); if ($this->User->hashExists($passwordHash)) { diff --git a/modules/remoteprocessing/Notification.php b/modules/remoteprocessing/Notification.php index 27a0172c5..556a9976c 100644 --- a/modules/remoteprocessing/Notification.php +++ b/modules/remoteprocessing/Notification.php @@ -63,7 +63,7 @@ public function getFooter() /** add a process button */ public function getButton($params) { - if ($this->Setting->getValueByName(MIDAS_REMOTEPROCESSING_SHOW_BUTTON_KEY, $this->moduleName) == 1) { + if ((int) $this->Setting->getValueByName(MIDAS_REMOTEPROCESSING_SHOW_BUTTON_KEY, $this->moduleName) === 1) { $html = "
  • diff --git a/modules/solr/controllers/components/SolrComponent.php b/modules/solr/controllers/components/SolrComponent.php index 806755d1e..f287f66fa 100644 --- a/modules/solr/controllers/components/SolrComponent.php +++ b/modules/solr/controllers/components/SolrComponent.php @@ -29,7 +29,7 @@ public function getSolrIndex() /** @var SettingModel $settingModel */ $settingModel = MidasLoader::loadModel('Setting'); $solrHost = $settingModel->getValueByName(SOLR_HOST_KEY, 'solr'); - $solrPort = $settingModel->getValueByName(SOLR_PORT_KEY, 'solr'); + $solrPort = (int) $settingModel->getValueByName(SOLR_PORT_KEY, 'solr'); $solrWebroot = $settingModel->getValueByName(SOLR_WEBROOT_KEY, 'solr'); if ($solrHost === null) { diff --git a/modules/statistics/controllers/components/ReportComponent.php b/modules/statistics/controllers/components/ReportComponent.php index 07805f32d..2136416c8 100644 --- a/modules/statistics/controllers/components/ReportComponent.php +++ b/modules/statistics/controllers/components/ReportComponent.php @@ -33,8 +33,11 @@ public function generate() /** @var AssetstoreModel $assetStoreModel */ $assetStoreModel = MidasLoader::loadModel('Assetstore'); $reportContent = ''; - $reportContent .= 'Midas Report: '.Zend_Registry::get('configGlobal')->application->name.''; - $reportContent .= '
    http://'.$_SERVER['SERVER_NAME']; + + /** @var SettingModel $settingModel */ + $settingModel = MidasLoader::loadModel('Setting'); + $reportContent .= 'Midas Report: '.$settingModel->getValueByNameWithDefault('title', 'Midas Platform - Digital Archiving System').''; + $reportContent .= '
    '.$_SERVER['SERVER_NAME']; $reportContent .= '

    Status'; $errors = $errorLogModel->getLog( diff --git a/modules/thumbnailcreator/controllers/components/ImagemagickComponent.php b/modules/thumbnailcreator/controllers/components/ImagemagickComponent.php index 44795eef6..10661e8d1 100644 --- a/modules/thumbnailcreator/controllers/components/ImagemagickComponent.php +++ b/modules/thumbnailcreator/controllers/components/ImagemagickComponent.php @@ -263,7 +263,7 @@ public function createThumbnailFromPath($name, $fullPath, $width, $height, $exac /** @var SettingModel $settingModel */ $settingModel = MidasLoader::loadModel('Setting'); $provider = $settingModel->getValueByName(MIDAS_THUMBNAILCREATOR_PROVIDER_KEY, $this->moduleName); - $useThumbnailer = $settingModel->getValueByName(MIDAS_THUMBNAILCREATOR_USE_THUMBNAILER_KEY, $this->moduleName); + $useThumbnailer = (int) $settingModel->getValueByName(MIDAS_THUMBNAILCREATOR_USE_THUMBNAILER_KEY, $this->moduleName); $preprocessedFormats = array('mha', 'nrrd'); $ext = strtolower(substr(strrchr($name, '.'), 1)); diff --git a/modules/tracker/controllers/components/ApiComponent.php b/modules/tracker/controllers/components/ApiComponent.php index 78974f2ce..9db6b2d31 100644 --- a/modules/tracker/controllers/components/ApiComponent.php +++ b/modules/tracker/controllers/components/ApiComponent.php @@ -312,7 +312,7 @@ public function scalarAdd($args) /** @var SettingModel $settingModel */ $settingModel = MidasLoader::loadModel('Setting'); - $nHours = $settingModel->getValueByName(MIDAS_TRACKER_TEMP_SCALAR_TTL_KEY, $this->moduleName); + $nHours = (int) $settingModel->getValueByName(MIDAS_TRACKER_TEMP_SCALAR_TTL_KEY, $this->moduleName); if (!$nHours) { $nHours = 24; // default to 24 hours } @@ -373,7 +373,7 @@ public function resultsUploadJson($args) /** @var SettingModel $settingModel */ $settingModel = MidasLoader::loadModel('Setting'); - $nHours = $settingModel->getValueByName(MIDAS_TRACKER_TEMP_SCALAR_TTL_KEY, $this->moduleName); + $nHours = (int) $settingModel->getValueByName(MIDAS_TRACKER_TEMP_SCALAR_TTL_KEY, $this->moduleName); if (!$nHours) { $nHours = MIDAS_TRACKER_TEMP_SCALAR_TTL_DEFAULT_VALUE; // default to 24 hours } diff --git a/modules/visualize/Notification.php b/modules/visualize/Notification.php index 067a4726c..77f352f68 100644 --- a/modules/visualize/Notification.php +++ b/modules/visualize/Notification.php @@ -78,9 +78,9 @@ public function canVisualize($params) /** generate dashboard information */ public function getDashboard() { - $useParaView = $this->Setting->getValueByName(VISUALIZE_USE_PARAVIEW_WEB_KEY, $this->moduleName); + $useParaView = (int) $this->Setting->getValueByName(VISUALIZE_USE_PARAVIEW_WEB_KEY, $this->moduleName); - if (!isset($useParaView) || !$useParaView) { + if ($useParaView === 0) { return false; } diff --git a/modules/visualize/controllers/ParaviewController.php b/modules/visualize/controllers/ParaviewController.php index e0e87cfa9..5dba5b3c3 100644 --- a/modules/visualize/controllers/ParaviewController.php +++ b/modules/visualize/controllers/ParaviewController.php @@ -47,12 +47,12 @@ public function surfaceAction() $this->view->header = $header; $paraViewWorkDirectory = $this->Setting->getValueByName(VISUALIZE_PARAVIEW_WEB_WORK_DIRECTORY_KEY, $this->moduleName); - $useParaView = $this->Setting->getValueByName(VISUALIZE_USE_PARAVIEW_WEB_KEY, $this->moduleName); - $useWebGL = $this->Setting->getValueByName(VISUALIZE_USE_WEB_GL_KEY, $this->moduleName); - $useSymlinks = $this->Setting->getValueByName(VISUALIZE_USE_SYMLINKS_KEY, $this->moduleName); + $useParaView = (int) $this->Setting->getValueByName(VISUALIZE_USE_PARAVIEW_WEB_KEY, $this->moduleName); + $useWebGL = (int) $this->Setting->getValueByName(VISUALIZE_USE_WEB_GL_KEY, $this->moduleName); + $useSymlinks = (int) $this->Setting->getValueByName(VISUALIZE_USE_SYMLINKS_KEY, $this->moduleName); $pwApp = $this->Setting->getValueByName(VISUALIZE_TOMCAT_ROOT_URL_KEY, $this->moduleName); - if (!isset($useParaView) || !$useParaView) { + if ($useParaView === 0) { throw new Zend_Exception('Please enable the use of a ParaViewWeb server on the module configuration page'); } @@ -70,7 +70,7 @@ public function surfaceAction() } $bitstreams = $revision->getBitstreams(); foreach ($bitstreams as $bitstream) { - if ($useSymlinks) { + if ($useSymlinks === 1) { symlink($bitstream->getFullPath(), $path.'/'.$bitstream->getName()); } else { copy($bitstream->getFullPath(), $path.'/'.$bitstream->getName()); @@ -82,7 +82,7 @@ public function surfaceAction() } } - if (!$useWebGL || $item->getSizebytes() > 1 * 1024 * 1024) { + if ($useWebGL === 0 || $item->getSizebytes() > 1 * 1024 * 1024) { $this->view->renderer = 'js'; } else { $this->view->renderer = 'webgl'; @@ -138,11 +138,11 @@ public function dualAction() $this->view->header = $header; $paraViewWorkDirectory = $this->Setting->getValueByName(VISUALIZE_PARAVIEW_WEB_WORK_DIRECTORY_KEY, $this->moduleName); - $useParaView = $this->Setting->getValueByName(VISUALIZE_USE_PARAVIEW_WEB_KEY, $this->moduleName); - $useSymlinks = $this->Setting->getValueByName(VISUALIZE_USE_SYMLINKS_KEY, $this->moduleName); + $useParaView = (int) $this->Setting->getValueByName(VISUALIZE_USE_PARAVIEW_WEB_KEY, $this->moduleName); + $useSymlinks = (int) $this->Setting->getValueByName(VISUALIZE_USE_SYMLINKS_KEY, $this->moduleName); $pwApp = $this->Setting->getValueByName(VISUALIZE_TOMCAT_ROOT_URL_KEY, $this->moduleName); - if (!isset($useParaView) || !$useParaView) { + if ($useParaView === 0) { throw new Zend_Exception('Please enable the use of a ParaViewWeb server on the module configuration page'); } @@ -163,7 +163,7 @@ public function dualAction() } $bitstreams = $revision->getBitstreams(); foreach ($bitstreams as $bitstream) { - if ($useSymlinks) { + if ($useSymlinks === 1) { symlink($bitstream->getFullPath(), $subPath.'/'.$bitstream->getName()); } else { copy($bitstream->getFullPath(), $subPath.'/'.$bitstream->getName()); @@ -231,11 +231,11 @@ public function volumeAction() $this->view->header = $header; $paraViewWorkDirectory = $this->Setting->getValueByName(VISUALIZE_PARAVIEW_WEB_WORK_DIRECTORY_KEY, $this->moduleName); - $useParaView = $this->Setting->getValueByName(VISUALIZE_USE_PARAVIEW_WEB_KEY, $this->moduleName); - $useSymlinks = $this->Setting->getValueByName(VISUALIZE_USE_SYMLINKS_KEY, $this->moduleName); + $useParaView = (int) $this->Setting->getValueByName(VISUALIZE_USE_PARAVIEW_WEB_KEY, $this->moduleName); + $useSymlinks = (int) $this->Setting->getValueByName(VISUALIZE_USE_SYMLINKS_KEY, $this->moduleName); $pwApp = $this->Setting->getValueByName(VISUALIZE_TOMCAT_ROOT_URL_KEY, $this->moduleName); - if (!isset($useParaView) || !$useParaView) { + if ($useParaView === 0) { throw new Zend_Exception('Please enable the use of a ParaViewWeb server on the module configuration page'); } @@ -253,7 +253,7 @@ public function volumeAction() } $bitstreams = $revision->getBitstreams(); foreach ($bitstreams as $bitstream) { - if ($useSymlinks) { + if ($useSymlinks === 1) { symlink($bitstream->getFullPath(), $path.'/'.$bitstream->getName()); } else { copy($bitstream->getFullPath(), $path.'/'.$bitstream->getName()); @@ -386,11 +386,11 @@ public function sliceAction() $this->view->header = $header; $paraViewWorkDirectory = $this->Setting->getValueByName(VISUALIZE_PARAVIEW_WEB_WORK_DIRECTORY_KEY, $this->moduleName); - $useParaView = $this->Setting->getValueByName(VISUALIZE_USE_PARAVIEW_WEB_KEY, $this->moduleName); - $useSymlinks = $this->Setting->getValueByName(VISUALIZE_USE_SYMLINKS_KEY, $this->moduleName); + $useParaView = (int) $this->Setting->getValueByName(VISUALIZE_USE_PARAVIEW_WEB_KEY, $this->moduleName); + $useSymlinks = (int) $this->Setting->getValueByName(VISUALIZE_USE_SYMLINKS_KEY, $this->moduleName); $pwApp = $this->Setting->getValueByName(VISUALIZE_TOMCAT_ROOT_URL_KEY, $this->moduleName); - if (!isset($useParaView) || !$useParaView) { + if ($useParaView === 0) { throw new Zend_Exception('Please enable the use of a ParaViewWeb server on the module configuration page'); } @@ -408,7 +408,7 @@ public function sliceAction() } $bitstreams = $revision->getBitstreams(); foreach ($bitstreams as $bitstream) { - if ($useSymlinks) { + if ($useSymlinks === 1) { symlink($bitstream->getFullPath(), $path.'/'.$bitstream->getName()); } else { copy($bitstream->getFullPath(), $path.'/'.$bitstream->getName()); diff --git a/modules/visualize/controllers/TxtController.php b/modules/visualize/controllers/TxtController.php index 38b83de04..1baef807e 100644 --- a/modules/visualize/controllers/TxtController.php +++ b/modules/visualize/controllers/TxtController.php @@ -45,7 +45,7 @@ public function indexAction() throw new Zend_Exception('The item has no bitstreams', MIDAS_INVALID_POLICY); } $this->bistream = $bitstreams[0]; - if (Zend_Registry::get('configGlobal')->environment != 'testing') { + if (Zend_Registry::get('configGlobal')->get('environment', 'production') !== 'testing') { header('content-type: text/plain'); } echo '
    ';
    diff --git a/modules/visualize/controllers/components/MainComponent.php b/modules/visualize/controllers/components/MainComponent.php
    index d42829fe4..4db3d3eda 100644
    --- a/modules/visualize/controllers/components/MainComponent.php
    +++ b/modules/visualize/controllers/components/MainComponent.php
    @@ -30,9 +30,9 @@ public function convertToThreejs($revision)
         {
             /** @var SettingModel $settingModel */
             $settingModel = MidasLoader::loadModel('Setting');
    -        $useWebGL = $settingModel->getValueByName(VISUALIZE_USE_WEB_GL_KEY, $this->moduleName);
    +        $useWebGL = (int) $settingModel->getValueByName(VISUALIZE_USE_WEB_GL_KEY, $this->moduleName);
     
    -        if (!isset($useWebGL) || !$useWebGL) {
    +        if ($useWebGL === 0) {
                 return false;
             }
     
    @@ -128,9 +128,9 @@ public function canVisualizeWithSliceView($itemDao)
         {
             /** @var SettingModel $settingModel */
             $settingModel = MidasLoader::loadModel('Setting');
    -        $useParaView = $settingModel->getValueByName(VISUALIZE_USE_PARAVIEW_WEB_KEY, $this->moduleName);
    +        $useParaView = (int) $settingModel->getValueByName(VISUALIZE_USE_PARAVIEW_WEB_KEY, $this->moduleName);
     
    -        if (!isset($useParaView) || !$useParaView) {
    +        if ($useParaView === 0) {
                 return false;
             }
     
    @@ -157,9 +157,9 @@ public function canVisualizeWithSurfaceView($itemDao)
         {
             /** @var SettingModel $settingModel */
             $settingModel = MidasLoader::loadModel('Setting');
    -        $useParaView = $settingModel->getValueByName(VISUALIZE_USE_PARAVIEW_WEB_KEY, $this->moduleName);
    +        $useParaView = (int) $settingModel->getValueByName(VISUALIZE_USE_PARAVIEW_WEB_KEY, $this->moduleName);
     
    -        if (!isset($useParaView) || !$useParaView) {
    +        if ($useParaView === 0) {
                 return false;
             }
     
    @@ -186,9 +186,9 @@ public function canVisualizeWithParaview($itemDao)
         {
             /** @var SettingModel $settingModel */
             $settingModel = MidasLoader::loadModel('Setting');
    -        $useParaView = $settingModel->getValueByName(VISUALIZE_USE_PARAVIEW_WEB_KEY, $this->moduleName);
    +        $useParaView = (int) $settingModel->getValueByName(VISUALIZE_USE_PARAVIEW_WEB_KEY, $this->moduleName);
     
    -        if (!isset($useParaView) || !$useParaView) {
    +        if ($useParaView === 0) {
                 return false;
             }
     
    @@ -334,7 +334,7 @@ public function processParaviewData($itemDao)
             /** @var SettingModel $settingModel */
             $settingModel = MidasLoader::loadModel('Setting');
             $paraViewWorkDirectory = $settingModel->getValueByName(VISUALIZE_PARAVIEW_WEB_WORK_DIRECTORY_KEY, $this->moduleName);
    -        $useSymlinks = $settingModel->getValueByName(VISUALIZE_USE_SYMLINKS_KEY, $this->moduleName);
    +        $useSymlinks = (int) $settingModel->getValueByName(VISUALIZE_USE_SYMLINKS_KEY, $this->moduleName);
             $pwApp = $settingModel->getValueByName(VISUALIZE_TOMCAT_ROOT_URL_KEY, $this->moduleName);
             $pvBatch = $settingModel->getValueByName(VISUALIZE_PVBATCH_COMMAND_KEY, $this->moduleName);
     
    @@ -352,7 +352,7 @@ public function processParaviewData($itemDao)
             }
             $bitstreams = $revision->getBitstreams();
             foreach ($bitstreams as $bitstream) {
    -            if ($useSymlinks) {
    +            if ($useSymlinks === 1) {
                     symlink($bitstream->getFullPath(), $path.'/'.$bitstream->getName());
                 } else {
                     copy($bitstream->getFullPath(), $path.'/'.$bitstream->getName());