MysqlRowFormat.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\SetupChecks;
  8. use Doctrine\DBAL\Platforms\MySQLPlatform;
  9. use OC\DB\Connection;
  10. use OCP\IConfig;
  11. use OCP\IL10N;
  12. use OCP\IURLGenerator;
  13. use OCP\SetupCheck\ISetupCheck;
  14. use OCP\SetupCheck\SetupResult;
  15. class MysqlRowFormat implements ISetupCheck {
  16. public function __construct(
  17. private IL10N $l10n,
  18. private IConfig $config,
  19. private Connection $connection,
  20. private IURLGenerator $urlGenerator,
  21. ) {
  22. }
  23. public function getName(): string {
  24. return $this->l10n->t('MySQL row format');
  25. }
  26. public function getCategory(): string {
  27. return 'database';
  28. }
  29. public function run(): SetupResult {
  30. if (!$this->connection->getDatabasePlatform() instanceof MySQLPlatform) {
  31. return SetupResult::success($this->l10n->t('You are not using MySQL'));
  32. }
  33. $wrongRowFormatTables = $this->getRowNotDynamicTables();
  34. if (empty($wrongRowFormatTables)) {
  35. return SetupResult::success($this->l10n->t('None of your table use ROW_FORMAT=Compressed'));
  36. }
  37. return SetupResult::warning(
  38. $this->l10n->n(
  39. 'Table %s is not using ROW_FORMAT=Dynamic. This format offers the best database performances for Nextcloud. Please change the row format to Dynamic.',
  40. 'Some tables are not using ROW_FORMAT=Dynamic. This format offers the best database performances for Nextcloud. Please change the row format to Dynamic on the following tables: %s.',
  41. count($wrongRowFormatTables),
  42. [implode(', ', $wrongRowFormatTables)],
  43. ),
  44. 'https://dev.mysql.com/doc/refman/en/innodb-row-format.html',
  45. );
  46. }
  47. /**
  48. * @return string[]
  49. */
  50. private function getRowNotDynamicTables(): array {
  51. $sql = 'SELECT table_name
  52. FROM information_schema.tables
  53. WHERE table_schema = ?
  54. AND table_name LIKE "*PREFIX*%"
  55. AND row_format != "Dynamic";';
  56. return $this->connection->executeQuery(
  57. $sql,
  58. [$this->config->getSystemValueString('dbname')],
  59. )->fetchFirstColumn();
  60. }
  61. }