Skip to content

Commit

Permalink
Merge pull request #25088 from eileenmcnaughton/activity_import
Browse files Browse the repository at this point in the history
Duplicate `Activity::importableFields` to upgrader & increase deprecation
  • Loading branch information
yashodha authored Dec 3, 2022
2 parents f55f3c0 + ea43ebd commit 3e31d94
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,7 @@ public static function sendMessage(
* array of importable Fields
*/
public static function &importableFields($status = FALSE) {
CRM_Core_Error::deprecatedFunctionWarning('api');
if (empty(Civi::$statics[__CLASS__][__FUNCTION__])) {
Civi::$statics[__CLASS__][__FUNCTION__] = [];
if (!$status) {
Expand Down
50 changes: 49 additions & 1 deletion CRM/Upgrade/Incremental/php/FiveFiftyOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public static function convertMappingFieldLabelsToNames(): bool {

$activityContact = CRM_Activity_BAO_ActivityContact::import();
$activityTarget['target_contact_id'] = $activityContact['contact_id'];
$fields = array_merge(CRM_Activity_BAO_Activity::importableFields(),
$fields = array_merge(self::getImportableActivityFields(),
$activityTarget
);

Expand Down Expand Up @@ -324,6 +324,54 @@ public static function updateUserJobTable($context): bool {
return TRUE;
}

/**
* Combine all the importable fields from the lower levels object.
*
* The ordering is important, since currently we do not have a weight
* scheme. Adding weight is super important and should be done in the
* next week or so, before this can be called complete.
*
* @return array
* array of importable Fields
*/
private static function getImportableActivityFields(): array {
if (empty(Civi::$statics[__CLASS__][__FUNCTION__])) {
Civi::$statics[__CLASS__][__FUNCTION__] = [];
$fields = ['' => ['title' => ts('- do not import -')]];

$tmpFields = CRM_Activity_DAO_Activity::import();
$contactFields = CRM_Contact_BAO_Contact::importableFields('Individual', NULL);

// Using new Dedupe rule.
$ruleParams = [
'contact_type' => 'Individual',
'used' => 'Unsupervised',
];
$fieldsArray = CRM_Dedupe_BAO_DedupeRule::dedupeRuleFields($ruleParams);

$tmpConatctField = [];
if (is_array($fieldsArray)) {
foreach ($fieldsArray as $value) {
$customFieldId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField',
$value,
'id',
'column_name'
);
$value = $customFieldId ? 'custom_' . $customFieldId : $value;
$tmpConatctField[trim($value)] = $contactFields[trim($value)];
$tmpConatctField[trim($value)]['title'] = $tmpConatctField[trim($value)]['title'] . " (match to contact)";
}
}
$tmpConatctField['external_identifier'] = $contactFields['external_identifier'];
$tmpConatctField['external_identifier']['title'] = $contactFields['external_identifier']['title'] . " (match to contact)";
$fields = array_merge($fields, $tmpConatctField);
$fields = array_merge($fields, $tmpFields);
$fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Activity'));
Civi::$statics[__CLASS__][__FUNCTION__] = $fields;
}
return Civi::$statics[__CLASS__][__FUNCTION__];
}

/**
* Historical copy of Contribution importable fields function.
*
Expand Down

0 comments on commit 3e31d94

Please sign in to comment.