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 ;
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' ;
2025-07-10 10:18:50 -04:00
private const MAX_MARIADB = '11.8' ;
2024-06-27 10:22:42 -04:00
private const MIN_MYSQL = '8.0' ;
private const MAX_MYSQL = '8.4' ;
2025-11-03 05:34:05 -05:00
private const MIN_POSTGRES = '14' ;
private const MAX_POSTGRES = '18' ;
2025-11-27 08:35:54 -05:00
private const MIN_ORACLE = '12.2' ;
private const MAX_ORACLE = '26' ;
2024-06-27 10:22:42 -04:00
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 {
2025-10-10 10:09:18 -04:00
$databasePlatform = $this -> connection -> getDatabaseProvider ();
if ( $databasePlatform === IDBConnection :: PLATFORM_MYSQL || $databasePlatform === IDBConnection :: PLATFORM_MARIADB ) {
2024-06-25 17:52:11 -04:00
$statement = $this -> connection -> prepare ( " SHOW VARIABLES LIKE 'version'; " );
$result = $statement -> execute ();
2025-11-17 06:20:11 -05:00
$row = $result -> fetchAssociative ();
2023-10-24 05:40:03 -04:00
$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
}
2025-10-10 10:09:18 -04:00
} elseif ( $databasePlatform === IDBConnection :: PLATFORM_POSTGRES ) {
2024-06-25 17:52:11 -04:00
$statement = $this -> connection -> prepare ( 'SHOW server_version;' );
$result = $statement -> execute ();
2025-11-17 06:20:11 -05:00
$row = $result -> fetchAssociative ();
2023-10-24 05:40:03 -04:00
$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 ;
2024-11-12 20:50:13 -05:00
if ( version_compare ( $versionConcern , self :: MIN_POSTGRES , '<' ) || version_compare ( $versionConcern , self :: MAX_POSTGRES , '>' )) {
return SetupResult :: warning (
$this -> l10n -> t (
'PostgreSQL version "%1$s" detected. PostgreSQL >=%2$s and <=%3$s is suggested for best performance, stability and functionality with this version of Nextcloud.' ,
[
$version ,
self :: MIN_POSTGRES ,
self :: MAX_POSTGRES ,
])
);
2023-10-24 05:40:03 -04:00
}
2025-10-10 10:09:18 -04:00
} elseif ( $databasePlatform === IDBConnection :: PLATFORM_ORACLE ) {
2025-11-27 08:35:54 -05:00
$result = $this -> connection -> executeQuery ( 'SELECT VERSION FROM PRODUCT_COMPONENT_VERSION' );
$version = $result -> fetchOne ();
$result -> closeCursor ();
$versionLower = strtolower ( $version );
// we only care about X.Y not X.Y.Z differences
[ $major , $minor , ] = explode ( '.' , $versionLower );
$versionConcern = $major . '.' . $minor ;
if ( version_compare ( $versionConcern , self :: MIN_ORACLE , '<' ) || version_compare ( $versionConcern , self :: MAX_ORACLE , '>' )) {
$extendedWarning = '' ;
if ( version_compare ( $versionConcern , self :: MIN_ORACLE , '<' )) {
$extendedWarning = " \n " . $this -> l10n -> t ( 'Nextcloud %d does not support your current version, so be sure to update the database before updating your Nextcloud Server.' , [ 33 ]);
}
return SetupResult :: warning (
$this -> l10n -> t (
'Oracle version "%1$s" detected. Oracle >=%2$s and <=%3$s is suggested for best performance, stability and functionality with this version of Nextcloud.' ,
[
$version ,
self :: MIN_ORACLE ,
self :: MAX_ORACLE ,
])
. $extendedWarning
);
}
2025-10-10 10:09:18 -04:00
} elseif ( $databasePlatform === IDBConnection :: PLATFORM_SQLITE ) {
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
}
}