diff --git a/CRM/Core/Config/MagicMerge.php b/CRM/Core/Config/MagicMerge.php index 801f803f3b4e..30188ce3bfc8 100644 --- a/CRM/Core/Config/MagicMerge.php +++ b/CRM/Core/Config/MagicMerge.php @@ -106,8 +106,6 @@ public static function getPropertyMap() { '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 @@ public static function getPropertyMap() { '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 @@ -241,10 +245,14 @@ public function __get($k) { case 'setting': return $this->getSettings()->get($name); + // The interpretation of 'path' and 'setting-path' is similar, except + // that the latter originates in a stored setting. + case 'path': case 'setting-path': // Array(0 => $type, 1 => $setting, 2 => $actions). - $value = $this->getSettings()->get($name); - $value = Civi::paths()->getPath($value); + $value = ($type === 'path') + ? Civi::paths()->getVariable($name, 'path') + : Civi::paths()->getPath($this->getSettings()->get($name)); if ($value) { $value = CRM_Utils_File::addTrailingSlash($value); if (isset($this->map[$k][2]) && in_array('mkdir', $this->map[$k][2])) { @@ -322,6 +330,7 @@ public function __set($k, $v) { case 'setting': case 'setting-path': case 'setting-url': + case 'path': case 'user-system': case 'runtime': case 'callback': diff --git a/CRM/Core/Config/Runtime.php b/CRM/Core/Config/Runtime.php index d1aef183d9b7..d64c5ce5f943 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 @@ -95,20 +88,6 @@ public function initialize($loadFromDB = TRUE) { } $this->dsn = defined('CIVICRM_DSN') ? CIVICRM_DSN : NULL; - if (!defined('CIVICRM_TEMPLATE_COMPILEDIR') && $loadFromDB) { - $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; - CRM_Utils_File::createDir($this->configAndLogDir); - CRM_Utils_File::restrictAccess($this->configAndLogDir); - - $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); - } - if (!defined('CIVICRM_UF')) { $this->fatal('You need to define CIVICRM_UF in civicrm.settings.php'); } diff --git a/CRM/Core/IDS.php b/CRM/Core/IDS.php index 4d0d513e2c01..3af51e5833c7 100644 --- a/CRM/Core/IDS.php +++ b/CRM/Core/IDS.php @@ -118,7 +118,7 @@ protected static function create($config) { */ public static function createBaseConfig() { $config = \CRM_Core_Config::singleton(); - $tmpDir = empty($config->uploadDir) ? CIVICRM_TEMPLATE_COMPILEDIR : $config->uploadDir; + $tmpDir = empty($config->uploadDir) ? Civi::paths()->getVariable('civicrm.compile', 'path') : $config->uploadDir; global $civicrm_root; return [ diff --git a/CRM/Extension/ClassLoader.php b/CRM/Extension/ClassLoader.php index bba8731510ec..4569f6c2e4ee 100644 --- a/CRM/Extension/ClassLoader.php +++ b/CRM/Extension/ClassLoader.php @@ -77,7 +77,7 @@ public function __destruct() { */ public function register() { // In pre-installation environments, don't bother with caching. - if (!defined('CIVICRM_TEMPLATE_COMPILEDIR') || !defined('CIVICRM_DSN') || defined('CIVICRM_TEST') || \CRM_Utils_System::isInUpgradeMode()) { + if (!defined('CIVICRM_DSN') || defined('CIVICRM_TEST') || \CRM_Utils_System::isInUpgradeMode()) { return $this->buildClassLoader()->register(); } @@ -146,7 +146,7 @@ public function refresh() { */ protected function getCacheFile() { $envId = \CRM_Core_Config_Runtime::getId(); - $file = CIVICRM_TEMPLATE_COMPILEDIR . "/CachedExtLoader.{$envId}.php"; + $file = \Civi::paths()->getPath("[civicrm.compile]/CachedExtLoader.{$envId}.php"); return $file; } diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index 55c2b92e2b31..9c78f0b3126c 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -46,7 +46,6 @@ public static function singleton($reset = FALSE) { * - CIVICRM_CONTAINER_CACHE -- 'always' [default], 'never', 'auto' * - CIVICRM_DSN * - CIVICRM_DOMAIN_ID - * - CIVICRM_TEMPLATE_COMPILEDIR * * @return \Symfony\Component\DependencyInjection\ContainerInterface */ @@ -58,14 +57,14 @@ public function loadContainer() { $cacheMode = defined('CIVICRM_CONTAINER_CACHE') ? CIVICRM_CONTAINER_CACHE : 'auto'; // In pre-installation environments, don't bother with caching. - if (!defined('CIVICRM_TEMPLATE_COMPILEDIR') || !defined('CIVICRM_DSN') || $cacheMode === 'never' || \CRM_Utils_System::isInUpgradeMode()) { + if (!defined('CIVICRM_DSN') || $cacheMode === 'never' || \CRM_Utils_System::isInUpgradeMode()) { $containerBuilder = $this->createContainer(); $containerBuilder->compile(); return $containerBuilder; } $envId = \CRM_Core_Config_Runtime::getId(); - $file = CIVICRM_TEMPLATE_COMPILEDIR . "/CachedCiviContainer.{$envId}.php"; + $file = \Civi::paths()->getPath("[civicrm.compile]/CachedCiviContainer.{$envId}.php"); $containerConfigCache = new ConfigCache($file, $cacheMode === 'auto'); if (!$containerConfigCache->isFresh()) { $containerBuilder = $this->createContainer(); diff --git a/Civi/Core/Paths.php b/Civi/Core/Paths.php index 31c926601317..29bd7393d04d 100644 --- a/Civi/Core/Paths.php +++ b/Civi/Core/Paths.php @@ -56,6 +56,28 @@ public function __construct() { ->register('civicrm.files', function () { return \CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage(); }) + ->register('civicrm.private', function () { + 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, '/') . '/']; })