From a2d822ad72b3eaa1b8808f2379a8ca1ae3ef15fc Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 27 May 2016 16:15:57 +0200 Subject: [PATCH] Overhauled db setup --- .../install/files/lib/system/WCF.class.php | 3 +- .../files/lib/system/WCFSetup.class.php | 98 +++------- wcfsetup/setup/lang/setup_de.xml | 5 +- wcfsetup/setup/lang/setup_en.xml | 5 +- wcfsetup/setup/template/stepConfigureDB.tpl | 11 -- .../template/stepShowSystemRequirements.tpl | 184 +++++++++--------- 6 files changed, 122 insertions(+), 184 deletions(-) diff --git a/wcfsetup/install/files/lib/system/WCF.class.php b/wcfsetup/install/files/lib/system/WCF.class.php index 80611c82b9..40f64c8d17 100644 --- a/wcfsetup/install/files/lib/system/WCF.class.php +++ b/wcfsetup/install/files/lib/system/WCF.class.php @@ -301,11 +301,10 @@ class WCF { // get configuration $dbHost = $dbUser = $dbPassword = $dbName = ''; $dbPort = 0; - $dbClass = MySQLDatabase::class; require(WCF_DIR.'config.inc.php'); // create database connection - self::$dbObj = new $dbClass($dbHost, $dbUser, $dbPassword, $dbName, $dbPort); + self::$dbObj = new MySQLDatabase($dbHost, $dbUser, $dbPassword, $dbName, $dbPort); } /** diff --git a/wcfsetup/install/files/lib/system/WCFSetup.class.php b/wcfsetup/install/files/lib/system/WCFSetup.class.php index 9b64510fc2..4302e5720e 100644 --- a/wcfsetup/install/files/lib/system/WCFSetup.class.php +++ b/wcfsetup/install/files/lib/system/WCFSetup.class.php @@ -89,15 +89,6 @@ class WCFSetup extends WCF { */ protected static $developerMode = 0; - /** - * supported databases - * @var string[][] - */ - protected static $dbClasses = [ - 'MySQLDatabase' => ['class' => MySQLDatabase::class, 'minversion' => '5.1.17']//, // MySQL 5.1.17+ - //'PostgreSQLDatabase' => ['class' => 'wcf\system\database\PostgreSQLDatabase', 'minversion' => '8.2.0'] // PostgreSQL 8.2.0+ - ]; - /** @noinspection PhpMissingParentConstructorInspection */ /** * Calls all init functions of the WCFSetup class and starts the setup process. @@ -143,22 +134,6 @@ class WCFSetup extends WCF { } } - /** - * Gets the available database classes. - * - * @return string[] - */ - protected static function getAvailableDBClasses() { - $availableDBClasses = []; - foreach (self::$dbClasses as $class => $data) { - if (call_user_func([$data['class'], 'isSupported'])) { - $availableDBClasses[$class] = $data; - } - } - - return $availableDBClasses; - } - /** * Gets the selected wcf dir from request. * @@ -389,8 +364,7 @@ class WCFSetup extends WCF { $system['phpVersion']['result'] = (version_compare($comparePhpVersion, '5.5.4') >= 0); // sql - $system['sql']['value'] = array_keys(self::getAvailableDBClasses()); - $system['sql']['result'] = !empty($system['sql']['value']); + $system['sql']['result'] = MySQLDatabase::isSupported(); // upload_max_filesize $system['uploadMaxFilesize']['value'] = ini_get('upload_max_filesize'); @@ -643,8 +617,6 @@ class WCFSetup extends WCF { * Shows the page for configurating the database connection. */ protected function configureDB() { - $availableDBClasses = self::getAvailableDBClasses(); - $dbClass = ''; if (self::$developerMode && isset($_ENV['WCFSETUP_DBHOST'])) { $dbHost = $_ENV['WCFSETUP_DBHOST']; $dbUser = $_ENV['WCFSETUP_DBUSER']; @@ -660,12 +632,6 @@ class WCFSetup extends WCF { $dbNumber = 1; } - // set $dbClass to first item in $availableDBClasses - foreach ($availableDBClasses as $dbClass) { - $dbClass = $dbClass['class']; - break; - } - if (isset($_POST['send']) || (self::$developerMode && isset($_ENV['WCFSETUP_DBHOST']))) { if (isset($_POST['dbHost'])) $dbHost = $_POST['dbHost']; if (isset($_POST['dbUser'])) $dbUser = $_POST['dbUser']; @@ -674,7 +640,6 @@ class WCFSetup extends WCF { // ensure that $dbNumber is zero or a positive integer if (isset($_POST['dbNumber'])) $dbNumber = max(0, intval($_POST['dbNumber'])); - if (isset($_POST['dbClass'])) $dbClass = $_POST['dbClass']; // get port $dbPort = 0; @@ -685,49 +650,43 @@ class WCFSetup extends WCF { // test connection try { - // check db class - $validDB = false; - foreach ($availableDBClasses as $dbData) { - if ($dbData['class'] == $dbClass) { - $validDB = true; - break; - } - } - - if (!$validDB) { - throw new SystemException("Database type '".$dbClass."'. is not available on this system."); - } - // check connection data /** @var \wcf\system\database\Database $db */ - $db = new $dbClass($dbHost, $dbUser, $dbPassword, $dbName, $dbPort, true); + $db = new MySQLDatabase($dbHost, $dbUser, $dbPassword, $dbName, $dbPort, true); $db->connect(); // check sql version - if (!empty($availableDBClasses[$dbClass]['minversion'])) { - $compareSQLVersion = preg_replace('/^(\d+\.\d+\.\d+).*$/', '\\1', $db->getVersion()); - if (!(version_compare($compareSQLVersion, $availableDBClasses[$dbClass]['minversion']) >= 0)) { - throw new SystemException("Insufficient SQL version '".$compareSQLVersion."'. Version '".$availableDBClasses[$dbClass]['minversion']."' or greater is needed."); + $sqlVersion = $db->getVersion(); + $compareSQLVersion = preg_replace('/^(\d+\.\d+\.\d+).*$/', '\\1', $sqlVersion); + if (stripos($sqlVersion, 'MariaDB')) { + // MariaDB 10.0.22+ + if (!(version_compare($compareSQLVersion, '10.0.22') >= 0)) { + throw new SystemException("Insufficient MariaDB version '".$compareSQLVersion."'. Version '10.0.22' or greater is needed."); } } - // check innodb support - if ($dbClass == MySQLDatabase::class) { - $sql = "SHOW ENGINES"; - $statement = $db->prepareStatement($sql); - $statement->execute(); - $hasInnoDB = false; - while ($row = $statement->fetchArray()) { - if ($row['Engine'] == 'InnoDB' && in_array($row['Support'], ['DEFAULT', 'YES'])) { - $hasInnoDB = true; - break; - } + else { + // MySQL 5.5.35+ + if (!(version_compare($compareSQLVersion, '5.5.35') >= 0)) { + throw new SystemException("Insufficient MySQL version '".$compareSQLVersion."'. Version '5.5.35' or greater is needed."); } - - if (!$hasInnoDB) { - throw new SystemException("Support for InnoDB is missing."); + } + + // check innodb support + $sql = "SHOW ENGINES"; + $statement = $db->prepareStatement($sql); + $statement->execute(); + $hasInnoDB = false; + while ($row = $statement->fetchArray()) { + if ($row['Engine'] == 'InnoDB' && in_array($row['Support'], ['DEFAULT', 'YES'])) { + $hasInnoDB = true; + break; } } + if (!$hasInnoDB) { + throw new SystemException("Support for InnoDB is missing."); + } + // check for table conflicts $conflictedTables = $this->getConflictedTables($db, $dbNumber); @@ -742,7 +701,6 @@ class WCFSetup extends WCF { $file->write("\$dbUser = '".str_replace("'", "\\'", $dbUser)."';\n"); $file->write("\$dbPassword = '".str_replace("'", "\\'", $dbPassword)."';\n"); $file->write("\$dbName = '".str_replace("'", "\\'", $dbName)."';\n"); - $file->write("\$dbClass = '".str_replace("'", "\\'", $dbClass)."';\n"); $file->write("if (!defined('WCF_N')) define('WCF_N', $dbNumber);\n"); $file->close(); @@ -765,8 +723,6 @@ class WCFSetup extends WCF { 'dbPassword' => $dbPassword, 'dbName' => $dbName, 'dbNumber' => $dbNumber, - 'dbClass' => $dbClass, - 'availableDBClasses' => $availableDBClasses, 'nextStep' => 'configureDB' ]); WCF::getTPL()->display('stepConfigureDB'); diff --git a/wcfsetup/setup/lang/setup_de.xml b/wcfsetup/setup/lang/setup_de.xml index 69d8d2bbd2..6c1cdc055b 100644 --- a/wcfsetup/setup/lang/setup_de.xml +++ b/wcfsetup/setup/lang/setup_de.xml @@ -41,7 +41,7 @@ - + @@ -52,9 +52,6 @@ {$exception->getMessage()}{if $exception->getPrevious()}
{$exception->getPrevious()->getMessage()}{/if}
]]>
1}n{/if} existier{if $conflictedTables|count > 1}en{else}t{/if} schon in der Datenbank „{$dbName}“:
{implode from=$conflictedTables item="table"}{$table}{/implode}.

