diff --git a/_config/cache.yml b/_config/cache.yml index 4eca4560d..9bcb5dc47 100644 --- a/_config/cache.yml +++ b/_config/cache.yml @@ -6,7 +6,7 @@ SilverStripe\Core\Injector\Injector: class: 'SilverStripe\Core\Cache\DefaultCacheFactory' constructor: args: - directory: '`TEMP_FOLDER`' + directory: '`TEMP_PATH`' version: null logger: '%$Psr\Log\LoggerInterface' Psr\SimpleCache\CacheInterface.cacheblock: diff --git a/_config/i18n.yml b/_config/i18n.yml index b5629f3ff..32e72f433 100644 --- a/_config/i18n.yml +++ b/_config/i18n.yml @@ -38,7 +38,7 @@ SilverStripe\Core\Injector\Injector: constructor: 0: 'en' 1: null - 2: '`TEMP_FOLDER`' + 2: '`TEMP_PATH`' properties: ConfigCacheFactory: '%$Symfony\Component\Config\ConfigCacheFactoryInterface' calls: diff --git a/docs/en/02_Developer_Guides/16_Execution_Pipeline/index.md b/docs/en/02_Developer_Guides/16_Execution_Pipeline/index.md index f43de804b..9d249beab 100644 --- a/docs/en/02_Developer_Guides/16_Execution_Pipeline/index.md +++ b/docs/en/02_Developer_Guides/16_Execution_Pipeline/index.md @@ -84,7 +84,7 @@ tasks silently in the background. * Tries to locate an `.env` [configuration file](/getting_started/environment_management) in the webroot. - * Sets constants based on the filesystem structure (e.g. `BASE_URL`, `BASE_PATH` and `TEMP_FOLDER`) + * Sets constants based on the filesystem structure (e.g. `BASE_URL`, `BASE_PATH` and `TEMP_PATH`) All requests go through `main.php`, which sets up the core [Kernel](api:SilverStripe\Core\Kernel) and [HTTPApplication](api:SilverStripe\Control\HTTPApplication) objects. See [/developer_guides/execution_pipeline/app_object_and_kernel] for details on this. diff --git a/docs/en/04_Changelogs/4.0.0.md b/docs/en/04_Changelogs/4.0.0.md index 40ba5ddd8..18717b25b 100644 --- a/docs/en/04_Changelogs/4.0.0.md +++ b/docs/en/04_Changelogs/4.0.0.md @@ -65,6 +65,7 @@ guide developers in preparing existing 3.x code for compatibility with 4.0 * Dependencies can managed via [recipe-plugin](https://github.com/silverstripe/recipe-plugin). See [recipe-core](https://github.com/silverstripe/recipe-core) and [recipe-cms](https://github.com/silverstripe/recipe-cms) as examples. * Authentication has been upgraded to a modular approach using re-usable interfaces and easier to hook in to LoginHandlers. * Core modules are installed in the `vendor/` folder by default (other modules can opt-in, see [guide](/developer_guides/extending/how_tos/publish_a_module)) +* Renamed constant for temp folder from `TEMP_FOLDER` to `TEMP_PATH` for naming consistency with other path variables and constants ## Upgrading diff --git a/src/Core/Startup/ParameterConfirmationToken.php b/src/Core/Startup/ParameterConfirmationToken.php index f13589a42..6162ebee1 100644 --- a/src/Core/Startup/ParameterConfirmationToken.php +++ b/src/Core/Startup/ParameterConfirmationToken.php @@ -57,7 +57,7 @@ class ParameterConfirmationToken protected function pathForToken($token) { - return TEMP_FOLDER.'/token_'.preg_replace('/[^a-z0-9]+/', '', $token); + return TEMP_PATH . DIRECTORY_SEPARATOR . 'token_'.preg_replace('/[^a-z0-9]+/', '', $token); } /** diff --git a/src/Dev/CsvBulkLoader.php b/src/Dev/CsvBulkLoader.php index f9a90b6ff..4d4fc6f0a 100644 --- a/src/Dev/CsvBulkLoader.php +++ b/src/Dev/CsvBulkLoader.php @@ -169,7 +169,7 @@ class CsvBulkLoader extends BulkLoader */ protected function getNewSplitFileName() { - return TEMP_FOLDER . DIRECTORY_SEPARATOR . uniqid(str_replace('\\', '_', static::class), true) . '.csv'; + return TEMP_PATH . DIRECTORY_SEPARATOR . uniqid(str_replace('\\', '_', static::class), true) . '.csv'; } /** diff --git a/src/ORM/DatabaseAdmin.php b/src/ORM/DatabaseAdmin.php index 0489099a7..945b787e8 100644 --- a/src/ORM/DatabaseAdmin.php +++ b/src/ORM/DatabaseAdmin.php @@ -196,8 +196,9 @@ class DatabaseAdmin extends Controller */ public static function lastBuilt() { - $file = TEMP_FOLDER - . '/database-last-generated-' + $file = TEMP_PATH + . DIRECTORY_SEPARATOR + . 'database-last-generated-' . str_replace(array('\\','/',':'), '.', Director::baseFolder()); if (file_exists($file)) { @@ -371,8 +372,9 @@ class DatabaseAdmin extends Controller } } - touch(TEMP_FOLDER - . '/database-last-generated-' + touch(TEMP_PATH + . DIRECTORY_SEPARATOR + . 'database-last-generated-' . str_replace(array('\\', '/', ':'), '.', Director::baseFolder())); if (isset($_REQUEST['from_installer'])) { diff --git a/src/View/SSViewer.php b/src/View/SSViewer.php index 5835a4bae..30a5664de 100644 --- a/src/View/SSViewer.php +++ b/src/View/SSViewer.php @@ -500,10 +500,10 @@ class SSViewer implements Flushable public static function flush_template_cache($force = false) { if (!self::$template_cache_flushed || $force) { - $dir = dir(TEMP_FOLDER); + $dir = dir(TEMP_PATH); while (false !== ($file = $dir->read())) { if (strstr($file, '.cache')) { - unlink(TEMP_FOLDER . '/' . $file); + unlink(TEMP_PATH . DIRECTORY_SEPARATOR . $file); } } self::$template_cache_flushed = true; @@ -626,7 +626,7 @@ class SSViewer implements Flushable $template = $this->chosen; - $cacheFile = TEMP_FOLDER . "/.cache" + $cacheFile = TEMP_PATH . DIRECTORY_SEPARATOR . '.cache' . str_replace(['\\','/',':'], '.', Director::makeRelative(realpath($template))); $lastEdited = filemtime($template); diff --git a/src/View/SSViewer_FromString.php b/src/View/SSViewer_FromString.php index 93fb57b86..e88433eef 100644 --- a/src/View/SSViewer_FromString.php +++ b/src/View/SSViewer_FromString.php @@ -50,7 +50,7 @@ class SSViewer_FromString extends SSViewer public function process($item, $arguments = null, $scope = null) { $hash = sha1($this->content); - $cacheFile = TEMP_FOLDER . "/.cache.$hash"; + $cacheFile = TEMP_PATH . DIRECTORY_SEPARATOR . ".cache.$hash"; if (!file_exists($cacheFile) || isset($_GET['flush'])) { $content = $this->parseTemplateContent($this->content, "string sha1=$hash"); diff --git a/src/i18n/Messages/Symfony/FlushInvalidatedResource.php b/src/i18n/Messages/Symfony/FlushInvalidatedResource.php index 7bf976570..0e01f45f1 100644 --- a/src/i18n/Messages/Symfony/FlushInvalidatedResource.php +++ b/src/i18n/Messages/Symfony/FlushInvalidatedResource.php @@ -63,7 +63,7 @@ class FlushInvalidatedResource implements SelfCheckingResourceInterface, \Serial */ protected static function canary() { - return TEMP_FOLDER . '/catalog.i18n_canary'; + return TEMP_PATH . DIRECTORY_SEPARATOR . 'catalog.i18n_canary'; } /** diff --git a/src/includes/constants.php b/src/includes/constants.php index 27fada010..e413532d1 100644 --- a/src/includes/constants.php +++ b/src/includes/constants.php @@ -15,7 +15,7 @@ use SilverStripe\Core\TempFolder; * - BASE_URL: Full URL to the webroot, e.g. "http://my-host.com/my-webroot" (no trailing slash). * - BASE_PATH: Absolute path to the webroot, e.g. "/var/www/my-webroot" (no trailing slash). * See Director::baseFolder(). Can be overwritten by Config::modify()->set(Director::class, 'alternate_base_folder', ). - * - TEMP_FOLDER: Absolute path to temporary folder, used for manifest and template caches. Example: "/var/tmp" + * - TEMP_PATH: Absolute path to temporary folder, used for manifest and template caches. Example: "/var/tmp" * See getTempFolder(). No trailing slash. * - ASSETS_DIR: Dir for assets folder. e.g. "assets" * - ASSETS_PATH: Full path to assets folder. e.g. "/var/www/my-webroot/assets" @@ -140,6 +140,15 @@ if (defined('CUSTOM_INCLUDE_PATH')) { } // Define the temporary folder if it wasn't defined yet -if (!defined('TEMP_FOLDER')) { - define('TEMP_FOLDER', TempFolder::getTempFolder(BASE_PATH)); +if (!defined('TEMP_PATH')) { + if (defined('TEMP_FOLDER')) { + define('TEMP_PATH', TEMP_FOLDER); + } else { + define('TEMP_PATH', TempFolder::getTempFolder(BASE_PATH)); + } +} + +// Define the temporary folder for backwards compatibility +if (!defined('TEMP_FOLDER')) { + define('TEMP_FOLDER', TEMP_PATH); } diff --git a/tests/php/Control/DirectorTest.php b/tests/php/Control/DirectorTest.php index 01144dc2f..01cc37d71 100644 --- a/tests/php/Control/DirectorTest.php +++ b/tests/php/Control/DirectorTest.php @@ -54,7 +54,7 @@ class DirectorTest extends SapphireTest public function testFileExists() { $tempFileName = 'DirectorTest_testFileExists.tmp'; - $tempFilePath = TEMP_FOLDER . '/' . $tempFileName; + $tempFilePath = TEMP_PATH . DIRECTORY_SEPARATOR . $tempFileName; // create temp file file_put_contents($tempFilePath, ''); diff --git a/tests/php/Core/Injector/InjectorTest.php b/tests/php/Core/Injector/InjectorTest.php index 9d7850357..10473d035 100644 --- a/tests/php/Core/Injector/InjectorTest.php +++ b/tests/php/Core/Injector/InjectorTest.php @@ -230,7 +230,7 @@ class InjectorTest extends SapphireTest 'properties' => array( 'filters' => array( '`BASE_PATH`', - '`TEMP_FOLDER`', + '`TEMP_PATH`', '`NOT_DEFINED`', 'THIRDPARTY_DIR' // Not back-tick escaped ) @@ -243,7 +243,7 @@ class InjectorTest extends SapphireTest $this->assertEquals( [ BASE_PATH, - TEMP_FOLDER, + TEMP_PATH, null, 'THIRDPARTY_DIR', ], diff --git a/tests/php/Core/Startup/ErrorControlChainTest/ErrorControlChainTest_Chain.php b/tests/php/Core/Startup/ErrorControlChainTest/ErrorControlChainTest_Chain.php index 685f58a5f..ab923c098 100644 --- a/tests/php/Core/Startup/ErrorControlChainTest/ErrorControlChainTest_Chain.php +++ b/tests/php/Core/Startup/ErrorControlChainTest/ErrorControlChainTest_Chain.php @@ -79,7 +79,7 @@ require_once '$classpath'; $src .= "->execute();"; // Now stick it in a temporary file & run it - $codepath = TEMP_FOLDER . '/ErrorControlChainTest_' . sha1($src) . '.php'; + $codepath = TEMP_PATH . DIRECTORY_SEPARATOR . 'ErrorControlChainTest_' . sha1($src) . '.php'; if ($includeStderr) { $null = '&1'; diff --git a/tests/php/View/SSViewerTest.php b/tests/php/View/SSViewerTest.php index 854093460..2260df02d 100644 --- a/tests/php/View/SSViewerTest.php +++ b/tests/php/View/SSViewerTest.php @@ -1689,7 +1689,7 @@ after' // as protocol-less absolute urls $base = Convert::raw2att('/file.com?foo"onclick="alert(\'xss\')""'); - $tmplFile = TEMP_FOLDER . '/SSViewerTest_testRewriteHashlinks_' . sha1(rand()) . '.ss'; + $tmplFile = TEMP_PATH . DIRECTORY_SEPARATOR . 'SSViewerTest_testRewriteHashlinks_' . sha1(rand()) . '.ss'; // Note: SSViewer_FromString doesn't rewrite hash links. file_put_contents( @@ -1746,7 +1746,7 @@ after' { SSViewer::setRewriteHashLinksDefault('php'); - $tmplFile = TEMP_FOLDER . '/SSViewerTest_testRewriteHashlinksInPhpMode_' . sha1(rand()) . '.ss'; + $tmplFile = TEMP_PATH . DIRECTORY_SEPARATOR . 'SSViewerTest_testRewriteHashlinksInPhpMode_' . sha1(rand()) . '.ss'; // Note: SSViewer_FromString doesn't rewrite hash links. file_put_contents( @@ -2060,7 +2060,7 @@ EOC; public function testFromStringCaching() { $content = 'Test content'; - $cacheFile = TEMP_FOLDER . '/.cache.' . sha1($content); + $cacheFile = TEMP_PATH . DIRECTORY_SEPARATOR . '.cache.' . sha1($content); if (file_exists($cacheFile)) { unlink($cacheFile); } diff --git a/tests/php/i18n/i18nTextCollectorTest.php b/tests/php/i18n/i18nTextCollectorTest.php index 6e0914a4a..57494dd04 100644 --- a/tests/php/i18n/i18nTextCollectorTest.php +++ b/tests/php/i18n/i18nTextCollectorTest.php @@ -25,7 +25,7 @@ class i18nTextCollectorTest extends SapphireTest parent::setUp(); $this->setupManifest(); - $this->alternateBaseSavePath = TEMP_FOLDER . DIRECTORY_SEPARATOR . 'i18nTextCollectorTest_webroot'; + $this->alternateBaseSavePath = TEMP_PATH . DIRECTORY_SEPARATOR . 'i18nTextCollectorTest_webroot'; Filesystem::makeFolder($this->alternateBaseSavePath); }