1
0

SupportedDatabase.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2021 Morris Jobke <hey@morrisjobke.de>
  5. *
  6. * @author Claas Augner <github@caugner.de>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Vincent Petry <vincent@nextcloud.com>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\Settings\SetupChecks;
  27. use Doctrine\DBAL\Platforms\MySQLPlatform;
  28. use Doctrine\DBAL\Platforms\OraclePlatform;
  29. use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
  30. use Doctrine\DBAL\Platforms\SqlitePlatform;
  31. use OCP\IDBConnection;
  32. use OCP\IL10N;
  33. use OCP\IURLGenerator;
  34. use OCP\SetupCheck\ISetupCheck;
  35. use OCP\SetupCheck\SetupResult;
  36. class SupportedDatabase implements ISetupCheck {
  37. public function __construct(
  38. private IL10N $l10n,
  39. private IURLGenerator $urlGenerator,
  40. private IDBConnection $connection,
  41. ) {
  42. }
  43. public function getCategory(): string {
  44. return 'database';
  45. }
  46. public function getName(): string {
  47. return $this->l10n->t('Database version');
  48. }
  49. public function run(): SetupResult {
  50. $version = null;
  51. $databasePlatform = $this->connection->getDatabasePlatform();
  52. if ($databasePlatform instanceof MySQLPlatform) {
  53. $result = $this->connection->prepare("SHOW VARIABLES LIKE 'version';");
  54. $result->execute();
  55. $row = $result->fetch();
  56. $version = $row['Value'];
  57. $versionlc = strtolower($version);
  58. if (str_contains($versionlc, 'mariadb')) {
  59. if (version_compare($versionlc, '10.2', '<')) {
  60. return SetupResult::warning($this->l10n->t('MariaDB version "%s" is used. Nextcloud 21 and higher do not support this version and require MariaDB 10.2 or higher.', $version));
  61. }
  62. } else {
  63. if (version_compare($versionlc, '8', '<')) {
  64. return SetupResult::warning($this->l10n->t('MySQL version "%s" is used. Nextcloud 21 and higher do not support this version and require MySQL 8.0 or MariaDB 10.2 or higher.', $version));
  65. }
  66. }
  67. } elseif ($databasePlatform instanceof PostgreSQLPlatform) {
  68. $result = $this->connection->prepare('SHOW server_version;');
  69. $result->execute();
  70. $row = $result->fetch();
  71. $version = $row['server_version'];
  72. if (version_compare(strtolower($version), '9.6', '<')) {
  73. return SetupResult::warning($this->l10n->t('PostgreSQL version "%s" is used. Nextcloud 21 and higher do not support this version and require PostgreSQL 9.6 or higher.', $version));
  74. }
  75. } elseif ($databasePlatform instanceof OraclePlatform) {
  76. $version = 'Oracle';
  77. } elseif ($databasePlatform instanceof SqlitePlatform) {
  78. return SetupResult::warning(
  79. $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".'),
  80. $this->urlGenerator->linkToDocs('admin-db-conversion')
  81. );
  82. } else {
  83. return SetupResult::error($this->l10n->t('Unknown database platform'));
  84. }
  85. return SetupResult::success($version);
  86. }
  87. }