abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser

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
protected int $_rowCount Total number of lines in file
protected int $_unMatchCount Running total number of un-matched Contacts.
protected array $_unMatch Array of unmatched lines.
protected int $_unparsedAddressCount Total number of contacts with unparsed addresses
protected string $_misMatchFilemName Filename of mismatch data
protected $_primaryKeyName
protected $_statusFieldName
protected $fieldMetadata
int $_onDuplicate On duplicate
int $_dedupeRuleGroupID Dedupe rule group id to use if set

Methods

array
getImportableFieldsMetadata()

Get metadata for all importable fields in std getfields style format.

setImportableFieldsMetadata(array $importableFieldsMetadata)

Set metadata for all importable fields in std getfields style format.

__construct()

Class constructor.

init()

Abstract function definitions.

mixed
fini()

No description

mixed
mapField(array $values)

Map field.

mixed
preview(array $values)

Preview.

mixed
summary($values)

No description

mixed
import($onDuplicate, $values)

No description

int
setActiveFieldValues(array $elements, $erroneousField)

Set and validate field values.

array
getActiveFieldParams()

Format the field values for input to the api.

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.

array
getSelectValues()

No description

array
getSelectTypes()

No description

array
getHeaderPatterns()

No description

array
getDataPatterns()

No description

static void
encloseScrub(array $values, string $enclosure = "'")

Remove single-quote enclosures from a value array (row).

void
setMaxLinesToProcess(int $max)

Setter function.

static string
errorFileName($type)

Determines the file extension based on error code.

static string
saveFileName($type)

Determines the file name based on error code.

array
checkContactDuplicate(array $formatValues)

Check if contact is a duplicate .

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.

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.

setActiveFields(array $fieldKeys)

Given a list of the importable field keys that the user has selected.

setActiveFieldLocationTypes($elements)

No description

setActiveFieldPhoneTypes($elements)

No description

setActiveFieldWebsiteTypes($elements)

No description

setActiveFieldImProviders(array $elements)

Set IM Service Provider type fields.

setActiveFieldRelated($elements)

No description

setActiveFieldRelatedContactType($elements)

No description

setActiveFieldRelatedContactDetails($elements)

No description

setActiveFieldRelatedContactLocType($elements)

No description

setActiveFieldRelatedContactPhoneType(array $elements)

Set active field for related contact's phone type.

setActiveFieldRelatedContactWebsiteType($elements)

No description

setActiveFieldRelatedContactImProvider(array $elements)

Set IM Service Provider type fields for related contacts.

array
getColumnPatterns()

No description

addField(string $name, $title, int $type = CRM_Utils_Type::T_INT, string $headerPattern = '//', string $dataPattern = '//', bool $hasLocationType = FALSE)

No description

set(CRM_Core_Session $store, int $mode = self::MODE_SUMMARY)

Store parser values.

static 
exportCSV(string $fileName, array $header, array $data)

Export data to a CSV file.

updateImportRecord(int $id, array $params)

Update the record with PK $id in the import database table.

formatCommonData(array $params, array $formatted, array $contactFields)

Format common params data to proper format to store.

bool
formatContactParameters(array $values, array $params)

Format contact parameters.

bool
formatLocationBlock(array $values, array $params)

Format location block ready for importing.

array
getMetadataForEntity(string $entity)

Get the field metadata for the relevant entity.

fillPrimary(array $params, array $values, string $entity, int|null $contactID)

Fill in the primary location.

Details

in CRM_Import_Parser at line 155
array getImportableFieldsMetadata()

Get metadata for all importable fields in std getfields style format.

Return Value

array

in CRM_Import_Parser at line 163
setImportableFieldsMetadata(array $importableFieldsMetadata)

Set metadata for all importable fields in std getfields style format.

Parameters

array $importableFieldsMetadata

in CRM_Import_Parser at line 226
__construct()

Class constructor.

in CRM_Import_Parser at line 233
abstract protected init()

Abstract function definitions.

in CRM_Import_Parser at line 238
abstract protected mixed fini()

Return Value

mixed

in CRM_Import_Parser at line 247
abstract protected mixed mapField(array $values)

Map field.

Parameters

array $values

Return Value

mixed

in CRM_Import_Parser at line 256
abstract protected mixed preview(array $values)

Preview.

Parameters

array $values

Return Value

mixed

in CRM_Import_Parser at line 263
abstract protected mixed summary($values)

Parameters

$values

Return Value

mixed

in CRM_Import_Parser at line 271
abstract protected mixed import($onDuplicate, $values)

Parameters

$onDuplicate
$values

Return Value

mixed

in CRM_Import_Parser at line 283
int setActiveFieldValues(array $elements, $erroneousField)

Set and validate field values.

Parameters

array $elements array.
$erroneousField reference.

