Skip to content

Instantly share code, notes, and snippets.

@lerni
Last active January 15, 2018 10:20
Show Gist options
  • Save lerni/728db328acf3fcc38fac5419270745b1 to your computer and use it in GitHub Desktop.
Save lerni/728db328acf3fcc38fac5419270745b1 to your computer and use it in GitHub Desktop.
diff --git a/core/TempPath.php b/core/TempPath.php
index 88979ba..4f3a94c 100644
--- a/core/TempPath.php
+++ b/core/TempPath.php
@@ -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);
diff --git a/tests/core/CoreTest.php b/tests/core/CoreTest.php
index 7e79154..c42701a 100644
--- a/tests/core/CoreTest.php
+++ b/tests/core/CoreTest.php
@@ -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);
+ $this->assertEquals(getTempFolder(BASE_PATH), $this->tempPath . DIRECTORY_SEPARATOR . $user . $phpversion);
// 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,8 @@ 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 +52,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);
}
}
}
-
-}
+}
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment