Merge pull request #19327 from nextcloud/backport/19303/stable17
[stable17] Fix occ maintenance:install database connect failure
This commit is contained in:
commit
8c92c4aad1
3 changed files with 38 additions and 8 deletions
|
@ -132,6 +132,10 @@ class Install extends Command {
|
||||||
} else {
|
} else {
|
||||||
$dbHost = $input->getOption('database-host');
|
$dbHost = $input->getOption('database-host');
|
||||||
}
|
}
|
||||||
|
if ($dbPort) {
|
||||||
|
// Append the port to the host so it is the same as in the config (there is no dbport config)
|
||||||
|
$dbHost .= ':' . $dbPort;
|
||||||
|
}
|
||||||
$dbTablePrefix = 'oc_';
|
$dbTablePrefix = 'oc_';
|
||||||
if ($input->hasParameterOption('--database-table-prefix')) {
|
if ($input->hasParameterOption('--database-table-prefix')) {
|
||||||
$dbTablePrefix = (string) $input->getOption('database-table-prefix');
|
$dbTablePrefix = (string) $input->getOption('database-table-prefix');
|
||||||
|
@ -181,7 +185,6 @@ class Install extends Command {
|
||||||
'dbpass' => $dbPass,
|
'dbpass' => $dbPass,
|
||||||
'dbname' => $dbName,
|
'dbname' => $dbName,
|
||||||
'dbhost' => $dbHost,
|
'dbhost' => $dbHost,
|
||||||
'dbport' => $dbPort,
|
|
||||||
'dbtableprefix' => $dbTablePrefix,
|
'dbtableprefix' => $dbTablePrefix,
|
||||||
'adminlogin' => $adminLogin,
|
'adminlogin' => $adminLogin,
|
||||||
'adminpass' => $adminPassword,
|
'adminpass' => $adminPassword,
|
||||||
|
|
|
@ -343,11 +343,9 @@ class Setup {
|
||||||
|
|
||||||
$this->config->setValues($newConfigValues);
|
$this->config->setValues($newConfigValues);
|
||||||
|
|
||||||
|
$dbSetup->initialize($options);
|
||||||
try {
|
try {
|
||||||
$dbSetup->initialize($options);
|
|
||||||
$dbSetup->setupDatabase($username);
|
$dbSetup->setupDatabase($username);
|
||||||
// apply necessary migrations
|
|
||||||
$dbSetup->runMigrations();
|
|
||||||
} catch (\OC\DatabaseSetupException $e) {
|
} catch (\OC\DatabaseSetupException $e) {
|
||||||
$error[] = [
|
$error[] = [
|
||||||
'error' => $e->getMessage(),
|
'error' => $e->getMessage(),
|
||||||
|
@ -361,6 +359,16 @@ class Setup {
|
||||||
];
|
];
|
||||||
return $error;
|
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
|
//create the user and group
|
||||||
$user = null;
|
$user = null;
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace OC\Setup;
|
||||||
use OC\DB\MySqlTools;
|
use OC\DB\MySqlTools;
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
|
use Doctrine\DBAL\Platforms\MySQL80Platform;
|
||||||
|
|
||||||
class MySQL extends AbstractDatabase {
|
class MySQL extends AbstractDatabase {
|
||||||
public $dbprettyname = 'MySQL/MariaDB';
|
public $dbprettyname = 'MySQL/MariaDB';
|
||||||
|
@ -55,6 +56,16 @@ class MySQL extends AbstractDatabase {
|
||||||
//fill the database if needed
|
//fill the database if needed
|
||||||
$query='select count(*) from information_schema.tables where table_schema=? AND table_name = ?';
|
$query='select count(*) from information_schema.tables where table_schema=? AND table_name = ?';
|
||||||
$connection->executeQuery($query, [$this->dbName, $this->tablePrefix.'users']);
|
$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.'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,10 +111,18 @@ class MySQL extends AbstractDatabase {
|
||||||
$password = $this->dbPassword;
|
$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,
|
// 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.
|
// 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);
|
if ($connection->getDatabasePlatform() instanceof Mysql80Platform) {
|
||||||
$query = "CREATE USER '$name'@'%' IDENTIFIED WITH mysql_native_password BY '$password'";
|
$query = "CREATE USER '$name'@'localhost' IDENTIFIED WITH mysql_native_password BY '$password'";
|
||||||
$connection->executeUpdate($query);
|
$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){
|
catch (\Exception $ex){
|
||||||
$this->logger->logException($ex, [
|
$this->logger->logException($ex, [
|
||||||
|
|
Loading…
Reference in a new issue