SupportedDatabase.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2021 Morris Jobke <hey@morrisjobke.de>
  5. *
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Settings\SetupChecks;
  25. use Doctrine\DBAL\Platforms\MariaDb1027Platform;
  26. use Doctrine\DBAL\Platforms\MySQL57Platform;
  27. use Doctrine\DBAL\Platforms\MySQL80Platform;
  28. use Doctrine\DBAL\Platforms\MySQLPlatform;
  29. use Doctrine\DBAL\Platforms\OraclePlatform;
  30. use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
  31. use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
  32. use Doctrine\DBAL\Platforms\SqlitePlatform;
  33. use OCP\IDBConnection;
  34. use OCP\IL10N;
  35. class SupportedDatabase {
  36. /** @var IL10N */
  37. private $l10n;
  38. /** @var IDBConnection */
  39. private $connection;
  40. private $checked = false;
  41. private $description = '';
  42. public function __construct(IL10N $l10n, IDBConnection $connection) {
  43. $this->l10n = $l10n;
  44. $this->connection = $connection;
  45. }
  46. public function check() {
  47. if ($this->checked === true) {
  48. return;
  49. }
  50. $this->checked = true;
  51. switch (get_class($this->connection->getDatabasePlatform())) {
  52. case MySQL80Platform::class: # extends MySQL57Platform
  53. case MySQL57Platform::class: # extends MySQLPlatform
  54. case MariaDb1027Platform::class: # extends MySQLPlatform
  55. case MySQLPlatform::class:
  56. $result = $this->connection->prepare('SHOW VARIABLES LIKE "version";');
  57. $result->execute();
  58. $row = $result->fetch();
  59. $version = strtolower($row['Value']);
  60. if (strpos($version, 'mariadb') !== false) {
  61. if (version_compare($version, '10.2', '<')) {
  62. $this->description = $this->l10n->t('MariaDB version "%s" is used. Nextcloud 21 will no longer support this version and requires MariaDB 10.2 or higher.', $row['Value']);
  63. return;
  64. }
  65. } else {
  66. if (version_compare($version, '8', '<')) {
  67. $this->description = $this->l10n->t('MySQL version "%s" is used. Nextcloud 21 will no longer support this version and requires MySQL 8 or higher.', $row['Value']);
  68. return;
  69. }
  70. }
  71. break;
  72. case SqlitePlatform::class:
  73. break;
  74. case PostgreSQL100Platform::class: # extends PostgreSQL94Platform
  75. case PostgreSQL94Platform::class:
  76. $result = $this->connection->prepare('SHOW server_version;');
  77. $result->execute();
  78. $row = $result->fetch();
  79. if (version_compare($row['server_version'], '9.6', '<')) {
  80. $this->description = $this->l10n->t('PostgreSQL version "%s" is used. Nextcloud 21 will no longer support this version and requires PostgreSQL 9.6 or higher.', $row['server_version']);
  81. return;
  82. }
  83. break;
  84. case OraclePlatform::class:
  85. break;
  86. }
  87. }
  88. public function description(): string {
  89. $this->check();
  90. return $this->description;
  91. }
  92. public function severity(): string {
  93. return 'info';
  94. }
  95. public function run(): bool {
  96. $this->check();
  97. return $this->description === '';
  98. }
  99. }