/** * Execute the action */ public function execute() { // get parameters $this->id = $this->getParameter('mailing_id', 'int'); // does the item exist if (BackendMailmotorModel::existsMailing($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // fetch the mailing $mailing = BackendMailmotorModel::getMailing($this->id); // get all data for the user we want to edit $records = (array) BackendMailmotorCMHelper::getCM()->getCampaignBounces($mailing['cm_id']); // reset some data if (!empty($records)) { // loop the records foreach ($records as $record) { // only remove the hard bounces if ($record['bounce_type'] == 'Hard') { // remove the address BackendMailmotorModel::deleteAddresses($record['email']); } } } // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete_bounces'); // user was deleted, so redirect $this->redirect(BackendModel::createURLForAction('statistics') . '&id=' . $mailing['id'] . '&report=deleted-bounces'); } else { $this->redirect(BackendModel::createURLForAction('statistics') . '&error=no-bounces'); } }
/** * Delete addresses */ private function deleteAddresses() { // no group set if ($this->groupId == '') { $this->groupId = null; } // get all groups $groupIds = BackendMailmotorModel::getGroupIDs(); // loop the emails foreach ($this->emails as $email) { // the group ID is not set if ($this->groupId == null) { // if no groups were set, break here if (empty($groupIds)) { break; } // loop the group IDs foreach ($groupIds as $groupId) { // try to unsubscribe this address try { BackendMailmotorCMHelper::unsubscribe($email, $groupId); } catch (Exception $e) { // do nothing } } // delete all addresses BackendMailmotorModel::deleteAddresses($email); } else { BackendMailmotorCMHelper::unsubscribe($email, $this->groupId); } } // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete_addresses'); // redirect $this->redirect(BackendModel::createURLForAction('addresses') . '&report=delete-addresses' . (!empty($this->groupId) ? '&group_id=' . $this->groupId : '')); }