CRM_Contact_Import_Parser_Contact
class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser
class to parse contact csv files
Traits
Constants
MAX_WARNINGS |
Settings |
DEFAULT_TIMEOUT |
Settings |
VALID |
Return codes |
WARNING |
Return codes |
ERROR |
Return codes |
CONFLICT |
Return codes |
STOP |
Return codes |
DUPLICATE |
Return codes |
MULTIPLE_DUPE |
Return codes |
NO_MATCH |
Return codes |
UNPARSED_ADDRESS_WARNING |
Return codes |
MODE_MAPFIELD |
Parser modes |
MODE_PREVIEW |
Parser modes |
MODE_SUMMARY |
Parser modes |
MODE_IMPORT |
Parser modes |
DUPLICATE_SKIP |
Codes for duplicate record handling |
DUPLICATE_REPLACE |
Codes for duplicate record handling |
DUPLICATE_UPDATE |
Codes for duplicate record handling |
DUPLICATE_FILL |
Codes for duplicate record handling |
DUPLICATE_NOCHECK |
Codes for duplicate record handling |
CONTACT_INDIVIDUAL |
Contact types |
CONTACT_HOUSEHOLD |
Contact types |
CONTACT_ORGANIZATION |
Contact types |
Properties
protected int | $_totalCount | Total number of non empty lines | from CRM_Import_Parser |
protected int | $_validCount | Running total number of valid lines | from CRM_Import_Parser |
protected int | $_invalidRowCount | Running total number of invalid rows | from CRM_Import_Parser |
protected int | $_maxLinesToProcess | Maximum number of non-empty/comment lines to process | from CRM_Import_Parser |
protected array | $_errors | Array of error lines, bounded by MAX_ERROR | from CRM_Import_Parser |
protected int | $_conflictCount | Total number of conflict lines | from CRM_Import_Parser |
protected array | $_conflicts | Array of conflict lines | from CRM_Import_Parser |
protected int | $_duplicateCount | Total number of duplicate (from database) lines | from CRM_Import_Parser |
protected array | $_duplicates | Array of duplicate lines | from CRM_Import_Parser |
protected int | $_warningCount | Running total number of warnings | from CRM_Import_Parser |
protected int | $_maxWarningCount | Maximum number of warnings to store | from CRM_Import_Parser |
protected array | $_warnings | Array of warning lines, bounded by MAX_WARNING | from CRM_Import_Parser |
protected array | $_fields | Array of all the fields that could potentially be part of this import process | from CRM_Import_Parser |
protected array | $importableFieldsMetadata | Metadata for all available fields, keyed by unique name. | from CRM_Import_Parser |
protected array | $_activeFields | Array of the fields that are actually part of the import process the position in the array also dictates their position in the import file | from CRM_Import_Parser |
protected int | $_activeFieldCount | Cache the count of active fields | from CRM_Import_Parser |
protected array | $_rows | Cache of preview rows | from CRM_Import_Parser |
protected string | $_errorFileName | Filename of error data | from CRM_Import_Parser |
protected string | $_conflictFileName | Filename of conflict data | from CRM_Import_Parser |
protected string | $_duplicateFileName | Filename of duplicate data | from CRM_Import_Parser |
int | $_contactType | Contact type | from CRM_Import_Parser |
int | $_contactSubType | Contact sub-type | from CRM_Import_Parser |
protected | $_tableName | from CRM_Contact_Import_Parser | |
protected int | $_rowCount | Total number of lines in file | from CRM_Contact_Import_Parser |
protected int | $_unMatchCount | Running total number of un-matched Contacts. | from CRM_Contact_Import_Parser |
protected array | $_unMatch | Array of unmatched lines. | from CRM_Contact_Import_Parser |
protected int | $_unparsedAddressCount | Total number of contacts with unparsed addresses | from CRM_Contact_Import_Parser |
protected string | $_misMatchFilemName | Filename of mismatch data | from CRM_Contact_Import_Parser |
protected | $_primaryKeyName | from CRM_Contact_Import_Parser | |
protected | $_statusFieldName | from CRM_Contact_Import_Parser | |
protected | $fieldMetadata | from CRM_Contact_Import_Parser | |
int | $_onDuplicate | On duplicate | from CRM_Contact_Import_Parser |
int | $_dedupeRuleGroupID | Dedupe rule group id to use if set | from CRM_Contact_Import_Parser |
protected | $_mapperKeys | ||
protected | $_mapperLocType | ||
protected | $_mapperPhoneType | ||
protected | $_mapperImProvider | ||
protected | $_mapperWebsiteType | ||
protected | $_mapperRelated | ||
protected | $_mapperRelatedContactType | ||
protected | $_mapperRelatedContactDetails | ||
protected | $_mapperRelatedContactEmailType | ||
protected | $_mapperRelatedContactImProvider | ||
protected | $_mapperRelatedContactWebsiteType | ||
protected | $_relationships | ||
protected | $_emailIndex | ||
protected | $_firstNameIndex | ||
protected | $_lastNameIndex | ||
protected | $_householdNameIndex | ||
protected | $_organizationNameIndex | ||
protected | $_allEmails | ||
protected | $_phoneIndex | ||
protected bool | $_updateWithId | Is update only permitted on an id match. | |
protected | $_retCode | ||
protected | $_externalIdentifierIndex | ||
protected | $_allExternalIdentifiers | ||
protected | $_parseStreetAddress | ||
protected array | $_newContacts | Array of successfully imported contact id's | |
protected int | $_lineCount | Line count id. | |
protected array | $_newRelatedContacts | Array of successfully imported related contact id's | |
protected array | $_unparsedStreetAddressContacts | Array of all the contacts whose street addresses are not parsed. |
Methods
Get metadata for all importable fields in std getfields style format.
Set metadata for all importable fields in std getfields style format.
Class constructor.
The initializer code, called before processing.
The initializer code, called before the processing.
Handle the values in mapField mode.
Handle the values in preview mode.
Handle the values in summary mode.
Handle the values in import mode.
Set and validate field values.
Format the field values for input to the api.
Add progress bar to the import process. Calculates time remaining, status etc.
Get an array of header patterns for importable keys.
Get an array of header patterns for importable keys.
Remove single-quote enclosures from a value array (row).
Determines the file extension based on error code.
Determines the file name based on error code.
Check if contact is a duplicate .
Parse a field which could be represented by a label or name value rather than the DB value.
Run import.
Given a list of the importable field keys that the user has selected.
Set IM Service Provider type fields.
Set active field for related contact's phone type.
Set IM Service Provider type fields for related contacts.
No description
Export data to a CSV file.
Update the record with PK $id in the import database table.
Format common params data to proper format to store.
Format contact parameters.
Format location block ready for importing.
Get the field metadata for the relevant entity.
Fill in the primary location.
Get metadata for contact importable fields.
Get an array of header patterns for importable keys.
Get Array of all the fields that could potentially be part import process
Get the array of successfully imported contact id's
Get the array of successfully imported related contact id's
Check if an error in custom data.
Check if value present in all genders or.
Check if an error in Core( non-custom fields ) field
Ckeck a value present or not in a array.
Build error-message containing error-fields
Method for creating contact.
Format params for update and fill mode.
Convert any given date string to default date array.
Generate status and error message for unparsed street address records.
No description
get subtypes given the contact type
Get the possible contact matches.
Format the form mapping parameters ready for the parser.
Set field metadata.
Details
in CRM_Import_Parser at line 155
array
getImportableFieldsMetadata()
Get metadata for all importable fields in std getfields style format.
in CRM_Import_Parser at line 163
setImportableFieldsMetadata(array $importableFieldsMetadata)
Set metadata for all importable fields in std getfields style format.
at line 127
__construct(array $mapperKeys, array $mapperLocType = [], array $mapperPhoneType = [], array $mapperImProvider = [], array $mapperRelated = [], array $mapperRelatedContactType = [], array $mapperRelatedContactDetails = [], array $mapperRelatedContactLocType = [], array $mapperRelatedContactPhoneType = [], array $mapperRelatedContactImProvider = [], array $mapperWebsiteType = [], array $mapperRelatedContactWebsiteType = [])
Class constructor.
at line 151
init()
The initializer code, called before processing.
at line 1123
mixed
fini()
The initializer code, called before the processing.
at line 232
mixed
mapField(array $values)
Handle the values in mapField mode.
at line 245
mixed
preview(array $values)
Handle the values in preview mode.
at line 258
mixed
summary($values)
Handle the values in summary mode.
at line 445
mixed
import($onDuplicate, $values, bool $doGeocodeAddress = FALSE)
Handle the values in import mode.
in CRM_Import_Parser at line 283
int
setActiveFieldValues(array $elements, $erroneousField)
Set and validate field values.
in CRM_Contact_Import_Parser at line 484
array
getActiveFieldParams()
Format the field values for input to the api.
in CRM_Import_Parser at line 343
NULL|$currTimestamp
progressImport($statusID, bool $startImport = TRUE, $startTimestamp = NULL, $prevTimestamp = NULL, $totalRowCount = NULL)
Add progress bar to the import process. Calculates time remaining, status etc.
in CRM_Import_Parser at line 385
array
getSelectValues()
in CRM_Import_Parser at line 396
array
getSelectTypes()
in CRM_Contact_Import_MetadataTrait at line 84
array
getHeaderPatterns()
Get an array of header patterns for importable keys.
in CRM_Contact_Import_MetadataTrait at line 93
array
getDataPatterns()
Get an array of header patterns for importable keys.
in CRM_Import_Parser at line 438
static void
encloseScrub(array $values, string $enclosure = "'")
Remove single-quote enclosures from a value array (row).
in CRM_Import_Parser at line 455
void
setMaxLinesToProcess(int $max)
Setter function.
in CRM_Import_Parser at line 465
static string
errorFileName($type)
Determines the file extension based on error code.
in CRM_Import_Parser at line 504
static string
saveFileName($type)
Determines the file name based on error code.
in CRM_Import_Parser at line 541
protected array
checkContactDuplicate(array $formatValues)
Check if contact is a duplicate .
in CRM_Import_Parser at line 563
protected mixed
parsePseudoConstantField(string|int|null $submittedValue, array $fieldSpec)
Parse a field which could be represented by a label or name value rather than the DB value.
We will try to match name first or (per https://lab.civicrm.org/dev/core/issues/1285 if we have an id.
but if not available then see if we have a label that can be converted to a name.
in CRM_Contact_Import_Parser at line 108
mixed
run(string $tableName, array $mapper = [], int $mode = self::MODE_PREVIEW, int $contactType = self::CONTACT_INDIVIDUAL, string $primaryKeyName = '_id', string $statusFieldName = '_status', int $onDuplicate = self::DUPLICATE_SKIP, int $statusID = NULL, int $totalRowCount = NULL, bool $doGeocodeAddress = FALSE, int $timeout = CRM_Contact_Import_Parser::DEFAULT_TIMEOUT, string $contactSubType = NULL, int $dedupeRuleGroupID = NULL)
Run import.
in CRM_Contact_Import_Parser at line 355
setActiveFields(array $fieldKeys)
Given a list of the importable field keys that the user has selected.
set the active fields array to this list
in CRM_Contact_Import_Parser at line 370
setActiveFieldLocationTypes($elements)
in CRM_Contact_Import_Parser at line 383
setActiveFieldPhoneTypes($elements)
in CRM_Contact_Import_Parser at line 392
setActiveFieldWebsiteTypes($elements)
in CRM_Contact_Import_Parser at line 404
setActiveFieldImProviders(array $elements)
Set IM Service Provider type fields.
in CRM_Contact_Import_Parser at line 413
setActiveFieldRelated($elements)
in CRM_Contact_Import_Parser at line 422
setActiveFieldRelatedContactType($elements)
in CRM_Contact_Import_Parser at line 431
setActiveFieldRelatedContactDetails($elements)
in CRM_Contact_Import_Parser at line 440
setActiveFieldRelatedContactLocType($elements)
in CRM_Contact_Import_Parser at line 451
setActiveFieldRelatedContactPhoneType(array $elements)
Set active field for related contact's phone type.
in CRM_Contact_Import_Parser at line 460
setActiveFieldRelatedContactWebsiteType($elements)
in CRM_Contact_Import_Parser at line 472
setActiveFieldRelatedContactImProvider(array $elements)
Set IM Service Provider type fields for related contacts.
in CRM_Contact_Import_Parser at line 580
array
getColumnPatterns()
in CRM_Contact_Import_Parser at line 597
addField(string $name, $title, int $type = CRM_Utils_Type::T_INT, string $headerPattern = '//', string $dataPattern = '//', bool $hasLocationType = FALSE)
in CRM_Contact_Import_Parser at line 615
set(CRM_Core_Session $store, int $mode = self::MODE_SUMMARY)
Store parser values.
in CRM_Contact_Import_Parser at line 675
static
exportCSV(string $fileName, array $header, array $data)
Export data to a CSV file.
in CRM_Contact_Import_Parser at line 720
updateImportRecord(int $id, array $params)
Update the record with PK $id in the import database table.
in CRM_Contact_Import_Parser at line 754
formatCommonData(array $params, array $formatted, array $contactFields)
Format common params data to proper format to store.
in CRM_Contact_Import_Parser at line 988
protected bool
formatContactParameters(array $values, array $params)
Format contact parameters.
in CRM_Contact_Import_Parser at line 1197
protected bool
formatLocationBlock(array $values, array $params)
Format location block ready for importing.
There is some test coverage for this in CRM_Contact_Import_Parser_ContactTest e.g. testImportPrimaryAddress.
in CRM_Contact_Import_Parser at line 1324
protected array
getMetadataForEntity(string $entity)
Get the field metadata for the relevant entity.
in CRM_Contact_Import_Parser at line 1348
protected
fillPrimary(array $params, array $values, string $entity, int|null $contactID)
Fill in the primary location.
If the contact has a primary address we update it. Otherwise we add an address of the default location type.
in CRM_Contact_Import_MetadataTrait at line 16
protected array
getContactImportMetadata()
Get metadata for contact importable fields.
in CRM_Contact_Import_MetadataTrait at line 64
protected array
getRelationships()
Get sorted available relationships.
in CRM_Contact_Import_MetadataTrait at line 102
array
getFieldTitles()
Get an array of header patterns for importable keys.
in CRM_Contact_Import_MetadataTrait at line 109
protected
getContactType()
Get configured contact type.
in CRM_Contact_Import_MetadataTrait at line 118
protected string
getContactSubType()
Get configured contact sub type.
at line 425
array
getAllFields()
Get Array of all the fields that could potentially be part import process
at line 1107
array
getImportedContacts()
Get the array of successfully imported contact id's
at line 1116
array
getRelatedImportedContacts()
Get the array of successfully imported related contact id's
at line 1136
static
isErrorInCustomData(array $params, string $errorMessage, null $csType = NULL, null $relationships = NULL)
Check if an error in custom data.
at line 1336
bool
checkGender(string $gender)
Check if value present in all genders or.
as a substring of any gender value, if yes than return corresponding gender. eg value might be m/M, ma/MA, mal/MAL, male return 'Male' but if value is 'maleabc' than return false
at line 1365
isErrorInCoreData(array $params, string $errorMessage)
Check if an error in Core( non-custom fields ) field
at line 1636
static bool
in_value($value, $valueArray)
Ckeck a value present or not in a array.
at line 1659
static
addToErrorMsg(string $errorName, string $errorMessage)
Build error-message containing error-fields
Once upon a time there was a dev who hadn't heard of implode. That dev wrote this function.
at line 1680
array|bool|CRM_Contact_BAO_Contact|CRM_Core_Error|null
createContact(array $formatted, array $contactFields, int $onDuplicate, int $contactId = NULL, bool $requiredCheck = TRUE, int $dedupeRuleGroupID = NULL)
Method for creating contact.
at line 1744
formatParams(array $params, int $onDuplicate, int $cid)
Format params for update and fill mode.
at line 1866
static
formatCustomDate(array $params, array $formatted, int $dateType, string $dateParam)
Convert any given date string to default date array.
at line 1883
int
processMessage(array $values, array $statusFieldName, $returnCode)
Generate status and error message for unparsed street address records.
at line 1912
bool
checkRelatedContactFields($relKey, array $params)
at line 1956
static array
getSubtypes(string $contactType)
get subtypes given the contact type
at line 1984
protected array
getPossibleContactMatches(array $params)
Get the possible contact matches.
1) the chosen dedupe rule falling back to 2) a check for the external ID.
CRM-17275
at line 2035
static array
getParameterForParser(int $count)
Format the form mapping parameters ready for the parser.
at line 2059
protected
setFieldMetadata()
Set field metadata.