1313
1414use OC ;
1515use OC \Authentication \LoginCredentials \Store ;
16+ use OC \DB \Connection ;
1617use OC \Security \CSRF \TokenStorage \SessionStorage ;
1718use OC \Session \CryptoWrapper ;
1819use OC \Session \Memory ;
@@ -38,6 +39,7 @@ public function __construct(
3839 private readonly IAppManager $ appManager ,
3940 private readonly ISession $ session ,
4041 private readonly Session $ userSession ,
42+ private readonly Connection $ connection ,
4143 private readonly CryptoWrapper $ cryptoWrapper ,
4244 private readonly Store $ store ,
4345 private readonly SessionStorage $ sessionStorage ,
@@ -210,6 +212,12 @@ private function runCli(string $appMode, ?array $jobClasses): void {
210212 // clean up after unclean jobs
211213 $ this ->setupManager ->tearDown ();
212214 $ this ->tempManager ->clean ();
215+ if ($ this ->connection ->inTransaction ()) {
216+ $ this ->connection ->rollBack ();
217+ $ message = 'Cron job left a transaction opened after executing job ' . $ jobDetails . '. The transaction was rolled back. ' ;
218+ $ this ->logger ->warning ($ message , ['app ' => 'cron ' ]);
219+ $ this ->verboseOutput ($ message );
220+ }
213221
214222 $ this ->verboseOutput ('Job ' . $ jobDetails . ' done in ' . ($ timeAfter - $ timeBefore ) . ' seconds ' );
215223
0 commit comments