mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
NEW: suffix subfolder in silverstripe-cache with php-version (#6810)
Note that this changes the default temp path value * Was: /tmp/silverstripe-cache-Users-FOO-webroot-BAR-php7.1.5/USER * Now: /tmp/silverstripe-cache-Users-FOO-webroot-BAR/USER-php7.1.5
This commit is contained in:
parent
273a087f5a
commit
a990c99d6e
@ -11,8 +11,9 @@
|
||||
function getTempFolder($base = null) {
|
||||
$parent = getTempParentFolder($base);
|
||||
|
||||
// The actual temp folder is a subfolder of getTempParentFolder(), named by username
|
||||
$subfolder = $parent . DIRECTORY_SEPARATOR . getTempFolderUsername();
|
||||
// The actual temp folder is a subfolder of getTempParentFolder(), named by username and suffixed with currently used php-version
|
||||
$phpversion = '-php' . preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION);
|
||||
$subfolder = $parent . DIRECTORY_SEPARATOR . getTempFolderUsername() . $phpversion;
|
||||
|
||||
if(!@file_exists($subfolder)) {
|
||||
mkdir($subfolder);
|
||||
@ -64,7 +65,7 @@ function getTempParentFolder($base = null) {
|
||||
|
||||
// failing the above, try finding a namespaced silverstripe-cache dir in the system temp
|
||||
$tempPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR .
|
||||
'silverstripe-cache-php' . preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION) .
|
||||
'silverstripe-cache' .
|
||||
str_replace(array(' ', '/', ':', '\\'), '-', $base);
|
||||
if(!@file_exists($tempPath)) {
|
||||
$oldUMask = umask(0);
|
||||
|
@ -17,27 +17,25 @@ class CoreTest extends SapphireTest {
|
||||
|
||||
public function testGetTempPathInProject() {
|
||||
$user = getTempFolderUsername();
|
||||
|
||||
$phpversion = '-php' . preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION);
|
||||
if(file_exists($this->tempPath)) {
|
||||
$this->assertEquals(getTempFolder(BASE_PATH), $this->tempPath . DIRECTORY_SEPARATOR . $user);
|
||||
$this->assertEquals(getTempFolder(BASE_PATH), $this->tempPath . DIRECTORY_SEPARATOR . $user . $phpversion);
|
||||
} else {
|
||||
$user = getTempFolderUsername();
|
||||
$base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache-php' .
|
||||
preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION);
|
||||
$base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache';
|
||||
|
||||
// A typical Windows location for where sites are stored on IIS
|
||||
$this->assertEquals(
|
||||
$base . 'C--inetpub-wwwroot-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user,
|
||||
$base . 'C--inetpub-wwwroot-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user . $phpversion,
|
||||
getTempFolder('C:\\inetpub\\wwwroot\\silverstripe-test-project'));
|
||||
|
||||
// A typical Mac OS X location for where sites are stored
|
||||
$this->assertEquals(
|
||||
$base . '-Users-joebloggs-Sites-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user,
|
||||
$base . '-Users-joebloggs-Sites-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user . $phpversion,
|
||||
getTempFolder('/Users/joebloggs/Sites/silverstripe-test-project'));
|
||||
|
||||
// A typical Linux location for where sites are stored
|
||||
$this->assertEquals(
|
||||
$base . '-var-www-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user,
|
||||
$base . '-var-www-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user . $phpversion,
|
||||
getTempFolder('/var/www/silverstripe-test-project'));
|
||||
}
|
||||
}
|
||||
@ -45,8 +43,9 @@ class CoreTest extends SapphireTest {
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
$user = getTempFolderUsername();
|
||||
$base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache-php' .
|
||||
preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION);
|
||||
$phpversion = '-php' . preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION);
|
||||
$base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache' . $phpversion;
|
||||
|
||||
foreach(array(
|
||||
'C--inetpub-wwwroot-silverstripe-test-project',
|
||||
'-Users-joebloggs-Sites-silverstripe-test-project',
|
||||
@ -54,10 +53,9 @@ class CoreTest extends SapphireTest {
|
||||
) as $dir) {
|
||||
$path = $base . $dir;
|
||||
if(file_exists($path)) {
|
||||
rmdir($path . DIRECTORY_SEPARATOR . $user);
|
||||
rmdir($path . DIRECTORY_SEPARATOR . $user . $phpversion);
|
||||
rmdir($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user