Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIv3 - Use new DAO::deleteRecord method #16869

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions api/v3/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ function _civicrm_api3_basic_create_fallback($bao_name, $params) {
*
* When the api is only doing a $bao::del then use this if api::del doesn't exist it will try DAO delete method.
*
* @param string $bao_name
* @param string|CRM_Core_DAO $bao_name
* @param array $params
*
* @return array
Expand All @@ -1355,8 +1355,8 @@ function _civicrm_api3_basic_create_fallback($bao_name, $params) {
function _civicrm_api3_basic_delete($bao_name, &$params) {
civicrm_api3_verify_mandatory($params, NULL, ['id']);
_civicrm_api3_check_edit_permissions($bao_name, ['id' => $params['id']]);
$args = [&$params['id']];
if (method_exists($bao_name, 'del')) {
$args = [&$params['id']];
$dao = new $bao_name();
$dao->id = $params['id'];
if ($dao->find()) {
Expand All @@ -1368,21 +1368,10 @@ function _civicrm_api3_basic_delete($bao_name, &$params) {
}
throw new API_Exception('Could not delete entity id ' . $params['id']);
}
elseif (method_exists($bao_name, 'delete')) {
$dao = new $bao_name();
$dao->id = $params['id'];
if ($dao->find()) {
while ($dao->fetch()) {
$dao->delete();
return civicrm_api3_create_success();
}
}
else {
throw new API_Exception('Could not delete entity id ' . $params['id']);
}
else {
$bao_name::deleteRecord($params);
return civicrm_api3_create_success();
}

throw new API_Exception('no delete method found');
}

/**
Expand Down