Um dieses Problem zu beheben, können Sie:
1. diese Tabelle{if $conflictedTables|count > 1}n{/if} manuell löschen und die „Weiter“ Schaltfläche betätigen, oder
2. Sie geben die Daten einer anderen Datenbank ein und betätigen die „Weiter“ Schaltfläche, oder
3. Sie geben eine von „{$dbNumber}“ unterschiedliche Installationsnummer an und betätigen die „Weiter“ Schaltfläche.]]>
- - - diff --git a/wcfsetup/setup/lang/setup_en.xml b/wcfsetup/setup/lang/setup_en.xml index 6c4c82a4d3..03a2a2caac 100644 --- a/wcfsetup/setup/lang/setup_en.xml +++ b/wcfsetup/setup/lang/setup_en.xml @@ -41,7 +41,7 @@ - + @@ -52,9 +52,6 @@ {$exception->getMessage()}{if $exception->getPrevious()}
{$exception->getPrevious()->getMessage()}{/if}
]]>
1}s{/if} already exist{if $conflictedTables|count == 1}s{/if} within your “{$dbName}” Database:
{implode from=$conflictedTables item="table"}{$table}{/implode}.

To solve this problem, please do one of the following:
1. Remove the table{if $conflictedTables|count > 1}s{/if} manually and continue the installation with the “Next” button or
2. You re-enter the database access information, but to a different database and continue the installation with the “Next” button or
3. Enter a new installation number, not forgetting to continue the installation with the “Next” Button.]]>
- - - diff --git a/wcfsetup/setup/template/stepConfigureDB.tpl b/wcfsetup/setup/template/stepConfigureDB.tpl index ce88b54570..42f464ecca 100644 --- a/wcfsetup/setup/template/stepConfigureDB.tpl +++ b/wcfsetup/setup/template/stepConfigureDB.tpl @@ -15,17 +15,6 @@

