You are here

function _simplenews_scheduler_send_new_edition in Simplenews Scheduler 2.0.x

Same name and namespace in other branches
  1. 8 simplenews_scheduler.module \_simplenews_scheduler_send_new_edition()
  2. 6.2 simplenews_scheduler.module \_simplenews_scheduler_send_new_edition()
  3. 7 simplenews_scheduler.module \_simplenews_scheduler_send_new_edition()

Helper for hook_cron() to send a new edition.

Parameters

$edition_time: The time of the operation. Usually the current time unless testing.

$newsletter_parent_data: A row of data from {simplenews_scheduler}, as returned by simplenews_scheduler_get_newsletters_due().

$eid: The node id of the new edition to send. This should already have been created by _simplenews_scheduler_new_edition().

1 call to _simplenews_scheduler_send_new_edition()
simplenews_scheduler_cron in ./simplenews_scheduler.module
Implements hook_cron().

File

./simplenews_scheduler.module, line 523
Simplenews Scheduler module allows a schedule to be set for sending (and resending) a Simplenews item.

Code

function _simplenews_scheduler_send_new_edition($edition_time, $newsletter_parent_data, $eid) {
  $pid = $newsletter_parent_data->nid;

  // persist last_run
  \Drupal::database()
    ->update('simplenews_scheduler')
    ->fields(array(
    'last_run' => $edition_time,
  ))
    ->condition('nid', $pid)
    ->execute();

  // Send the newsletter edition to each subscriber of the parent newsletter.
  $node = \Drupal::entityTypeManager()
    ->getStorage('node')
    ->load($eid);
  $node
    ->setPublished();
  $node->simplenews_issue->status = SIMPLENEWS_STATUS_SEND_NOT;
  \Drupal::service('simplenews.spool_storage')
    ->addIssue($node);
}