aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Setup
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Setup')
-rw-r--r--lib/private/Setup/AbstractDatabase.php6
-rw-r--r--lib/private/Setup/MySQL.php25
-rw-r--r--lib/private/Setup/PostgreSQL.php24
3 files changed, 29 insertions, 26 deletions
diff --git a/lib/private/Setup/AbstractDatabase.php b/lib/private/Setup/AbstractDatabase.php
index 77f3c02f9f6..5b975bcfcca 100644
--- a/lib/private/Setup/AbstractDatabase.php
+++ b/lib/private/Setup/AbstractDatabase.php
@@ -34,8 +34,8 @@ use OC\DB\ConnectionFactory;
use OC\DB\MigrationService;
use OC\SystemConfig;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\Security\ISecureRandom;
+use Psr\Log\LoggerInterface;
abstract class AbstractDatabase {
@@ -55,12 +55,12 @@ abstract class AbstractDatabase {
protected $tablePrefix;
/** @var SystemConfig */
protected $config;
- /** @var ILogger */
+ /** @var LoggerInterface */
protected $logger;
/** @var ISecureRandom */
protected $random;
- public function __construct(IL10N $trans, SystemConfig $config, ILogger $logger, ISecureRandom $random) {
+ public function __construct(IL10N $trans, SystemConfig $config, LoggerInterface $logger, ISecureRandom $random) {
$this->trans = $trans;
$this->config = $config;
$this->logger = $logger;
diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php
index 229d47160f5..c5c921cecd8 100644
--- a/lib/private/Setup/MySQL.php
+++ b/lib/private/Setup/MySQL.php
@@ -34,7 +34,6 @@ namespace OC\Setup;
use OC\DB\ConnectionAdapter;
use OC\DB\MySqlTools;
use OCP\IDBConnection;
-use OCP\ILogger;
use Doctrine\DBAL\Platforms\MySQL80Platform;
use OCP\Security\ISecureRandom;
@@ -66,7 +65,9 @@ class MySQL extends AbstractDatabase {
try {
$connection->connect();
} catch (\Exception $e) {
- $this->logger->logException($e);
+ $this->logger->error($e->getMessage(), [
+ 'exception' => $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.'), 0, $e);
}
@@ -84,9 +85,8 @@ class MySQL extends AbstractDatabase {
$query = "CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET $characterSet COLLATE ${characterSet}_bin;";
$connection->executeUpdate($query);
} catch (\Exception $ex) {
- $this->logger->logException($ex, [
- 'message' => 'Database creation failed.',
- 'level' => ILogger::ERROR,
+ $this->logger->error('Database creation failed.', [
+ 'exception' => $ex,
'app' => 'mysql.setup',
]);
return;
@@ -97,9 +97,8 @@ class MySQL extends AbstractDatabase {
$query = "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `$name` . * TO '$user'";
$connection->executeUpdate($query);
} catch (\Exception $ex) {
- $this->logger->logException($ex, [
- 'message' => 'Could not automatically grant privileges, this can be ignored if database user already had privileges.',
- 'level' => ILogger::DEBUG,
+ $this->logger->debug('Could not automatically grant privileges, this can be ignored if database user already had privileges.', [
+ 'exception' => $ex,
'app' => 'mysql.setup',
]);
}
@@ -128,9 +127,8 @@ class MySQL extends AbstractDatabase {
$connection->executeUpdate($query);
}
} catch (\Exception $ex) {
- $this->logger->logException($ex, [
- 'message' => 'Database user creation failed.',
- 'level' => ILogger::ERROR,
+ $this->logger->error('Database user creation failed.',[
+ 'exception' => $ex,
'app' => 'mysql.setup',
]);
}
@@ -180,9 +178,8 @@ class MySQL extends AbstractDatabase {
}
}
} catch (\Exception $ex) {
- $this->logger->logException($ex, [
- 'message' => 'Can not create a new MySQL user, will continue with the provided user.',
- 'level' => ILogger::INFO,
+ $this->logger->info('Can not create a new MySQL user, will continue with the provided user.', [
+ 'exception' => $ex,
'app' => 'mysql.setup',
]);
}
diff --git a/lib/private/Setup/PostgreSQL.php b/lib/private/Setup/PostgreSQL.php
index 7e59bf297f1..40386666341 100644
--- a/lib/private/Setup/PostgreSQL.php
+++ b/lib/private/Setup/PostgreSQL.php
@@ -82,8 +82,9 @@ class PostgreSQL extends AbstractDatabase {
// the connection to dbname=postgres is not needed anymore
$connection->close();
} catch (\Exception $e) {
- $this->logger->logException($e);
- $this->logger->warning('Error trying to connect as "postgres", assuming database is setup and tables need to be created');
+ $this->logger->warning('Error trying to connect as "postgres", assuming database is setup and tables need to be created', [
+ 'exception' => $e,
+ ]);
$this->config->setValues([
'dbuser' => $this->dbUser,
'dbpassword' => $this->dbPassword,
@@ -97,7 +98,9 @@ class PostgreSQL extends AbstractDatabase {
try {
$connection->connect();
} catch (\Exception $e) {
- $this->logger->logException($e);
+ $this->logger->error($e->getMessage(), [
+ 'exception' => $e,
+ ]);
throw new \OC\DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'),
$this->trans->t('You need to enter details of an existing account.'), 0, $e);
}
@@ -110,16 +113,18 @@ class PostgreSQL extends AbstractDatabase {
try {
$query->execute();
} catch (DatabaseException $e) {
- $this->logger->error('Error while trying to create database');
- $this->logger->logException($e);
+ $this->logger->error('Error while trying to create database', [
+ 'exception' => $e,
+ ]);
}
} else {
$query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE " . addslashes($this->dbName) . " FROM PUBLIC");
try {
$query->execute();
} catch (DatabaseException $e) {
- $this->logger->error('Error while trying to restrict database permissions');
- $this->logger->logException($e);
+ $this->logger->error('Error while trying to restrict database permissions', [
+ 'exception' => $e,
+ ]);
}
}
}
@@ -161,8 +166,9 @@ class PostgreSQL extends AbstractDatabase {
$query->execute();
}
} catch (DatabaseException $e) {
- $this->logger->error('Error while trying to create database user');
- $this->logger->logException($e);
+ $this->logger->error('Error while trying to create database user', [
+ 'exception' => $e,
+ ]);
}
}
}