{lang}wcf.global.configureDB.description{/lang}

-
-
-
- -
-
-
diff --git a/wcfsetup/setup/template/stepShowSystemRequirements.tpl b/wcfsetup/setup/template/stepShowSystemRequirements.tpl index bbc102d42b..16f43c44d5 100644 --- a/wcfsetup/setup/template/stepShowSystemRequirements.tpl +++ b/wcfsetup/setup/template/stepShowSystemRequirements.tpl @@ -1,112 +1,112 @@ {include file='header'} -
-

{lang}wcf.global.systemRequirements.required{/lang}

- +
-

{lang}wcf.global.systemRequirements.php{/lang}

+

{lang}wcf.global.systemRequirements.required{/lang}

-
-
-
{lang}wcf.global.systemRequirements.element.required{/lang}
-
5.5.4
-
+
+

{lang}wcf.global.systemRequirements.php{/lang}

-
-
{lang}wcf.global.systemRequirements.element.yours{/lang}
-
- {$system.phpVersion.value} - {if !$system.phpVersion.result}{lang}wcf.global.systemRequirements.php.description{/lang}{/if} -
-
-
-
- -
-

{lang}wcf.global.systemRequirements.memoryLimit{/lang}

- -
-
-
{lang}wcf.global.systemRequirements.element.required{/lang}
-
128M
-
+
+
+
{lang}wcf.global.systemRequirements.element.required{/lang}
+
5.5.4
+
+ +
+
{lang}wcf.global.systemRequirements.element.yours{/lang}
+
+ {$system.phpVersion.value} + {if !$system.phpVersion.result}{lang}wcf.global.systemRequirements.php.description{/lang}{/if} +
+
+
+
-
-
{lang}wcf.global.systemRequirements.element.yours{/lang}
-
- {$system.memoryLimit.value} - {if !$system.memoryLimit.result}{lang}wcf.global.systemRequirements.memoryLimit.description{/lang}{/if} -
-
- -
- -
-

