SupportedDatabase.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2021 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 Doctrine\DBAL\Platforms\OraclePlatform;
  10. use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
  11. use Doctrine\DBAL\Platforms\SqlitePlatform;
  12. use OCP\IDBConnection;
  13. use OCP\IL10N;
  14. use OCP\IURLGenerator;
  15. use OCP\SetupCheck\ISetupCheck;
  16. use OCP\SetupCheck\SetupResult;
  17. class SupportedDatabase implements ISetupCheck {
  18. private const MIN_MARIADB = '10.6';
  19. private const MAX_MARIADB = '11.4';
  20. private const MIN_MYSQL = '8.0';
  21. private const MAX_MYSQL = '8.4';
  22. public function __construct(
  23. private IL10N $l10n,
  24. private IURLGenerator $urlGenerator,
  25. private IDBConnection $connection,
  26. ) {
  27. }
  28. public function getCategory(): string {
  29. return 'database';
  30. }
  31. public function getName(): string {
  32. return $this->l10n->t('Database version');
  33. }
  34. public function run(): SetupResult {
  35. $version = null;
  36. $databasePlatform = $this->connection->getDatabasePlatform();
  37. if ($databasePlatform instanceof MySQLPlatform) {
  38. $statement = $this->connection->prepare("SHOW VARIABLES LIKE 'version';");
  39. $result = $statement->execute();
  40. $row = $result->fetch();
  41. $version = $row['Value'];
  42. $versionlc = strtolower($version);
  43. // we only care about X.Y not X.Y.Z differences
  44. [$major, $minor, ] = explode('.', $versionlc);
  45. $versionConcern = $major . '.' . $minor;
  46. if (str_contains($versionlc, 'mariadb')) {
  47. if (version_compare($versionConcern, '10.3', '=')) {
  48. return SetupResult::info(
  49. $this->l10n->t(
  50. 'MariaDB version 10.3 detected, this version is end-of-life and only supported as part of Ubuntu 20.04. MariaDB >=%1$s and <=%2$s is suggested for best performance, stability and functionality with this version of Nextcloud.',
  51. [
  52. self::MIN_MARIADB,
  53. self::MAX_MARIADB,
  54. ]
  55. ),
  56. );
  57. } elseif (version_compare($versionConcern, self::MIN_MARIADB, '<') || version_compare($versionConcern, self::MAX_MARIADB, '>')) {
  58. return SetupResult::warning(
  59. $this->l10n->t(
  60. 'MariaDB version "%1$s" detected. MariaDB >=%2$s and <=%3$s is suggested for best performance, stability and functionality with this version of Nextcloud.',
  61. [
  62. $version,
  63. self::MIN_MARIADB,
  64. self::MAX_MARIADB,
  65. ],
  66. ),
  67. );
  68. }
  69. } else {
  70. if (version_compare($versionConcern, self::MIN_MYSQL, '<') || version_compare($versionConcern, self::MAX_MYSQL, '>')) {
  71. return SetupResult::warning(
  72. $this->l10n->t(
  73. 'MySQL version "%1$s" detected. MySQL >=%2$s and <=%3$s is suggested for best performance, stability and functionality with this version of Nextcloud.',
  74. [
  75. $version,
  76. self::MIN_MYSQL,
  77. self::MAX_MYSQL,
  78. ],
  79. ),
  80. );
  81. }
  82. }
  83. } elseif ($databasePlatform instanceof PostgreSQLPlatform) {
  84. $statement = $this->connection->prepare('SHOW server_version;');
  85. $result = $statement->execute();
  86. $row = $result->fetch();
  87. $version = $row['server_version'];
  88. $versionlc = strtolower($version);
  89. // we only care about X not X.Y or X.Y.Z differences
  90. [$major, ] = explode('.', $versionlc);
  91. $versionConcern = $major;
  92. if (version_compare($versionConcern, '12', '<') || version_compare($versionConcern, '16', '>')) {
  93. return SetupResult::warning($this->l10n->t('PostgreSQL version "%s" detected. PostgreSQL >=12 and <=16 is suggested for best performance, stability and functionality with this version of Nextcloud.', $version));
  94. }
  95. } elseif ($databasePlatform instanceof OraclePlatform) {
  96. $version = 'Oracle';
  97. } elseif ($databasePlatform instanceof SqlitePlatform) {
  98. return SetupResult::warning(
  99. $this->l10n->t('SQLite is currently being used as the backend database. For larger installations we recommend that you switch to a different database backend. This is particularly recommended when using the desktop client for file synchronisation. To migrate to another database use the command line tool: "occ db:convert-type".'),
  100. $this->urlGenerator->linkToDocs('admin-db-conversion')
  101. );
  102. } else {
  103. return SetupResult::error($this->l10n->t('Unknown database platform'));
  104. }
  105. return SetupResult::success($version);
  106. }
  107. }