public static function del($params) {
//delete from contribution soft table
$contributionSoft = new CRM_Contribute_DAO_ContributionSoft();
+ $contributionSoft->id = $params['id'];
+ if (!$contributionSoft->find()) {
+ return FALSE;
+ }
+ unset($params['id']);
foreach ($params as $column => $value) {
$contributionSoft->$column = $value;
}
$contributionSoft->delete();
+ return TRUE;
}
/**
public static function deleteDashlet($dashletID) {
$dashlet = new CRM_Core_DAO_Dashboard();
$dashlet->id = $dashletID;
+ if (!$dashlet->find(TRUE)) {
+ return FALSE;
+ }
$dashlet->delete();
return TRUE;
}
public static function del($optionValueId) {
$optionValue = new CRM_Core_DAO_OptionValue();
$optionValue->id = $optionValueId;
+ if (!$optionValue->find()) {
+ return FALSE;
+ }
if (self::updateRecords($optionValueId, CRM_Core_Action::DELETE)) {
CRM_Core_PseudoConstant::flush();
- return $optionValue->delete();
+ $optionValue->delete();
+ return TRUE;
}
return FALSE;
}
'version' => 3,
'id' => $dao->entity_id,
);
- $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);
+ }
- CRM_Core_DAO::executeQuery('DELETE FROM civicrm_managed WHERE id = %1', array(
- 1 => array($dao->id, 'Integer'),
- ));
+ CRM_Core_DAO::executeQuery('DELETE FROM civicrm_managed WHERE id = %1', array(
+ 1 => array($dao->id, 'Integer'),
+ ));
+ }
}
}
* @return \CRM_Event_DAO_Participant
*/
public static function deleteParticipant($id) {
+ $participant = new CRM_Event_DAO_Participant();
+ $participant->id = $id;
+ if (!$participant->find()) {
+ return FALSE;
+ }
CRM_Utils_Hook::pre('delete', 'Participant', $id, CRM_Core_DAO::$_nullArray);
$transaction = new CRM_Core_Transaction();
CRM_Core_BAO_Note::del($noteId, FALSE);
}
- $participant = new CRM_Event_DAO_Participant();
- $participant->id = $id;
$participant->delete();
$transaction->commit();
$dao = new CRM_Event_DAO_ParticipantStatusType();
$dao->id = $id;
- $dao->find(TRUE);
+ if (!$dao->find()) {
+ return FALSE;
+ }
$dao->delete();
return TRUE;
}
//delete from membership Type table
$membershipStatus = new CRM_Member_DAO_MembershipStatus();
$membershipStatus->id = $membershipStatusId;
+ if (!$membershipStatus->find()) {
+ throw new CRM_Core_Exception(ts('Cannot delete membership status ' . $membershipStatusId));
+ }
$membershipStatus->delete();
CRM_Member_PseudoConstant::flush('membershipStatus');
$membershipStatus->free();
* @deprecated use OptionValue api
*/
function civicrm_api3_activity_type_delete($params) {
- return civicrm_api3_create_success(CRM_Core_BAO_OptionValue::del($params['id']), $params);
+ $result = CRM_Core_BAO_OptionValue::del($params['id']);
+ if ($result) {
+ return civicrm_api3_create_success(TRUE, $params);
+ }
+ throw new API_Exception("Failure to delete activity type id {$params['id']}");
}
*/
function civicrm_api3_contribution_soft_delete($params) {
// Non standard BAO - we have to write custom code to cope.
- CRM_Contribute_BAO_ContributionSoft::del(array('id' => $params['id']));
-
+ $result = CRM_Contribute_BAO_ContributionSoft::del(array('id' => $params['id']));
+ if (!$result) {
+ throw new API_Exception('Cannot delete contributionSoft ' . $params['id']);
+ }
+ civicrm_api3_create_success(TRUE);
}
/**
return civicrm_api3_create_success(1, $params, 'Dashboard', 'delete');
}
else {
- return civicrm_api3_create_error('Could not delete dashlet');
+ throw new API_Exception('Could not delete dashlet');
}
}
* API result array
*/
function civicrm_api3_group_delete($params) {
-
+ $group = civicrm_api3_group_get(array('id' => $params['id']));
+ if ($group['count'] == 0) {
+ throw new API_Exception('Could not delete group ' . $params['id']);
+ }
CRM_Contact_BAO_Group::discard($params['id']);
return civicrm_api3_create_success(TRUE);
}
* @deprecated
*/
function civicrm_api3_group_contact_delete($params) {
+ $groupContact = civicrm_api3('GroupContact', 'get', $params);
+ if ($groupContact['count'] == 0) {
+ throw new API_Exception('Cannot Delete GroupContact');
+ }
$params['status'] = CRM_Utils_Array::value('status', $params, empty($params['skip_undelete']) ? 'Removed' : 'Deleted');
// "Deleted" isn't a real option so skip the api wrapper to avoid pseudoconstant validation
return civicrm_api3_group_contact_create($params);
function civicrm_api3_membership_status_delete($params) {
$memberStatusDelete = CRM_Member_BAO_MembershipStatus::del($params['id'], TRUE);
- return $memberStatusDelete ? civicrm_api3_create_error($memberStatusDelete['error_message']) : civicrm_api3_create_success();
+ if ($memberStatusDelete) {
+ throw new API_Exception($memberStatusDelete['error_message']);
+ }
+ return civicrm_api3_create_success();
}
/**
function civicrm_api3_option_value_delete($params) {
// We will get the option group id before deleting so we can flush pseudoconstants.
$optionGroupID = civicrm_api('option_value', 'getvalue', array('version' => 3, 'id' => $params['id'], 'return' => 'option_group_id'));
- if (CRM_Core_BAO_OptionValue::del((int) $params['id'])) {
+ $result = CRM_Core_BAO_OptionValue::del($params['id']);
+ if ($result) {
civicrm_api('option_value', 'getfields', array('version' => 3, 'cache_clear' => 1, 'option_group_id' => $optionGroupID));
return civicrm_api3_create_success();
}
else {
- civicrm_api3_create_error('Could not delete OptionValue ' . $params['id']);
+ throw new API_Exception('Could not delete OptionValue ' . $params['id']);
}
}
return civicrm_api3_create_success(TRUE);
}
- return civicrm_api3_create_error(TRUE);
+ throw new API_Exception('Could not delete participant status type id ' . $params['id']);
}
* @return array
*/
function civicrm_api3_system_log_delete($params) {
- return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'SystemLog');
+ return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
/**
_civicrm_api3_check_edit_permissions($bao_name, array('id' => $params['id']));
$args = array(&$params['id']);
if (method_exists($bao_name, 'del')) {
- $bao = call_user_func_array(array($bao_name, 'del'), $args);
- if ($bao !== FALSE) {
- return civicrm_api3_create_success(TRUE);
+ $dao = new $bao_name();
+ $dao->id = $params['id'];
+ if ($dao->find()) {
+ $bao = call_user_func_array(array($bao_name, 'del'), $args);
+ if ($bao !== FALSE) {
+ return civicrm_api3_create_success();
+ }
+ throw new API_Exception('Could not delete entity id ' . $params['id']);
}
throw new API_Exception('Could not delete entity id ' . $params['id']);
}
if ($this->callAPISuccessGetCount('membership', array('id' => $this->_membershipTypeID))) {
$this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
}
- $this->membershipStatusDelete($this->_membershipStatusID);
+ if ($this->callAPISuccessGetCount('MembershipStatus', array('id' => $this->_membershipStatusID))) {
+ $this->membershipStatusDelete($this->_membershipStatusID);
+ }
$this->contactDelete($this->_contactID);
$this->contactDelete($this->_contactID2);
$this->contactDelete($this->_orgContactID);
*/
public function relationshipTypeDelete($relationshipTypeID) {
$params['id'] = $relationshipTypeID;
- $this->callAPISuccess('relationship_type', 'delete', $params);
+ $check = $this->callAPISuccess('relationship_type', 'get', $params);
+ if (!empty($check['count'])) {
+ $this->callAPISuccess('relationship_type', 'delete', $params);
+ }
}
/**
$params = array(
'id' => $participantID,
);
- return $this->callAPISuccess('Participant', 'delete', $params);
+ $check = $this->callAPISuccess('Participant', 'get', $params);
+ if ($check['count'] > 0) {
+ return $this->callAPISuccess('Participant', 'delete', $params);
+ }
}
/**
'civicrm_uf_match',
);
$this->quickCleanup($tablesToTruncate, TRUE);
- $this->callAPISuccess('option_value', 'delete', array('id' => $this->test_activity_type_id));
+ $type = $this->callAPISuccess('optionValue', 'get', array('id' => $this->test_activity_type_id));
+ if (!empty($type['count'])) {
+ $this->callAPISuccess('option_value', 'delete', array('id' => $this->test_activity_type_id));
+ }
}
/**
AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
$this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
-
- $result = $this->callAPISuccess('CustomSearch', 'delete', array(
- 'id' => $entityId,
- ));
+ $check = $this->callAPISuccess('CustomSearch', 'get', array('id' => $entityId));
+ if (!empty($check['count'])) {
+ $result = $this->callAPISuccess('CustomSearch', 'delete', array(
+ 'id' => $entityId,
+ ));
+ }
$this->assertEquals(1, $result['count']);
$this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value
WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
if (!empty($this->optionGroup)) {
foreach ($this->optionGroup as $type => $value) {
if (!empty($value['id'])) {
- $this->callAPISuccess('OptionGroup', 'delete', array('id' => $value['id']));
+ $count = $this->callAPISuccess('OptionGroup', 'get', array('id' => $value['id']));
+ if ((bool) $count['count']) {
+ $this->callAPISuccess('OptionGroup', 'delete', array('id' => $value['id']));
+ }
}
}
}
* @throws \PHPUnit_Framework_IncompleteTestError
*/
public function testInvalidID_delete($Entity) {
- // turn test off for now
- $this->markTestIncomplete("Entity [ $Entity ] cannot be mocked - no known DAO");
- return;
if (in_array($Entity, $this->toBeImplemented['delete'])) {
- // $this->markTestIncomplete("civicrm_api3_{$Entity}_delete to be implemented");
+ $this->markTestIncomplete("civicrm_api3_{$Entity}_delete to be implemented");
return;
}
$result = $this->callAPIFailure($Entity, 'Delete', array('id' => 999));