public function interceptExecution(ExecutionInterceptorChain $chain, $depth) { $previous = $this->scope->getContextExecution(); try { return $chain->performExecution(); } finally { $this->scope->enterContext($previous); if ($depth == 0) { $this->scope->clear(); } } }
/** * {@inheritdoc} */ protected function performExecution(callable $callback) { $trans = false; if ($this->executionDepth == 0) { if ($this->handleTransactions) { $this->debug('BEGIN transaction'); $this->conn->beginTransaction(); } $trans = true; } try { $chain = new ExecutionInterceptorChain(function () use($callback) { return parent::performExecution($callback); }, $this->executionDepth, $this->interceptors); $result = $chain->performExecution($this->executionDepth); if ($trans) { if ($this->handleTransactions) { $this->debug('COMMIT transaction'); $this->conn->commit(); } } } catch (\Exception $e) { if ($trans) { if ($this->handleTransactions) { $this->debug('ROLL BACK transaction'); $this->conn->rollBack(); } } throw $e; } finally { if ($trans) { $this->executions = []; $this->jobs = []; } } // Schedule jobs after commit to DB, ensures consistent state in DB and failed scheduling attempts can be repeated. if ($trans) { if ($this->jobExecutor !== NULL) { $this->jobExecutor->syncScheduledJobs(); } } return $result; }