Skip to content

Commit

Permalink
Revert deprecated functions being removed in civicrm#25615, civicrm#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
jensschuppe committed Jun 6, 2024
1 parent 1dc2192 commit 3dd8183
Show file tree
Hide file tree
Showing 8 changed files with 352 additions and 0 deletions.
30 changes: 30 additions & 0 deletions CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,36 @@ public static function processImage() {
}
}

/**
* Function to set is_delete true or restore deleted contact.
*
* @param CRM_Contact_DAO_Contact $contact
* Contact DAO object.
* @param bool $restore
* True to set the is_delete = 1 else false to restore deleted contact,
* i.e. is_delete = 0
*
* @deprecated
*
* @return bool
* @throws \CRM_Core_Exception
*/
public static function contactTrashRestore($contact, $restore = FALSE) {
CRM_Core_Error::deprecatedFunctionWarning('Use the api');

if ($restore) {
CRM_Core_Error::deprecatedFunctionWarning('Use contact.create to restore - this does nothing much');
// @todo deprecate calling contactDelete with the intention to restore.
$updateParams = [
'id' => $contact->id,
'is_deleted' => FALSE,
];
self::create($updateParams);
return TRUE;
}
return self::contactTrash($contact);
}

/**
* Get contact type for a contact.
*
Expand Down
38 changes: 38 additions & 0 deletions CRM/Contact/BAO/Contact/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,44 @@ public static function getEmailDetails($id, $isPrimary = TRUE, $locationTypeID =
return $returnParams;
}

/**
* @deprecated Not used anywhere, use the Phone API instead
* Get the sms number and display name of a contact.
*
* @param int $id
* Id of the contact.
* @param string|null $type
*
* @return array
* tuple of display_name and sms if found, or (null,null)
*/
public static function getPhoneDetails($id, $type = NULL) {
CRM_Core_Error::deprecatedFunctionWarning('Phone.get API instead');
if (!$id) {
return [NULL, NULL];
}

$cond = NULL;
if ($type) {
$cond = " AND civicrm_phone.phone_type_id = '$type'";
}

$sql = "
SELECT civicrm_contact.display_name, civicrm_phone.phone, civicrm_contact.do_not_sms
FROM civicrm_contact
LEFT JOIN civicrm_phone ON ( civicrm_phone.contact_id = civicrm_contact.id )
WHERE civicrm_phone.is_primary = 1
$cond
AND civicrm_contact.id = %1";

$params = [1 => [$id, 'Integer']];
$dao = CRM_Core_DAO::executeQuery($sql, $params);
if ($dao->fetch()) {
return [$dao->display_name, $dao->phone, $dao->do_not_sms];
}
return [NULL, NULL, NULL];
}

/**
* Get the information to map a contact.
*
Expand Down
38 changes: 38 additions & 0 deletions CRM/Core/BAO/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,44 @@ public static function getValues($entityBlock, $microformat = FALSE): ?array {
];
}

/**
* Delete all the block associated with the location.
*
* Note a universe search on 1 Oct 2020 found no calls to this function.
*
* @deprecated
*
* @param int $contactId
* Contact id.
* @param int $locationTypeId
* Id of the location to delete.
* @throws CRM_Core_Exception
*/
public static function deleteLocationBlocks($contactId, $locationTypeId) {
CRM_Core_Error::deprecatedFunctionWarning('Use v4 api');
// ensure that contactId has a value
if (empty($contactId) ||
!CRM_Utils_Rule::positiveInteger($contactId)
) {
throw new CRM_Core_Exception('Incorrect contact id parameter passed to deleteLocationBlocks');
}

if (empty($locationTypeId) ||
!CRM_Utils_Rule::positiveInteger($locationTypeId)
) {
// so we only delete the blocks which DO NOT have a location type Id
// CRM-3581
$locationTypeId = 'null';
}

static $blocks = ['Address', 'Phone', 'IM', 'OpenID', 'Email'];

$params = ['contact_id' => $contactId, 'location_type_id' => $locationTypeId];
foreach ($blocks as $name) {
CRM_Core_BAO_Block::blockDelete($name, $params);
}
}

