From 0bd3f65c109ae435fb3b43de5eaa4086e862cf05 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 2 Jul 2019 18:08:20 -0700 Subject: [PATCH] (dev/cloud-native#3) configAndLogDir,templateCompileDir - Move from "Runtime" to "Paths". Use hierarchy. This slightly changes the computation of the private log and compilation directories so that: * The definition appears more declarative. * The default is computed on-demand (i.e. later in the process). * The values can be overriden more intuitively. Before ------ The properties `$config->configAndLogDir` and `$config->templateCompileDir` are computed as part of a procedural initialization step in `CRM_Core_Config_Runtime`. After ----- The properties `$config->configAndLogDir` and `$config->templateCompileDir` are computed on-demand by `Civi\Core\Paths`. The values of these properties may: * Be computed automatically in a way that matches the previous output (i.e. `configAndLogDir`=~`CIVICRM_TEMPLATE_COMPILEDIR/../configAndLog`; `templateCompileDir`=~`CIVICRM_TEMPLATE_COMPILEDIR`). * Be customized as a pair (by setting `civicrm.private`) * Be customized individually (by setting `civicrm.logs` or `civicrm.compile`). --- CRM/Core/Config/MagicMerge.php | 8 ++++++-- CRM/Core/Config/Runtime.php | 21 --------------------- Civi/Core/Paths.php | 21 ++++++++++++++++++++- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/CRM/Core/Config/MagicMerge.php b/CRM/Core/Config/MagicMerge.php index 2bc5a8f32e..30188ce3bf 100644 --- a/CRM/Core/Config/MagicMerge.php +++ b/CRM/Core/Config/MagicMerge.php @@ -106,8 +106,6 @@ class CRM_Core_Config_MagicMerge { 'userFrameworkURLVar' => ['runtime'], 'userHookClass' => ['runtime'], 'cleanURL' => ['runtime'], - 'configAndLogDir' => ['runtime'], - 'templateCompileDir' => ['runtime'], 'templateDir' => ['runtime'], // "boot-svc" properties are critical services needed during init. @@ -190,6 +188,12 @@ class CRM_Core_Config_MagicMerge { 'wpBasePage' => ['setting'], 'wpLoadPhp' => ['setting'], + // "path" properties are managed via Civi::paths and $civicrm_paths + // Option: `mkdir` - auto-create dir + // Option: `restrict` - auto-restrict remote access + 'configAndLogDir' => ['path', 'civicrm.log', ['mkdir', 'restrict']], + 'templateCompileDir' => ['path', 'civicrm.compile', ['mkdir', 'restrict']], + // "setting-path" properties are settings with special filtering // to return normalized file paths. // Option: `mkdir` - auto-create dir diff --git a/CRM/Core/Config/Runtime.php b/CRM/Core/Config/Runtime.php index 886777e40e..5483822a1a 100644 --- a/CRM/Core/Config/Runtime.php +++ b/CRM/Core/Config/Runtime.php @@ -73,13 +73,6 @@ class CRM_Core_Config_Runtime extends CRM_Core_Config_MagicMerge { */ public $cleanURL; - /** - * @var string - */ - public $configAndLogDir; - - public $templateCompileDir; - /** * The root directory of our template tree. * @var string @@ -99,20 +92,6 @@ class CRM_Core_Config_Runtime extends CRM_Core_Config_MagicMerge { $this->fatal('You need to define CIVICRM_TEMPLATE_COMPILEDIR in civicrm.settings.php'); } - if (defined('CIVICRM_TEMPLATE_COMPILEDIR')) { - $this->configAndLogDir = CRM_Utils_File::baseFilePath() . 'ConfigAndLog' . DIRECTORY_SEPARATOR; - $this->templateCompileDir = defined('CIVICRM_TEMPLATE_COMPILEDIR') ? CRM_Utils_File::addTrailingSlash(CIVICRM_TEMPLATE_COMPILEDIR) : NULL; - CRM_Utils_File::createDir($this->templateCompileDir); - CRM_Utils_File::restrictAccess($this->templateCompileDir); - } - - $civicrm_private = $GLOBALS['civicrm_paths']['civicrm.private']['path']; - if (!empty($civicrm_private)) { - $this->configAndLogDir = rtrim($civicrm_private, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'ConfigAndLog' . DIRECTORY_SEPARATOR; - } - CRM_Utils_File::createDir($this->configAndLogDir); - CRM_Utils_File::restrictAccess($this->configAndLogDir); - if (!defined('CIVICRM_UF')) { $this->fatal('You need to define CIVICRM_UF in civicrm.settings.php'); } diff --git a/Civi/Core/Paths.php b/Civi/Core/Paths.php index 8271f7ba4c..29bd7393d0 100644 --- a/Civi/Core/Paths.php +++ b/Civi/Core/Paths.php @@ -57,7 +57,26 @@ class Paths { return \CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage(); }) ->register('civicrm.private', function () { - return \CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage(); + return [ + // For backward compatibility with existing deployments, this + // effectively returns `dirname(CIVICRM_TEMPLATE_COMPILEDIR)`. + // That's confusing. Future installers should probably set `civicrm.private` + // explicitly instead of setting `CIVICRM_TEMPLATE_COMPILEDIR`. + 'path' => \CRM_Utils_File::baseFilePath(), + ]; + }) + ->register('civicrm.log', function () { + return [ + 'path' => \Civi::paths()->getPath('[civicrm.private]/ConfigAndLog'), + ]; + }) + ->register('civicrm.compile', function () { + return [ + // These two formulations are equivalent in typical deployments; however, + // for existing systems which previously customized CIVICRM_TEMPLATE_COMPILEDIR, + // using the constant should be more backward-compatibility. + 'path' => defined('CIVICRM_TEMPLATE_COMPILEDIR') ? CIVICRM_TEMPLATE_COMPILEDIR : \Civi::paths()->getPath('[civicrm.private]/templates_c'), + ]; }) ->register('wp.frontend.base', function () { return ['url' => rtrim(CIVICRM_UF_BASEURL, '/') . '/']; -- 2.25.1