Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move log and compilation dirs from "Runtime" to "Paths" #14718

Merged
merged 9 commits into from
Jul 24, 2019
17 changes: 13 additions & 4 deletions CRM/Core/Config/MagicMerge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])) {
Expand Down Expand Up @@ -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':
Expand Down
21 changes: 0 additions & 21 deletions CRM/Core/Config/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/IDS.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
4 changes: 2 additions & 2 deletions CRM/Extension/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 2 additions & 3 deletions Civi/Core/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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();
Expand Down
22 changes: 22 additions & 0 deletions Civi/Core/Paths.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/') . '/'];
})
Expand Down