Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for core#1247 - export hook doesn't work #15287

Merged
merged 1 commit into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public static function exportComponents(
}
$processor->setComponentTable($componentTable);
$processor->setComponentClause($componentClause);
$processor->setIds($ids);

list($query, $queryString) = $processor->runQuery($params, $order);

Expand Down
30 changes: 29 additions & 1 deletion CRM/Export/BAO/ExportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ class CRM_Export_BAO_ExportProcessor {
*/
protected $contactGreetingFields = [];

/**
* An array of primary IDs of the entity being exported.
*
* @var array
*/
protected $ids = [];

/**
* Get additional non-visible fields for address merge purposes.
*
Expand Down Expand Up @@ -585,6 +592,20 @@ public function setQueryOperator($queryOperator) {
$this->queryOperator = $queryOperator;
}

/**
* @return array
*/
public function getIds() {
return $this->ids;
}

/**
* @param array $ids
*/
public function setIds($ids) {
$this->ids = $ids;
}

/**
* @return array
*/
Expand Down Expand Up @@ -2327,7 +2348,14 @@ public function writeCSVFromTable() {
// call export hook
$headerRows = $this->getHeaderRows();
$exportTempTable = $this->getTemporaryTable();
$exportMode = $this->getExportMode();
$sqlColumns = $this->getSQLColumns();
$componentTable = $this->getComponentTable();
$ids = $this->getIds();
CRM_Utils_Hook::export($exportTempTable, $headerRows, $sqlColumns, $exportMode, $componentTable, $ids);
if ($exportMode !== $this->getExportMode() || $componentTable !== $this->getComponentTable()) {
CRM_Core_Error::deprecatedFunctionWarning('altering the export mode and/or component table in the hook is no longer supported.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MegaphoneJon so per your discussion it's kinda meaningless to change ids & we are assuming it's safe to be clear about that - shall we change the hook to no longer accept $ids as a reference? (could be in master)

}
if ($exportTempTable !== $this->getTemporaryTable()) {
CRM_Core_Error::deprecatedFunctionWarning('altering the export table in the hook is deprecated (in some flows the table itself will be)');
$this->setTemporaryTable($exportTempTable);
Expand Down Expand Up @@ -2356,7 +2384,7 @@ public function writeCSVFromTable() {
while ($dao->fetch()) {
$row = [];

foreach (array_keys($this->getSQLColumns()) as $column) {
foreach (array_keys($sqlColumns) as $column) {
$row[$column] = $dao->$column;
}
$componentDetails[] = $row;
Expand Down