You are here

public function SimplenewsNewsletterController::delete in Simplenews 7.2

Overrides EntityAPIController::delete().

Make sure that all subscriptions of the newsletter are deleted.

Overrides EntityAPIController::delete

File

includes/simplenews.controller.inc, line 42
Seimplenews entity controllers definitions.

Class

SimplenewsNewsletterController
Controller for simplenews_newsletter entity.

Code

public function delete($ids, DatabaseTransaction $transaction = NULL) {
  $names = array();
  foreach (simplenews_newsletter_load_multiple($ids) as $newsletter) {
    $names[$newsletter->newsletter_id] = $newsletter->name;
  }
  parent::delete($ids, $transaction);
  foreach ($ids as $id) {

    // Delete subscriptions.
    simplenews_subscription_delete(array(
      'newsletter_id' => $id,
    ));
    drupal_set_message(t('All subscriptions to newsletter %newsletter have been deleted.', array(
      '%newsletter' => $names[$id],
    )));

    // Delete subscription block.
    db_delete('block')
      ->condition('module', 'simplenews')
      ->condition('delta', $id)
      ->execute();
  }
}