Merge pull request #14802 from eileenmcnaughton/ex4
authorcolemanw <coleman@civicrm.org>
Thu, 11 Jul 2019 23:30:11 +0000 (19:30 -0400)
committerGitHub <noreply@github.com>
Thu, 11 Jul 2019 23:30:11 +0000 (19:30 -0400)
[REF] [Export] Move setting of household properties to processor

CRM/Export/BAO/Export.php
CRM/Export/BAO/ExportProcessor.php
Civi/Core/Container.php

index 964aad576a3cd4f4665ad478789418d1e7a65edc..20e0f03f57dae53e1855f4e8275bbdbc35c734f7 100644 (file)
@@ -182,20 +182,22 @@ class CRM_Export_BAO_Export {
       $mappedFields[] = CRM_Core_BAO_Mapping::getMappingParams([], $field);
     }
 
+    if (!$selectAll && $componentTable && !empty($exportParams['additional_group'])) {
+      // If an Additional Group is selected, then all contacts in that group are
+      // added to the export set (filtering out duplicates).
+      // Really - the calling function could do this ... just saying
+      // @todo take a whip to the calling function.
+      CRM_Core_DAO::executeQuery("
+INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_contact gc WHERE gc.group_id = {$exportParams['additional_group']} ON DUPLICATE KEY UPDATE {$componentTable}.contact_id = gc.contact_id"
+      );
+    }
+
     $processor = new CRM_Export_BAO_ExportProcessor($exportMode, $mappedFields, $queryOperator, $mergeSameHousehold, $isPostalOnly, $mergeSameAddress);
     if ($moreReturnProperties) {
       $processor->setAdditionalRequestedReturnProperties($moreReturnProperties);
     }
     $paymentTableId = $processor->getPaymentTableID();
 
-    if (!$selectAll && $componentTable && !empty($exportParams['additional_group'])) {
-      // If an Additional Group is selected, then all contacts in that group are
-      // added to the export set (filtering out duplicates).
-      $query = "
-INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_contact gc WHERE gc.group_id = {$exportParams['additional_group']} ON DUPLICATE KEY UPDATE {$componentTable}.contact_id = gc.contact_id";
-      CRM_Core_DAO::executeQuery($query);
-    }
-
     if ($processor->getRequestedFields() &&
       $processor->isPostalableOnly()
     ) {
@@ -684,43 +686,6 @@ WHERE  id IN ( $deleteIDString )
     }
   }
 
-  /**
-   * @param int $contactId
-   * @param array $exportParams
-   *
-   * @return array
-   */
-  public static function _replaceMergeTokens($contactId, $exportParams) {
-    $greetings = [];
-    $contact = NULL;
-
-    $greetingFields = [
-      'postal_greeting',
-      'addressee',
-    ];
-    foreach ($greetingFields as $greeting) {
-      if (!empty($exportParams[$greeting])) {
-        $greetingLabel = $exportParams[$greeting];
-        if (empty($contact)) {
-          $values = [
-            'id' => $contactId,
-            'version' => 3,
-          ];
-          $contact = civicrm_api('contact', 'get', $values);
-
-          if (!empty($contact['is_error'])) {
-            return $greetings;
-          }
-          $contact = $contact['values'][$contact['id']];
-        }
-
-        $tokens = ['contact' => $greetingLabel];
-        $greetings[$greeting] = CRM_Utils_Token::replaceContactTokens($greetingLabel, $contact, NULL, $tokens);
-      }
-    }
-    return $greetings;
-  }
-
   /**
    * @param \CRM_Export_BAO_ExportProcessor $processor
    * @param $sql
@@ -747,7 +712,7 @@ WHERE  id IN ( $deleteIDString )
 
       if (!$sharedAddress) {
         if (!isset($contactGreetingTokens[$dao->master_contact_id])) {
-          $contactGreetingTokens[$dao->master_contact_id] = self::_replaceMergeTokens($dao->master_contact_id, $exportParams);
+          $contactGreetingTokens[$dao->master_contact_id] = $processor->replaceMergeTokens($dao->master_contact_id, $exportParams);
         }
         $masterPostalGreeting = CRM_Utils_Array::value('postal_greeting',
           $contactGreetingTokens[$dao->master_contact_id], $dao->master_postal_greeting
@@ -757,7 +722,7 @@ WHERE  id IN ( $deleteIDString )
         );
 
         if (!isset($contactGreetingTokens[$dao->copy_contact_id])) {
-          $contactGreetingTokens[$dao->copy_contact_id] = self::_replaceMergeTokens($dao->copy_contact_id, $exportParams);
+          $contactGreetingTokens[$dao->copy_contact_id] = $processor->replaceMergeTokens($dao->copy_contact_id, $exportParams);
         }
         $copyPostalGreeting = CRM_Utils_Array::value('postal_greeting',
           $contactGreetingTokens[$dao->copy_contact_id], $dao->copy_postal_greeting
index f06992ddfa4775c480edc835714f50a90270907b..2a0379a917f5a42327eb389e7feb3fdb0d40a504 100644 (file)
@@ -1612,6 +1612,43 @@ class CRM_Export_BAO_ExportProcessor {
     return $returnProperties;
   }
 
+  /**
+   * @param int $contactId
+   * @param array $exportParams
+   *
+   * @return array
+   */
+  public function replaceMergeTokens($contactId, $exportParams) {
+    $greetings = [];
+    $contact = NULL;
+
+    $greetingFields = [
+      'postal_greeting',
+      'addressee',
+    ];
+    foreach ($greetingFields as $greeting) {
+      if (!empty($exportParams[$greeting])) {
+        $greetingLabel = $exportParams[$greeting];
+        if (empty($contact)) {
+          $values = [
+            'id' => $contactId,
+            'version' => 3,
+          ];
+          $contact = civicrm_api('contact', 'get', $values);
+
+          if (!empty($contact['is_error'])) {
+            return $greetings;
+          }
+          $contact = $contact['values'][$contact['id']];
+        }
+
+        $tokens = ['contact' => $greetingLabel];
+        $greetings[$greeting] = CRM_Utils_Token::replaceContactTokens($greetingLabel, $contact, NULL, $tokens);
+      }
+    }
+    return $greetings;
+  }
+
   /**
    * The function unsets static part of the string, if token is the dynamic part.
    *
index 533e8d8b945be5456d5fe454de6eb42af30192e8..853299498b870c9a89287d537d39df6ed8c377a9 100644 (file)
@@ -159,14 +159,20 @@ class Container {
       'groups' => 'contact groups',
     ];
     foreach ($basicCaches as $cacheSvc => $cacheGrp) {
+      $definitionParams = [
+        'name' => $cacheGrp,
+        'type' => ['*memory*', 'SqlGroup', 'ArrayCache'],
+      ];
+      // For Caches that we don't really care about the ttl for and/or maybe accessed
+      // fairly often we use the fastArrayDecorator which improves reads and writes, these
+      // caches should also not have concurrency risk.
+      $fastArrayCaches = ['groups'];
+      if (in_array($cacheSvc, $fastArrayCaches)) {
+        $definitionParams['withArray'] = 'fast';
+      }
       $container->setDefinition("cache.{$cacheSvc}", new Definition(
         'CRM_Utils_Cache_Interface',
-        [
-          [
-            'name' => $cacheGrp,
-            'type' => ['*memory*', 'SqlGroup', 'ArrayCache'],
-          ],
-        ]
+        [$definitionParams]
       ))->setFactory('CRM_Utils_Cache::create');
     }