diff --git a/core/GlobalController.php b/core/GlobalController.php index 2b284cfd8..0e43542ad 100644 --- a/core/GlobalController.php +++ b/core/GlobalController.php @@ -325,14 +325,24 @@ public function getEnvironment() return $config->environment; } + /** + * @method protected getDataDirectory() + * get the midas data directory + * @return string + */ + protected function getDataDirectory($subdir = '') + { + return UtilityComponent::getDataDirectory($subdir); + } + /** * @method protected getTempDirectory() * get the midas temporary directory * @return string */ - protected function getTempDirectory() + protected function getTempDirectory($subdir = 'misc') { - return UtilityComponent::getTempDirectory(); + return UtilityComponent::getTempDirectory($subdir); } /** return an array of form element */ diff --git a/core/controllers/InstallController.php b/core/controllers/InstallController.php index dc2700f56..6ed40dcc0 100644 --- a/core/controllers/InstallController.php +++ b/core/controllers/InstallController.php @@ -226,7 +226,7 @@ function step2Action() // create default assetstore $assetstoreDao = new AssetstoreDao(); $assetstoreDao->setName('Local'); - $assetstoreDao->setPath(BASE_PATH . '/data/assetstore'); + $assetstoreDao->setPath($this->getDataDirectory('assetstore')); $assetstoreDao->setType(MIDAS_ASSETSTORE_LOCAL); $this->Assetstore = new AssetstoreModel(); //reset Database adapter $this->Assetstore->save($assetstoreDao); diff --git a/core/controllers/UploadController.php b/core/controllers/UploadController.php index f737604b4..c9758fb10 100644 --- a/core/controllers/UploadController.php +++ b/core/controllers/UploadController.php @@ -51,7 +51,7 @@ function init() { $assetstoreDao = new AssetstoreDao(); $assetstoreDao->setName('Default'); - $assetstoreDao->setPath(BASE_PATH.'/data/assetstore'); + $assetstoreDao->setPath($this->getDataDirectory('assetstore')); $assetstoreDao->setType(MIDAS_ASSETSTORE_LOCAL); $this->Assetstore = new AssetstoreModel(); //reset Database adapter $this->Assetstore->save($assetstoreDao); diff --git a/core/controllers/UserController.php b/core/controllers/UserController.php index 19e224b90..7682887f9 100644 --- a/core/controllers/UserController.php +++ b/core/controllers/UserController.php @@ -852,10 +852,10 @@ public function settingsAction() return; } - $tmpPath = BASE_PATH.'/data/thumbnail/'.rand(1, 1000); - if(!file_exists(BASE_PATH.'/data/thumbnail/')) + $tmpPath = $this->getDataDirectory('thumbnail').rand(1, 1000); + if(!file_exists($this->getDataDirectory('thumbnail'))) { - throw new Zend_Exception("Thumbnail path does not exist: ".BASE_PATH.'/data/thumbnail/'); + throw new Zend_Exception("Thumbnail path does not exist: ".$this->getDataDirectory('thumbnail')); } if(!file_exists($tmpPath)) { diff --git a/core/controllers/components/DemoComponent.php b/core/controllers/components/DemoComponent.php index 514d2f128..ea521d9a7 100644 --- a/core/controllers/components/DemoComponent.php +++ b/core/controllers/components/DemoComponent.php @@ -38,7 +38,7 @@ public function reset() $db->query("DELETE FROM `".$row['TABLE_NAME']."`"); } - $path = BASE_PATH.'/data/assetstore'; + $path = UtilityComponent::getDataDirectory('assetstore'); $dir = opendir($path); while($entry = readdir($dir)) { @@ -48,7 +48,7 @@ public function reset() } } - $path = BASE_PATH.'/data/thumbnail'; + $path = UtilityComponent::getDataDirectory('thumbnail'); $dir = opendir($path); while($entry = readdir($dir)) { @@ -73,7 +73,7 @@ public function reset() $assetstoreDao = new AssetstoreDao(); $assetstoreDao->setName('Default'); - $assetstoreDao->setPath(BASE_PATH.'/data/assetstore'); + $assetstoreDao->setPath(UtilityComponent::getDataDirectory('assetstore')); $assetstoreDao->setType(MIDAS_ASSETSTORE_LOCAL); $assetstoreModel->save($assetstoreDao); diff --git a/core/controllers/components/UtilityComponent.php b/core/controllers/components/UtilityComponent.php index c3226d6d9..788a997aa 100644 --- a/core/controllers/components/UtilityComponent.php +++ b/core/controllers/components/UtilityComponent.php @@ -411,6 +411,33 @@ static function run_pgsql_from_file($sqlfile, $host, $username, $password, $dbna return self::run_query_from_file('Pdo_Pgsql', $sqlfile, $host, $username, $password, $dbname, $port); } + /** Get the data directory */ + public static function getDataDirectory($subdir = '') + { + $settingModel = MidasLoader::loadModel('Setting'); + try + { + $dataDirectory = $settingModel->getValueByName('data_directory'); + } + catch(Exception $e) + { + $dataDirectory = null; + } + if(!isset($dataDirectory) || empty($dataDirectory)) + { + $dataDirectory = BASE_PATH.'/data'; + } + if($subdir == '') + { + $dataDirectory .= '/'; + } + else + { + $dataDirectory .= '/'.$subdir.'/'; + } + return $dataDirectory; + } + /** * @method public getTempDirectory() * @param $subdir diff --git a/core/models/base/ItemRevisionModelBase.php b/core/models/base/ItemRevisionModelBase.php index f6c428636..0e013cd80 100644 --- a/core/models/base/ItemRevisionModelBase.php +++ b/core/models/base/ItemRevisionModelBase.php @@ -122,10 +122,10 @@ function addBitstream($itemRevisionDao, $bitstreamDao) if($createThumb) { - $tmpPath = BASE_PATH.'/data/thumbnail'; + $tmpPath = UtilityComponent::getDataDirectory('thumbnail'); if(!file_exists($tmpPath)) { - throw new Zend_Exception("Problem thumbnail path: ".BASE_PATH.'/data/thumbnail/'); + throw new Zend_Exception("Problem thumbnail path: ".UtilityComponent::getDataDirectory('thumbnail')); } $destination = $tmpPath.'/'.rand(1, 10000).'.jpeg'; while(file_exists($destination)) diff --git a/modules/packages/controllers/components/ApiComponent.php b/modules/packages/controllers/components/ApiComponent.php index f1a261395..e07b654c3 100644 --- a/modules/packages/controllers/components/ApiComponent.php +++ b/modules/packages/controllers/components/ApiComponent.php @@ -53,7 +53,7 @@ private function _readUploadedFile($prefix) { set_time_limit(0); $inputfile = 'php://input'; - $tmpfile = tempnam(BASE_PATH.'/tmp/misc', $prefix); + $tmpfile = tempnam(UtilityComponent::getTempDirectory('misc'), $prefix); $in = fopen($inputfile, 'rb'); $out = fopen($tmpfile, 'wb'); diff --git a/modules/pvw/controllers/components/ParaviewComponent.php b/modules/pvw/controllers/components/ParaviewComponent.php index 88e4dd81d..ad6bd842b 100644 --- a/modules/pvw/controllers/components/ParaviewComponent.php +++ b/modules/pvw/controllers/components/ParaviewComponent.php @@ -142,7 +142,7 @@ public function killInstance($instance) exec('kill -9 '.$instance->getPid()); } - UtilityComponent::rrmdir(BASE_PATH.'/tmp/pvw-data/'.$instance->getKey()); + UtilityComponent::rrmdir(UtilityComponent::getTempDirectory('pvw-data').$instance->getKey()); $instanceModel = MidasLoader::loadModel('Instance', 'pvw'); $instanceModel->delete($instance); @@ -204,11 +204,11 @@ private function _getNextOpenPort() */ private function _createDataDir($itemDao, $meshItems, $instanceDao) { - if(!is_dir(BASE_PATH.'/tmp/pvw-data')) + if(!is_dir(UtilityComponent::getTempDirectory('pvw-data'))) { - mkdir(BASE_PATH.'/tmp/pvw-data'); + mkdir(UtilityComponent::getTempDirectory('pvw-data')); } - $path = BASE_PATH.'/tmp/pvw-data/'.$instanceDao->getKey(); + $path = UtilityComponent::getTempDirectory('pvw-data').$instanceDao->getKey(); mkdir($path); mkdir($path.'/main'); mkdir($path.'/surfaces'); diff --git a/modules/thumbnailcreator/controllers/components/ImagemagickComponent.php b/modules/thumbnailcreator/controllers/components/ImagemagickComponent.php index 89d69d3ee..eaa2e84ba 100644 --- a/modules/thumbnailcreator/controllers/components/ImagemagickComponent.php +++ b/modules/thumbnailcreator/controllers/components/ImagemagickComponent.php @@ -110,15 +110,15 @@ public function createThumbnailFromPath($name, $fullPath, $width, $height, $exac } // create destination - $tmpPath = BASE_PATH.'/data/thumbnail'; + $tmpPath = UtilityComponent::getDataDirectory('thumbnail'); if(!file_exists($tmpPath)) { - throw new Zend_Exception('Temporary thumbnail dir does not exist: '.BASE_PATH.'/data/thumbnail/'); + throw new Zend_Exception('Temporary thumbnail dir does not exist: '.UtilityComponent::getDataDirectory('thumbnail')); } - $destination = $tmpPath.'/'.rand(1, 10000).'.jpeg'; + $destination = $tmpPath.rand(1, 10000).'.jpeg'; while(file_exists($destination)) { - $destination = $tmpPath.'/'.rand(1, 10000).'.jpeg'; + $destination = $tmpPath.rand(1, 10000).'.jpeg'; } $pathThumbnail = $destination; @@ -186,19 +186,19 @@ public function createThumbnailFromPath($name, $fullPath, $width, $height, $exac */ public function preprocessByThumbnailer($name, $fullpath) { - $tmpPath = BASE_PATH.'/data/thumbnail'; + $tmpPath = UtilityComponent::getDataDirectory('thumbnail'); if(!file_exists($tmpPath)) { - throw new Zend_Exception('Temporary thumbnail dir does not exist: '.BASE_PATH.'/data/thumbnail/'); + throw new Zend_Exception('Temporary thumbnail dir does not exist: '.UtilityComponent::getDataDirectory('thumbnail')); } - $copyDestination = $tmpPath.'/'.$name; + $copyDestination = $tmpPath.$name; copy($fullpath, $copyDestination); - $jpegDestination = $tmpPath.'/'.$name.'.jpeg'; + $jpegDestination = $tmpPath.$name.'.jpeg'; while(file_exists($jpegDestination)) { - $jpegDestination = $tmpPath.'/'.$name.rand(1, 10000).'.jpeg'; + $jpegDestination = $tmpPath.$name.rand(1, 10000).'.jpeg'; } $modulesConfig = Zend_Registry::get('configsModules'); $thumbnailerPath = $modulesConfig['thumbnailcreator']->thumbnailer; diff --git a/modules/visualize/controllers/components/MainComponent.php b/modules/visualize/controllers/components/MainComponent.php index ce052d95e..f717b2466 100644 --- a/modules/visualize/controllers/components/MainComponent.php +++ b/modules/visualize/controllers/components/MainComponent.php @@ -451,10 +451,10 @@ public function processParaviewData($itemDao) return; } - $thumbnailPath = BASE_PATH.'/data/thumbnail/'.rand(1, 1000); - if(!file_exists(BASE_PATH.'/data/thumbnail/')) + $thumbnailPath = UtilityComponent::getDataDirectory('thumbnail').rand(1, 1000); + if(!file_exists(UtilityComponent::getDataDirectory('thumbnail'))) { - throw new Zend_Exception("Problem thumbnail path: ".BASE_PATH.'/data/thumbnail/'); + throw new Zend_Exception("Problem thumbnail path: ".UtilityComponent::getDataDirectory('thumbnail')); } if(!file_exists($thumbnailPath)) { @@ -499,7 +499,7 @@ public function processParaviewData($itemDao) $itemDao->setThumbnail(substr($pathThumbnail, strlen(BASE_PATH) + 1)); $itemModel->save($itemDao); - $data_dir = BASE_PATH.'/data/visualize/'; + $data_dir = UtilityComponent::getDataDirectory('visualize'); if(!file_exists($data_dir)) { mkdir($data_dir);