SpoolList.php in Simplenews 8
File
src/Spool/SpoolList.php
View source
<?php
namespace Drupal\simplenews\Spool;
use Drupal\simplenews\Mail\MailEntity;
class SpoolList implements SpoolListInterface {
protected $mails;
protected $processed = array();
public function __construct(array $mails) {
$this->mails = $mails;
}
public function count() {
return count($this->mails);
}
public function nextMail() {
$spool_data = current($this->mails);
next($this->mails);
if (!$spool_data) {
return FALSE;
}
$this->processed[$spool_data->msid] = $spool_data;
$entity = \Drupal::entityTypeManager()
->getStorage($spool_data->entity_type)
->load($spool_data->entity_id);
if (!$entity) {
$this->processed[$spool_data->msid]->result = array(
'status' => SpoolStorageInterface::STATUS_DONE,
'error' => TRUE,
);
return $this
->nextMail();
}
if ($spool_data->data) {
$subscriber = $spool_data->data;
}
else {
$subscriber = simplenews_subscriber_load_by_mail($spool_data->mail);
}
if (!$subscriber) {
$this->processed[$spool_data->msid]->result = array(
'status' => SpoolStorageInterface::STATUS_DONE,
'error' => TRUE,
);
return $this
->nextMail();
}
$mail = new MailEntity($entity, $subscriber, \Drupal::service('simplenews.mail_cache'));
$this->processed[$spool_data->msid]->langcode = $mail
->getEntity()
->language()
->getId();
return $mail;
}
function getProcessed() {
$processed = $this->processed;
$this->processed = array();
return $processed;
}
}