summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2020-02-06 19:36:53 +0100
committerGitHub <noreply@github.com>2020-02-06 19:36:53 +0100
commitc5c31784221f18aeb00aa4084d05648f131e910d (patch)
treed92039fa7fc9114ae3f370669ba1fab883de62fc /lib
parentd2d7e37b7bf00ea7929da02459e4abb8640d064a (diff)
parent0317c5b5c81d9df54c9b8c8c09c94cfdc60832e7 (diff)
downloadnextcloud-server-c5c31784221f18aeb00aa4084d05648f131e910d.tar.gz
nextcloud-server-c5c31784221f18aeb00aa4084d05648f131e910d.zip
Merge pull request #19303 from nextcloud/test/debug-install
Fix occ maintenance:install database connect failure
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Setup.php14
-rw-r--r--lib/private/Setup/MySQL.php27
2 files changed, 34 insertions, 7 deletions
diff --git a/lib/private/Setup.php b/lib/private/Setup.php
index 9b604895468..795c8cabcea 100644
--- a/lib/private/Setup.php
+++ b/lib/private/Setup.php
@@ -353,11 +353,9 @@ class Setup {
$this->config->setValues($newConfigValues);
+ $dbSetup->initialize($options);
try {
- $dbSetup->initialize($options);
$dbSetup->setupDatabase($username);
- // apply necessary migrations
- $dbSetup->runMigrations();
} catch (\OC\DatabaseSetupException $e) {
$error[] = [
'error' => $e->getMessage(),
@@ -371,6 +369,16 @@ class Setup {
];
return $error;
}
+ try {
+ // apply necessary migrations
+ $dbSetup->runMigrations();
+ } catch (Exception $e) {
+ $error[] = [
+ 'error' => 'Error while trying to initialise the database: ' . $e->getMessage(),
+ 'hint' => '',
+ ];
+ return $error;
+ }
//create the user and group
$user = null;
diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php
index 3f4dd616a2f..7371c7aeab2 100644
--- a/lib/private/Setup/MySQL.php
+++ b/lib/private/Setup/MySQL.php
@@ -34,6 +34,7 @@ namespace OC\Setup;
use OC\DB\MySqlTools;
use OCP\IDBConnection;
use OCP\ILogger;
+use Doctrine\DBAL\Platforms\MySQL80Platform;
class MySQL extends AbstractDatabase {
public $dbprettyname = 'MySQL/MariaDB';
@@ -57,6 +58,16 @@ class MySQL extends AbstractDatabase {
//fill the database if needed
$query='select count(*) from information_schema.tables where table_schema=? AND table_name = ?';
$connection->executeQuery($query, [$this->dbName, $this->tablePrefix.'users']);
+
+ $connection->close();
+ $connection = $this->connect();
+ try {
+ $connection->connect();
+ } catch (\Exception $e) {
+ $this->logger->logException($e);
+ throw new \OC\DatabaseSetupException($this->trans->t('MySQL username and/or password not valid'),
+ $this->trans->t('You need to enter details of an existing account.'));
+ }
}
/**
@@ -102,10 +113,18 @@ class MySQL extends AbstractDatabase {
$password = $this->dbPassword;
// we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one,
// the anonymous user would take precedence when there is one.
- $query = "CREATE USER '$name'@'localhost' IDENTIFIED WITH mysql_native_password BY '$password'";
- $connection->executeUpdate($query);
- $query = "CREATE USER '$name'@'%' IDENTIFIED WITH mysql_native_password BY '$password'";
- $connection->executeUpdate($query);
+
+ if ($connection->getDatabasePlatform() instanceof Mysql80Platform) {
+ $query = "CREATE USER '$name'@'localhost' IDENTIFIED WITH mysql_native_password BY '$password'";
+ $connection->executeUpdate($query);
+ $query = "CREATE USER '$name'@'%' IDENTIFIED WITH mysql_native_password BY '$password'";
+ $connection->executeUpdate($query);
+ } else {
+ $query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'";
+ $connection->executeUpdate($query);
+ $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'";
+ $connection->executeUpdate($query);
+ }
}
catch (\Exception $ex){
$this->logger->logException($ex, [