From ae574f8a842b2f0eda61f22f1514e6592baf4bf7 Mon Sep 17 00:00:00 2001 From: Mathieu Lutfy Date: Fri, 21 Jul 2023 13:21:50 -0400 Subject: [PATCH] dev/financial#216 Financial Batch: remove the Create/Edit activities --- CRM/Financial/Form/FinancialBatch.php | 28 +-------------- CRM/Upgrade/Incremental/php/FiveSixtyFive.php | 34 +++++++++++++++++++ .../activity_type.sqldata.php | 23 +------------ 3 files changed, 36 insertions(+), 49 deletions(-) diff --git a/CRM/Financial/Form/FinancialBatch.php b/CRM/Financial/Form/FinancialBatch.php index 30f573cf1b..b345b30e99 100644 --- a/CRM/Financial/Form/FinancialBatch.php +++ b/CRM/Financial/Form/FinancialBatch.php @@ -194,39 +194,13 @@ class CRM_Financial_Form_FinancialBatch extends CRM_Contribute_Form { if (empty($params['created_id'])) { $params['created_id'] = CRM_Core_Session::getLoggedInContactID(); } - $details = "{$params['title']} batch has been created by this contact."; - $activityTypeName = 'Create Batch'; } - elseif ($this->_action & CRM_Core_Action::UPDATE && $this->_id) { - $details = "{$params['title']} batch has been edited by this contact."; - if ($params['status_id'] === $closedStatusId) { - $details = "{$params['title']} batch has been closed by this contact."; - } - $activityTypeName = 'Edit Batch'; - } - - // FIXME: What happens if we get to here and no activityType is defined? $batch = CRM_Batch_BAO_Batch::writeRecord($params); - //set batch id + // Required for postProcess hooks $this->_id = $batch->id; - // create activity. - $activityParams = [ - // activityTypeName - dev/core#1116-unknown-if-ok - 'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_DAO_Activity', 'activity_type_id', $activityTypeName), - 'subject' => $batch->title . "- Batch", - 'status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_DAO_Activity', 'activity_status_id', 'Completed'), - 'priority_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_DAO_Activity', 'priority_id', 'Normal'), - 'activity_date_time' => date('YmdHis'), - 'source_contact_id' => CRM_Core_Session::getLoggedInContactID(), - 'source_contact_qid' => CRM_Core_Session::getLoggedInContactID(), - 'details' => $details, - ]; - - CRM_Activity_BAO_Activity::create($activityParams); - $buttonName = $this->controller->getButtonName(); $context = $this->get("context"); diff --git a/CRM/Upgrade/Incremental/php/FiveSixtyFive.php b/CRM/Upgrade/Incremental/php/FiveSixtyFive.php index 508c6dc52a..2753652918 100644 --- a/CRM/Upgrade/Incremental/php/FiveSixtyFive.php +++ b/CRM/Upgrade/Incremental/php/FiveSixtyFive.php @@ -40,6 +40,40 @@ class CRM_Upgrade_Incremental_php_FiveSixtyFive extends CRM_Upgrade_Incremental_ $this->addTask('Make Group.frontend_title required', 'alterColumn', 'civicrm_group', 'frontend_title', "varchar(255) NOT NULL COMMENT 'Alternative public description of the group.'", TRUE); $this->addTask('Update ActionSchedule.limit_to column', 'alterColumn', 'civicrm_action_schedule', 'limit_to', "int COMMENT 'Is this the recipient criteria limited to OR in addition to?'"); + $this->addTask('Remove Batch Create/Edit Activity Types', 'removeFinancialBatchActivityTypes'); + } + + /** + * dev/financial#216 Remove the Create/Edit Batch Activity Types if they were + * never used. Otherwise we leave them there for now, and extension could + * re-implement the old behaviour. + */ + public static function removeFinancialBatchActivityTypes($ctx): bool { + $atypes = []; + $atypes[] = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Create Batch'); + $atypes[] = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Edit Batch'); + + if (empty(array_filter($atypes))) { + return TRUE; + } + + // Check for existing Create Batch activities (no need to check for Edit) + $exists = CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_activity WHERE activity_type_id = %1 LIMIT 1', [ + 1 => [$atypes[0], 'Positive'], + ]); + + if (!$exists) { + $option_group_id = CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_option_group WHERE name = "activity_type"'); + + if ($option_group_id) { + CRM_Core_DAO::executeQuery('DELETE FROM civicrm_option_value WHERE option_group_id = %1 AND value IN (%2)', [ + 1 => [$option_group_id, 'Positive'], + 2 => [implode(',', $atypes), 'CommaSeparatedIntegers'], + ]); + } + } + + return TRUE; } } diff --git a/sql/civicrm_data/civicrm_option_group/activity_type.sqldata.php b/sql/civicrm_data/civicrm_option_group/activity_type.sqldata.php index 9f6b191973..eb33c6d5c1 100644 --- a/sql/civicrm_data/civicrm_option_group/activity_type.sqldata.php +++ b/sql/civicrm_data/civicrm_option_group/activity_type.sqldata.php @@ -381,28 +381,7 @@ return CRM_Core_CodeGen_OptionGroup::create('activity_type', 'a/0002') 'value' => 41, 'name' => 'Export Accounting Batch', 'filter' => 1, - // FIXME: Shouldn't this use ts() - 'description' => 'Export Accounting Batch', - 'is_reserved' => 1, - 'component_id' => 2, - ], - [ - 'label' => ts('Create Batch'), - 'value' => 42, - 'name' => 'Create Batch', - 'filter' => 1, - // FIXME: Shouldn't this use ts() - 'description' => 'Create Batch', - 'is_reserved' => 1, - 'component_id' => 2, - ], - [ - 'label' => ts('Edit Batch'), - 'value' => 43, - 'name' => 'Edit Batch', - 'filter' => 1, - // FIXME: Shouldn't this use ts() - 'description' => 'Edit Batch', + 'description' => ts('Export Accounting Batch'), 'is_reserved' => 1, 'component_id' => 2, ], -- 2.25.1