You are here

public function TransactorHandler::getNextTransaction in Transaction 8

Get the next same-type transaction in order of execution.

Parameters

\Drupal\transaction\TransactionInterface $transaction: The transaction from which to get the next.

Return value

\Drupal\transaction\TransactionInterface The previously executed transaction. NULL if this is the last executed.

Throws

\Drupal\transaction\InvalidTransactionStateException If the transaction is no executed.

Overrides TransactorHandlerInterface::getNextTransaction

File

src/TransactorHandler.php, line 293

Class

TransactorHandler
Transactor entity handler.

Namespace

Drupal\transaction

Code

public function getNextTransaction(TransactionInterface $transaction) {
  if ($transaction
    ->isPending()) {
    throw new InvalidTransactionStateException('Cannot get the next executed transaction to one that is pending execution.');
  }
  $result = $this->transactionStorage
    ->getQuery()
    ->condition('type', $transaction
    ->getTypeId())
    ->condition('target_entity.target_id', $transaction
    ->getTargetEntityId())
    ->condition('target_entity.target_type', $transaction
    ->getType()
    ->getTargetEntityTypeId())
    ->exists('executed')
    ->condition('executed', $transaction
    ->getExecutionTime(), '>')
    ->range(0, 1)
    ->sort('executed')
    ->execute();
  return count($result) ? $this->transactionStorage
    ->load(array_pop($result)) : NULL;
}