Commit 28a57403 authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub

Merge pull request #14808 from eileenmcnaughton/export_sql

[REF] [Export] Further  cleanup - construct  sql more concisely
parents 5d4afc87 9858dc0b
......@@ -198,36 +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);
list($query, $queryString) = $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);
$queryString .= $groupBy;
......
......@@ -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,7 +720,28 @@ class CRM_Export_BAO_ExportProcessor {
$query->_sort = $order;
list($select, $from, $where, $having) = $query->query();
$this->setQueryFields($query->_fields);
return [$query, $select, $from, $where . $addressWhere, $having];
$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 $having"];
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment