@@ -36,35 +36,35 @@ |
||
36 | 36 | */ |
37 | 37 | trait TTransactional { |
38 | 38 | |
39 | - /** |
|
40 | - * Run an atomic database operation |
|
41 | - * |
|
42 | - * - Commit if no exceptions are thrown, return the callable result |
|
43 | - * - Revert otherwise and rethrows the exception |
|
44 | - * |
|
45 | - * @template T |
|
46 | - * @param callable $fn |
|
47 | - * @psalm-param callable():T $fn |
|
48 | - * @param IDBConnection $db |
|
49 | - * |
|
50 | - * @return mixed the result of the passed callable |
|
51 | - * @psalm-return T |
|
52 | - * |
|
53 | - * @throws Exception for possible errors of commit or rollback or the custom operations within the closure |
|
54 | - * @throws Throwable any other error caused by the closure |
|
55 | - * |
|
56 | - * @since 24.0.0 |
|
57 | - * @see https://docs.nextcloud.com/server/latest/developer_manual/basics/storage/database.html#transactions |
|
58 | - */ |
|
59 | - protected function atomic(callable $fn, IDBConnection $db) { |
|
60 | - $db->beginTransaction(); |
|
61 | - try { |
|
62 | - $result = $fn(); |
|
63 | - $db->commit(); |
|
64 | - return $result; |
|
65 | - } catch (Throwable $e) { |
|
66 | - $db->rollBack(); |
|
67 | - throw $e; |
|
68 | - } |
|
69 | - } |
|
39 | + /** |
|
40 | + * Run an atomic database operation |
|
41 | + * |
|
42 | + * - Commit if no exceptions are thrown, return the callable result |
|
43 | + * - Revert otherwise and rethrows the exception |
|
44 | + * |
|
45 | + * @template T |
|
46 | + * @param callable $fn |
|
47 | + * @psalm-param callable():T $fn |
|
48 | + * @param IDBConnection $db |
|
49 | + * |
|
50 | + * @return mixed the result of the passed callable |
|
51 | + * @psalm-return T |
|
52 | + * |
|
53 | + * @throws Exception for possible errors of commit or rollback or the custom operations within the closure |
|
54 | + * @throws Throwable any other error caused by the closure |
|
55 | + * |
|
56 | + * @since 24.0.0 |
|
57 | + * @see https://docs.nextcloud.com/server/latest/developer_manual/basics/storage/database.html#transactions |
|
58 | + */ |
|
59 | + protected function atomic(callable $fn, IDBConnection $db) { |
|
60 | + $db->beginTransaction(); |
|
61 | + try { |
|
62 | + $result = $fn(); |
|
63 | + $db->commit(); |
|
64 | + return $result; |
|
65 | + } catch (Throwable $e) { |
|
66 | + $db->rollBack(); |
|
67 | + throw $e; |
|
68 | + } |
|
69 | + } |
|
70 | 70 | } |