From 91ceb1d4b88c099314bb77ac442a6ed81ca12a1e Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 23 Jun 2023 16:31:02 -0700 Subject: [PATCH] Add deployID to civicrm.settings.php --- CRM/Utils/Cache/Redis.php | 3 +++ setup/plugins/installFiles/GenerateCredKey.civi-setup.php | 4 ++++ .../plugins/installFiles/InstallSettingsFile.civi-setup.php | 3 ++- setup/src/Setup/Model.php | 2 ++ templates/CRM/common/civicrm.settings.php.template | 6 ++++++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CRM/Utils/Cache/Redis.php b/CRM/Utils/Cache/Redis.php index 87c7361139..4461eebbf7 100644 --- a/CRM/Utils/Cache/Redis.php +++ b/CRM/Utils/Cache/Redis.php @@ -95,6 +95,9 @@ class CRM_Utils_Cache_Redis implements CRM_Utils_Cache_Interface { if (isset($config['prefix'])) { $this->_prefix = $config['prefix']; } + if (defined('CIVICRM_DEPLOY_ID')) { + $this->_prefix = CIVICRM_DEPLOY_ID . '_' . $this->_prefix; + } $this->_cache = self::connect($config); } diff --git a/setup/plugins/installFiles/GenerateCredKey.civi-setup.php b/setup/plugins/installFiles/GenerateCredKey.civi-setup.php index 33676d5055..003843a655 100644 --- a/setup/plugins/installFiles/GenerateCredKey.civi-setup.php +++ b/setup/plugins/installFiles/GenerateCredKey.civi-setup.php @@ -25,6 +25,10 @@ if (!defined('CIVI_SETUP')) { $e->getModel()->credKeys = [$e->getModel()->credKeys]; } + if (empty($e->getModel()->deployID)) { + $e->getModel()->deployID = $toAlphanum(random_bytes(10)); + } + \Civi\Setup::log()->info(sprintf('[%s] Done %s', basename(__FILE__), 'installFiles')); }, \Civi\Setup::PRIORITY_PREPARE); diff --git a/setup/plugins/installFiles/InstallSettingsFile.civi-setup.php b/setup/plugins/installFiles/InstallSettingsFile.civi-setup.php index 8140f5d48d..5902ade15c 100644 --- a/setup/plugins/installFiles/InstallSettingsFile.civi-setup.php +++ b/setup/plugins/installFiles/InstallSettingsFile.civi-setup.php @@ -100,8 +100,9 @@ if (!defined('CIVI_SETUP')) { $params['siteKey'] = addslashes($m->siteKey); $params['credKeys'] = addslashes(implode(' ', $m->credKeys)); $params['signKeys'] = addslashes(implode(' ', $m->signKeys)); + $params['deployID'] = addslashes($m->deployID); - $extraSettings = array(); + $extraSettings = []; foreach ($m->paths as $key => $aspects) { foreach ($aspects as $aspect => $value) { diff --git a/setup/src/Setup/Model.php b/setup/src/Setup/Model.php index 3b740edc18..a8e00e1147 100644 --- a/setup/src/Setup/Model.php +++ b/setup/src/Setup/Model.php @@ -32,6 +32,8 @@ namespace Civi\Setup; * Ex: ['::abcd1234ABCD9876']. * @property string[] $signKeys * Ex: ['jwt-hs256::abcd1234ABCD9876']. + * @property string $deployID + * Ex: '1234ABCD9876'. * @property string|NULL $lang * The language of the default dataset. * Ex: 'fr_FR'. diff --git a/templates/CRM/common/civicrm.settings.php.template b/templates/CRM/common/civicrm.settings.php.template index ffb2bc2dd5..baf563771b 100644 --- a/templates/CRM/common/civicrm.settings.php.template +++ b/templates/CRM/common/civicrm.settings.php.template @@ -335,6 +335,12 @@ if (!defined('CIVICRM_CRED_KEYS') ) { // Some old installers may not set a decent value, and this extra complexity is a failsafe. // Feel free to simplify post-install. } +if (!defined('CIVICRM_DEPLOY_ID') ) { + define( '_CIVICRM_DEPLOY_ID', '%%deployID%%'); + define( 'CIVICRM_DEPLOY_ID', _CIVICRM_DEPLOY_ID === '%%' . 'deployID' . '%%' ? '' : _CIVICRM_DEPLOY_ID ); + // Some old installers may not set a decent value, and this extra complexity is a failsafe. + // Feel free to simplify post-install. +} /** * The signing key is used to generate and verify shareable tokens. -- 2.25.1