From 2cd3d76753c022f265c0614e44cad98903a7ee84 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 3 Dec 2018 16:48:54 +1300 Subject: [PATCH] Move sql column definition to to the processor class --- CRM/Export/BAO/Export.php | 30 +++++++++++------------------- CRM/Export/BAO/ExportProcessor.php | 22 +++++++++++++++++++++- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index f8b0dc4411..c6c651af8e 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -441,19 +441,20 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c $count = -1; - list($outputColumns, $sqlColumns, $metadata) = self::getExportStructureArrays($returnProperties, $processor); + list($outputColumns, $metadata) = self::getExportStructureArrays($returnProperties, $processor); $headerRows = $processor->getHeaderRows(); + // add payment headers if required if ($addPaymentHeader && $processor->isExportPaymentFields()) { // @todo rather than do this for every single row do it before the loop starts. // where other header definitions take place. $headerRows = array_merge($headerRows, $processor->getPaymentHeaders()); foreach (array_keys($processor->getPaymentHeaders()) as $paymentHdr) { - self::sqlColumnDefn($processor, $sqlColumns, $paymentHdr); + $processor->setSqlColumnDefn($paymentHdr); } } - + $sqlColumns = $processor->getSQLColumns(); $exportTempTable = self::createTempTable($sqlColumns); $limitReached = FALSE; @@ -625,15 +626,6 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c CRM_Utils_System::civiExit(); } - /** - * @param \CRM_Export_BAO_ExportProcessor $processor - * @param $sqlColumns - * @param $field - */ - public static function sqlColumnDefn($processor, &$sqlColumns, $field) { - $sqlColumns[$processor->getMungedFieldName($field)] = $processor->getSqlColumnDefinition($field); - } - /** * @param string $tableName * @param $details @@ -1236,7 +1228,7 @@ WHERE {$whereClause}"; * yet find a way to comment them for posterity. */ public static function getExportStructureArrays($returnProperties, $processor) { - $metadata = $outputColumns = $sqlColumns = array(); + $metadata = $outputColumns = array(); $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'); $queryFields = $processor->getQueryFields(); @@ -1244,7 +1236,7 @@ WHERE {$whereClause}"; if (($key != 'location' || !is_array($value)) && !$processor->isRelationshipTypeKey($key)) { $outputColumns[$key] = $value; $processor->addOutputSpecification($key); - self::sqlColumnDefn($processor, $sqlColumns, $key); + $processor->setSqlColumnDefn($key); } elseif ($processor->isRelationshipTypeKey($key)) { $outputColumns[$key] = $value; @@ -1256,7 +1248,7 @@ WHERE {$whereClause}"; // Do not add to header row if we are only generating for merge reasons. $processor->addOutputSpecification($relationField, $key); } - self::sqlColumnDefn($processor, $sqlColumns, $field . '-' . $relationField); + $processor->setSqlColumnDefn($field . '-' . $relationField); } elseif (is_array($relationValue) && $relationField == 'location') { // fix header for location type case @@ -1275,7 +1267,7 @@ WHERE {$whereClause}"; } } $processor->addOutputSpecification($field, $key, $ltype, CRM_Utils_Array::value(1, $type)); - self::sqlColumnDefn($processor, $sqlColumns, $field . '-' . $hdr); + $processor->setSqlColumnDefn($field . '-' . $hdr); } } } @@ -1303,9 +1295,9 @@ WHERE {$whereClause}"; // Warning: shame inducing hack. $metadata[$daoFieldName]['pseudoconstant']['var'] = 'imProviders'; } - self::sqlColumnDefn($processor, $sqlColumns, $outputFieldName); + $processor->addOutputSpecification($outputFieldName, NULL, $locationType, CRM_Utils_Array::value(1, $type)); - self::sqlColumnDefn($processor, $sqlColumns, $outputFieldName); + $processor->setSqlColumnDefn($outputFieldName); if ($actualDBFieldName == 'country' || $actualDBFieldName == 'world_region') { $metadata[$daoFieldName] = array('context' => 'country'); } @@ -1317,7 +1309,7 @@ WHERE {$whereClause}"; } } } - return array($outputColumns, $sqlColumns, $metadata); + return array($outputColumns, $metadata); } /** diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index 72f99b32a7..711b7e51c4 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -467,9 +467,15 @@ class CRM_Export_BAO_ExportProcessor { $labelPrefix[] = $fieldPrefix[] = CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_IM', 'provider_id', $entityTypeID); } } - $index = ($fieldPrefix ? (implode('-', $fieldPrefix) . '-') : '') . $key; + $index = $this->getMungedFieldName(($fieldPrefix ? (implode('-', $fieldPrefix) . '-') : '') . $key); $this->outputSpecification[$index]['header'] = ($labelPrefix ? (implode('-', $labelPrefix) . '-') : '') . $label; + } + /** + * @param $key + */ + public function setSqlColumnDefn($key) { + $this->outputSpecification[$this->getMungedFieldName($key)]['sql_columns'] = $this->getSqlColumnDefinition($key); } /** @@ -496,6 +502,20 @@ class CRM_Export_BAO_ExportProcessor { return $headerRows; } + /** + * @return array + */ + public function getSQLColumns() { + $sqlColumns = []; + foreach ($this->outputSpecification as $key => $spec) { + if (empty($spec['do_not_output_to_sql'])) { + $sqlColumns[$key] = $spec['sql_columns']; + } + } + return $sqlColumns; + } + + /** * Build the row for output. * -- 2.25.1