aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2023-10-26 15:04:02 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2023-11-07 12:14:03 +0100
commit3c75075eba3414da7b3c4db9aefe22da074cdcd9 (patch)
treee5d77c731fba31874ad9b2d9af34acb4339e57e5
parent5957a2bf6bfbb89c7c6b689e3eef89b7072fe3cf (diff)
downloadnextcloud-server-3c75075eba3414da7b3c4db9aefe22da074cdcd9.tar.gz
nextcloud-server-3c75075eba3414da7b3c4db9aefe22da074cdcd9.zip
Migrate database transaction level check to SetupCheck API
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r--apps/settings/composer/composer/autoload_classmap.php1
-rw-r--r--apps/settings/composer/composer/autoload_static.php1
-rw-r--r--apps/settings/lib/AppInfo/Application.php2
-rw-r--r--apps/settings/lib/Controller/CheckSetupController.php17
-rw-r--r--apps/settings/lib/SetupChecks/TransactionIsolation.php75
-rw-r--r--apps/settings/tests/Controller/CheckSetupControllerTest.php6
-rw-r--r--core/js/tests/specs/setupchecksSpec.js24
7 files changed, 79 insertions, 47 deletions
diff --git a/apps/settings/composer/composer/autoload_classmap.php b/apps/settings/composer/composer/autoload_classmap.php
index 8626e190ff6..b770553839e 100644
--- a/apps/settings/composer/composer/autoload_classmap.php
+++ b/apps/settings/composer/composer/autoload_classmap.php
@@ -85,6 +85,7 @@ return array(
'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => $baseDir . '/../lib/SetupChecks/PhpOutputBuffering.php',
'OCA\\Settings\\SetupChecks\\ReadOnlyConfig' => $baseDir . '/../lib/SetupChecks/ReadOnlyConfig.php',
'OCA\\Settings\\SetupChecks\\SupportedDatabase' => $baseDir . '/../lib/SetupChecks/SupportedDatabase.php',
+ 'OCA\\Settings\\SetupChecks\\TransactionIsolation' => $baseDir . '/../lib/SetupChecks/TransactionIsolation.php',
'OCA\\Settings\\UserMigration\\AccountMigrator' => $baseDir . '/../lib/UserMigration/AccountMigrator.php',
'OCA\\Settings\\UserMigration\\AccountMigratorException' => $baseDir . '/../lib/UserMigration/AccountMigratorException.php',
'OCA\\Settings\\WellKnown\\ChangePasswordHandler' => $baseDir . '/../lib/WellKnown/ChangePasswordHandler.php',
diff --git a/apps/settings/composer/composer/autoload_static.php b/apps/settings/composer/composer/autoload_static.php
index 76b2d357cda..c8aff3de76e 100644
--- a/apps/settings/composer/composer/autoload_static.php
+++ b/apps/settings/composer/composer/autoload_static.php
@@ -100,6 +100,7 @@ class ComposerStaticInitSettings
'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOutputBuffering.php',
'OCA\\Settings\\SetupChecks\\ReadOnlyConfig' => __DIR__ . '/..' . '/../lib/SetupChecks/ReadOnlyConfig.php',
'OCA\\Settings\\SetupChecks\\SupportedDatabase' => __DIR__ . '/..' . '/../lib/SetupChecks/SupportedDatabase.php',
+ 'OCA\\Settings\\SetupChecks\\TransactionIsolation' => __DIR__ . '/..' . '/../lib/SetupChecks/TransactionIsolation.php',
'OCA\\Settings\\UserMigration\\AccountMigrator' => __DIR__ . '/..' . '/../lib/UserMigration/AccountMigrator.php',
'OCA\\Settings\\UserMigration\\AccountMigratorException' => __DIR__ . '/..' . '/../lib/UserMigration/AccountMigratorException.php',
'OCA\\Settings\\WellKnown\\ChangePasswordHandler' => __DIR__ . '/..' . '/../lib/WellKnown/ChangePasswordHandler.php',
diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php
index 3f6333017c4..abc61c7e601 100644
--- a/apps/settings/lib/AppInfo/Application.php
+++ b/apps/settings/lib/AppInfo/Application.php
@@ -60,6 +60,7 @@ use OCA\Settings\SetupChecks\PhpOutdated;
use OCA\Settings\SetupChecks\PhpOutputBuffering;
use OCA\Settings\SetupChecks\ReadOnlyConfig;
use OCA\Settings\SetupChecks\SupportedDatabase;
+use OCA\Settings\SetupChecks\TransactionIsolation;
use OCA\Settings\UserMigration\AccountMigrator;
use OCA\Settings\WellKnown\ChangePasswordHandler;
use OCA\Settings\WellKnown\SecurityTxtHandler;
@@ -161,6 +162,7 @@ class Application extends App implements IBootstrap {
$context->registerSetupCheck(PhpOutputBuffering::class);
$context->registerSetupCheck(ReadOnlyConfig::class);
$context->registerSetupCheck(SupportedDatabase::class);
+ $context->registerSetupCheck(TransactionIsolation::class);
$context->registerUserMigrator(AccountMigrator::class);
}
diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php
index b5d20598cbd..dc36e8208e3 100644
--- a/apps/settings/lib/Controller/CheckSetupController.php
+++ b/apps/settings/lib/Controller/CheckSetupController.php
@@ -47,8 +47,6 @@ namespace OCA\Settings\Controller;
use bantu\IniGetWrapper\IniGetWrapper;
use DirectoryIterator;
-use Doctrine\DBAL\Exception;
-use Doctrine\DBAL\TransactionIsolationLevel;
use GuzzleHttp\Exception\ClientException;
use OC;
use OC\AppFramework\Http;
@@ -564,20 +562,6 @@ Raw output
return str_contains($this->config->getSystemValue('dbtype'), 'sqlite');
}
- protected function hasValidTransactionIsolationLevel(): bool {
- try {
- if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE) {
- return true;
- }
-
- return $this->db->getTransactionIsolation() === TransactionIsolationLevel::READ_COMMITTED;
- } catch (Exception $e) {
- // ignore
- }
-
- return true;
- }
-
protected function hasFileinfoInstalled(): bool {
return \OC_Util::fileInfoLoaded();
}
@@ -799,7 +783,6 @@ Raw output
public function check() {
return new DataResponse(
[
- 'hasValidTransactionIsolationLevel' => $this->hasValidTransactionIsolationLevel(),
'hasFileinfoInstalled' => $this->hasFileinfoInstalled(),
'hasWorkingFileLocking' => $this->hasWorkingFileLocking(),
'hasDBFileLocking' => $this->hasDBFileLocking(),
diff --git a/apps/settings/lib/SetupChecks/TransactionIsolation.php b/apps/settings/lib/SetupChecks/TransactionIsolation.php
new file mode 100644
index 00000000000..3b7be7da3e1
--- /dev/null
+++ b/apps/settings/lib/SetupChecks/TransactionIsolation.php
@@ -0,0 +1,75 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @author Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Settings\SetupChecks;
+
+use Doctrine\DBAL\Exception;
+use Doctrine\DBAL\TransactionIsolationLevel;
+use OC\DB\Connection;
+use OCP\IDBConnection;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\SetupCheck\ISetupCheck;
+use OCP\SetupCheck\SetupResult;
+
+class TransactionIsolation implements ISetupCheck {
+ public function __construct(
+ private IL10N $l10n,
+ private IURLGenerator $urlGenerator,
+ private IDBConnection $connection,
+ private Connection $db,
+ ) {
+ }
+
+ public function getName(): string {
+ return $this->l10n->t('Database transaction isolation level');
+ }
+
+ public function getCategory(): string {
+ return 'database';
+ }
+
+ public function run(): SetupResult {
+ try {
+ if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE) {
+ return SetupResult::success();
+ }
+
+ if ($this->db->getTransactionIsolation() === TransactionIsolationLevel::READ_COMMITTED) {
+ return SetupResult::success('Read committed');
+ } else {
+ return SetupResult::error(
+ $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.'),
+ $this->urlGenerator->linkToDocs('admin-db-transaction')
+ );
+ }
+ } catch (Exception $e) {
+ return SetupResult::warning(
+ $this->l10n->t('Was not able to get transaction isolation level: %s', $e->getMessage())
+ );
+ }
+ }
+}
diff --git a/apps/settings/tests/Controller/CheckSetupControllerTest.php b/apps/settings/tests/Controller/CheckSetupControllerTest.php
index 586b59132ee..b08c639f45f 100644
--- a/apps/settings/tests/Controller/CheckSetupControllerTest.php
+++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php
@@ -189,7 +189,6 @@ class CheckSetupControllerTest extends TestCase {
$this->setupCheckManager,
])
->setMethods([
- 'hasValidTransactionIsolationLevel',
'hasFileinfoInstalled',
'hasWorkingFileLocking',
'hasDBFileLocking',
@@ -379,10 +378,6 @@ class CheckSetupControllerTest extends TestCase {
->willReturn(false);
$this->checkSetupController
->expects($this->once())
- ->method('hasValidTransactionIsolationLevel')
- ->willReturn(true);
- $this->checkSetupController
- ->expects($this->once())
->method('hasFileinfoInstalled')
->willReturn(true);
$this->checkSetupController
@@ -484,7 +479,6 @@ class CheckSetupControllerTest extends TestCase {
$expected = new DataResponse(
[
- 'hasValidTransactionIsolationLevel' => true,
'hasFileinfoInstalled' => true,
'hasWorkingFileLocking' => true,
'hasDBFileLocking' => true,
diff --git a/core/js/tests/specs/setupchecksSpec.js b/core/js/tests/specs/setupchecksSpec.js
index 14f8d95e962..306813c90f9 100644
--- a/core/js/tests/specs/setupchecksSpec.js
+++ b/core/js/tests/specs/setupchecksSpec.js
@@ -226,7 +226,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
isFairUseOfFreePushService: true,
@@ -293,7 +292,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
isFairUseOfFreePushService: true,
@@ -360,7 +358,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
isFairUseOfFreePushService: true,
@@ -423,7 +420,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: false,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
@@ -485,7 +481,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
@@ -547,7 +542,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: false,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
@@ -609,7 +603,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: true,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
@@ -671,7 +664,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
@@ -735,7 +727,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
isFairUseOfFreePushService: true,
@@ -797,7 +788,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
isFairUseOfFreePushService: true,
@@ -861,7 +851,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
isFairUseOfFreePushService: true,
@@ -923,7 +912,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
isFairUseOfFreePushService: true,
@@ -1005,7 +993,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
@@ -1074,7 +1061,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
@@ -1136,7 +1122,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
@@ -1198,7 +1183,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
@@ -1264,7 +1248,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
@@ -1327,7 +1310,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
@@ -1387,7 +1369,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
@@ -1450,7 +1431,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
@@ -1513,7 +1493,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
@@ -1575,7 +1554,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
@@ -1637,7 +1615,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',
@@ -1706,7 +1683,6 @@ describe('OC.SetupChecks tests', function() {
hasFileinfoInstalled: true,
hasWorkingFileLocking: true,
hasDBFileLocking: false,
- hasValidTransactionIsolationLevel: true,
suggestedOverwriteCliURL: '',
isRandomnessSecure: true,
securityDocs: 'https://docs.nextcloud.com/myDocs.html',