Skip to content
Snippets Groups Projects
Commit 7541b9e8 authored by eileen's avatar eileen
Browse files

#2308 do not require fields if activity_id is present

Note this is only one place they are required & it will still fail later with this merged
parent 1ee41a64
Branches
Tags
No related merge requests found
......@@ -132,9 +132,21 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser {
$this->setActiveFieldValues($values);
try {
// Check required fields if this is not an update.
if (!$this->getFieldValue($values, 'activity_id')) {
if (!$this->getFieldValue($values, 'activity_label')
&& !$this->getFieldValue($values, 'activity_type_id')) {
throw new CRM_Core_Exception(ts('Missing required fields: Activity type label or Activity type ID'));
}
if (!$this->getFieldValue($values, 'activity_date_time')) {
throw new CRM_Core_Exception(ts('Missing required fields'));
}
}
$this->validateActivityTypeIDAndLabel($values);
if (!$this->getFieldValue($values, 'activity_date_time')) {
throw new CRM_Core_Exception(ts('Missing required fields'));
if ($this->getFieldValue($values, 'activity_date_time')
&& !$this->isValidDate($this->getFieldValue($values, 'activity_date_time'))) {
throw new CRM_Core_Exception(ts('Invalid Activity Date'));
}
}
catch (CRM_Core_Exception $e) {
......@@ -147,23 +159,11 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser {
// For date-Formats
$session = CRM_Core_Session::singleton();
$dateType = $session->get('dateTypes');
if (!isset($params['source_contact_id'])) {
$params['source_contact_id'] = $session->get('userID');
}
foreach ($params as $key => $val) {
if ($key === 'activity_date_time') {
if ($val) {
$dateValue = CRM_Utils_Date::formatDate($val, $dateType);
if ($dateValue) {
$params[$key] = $dateValue;
}
else {
CRM_Contact_Import_Parser_Contact::addToErrorMsg('Activity date', $errorMessage);
}
}
}
elseif ($key == 'activity_engagement_level' && $val &&
if ($key == 'activity_engagement_level' && $val &&
!CRM_Utils_Rule::positiveInteger($val)
) {
CRM_Contact_Import_Parser_Contact::addToErrorMsg('Activity Engagement Index', $errorMessage);
......@@ -457,9 +457,17 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser {
&& $activityLabel !== CRM_Core_PseudoConstant::getLabel('CRM_Activity_BAO_Activity', 'activity_type_id', $activityTypeID)) {
throw new CRM_Core_Exception(ts('Activity type label and Activity type ID are in conflict'));
}
if (!$activityLabel && !$activityTypeID) {
throw new CRM_Core_Exception(ts('Missing required fields: Activity type label or Activity type ID'));
}
}
/**
* Is the supplied date field valid based on selected date format.
*
* @param string $value
*
* @return bool
*/
protected function isValidDate(string $value): bool {
return (bool) CRM_Utils_Date::formatDate($value, CRM_Core_Session::singleton()->get('dateTypes'));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment