1
0

SupportedDatabase.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. private const MIN_POSTGRES = '13';
  23. private const MAX_POSTGRES = '17';
  24. public function __construct(
  25. private IL10N $l10n,
  26. private IURLGenerator $urlGenerator,
  27. private IDBConnection $connection,
  28. ) {
  29. }
  30. public function getCategory(): string {
  31. return 'database';
  32. }
  33. public function getName(): string {
  34. return $this->l10n->t('Database version');
  35. }
  36. public function run(): SetupResult {
  37. $version = null;
  38. $databasePlatform = $this->connection->getDatabasePlatform();
  39. if ($databasePlatform instanceof MySQLPlatform) {
  40. $statement = $this->connection->prepare("SHOW VARIABLES LIKE 'version';");
  41. $result = $statement->execute();
  42. $row = $result->fetch();
  43. $version = $row['Value'];
  44. $versionlc = strtolower($version);
  45. // we only care about X.Y not X.Y.Z differences
  46. [$major, $minor, ] = explode('.', $versionlc);
  47. $versionConcern = $major . '.' . $minor;
  48. if (str_contains($versionlc, 'mariadb')) {
  49. if (version_compare($versionConcern, '10.3', '=')) {
  50. return SetupResult::info(
  51. $this->l10n->t(
  52. '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.',
  53. [
  54. self::MIN_MARIADB,
  55. self::MAX_MARIADB,
  56. ]
  57. ),
  58. );
  59. } elseif (version_compare($versionConcern, self::MIN_MARIADB, '<') || version_compare($versionConcern, self::MAX_MARIADB, '>')) {
  60. return SetupResult::warning(
  61. $this->l10n->t(
  62. 'MariaDB version "%1$s" detected. MariaDB >=%2$s and <=%3$s is suggested for best performance, stability and functionality with this version of Nextcloud.',
  63. [
  64. $version,
  65. self::MIN_MARIADB,
  66. self::MAX_MARIADB,
  67. ],
  68. ),
  69. );
  70. }
  71. } else {
  72. if (version_compare($versionConcern, self::MIN_MYSQL, '<') || version_compare($versionConcern, self::MAX_MYSQL, '>')) {
  73. return SetupResult::warning(
  74. $this->l10n->t(
  75. 'MySQL version "%1$s" detected. MySQL >=%2$s and <=%3$s is suggested for best performance, stability and functionality with this version of Nextcloud.',
  76. [
  77. $version,
  78. self::MIN_MYSQL,
  79. self::MAX_MYSQL,
  80. ],
  81. ),
  82. );
  83. }
  84. }
  85. } elseif ($databasePlatform instanceof PostgreSQLPlatform) {
  86. $statement = $this->connection->prepare('SHOW server_version;');
  87. $result = $statement->execute();
  88. $row = $result->fetch();
  89. $version = $row['server_version'];
  90. $versionlc = strtolower($version);
  91. // we only care about X not X.Y or X.Y.Z differences
  92. [$major, ] = explode('.', $versionlc);
  93. $versionConcern = $major;
  94. if (version_compare($versionConcern, self::MIN_POSTGRES, '<') || version_compare($versionConcern, self::MAX_POSTGRES, '>')) {
  95. return SetupResult::warning(
  96. $this->l10n->t(
  97. 'PostgreSQL version "%1$s" detected. PostgreSQL >=%2$s and <=%3$s is suggested for best performance, stability and functionality with this version of Nextcloud.',
  98. [
  99. $version,
  100. self::MIN_POSTGRES,
  101. self::MAX_POSTGRES,
  102. ])
  103. );
  104. }
  105. } elseif ($databasePlatform instanceof OraclePlatform) {
  106. $version = 'Oracle';
  107. } elseif ($databasePlatform instanceof SqlitePlatform) {
  108. return SetupResult::warning(
  109. $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".'),
  110. $this->urlGenerator->linkToDocs('admin-db-conversion')
  111. );
  112. } else {
  113. return SetupResult::error($this->l10n->t('Unknown database platform'));
  114. }
  115. return SetupResult::success($version);
  116. }
  117. }