From: eileen Date: Wed, 10 Jul 2019 13:16:29 +0000 (+1200) Subject: Move more of the query construction into runQuery X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e034ee91e76e0683e382ef99d92f15ac0180fe47;p=civicrm-core.git Move more of the query construction into runQuery --- 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]; }