Commit a7488080 authored by colemanw's avatar colemanw

CRM-14106 - Regex targeting the first part of if statements

Pattern used
if\s*\(\s*CRM_Utils_Array::value\s*\([ ]*(['"$0-9][^,]*),\s*(\$[^ )]*)\s*\)\s*(\&\&|\|\||\))
if \(!empty\($2\[$1\]\)$3
parent 0d8afee2
......@@ -180,7 +180,7 @@ ORDER BY entity_id
$dao->entity_id
);
}
elseif (CRM_Utils_Array::value($dao->object_table, $permissions)) {
elseif (!empty($permissions[$dao->object_table])) {
$acl[$dao->entity_id]['object_table'] .= ", {$permissions[$dao->object_table]}";
}
}
......
......@@ -64,7 +64,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
* @access public
*/
public static function dataExists(&$params) {
if (CRM_Utils_Array::value('source_contact_id', $params) ||
if (!empty($params['source_contact_id']) ||
CRM_Utils_Array::value('id', $params)
) {
return TRUE;
......@@ -157,7 +157,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
*/
public static function deleteActivity(&$params, $moveToTrash = FALSE) {
// CRM-9137
if (CRM_Utils_Array::value('id', $params) && !is_array($params['id'])) {
if (!empty($params['id']) && !is_array($params['id'])) {
CRM_Utils_Hook::pre('delete', 'Activity', $params['id'], $params);
}
else {
......@@ -294,7 +294,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
unset($params['id']);
}
if (!CRM_Utils_Array::value('status_id', $params) &&
if (empty($params['status_id']) &&
!CRM_Utils_Array::value('activity_status_id', $params) &&
!CRM_Utils_Array::value('id', $params)
) {
......@@ -325,7 +325,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
}
// CRM-9137
if (CRM_Utils_Array::value('id', $params)) {
if (!empty($params['id'])) {
CRM_Utils_Hook::pre('edit', 'Activity', $activity->id, $params);
}
else {
......@@ -373,7 +373,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
// attempt to save activity assignment
$resultAssignment = NULL;
if (CRM_Utils_Array::value('assignee_contact_id', $params)) {
if (!empty($params['assignee_contact_id'])) {
$assignmentParams = array('activity_id' => $activityId);
......@@ -399,7 +399,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
else {
$assignmentParams['contact_id'] = $params['assignee_contact_id'];
$assignmentParams['record_type_id'] = $assigneeID;
if (CRM_Utils_Array::value('id', $params)) {
if (!empty($params['id'])) {
$assignment = new CRM_Activity_BAO_ActivityContact();
$assignment->activity_id = $activityId;
$assignment->record_type_id = $assigneeID;
......@@ -428,7 +428,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
// attempt to save activity targets
$resultTarget = NULL;
if (CRM_Utils_Array::value('target_contact_id', $params)) {
if (!empty($params['target_contact_id'])) {
$targetParams = array('activity_id' => $activityId);
$resultTarget = array();
......@@ -455,7 +455,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
else {
$targetParams['contact_id'] = $params['target_contact_id'];
$targetParams['record_type_id'] = $targetID;
if (CRM_Utils_Array::value('id', $params)) {
if (!empty($params['id'])) {
$target = new CRM_Activity_BAO_ActivityContact();
$target->activity_id = $activityId;
$target->record_type_id = $targetID;
......@@ -479,7 +479,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
// write to changelog before transaction is committed/rolled
// back (and prepare status to display)
if (CRM_Utils_Array::value('id', $params)) {
if (!empty($params['id'])) {
$logMsg = "Activity (id: {$result->id} ) updated with ";
}
else {
......@@ -491,7 +491,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
$msgs[] = "source={$params['source_contact_id']}";
}
if (CRM_Utils_Array::value('target_contact_id', $params)) {
if (!empty($params['target_contact_id'])) {
if (is_array($params['target_contact_id']) && !CRM_Utils_array::crmIsEmptyArray($params['target_contact_id'])) {
$msgs[] = "target=" . implode(',', $params['target_contact_id']);
// take only first target
......@@ -522,16 +522,16 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
self::logActivityAction($result, $logMsg);
if (CRM_Utils_Array::value('custom', $params) &&
if (!empty($params['custom']) &&
is_array($params['custom'])
) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_activity', $result->id);
}
$transaction->commit();
if (!CRM_Utils_Array::value('skipRecentView', $params)) {
if (empty($params['skipRecentView'])) {
$recentOther = array();
if (CRM_Utils_Array::value('case_id', $params)) {
if (!empty($params['case_id'])) {
$caseContactID = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseContact', $params['case_id'], 'contact_id', 'case_id');
$url = CRM_Utils_System::url('civicrm/case/activity/view',
"reset=1&aid={$activity->id}&cid={$caseContactID}&caseID={$params['case_id']}&context=home"
......@@ -580,7 +580,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
}
$title = $title . $recentContactDisplay;
if (CRM_Utils_Array::value($activity->activity_type_id, $activityTypes)) {
if (!empty($activityTypes[$activity->activity_type_id])) {
$title .= ' (' . $activityTypes[$activity->activity_type_id] . ')';
}
......@@ -598,7 +598,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
// reset the group contact cache since smart groups might be affected due to this
CRM_Contact_BAO_GroupContactCache::remove();
if (CRM_Utils_Array::value('id', $params)) {
if (!empty($params['id'])) {
CRM_Utils_Hook::post('edit', 'Activity', $activity->id, $activity);
}
else {
......@@ -832,11 +832,11 @@ ORDER BY fixed_sort_order
$values[$activityID]['campaign'] = $allCampaigns[$dao->campaign_id];
}
if (!CRM_Utils_Array::value('assignee_contact_name', $values[$activityID])) {
if (empty($values[$activityID]['assignee_contact_name'])) {
$values[$activityID]['assignee_contact_name'] = array();
}
if (!CRM_Utils_Array::value('target_contact_name', $values[$activityID])) {
if (empty($values[$activityID]['target_contact_name'])) {
$values[$activityID]['target_contact_name'] = array();
}
......@@ -890,7 +890,7 @@ ORDER BY fixed_sort_order
$components = array();
$compInfo = CRM_Core_Component::getEnabledComponents();
foreach ($compInfo as $compObj) {
if (CRM_Utils_Array::value('showActivitiesInCore', $compObj->info)) {
if (!empty($compObj->info['showActivitiesInCore'])) {
if ($compObj->info['name'] == 'CiviCampaign') {
$componentPermission = "administer {$compObj->name}";
}
......@@ -1789,10 +1789,10 @@ SELECT display_name
$status = CRM_Event_PseudoConstant::participantStatus();
$subject = $event[$activity->event_id];
if (CRM_Utils_Array::value($activity->role_id, $roles)) {
if (!empty($roles[$activity->role_id])) {
$subject .= ' - ' . $roles[$activity->role_id];
}
if (CRM_Utils_Array::value($activity->status_id, $status)) {
if (!empty($status[$activity->status_id])) {
$subject .= ' - ' . $status[$activity->status_id];
}
$date = date('YmdHis');
......@@ -2026,7 +2026,7 @@ AND cl.modified_id = c.id
$followupParams['assignee_contact_id'] = CRM_Utils_Array::value('followup_assignee_contact_id', $params);
//create target contact for followup
if (CRM_Utils_Array::value('target_contact_id', $params)) {
if (!empty($params['target_contact_id'])) {
$followupParams['target_contact_id'] = $params['target_contact_id'];
}
......@@ -2437,7 +2437,7 @@ INNER JOIN civicrm_option_group grp ON ( grp.id = val.option_group_id AND grp.n
'civicrm/mailing/report/event',
"mid={$values['source_record_id']}&reset=1&event=queue&cid={$params['contact_id']}&context=activitySelector");
}
elseif (CRM_Utils_Array::value('recipients', $values)) {
elseif (!empty($values['recipients'])) {
$contactActivities[$activityId]['target_contact'] = $values['recipients'];
}
elseif (!$values['target_contact_name']) {
......@@ -2502,7 +2502,7 @@ INNER JOIN civicrm_option_group grp ON ( grp.id = val.option_group_id AND grp.n
// build links
$contactActivities[$activityId]['links'] = '';
$accessMailingReport = FALSE;
if (CRM_Utils_Array::value('mailingId', $values)) {
if (!empty($values['mailingId'])) {
$accessMailingReport = TRUE;
}
......
......@@ -42,13 +42,13 @@ class CRM_Activity_BAO_Query {
* @access public
*/
static function select(&$query) {
if (CRM_Utils_Array::value('activity_id', $query->_returnProperties)) {
if (!empty($query->_returnProperties['activity_id'])) {
$query->_select['activity_id'] = "civicrm_activity.id as activity_id";
$query->_element['activity_id'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}
if (CRM_Utils_Array::value('activity_type_id', $query->_returnProperties)) {
if (!empty($query->_returnProperties['activity_type_id'])) {
$query->_select['activity_type_id'] = "activity_type.id as activity_type_id";
$query->_element['activity_type_id'] = 1;
$query->_tables['civicrm_activity'] = 1;
......@@ -57,7 +57,7 @@ class CRM_Activity_BAO_Query {
$query->_whereTables['activity_type'] = 1;
}
if (CRM_Utils_Array::value('activity_type', $query->_returnProperties)) {
if (!empty($query->_returnProperties['activity_type'])) {
$query->_select['activity_type'] = "activity_type.label as activity_type";
$query->_element['activity_type'] = 1;
$query->_tables['civicrm_activity'] = 1;
......@@ -66,19 +66,19 @@ class CRM_Activity_BAO_Query {
$query->_whereTables['activity_type'] = 1;
}
if (CRM_Utils_Array::value('activity_subject', $query->_returnProperties)) {
if (!empty($query->_returnProperties['activity_subject'])) {
$query->_select['activity_subject'] = "civicrm_activity.subject as activity_subject";
$query->_element['activity_subject'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}
if (CRM_Utils_Array::value('activity_date_time', $query->_returnProperties)) {
if (!empty($query->_returnProperties['activity_date_time'])) {
$query->_select['activity_date_time'] = "civicrm_activity.activity_date_time as activity_date_time";
$query->_element['activity_date_time'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}
if (CRM_Utils_Array::value('activity_status_id', $query->_returnProperties)) {
if (!empty($query->_returnProperties['activity_status_id'])) {
$query->_select['activity_status_id'] = "activity_status.value as activity_status_id";
$query->_element['activity_status_id'] = 1;
$query->_tables['civicrm_activity'] = 1;
......@@ -87,7 +87,7 @@ class CRM_Activity_BAO_Query {
$query->_whereTables['activity_status'] = 1;
}
if (CRM_Utils_Array::value('activity_status', $query->_returnProperties)) {
if (!empty($query->_returnProperties['activity_status'])) {
$query->_select['activity_status'] = "activity_status.label as activity_status";
$query->_element['activity_status'] = 1;
$query->_tables['civicrm_activity'] = 1;
......@@ -96,55 +96,55 @@ class CRM_Activity_BAO_Query {
$query->_whereTables['activity_status'] = 1;
}
if (CRM_Utils_Array::value('activity_duration', $query->_returnProperties)) {
if (!empty($query->_returnProperties['activity_duration'])) {
$query->_select['activity_duration'] = "civicrm_activity.duration as activity_duration";
$query->_element['activity_duration'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}
if (CRM_Utils_Array::value('activity_location', $query->_returnProperties)) {
if (!empty($query->_returnProperties['activity_location'])) {
$query->_select['activity_location'] = "civicrm_activity.location as activity_location";
$query->_element['activity_location'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}
if (CRM_Utils_Array::value('activity_details', $query->_returnProperties)) {
if (!empty($query->_returnProperties['activity_details'])) {
$query->_select['activity_details'] = "civicrm_activity.details as activity_details";
$query->_element['activity_details'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}
if (CRM_Utils_Array::value('source_record_id', $query->_returnProperties)) {
if (!empty($query->_returnProperties['source_record_id'])) {
$query->_select['source_record_id'] = "civicrm_activity.source_record_id as source_record_id";
$query->_element['source_record_id'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}
if (CRM_Utils_Array::value('activity_is_test', $query->_returnProperties)) {
if (!empty($query->_returnProperties['activity_is_test'])) {
$query->_select['activity_is_test'] = "civicrm_activity.is_test as activity_is_test";
$query->_element['activity_is_test'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}
if (CRM_Utils_Array::value('activity_campaign_id', $query->_returnProperties)) {
if (!empty($query->_returnProperties['activity_campaign_id'])) {
$query->_select['activity_campaign_id'] = 'civicrm_activity.campaign_id as activity_campaign_id';
$query->_element['activity_campaign_id'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}
if (CRM_Utils_Array::value('activity_engagement_level', $query->_returnProperties)) {
if (!empty($query->_returnProperties['activity_engagement_level'])) {
$query->_select['activity_engagement_level'] = 'civicrm_activity.engagement_level as activity_engagement_level';
$query->_element['activity_engagement_level'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}
if (CRM_Utils_Array::value('source_contact', $query->_returnProperties)) {
if (!empty($query->_returnProperties['source_contact'])) {
$query->_select['source_contact'] = 'source_contact.sort_name as source_contact';
$query->_element['source_contact'] = 1;
$query->_tables['source_contact'] = $query->_whereTables['source_contact'] = 1;
}
if (CRM_Utils_Array::value('activity_result', $query->_returnProperties)) {
if (!empty($query->_returnProperties['activity_result'])) {
$query->_select['activity_result'] = 'civicrm_activity.result as activity_result';
$query->_element['result'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
......
......@@ -451,7 +451,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
}
// when custom data is included in this page
if (CRM_Utils_Array::value('hidden_custom', $_POST)) {
if (!empty($_POST['hidden_custom'])) {
// we need to set it in the session for the below code to work
// CRM-3014
//need to assign custom data subtype to the template
......@@ -540,7 +540,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
}
}
if (!CRM_Utils_Array::value('activity_date_time', $defaults)) {
if (empty($defaults['activity_date_time'])) {
list($defaults['activity_date_time'], $defaults['activity_date_time_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
}
elseif ($this->_action & CRM_Core_Action::UPDATE) {
......@@ -613,11 +613,11 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
$className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}";
$defaults += $className::setDefaultValues($this);
}
if (!CRM_Utils_Array::value('priority_id', $defaults)) {
if (empty($defaults['priority_id'])) {
$priority = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id');
$defaults['priority_id'] = array_search('Normal', $priority);
}
if (!CRM_Utils_Array::value('status_id', $defaults)) {
if (empty($defaults['status_id'])) {
$defaults['status_id'] = CRM_Core_OptionGroup::getDefaultValue('activity_status');
}
return $defaults;
......@@ -701,14 +701,14 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
}
foreach ($this->_fields as $field => $values) {
if (CRM_Utils_Array::value($field, $this->_fields)) {
if (!empty($this->_fields[$field])) {
$attribute = NULL;
if (CRM_Utils_Array::value('attributes', $values)) {
if (!empty($values['attributes'])) {
$attribute = $values['attributes'];
}
$required = FALSE;
if (CRM_Utils_Array::value('required', $values)) {
if (!empty($values['required'])) {
$required = TRUE;
}
if ($values['type'] == 'wysiwyg') {
......@@ -960,7 +960,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
$errors['status_id'] = ts('You cannot record scheduled SMS activity.');
}
if (CRM_Utils_Array::value('followup_activity_type_id', $fields) && !CRM_Utils_Array::value('followup_date', $fields)) {
if (!empty($fields['followup_activity_type_id']) && !CRM_Utils_Array::value('followup_date', $fields)) {
$errors['followup_date_time'] = ts('Followup date is a required field.');
}
//Activity type is mandatory if subject or follow-up date is specified for an Follow-up activity, CRM-4515
......@@ -1003,11 +1003,11 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
}
//set activity type id
if (!CRM_Utils_Array::value('activity_type_id', $params)) {
if (empty($params['activity_type_id'])) {
$params['activity_type_id'] = $this->_activityTypeId;
}
if (CRM_Utils_Array::value('hidden_custom', $params) &&
if (!empty($params['hidden_custom']) &&
!isset($params['custom'])
) {
$customFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE,
......@@ -1037,14 +1037,14 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
}
// assigning formated value to related variable
if (CRM_Utils_Array::value('assignee_contact_id', $params)) {
if (!empty($params['assignee_contact_id'])) {
$params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']);
}
else {
$params['assignee_contact_id'] = array();
}
// civicrm-10043 - 14/12/13
if ( CRM_Utils_Array::value( 'followup_assignee_contact_id', $params ) ) {
if (!empty($params['followup_assignee_contact_id'])) {
$params['followup_assignee_contact_id'] = explode( ',', $params['followup_assignee_contact_id'] );
}
else {
......@@ -1076,7 +1076,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
}
$activity = array();
if (CRM_Utils_Array::value('is_multi_activity', $params) &&
if (!empty($params['is_multi_activity']) &&
!CRM_Utils_Array::crmIsEmptyArray($params['target_contact_id'])
) {
$targetContacts = $params['target_contact_id'];
......@@ -1142,7 +1142,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
$this->endPostProcess($params, $activity);
// CRM-9590
if (CRM_Utils_Array::value('is_multi_activity', $params)) {
if (!empty($params['is_multi_activity'])) {
$this->_activityIds[] = $activity->id;
}
else {
......@@ -1152,7 +1152,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
// create follow up activity if needed
$followupStatus = '';
$followupActivity = NULL;
if (CRM_Utils_Array::value('followup_activity_type_id', $params)) {
if (!empty($params['followup_activity_type_id'])) {
$followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params);
$followupStatus = ts('A followup activity has been scheduled.');
}
......@@ -1219,7 +1219,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
// set status message
$subject = '';
if (CRM_Utils_Array::value('subject', $params)) {
if (!empty($params['subject'])) {
$subject = "'" . $params['subject'] . "'";
}
......
......@@ -78,7 +78,7 @@ class CRM_Activity_Form_ActivityView extends CRM_Core_Form {
$this->assign('activityTypeName', $activityTypeName);
$this->assign('activityTypeDescription', $activityTypeDescription);
if (CRM_Utils_Array::value('mailingId', $defaults)) {
if (!empty($defaults['mailingId'])) {
$this->_mailing_id = CRM_Utils_Array::value('source_record_id', $defaults);
$mailingReport = CRM_Mailing_BAO_Mailing::report($this->_mailing_id, TRUE);
CRM_Mailing_BAO_Mailing::getMailingContent($mailingReport, $this);
......
......@@ -101,12 +101,12 @@ class CRM_Activity_Form_Task_AddToTag extends CRM_Activity_Form_Task {
$activityTags = $tagList = array();
// check if contact tags exists
if (CRM_Utils_Array::value('tag', $params)) {
if (!empty($params['tag'])) {
$activityTags = $params['tag'];
}
// check if tags are selected from taglists
if (CRM_Utils_Array::value('activity_taglist', $params)) {
if (!empty($params['activity_taglist'])) {
foreach ($params['activity_taglist'] as $val) {
if ($val) {
if (is_numeric($val)) {
......
......@@ -162,12 +162,12 @@ class CRM_Activity_Form_Task_Batch extends CRM_Activity_Form_Task {
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
$customValue = CRM_Utils_Array::value($customFieldID, $customFields);
if (CRM_Utils_Array::value('extends_entity_column_value', $customValue)) {
if (!empty($customValue['extends_entity_column_value'])) {
$entityColumnValue = explode(CRM_Core_DAO::VALUE_SEPARATOR,
$customValue['extends_entity_column_value']
);
}
if (CRM_Utils_Array::value($typeId, $entityColumnValue) ||
if (!empty($entityColumnValue[$typeId]) ||
CRM_Utils_System::isNull($entityColumnValue[$typeId])
) {
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $activityId);
......@@ -236,23 +236,23 @@ class CRM_Activity_Form_Task_Batch extends CRM_Activity_Form_Task {
$value['activity_date_time'] = CRM_Utils_Date::processDate($value['activity_date_time'], $value['activity_date_time_time']);
}