$check = civicrm_api3($dao->entity_type, 'get', $params);
if ((bool) $check['count']) {
$result = civicrm_api($dao->entity_type, 'delete', $params);
if ($result['is_error']) {
$this->onApiError($dao->entity_type, 'delete', $params, $result);
}
$check = civicrm_api3($dao->entity_type, 'get', $params);
if ((bool) $check['count']) {
$result = civicrm_api($dao->entity_type, 'delete', $params);
if ($result['is_error']) {
$this->onApiError($dao->entity_type, 'delete', $params, $result);
}