1
0

MysqlRowFormat.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 tables use ROW_FORMAT=Compressed'));
  36. }
  37. return SetupResult::warning(
  38. $this->l10n->t(
  39. 'Incorrect row format found in your database. ROW_FORMAT=Dynamic offers the best database performances for Nextcloud. Please update row format on the following list: %s.',
  40. [implode(', ', $wrongRowFormatTables)],
  41. ),
  42. 'https://dev.mysql.com/doc/refman/en/innodb-row-format.html',
  43. );
  44. }
  45. /**
  46. * @return string[]
  47. */
  48. private function getRowNotDynamicTables(): array {
  49. $sql = 'SELECT table_name
  50. FROM information_schema.tables
  51. WHERE table_schema = ?
  52. AND table_name LIKE "*PREFIX*%"
  53. AND row_format != "Dynamic";';
  54. return $this->connection->executeQuery(
  55. $sql,
  56. [$this->config->getSystemValueString('dbname')],
  57. )->fetchFirstColumn();
  58. }
  59. }