From a173d5fb0a617bc3da1988d10b29e9b76f147e6a Mon Sep 17 00:00:00 2001 From: colemanw Date: Wed, 19 Jul 2023 11:49:46 -0400 Subject: [PATCH] LocationType - Fix generated sql with correct defaults and untranslated names --- CRM/Upgrade/Incremental/php/FiveSixtyFive.php | 7 ++++++- CRM/Upgrade/Incremental/sql/5.65.alpha1.mysql.tpl | 10 +++------- .../civicrm_location_type.sqldata.php | 15 +++++---------- sql/civicrm_generated.mysql | 8 ++++---- tests/phpunit/CiviTest/CiviUnitTestCase.php | 7 ++----- 5 files changed, 20 insertions(+), 27 deletions(-) diff --git a/CRM/Upgrade/Incremental/php/FiveSixtyFive.php b/CRM/Upgrade/Incremental/php/FiveSixtyFive.php index b2449b592b..ea19711797 100644 --- a/CRM/Upgrade/Incremental/php/FiveSixtyFive.php +++ b/CRM/Upgrade/Incremental/php/FiveSixtyFive.php @@ -29,7 +29,12 @@ class CRM_Upgrade_Incremental_php_FiveSixtyFive extends CRM_Upgrade_Incremental_ */ public function upgrade_5_65_alpha1($rev): void { $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); - // These 3 should run after the sql file. + // These should run after the sql file. + $this->addTask('Make LocationType.name required', 'alterColumn', 'civicrm_location_type', 'name', "varchar(64) NOT NULL COMMENT 'Location Type Name.'"); + $this->addTask('Make LocationType.display_name required', 'alterColumn', 'civicrm_location_type', 'display_name', "varchar(64) NOT NULL COMMENT 'Location Type Display Name.'", TRUE); + $this->addTask('Make LocationType.is_reserved required', 'alterColumn', 'civicrm_location_type', 'is_reserved', "tinyint NOT NULL DEFAULT 0 COMMENT 'Is this location type a predefined system location?'"); + $this->addTask('Make LocationType.is_active required', 'alterColumn', 'civicrm_location_type', 'is_active', "tinyint NOT NULL DEFAULT 1 COMMENT 'Is this property active?'"); + $this->addTask('Make LocationType.is_default required', 'alterColumn', 'civicrm_location_type', 'is_default', "tinyint NOT NULL DEFAULT 0 COMMENT 'Is this location type the default?'"); $this->addTask('Make Group.name required', 'alterColumn', 'civicrm_group', 'name', "varchar(255) NOT NULL COMMENT 'Internal name of Group.'"); $this->addTask('Make Group.title required', 'alterColumn', 'civicrm_group', 'title', "varchar(255) NOT NULL COMMENT 'Alternative public title for this Group.'", TRUE); $this->addTask('Make Group.frontend_title required', 'alterColumn', 'civicrm_group', 'frontend_title', "varchar(255) NOT NULL COMMENT 'Alternative public description of the group.'", TRUE); diff --git a/CRM/Upgrade/Incremental/sql/5.65.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.65.alpha1.mysql.tpl index 26860fb91d..a8704d21a1 100644 --- a/CRM/Upgrade/Incremental/sql/5.65.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.65.alpha1.mysql.tpl @@ -32,12 +32,8 @@ subject = REPLACE(subject, '{welcome.group}', '{group.frontend_title}') WHERE component_type = 'Welcome'; {/literal} +UPDATE `civicrm_location_type` SET `is_reserved` = 0 WHERE `is_reserved` IS NULL; UPDATE `civicrm_location_type` SET `is_active` = 0 WHERE `is_active` IS NULL; +UPDATE `civicrm_location_type` SET `is_default` = 0 WHERE `is_default` IS NULL; UPDATE `civicrm_location_type` SET `name` = CONCAT('location_', id) WHERE `name` IS NULL; -UPDATE `civicrm_location_type` SET `display_name` = `name` WHERE `display_name` IS NULL; -ALTER TABLE `civicrm_location_type` - MODIFY COLUMN `name` varchar(64) NOT NULL COMMENT 'Location Type Name.', - MODIFY COLUMN `display_name` varchar(64) NOT NULL COMMENT 'Location Type Display Name.', - MODIFY COLUMN `is_reserved` tinyint NOT NULL DEFAULT 0 COMMENT 'Is this location type a predefined system location?', - MODIFY COLUMN `is_active` tinyint NOT NULL DEFAULT 1 COMMENT 'Is this property active?', - MODIFY COLUMN `is_default` tinyint NOT NULL DEFAULT 0 COMMENT 'Is this location type the default?'; +UPDATE `civicrm_location_type` SET {localize field=display_name}`display_name` = COALESCE(`display_name`, `name`){/localize}; diff --git a/sql/civicrm_data/civicrm_location_type.sqldata.php b/sql/civicrm_data/civicrm_location_type.sqldata.php index 0d611080f0..8c455483b7 100644 --- a/sql/civicrm_data/civicrm_location_type.sqldata.php +++ b/sql/civicrm_data/civicrm_location_type.sqldata.php @@ -2,35 +2,31 @@ return CRM_Core_CodeGen_SqlData::create('civicrm_location_type') ->addValues([ - // CRM-9120 for legacy reasons we are continuing to translate the 'name', but this - // field is used mainly as an ID, and display_name will be shown to the user, but - // we have not yet finished modifying all places where the 'name' is shown. [ - 'name' => ts('Home'), + 'name' => 'Home', 'display_name' => ts('Home'), 'vcard_name' => 'HOME', 'description' => ts('Place of residence'), 'is_default' => 1, ], [ - 'name' => ts('Work'), + 'name' => 'Work', 'display_name' => ts('Work'), 'vcard_name' => 'WORK', 'description' => ts('Work location'), ], [ - 'name' => ts('Main'), + 'name' => 'Main', 'display_name' => ts('Main'), 'vcard_name' => NULL, 'description' => ts('Main office location'), ], [ - 'name' => ts('Other'), + 'name' => 'Other', 'display_name' => ts('Other'), 'vcard_name' => NULL, 'description' => ts('Other location'), ], - // -- the following location must stay with the untranslated Billing name, CRM-2064 [ 'name' => 'Billing', 'display_name' => ts('Billing'), @@ -41,7 +37,6 @@ return CRM_Core_CodeGen_SqlData::create('civicrm_location_type') ]) ->addDefaults([ 'is_active' => 1, - 'is_default' => NULL, + 'is_default' => 0, 'is_reserved' => 0, - // FIXME: Doesn't 0 make more sense than NULL? ]); diff --git a/sql/civicrm_generated.mysql b/sql/civicrm_generated.mysql index 9448bab696..cea2e0af98 100644 --- a/sql/civicrm_generated.mysql +++ b/sql/civicrm_generated.mysql @@ -4274,10 +4274,10 @@ LOCK TABLES `civicrm_location_type` WRITE; /*!40000 ALTER TABLE `civicrm_location_type` DISABLE KEYS */; INSERT INTO `civicrm_location_type` (`id`, `name`, `display_name`, `vcard_name`, `description`, `is_reserved`, `is_active`, `is_default`) VALUES (1,'Home','Home','HOME','Place of residence',0,1,1), - (2,'Work','Work','WORK','Work location',0,1,NULL), - (3,'Main','Main',NULL,'Main office location',0,1,NULL), - (4,'Other','Other',NULL,'Other location',0,1,NULL), - (5,'Billing','Billing',NULL,'Billing Address location',1,1,NULL); + (2,'Work','Work','WORK','Work location',0,1,0), + (3,'Main','Main',NULL,'Main office location',0,1,0), + (4,'Other','Other',NULL,'Other location',0,1,0), + (5,'Billing','Billing',NULL,'Billing Address location',1,1,0); /*!40000 ALTER TABLE `civicrm_location_type` ENABLE KEYS */; UNLOCK TABLES; diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 2240371b0d..66197d36aa 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -1117,16 +1117,13 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { public function locationTypeCreate(array $params = []): int { $params = array_merge([ 'name' => 'New Location Type', + 'display_name' => 'New Location Type', 'vcard_name' => 'New Location Type', 'description' => 'Location Type for Delete', 'is_active' => 1, ], $params); - $locationType = new CRM_Core_DAO_LocationType(); - $locationType->copyValues($params); - $locationType->save(); - // clear getfields cache - CRM_Core_PseudoConstant::flush(); + $locationType = CRM_Core_BAO_LocationType::writeRecord($params); $this->callAPISuccess('Phone', 'getfields', ['version' => 3, 'cache_clear' => 1]); return $locationType->id; } -- 2.25.1