From: Mathieu Lutfy Date: Mon, 24 Jun 2019 14:21:42 +0000 (-0400) Subject: Activity formRule status check cleanup X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f47754ac7e9424af1feb5ccdbf2df9c7256ecf60;p=civicrm-core.git Activity formRule status check cleanup Under some circumstances, the activity_type_id from fields and from the getKey call can both return NULL, causing the formRule to raise an error that one cannot record a scheduled SMS activity. --- diff --git a/CRM/Activity/Form/Activity.php b/CRM/Activity/Form/Activity.php index d1ccc1bfb9..c89b52f6c3 100644 --- a/CRM/Activity/Form/Activity.php +++ b/CRM/Activity/Form/Activity.php @@ -865,13 +865,17 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $errors['activity_type_id'] = ts('Activity Type is a required field'); } - if (CRM_Utils_Array::value('activity_type_id', $fields) == CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Email') - && CRM_Utils_Array::value('status_id', $fields) == CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Scheduled')) { - $errors['status_id'] = ts('You cannot record scheduled email activity.'); - } - elseif (CRM_Utils_Array::value('activity_type_id', $fields) == CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'SMS') - && CRM_Utils_Array::value('status_id', $fields) == CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Scheduled')) { - $errors['status_id'] = ts('You cannot record scheduled SMS activity.'); + $activity_type_id = CRM_Utils_Array::value('activity_type_id', $fields); + $activity_status_id = CRM_Utils_Array::value('status_id', $fields); + $scheduled_status_id = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Scheduled'); + + if ($activity_type_id && $activity_status_id == $scheduled_status_id) { + if ($activity_type_id == CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Email')) { + $errors['status_id'] = ts('You cannot record scheduled email activity.'); + } + elseif ($activity_type_id == CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'SMS')) { + $errors['status_id'] = ts('You cannot record scheduled SMS activity'); + } } if (!empty($fields['followup_activity_type_id']) && empty($fields['followup_date'])) {