2021-01-07 10:26:51 -05:00
< ? php
declare ( strict_types = 1 );
/**
2024-06-03 04:23:34 -04:00
* SPDX - FileCopyrightText : 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX - License - Identifier : AGPL - 3.0 - or - later
2021-01-07 10:26:51 -05:00
*/
namespace OCA\Settings\SetupChecks ;
2021-01-12 03:39:18 -05:00
use Doctrine\DBAL\Platforms\MySQLPlatform ;
2021-01-07 10:26:51 -05:00
use Doctrine\DBAL\Platforms\OraclePlatform ;
2023-10-24 05:40:03 -04:00
use Doctrine\DBAL\Platforms\PostgreSQLPlatform ;
2021-01-07 10:26:51 -05:00
use Doctrine\DBAL\Platforms\SqlitePlatform ;
use OCP\IDBConnection ;
use OCP\IL10N ;
2023-11-16 05:48:04 -05:00
use OCP\IURLGenerator ;
2023-10-02 05:21:45 -04:00
use OCP\SetupCheck\ISetupCheck ;
use OCP\SetupCheck\SetupResult ;
2021-01-07 10:26:51 -05:00
2023-10-02 05:21:45 -04:00
class SupportedDatabase implements ISetupCheck {
2024-06-27 10:22:42 -04:00
private const MIN_MARIADB = '10.6' ;
private const MAX_MARIADB = '11.4' ;
private const MIN_MYSQL = '8.0' ;
private const MAX_MYSQL = '8.4' ;
2023-10-02 05:21:45 -04:00
public function __construct (
private IL10N $l10n ,
2023-11-16 05:48:04 -05:00
private IURLGenerator $urlGenerator ,
2023-10-02 05:21:45 -04:00
private IDBConnection $connection ,
) {
}
2021-01-07 10:26:51 -05:00
2023-10-02 05:21:45 -04:00
public function getCategory () : string {
return 'database' ;
2021-01-07 10:26:51 -05:00
}
2023-10-02 05:21:45 -04:00
public function getName () : string {
2023-10-24 05:40:03 -04:00
return $this -> l10n -> t ( 'Database version' );
2023-10-02 05:21:45 -04:00
}
2021-01-07 10:26:51 -05:00
2023-10-02 05:21:45 -04:00
public function run () : SetupResult {
2023-10-24 05:40:03 -04:00
$version = null ;
$databasePlatform = $this -> connection -> getDatabasePlatform ();
if ( $databasePlatform instanceof MySQLPlatform ) {
2024-06-25 17:52:11 -04:00
$statement = $this -> connection -> prepare ( " SHOW VARIABLES LIKE 'version'; " );
$result = $statement -> execute ();
2023-10-24 05:40:03 -04:00
$row = $result -> fetch ();
$version = $row [ 'Value' ];
$versionlc = strtolower ( $version );
2024-05-10 08:23:32 -04:00
// we only care about X.Y not X.Y.Z differences
[ $major , $minor , ] = explode ( '.' , $versionlc );
2024-05-10 09:12:43 -04:00
$versionConcern = $major . '.' . $minor ;
2023-10-24 05:40:03 -04:00
if ( str_contains ( $versionlc , 'mariadb' )) {
2024-06-25 17:52:11 -04:00
if ( version_compare ( $versionConcern , '10.3' , '=' )) {
2024-06-27 10:22:42 -04:00
return SetupResult :: info (
$this -> l10n -> t (
'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.' ,
[
self :: MIN_MARIADB ,
self :: MAX_MARIADB ,
]
),
);
} elseif ( version_compare ( $versionConcern , self :: MIN_MARIADB , '<' ) || version_compare ( $versionConcern , self :: MAX_MARIADB , '>' )) {
return SetupResult :: warning (
$this -> l10n -> t (
'MariaDB version "%1$s" detected. MariaDB >=%2$s and <=%3$s is suggested for best performance, stability and functionality with this version of Nextcloud.' ,
[
$version ,
self :: MIN_MARIADB ,
self :: MAX_MARIADB ,
],
),
);
2021-01-07 10:26:51 -05:00
}
2023-10-24 05:40:03 -04:00
} else {
2024-06-27 10:22:42 -04:00
if ( version_compare ( $versionConcern , self :: MIN_MYSQL , '<' ) || version_compare ( $versionConcern , self :: MAX_MYSQL , '>' )) {
return SetupResult :: warning (
$this -> l10n -> t (
'MySQL version "%1$s" detected. MySQL >=%2$s and <=%3$s is suggested for best performance, stability and functionality with this version of Nextcloud.' ,
[
$version ,
self :: MIN_MYSQL ,
self :: MAX_MYSQL ,
],
),
);
2021-01-07 10:26:51 -05:00
}
2023-10-24 05:40:03 -04:00
}
} elseif ( $databasePlatform instanceof PostgreSQLPlatform ) {
2024-06-25 17:52:11 -04:00
$statement = $this -> connection -> prepare ( 'SHOW server_version;' );
$result = $statement -> execute ();
2023-10-24 05:40:03 -04:00
$row = $result -> fetch ();
$version = $row [ 'server_version' ];
2024-05-10 08:28:05 -04:00
$versionlc = strtolower ( $version );
2024-05-10 08:49:02 -04:00
// we only care about X not X.Y or X.Y.Z differences
[ $major , ] = explode ( '.' , $versionlc );
2024-05-10 09:12:43 -04:00
$versionConcern = $major ;
if ( version_compare ( $versionConcern , '12' , '<' ) || version_compare ( $versionConcern , '16' , '>' )) {
2024-05-09 10:55:36 -04:00
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 ));
2023-10-24 05:40:03 -04:00
}
} elseif ( $databasePlatform instanceof OraclePlatform ) {
$version = 'Oracle' ;
} elseif ( $databasePlatform instanceof SqlitePlatform ) {
2023-11-16 05:48:04 -05:00
return SetupResult :: warning (
$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".' ),
$this -> urlGenerator -> linkToDocs ( 'admin-db-conversion' )
);
2023-10-24 05:40:03 -04:00
} else {
2023-11-21 09:45:33 -05:00
return SetupResult :: error ( $this -> l10n -> t ( 'Unknown database platform' ));
2021-01-07 10:26:51 -05:00
}
2023-10-24 05:40:03 -04:00
return SetupResult :: success ( $version );
2021-01-07 10:26:51 -05:00
}
}