From 71464b7347c433b4e6e2e5be8957e14a67c90be2 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 16 Jul 2018 15:35:19 +1200 Subject: [PATCH] Set, don't pass queryOperator --- CRM/Export/BAO/Export.php | 4 +- CRM/Export/BAO/ExportProcessor.php | 48 +++++++++++++++------ tests/phpunit/CRM/Export/BAO/ExportTest.php | 10 ++--- 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 06dbd629a6..b68509f7ef 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -353,7 +353,7 @@ class CRM_Export_BAO_Export { $queryOperator = 'AND' ) { - $processor = new CRM_Export_BAO_ExportProcessor($exportMode); + $processor = new CRM_Export_BAO_ExportProcessor($exportMode, $queryOperator); $returnProperties = array(); $paymentFields = $selectedPaymentFields = FALSE; @@ -556,7 +556,7 @@ 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, $queryOperator, $returnProperties); + list($query, $select, $from, $where, $having) = $processor->runQuery($params, $order, $returnProperties); if ($mergeSameHousehold == 1) { if (empty($returnProperties['id'])) { diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index 807c231628..8479f038a3 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -55,6 +55,39 @@ class CRM_Export_BAO_ExportProcessor { */ protected $queryFields = []; + /** + * Either AND or OR. + * + * @var string + */ + protected $queryOperator; + + /** + * CRM_Export_BAO_ExportProcessor constructor. + * + * @param int $exportMode + * @param string $queryOperator + */ + public function __construct($exportMode, $queryOperator) { + $this->setExportMode($exportMode); + $this->setQueryMode(); + $this->setQueryOperator($queryOperator); + } + + /** + * @return string + */ + public function getQueryOperator() { + return $this->queryOperator; + } + + /** + * @param string $queryOperator + */ + public function setQueryOperator($queryOperator) { + $this->queryOperator = $queryOperator; + } + /** * @return array */ @@ -69,16 +102,6 @@ class CRM_Export_BAO_ExportProcessor { $this->queryFields = $queryFields; } - /** - * CRM_Export_BAO_ExportProcessor constructor. - * - * @param int $exportMode - */ - public function __construct($exportMode) { - $this->setExportMode($exportMode); - $this->setQueryMode(); - } - /** * @return int */ @@ -142,14 +165,13 @@ class CRM_Export_BAO_ExportProcessor { /** * @param $params * @param $order - * @param $queryOperator * @param $returnProperties * @return array */ - public function runQuery($params, $order, $queryOperator, $returnProperties) { + public function runQuery($params, $order, $returnProperties) { $query = new CRM_Contact_BAO_Query($params, $returnProperties, NULL, FALSE, FALSE, $this->getQueryMode(), - FALSE, TRUE, TRUE, NULL, $queryOperator + FALSE, TRUE, TRUE, NULL, $this->getQueryOperator() ); //sort by state diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php index 1eae9a092d..3d1df3c883 100644 --- a/tests/phpunit/CRM/Export/BAO/ExportTest.php +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -44,7 +44,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { * Basic test to ensure the exportComponents function completes without error. */ public function testExportComponentsNull() { - list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents( + list($tableName) = CRM_Export_BAO_Export::exportComponents( TRUE, array(), array(), @@ -192,10 +192,10 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { $pattern = '/as `?([^`,]*)/'; $queryFieldAliases = array(); preg_match_all($pattern, $select, $queryFieldAliases, PREG_PATTERN_ORDER); - $processor = new CRM_Export_BAO_ExportProcessor(CRM_Contact_BAO_Query::MODE_CONTRIBUTE); + $processor = new CRM_Export_BAO_ExportProcessor(CRM_Contact_BAO_Query::MODE_CONTRIBUTE, 'AND'); $processor->setQueryFields($query->_fields); - list($outputFields) = CRM_Export_BAO_Export::getExportStructureArrays($returnProperties, $processor, $contactRelationshipTypes, '', array()); + list($outputFields) = CRM_Export_BAO_Export::getExportStructureArrays($returnProperties, $processor, $contactRelationshipTypes, ''); foreach (array_keys($outputFields) as $fieldAlias) { 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'); @@ -502,7 +502,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { )); //create address for contact A - $result = $this->callAPISuccess('address', 'create', array( + $this->callAPISuccess('address', 'create', array( 'contact_id' => $contactA['id'], 'location_type_id' => 'Home', 'street_address' => 'ABC 12', @@ -513,7 +513,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { )); //create address for contact B - $result = $this->callAPISuccess('address', 'create', array( + $this->callAPISuccess('address', 'create', array( 'contact_id' => $contactB['id'], 'location_type_id' => 'Home', 'street_address' => 'ABC 12', -- 2.25.1