Return Value

int

at line 484
array getActiveFieldParams()

Format the field values for input to the api.

Return Value

array (reference) associative array of name/value pairs

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.

Parameters

$statusID status id of the import process saved in $config->uploadDir.
bool $startImport True when progress bar is to be initiated.
$startTimestamp Initial timstamp when the import was started.
$prevTimestamp Previous timestamp when this function was last called.
$totalRowCount Total number of rows in the import file.

Return Value

NULL|$currTimestamp

in CRM_Import_Parser at line 385
array getSelectValues()

Return Value

array

in CRM_Import_Parser at line 396
array getSelectTypes()

Return Value

array

in CRM_Import_Parser at line 409
array getHeaderPatterns()

Return Value

array

in CRM_Import_Parser at line 422
array getDataPatterns()

Return Value

array

in CRM_Import_Parser at line 438
static void encloseScrub(array $values, string $enclosure = "'")

Remove single-quote enclosures from a value array (row).

Parameters

array $values
string $enclosure

Return Value

void

in CRM_Import_Parser at line 455
void setMaxLinesToProcess(int $max)

Setter function.

Parameters

int $max

Return Value

void

in CRM_Import_Parser at line 465
static string errorFileName($type)

Determines the file extension based on error code.

Parameters

$type

Return Value

string

in CRM_Import_Parser at line 504
static string saveFileName($type)

Determines the file name based on error code.

Parameters

$type

Return Value

string

in CRM_Import_Parser at line 541
protected array checkContactDuplicate(array $formatValues)

Check if contact is a duplicate .

Parameters

array $formatValues

Return Value

array

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.

Parameters

string|int|null $submittedValue
array $fieldSpec Metadata for the field

Return Value

mixed

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.

Parameters

string $tableName
array $mapper
int $mode
int $contactType
string $primaryKeyName
string $statusFieldName
int $onDuplicate
int $statusID
int $totalRowCount
bool $doGeocodeAddress
int $timeout
string $contactSubType
int $dedupeRuleGroupID

Return Value

mixed

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

Parameters

array $fieldKeys Mapped array of values.

at line 370
setActiveFieldLocationTypes($elements)

Parameters

$elements

at line 383
setActiveFieldPhoneTypes($elements)

Parameters

$elements

at line 392
setActiveFieldWebsiteTypes($elements)

Parameters

$elements

at line 404
setActiveFieldImProviders(array $elements)

Set IM Service Provider type fields.

Parameters

array $elements IM service provider type ids.

at line 413
setActiveFieldRelated($elements)

Parameters

$elements

at line 422
setActiveFieldRelatedContactType($elements)

Parameters

$elements

at line 431
setActiveFieldRelatedContactDetails($elements)

Parameters

$elements

at line 440
setActiveFieldRelatedContactLocType($elements)

Parameters

$elements

at line 451
setActiveFieldRelatedContactPhoneType(array $elements)

Set active field for related contact's phone type.

Parameters

array $elements

at line 460
setActiveFieldRelatedContactWebsiteType($elements)

Parameters

$elements

at line 472
setActiveFieldRelatedContactImProvider(array $elements)

Set IM Service Provider type fields for related contacts.

Parameters

array $elements IM service provider type ids of related contact.

at line 580
array getColumnPatterns()

Return Value

array

at line 597
addField(string $name, $title, int $type = CRM_Utils_Type::T_INT, string $headerPattern = '//', string $dataPattern = '//', bool $hasLocationType = FALSE)

Parameters

string $name
$title
int $type
string $headerPattern
string $dataPattern
bool $hasLocationType

at line 615
set(CRM_Core_Session $store, int $mode = self::MODE_SUMMARY)

Store parser values.

Parameters

CRM_Core_Session $store
int $mode

at line 675
static exportCSV(string $fileName, array $header, array $data)

Export data to a CSV file.

Parameters

string $fileName
array $header
array $data

at line 720
updateImportRecord(int $id, array $params)

Update the record with PK $id in the import database table.

Parameters

int $id
array $params

at line 754
formatCommonData(array $params, array $formatted, array $contactFields)

Format common params data to proper format to store.

Parameters

array $params Contain record values.
array $formatted Array of formatted data.
array $contactFields Contact DAO fields.

at line 988
protected bool formatContactParameters(array $values, array $params)

Format contact parameters.

Parameters

array $values
array $params

Return Value

bool

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.

Parameters

array $values
array $params

Return Value

bool

at line 1324
protected array getMetadataForEntity(string $entity)

Get the field metadata for the relevant entity.

Parameters

string $entity

Return Value

array

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.

Parameters

array $params Address block parameters
array $values Input values
string $entity
  • address, email, phone
int|null $contactID

Exceptions

CiviCRM_API3_Exception