You are here

public function SpoolList::getResults in Simplenews 8.2

Same name and namespace in other branches
  1. 3.x src/Spool/SpoolList.php \Drupal\simplenews\Spool\SpoolList::getResults()

Returns the results of all mails that have been processed by this list.

This function cancels any remaining mails in the list.

Return value

array An array of mail spool rows. Each array value is a simplenews_mail_spool database row plus the following additional properties.

  • langcode: language used to send this mail.
  • result: one of the SpoolStorageInterface::STATUS_* constants.

Overrides SpoolListInterface::getResults

File

src/Spool/SpoolList.php, line 150

Class

SpoolList
List of mail spool entries.

Namespace

Drupal\simplenews\Spool

Code

public function getResults() {
  if ($this->success && $this->pendingErrors) {

    // At least one mail was sent successfully so we can assume there is not
    // a global transport failure. Mark any 'unclassified' errors
    // (SpoolStorageInterface::STATUS_PENDING) as failed.
    $this->spoolStorage
      ->updateMails($this->pendingErrors, SpoolStorageInterface::STATUS_FAILED);
    foreach ($this->pendingErrors as $msid) {
      $this->spoolRows[$msid]->result = SpoolStorageInterface::STATUS_FAILED;
    }
  }
  if ($msid = key($this->spoolRows)) {

    // The loop didn't finish so clear any rows that don't have a result.
    $spool_ids = array_keys($this->spoolRows);
    $offset = array_search($msid, $spool_ids);
    $this->spoolStorage
      ->updateMails(array_slice($spool_ids, $offset), SpoolStorageInterface::STATUS_PENDING);
    $this->spoolRows = array_slice($this->spoolRows, 0, $offset);
  }
  return $this->spoolRows;
}