* @param array $params
* Input parameters.
*
- * @throws API_Exception
- *
* @return array
* API Result Array
+ *
+ * @throws \CiviCRM_API3_Exception
+ * @throws API_Exception
+ * @throws \CRM_Core_Exception
*/
function civicrm_api3_contact_create($params) {
$contactID = CRM_Utils_Array::value('contact_id', $params, CRM_Utils_Array::value('id', $params));
* API Result Array
*
* @throws \API_Exception
+ * @throws \CiviCRM_API3_Exception
*/
function civicrm_api3_contact_get($params) {
$options = [];
* @param array $params
*
* @return int
+ * @throws \API_Exception
*/
function civicrm_api3_contact_getcount($params) {
$options = [];
* @param array $params
* input parameters per getfields
*
- * @throws \Civi\API\Exception\UnauthorizedException
* @return array
* API Result Array
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ * @throws \Civi\API\Exception\UnauthorizedException
*/
function civicrm_api3_contact_delete($params) {
- $contactID = CRM_Utils_Array::value('id', $params);
+ $contactID = (int) $params['id'];
if (!empty($params['check_permissions']) && !CRM_Contact_BAO_Contact_Permission::allow($contactID, CRM_Core_Permission::DELETE)) {
throw new \Civi\API\Exception\UnauthorizedException('Permission denied to modify contact record');
}
- $session = CRM_Core_Session::singleton();
- if ($contactID == $session->get('userID')) {
- return civicrm_api3_create_error('This contact record is linked to the currently logged in user account - and cannot be deleted.');
+ if ($contactID == CRM_Core_Session::getLoggedInContactID()) {
+ throw new API_Exception('This contact record is linked to the currently logged in user account - and cannot be deleted.');
}
$restore = !empty($params['restore']);
$skipUndelete = !empty($params['skip_undelete']);
// restrict permanent delete if a contact has financial trxn associated with it
$error = NULL;
if ($skipUndelete && CRM_Financial_BAO_FinancialItem::checkContactPresent([$contactID], $error)) {
- return civicrm_api3_create_error($error['_qf_default']);
+ throw new API_Exception($error['_qf_default']);
}
if (CRM_Contact_BAO_Contact::deleteContact($contactID, $restore, $skipUndelete,
CRM_Utils_Array::value('check_permissions', $params))) {
return civicrm_api3_create_success();
}
- else {
- return civicrm_api3_create_error('Could not delete contact');
- }
+ throw new CiviCRM_API3_Exception('Could not delete contact');
}
/**
* If present the contact with that ID is updated.
*
* @return CRM_Contact_BAO_Contact|CRM_Core_Error
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ * @throws \Civi\API\Exception\UnauthorizedException
*/
function _civicrm_api3_contact_update($params, $contactID = NULL) {
//@todo - doesn't contact create support 'id' which is already set- check & remove
* Array per getfields metadata.
*
* @throws API_Exception
+ * @throws \CRM_Core_Exception
*/
function _civicrm_api3_greeting_format_params($params) {
$greetingParams = ['', '_id', '_custom'];
// If we are doing quicksearch by a field other than name, make sure that field is added to results
if (!empty($params['field_name'])) {
$field_name = CRM_Utils_String::munge($params['field_name']);
+ // there is no good reason to request api_key via getquick
+ if ($field_name == 'api_key') {
+ throw new API_Exception('Illegal value "api_key" for parameter "field_name"');
+ }
// Unique name contact_id = id
if ($field_name == 'contact_id') {
$field_name = 'id';
// Contact's based of relationhip type
$relType = NULL;
if (!empty($params['rel'])) {
- $relation = explode('_', CRM_Utils_Array::value('rel', $params));
+ $relation = explode('_', $params['rel']);
$relType = CRM_Utils_Type::escape($relation[0], 'Integer');
$rel = CRM_Utils_Type::escape($relation[2], 'String');
}
while ($dao->fetch()) {
$t = ['id' => $dao->id];
foreach ($as as $k) {
- $t[$k] = isset($dao->$k) ? $dao->$k : '';
+ $t[$k] = $dao->$k ?? '';
}
$t['data'] = $dao->data;
// Replace keys with values when displaying fields from an option list
*
* @return array
* API Result Array
+ *
* @throws API_Exception
+ * @throws \CiviCRM_API3_Exception
+ * @throws \CRM_Core_Exception
*/
function civicrm_api3_contact_merge($params) {
if (($result = CRM_Dedupe_Merger::merge(
*
* @return array
* API Result Array
- * @throws API_Exception
+ *
+ * @throws \CiviCRM_API3_Exception
*/
function civicrm_api3_contact_getmergedto($params) {
$contactID = _civicrm_api3_contact_getmergedto($params);
* @param array $params
*
* @return int|false
+ *
+ * @throws \CiviCRM_API3_Exception
*/
function _civicrm_api3_contact_getmergedto($params) {
$contactID = FALSE;
*
* @return array
* API Result Array
- * @throws API_Exception
+ *
+ * @throws \CiviCRM_API3_Exception
*/
function civicrm_api3_contact_getmergedfrom($params) {
$contacts = _civicrm_api3_contact_getmergedfrom($params);
* @param array $params
*
* @return array
+ *
+ * @throws \CiviCRM_API3_Exception
*/
function _civicrm_api3_contact_getmergedfrom($params) {
$activities = [];
!CRM_Utils_Rule::numeric($longitude) ||
!CRM_Utils_Rule::numeric($distance)
) {
- throw new Exception(ts('Latitude, Longitude and Distance should exist and be numeric'));
+ throw new API_Exception(ts('Latitude, Longitude and Distance should exist and be numeric'));
}
- if ($unit == "mile") {
+ if ($unit === 'mile') {
$conversionFactor = 1609.344;
}
else {
// If we are doing quicksearch by a field other than name, make sure that field is added to results
$field_name = CRM_Utils_String::munge($request['search_field']);
// Unique name contact_id = id
- if ($field_name == 'contact_id') {
+ if ($field_name === 'contact_id') {
$field_name = 'id';
}
// phone_numeric should be phone
if (!empty($request['input'])) {
$request['params'][$request['search_field']] = $request['input'];
// Temporarily override wildcard setting
- if (Civi::settings()->get('includeWildCardInName') != $request['add_wildcard']) {
+ if (Civi::settings()->get('includeWildCardInName') !== $request['add_wildcard']) {
Civi::$statics['civicrm_api3_contact_getlist']['override_wildcard'] = !$request['add_wildcard'];
Civi::settings()->set('includeWildCardInName', $request['add_wildcard']);
}
$data['description'][] = implode(' ', $address);
}
if (!empty($request['image_field'])) {
- $data['image'] = isset($row[$request['image_field']]) ? $row[$request['image_field']] : '';
+ $data['image'] = $row[$request['image_field']] ?? '';
}
else {
$data['icon_class'] = $row['contact_type'];
*
* @return array
* API formatted array
+ *
+ * @throws \CiviCRM_API3_Exception
*/
function civicrm_api3_contact_duplicatecheck($params) {
$dupes = CRM_Contact_BAO_Contact::getDuplicateContacts(
/**
* Declare metadata for contact dedupe function.
*
- * @param $params
+ * @param array $params
*/
function _civicrm_api3_contact_duplicatecheck_spec(&$params) {
$params['dedupe_rule_id'] = [