From d0a72a103d220fe15d34237e427f1ae0fec450c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 14 Nov 2023 15:14:14 +0100 Subject: [PATCH 1/6] Migrate missing column database check to new API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../composer/composer/autoload_classmap.php | 1 + .../composer/composer/autoload_static.php | 1 + apps/settings/lib/AppInfo/Application.php | 2 + .../lib/Controller/CheckSetupController.php | 25 ------ .../SetupChecks/DatabaseHasMissingColumns.php | 89 +++++++++++++++++++ .../Controller/CheckSetupControllerTest.php | 1 - core/js/setupchecks.js | 12 --- core/js/tests/specs/setupchecksSpec.js | 17 ---- lib/private/DB/MissingColumnInformation.php | 2 +- 9 files changed, 94 insertions(+), 56 deletions(-) create mode 100644 apps/settings/lib/SetupChecks/DatabaseHasMissingColumns.php diff --git a/apps/settings/composer/composer/autoload_classmap.php b/apps/settings/composer/composer/autoload_classmap.php index e6d1f3ff83f..c3ce8650443 100644 --- a/apps/settings/composer/composer/autoload_classmap.php +++ b/apps/settings/composer/composer/autoload_classmap.php @@ -75,6 +75,7 @@ return array( 'OCA\\Settings\\Settings\\Personal\\ServerDevNotice' => $baseDir . '/../lib/Settings/Personal/ServerDevNotice.php', 'OCA\\Settings\\SetupChecks\\BruteForceThrottler' => $baseDir . '/../lib/SetupChecks/BruteForceThrottler.php', 'OCA\\Settings\\SetupChecks\\CheckUserCertificates' => $baseDir . '/../lib/SetupChecks/CheckUserCertificates.php', + 'OCA\\Settings\\SetupChecks\\DatabaseHasMissingColumns' => $baseDir . '/../lib/SetupChecks/DatabaseHasMissingColumns.php', 'OCA\\Settings\\SetupChecks\\DefaultPhoneRegionSet' => $baseDir . '/../lib/SetupChecks/DefaultPhoneRegionSet.php', 'OCA\\Settings\\SetupChecks\\EmailTestSuccessful' => $baseDir . '/../lib/SetupChecks/EmailTestSuccessful.php', 'OCA\\Settings\\SetupChecks\\FileLocking' => $baseDir . '/../lib/SetupChecks/FileLocking.php', diff --git a/apps/settings/composer/composer/autoload_static.php b/apps/settings/composer/composer/autoload_static.php index 1a95f65119a..fe123d74d81 100644 --- a/apps/settings/composer/composer/autoload_static.php +++ b/apps/settings/composer/composer/autoload_static.php @@ -90,6 +90,7 @@ class ComposerStaticInitSettings 'OCA\\Settings\\Settings\\Personal\\ServerDevNotice' => __DIR__ . '/..' . '/../lib/Settings/Personal/ServerDevNotice.php', 'OCA\\Settings\\SetupChecks\\BruteForceThrottler' => __DIR__ . '/..' . '/../lib/SetupChecks/BruteForceThrottler.php', 'OCA\\Settings\\SetupChecks\\CheckUserCertificates' => __DIR__ . '/..' . '/../lib/SetupChecks/CheckUserCertificates.php', + 'OCA\\Settings\\SetupChecks\\DatabaseHasMissingColumns' => __DIR__ . '/..' . '/../lib/SetupChecks/DatabaseHasMissingColumns.php', 'OCA\\Settings\\SetupChecks\\DefaultPhoneRegionSet' => __DIR__ . '/..' . '/../lib/SetupChecks/DefaultPhoneRegionSet.php', 'OCA\\Settings\\SetupChecks\\EmailTestSuccessful' => __DIR__ . '/..' . '/../lib/SetupChecks/EmailTestSuccessful.php', 'OCA\\Settings\\SetupChecks\\FileLocking' => __DIR__ . '/..' . '/../lib/SetupChecks/FileLocking.php', diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php index d694e650b48..d73961968f8 100644 --- a/apps/settings/lib/AppInfo/Application.php +++ b/apps/settings/lib/AppInfo/Application.php @@ -50,6 +50,7 @@ use OCA\Settings\Search\SectionSearch; use OCA\Settings\Search\UserSearch; use OCA\Settings\SetupChecks\BruteForceThrottler; use OCA\Settings\SetupChecks\CheckUserCertificates; +use OCA\Settings\SetupChecks\DatabaseHasMissingColumns; use OCA\Settings\SetupChecks\DefaultPhoneRegionSet; use OCA\Settings\SetupChecks\EmailTestSuccessful; use OCA\Settings\SetupChecks\FileLocking; @@ -160,6 +161,7 @@ class Application extends App implements IBootstrap { }); $context->registerSetupCheck(BruteForceThrottler::class); $context->registerSetupCheck(CheckUserCertificates::class); + $context->registerSetupCheck(DatabaseHasMissingColumns::class); $context->registerSetupCheck(DefaultPhoneRegionSet::class); $context->registerSetupCheck(EmailTestSuccessful::class); $context->registerSetupCheck(FileLocking::class); diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php index 13e54063d8a..1fa6a658878 100644 --- a/apps/settings/lib/Controller/CheckSetupController.php +++ b/apps/settings/lib/Controller/CheckSetupController.php @@ -51,7 +51,6 @@ use GuzzleHttp\Exception\ClientException; use OC; use OC\AppFramework\Http; use OC\DB\Connection; -use OC\DB\MissingColumnInformation; use OC\DB\MissingIndexInformation; use OC\DB\MissingPrimaryKeyInformation; use OC\DB\SchemaWrapper; @@ -62,7 +61,6 @@ use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI; use OCP\AppFramework\Http\DataDisplayResponse; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\RedirectResponse; -use OCP\DB\Events\AddMissingColumnsEvent; use OCP\DB\Events\AddMissingIndicesEvent; use OCP\DB\Events\AddMissingPrimaryKeyEvent; use OCP\DB\Types; @@ -464,28 +462,6 @@ Raw output return $info->getListOfMissingPrimaryKeys(); } - protected function hasMissingColumns(): array { - $columnInfo = new MissingColumnInformation(); - // Dispatch event so apps can also hint for pending column updates if needed - $event = new AddMissingColumnsEvent(); - $this->dispatcher->dispatchTyped($event); - $missingColumns = $event->getMissingColumns(); - - if (!empty($missingColumns)) { - $schema = new SchemaWrapper(\OCP\Server::get(Connection::class)); - foreach ($missingColumns as $missingColumn) { - if ($schema->hasTable($missingColumn['tableName'])) { - $table = $schema->getTable($missingColumn['tableName']); - if (!$table->hasColumn($missingColumn['columnName'])) { - $columnInfo->addHintForMissingColumn($missingColumn['tableName'], $missingColumn['columnName']); - } - } - } - } - - return $columnInfo->getListOfMissingColumns(); - } - protected function isSqliteUsed() { return str_contains($this->config->getSystemValue('dbtype'), 'sqlite'); } @@ -704,7 +680,6 @@ Raw output 'isSettimelimitAvailable' => $this->isSettimelimitAvailable(), 'missingPrimaryKeys' => $this->hasMissingPrimaryKeys(), 'missingIndexes' => $this->hasMissingIndexes(), - 'missingColumns' => $this->hasMissingColumns(), 'isSqliteUsed' => $this->isSqliteUsed(), 'databaseConversionDocumentation' => $this->urlGenerator->linkToDocs('admin-db-conversion'), 'appDirsWithDifferentOwner' => $this->getAppDirsWithDifferentOwner(), diff --git a/apps/settings/lib/SetupChecks/DatabaseHasMissingColumns.php b/apps/settings/lib/SetupChecks/DatabaseHasMissingColumns.php new file mode 100644 index 00000000000..946f357a04b --- /dev/null +++ b/apps/settings/lib/SetupChecks/DatabaseHasMissingColumns.php @@ -0,0 +1,89 @@ + + * + * @author Côme Chilliet + * + * @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 . + * + */ +namespace OCA\Settings\SetupChecks; + +use OC\DB\Connection; +use OC\DB\MissingColumnInformation; +use OC\DB\SchemaWrapper; +use OCP\DB\Events\AddMissingColumnsEvent; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\IL10N; +use OCP\SetupCheck\ISetupCheck; +use OCP\SetupCheck\SetupResult; + +class DatabaseHasMissingColumns implements ISetupCheck { + public function __construct( + private IL10N $l10n, + private Connection $connection, + private IEventDispatcher $dispatcher, + ) { + } + + public function getCategory(): string { + return 'database'; + } + + public function getName(): string { + return $this->l10n->t('Database missing columns'); + } + + private function getMissingColumns(): array { + $columnInfo = new MissingColumnInformation(); + // Dispatch event so apps can also hint for pending column updates if needed + $event = new AddMissingColumnsEvent(); + $this->dispatcher->dispatchTyped($event); + $missingColumns = $event->getMissingColumns(); + + if (!empty($missingColumns)) { + $schema = new SchemaWrapper($this->connection); + foreach ($missingColumns as $missingColumn) { + if ($schema->hasTable($missingColumn['tableName'])) { + $table = $schema->getTable($missingColumn['tableName']); + if (!$table->hasColumn($missingColumn['columnName'])) { + $columnInfo->addHintForMissingColumn($missingColumn['tableName'], $missingColumn['columnName']); + } + } + } + } + + return $columnInfo->getListOfMissingColumns(); + } + + public function run(): SetupResult { + $missingColumns = $this->getMissingColumns(); + if (empty($missingColumns)) { + return SetupResult::success('None'); + } else { + $list = ''; + foreach ($missingColumns as $missingColumn) { + $list .= "\n".$this->l10n->t('Missing optional column "%s" in table "%s".', [$missingColumn['columnName'], $missingColumn['tableName']]); + } + return SetupResult::info( + $this->l10n->t('The database is missing some optional columns. Due to the fact that adding columns on big tables could take some time they were not added automatically when they can be optional. By running "occ db:add-missing-columns" those missing columns could be added manually while the instance keeps running. Once the columns are added some features might improve responsiveness or usability.').$list + ); + } + } +} diff --git a/apps/settings/tests/Controller/CheckSetupControllerTest.php b/apps/settings/tests/Controller/CheckSetupControllerTest.php index fb2aa1a975d..e5db2d52e3c 100644 --- a/apps/settings/tests/Controller/CheckSetupControllerTest.php +++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php @@ -339,7 +339,6 @@ class CheckSetupControllerTest extends TestCase { 'databaseConversionDocumentation' => 'http://docs.example.org/server/go.php?to=admin-db-conversion', 'missingIndexes' => [], 'missingPrimaryKeys' => [], - 'missingColumns' => [], 'appDirsWithDifferentOwner' => [], 'isImagickEnabled' => false, 'areWebauthnExtensionsEnabled' => false, diff --git a/core/js/setupchecks.js b/core/js/setupchecks.js index 1d64acf01ea..5cd2cadaa2d 100644 --- a/core/js/setupchecks.js +++ b/core/js/setupchecks.js @@ -282,18 +282,6 @@ type: OC.SetupChecks.MESSAGE_TYPE_INFO }) } - if (data.missingColumns.length > 0) { - var listOfMissingColumns = ""; - data.missingColumns.forEach(function(element){ - listOfMissingColumns += '
  • '; - listOfMissingColumns += t('core', 'Missing optional column "{columnName}" in table "{tableName}".', element); - listOfMissingColumns += '
  • '; - }); - messages.push({ - msg: t('core', 'The database is missing some optional columns. Due to the fact that adding columns on big tables could take some time they were not added automatically when they can be optional. By running "occ db:add-missing-columns" those missing columns could be added manually while the instance keeps running. Once the columns are added some features might improve responsiveness or usability.') + '
      ' + listOfMissingColumns + '
    ', - type: OC.SetupChecks.MESSAGE_TYPE_INFO - }) - } if (!data.isImagickEnabled) { messages.push({ msg: t( diff --git a/core/js/tests/specs/setupchecksSpec.js b/core/js/tests/specs/setupchecksSpec.js index d9124cfc84d..9cba013bb87 100644 --- a/core/js/tests/specs/setupchecksSpec.js +++ b/core/js/tests/specs/setupchecksSpec.js @@ -231,7 +231,6 @@ describe('OC.SetupChecks tests', function() { isSettimelimitAvailable: true, missingIndexes: [], missingPrimaryKeys: [], - missingColumns: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -284,7 +283,6 @@ describe('OC.SetupChecks tests', function() { isSettimelimitAvailable: true, missingIndexes: [], missingPrimaryKeys: [], - missingColumns: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -337,7 +335,6 @@ describe('OC.SetupChecks tests', function() { isSettimelimitAvailable: true, missingIndexes: [], missingPrimaryKeys: [], - missingColumns: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -390,7 +387,6 @@ describe('OC.SetupChecks tests', function() { isSettimelimitAvailable: true, missingIndexes: [], missingPrimaryKeys: [], - missingColumns: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -441,7 +437,6 @@ describe('OC.SetupChecks tests', function() { isSettimelimitAvailable: true, missingIndexes: [], missingPrimaryKeys: [], - missingColumns: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -495,7 +490,6 @@ describe('OC.SetupChecks tests', function() { isSettimelimitAvailable: false, missingIndexes: [], missingPrimaryKeys: [], - missingColumns: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -547,7 +541,6 @@ describe('OC.SetupChecks tests', function() { isSettimelimitAvailable: true, missingIndexes: [], missingPrimaryKeys: [], - missingColumns: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -630,7 +623,6 @@ describe('OC.SetupChecks tests', function() { isSettimelimitAvailable: true, missingIndexes: [], missingPrimaryKeys: [], - missingColumns: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -688,7 +680,6 @@ describe('OC.SetupChecks tests', function() { isSettimelimitAvailable: true, missingIndexes: [], missingPrimaryKeys: [], - missingColumns: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -739,7 +730,6 @@ describe('OC.SetupChecks tests', function() { isSettimelimitAvailable: true, missingIndexes: [], missingPrimaryKeys: [], - missingColumns: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -794,7 +784,6 @@ describe('OC.SetupChecks tests', function() { isSettimelimitAvailable: true, missingIndexes: [], missingPrimaryKeys: [], - missingColumns: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -846,7 +835,6 @@ describe('OC.SetupChecks tests', function() { isSettimelimitAvailable: true, missingIndexes: [], missingPrimaryKeys: [], - missingColumns: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -895,7 +883,6 @@ describe('OC.SetupChecks tests', function() { isSettimelimitAvailable: true, missingIndexes: [], missingPrimaryKeys: [], - missingColumns: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -947,7 +934,6 @@ describe('OC.SetupChecks tests', function() { isSettimelimitAvailable: true, missingIndexes: [], missingPrimaryKeys: [], - missingColumns: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -999,7 +985,6 @@ describe('OC.SetupChecks tests', function() { isSettimelimitAvailable: true, missingIndexes: [], missingPrimaryKeys: [], - missingColumns: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -1050,7 +1035,6 @@ describe('OC.SetupChecks tests', function() { isSettimelimitAvailable: true, missingIndexes: [], missingPrimaryKeys: [], - missingColumns: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -1108,7 +1092,6 @@ describe('OC.SetupChecks tests', function() { isSettimelimitAvailable: true, missingIndexes: [], missingPrimaryKeys: [], - missingColumns: [], cronErrors: [], cronInfo: { diffInSeconds: 0 diff --git a/lib/private/DB/MissingColumnInformation.php b/lib/private/DB/MissingColumnInformation.php index f651546b4b3..919f8923a26 100644 --- a/lib/private/DB/MissingColumnInformation.php +++ b/lib/private/DB/MissingColumnInformation.php @@ -26,7 +26,7 @@ declare(strict_types=1); namespace OC\DB; class MissingColumnInformation { - private $listOfMissingColumns = []; + private array $listOfMissingColumns = []; public function addHintForMissingColumn(string $tableName, string $columnName): void { $this->listOfMissingColumns[] = [ From e48e67b0a43bca34c373387ac42184ba1f44fda0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 14 Nov 2023 15:51:26 +0100 Subject: [PATCH 2/6] Migrate missing index database check to new API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../composer/composer/autoload_classmap.php | 1 + .../composer/composer/autoload_static.php | 1 + apps/settings/lib/AppInfo/Application.php | 2 + .../lib/Controller/CheckSetupController.php | 26 ------ .../SetupChecks/DatabaseHasMissingIndices.php | 89 +++++++++++++++++++ .../Controller/CheckSetupControllerTest.php | 4 - core/js/setupchecks.js | 12 --- core/js/tests/specs/setupchecksSpec.js | 17 ---- lib/private/DB/MissingIndexInformation.php | 10 +-- 9 files changed, 98 insertions(+), 64 deletions(-) create mode 100644 apps/settings/lib/SetupChecks/DatabaseHasMissingIndices.php diff --git a/apps/settings/composer/composer/autoload_classmap.php b/apps/settings/composer/composer/autoload_classmap.php index c3ce8650443..7c1c1534a74 100644 --- a/apps/settings/composer/composer/autoload_classmap.php +++ b/apps/settings/composer/composer/autoload_classmap.php @@ -76,6 +76,7 @@ return array( 'OCA\\Settings\\SetupChecks\\BruteForceThrottler' => $baseDir . '/../lib/SetupChecks/BruteForceThrottler.php', 'OCA\\Settings\\SetupChecks\\CheckUserCertificates' => $baseDir . '/../lib/SetupChecks/CheckUserCertificates.php', 'OCA\\Settings\\SetupChecks\\DatabaseHasMissingColumns' => $baseDir . '/../lib/SetupChecks/DatabaseHasMissingColumns.php', + 'OCA\\Settings\\SetupChecks\\DatabaseHasMissingIndices' => $baseDir . '/../lib/SetupChecks/DatabaseHasMissingIndices.php', 'OCA\\Settings\\SetupChecks\\DefaultPhoneRegionSet' => $baseDir . '/../lib/SetupChecks/DefaultPhoneRegionSet.php', 'OCA\\Settings\\SetupChecks\\EmailTestSuccessful' => $baseDir . '/../lib/SetupChecks/EmailTestSuccessful.php', 'OCA\\Settings\\SetupChecks\\FileLocking' => $baseDir . '/../lib/SetupChecks/FileLocking.php', diff --git a/apps/settings/composer/composer/autoload_static.php b/apps/settings/composer/composer/autoload_static.php index fe123d74d81..010b19f7243 100644 --- a/apps/settings/composer/composer/autoload_static.php +++ b/apps/settings/composer/composer/autoload_static.php @@ -91,6 +91,7 @@ class ComposerStaticInitSettings 'OCA\\Settings\\SetupChecks\\BruteForceThrottler' => __DIR__ . '/..' . '/../lib/SetupChecks/BruteForceThrottler.php', 'OCA\\Settings\\SetupChecks\\CheckUserCertificates' => __DIR__ . '/..' . '/../lib/SetupChecks/CheckUserCertificates.php', 'OCA\\Settings\\SetupChecks\\DatabaseHasMissingColumns' => __DIR__ . '/..' . '/../lib/SetupChecks/DatabaseHasMissingColumns.php', + 'OCA\\Settings\\SetupChecks\\DatabaseHasMissingIndices' => __DIR__ . '/..' . '/../lib/SetupChecks/DatabaseHasMissingIndices.php', 'OCA\\Settings\\SetupChecks\\DefaultPhoneRegionSet' => __DIR__ . '/..' . '/../lib/SetupChecks/DefaultPhoneRegionSet.php', 'OCA\\Settings\\SetupChecks\\EmailTestSuccessful' => __DIR__ . '/..' . '/../lib/SetupChecks/EmailTestSuccessful.php', 'OCA\\Settings\\SetupChecks\\FileLocking' => __DIR__ . '/..' . '/../lib/SetupChecks/FileLocking.php', diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php index d73961968f8..65ef8ac74a4 100644 --- a/apps/settings/lib/AppInfo/Application.php +++ b/apps/settings/lib/AppInfo/Application.php @@ -51,6 +51,7 @@ use OCA\Settings\Search\UserSearch; use OCA\Settings\SetupChecks\BruteForceThrottler; use OCA\Settings\SetupChecks\CheckUserCertificates; use OCA\Settings\SetupChecks\DatabaseHasMissingColumns; +use OCA\Settings\SetupChecks\DatabaseHasMissingIndices; use OCA\Settings\SetupChecks\DefaultPhoneRegionSet; use OCA\Settings\SetupChecks\EmailTestSuccessful; use OCA\Settings\SetupChecks\FileLocking; @@ -162,6 +163,7 @@ class Application extends App implements IBootstrap { $context->registerSetupCheck(BruteForceThrottler::class); $context->registerSetupCheck(CheckUserCertificates::class); $context->registerSetupCheck(DatabaseHasMissingColumns::class); + $context->registerSetupCheck(DatabaseHasMissingIndices::class); $context->registerSetupCheck(DefaultPhoneRegionSet::class); $context->registerSetupCheck(EmailTestSuccessful::class); $context->registerSetupCheck(FileLocking::class); diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php index 1fa6a658878..27ee0df4971 100644 --- a/apps/settings/lib/Controller/CheckSetupController.php +++ b/apps/settings/lib/Controller/CheckSetupController.php @@ -51,7 +51,6 @@ use GuzzleHttp\Exception\ClientException; use OC; use OC\AppFramework\Http; use OC\DB\Connection; -use OC\DB\MissingIndexInformation; use OC\DB\MissingPrimaryKeyInformation; use OC\DB\SchemaWrapper; use OC\IntegrityCheck\Checker; @@ -61,7 +60,6 @@ use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI; use OCP\AppFramework\Http\DataDisplayResponse; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\RedirectResponse; -use OCP\DB\Events\AddMissingIndicesEvent; use OCP\DB\Events\AddMissingPrimaryKeyEvent; use OCP\DB\Types; use OCP\EventDispatcher\IEventDispatcher; @@ -417,29 +415,6 @@ Raw output return $recommendations; } - protected function hasMissingIndexes(): array { - $indexInfo = new MissingIndexInformation(); - - // Dispatch event so apps can also hint for pending index updates if needed - $event = new AddMissingIndicesEvent(); - $this->dispatcher->dispatchTyped($event); - $missingIndices = $event->getMissingIndices(); - - if ($missingIndices !== []) { - $schema = new SchemaWrapper(\OCP\Server::get(Connection::class)); - foreach ($missingIndices as $missingIndex) { - if ($schema->hasTable($missingIndex['tableName'])) { - $table = $schema->getTable($missingIndex['tableName']); - if (!$table->hasIndex($missingIndex['indexName'])) { - $indexInfo->addHintForMissingSubject($missingIndex['tableName'], $missingIndex['indexName']); - } - } - } - } - - return $indexInfo->getListOfMissingIndexes(); - } - protected function hasMissingPrimaryKeys(): array { $info = new MissingPrimaryKeyInformation(); // Dispatch event so apps can also hint for pending key updates if needed @@ -679,7 +654,6 @@ Raw output 'OpcacheSetupRecommendations' => $this->getOpcacheSetupRecommendations(), 'isSettimelimitAvailable' => $this->isSettimelimitAvailable(), 'missingPrimaryKeys' => $this->hasMissingPrimaryKeys(), - 'missingIndexes' => $this->hasMissingIndexes(), 'isSqliteUsed' => $this->isSqliteUsed(), 'databaseConversionDocumentation' => $this->urlGenerator->linkToDocs('admin-db-conversion'), 'appDirsWithDifferentOwner' => $this->getAppDirsWithDifferentOwner(), diff --git a/apps/settings/lib/SetupChecks/DatabaseHasMissingIndices.php b/apps/settings/lib/SetupChecks/DatabaseHasMissingIndices.php new file mode 100644 index 00000000000..b19c3abb690 --- /dev/null +++ b/apps/settings/lib/SetupChecks/DatabaseHasMissingIndices.php @@ -0,0 +1,89 @@ + + * + * @author Côme Chilliet + * + * @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 . + * + */ +namespace OCA\Settings\SetupChecks; + +use OC\DB\Connection; +use OC\DB\MissingIndexInformation; +use OC\DB\SchemaWrapper; +use OCP\DB\Events\AddMissingIndicesEvent; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\IL10N; +use OCP\SetupCheck\ISetupCheck; +use OCP\SetupCheck\SetupResult; + +class DatabaseHasMissingIndices implements ISetupCheck { + public function __construct( + private IL10N $l10n, + private Connection $connection, + private IEventDispatcher $dispatcher, + ) { + } + + public function getCategory(): string { + return 'database'; + } + + public function getName(): string { + return $this->l10n->t('Database missing indices'); + } + + private function getMissingIndices(): array { + $indexInfo = new MissingIndexInformation(); + // Dispatch event so apps can also hint for pending index updates if needed + $event = new AddMissingIndicesEvent(); + $this->dispatcher->dispatchTyped($event); + $missingIndices = $event->getMissingIndices(); + + if (!empty($missingIndices)) { + $schema = new SchemaWrapper($this->connection); + foreach ($missingIndices as $missingIndex) { + if ($schema->hasTable($missingIndex['tableName'])) { + $table = $schema->getTable($missingIndex['tableName']); + if (!$table->hasIndex($missingIndex['indexName'])) { + $indexInfo->addHintForMissingIndex($missingIndex['tableName'], $missingIndex['indexName']); + } + } + } + } + + return $indexInfo->getListOfMissingIndices(); + } + + public function run(): SetupResult { + $missingIndices = $this->getMissingIndices(); + if (empty($missingIndices)) { + return SetupResult::success('None'); + } else { + $list = ''; + foreach ($missingIndices as $missingIndex) { + $list .= "\n".$this->l10n->t('Missing optional index "%s" in table "%s".', [$missingIndex['indexName'], $missingIndex['tableName']]); + } + return SetupResult::info( + $this->l10n->t('The database is missing some indexes. Due to the fact that adding indexes on big tables could take some time they were not added automatically. By running "occ db:add-missing-indices" those missing indexes could be added manually while the instance keeps running. Once the indexes are added queries to those tables are usually much faster.').$list + ); + } + } +} diff --git a/apps/settings/tests/Controller/CheckSetupControllerTest.php b/apps/settings/tests/Controller/CheckSetupControllerTest.php index e5db2d52e3c..a493722a3ce 100644 --- a/apps/settings/tests/Controller/CheckSetupControllerTest.php +++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php @@ -178,7 +178,6 @@ class CheckSetupControllerTest extends TestCase { 'getCurlVersion', 'isPhpOutdated', 'getOpcacheSetupRecommendations', - 'hasMissingIndexes', 'hasMissingPrimaryKeys', 'isSqliteUsed', 'isPHPMailerUsed', @@ -229,9 +228,6 @@ class CheckSetupControllerTest extends TestCase { ->expects($this->once()) ->method('getOpcacheSetupRecommendations') ->willReturn(['recommendation1', 'recommendation2']); - $this->checkSetupController - ->method('hasMissingIndexes') - ->willReturn([]); $this->checkSetupController ->method('hasMissingPrimaryKeys') ->willReturn([]); diff --git a/core/js/setupchecks.js b/core/js/setupchecks.js index 5cd2cadaa2d..f926d1534a5 100644 --- a/core/js/setupchecks.js +++ b/core/js/setupchecks.js @@ -258,18 +258,6 @@ type: OC.SetupChecks.MESSAGE_TYPE_WARNING }); } - if (data.missingIndexes.length > 0) { - var listOfMissingIndexes = ""; - data.missingIndexes.forEach(function(element){ - listOfMissingIndexes += '
  • '; - listOfMissingIndexes += t('core', 'Missing index "{indexName}" in table "{tableName}".', element); - listOfMissingIndexes += '
  • '; - }); - messages.push({ - msg: t('core', 'The database is missing some indexes. Due to the fact that adding indexes on big tables could take some time they were not added automatically. By running "occ db:add-missing-indices" those missing indexes could be added manually while the instance keeps running. Once the indexes are added queries to those tables are usually much faster.') + '
      ' + listOfMissingIndexes + '
    ', - type: OC.SetupChecks.MESSAGE_TYPE_INFO - }) - } if (data.missingPrimaryKeys.length > 0) { var listOfMissingPrimaryKeys = ""; data.missingPrimaryKeys.forEach(function(element){ diff --git a/core/js/tests/specs/setupchecksSpec.js b/core/js/tests/specs/setupchecksSpec.js index 9cba013bb87..d48f92d5dc3 100644 --- a/core/js/tests/specs/setupchecksSpec.js +++ b/core/js/tests/specs/setupchecksSpec.js @@ -229,7 +229,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingIndexes: [], missingPrimaryKeys: [], cronErrors: [], cronInfo: { @@ -281,7 +280,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingIndexes: [], missingPrimaryKeys: [], cronErrors: [], cronInfo: { @@ -333,7 +331,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingIndexes: [], missingPrimaryKeys: [], cronErrors: [], cronInfo: { @@ -385,7 +382,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingIndexes: [], missingPrimaryKeys: [], cronErrors: [], cronInfo: { @@ -435,7 +431,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingIndexes: [], missingPrimaryKeys: [], cronErrors: [], cronInfo: { @@ -488,7 +483,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: false, - missingIndexes: [], missingPrimaryKeys: [], cronErrors: [], cronInfo: { @@ -539,7 +533,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingIndexes: [], missingPrimaryKeys: [], cronErrors: [], cronInfo: { @@ -621,7 +614,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingIndexes: [], missingPrimaryKeys: [], cronErrors: [], cronInfo: { @@ -678,7 +670,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: ['recommendation1', 'recommendation2'], isSettimelimitAvailable: true, - missingIndexes: [], missingPrimaryKeys: [], cronErrors: [], cronInfo: { @@ -728,7 +719,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingIndexes: [], missingPrimaryKeys: [], cronErrors: [], cronInfo: { @@ -782,7 +772,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingIndexes: [], missingPrimaryKeys: [], cronErrors: [], cronInfo: { @@ -833,7 +822,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingIndexes: [], missingPrimaryKeys: [], cronErrors: [], cronInfo: { @@ -881,7 +869,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingIndexes: [], missingPrimaryKeys: [], cronErrors: [], cronInfo: { @@ -932,7 +919,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingIndexes: [], missingPrimaryKeys: [], cronErrors: [], cronInfo: { @@ -983,7 +969,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingIndexes: [], missingPrimaryKeys: [], cronErrors: [], cronInfo: { @@ -1033,7 +1018,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingIndexes: [], missingPrimaryKeys: [], cronErrors: [], cronInfo: { @@ -1090,7 +1074,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingIndexes: [], missingPrimaryKeys: [], cronErrors: [], cronInfo: { diff --git a/lib/private/DB/MissingIndexInformation.php b/lib/private/DB/MissingIndexInformation.php index 74498668349..4fc3a52d3a4 100644 --- a/lib/private/DB/MissingIndexInformation.php +++ b/lib/private/DB/MissingIndexInformation.php @@ -27,16 +27,16 @@ declare(strict_types=1); namespace OC\DB; class MissingIndexInformation { - private $listOfMissingIndexes = []; + private array $listOfMissingIndices = []; - public function addHintForMissingSubject(string $tableName, string $indexName) { - $this->listOfMissingIndexes[] = [ + public function addHintForMissingIndex(string $tableName, string $indexName): void { + $this->listOfMissingIndices[] = [ 'tableName' => $tableName, 'indexName' => $indexName ]; } - public function getListOfMissingIndexes(): array { - return $this->listOfMissingIndexes; + public function getListOfMissingIndices(): array { + return $this->listOfMissingIndices; } } From fc2467c18f0fab8856b00a83082d1f86e6fd4336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 14 Nov 2023 16:07:37 +0100 Subject: [PATCH 3/6] Migrate missing primary key database check to new API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../composer/composer/autoload_classmap.php | 1 + .../composer/composer/autoload_static.php | 1 + apps/settings/lib/AppInfo/Application.php | 2 + .../lib/Controller/CheckSetupController.php | 25 ------ .../DatabaseHasMissingPrimaryKeys.php | 89 +++++++++++++++++++ .../Controller/CheckSetupControllerTest.php | 4 - core/js/setupchecks.js | 12 --- core/js/tests/specs/setupchecksSpec.js | 17 ---- .../DB/MissingPrimaryKeyInformation.php | 4 +- 9 files changed, 95 insertions(+), 60 deletions(-) create mode 100644 apps/settings/lib/SetupChecks/DatabaseHasMissingPrimaryKeys.php diff --git a/apps/settings/composer/composer/autoload_classmap.php b/apps/settings/composer/composer/autoload_classmap.php index 7c1c1534a74..6dbc2518219 100644 --- a/apps/settings/composer/composer/autoload_classmap.php +++ b/apps/settings/composer/composer/autoload_classmap.php @@ -77,6 +77,7 @@ return array( 'OCA\\Settings\\SetupChecks\\CheckUserCertificates' => $baseDir . '/../lib/SetupChecks/CheckUserCertificates.php', 'OCA\\Settings\\SetupChecks\\DatabaseHasMissingColumns' => $baseDir . '/../lib/SetupChecks/DatabaseHasMissingColumns.php', 'OCA\\Settings\\SetupChecks\\DatabaseHasMissingIndices' => $baseDir . '/../lib/SetupChecks/DatabaseHasMissingIndices.php', + 'OCA\\Settings\\SetupChecks\\DatabaseHasMissingPrimaryKeys' => $baseDir . '/../lib/SetupChecks/DatabaseHasMissingPrimaryKeys.php', 'OCA\\Settings\\SetupChecks\\DefaultPhoneRegionSet' => $baseDir . '/../lib/SetupChecks/DefaultPhoneRegionSet.php', 'OCA\\Settings\\SetupChecks\\EmailTestSuccessful' => $baseDir . '/../lib/SetupChecks/EmailTestSuccessful.php', 'OCA\\Settings\\SetupChecks\\FileLocking' => $baseDir . '/../lib/SetupChecks/FileLocking.php', diff --git a/apps/settings/composer/composer/autoload_static.php b/apps/settings/composer/composer/autoload_static.php index 010b19f7243..c05f58ac459 100644 --- a/apps/settings/composer/composer/autoload_static.php +++ b/apps/settings/composer/composer/autoload_static.php @@ -92,6 +92,7 @@ class ComposerStaticInitSettings 'OCA\\Settings\\SetupChecks\\CheckUserCertificates' => __DIR__ . '/..' . '/../lib/SetupChecks/CheckUserCertificates.php', 'OCA\\Settings\\SetupChecks\\DatabaseHasMissingColumns' => __DIR__ . '/..' . '/../lib/SetupChecks/DatabaseHasMissingColumns.php', 'OCA\\Settings\\SetupChecks\\DatabaseHasMissingIndices' => __DIR__ . '/..' . '/../lib/SetupChecks/DatabaseHasMissingIndices.php', + 'OCA\\Settings\\SetupChecks\\DatabaseHasMissingPrimaryKeys' => __DIR__ . '/..' . '/../lib/SetupChecks/DatabaseHasMissingPrimaryKeys.php', 'OCA\\Settings\\SetupChecks\\DefaultPhoneRegionSet' => __DIR__ . '/..' . '/../lib/SetupChecks/DefaultPhoneRegionSet.php', 'OCA\\Settings\\SetupChecks\\EmailTestSuccessful' => __DIR__ . '/..' . '/../lib/SetupChecks/EmailTestSuccessful.php', 'OCA\\Settings\\SetupChecks\\FileLocking' => __DIR__ . '/..' . '/../lib/SetupChecks/FileLocking.php', diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php index 65ef8ac74a4..d96715a9eca 100644 --- a/apps/settings/lib/AppInfo/Application.php +++ b/apps/settings/lib/AppInfo/Application.php @@ -52,6 +52,7 @@ use OCA\Settings\SetupChecks\BruteForceThrottler; use OCA\Settings\SetupChecks\CheckUserCertificates; use OCA\Settings\SetupChecks\DatabaseHasMissingColumns; use OCA\Settings\SetupChecks\DatabaseHasMissingIndices; +use OCA\Settings\SetupChecks\DatabaseHasMissingPrimaryKeys; use OCA\Settings\SetupChecks\DefaultPhoneRegionSet; use OCA\Settings\SetupChecks\EmailTestSuccessful; use OCA\Settings\SetupChecks\FileLocking; @@ -164,6 +165,7 @@ class Application extends App implements IBootstrap { $context->registerSetupCheck(CheckUserCertificates::class); $context->registerSetupCheck(DatabaseHasMissingColumns::class); $context->registerSetupCheck(DatabaseHasMissingIndices::class); + $context->registerSetupCheck(DatabaseHasMissingPrimaryKeys::class); $context->registerSetupCheck(DefaultPhoneRegionSet::class); $context->registerSetupCheck(EmailTestSuccessful::class); $context->registerSetupCheck(FileLocking::class); diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php index 27ee0df4971..7bb2c8319c2 100644 --- a/apps/settings/lib/Controller/CheckSetupController.php +++ b/apps/settings/lib/Controller/CheckSetupController.php @@ -51,7 +51,6 @@ use GuzzleHttp\Exception\ClientException; use OC; use OC\AppFramework\Http; use OC\DB\Connection; -use OC\DB\MissingPrimaryKeyInformation; use OC\DB\SchemaWrapper; use OC\IntegrityCheck\Checker; use OCP\App\IAppManager; @@ -60,7 +59,6 @@ use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI; use OCP\AppFramework\Http\DataDisplayResponse; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\RedirectResponse; -use OCP\DB\Events\AddMissingPrimaryKeyEvent; use OCP\DB\Types; use OCP\EventDispatcher\IEventDispatcher; use OCP\Http\Client\IClientService; @@ -415,28 +413,6 @@ Raw output return $recommendations; } - protected function hasMissingPrimaryKeys(): array { - $info = new MissingPrimaryKeyInformation(); - // Dispatch event so apps can also hint for pending key updates if needed - $event = new AddMissingPrimaryKeyEvent(); - $this->dispatcher->dispatchTyped($event); - $missingKeys = $event->getMissingPrimaryKeys(); - - if (!empty($missingKeys)) { - $schema = new SchemaWrapper(\OCP\Server::get(Connection::class)); - foreach ($missingKeys as $missingKey) { - if ($schema->hasTable($missingKey['tableName'])) { - $table = $schema->getTable($missingKey['tableName']); - if (!$table->hasPrimaryKey()) { - $info->addHintForMissingSubject($missingKey['tableName']); - } - } - } - } - - return $info->getListOfMissingPrimaryKeys(); - } - protected function isSqliteUsed() { return str_contains($this->config->getSystemValue('dbtype'), 'sqlite'); } @@ -653,7 +629,6 @@ Raw output 'codeIntegrityCheckerDocumentation' => $this->urlGenerator->linkToDocs('admin-code-integrity'), 'OpcacheSetupRecommendations' => $this->getOpcacheSetupRecommendations(), 'isSettimelimitAvailable' => $this->isSettimelimitAvailable(), - 'missingPrimaryKeys' => $this->hasMissingPrimaryKeys(), 'isSqliteUsed' => $this->isSqliteUsed(), 'databaseConversionDocumentation' => $this->urlGenerator->linkToDocs('admin-db-conversion'), 'appDirsWithDifferentOwner' => $this->getAppDirsWithDifferentOwner(), diff --git a/apps/settings/lib/SetupChecks/DatabaseHasMissingPrimaryKeys.php b/apps/settings/lib/SetupChecks/DatabaseHasMissingPrimaryKeys.php new file mode 100644 index 00000000000..ca872fa265c --- /dev/null +++ b/apps/settings/lib/SetupChecks/DatabaseHasMissingPrimaryKeys.php @@ -0,0 +1,89 @@ + + * + * @author Côme Chilliet + * + * @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 . + * + */ +namespace OCA\Settings\SetupChecks; + +use OC\DB\Connection; +use OC\DB\MissingPrimaryKeyInformation; +use OC\DB\SchemaWrapper; +use OCP\DB\Events\AddMissingPrimaryKeyEvent; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\IL10N; +use OCP\SetupCheck\ISetupCheck; +use OCP\SetupCheck\SetupResult; + +class DatabaseHasMissingPrimaryKeys implements ISetupCheck { + public function __construct( + private IL10N $l10n, + private Connection $connection, + private IEventDispatcher $dispatcher, + ) { + } + + public function getCategory(): string { + return 'database'; + } + + public function getName(): string { + return $this->l10n->t('Database missing primary keys'); + } + + private function getMissingPrimaryKeys(): array { + $primaryKeyInfo = new MissingPrimaryKeyInformation(); + // Dispatch event so apps can also hint for pending primary key updates if needed + $event = new AddMissingPrimaryKeyEvent(); + $this->dispatcher->dispatchTyped($event); + $missingPrimaryKeys = $event->getMissingPrimaryKeys(); + + if (!empty($missingPrimaryKeys)) { + $schema = new SchemaWrapper($this->connection); + foreach ($missingPrimaryKeys as $missingPrimaryKey) { + if ($schema->hasTable($missingPrimaryKey['tableName'])) { + $table = $schema->getTable($missingPrimaryKey['tableName']); + if (!$table->hasPrimaryKey()) { + $primaryKeyInfo->addHintForMissingPrimaryKey($missingPrimaryKey['tableName']); + } + } + } + } + + return $primaryKeyInfo->getListOfMissingPrimaryKeys(); + } + + public function run(): SetupResult { + $missingPrimaryKeys = $this->getMissingPrimaryKeys(); + if (empty($missingPrimaryKeys)) { + return SetupResult::success('None'); + } else { + $list = ''; + foreach ($missingPrimaryKeys as $missingPrimaryKey) { + $list .= "\n".$this->l10n->t('Missing primary key on table "%s".', [$missingPrimaryKey['tableName']]); + } + return SetupResult::info( + $this->l10n->t('The database is missing some primary keys. Due to the fact that adding primary keys on big tables could take some time they were not added automatically. By running "occ db:add-missing-primary-keys" those missing primary keys could be added manually while the instance keeps running.').$list + ); + } + } +} diff --git a/apps/settings/tests/Controller/CheckSetupControllerTest.php b/apps/settings/tests/Controller/CheckSetupControllerTest.php index a493722a3ce..fe299b6e799 100644 --- a/apps/settings/tests/Controller/CheckSetupControllerTest.php +++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php @@ -178,7 +178,6 @@ class CheckSetupControllerTest extends TestCase { 'getCurlVersion', 'isPhpOutdated', 'getOpcacheSetupRecommendations', - 'hasMissingPrimaryKeys', 'isSqliteUsed', 'isPHPMailerUsed', 'getAppDirsWithDifferentOwner', @@ -228,9 +227,6 @@ class CheckSetupControllerTest extends TestCase { ->expects($this->once()) ->method('getOpcacheSetupRecommendations') ->willReturn(['recommendation1', 'recommendation2']); - $this->checkSetupController - ->method('hasMissingPrimaryKeys') - ->willReturn([]); $this->checkSetupController ->method('isSqliteUsed') ->willReturn(false); diff --git a/core/js/setupchecks.js b/core/js/setupchecks.js index f926d1534a5..24fec85aeb3 100644 --- a/core/js/setupchecks.js +++ b/core/js/setupchecks.js @@ -258,18 +258,6 @@ type: OC.SetupChecks.MESSAGE_TYPE_WARNING }); } - if (data.missingPrimaryKeys.length > 0) { - var listOfMissingPrimaryKeys = ""; - data.missingPrimaryKeys.forEach(function(element){ - listOfMissingPrimaryKeys += '
  • '; - listOfMissingPrimaryKeys += t('core', 'Missing primary key on table "{tableName}".', element); - listOfMissingPrimaryKeys += '
  • '; - }); - messages.push({ - msg: t('core', 'The database is missing some primary keys. Due to the fact that adding primary keys on big tables could take some time they were not added automatically. By running "occ db:add-missing-primary-keys" those missing primary keys could be added manually while the instance keeps running.') + '
      ' + listOfMissingPrimaryKeys + '
    ', - type: OC.SetupChecks.MESSAGE_TYPE_INFO - }) - } if (!data.isImagickEnabled) { messages.push({ msg: t( diff --git a/core/js/tests/specs/setupchecksSpec.js b/core/js/tests/specs/setupchecksSpec.js index d48f92d5dc3..9020a895af5 100644 --- a/core/js/tests/specs/setupchecksSpec.js +++ b/core/js/tests/specs/setupchecksSpec.js @@ -229,7 +229,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingPrimaryKeys: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -280,7 +279,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingPrimaryKeys: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -331,7 +329,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingPrimaryKeys: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -382,7 +379,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingPrimaryKeys: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -431,7 +427,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingPrimaryKeys: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -483,7 +478,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: false, - missingPrimaryKeys: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -533,7 +527,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingPrimaryKeys: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -614,7 +607,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingPrimaryKeys: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -670,7 +662,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: ['recommendation1', 'recommendation2'], isSettimelimitAvailable: true, - missingPrimaryKeys: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -719,7 +710,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingPrimaryKeys: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -772,7 +762,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingPrimaryKeys: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -822,7 +811,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingPrimaryKeys: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -869,7 +857,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingPrimaryKeys: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -919,7 +906,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingPrimaryKeys: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -969,7 +955,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingPrimaryKeys: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -1018,7 +1003,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingPrimaryKeys: [], cronErrors: [], cronInfo: { diffInSeconds: 0 @@ -1074,7 +1058,6 @@ describe('OC.SetupChecks tests', function() { hasPassedCodeIntegrityCheck: true, OpcacheSetupRecommendations: [], isSettimelimitAvailable: true, - missingPrimaryKeys: [], cronErrors: [], cronInfo: { diffInSeconds: 0 diff --git a/lib/private/DB/MissingPrimaryKeyInformation.php b/lib/private/DB/MissingPrimaryKeyInformation.php index f28c8cfb352..42e5584291c 100644 --- a/lib/private/DB/MissingPrimaryKeyInformation.php +++ b/lib/private/DB/MissingPrimaryKeyInformation.php @@ -26,9 +26,9 @@ declare(strict_types=1); namespace OC\DB; class MissingPrimaryKeyInformation { - private $listOfMissingPrimaryKeys = []; + private array $listOfMissingPrimaryKeys = []; - public function addHintForMissingSubject(string $tableName) { + public function addHintForMissingPrimaryKey(string $tableName): void { $this->listOfMissingPrimaryKeys[] = [ 'tableName' => $tableName, ]; From b75affa7935305993b4b1786e9a1124b2263907c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 14 Nov 2023 16:19:16 +0100 Subject: [PATCH 4/6] Switch from deprecated hasPrimaryKey to getPrimaryKey function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/settings/lib/SetupChecks/DatabaseHasMissingPrimaryKeys.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/settings/lib/SetupChecks/DatabaseHasMissingPrimaryKeys.php b/apps/settings/lib/SetupChecks/DatabaseHasMissingPrimaryKeys.php index ca872fa265c..9609fe117bb 100644 --- a/apps/settings/lib/SetupChecks/DatabaseHasMissingPrimaryKeys.php +++ b/apps/settings/lib/SetupChecks/DatabaseHasMissingPrimaryKeys.php @@ -62,7 +62,7 @@ class DatabaseHasMissingPrimaryKeys implements ISetupCheck { foreach ($missingPrimaryKeys as $missingPrimaryKey) { if ($schema->hasTable($missingPrimaryKey['tableName'])) { $table = $schema->getTable($missingPrimaryKey['tableName']); - if (!$table->hasPrimaryKey()) { + if ($table->getPrimaryKey() === null) { $primaryKeyInfo->addHintForMissingPrimaryKey($missingPrimaryKey['tableName']); } } From bd9a5df5d18cf24b772d4e9315f656d3d8de65eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 14 Nov 2023 17:05:38 +0100 Subject: [PATCH 5/6] fix(tests) Fix CheckSetupControllerTest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/settings/tests/Controller/CheckSetupControllerTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/settings/tests/Controller/CheckSetupControllerTest.php b/apps/settings/tests/Controller/CheckSetupControllerTest.php index fe299b6e799..65ed93523c7 100644 --- a/apps/settings/tests/Controller/CheckSetupControllerTest.php +++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php @@ -329,8 +329,6 @@ class CheckSetupControllerTest extends TestCase { 'isSettimelimitAvailable' => true, 'isSqliteUsed' => false, 'databaseConversionDocumentation' => 'http://docs.example.org/server/go.php?to=admin-db-conversion', - 'missingIndexes' => [], - 'missingPrimaryKeys' => [], 'appDirsWithDifferentOwner' => [], 'isImagickEnabled' => false, 'areWebauthnExtensionsEnabled' => false, From e57d31ffb08cf247d7abbdd54089922a22c48de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 23 Nov 2023 10:29:10 +0100 Subject: [PATCH 6/6] Missing things in database should be warning, not info MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/settings/lib/SetupChecks/DatabaseHasMissingColumns.php | 2 +- apps/settings/lib/SetupChecks/DatabaseHasMissingIndices.php | 2 +- apps/settings/lib/SetupChecks/DatabaseHasMissingPrimaryKeys.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/settings/lib/SetupChecks/DatabaseHasMissingColumns.php b/apps/settings/lib/SetupChecks/DatabaseHasMissingColumns.php index 946f357a04b..b062eb49372 100644 --- a/apps/settings/lib/SetupChecks/DatabaseHasMissingColumns.php +++ b/apps/settings/lib/SetupChecks/DatabaseHasMissingColumns.php @@ -81,7 +81,7 @@ class DatabaseHasMissingColumns implements ISetupCheck { foreach ($missingColumns as $missingColumn) { $list .= "\n".$this->l10n->t('Missing optional column "%s" in table "%s".', [$missingColumn['columnName'], $missingColumn['tableName']]); } - return SetupResult::info( + return SetupResult::warning( $this->l10n->t('The database is missing some optional columns. Due to the fact that adding columns on big tables could take some time they were not added automatically when they can be optional. By running "occ db:add-missing-columns" those missing columns could be added manually while the instance keeps running. Once the columns are added some features might improve responsiveness or usability.').$list ); } diff --git a/apps/settings/lib/SetupChecks/DatabaseHasMissingIndices.php b/apps/settings/lib/SetupChecks/DatabaseHasMissingIndices.php index b19c3abb690..ccf6bbb52d0 100644 --- a/apps/settings/lib/SetupChecks/DatabaseHasMissingIndices.php +++ b/apps/settings/lib/SetupChecks/DatabaseHasMissingIndices.php @@ -81,7 +81,7 @@ class DatabaseHasMissingIndices implements ISetupCheck { foreach ($missingIndices as $missingIndex) { $list .= "\n".$this->l10n->t('Missing optional index "%s" in table "%s".', [$missingIndex['indexName'], $missingIndex['tableName']]); } - return SetupResult::info( + return SetupResult::warning( $this->l10n->t('The database is missing some indexes. Due to the fact that adding indexes on big tables could take some time they were not added automatically. By running "occ db:add-missing-indices" those missing indexes could be added manually while the instance keeps running. Once the indexes are added queries to those tables are usually much faster.').$list ); } diff --git a/apps/settings/lib/SetupChecks/DatabaseHasMissingPrimaryKeys.php b/apps/settings/lib/SetupChecks/DatabaseHasMissingPrimaryKeys.php index 9609fe117bb..5ef65e63eff 100644 --- a/apps/settings/lib/SetupChecks/DatabaseHasMissingPrimaryKeys.php +++ b/apps/settings/lib/SetupChecks/DatabaseHasMissingPrimaryKeys.php @@ -81,7 +81,7 @@ class DatabaseHasMissingPrimaryKeys implements ISetupCheck { foreach ($missingPrimaryKeys as $missingPrimaryKey) { $list .= "\n".$this->l10n->t('Missing primary key on table "%s".', [$missingPrimaryKey['tableName']]); } - return SetupResult::info( + return SetupResult::warning( $this->l10n->t('The database is missing some primary keys. Due to the fact that adding primary keys on big tables could take some time they were not added automatically. By running "occ db:add-missing-primary-keys" those missing primary keys could be added manually while the instance keeps running.').$list ); }