diff --git a/core/Core.php b/core/Core.php index 4c5236f4f..3959fb76e 100755 --- a/core/Core.php +++ b/core/Core.php @@ -173,6 +173,7 @@ define('ASSETS_PATH', BASE_PATH . '/' . ASSETS_DIR); /** * Define the temporary folder if it wasn't defined yet */ +require_once('core/TempPath.php'); if(!defined('TEMP_FOLDER')) { define('TEMP_FOLDER', getTempFolder()); } @@ -254,65 +255,6 @@ Debug::loadErrorHandlers(); /////////////////////////////////////////////////////////////////////////////// // HELPER FUNCTIONS -function getSysTempDir() { - if(function_exists('sys_get_temp_dir')) { - $sysTmp = sys_get_temp_dir(); - } elseif(isset($_ENV['TMP'])) { - $sysTmp = $_ENV['TMP']; - } else { - $tmpFile = tempnam('adfadsfdas',''); - unlink($tmpFile); - $sysTmp = dirname($tmpFile); - } - return $sysTmp; -} - -/** - * Returns the temporary folder that sapphire/silverstripe should use for its cache files - * This is loaded into the TEMP_FOLDER define on start up - * - * @param $base The base path to use as the basis for the temp folder name. Defaults to BASE_PATH, - * which is usually fine; however, the $base argument can be used to help test. - */ -function getTempFolder($base = null) { - if(!$base) $base = BASE_PATH; - - if($base) { - $cachefolder = "silverstripe-cache" . str_replace(array(' ', "/", ":", "\\"), "-", $base); - } else { - $cachefolder = "silverstripe-cache"; - } - - $ssTmp = BASE_PATH . "/silverstripe-cache"; - if(@file_exists($ssTmp)) { - return $ssTmp; - } - - $sysTmp = getSysTempDir(); - $worked = true; - $ssTmp = "$sysTmp/$cachefolder"; - - if(!@file_exists($ssTmp)) { - @$worked = mkdir($ssTmp); - } - - if(!$worked) { - $ssTmp = BASE_PATH . "/silverstripe-cache"; - $worked = true; - if(!@file_exists($ssTmp)) { - @$worked = mkdir($ssTmp); - } - } - - if(!$worked) { - user_error("Permission problem gaining access to a temp folder. " . - "Please create a folder named silverstripe-cache in the base folder " . - "of the installation and ensure it has the correct permissions", E_USER_ERROR); - } - - return $ssTmp; -} - /** * Return the file where that class is stored. * diff --git a/core/TempPath.php b/core/TempPath.php new file mode 100644 index 000000000..c3b0a111d --- /dev/null +++ b/core/TempPath.php @@ -0,0 +1,60 @@ +