From e034ee91e76e0683e382ef99d92f15ac0180fe47 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 11 Jul 2019 01:16:29 +1200 Subject: [PATCH] Move more of the query construction into runQuery --- CRM/Export/BAO/Export.php | 24 +----------- CRM/Export/BAO/ExportProcessor.php | 63 ++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 22 deletions(-) diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index d8cee057ec..d9d25089b8 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -198,34 +198,14 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c if ($moreReturnProperties) { $processor->setAdditionalRequestedReturnProperties($moreReturnProperties); } + $processor->setComponentTable($componentTable); + $processor->setComponentClause($componentClause); list($query, $select, $from, $where, $having) = $processor->runQuery($params, $order); // This perhaps only needs calling when $mergeSameHousehold == 1 self::buildRelatedContactArray($selectAll, $ids, $processor, $componentTable); - $whereClauses = ['trash_clause' => "contact_a.is_deleted != 1"]; - if (!$selectAll && $componentTable) { - $from .= " INNER JOIN $componentTable ctTable ON ctTable.contact_id = contact_a.id "; - } - elseif ($componentClause) { - $whereClauses[] = $componentClause; - } - - // CRM-13982 - check if is deleted - foreach ($params as $value) { - if ($value[0] == 'contact_is_deleted') { - unset($whereClauses['trash_clause']); - } - } - - if (empty($where)) { - $where = "WHERE " . implode(' AND ', $whereClauses); - } - else { - $where .= " AND " . implode(' AND ', $whereClauses); - } - $queryString = "$select $from $where $having"; $groupBy = self::getGroupBy($processor, $query); diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index f39ae49029..e40099aa40 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -263,6 +263,48 @@ class CRM_Export_BAO_ExportProcessor { */ protected $outputSpecification = []; + /** + * @var string + */ + protected $componentTable = ''; + + /** + * @return string + */ + public function getComponentTable() { + return $this->componentTable; + } + + /** + * Set the component table (if any). + * + * @param string $componentTable + */ + public function setComponentTable($componentTable) { + $this->componentTable = $componentTable; + } + + /** + * Clause from component search. + * + * @var string + */ + protected $componentClause = ''; + + /** + * @return string + */ + public function getComponentClause() { + return $this->componentClause; + } + + /** + * @param string $componentClause + */ + public function setComponentClause($componentClause) { + $this->componentClause = $componentClause; + } + /** * Name of a temporary table created to hold the results. * @@ -678,6 +720,27 @@ class CRM_Export_BAO_ExportProcessor { $query->_sort = $order; list($select, $from, $where, $having) = $query->query(); $this->setQueryFields($query->_fields); + $whereClauses = ['trash_clause' => "contact_a.is_deleted != 1"]; + if ($this->getRequestedFields() && ($this->getComponentTable())){ + $from .= " INNER JOIN " . $this->getComponentTable() . " ctTable ON ctTable.contact_id = contact_a.id "; + } + elseif ($this->getComponentClause()) { + $whereClauses[] = $this->getComponentClause(); + } + + // CRM-13982 - check if is deleted + foreach ($params as $value) { + if ($value[0] == 'contact_is_deleted') { + unset($whereClauses['trash_clause']); + } + } + + if (empty($where)) { + $where = "WHERE " . implode(' AND ', $whereClauses); + } + else { + $where .= " AND " . implode(' AND ', $whereClauses); + } return [$query, $select, $from, $where . $addressWhere, $having]; } -- 2.25.1