/**
* Make sure contact should have only one primary block, CRM-5051.
*
Expand Down
43 changes: 43 additions & 0 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,25 @@ public static function objectExists($value, $daoName, $daoID, $fieldName = 'name
}
}

/**
* Check if there is a given column in a specific table.
*
* @deprecated
* @see CRM_Core_BAO_SchemaHandler::checkIfFieldExists
*
* @param string $tableName
* @param string $columnName
* @param bool $i18nRewrite
* Whether to rewrite the query on multilingual setups.
*
* @return bool
* true if exists, else false
*/
public static function checkFieldExists($tableName, $columnName, $i18nRewrite = TRUE) {
CRM_Core_Error::deprecatedFunctionWarning('CRM_Core_BAO_SchemaHandler::checkIfFieldExists');
return CRM_Core_BAO_SchemaHandler::checkIfFieldExists($tableName, $columnName, $i18nRewrite);
}

/**
* Gets the names of all enabled schema tables.
*
Expand Down Expand Up @@ -2514,6 +2533,30 @@ public static function setCreateDefaults(&$params, $defaults) {
}
}

/**
* @param string $prefix
* @param bool $addRandomString
* @param null $string
*
* @return string
* @deprecated
* @see CRM_Utils_SQL_TempTable
*/
public static function createTempTableName($prefix = 'civicrm', $addRandomString = TRUE, $string = NULL) {
CRM_Core_Error::deprecatedFunctionWarning('Use CRM_Utils_SQL_TempTable interface to create temporary tables');
$tableName = $prefix . "_temp";

if ($addRandomString) {
if ($string) {
$tableName .= "_" . $string;
}
else {
$tableName .= "_" . md5(uniqid('', TRUE));
}
}
return $tableName;
}

/**
* @param bool $view
* @param bool $trigger
Expand Down
42 changes: 42 additions & 0 deletions CRM/Core/Form/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,48 @@ public static function buildAllowedDateFormats(&$form) {
$form->setDefaults(['dateFormats' => self::DATE_yyyy_mm_dd]);
}

/**
* Retrieve the date range - relative or absolute and assign it to the form.
*
* @deprecated
*
* @param CRM_Core_Form $form
* The form the dates should be added to.
* @param string $fieldName
* @param int $count
* @param string $from
* @param string $to
* @param string $fromLabel
* @param bool $required
* @param array $operators
* Additional value pairs to add.
* @param string $dateFormat
* @param bool|string $displayTime
* @param array $attributes
*/
public static function buildDateRange(
&$form, $fieldName, $count = 1,
$from = '_from', $to = '_to', $fromLabel = 'From:',
$required = FALSE, $operators = [],
$dateFormat = 'searchDate', $displayTime = FALSE,
$attributes = ['class' => 'crm-select2']
) {
CRM_Core_Error::deprecatedFunctionWarning('function will be removed');
$selector
= CRM_Core_Form_Date::returnDateRangeSelector(
$form, $fieldName, $count,
$from, $to, $fromLabel,
$required, $operators,
$dateFormat, $displayTime
);
CRM_Core_Form_Date::addDateRangeToForm(
$form, $fieldName, $selector,
$from, $to, $fromLabel,
$required, $dateFormat, $displayTime,
$attributes
);
}

/**
* Build the date range array that will provide the form option values.
*
Expand Down
88 changes: 88 additions & 0 deletions CRM/Core/OptionGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,94 @@ public static function lookupValues(&$params, $names, $flip = FALSE) {
}
}

/**
* @deprecated - use CRM_Core_PseudoConstant::getLabel
*
* @param string $groupName
* @param $value
* @param bool $onlyActiveValue
*
* @return null
*/
public static function getLabel($groupName, $value, $onlyActiveValue = TRUE) {
CRM_Core_Error::deprecatedFunctionWarning('CRM_Core_PseudoConstant::getLabel');
if (empty($groupName) ||
empty($value)
) {
return NULL;
}

$query = "
SELECT v.label as label ,v.value as value
FROM civicrm_option_value v,
civicrm_option_group g
WHERE v.option_group_id = g.id
AND g.name = %1
AND g.is_active = 1
AND v.value = %2
";
if ($onlyActiveValue) {
$query .= " AND v.is_active = 1 ";
}
$p = [
1 => [$groupName, 'String'],
2 => [$value, 'Integer'],
];
$dao = CRM_Core_DAO::executeQuery($query, $p);
if ($dao->fetch()) {
return $dao->label;
}
return NULL;
}

