Fix support for setting TEMP_PATH in .env (fixes #8099) (#10138)

This commit is contained in:
Loz Calver 2021-11-15 20:35:28 +00:00 committed by GitHub
parent 2c1d8e232b
commit 29fa365d10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 8 deletions

View File

@ -122,6 +122,4 @@ Silverstripe core environment variables are listed here, though you're free to d
| `SS_DATABASE_SSL_CA` | Absolute path to SSL Certificate Authority bundle file |
| `SS_DATABASE_SSL_CIPHER` | Optional setting for custom SSL cipher |
| `SS_FLUSH_ON_DEPLOY` | Try to detect deployments through file system modifications and flush on the first request after every deploy. Does not run "dev/build", but only "flush". Possible values are `true` (check for a framework PHP file modification time), `false` (no checks, skip deploy detection) or a path to a specific file or folder to be checked. See [DeployFlushDiscoverer](api:SilverStripe\Core\Startup\DeployFlushDiscoverer) for more details.<br /><br />False by default. |
Note: A few additional PHP constants can be configured through a custom `index.php` rather than environment variables - see [constants.php](https://github.com/silverstripe/silverstripe-framework/blob/4/src/includes/constants.php) for details.
Most notably, `TEMP_PATH` can be set as file storage used for the default cache adapters in [Manifests](/developer_guides/execution_pipeline/manifests), [Object Caching](/developer_guides/performance/caching) and [Partial Template Caching](/developer_guides/templates/partial_template_caching). It defaults to PHP's built-in `sys_get_temp_dir()`.
| `SS_TEMP_PATH` | File storage used for the default cache adapters in [Manifests](/developer_guides/execution_pipeline/manifests), [Object Caching](/developer_guides/performance/caching) and [Partial Template Caching](/developer_guides/templates/partial_template_caching). It defaults to creating a sub-directory of PHP's built-in `sys_get_temp_dir()`. Can be an absolute path (with a leading `/`), or a path relative to the project root. |

View File

@ -10,7 +10,7 @@
## Regression test and Security audit{#audit}
This release has been comprehensively regression tested and passed to a third party for a security-focused audit.
This release has been comprehensively regression tested and passed to a third party for a security-focused audit.
While it is still advised that you perform your own due diligence when upgrading your project, this work is performed to ensure a safe and secure upgrade with each recipe release.
@ -24,6 +24,17 @@ We've recently updated our [PHP support policy](/Getting_Started/Server_Requirem
## Features and enhancements {#features-and-enhancements}
### New `SS_TEMP_PATH` environment variable
This release adds support for a new `SS_TEMP_PATH` environment variable, which allows developers to control where a series of “temporary” files are created. These include [Manifests](/developer_guides/execution_pipeline/manifests), [Object Caching](/developer_guides/performance/caching) and [Partial Template Caching](/developer_guides/templates/partial_template_caching).
The environment variable can be set to either an absolute path which must have a leading `/` (e.g. `SS_TEMP_PATH='/tmp/silverstripe/cachedir'`), or a path relative to the project root (e.g. `SS_TEMP_PATH='silverstripe-cache'`). See the [environment management](/getting_started/environment_management) section for more information.
**Please note:** setting this environment variable will impact both requests served by a webserver (i.e. a typical website pageview) and command-line execution. If your webserver user and command-line user are different, or have different filesystem permissions, you may encounter problems when using this setting.
The new `SS_TEMP_PATH` environment variable replaces the similarly-named `TEMP_PATH` environment variable, which only ever offered partial support for adjusting the temporary files' location. This is because setting a `TEMP_PATH` _environment variable_ would affect [Injector](/developer_guides/extending/injector) service definitions, but would **not** affect code that referenced the `TEMP_PATH` _PHP constant_. The confusion with both environment variables and PHP constants having the same name is why the environment variable has been renamed and prefixed with `SS_`, in-keeping with other environment variables.
The functionality of the `TEMP_PATH` and `TEMP_FOLDER` PHP constants remains unchanged.
## Bugfixes {#bugfixes}

View File

@ -497,7 +497,7 @@ class CoreKernel implements Kernel
{
return new ManifestCacheFactory([
'namespace' => 'manifestcache',
'directory' => TempFolder::getTempFolder($this->basePath),
'directory' => TEMP_PATH,
]);
}

View File

@ -15,9 +15,9 @@ 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_PATH: Absolute path to temporary folder, used as base for $TEMP_FOLDER. Example: "/var/tmp"
* - TEMP_FOLDER: folder name for manifest and template caches. Example: "silverstripe-cache-php7.2"
* See getTempFolder(). No trailing slash.
* - TEMP_PATH: Path to temporary folder for manifest and template caches. May be relative to project root or an
* absolute path. No trailing slash. Can be set with the SS_TEMP_PATH environment variable.
* - TEMP_FOLDER: DEPRECATED. Same as TEMP_PATH.
* - ASSETS_DIR: Dir for assets folder. e.g. "assets"
* - ASSETS_PATH: Full path to assets folder. e.g. "/var/www/my-webroot/assets"
* - THEMES_DIR: Path relative to webroot, e.g. "themes"
@ -199,6 +199,13 @@ if (defined('CUSTOM_INCLUDE_PATH')) {
if (!defined('TEMP_PATH')) {
if (defined('TEMP_FOLDER')) {
define('TEMP_PATH', TEMP_FOLDER);
} elseif ($path = Environment::getEnv('SS_TEMP_PATH')) {
// If path is relative, rewrite it to be relative to BASE_PATH - as web requests are relative to
// public/index.php, and we don't want the TEMP_PATH to be inside the public/ directory by default
if (ltrim($path, DIRECTORY_SEPARATOR) === $path) {
$path = BASE_PATH . DIRECTORY_SEPARATOR . $path;
}
define('TEMP_PATH', $path);
} else {
define('TEMP_PATH', TempFolder::getTempFolder(BASE_PATH));
}