From 07fc2e431a56a21b693e02860918c4e7c666d60e Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 10 Apr 2023 22:34:37 -0400 Subject: [PATCH] Make enable_components a non-domain setting --- CRM/Core/DAO/Setting.php | 14 +++++++------- CRM/Upgrade/Incremental/php/FiveSixtyTwo.php | 1 + CRM/Upgrade/Incremental/sql/5.62.alpha1.mysql.tpl | 3 +++ Civi/Core/SettingsBag.php | 13 ++++++++----- settings/Core.setting.php | 2 +- tests/phpunit/Civi/Core/SettingsStyleTest.php | 2 +- xml/schema/Core/Setting.xml | 6 +++--- 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/CRM/Core/DAO/Setting.php b/CRM/Core/DAO/Setting.php index 0225a8ccc3..7ae6686241 100644 --- a/CRM/Core/DAO/Setting.php +++ b/CRM/Core/DAO/Setting.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/Setting.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:a7dacfe60f4c9deebde197ae1595db04) + * (GenCodeChecksum:2edd9c93748aeaf72a7717586b2c8e72) */ /** @@ -56,9 +56,9 @@ class CRM_Core_DAO_Setting extends CRM_Core_DAO { public $value; /** - * Which Domain is this menu item for + * Which Domain does this setting belong to * - * @var int|string + * @var int|string|null * (SQL type: int unsigned) * Note that values will be retrieved from the database as a string. */ @@ -74,7 +74,7 @@ class CRM_Core_DAO_Setting extends CRM_Core_DAO { public $contact_id; /** - * Is this setting a contact specific or site wide setting? + * Is this setting per-domain or global? * * @var bool|string * (SQL type: tinyint) @@ -221,8 +221,7 @@ class CRM_Core_DAO_Setting extends CRM_Core_DAO { 'name' => 'domain_id', 'type' => CRM_Utils_Type::T_INT, 'title' => ts('Domain ID'), - 'description' => ts('Which Domain is this menu item for'), - 'required' => TRUE, + 'description' => ts('Which Domain does this setting belong to'), 'usage' => [ 'import' => FALSE, 'export' => FALSE, @@ -230,6 +229,7 @@ class CRM_Core_DAO_Setting extends CRM_Core_DAO { 'token' => FALSE, ], 'where' => 'civicrm_setting.domain_id', + 'default' => NULL, 'table_name' => 'civicrm_setting', 'entity' => 'Setting', 'bao' => 'CRM_Core_BAO_Setting', @@ -271,7 +271,7 @@ class CRM_Core_DAO_Setting extends CRM_Core_DAO { 'name' => 'is_domain', 'type' => CRM_Utils_Type::T_BOOLEAN, 'title' => ts('Is Domain Setting?'), - 'description' => ts('Is this setting a contact specific or site wide setting?'), + 'description' => ts('Is this setting per-domain or global?'), 'required' => TRUE, 'usage' => [ 'import' => FALSE, diff --git a/CRM/Upgrade/Incremental/php/FiveSixtyTwo.php b/CRM/Upgrade/Incremental/php/FiveSixtyTwo.php index c914ec712e..d4f72372b2 100644 --- a/CRM/Upgrade/Incremental/php/FiveSixtyTwo.php +++ b/CRM/Upgrade/Incremental/php/FiveSixtyTwo.php @@ -28,6 +28,7 @@ class CRM_Upgrade_Incremental_php_FiveSixtyTwo extends CRM_Upgrade_Incremental_B * The version number matching this function name */ public function upgrade_5_62_alpha1($rev): void { + $this->addTask('Make civicrm_setting.domain_id optional', 'alterColumn', 'civicrm_setting', 'domain_id', "int unsigned DEFAULT NULL COMMENT 'Which Domain does this setting belong to'"); $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); } diff --git a/CRM/Upgrade/Incremental/sql/5.62.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.62.alpha1.mysql.tpl index c07509a60c..39fa40600c 100644 --- a/CRM/Upgrade/Incremental/sql/5.62.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.62.alpha1.mysql.tpl @@ -1 +1,4 @@ {* file to handle db changes in 5.62.alpha1 during upgrade *} + +UPDATE `civicrm_setting` SET `domain_id` = NULL WHERE `name` = 'enable_components' AND `domain_id` = {$domainID}; +DELETE FROM `civicrm_setting` WHERE `name` = 'enable_components' AND `domain_id` IS NOT NULL; diff --git a/Civi/Core/SettingsBag.php b/Civi/Core/SettingsBag.php index be51cc6ae4..f1037848f4 100644 --- a/Civi/Core/SettingsBag.php +++ b/Civi/Core/SettingsBag.php @@ -324,11 +324,11 @@ class SettingsBag { protected function createQuery() { $select = \CRM_Utils_SQL_Select::from('civicrm_setting') ->select('id, name, value, domain_id, contact_id, is_domain, component_id, created_date, created_id') - ->where('domain_id = #id', [ + ->where('(domain_id IS NULL OR domain_id = #id)', [ 'id' => $this->domainId, ]); if ($this->contactId === NULL) { - $select->where('is_domain = 1'); + $select->where('contact_id IS NULL'); } else { $select->where('contact_id = #id', [ @@ -380,13 +380,16 @@ class SettingsBag { $dao = new \CRM_Core_DAO_Setting(); $dao->name = $name; - $dao->domain_id = $this->domainId; + $dao->is_domain = 0; + // Contact-specific settings if ($this->contactId) { $dao->contact_id = $this->contactId; - $dao->is_domain = 0; + $dao->domain_id = $this->domainId; } - else { + // Domain-specific settings. For legacy support this is assumed to be TRUE if not set + elseif ($metadata['is_domain'] ?? TRUE) { $dao->is_domain = 1; + $dao->domain_id = $this->domainId; } $dao->find(TRUE); diff --git a/settings/Core.setting.php b/settings/Core.setting.php index 69f2fedff9..42d90b7c7c 100644 --- a/settings/Core.setting.php +++ b/settings/Core.setting.php @@ -792,7 +792,7 @@ return [ 'default' => NULL, 'add' => '4.4', 'title' => ts('Enable Components'), - 'is_domain' => '1', + 'is_domain' => 0, 'is_contact' => 0, 'description' => NULL, 'help_text' => NULL, diff --git a/tests/phpunit/Civi/Core/SettingsStyleTest.php b/tests/phpunit/Civi/Core/SettingsStyleTest.php index 0098c5a8d9..2c674abd38 100644 --- a/tests/phpunit/Civi/Core/SettingsStyleTest.php +++ b/tests/phpunit/Civi/Core/SettingsStyleTest.php @@ -30,7 +30,7 @@ class SettingsStyleTest extends \CiviUnitTestCase { $this->assertTrue(count($all) > 10); foreach ($all as $key => $spec) { $assert($key, preg_match(';^\d+\.\d+(\.\d+)?$;', $spec['add'] ?? NULL), 'Should have well-formed \"add\" property'); - $assert($key, $spec['is_domain'] xor $spec['is_contact'], 'Should be is_domain xor is_contact'); + $assert($key, !($spec['is_domain'] && $spec['is_contact']), 'Cannot be both is_domain and is_contact'); $assert($key, $key === $spec['name'], 'Should have matching name'); $type = $spec['type'] ?? 'UNKNOWN'; $assert($key, in_array($type, $validTypes), 'Should have known type. Found: ' . $type); diff --git a/xml/schema/Core/Setting.xml b/xml/schema/Core/Setting.xml index 203977af5d..08b83f4051 100644 --- a/xml/schema/Core/Setting.xml +++ b/xml/schema/Core/Setting.xml @@ -59,13 +59,13 @@ domain_id Domain ID int unsigned - true + NULL civicrm_domain
id name
- Which Domain is this menu item for + Which Domain does this setting belong to @@ -101,7 +101,7 @@ boolean 0 true - Is this setting a contact specific or site wide setting? + Is this setting per-domain or global? 4.1 -- 2.25.1