mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Move getTempFolder out of Core.php to own file
This commit is contained in:
parent
5796ed225e
commit
31429b7936
@ -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.
|
||||
*
|
||||
|
60
core/TempPath.php
Normal file
60
core/TempPath.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user