TransactionIsolation.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
  5. *
  6. * @author Côme Chilliet <come.chilliet@nextcloud.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Settings\SetupChecks;
  25. use Doctrine\DBAL\Exception;
  26. use Doctrine\DBAL\TransactionIsolationLevel;
  27. use OC\DB\Connection;
  28. use OCP\IDBConnection;
  29. use OCP\IL10N;
  30. use OCP\IURLGenerator;
  31. use OCP\SetupCheck\ISetupCheck;
  32. use OCP\SetupCheck\SetupResult;
  33. class TransactionIsolation implements ISetupCheck {
  34. public function __construct(
  35. private IL10N $l10n,
  36. private IURLGenerator $urlGenerator,
  37. private IDBConnection $connection,
  38. private Connection $db,
  39. ) {
  40. }
  41. public function getName(): string {
  42. return $this->l10n->t('Database transaction isolation level');
  43. }
  44. public function getCategory(): string {
  45. return 'database';
  46. }
  47. public function run(): SetupResult {
  48. try {
  49. if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE) {
  50. return SetupResult::success();
  51. }
  52. if ($this->db->getTransactionIsolation() === TransactionIsolationLevel::READ_COMMITTED) {
  53. return SetupResult::success('Read committed');
  54. } else {
  55. return SetupResult::error(
  56. $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.'),
  57. $this->urlGenerator->linkToDocs('admin-db-transaction')
  58. );
  59. }
  60. } catch (Exception $e) {
  61. return SetupResult::warning(
  62. $this->l10n->t('Was not able to get transaction isolation level: %s', $e->getMessage())
  63. );
  64. }
  65. }
  66. }