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");
$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;
}
}
'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,
],