X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FImport%2FParser.php;h=a4b11fb439e09d39dadbbc37acebd346c2b7b4ab;hb=bc77d7c0798081f999e6eca92d75fa874fd04e74;hp=ba205617155379d71b906e0156e95b77768d923f;hpb=ffde4eabdf7b88feb5b03d8555c0ec0458cf1cfd;p=civicrm-core.git diff --git a/CRM/Contact/Import/Parser.php b/CRM/Contact/Import/Parser.php index ba20561715..a4b11fb439 100644 --- a/CRM/Contact/Import/Parser.php +++ b/CRM/Contact/Import/Parser.php @@ -1,34 +1,18 @@ getDatabaseConnection(); - $result = $db->query($query); - while ($values = $result->fetchRow(DB_FETCHMODE_ORDERED)) { + $result = CRM_Core_DAO::executeQuery($query); + + while ($result->fetch()) { + $values = array_values($result->toArray()); $this->_rowCount++; /* trim whitespace around the values */ @@ -578,6 +562,7 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser { * @return array */ public function getColumnPatterns() { + CRM_Core_Error::deprecatedFunctionWarning('no longer used- use CRM_Contact_Import_MetadataTrait'); $values = []; foreach ($this->_fields as $name => $field) { $values[$name] = $field->_columnPattern; @@ -616,8 +601,6 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser { $store->set('fields', $this->getSelectValues()); $store->set('fieldTypes', $this->getSelectTypes()); - $store->set('columnPatterns', $this->getColumnPatterns()); - $store->set('dataPatterns', $this->getDataPatterns()); $store->set('columnCount', $this->_activeFieldCount); $store->set('totalRowCount', $this->_totalCount); @@ -1000,9 +983,6 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser { // Note // Custom - // Cache the various object fields - static $fields = []; - // first add core contact values since for other Civi modules they are not added $contactFields = CRM_Contact_DAO_Contact::fields(); _civicrm_api3_store_values($contactFields, $values, $params); @@ -1016,6 +996,10 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser { return TRUE; } + // Cache the various object fields + // @todo - remove this after confirming this is just a compilation of other-wise-cached fields. + static $fields = []; + if (isset($values['individual_prefix'])) { if (!empty($params['prefix_id'])) { $prefixes = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'); @@ -1164,18 +1148,15 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser { } // Check for custom field values - - if (empty($fields['custom'])) { - $fields['custom'] = &CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $values), - FALSE, FALSE, NULL, NULL, FALSE, FALSE, FALSE - ); - } + $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $values), + FALSE, FALSE, NULL, NULL, FALSE, FALSE, FALSE + ); foreach ($values as $key => $value) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) { // check if it's a valid custom field id - if (!array_key_exists($customFieldID, $fields['custom'])) { + if (!array_key_exists($customFieldID, $customFields)) { return civicrm_api3_create_error('Invalid custom field ID'); } else { @@ -1209,6 +1190,7 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser { if (!array_key_exists($blockFieldName, $values)) { continue; } + $blockIndex = $values['location_type_id'] . (!empty($values['phone_type_id']) ? '_' . $values['phone_type_id'] : ''); // block present in value array. if (!array_key_exists($blockFieldName, $params) || !is_array($params[$blockFieldName])) { @@ -1223,13 +1205,13 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser { } _civicrm_api3_store_values($fields[$block], $values, - $params[$blockFieldName][$values['location_type_id']] + $params[$blockFieldName][$blockIndex] ); - $this->fillPrimary($params[$blockFieldName][$values['location_type_id']], $values, $block, CRM_Utils_Array::value('id', $params)); + $this->fillPrimary($params[$blockFieldName][$blockIndex], $values, $block, CRM_Utils_Array::value('id', $params)); if (empty($params['id']) && (count($params[$blockFieldName]) == 1)) { - $params[$blockFieldName][$values['location_type_id']]['is_primary'] = TRUE; + $params[$blockFieldName][$blockIndex]['is_primary'] = TRUE; } // we only process single block at a time.