$addressCustomFields = CRM_Core_BAO_CustomField::getFields('Address');
$customFields = $customFields + $addressCustomFields;
- //format date first
- $session = CRM_Core_Session::singleton();
- $dateType = $session->get("dateTypes");
foreach ($params as $key => $val) {
$customFieldID = CRM_Core_BAO_CustomField::getKeyID($key);
if ($customFieldID &&
!array_key_exists($customFieldID, $addressCustomFields)
) {
- //we should not update Date to null, CRM-4062
- if ($val && ($customFields[$customFieldID]['data_type'] == 'Date')) {
- //CRM-21267
- $this->formatCustomDate($params, $formatted, $dateType, $key);
- }
- elseif ($customFields[$customFieldID]['data_type'] == 'Boolean') {
+ if ($customFields[$customFieldID]['data_type'] == 'Boolean') {
if (empty($val) && !is_numeric($val) && $this->isFillDuplicates()) {
//retain earlier value when Import mode is `Fill`
unset($params[$key]);
$this->getDataSourceObject()->updateStatus($id, $status, $message, $entityID, $additionalFields);
}
- /**
- * Convert any given date string to default date array.
- *
- * @param array $params
- * Has given date-format.
- * @param array $formatted
- * Store formatted date in this array.
- * @param int $dateType
- * Type of date.
- * @param string $dateParam
- * Index of params.
- *
- * @deprecated
- */
- public static function formatCustomDate(&$params, &$formatted, $dateType, $dateParam) {
- //fix for CRM-2687
- CRM_Utils_Date::convertToDefaultDate($params, $dateType, $dateParam);
- $formatted[$dateParam] = CRM_Utils_Date::processDate($params[$dateParam]);
- }
-
/**
* Get the value to use for option comparison purposes.
*
* @throws \CRM_Core_Exception
*/
public function testValidateDateData(string $csv, int $dateType): void {
- $addressCustomGroupID = $this->createCustomGroup(['extends' => 'Address', 'name' => 'Address']);
- $contactCustomGroupID = $this->createCustomGroup(['extends' => 'Contact', 'name' => 'Contact']);
- $addressCustomFieldID = $this->createDateCustomField(['custom_group_id' => $addressCustomGroupID])['id'];
- $contactCustomFieldID = $this->createDateCustomField(['custom_group_id' => $contactCustomGroupID])['id'];
+ $this->createCustomGroupWithFieldOfType(['extends' => 'Address', 'name' => 'Address'], 'date', 'address_');
+ $this->createCustomGroupWithFieldOfType(['extends' => 'Contact', 'name' => 'Contact'], 'date', 'contact_');
$mapper = [
['first_name'],
['last_name'],
['birth_date'],
['deceased_date'],
- ['custom_' . $contactCustomFieldID],
- ['custom_' . $addressCustomFieldID, 1],
+ [$this->getCustomFieldName('contact_date')],
+ [$this->getCustomFieldName('address_date'), 1],
['street_address', 1],
['do_not_import'],
+ ['do_not_import'],
];
- // Date types should be picked up from submitted values but still some clean up to do.
- CRM_Core_Session::singleton()->set('dateTypes', $dateType);
$this->validateMultiRowCsv($csv, $mapper, 'custom_date_one', ['dateFormats' => $dateType]);
+ $this->importCSV($csv, $mapper);
$fields = [
'contact_id.birth_date',
'contact_id.deceased_date',
'contact_id.is_deceased',
- 'contact_id.custom_' . $contactCustomFieldID,
- $addressCustomFieldID,
+ 'contact_id.' . $this->getCustomFieldName('contact_date', 4),
+ $this->getCustomFieldName('address_date', 4),
];
$contacts = Address::get()->addWhere('contact_id.first_name', '=', 'Joe')->setSelect($fields)->execute();
foreach ($contacts as $contact) {
foreach ($fields as $field) {
- if ($field === 'contact_is_deceased') {
+ if ($field === 'contact_id.is_deceased') {
$this->assertTrue($contact[$field]);
}
else {
- $this->assertEquals('2008-09-01', $contact[$field]);
+ $this->assertEquals('2008-09-01', substr($contact[$field], 0, 10), $field);
}
}
}