/**
* @deprecated
*
* This function is not cached.
*
* @param string $groupName
* @param $label
* @param string $labelField
* @param string $labelType
* @param string $valueField
*
* @return null
*/
public static function getValue(
$groupName,
$label,
$labelField = 'label',
$labelType = 'String',
$valueField = 'value'
) {
if (empty($label)) {
return NULL;
}

CRM_Core_Error::deprecatedFunctionWarning('CRM_Core_PseudoConstant::getKey');

$query = "
SELECT v.label as label ,v.{$valueField} as value
FROM civicrm_option_value v,
civicrm_option_group g
WHERE v.option_group_id = g.id
AND g.name = %1
AND v.is_active = 1
AND g.is_active = 1
AND v.$labelField = %2
";

$p = [
1 => [$groupName, 'String'],
2 => [$label, $labelType],
];
$dao = CRM_Core_DAO::executeQuery($query, $p);
if ($dao->fetch()) {
return $dao->value;
}
return NULL;
}

/**
* Get option_value.value from default option_value row for an option group
*
Expand Down
54 changes: 54 additions & 0 deletions api/v3/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,60 @@ function civicrm_api3_contribution_repeattransaction($params) {
);
}

/**
* Calls IPN complete transaction for completing or repeating a transaction.
*
* The IPN function is overloaded with two purposes - this is simply a wrapper for that
* when separating them in the api layer.
*
* @deprecated
*
* @param array $params
* @param CRM_Contribute_BAO_Contribution $contribution
* @param array $input
*
* @param array $ids
*
* @return mixed
* @throws \CRM_Core_Exception
*/
function _ipn_process_transaction($params, $contribution, $input, $ids) {
CRM_Core_Error::deprecatedFunctionWarning('API3 contribution.completetransaction or contribution.repeattransaction');
$objects = $contribution->_relatedObjects;
$objects['contribution'] = &$contribution;
$input['component'] = $contribution->_component;
$input['is_test'] = $contribution->is_test;
$input['amount'] = empty($input['total_amount']) ? $contribution->total_amount : $input['total_amount'];

if (isset($params['is_email_receipt'])) {
$input['is_email_receipt'] = $params['is_email_receipt'];
}
if (!empty($params['trxn_date'])) {
$input['trxn_date'] = $params['trxn_date'];
}
if (!empty($params['receive_date'])) {
$input['receive_date'] = $params['receive_date'];
}
if (empty($contribution->contribution_page_id)) {
static $domainFromName;
static $domainFromEmail;
if (empty($domainFromEmail) && (empty($params['receipt_from_name']) || empty($params['receipt_from_email']))) {
[$domainFromName, $domainFromEmail] = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
}
$input['receipt_from_name'] = CRM_Utils_Array::value('receipt_from_name', $params, $domainFromName);
$input['receipt_from_email'] = CRM_Utils_Array::value('receipt_from_email', $params, $domainFromEmail);
}
$input['card_type_id'] = $params['card_type_id'] ?? NULL;
$input['pan_truncation'] = $params['pan_truncation'] ?? NULL;
if (!empty($params['payment_instrument_id'])) {
$input['payment_instrument_id'] = $params['payment_instrument_id'];
}
return CRM_Contribute_BAO_Contribution::completeOrder($input,
!empty($objects['contributionRecur']) ? $objects['contributionRecur']->id : NULL,
$objects['contribution']->id ?? NULL,
$params['is_post_payment_create'] ?? NULL);
}

/**
* Provide function metadata.
*
Expand Down
Loading

0 comments on commit 3dd8183

Please sign in to comment.