From ad6f6e4c81a7d3b51f42e798c96b580b4d6633cc Mon Sep 17 00:00:00 2001 From: adixon Date: Mon, 30 Jul 2018 10:01:33 -0400 Subject: [PATCH 1/2] Use text type field when exporting any id-type field that might get converted into text of arbitrary length --- CRM/Export/BAO/ExportProcessor.php | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index d25fefcb8df0..b814837aa173 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -515,32 +515,18 @@ public function getValidLocationFields() { */ public function getSqlColumnDefinition($field) { $fieldName = $this->getMungedFieldName($field); - - // early exit for master_id, CRM-12100 - // in the DB it is an ID, but in the export, we retrive the display_name of the master record - // also for current_employer, CRM-16939 - if ($fieldName == 'master_id' || $fieldName == 'current_employer') { - return "$fieldName varchar(128)"; - } - - if (substr($fieldName, -11) == 'campaign_id') { - // CRM-14398 - return "$fieldName varchar(128)"; - } - $queryFields = $this->getQueryFields(); - $lookUp = ['prefix_id', 'suffix_id']; // set the sql columns if (isset($queryFields[$field]['type'])) { switch ($queryFields[$field]['type']) { case CRM_Utils_Type::T_INT: + // Integer fields may be references that are retrieved for export as text of arbitrary length. + // We use "text" instead of "varchar(xyz)" to avoid row width limitations of mysql. + // This solution replaces a previous collection of ad-hoc partial solutions. + return "$fieldName text"; + case CRM_Utils_Type::T_BOOLEAN: - if (in_array($field, $lookUp)) { - return "$fieldName varchar(255)"; - } - else { - return "$fieldName varchar(16)"; - } + return "$fieldName varchar(16)"; case CRM_Utils_Type::T_STRING: if (isset($queryFields[$field]['maxlength'])) { @@ -570,8 +556,10 @@ public function getSqlColumnDefinition($field) { } } else { + // handle fields for which we have no 'type' configured (yet!) if (substr($fieldName, -3, 3) == '_id') { - return "$fieldName varchar(255)"; + // Will likely get expanded into text of arbitrary length. + return "$fieldName text"; } elseif (substr($fieldName, -5, 5) == '_note') { return "$fieldName text"; From c53004b95aad8c121194db9a905e6d3719bf66b0 Mon Sep 17 00:00:00 2001 From: adixon Date: Tue, 31 Jul 2018 12:08:34 -0400 Subject: [PATCH 2/2] fix special case of exporting the civicrm primary id --- CRM/Export/BAO/ExportProcessor.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index b814837aa173..f666f7d33659 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -516,6 +516,10 @@ public function getValidLocationFields() { public function getSqlColumnDefinition($field) { $fieldName = $this->getMungedFieldName($field); $queryFields = $this->getQueryFields(); + // special case: civicirm_primary_id exports the contact id and is an index field + if ($fieldName == 'civicrm_primary_id') { + return "$fieldName varchar(16)"; + } // set the sql columns if (isset($queryFields[$field]['type'])) { switch ($queryFields[$field]['type']) {