From 246e571e7a4f185f76715064ae035773dbcf5e4a Mon Sep 17 00:00:00 2001 From: Jon Goldberg Date: Tue, 10 Sep 2019 12:15:31 -0400 Subject: [PATCH] Fix for core#1247 - export hook doesn't work --- CRM/Export/BAO/Export.php | 1 + CRM/Export/BAO/ExportProcessor.php | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 22ef1aede73a..a95df716d8f7 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -115,6 +115,7 @@ public static function exportComponents( } $processor->setComponentTable($componentTable); $processor->setComponentClause($componentClause); + $processor->setIds($ids); list($query, $queryString) = $processor->runQuery($params, $order); diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index 4405a1aaeeac..6fae79fac178 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -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. * @@ -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 */ @@ -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.'); + } 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); @@ -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;