diff --git a/lib/private/AppFramework/Http/Dispatcher.php b/lib/private/AppFramework/Http/Dispatcher.php index f905296f95d38..2fa6bd8f1cbea 100644 --- a/lib/private/AppFramework/Http/Dispatcher.php +++ b/lib/private/AppFramework/Http/Dispatcher.php @@ -13,6 +13,7 @@ use OC\AppFramework\Middleware\MiddlewareDispatcher; use OC\AppFramework\Utility\ControllerMethodReflector; use OC\DB\ConnectionAdapter; +use OCP\App\IAppManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\ParameterOutOfRangeException; @@ -20,6 +21,7 @@ use OCP\Diagnostics\IEventLogger; use OCP\IConfig; use OCP\IRequest; +use OCP\Server; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -77,6 +79,12 @@ public function dispatch(Controller $controller, string $methodName): array { $response = $this->executeController($controller, $methodName); + if ($this->connection->inTransaction()) { + $this->connection->rollBack(); + $message = 'Controller method left a transaction open after executing controller method ' . $controller::class . '::' . $methodName . '. The transaction was rolled back.'; + $this->logger->warning($message, ['app' => Server::get(IAppManager::class)->getAppFromNamespace($controller::class)]); + } + if (!empty($databaseStatsBefore)) { $databaseStatsAfter = $this->connection->getInner()->getStats(); $numBuilt = $databaseStatsAfter['built'] - $databaseStatsBefore['built'];