if (empty($id)) {
CRM_Core_Error::fatal();
}
-
- CRM_Utils_Hook::pre('delete', 'MailingAB', $id, CRM_Core_DAO::$_nullArray);
-
- $dao = new CRM_Mailing_DAO_MailingAB();
- $dao->id = $id;
- $dao->delete();
-
- CRM_Core_Session::setStatus(ts('Selected mailing has been deleted.'), ts('Deleted'), 'success');
-
- CRM_Utils_Hook::post('delete', 'MailingAB', $id, $dao);
+ CRM_Core_Transaction::create()->run(function() use ($id) {
+ CRM_Utils_Hook::pre('delete', 'MailingAB', $id, CRM_Core_DAO::$_nullArray);
+
+ $dao = new CRM_Mailing_DAO_MailingAB();
+ $dao->id = $id;
+ if ($dao->find(TRUE)) {
+ $mailing_ids = array($dao->mailing_id_a, $dao->mailing_id_b, $dao->mailing_id_c);
+ $dao->delete();
+ foreach ($mailing_ids as $mailing_id) {
+ if ($mailing_id) {
+ CRM_Mailing_BAO_Mailing::del($mailing_id);
+ }
+ }
+ }
+
+ CRM_Core_Session::setStatus(ts('Selected mailing has been deleted.'), ts('Deleted'), 'success');
+
+ CRM_Utils_Hook::post('delete', 'MailingAB', $id, $dao);
+ });
}
}
function setUp() {
parent::setUp();
+ $this->useTransaction(TRUE);
$this->_mailingID_A = $this->createMailing();
$this->_mailingID_B = $this->createMailing();
$this->_mailingID_C = $this->createMailing();
);
}
- function tearDown() {
- $this->deleteMailing($this->_mailingID_A);
- $this->deleteMailing($this->_mailingID_B);
- $this->deleteMailing($this->_mailingID_C);
- $this->groupDelete($this->_groupID);
- }
-
/**
* Test civicrm_mailing_create
*/
*/
public function testMailerDeleteSuccess() {
$result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
+
+ $this->assertDBQuery(1, "SELECT count(*) FROM civicrm_mailing_abtesting WHERE id = %1", array(
+ 1 => array($result['id'], 'Integer'),
+ ));
+ $this->assertDBQuery(3, "SELECT count(*) FROM civicrm_mailing WHERE id IN (%1,%2,%3)", array(
+ 1 => array($this->_mailingID_A, 'Integer'),
+ 2 => array($this->_mailingID_B, 'Integer'),
+ 3 => array($this->_mailingID_C, 'Integer'),
+ ));
+
$this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id']));
+
+ $this->assertDBQuery(0, "SELECT count(*) FROM civicrm_mailing_abtesting WHERE id = %1", array(
+ 1 => array($result['id'], 'Integer'),
+ ));
+ $this->assertDBQuery(0, "SELECT count(*) FROM civicrm_mailing WHERE id IN (%1,%2,%3)", array(
+ 1 => array($this->_mailingID_A, 'Integer'),
+ 2 => array($this->_mailingID_B, 'Integer'),
+ 3 => array($this->_mailingID_C, 'Integer'),
+ ));
}
public function testMailingABRecipientsUpdate() {