{lang}wcf.global.systemRequirements.sql{/lang}

+
+

{lang}wcf.global.systemRequirements.memoryLimit{/lang}

+ +
+
+
{lang}wcf.global.systemRequirements.element.required{/lang}
+
128M
+
+ +
+
{lang}wcf.global.systemRequirements.element.yours{/lang}
+
+ {$system.memoryLimit.value} + {if !$system.memoryLimit.result}{lang}wcf.global.systemRequirements.memoryLimit.description{/lang}{/if} +
+
+
+
-
-
-
{lang}wcf.global.systemRequirements.element.required{/lang}
-
{lang}wcf.global.systemRequirements.active{/lang}
-
+
+

{lang}wcf.global.systemRequirements.sql{/lang}

-
-
{lang}wcf.global.systemRequirements.element.yours{/lang}
-
- - {if !$system.sql.result}{lang}wcf.global.systemRequirements.sql.notFound{/lang}{else} - {implode from=$system.sql.value item=$sqlType glue=', '}{lang}wcf.global.configureDB.class.{@$sqlType}{/lang}{/implode} - {/if} - {if !$system.sql.result}{lang}wcf.global.systemRequirements.sql.description{/lang}{/if} -
-
-
+
+
+
{lang}wcf.global.systemRequirements.element.required{/lang}
+
{lang}wcf.global.systemRequirements.active{/lang}
+
+ +
+
{lang}wcf.global.systemRequirements.element.yours{/lang}
+
+ + {if !$system.sql.result}{lang}wcf.global.systemRequirements.sql.notFound{/lang}{else} + MySQL 5.5.35+ / MariaDB 10.0.22+ + {/if} + {if !$system.sql.result}{lang}wcf.global.systemRequirements.sql.description{/lang}{/if} +
+
+
+
- - -
-

{lang}wcf.global.systemRequirements.recommended{/lang}

-

{lang}wcf.global.systemRequirements.uploadMaxFilesize{/lang}

+

{lang}wcf.global.systemRequirements.recommended{/lang}

-
-
-
{lang}wcf.global.systemRequirements.element.recommended{/lang}
-
> 0
-
+
+

{lang}wcf.global.systemRequirements.uploadMaxFilesize{/lang}

-
-
{lang}wcf.global.systemRequirements.element.yours{/lang}
-
- {$system.uploadMaxFilesize.value} - {if !$system.uploadMaxFilesize.result}{lang}wcf.global.systemRequirements.uploadMaxFilesize.description{/lang}{/if} -
-
-
-
- -
-

{lang}wcf.global.systemRequirements.gdLib{/lang}

+
+
+
{lang}wcf.global.systemRequirements.element.recommended{/lang}
+
> 0
+
+ +
+
{lang}wcf.global.systemRequirements.element.yours{/lang}
+
+ {$system.uploadMaxFilesize.value} + {if !$system.uploadMaxFilesize.result}{lang}wcf.global.systemRequirements.uploadMaxFilesize.description{/lang}{/if} +
+
+
+
-
-
-
{lang}wcf.global.systemRequirements.element.recommended{/lang}
-
2.0.0
-
+
+

{lang}wcf.global.systemRequirements.gdLib{/lang}

-
-
{lang}wcf.global.systemRequirements.element.yours{/lang}
-
- {$system.gdLib.value} - {if !$system.gdLib.result}{lang}wcf.global.systemRequirements.gdLib.description{/lang}{/if} -
-
-
+
+
+
{lang}wcf.global.systemRequirements.element.recommended{/lang}
+
2.0.0
+
+ +
+
{lang}wcf.global.systemRequirements.element.yours{/lang}
+
+ {$system.gdLib.value} + {if !$system.gdLib.result}{lang}wcf.global.systemRequirements.gdLib.description{/lang}{/if} +
+
+
+
- -
-- 2.20.1