Duplicate Activity::importableFields to upgrader & increase deprecation
authorEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 30 Nov 2022 07:36:55 +0000 (20:36 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 30 Nov 2022 07:55:53 +0000 (20:55 +1300)
CRM/Activity/BAO/Activity.php
CRM/Upgrade/Incremental/php/FiveFiftyOne.php

index 279cfc2959bf4c048da70cecedf096649173490f..cb9d728e2dbf14f7e5a15df61f61b57bc6c41782 100644 (file)
@@ -1434,6 +1434,7 @@ WHERE entity_id =%1 AND entity_table = %2";
    *   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) {
index 1b8f54332e10cf981922ac5bcef38baca96b6839..2c4a34dd0cb7b0a15d2edb3b94f0aa87c11ab9ee 100644 (file)
@@ -188,7 +188,7 @@ class CRM_Upgrade_Incremental_php_FiveFiftyOne extends CRM_Upgrade_Incremental_B
 
     $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
     );
 
@@ -324,6 +324,54 @@ class CRM_Upgrade_Incremental_php_FiveFiftyOne extends CRM_Upgrade_Incremental_B
     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.
    *