TransactionIsolation.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\SetupChecks;
  8. use Doctrine\DBAL\Exception;
  9. use Doctrine\DBAL\TransactionIsolationLevel;
  10. use OC\DB\Connection;
  11. use OCP\IDBConnection;
  12. use OCP\IL10N;
  13. use OCP\IURLGenerator;
  14. use OCP\SetupCheck\ISetupCheck;
  15. use OCP\SetupCheck\SetupResult;
  16. class TransactionIsolation implements ISetupCheck {
  17. public function __construct(
  18. private IL10N $l10n,
  19. private IURLGenerator $urlGenerator,
  20. private IDBConnection $connection,
  21. private Connection $db,
  22. ) {
  23. }
  24. public function getName(): string {
  25. return $this->l10n->t('Database transaction isolation level');
  26. }
  27. public function getCategory(): string {
  28. return 'database';
  29. }
  30. public function run(): SetupResult {
  31. try {
  32. if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE) {
  33. return SetupResult::success();
  34. }
  35. if ($this->db->getTransactionIsolation() === TransactionIsolationLevel::READ_COMMITTED) {
  36. return SetupResult::success('Read committed');
  37. } else {
  38. return SetupResult::error(
  39. $this->l10n->t('Your database does not run with "READ COMMITTED" transaction isolation level. This can cause problems when multiple actions are executed in parallel.'),
  40. $this->urlGenerator->linkToDocs('admin-db-transaction')
  41. );
  42. }
  43. } catch (Exception $e) {
  44. return SetupResult::warning(
  45. $this->l10n->t('Was not able to get transaction isolation level: %s', $e->getMessage())
  46. );
  47. }
  48. }
  49. }