/** * Indicates delegated transaction finished successfully. * The real database transaction is committed only if * all delegated transactions committed. * @param moodle_transaction $transaction The transaction to commit * @return void * @throws dml_transaction_exception Creates and throws transaction related exceptions. */ public function commit_delegated_transaction(moodle_transaction $transaction) { if ($transaction->is_disposed()) { throw new dml_transaction_exception('Transactions already disposed', $transaction); } // mark as disposed so that it can not be used again $transaction->dispose(); if (empty($this->transactions)) { throw new dml_transaction_exception('Transaction not started', $transaction); } if ($this->force_rollback) { throw new dml_transaction_exception('Tried to commit transaction after lower level rollback', $transaction); } if ($transaction !== $this->transactions[count($this->transactions) - 1]) { // one incorrect commit at any level rollbacks everything $this->force_rollback = true; throw new dml_transaction_exception('Invalid transaction commit attempt', $transaction); } if (count($this->transactions) == 1) { // only commit the top most level $this->commit_transaction(); } array_pop($this->transactions); if (empty($this->transactions)) { \core\event\manager::database_transaction_commited(); \core\message\manager::database_transaction_commited(); } }