public function SimplenewsSpool::nextSource in Simplenews 7.2
Same name and namespace in other branches
- 7 includes/simplenews.source.inc \SimplenewsSpool::nextSource()
Implements SimplenewsSpoolInterface::nextSource();
Overrides SimplenewsSpoolInterface::nextSource
File
- includes/
simplenews.source.inc, line 269 - Contains SimplenewsSource interface and implementations.
Class
- SimplenewsSpool
- Simplenews Spool implementation.
Code
public function nextSource() {
// Get the current mail spool row and update the internal pointer to the
// next row.
$return = each($this->spool_list);
// If we're done, return false.
if (!$return) {
return FALSE;
}
$spool_data = $return['value'];
// Store this spool row as processed.
$this->processed[$spool_data->msid] = $spool_data;
$entity = entity_load_single($spool_data->entity_type, $spool_data->entity_id);
if (!$entity) {
// If the entity load failed, set the processed status done and proceed with
// the next mail.
$this->processed[$spool_data->msid]->result = array(
'status' => SIMPLENEWS_SPOOL_DONE,
'error' => TRUE,
);
return $this
->nextSource();
}
if ($spool_data->data) {
$subscriber = $spool_data->data;
}
else {
$subscriber = simplenews_subscriber_load_by_mail($spool_data->mail);
}
if (!$subscriber) {
// If loading the subscriber failed, set the processed status done and
// proceed with the next mail.
$this->processed[$spool_data->msid]->result = array(
'status' => SIMPLENEWS_SPOOL_DONE,
'error' => TRUE,
);
return $this
->nextSource();
}
$source_class = $this
->getSourceImplementation($spool_data);
$source = new $source_class($entity, $subscriber, $spool_data->entity_type);
// Set which entity is actually used. In case of a translation set, this might
// not be the same entity.
$this->processed[$spool_data->msid]->actual_entity_type = $source
->getEntityType();
$this->processed[$spool_data->msid]->actual_entity_id = entity_id($source
->getEntityType(), $source
->getEntity());
return $source;
}