Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Allow for custom data and temp directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Snape committed Jun 27, 2014
1 parent ed3490f commit ce47c9e
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 30 deletions.
14 changes: 12 additions & 2 deletions core/GlobalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion core/controllers/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion core/controllers/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions core/controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
6 changes: 3 additions & 3 deletions core/controllers/components/DemoComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -48,7 +48,7 @@ public function reset()
}
}

$path = BASE_PATH.'/data/thumbnail';
$path = UtilityComponent::getDataDirectory('thumbnail');
$dir = opendir($path);
while($entry = readdir($dir))
{
Expand All @@ -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);

Expand Down
27 changes: 27 additions & 0 deletions core/controllers/components/UtilityComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions core/models/base/ItemRevisionModelBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion modules/packages/controllers/components/ApiComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
8 changes: 4 additions & 4 deletions modules/pvw/controllers/components/ParaviewComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions modules/visualize/controllers/components/MainComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ce47c9e

Please sign in to comment.