Skip to content

Commit

Permalink
dev/core#2814 migrate export processor to use MessageRender
Browse files Browse the repository at this point in the history
Note that test cover is in
I used  to step through it
as that specifically covers this change
  • Loading branch information
eileenmcnaughton committed Sep 4, 2021
1 parent e56a41a commit dd3bd63
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 32 deletions.
46 changes: 15 additions & 31 deletions CRM/Export/BAO/ExportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ public function runQuery($params, $order) {
//sort by state
//CRM-15301
$query->_sort = $order;
list($select, $from, $where, $having) = $query->query();
[$select, $from, $where, $having] = $query->query();
$this->setQueryFields($query->_fields);
$whereClauses = ['trash_clause' => "contact_a.is_deleted != 1"];
if ($this->getComponentClause()) {
Expand Down Expand Up @@ -844,7 +844,7 @@ public function runQuery($params, $order) {
$order .= ", contact_a.id";
}

list($field, $dir) = explode(' ', $order, 2);
[$field, $dir] = explode(' ', $order, 2);
$field = trim($field);
if (!empty($this->getReturnProperties()[$field])) {
//CRM-15301
Expand Down Expand Up @@ -1870,39 +1870,23 @@ public function getGroupBy($query) {
}

/**
* @param int $contactId
* Replace contact greetings in merged contacts.
*
* @param int $contactID
*
* @return array
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
public function replaceMergeTokens($contactId) {
$greetings = [];
$contact = NULL;

$greetingFields = [
'postal_greeting' => $this->getPostalGreetingTemplate(),
'addressee' => $this->getAddresseeGreetingTemplate(),
public function replaceMergeTokens(int $contactID): array {
$messageTemplate = [
'postal_greeting' => $this->getPostalGreetingTemplate() ?? '',
'addressee' => $this->getAddresseeGreetingTemplate() ?? '',
];
foreach ($greetingFields as $greeting => $greetingLabel) {
$tokens = CRM_Utils_Token::getTokens($greetingLabel);
if (!empty($tokens)) {
if (empty($contact)) {
$values = [
'id' => $contactId,
'version' => 3,
];
$contact = civicrm_api('contact', 'get', $values);

if (!empty($contact['is_error'])) {
return $greetings;
}
$contact = $contact['values'][$contact['id']];
}

$tokens = ['contact' => $greetingLabel];
$greetings[$greeting] = CRM_Utils_Token::replaceContactTokens($greetingLabel, $contact, NULL, $tokens);
}
if (array_filter($messageTemplate)) {
return CRM_Core_TokenSmarty::render($messageTemplate, ['contactId' => $contactID]);
}
return $greetings;
return $messageTemplate;
}

/**
Expand Down Expand Up @@ -2056,7 +2040,7 @@ public function trimNonTokensFromAddressString(
*/
public function getPreview($limit) {
$rows = [];
list($outputColumns) = $this->getExportStructureArrays();
[$outputColumns] = $this->getExportStructureArrays();
$query = $this->runQuery([], '');
CRM_Core_DAO::disableFullGroupByMode();
$result = CRM_Core_DAO::executeQuery($query[1] . ' LIMIT ' . (int) $limit);
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Export/BAO/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function tearDown(): void {
}
if ($this->processor && $this->processor->getTemporaryTable()) {
// delete the export temp table
CRM_Core_DAO::executeQuery("DROP TABLE IF EXISTS " . $this->processor->getTemporaryTable());
CRM_Core_DAO::executeQuery('DROP TABLE IF EXISTS ' . $this->processor->getTemporaryTable());
}
parent::tearDown();
}
Expand Down

0 comments on commit dd3bd63

Please sign in to comment.