Stop passing return Properties
authoreileen <emcnaughton@wikimedia.org>
Wed, 10 Jul 2019 12:30:03 +0000 (00:30 +1200)
committereileen <emcnaughton@wikimedia.org>
Thu, 11 Jul 2019 20:19:18 +0000 (08:19 +1200)
CRM/Export/BAO/Export.php
CRM/Export/BAO/ExportProcessor.php
tests/phpunit/CRM/Export/BAO/ExportTest.php

index 57f5ba5f0903f8ed9064d8cce89fba758477de2d..4b5e3232f0419388bc8c5de3075764d93fdf8503 100644 (file)
@@ -79,16 +79,15 @@ class CRM_Export_BAO_Export {
    * Get Query Group By Clause
    * @param \CRM_Export_BAO_ExportProcessor $processor
    *   Export Mode
-   * @param array $returnProperties
-   *   Return Properties
    * @param object $query
    *   CRM_Contact_BAO_Query
    *
    * @return string
    *   Group By Clause
    */
-  public static function getGroupBy($processor, $returnProperties, $query) {
+  public static function getGroupBy($processor, $query) {
     $groupBy = NULL;
+    $returnProperties = $processor->getReturnProperties();
     $exportMode = $processor->getExportMode();
     $queryMode = $processor->getQueryMode();
     if (!empty($returnProperties['tags']) || !empty($returnProperties['groups']) ||
@@ -187,7 +186,6 @@ class CRM_Export_BAO_Export {
     if ($moreReturnProperties) {
       $processor->setAdditionalRequestedReturnProperties($moreReturnProperties);
     }
-    $returnProperties = $processor->getReturnProperties();
     $paymentTableId = $processor->getPaymentTableID();
 
     if (!$selectAll && $componentTable && !empty($exportParams['additional_group'])) {
@@ -210,10 +208,10 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
       CRM_Contact_BAO_ProximityQuery::fixInputParams($params);
     }
 
-    list($query, $select, $from, $where, $having) = $processor->runQuery($params, $order, $returnProperties);
+    list($query, $select, $from, $where, $having) = $processor->runQuery($params, $order);
 
     if ($mergeSameHousehold == 1) {
-      $processor->setHouseholdMergeReturnProperties($returnProperties);
+      $processor->setHouseholdMergeReturnProperties();
     }
 
     // This perhaps only needs calling when $mergeSameHousehold == 1
@@ -243,7 +241,7 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
 
     $queryString = "$select $from $where $having";
 
-    $groupBy = self::getGroupBy($processor, $returnProperties, $query);
+    $groupBy = self::getGroupBy($processor, $query);
 
     $queryString .= $groupBy;
 
@@ -257,7 +255,7 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
 
       list($field, $dir) = explode(' ', $order, 2);
       $field = trim($field);
-      if (!empty($returnProperties[$field])) {
+      if (!empty($processor->getReturnProperties()[$field])) {
         //CRM-15301
         $queryString .= " ORDER BY $order";
       }
@@ -265,7 +263,7 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c
 
     $addPaymentHeader = FALSE;
 
-    list($outputColumns, $metadata) = self::getExportStructureArrays($returnProperties, $processor);
+    list($outputColumns, $metadata) = self::getExportStructureArrays($processor);
 
     if ($processor->isMergeSameAddress()) {
       //make sure the addressee fields are selected
@@ -907,7 +905,6 @@ LIMIT $offset, $limit
    * However it still feels a bit like something that I'm too polite to write down and this should be seen
    * as a step on the refactoring path rather than how it should be.
    *
-   * @param array $returnProperties
    * @param \CRM_Export_BAO_ExportProcessor $processor
    *
    * @return array
@@ -926,10 +923,10 @@ LIMIT $offset, $limit
    *    - b) this code is old & outdated. Submit your answers to circular bin or better
    *       yet find a way to comment them for posterity.
    */
-  public static function getExportStructureArrays($returnProperties, $processor) {
+  public static function getExportStructureArrays($processor) {
     $outputColumns = $metadata = [];
     $queryFields = $processor->getQueryFields();
-    foreach ($returnProperties as $key => $value) {
+    foreach ($processor->getReturnProperties() as $key => $value) {
       if (($key != 'location' || !is_array($value)) && !$processor->isRelationshipTypeKey($key)) {
         $outputColumns[$key] = $value;
         $processor->addOutputSpecification($key);
index e8dce0468f2500e04930d0dcb5afc4cc6e0306b3..aa4e0b36397166aebdba4e43c8f17ae33ce37243 100644 (file)
@@ -645,10 +645,11 @@ class CRM_Export_BAO_ExportProcessor {
   /**
    * @param $params
    * @param $order
-   * @param $returnProperties
+   *
    * @return array
    */
-  public function runQuery($params, $order, $returnProperties) {
+  public function runQuery($params, $order) {
+    $returnProperties = $this->getReturnProperties();
     $addressWhere = '';
     $params = array_merge($params, $this->getWhereParams());
     if ($this->isPostalableOnly) {
@@ -1217,10 +1218,9 @@ class CRM_Export_BAO_ExportProcessor {
    *
    * If we are using household merge we need to add these to the relationship properties to
    * be retrieved.
-   *
-   * @param $returnProperties
    */
-  public function setHouseholdMergeReturnProperties($returnProperties) {
+  public function setHouseholdMergeReturnProperties() {
+    $returnProperties = $this->getReturnProperties();
     $returnProperties = array_diff_key($returnProperties, array_fill_keys(['location_type', 'im_provider'], 1));
     foreach ($this->getHouseholdRelationshipTypes() as $householdRelationshipType) {
       $this->relationshipReturnProperties[$householdRelationshipType] = $returnProperties;
index 189712d920b333d53b3a7b47ce44e3923703e10c..f0c15879c28f9ca77b139c19d9603e9acd672e37 100644 (file)
@@ -289,16 +289,6 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase {
       'contribution_id' => 1,
     ];
 
-    $contactRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      TRUE,
-      'name',
-      FALSE
-    );
-
     $query = new CRM_Contact_BAO_Query([], $returnProperties, NULL,
       FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTRIBUTE,
       FALSE, TRUE, TRUE, NULL, 'AND'
@@ -310,10 +300,11 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase {
     preg_match_all($pattern, $select, $queryFieldAliases, PREG_PATTERN_ORDER);
     $processor = new CRM_Export_BAO_ExportProcessor(CRM_Contact_BAO_Query::MODE_CONTRIBUTE, NULL, 'AND');
     $processor->setQueryFields($query->_fields);
+    $processor->setReturnProperties($returnProperties);
 
-    list($outputFields) = CRM_Export_BAO_Export::getExportStructureArrays($returnProperties, $processor, $contactRelationshipTypes, '');
+    list($outputFields) = CRM_Export_BAO_Export::getExportStructureArrays($processor);
     foreach (array_keys($outputFields) as $fieldAlias) {
-      if ($fieldAlias == 'Home-country') {
+      if ($fieldAlias === 'Home-country') {
         $this->assertTrue(in_array($fieldAlias . '_id', $queryFieldAliases[1]), 'Country is subject to some funky translate so we make sure country id is present');
       }
       else {