Unverified Commit 31ecdc7e authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub

Merge pull request #16869 from colemanw/del

APIv3 - Use new DAO::deleteRecord method
parents 064037b6 a7d540f0
...@@ -1344,7 +1344,7 @@ function _civicrm_api3_basic_create_fallback($bao_name, $params) { ...@@ -1344,7 +1344,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. * 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 * @param array $params
* *
* @return array * @return array
...@@ -1357,8 +1357,8 @@ function _civicrm_api3_basic_create_fallback($bao_name, $params) { ...@@ -1357,8 +1357,8 @@ function _civicrm_api3_basic_create_fallback($bao_name, $params) {
function _civicrm_api3_basic_delete($bao_name, &$params) { function _civicrm_api3_basic_delete($bao_name, &$params) {
civicrm_api3_verify_mandatory($params, NULL, ['id']); civicrm_api3_verify_mandatory($params, NULL, ['id']);
_civicrm_api3_check_edit_permissions($bao_name, ['id' => $params['id']]); _civicrm_api3_check_edit_permissions($bao_name, ['id' => $params['id']]);
$args = [&$params['id']];
if (method_exists($bao_name, 'del')) { if (method_exists($bao_name, 'del')) {
$args = [&$params['id']];
$dao = new $bao_name(); $dao = new $bao_name();
$dao->id = $params['id']; $dao->id = $params['id'];
if ($dao->find()) { if ($dao->find()) {
...@@ -1370,21 +1370,10 @@ function _civicrm_api3_basic_delete($bao_name, &$params) { ...@@ -1370,21 +1370,10 @@ function _civicrm_api3_basic_delete($bao_name, &$params) {
} }
throw new API_Exception('Could not delete entity id ' . $params['id']); throw new API_Exception('Could not delete entity id ' . $params['id']);
} }
elseif (method_exists($bao_name, 'delete')) { else {
$dao = new $bao_name(); $bao_name::deleteRecord($params);
$dao->id = $params['id']; return civicrm_api3_create_success();
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']);
}
} }
throw new API_Exception('no delete method found');
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment