SupportedDatabase.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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\MariaDb1027Platform;
  28. use Doctrine\DBAL\Platforms\MySQL57Platform;
  29. use Doctrine\DBAL\Platforms\MySQL80Platform;
  30. use Doctrine\DBAL\Platforms\MySQLPlatform;
  31. use Doctrine\DBAL\Platforms\OraclePlatform;
  32. use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
  33. use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
  34. use Doctrine\DBAL\Platforms\SqlitePlatform;
  35. use OCP\IDBConnection;
  36. use OCP\IL10N;
  37. class SupportedDatabase {
  38. /** @var IL10N */
  39. private $l10n;
  40. /** @var IDBConnection */
  41. private $connection;
  42. private $checked = false;
  43. private $description = '';
  44. public function __construct(IL10N $l10n, IDBConnection $connection) {
  45. $this->l10n = $l10n;
  46. $this->connection = $connection;
  47. }
  48. public function check() {
  49. if ($this->checked === true) {
  50. return;
  51. }
  52. $this->checked = true;
  53. switch (get_class($this->connection->getDatabasePlatform())) {
  54. case MySQL80Platform::class: # extends MySQL57Platform
  55. case MySQL57Platform::class: # extends MySQLPlatform
  56. case MariaDb1027Platform::class: # extends MySQLPlatform
  57. case MySQLPlatform::class:
  58. $result = $this->connection->prepare("SHOW VARIABLES LIKE 'version';");
  59. $result->execute();
  60. $row = $result->fetch();
  61. $version = strtolower($row['Value']);
  62. if (strpos($version, 'mariadb') !== false) {
  63. if (version_compare($version, '10.2', '<')) {
  64. $this->description = $this->l10n->t('MariaDB version "%s" is used. Nextcloud 21 and higher do not support this version and require MariaDB 10.2 or higher.', $row['Value']);
  65. return;
  66. }
  67. } else {
  68. if (version_compare($version, '8', '<')) {
  69. $this->description = $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.', $row['Value']);
  70. return;
  71. }
  72. }
  73. break;
  74. case SqlitePlatform::class:
  75. break;
  76. case PostgreSQL100Platform::class: # extends PostgreSQL94Platform
  77. case PostgreSQL94Platform::class:
  78. $result = $this->connection->prepare('SHOW server_version;');
  79. $result->execute();
  80. $row = $result->fetch();
  81. if (version_compare($row['server_version'], '9.6', '<')) {
  82. $this->description = $this->l10n->t('PostgreSQL version "%s" is used. Nextcloud 21 and higher do not support this version and require PostgreSQL 9.6 or higher.', $row['server_version']);
  83. return;
  84. }
  85. break;
  86. case OraclePlatform::class:
  87. break;
  88. }
  89. }
  90. public function description(): string {
  91. $this->check();
  92. return $this->description;
  93. }
  94. public function severity(): string {
  95. return 'info';
  96. }
  97. public function run(): bool {
  98. $this->check();
  99. return $this->description === '';
  100. }
  101. }