diff --git a/demos/init-db.php b/demos/init-db.php index 5b87842b76..519d04cd32 100644 --- a/demos/init-db.php +++ b/demos/init-db.php @@ -36,13 +36,15 @@ protected function isAllowDbModifications(): bool public function atomic(\Closure $fx) { - $eRollback = new \Exception('Prevent modification'); + $eRollback = !$this->getModel(true)->getPersistence()->getConnection()->inTransaction() + ? new \Exception('Prevent modification') + : null; $res = null; try { parent::atomic(function () use ($fx, $eRollback, &$res) { $res = $fx(); - if (!$this->isAllowDbModifications()) { + if ($eRollback !== null && !$this->isAllowDbModifications()) { throw $eRollback; } });