From c87e11eb935f4e6f340ca9e161835ad732693b68 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 24 Aug 2021 07:46:54 +1200 Subject: [PATCH] dev/core#2682 Entity batch declare option group for pseudoconstant --- CRM/Batch/DAO/EntityBatch.php | 6 ++- CRM/Upgrade/Incremental/Base.php | 20 +++++++++ CRM/Upgrade/Incremental/php/FiveFortyTwo.php | 44 +++++++++++++------- xml/schema/Batch/EntityBatch.xml | 3 ++ xml/templates/civicrm_data.tpl | 11 ++++- 5 files changed, 65 insertions(+), 19 deletions(-) diff --git a/CRM/Batch/DAO/EntityBatch.php b/CRM/Batch/DAO/EntityBatch.php index c3108dae19..3a14e16132 100644 --- a/CRM/Batch/DAO/EntityBatch.php +++ b/CRM/Batch/DAO/EntityBatch.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Batch/EntityBatch.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:9a6509e0c6f8869d4cdaeebd7e0073a3) + * (GenCodeChecksum:916ca7535e5e9d344f17456a973fdad6) */ /** @@ -129,6 +129,10 @@ class CRM_Batch_DAO_EntityBatch extends CRM_Core_DAO { 'entity' => 'EntityBatch', 'bao' => 'CRM_Batch_BAO_EntityBatch', 'localizable' => 0, + 'pseudoconstant' => [ + 'optionGroupName' => 'entity_batch_extends', + 'optionEditPath' => 'civicrm/admin/options/entity_batch_extends', + ], 'add' => '3.3', ], 'entity_id' => [ diff --git a/CRM/Upgrade/Incremental/Base.php b/CRM/Upgrade/Incremental/Base.php index 940fb3b0d1..8e2e8641f7 100644 --- a/CRM/Upgrade/Incremental/Base.php +++ b/CRM/Upgrade/Incremental/Base.php @@ -220,6 +220,26 @@ class CRM_Upgrade_Incremental_Base { return TRUE; } + /** + * Add the specified option group, gracefully if it already exists. + * + * @param CRM_Queue_TaskContext $ctx + * @param array $params + * @param array $options + * + * @return bool + */ + public static function addOptionGroup(CRM_Queue_TaskContext $ctx, $params, $options): bool { + $defaults = ['is_active' => 1]; + $optionDefaults = ['is_active' => 1]; + $optionDefaults['option_group_id'] = \CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(array_merge($defaults, $params)); + + foreach ($options as $option) { + \CRM_Core_BAO_OptionValue::ensureOptionValueExists(array_merge($optionDefaults, $option)); + } + return TRUE; + } + /** * Do any relevant message template updates. * diff --git a/CRM/Upgrade/Incremental/php/FiveFortyTwo.php b/CRM/Upgrade/Incremental/php/FiveFortyTwo.php index ac35a3ee2b..265aa328ee 100644 --- a/CRM/Upgrade/Incremental/php/FiveFortyTwo.php +++ b/CRM/Upgrade/Incremental/php/FiveFortyTwo.php @@ -55,21 +55,33 @@ class CRM_Upgrade_Incremental_php_FiveFortyTwo extends CRM_Upgrade_Incremental_B * (change the x in the function name): */ - // /** - // * Upgrade function. - // * - // * @param string $rev - // */ - // public function upgrade_5_0_x($rev) { - // $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); - // $this->addTask('Do the foo change', 'taskFoo', ...); - // // Additional tasks here... - // // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex. - // // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable. - // } - - // public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) { - // return TRUE; - // } + /** + * Upgrade function. + * + * @param string $rev + */ + public function upgrade_5_42_alpha1(string $rev): void { + $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); + $contributeComponentID = CRM_Core_DAO::singleValueQuery('SELECT id from civicrm_component WHERE name = "CiviContribute"'); + $this->addTask( + 'Add option group for entity batch table (if you are using gift-aid you will need an extension update)', + 'addOptionGroup', + [ + 'name' => 'entity_batch_extends', + 'title' => ts('Entity Batch Extends'), + 'is_reserved' => 1, + 'is_active' => 1, + 'is_locked' => 1, + ], + [ + [ + 'name' => 'civicrm_financial_trxn', + 'value' => 'civicrm_financial_trxn', + 'label' => ts('Financial Transactions'), + 'component_id' => $contributeComponentID, + ], + ] + ); + } } diff --git a/xml/schema/Batch/EntityBatch.xml b/xml/schema/Batch/EntityBatch.xml index 324db5b5a1..130993d2d5 100644 --- a/xml/schema/Batch/EntityBatch.xml +++ b/xml/schema/Batch/EntityBatch.xml @@ -28,6 +28,9 @@ 64 physical tablename for entity being joined to file, e.g. civicrm_contact 3.3 + + entity_batch_extends + entity_id diff --git a/xml/templates/civicrm_data.tpl b/xml/templates/civicrm_data.tpl index 1deb48e62d..4d91916da1 100644 --- a/xml/templates/civicrm_data.tpl +++ b/xml/templates/civicrm_data.tpl @@ -199,7 +199,8 @@ VALUES ('pledge_status' , '{ts escape="sql"}Pledge Status{/ts}' , NULL, 1, 1, 1), ('contribution_recur_status' , '{ts escape="sql"}Recurring Contribution Status{/ts}' , NULL, 1, 1, 1), ('environment' , '{ts escape="sql"}Environment{/ts}' , NULL, 1, 1, 0), - ('activity_default_assignee' , '{ts escape="sql"}Activity default assignee{/ts}' , NULL, 1, 1, 0); + ('activity_default_assignee' , '{ts escape="sql"}Activity default assignee{/ts}' , NULL, 1, 1, 0), + ('entity_batch_extends' , '{ts escape="sql"}Entity Batch Extends{/ts}' , NULL, 1, 1, 0); SELECT @option_group_id_pcm := max(id) from civicrm_option_group where name = 'preferred_communication_method'; SELECT @option_group_id_act := max(id) from civicrm_option_group where name = 'activity_type'; @@ -284,6 +285,7 @@ SELECT @option_group_id_ps := max(id) from civicrm_option_group where name = SELECT @option_group_id_crs := max(id) from civicrm_option_group where name = 'contribution_recur_status'; SELECT @option_group_id_env := max(id) from civicrm_option_group where name = 'environment'; SELECT @option_group_id_default_assignee := max(id) from civicrm_option_group where name = 'activity_default_assignee'; +SELECT @option_group_id_entity_batch_extends := max(id) from civicrm_option_group where name = 'entity_batch_extends'; SELECT @contributeCompId := max(id) FROM civicrm_component where name = 'CiviContribute'; SELECT @eventCompId := max(id) FROM civicrm_component where name = 'CiviEvent'; @@ -1054,7 +1056,12 @@ VALUES (@option_group_id_default_assignee, '{ts escape="sql"}None{/ts}', '1', 'NONE', NULL, 0, 1, 1, NULL, 0, 0, 1, NULL, NULL, NULL), (@option_group_id_default_assignee, '{ts escape="sql"}By relationship to case client{/ts}', '2', 'BY_RELATIONSHIP', NULL, 0, 0, 1, NULL, 0, 0, 1, NULL, NULL, NULL), (@option_group_id_default_assignee, '{ts escape="sql"}Specific contact{/ts}', '3', 'SPECIFIC_CONTACT', NULL, 0, 0, 1, NULL, 0, 0, 1, NULL, NULL, NULL), -(@option_group_id_default_assignee, '{ts escape="sql"}User creating the case{/ts}', '4', 'USER_CREATING_THE_CASE', NULL, 0, 0, 1, NULL, 0, 0, 1, NULL, NULL, NULL); +(@option_group_id_default_assignee, '{ts escape="sql"}User creating the case{/ts}', '4', 'USER_CREATING_THE_CASE', NULL, 0, 0, 1, NULL, 0, 0, 1, NULL, NULL, NULL), + +-- Entity Batch options +-- (`option_group_id`, `label`, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `visibility_id`, `icon`) +(@option_group_id_entity_batch_extends, '{ts escape="sql"}Financial Transactions{/ts}', 'civicrm_financial_trxn', 'civicrm_financial_trxn', NULL, 0, 1, 1, NULL, 0, 0, 1, @contributeCompId, NULL, NULL); + -- financial accounts SELECT @opval := value FROM civicrm_option_value WHERE name = 'Revenue' and option_group_id = @option_group_id_fat; -- 2.25.1