Fix psalm errors

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2021-04-22 15:22:50 +02:00
parent df47445c01
commit 167efa19d7
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
6 changed files with 29 additions and 24 deletions

View File

@ -37,8 +37,8 @@ use OC\Console\TimestampFormatter;
use OC\Installer; use OC\Installer;
use OC\Updater; use OC\Updater;
use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger;
use OCP\Util; use OCP\Util;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
@ -56,15 +56,13 @@ class Upgrade extends Command {
/** @var IConfig */ /** @var IConfig */
private $config; private $config;
/** @var ILogger */ /** @var LoggerInterface */
private $logger; private $logger;
/** /** @var Installer */
* @param IConfig $config private $installer;
* @param ILogger $logger
* @param Installer $installer public function __construct(IConfig $config, LoggerInterface $logger, Installer $installer) {
*/
public function __construct(IConfig $config, ILogger $logger, Installer $installer) {
parent::__construct(); parent::__construct();
$this->config = $config; $this->config = $config;
$this->logger = $logger; $this->logger = $logger;

View File

@ -117,7 +117,7 @@ if (\OCP\Util::needUpgrade()) {
// avoid side effects // avoid side effects
\OC_User::setIncognitoMode(true); \OC_User::setIncognitoMode(true);
$logger = \OC::$server->getLogger(); $logger = \OC::$server->get(\Psr\Log\LoggerInterface::class);
$config = \OC::$server->getConfig(); $config = \OC::$server->getConfig();
$updater = new \OC\Updater( $updater = new \OC\Updater(
$config, $config,

View File

@ -160,7 +160,7 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
$application->add(new OC\Core\Command\Maintenance\UpdateHtaccess()); $application->add(new OC\Core\Command\Maintenance\UpdateHtaccess());
$application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory())); $application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory()));
$application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class))); $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->query(\OC\Installer::class)));
$application->add(new OC\Core\Command\Maintenance\Repair( $application->add(new OC\Core\Command\Maintenance\Repair(
new \OC\Repair([], \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class)), new \OC\Repair([], \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class)),
\OC::$server->getConfig(), \OC::$server->getConfig(),

View File

@ -929,7 +929,7 @@ class OC {
\OC::$server->get(\bantu\IniGetWrapper\IniGetWrapper::class), \OC::$server->get(\bantu\IniGetWrapper\IniGetWrapper::class),
\OC::$server->getL10N('lib'), \OC::$server->getL10N('lib'),
\OC::$server->query(\OCP\Defaults::class), \OC::$server->query(\OCP\Defaults::class),
\OC::$server->getLogger(), \OC::$server->get(\Psr\Log\LoggerInterface::class),
\OC::$server->getSecureRandom(), \OC::$server->getSecureRandom(),
\OC::$server->query(\OC\Installer::class) \OC::$server->query(\OC\Installer::class)
); );

View File

@ -66,7 +66,9 @@ class MySQL extends AbstractDatabase {
try { try {
$connection->connect(); $connection->connect();
} catch (\Exception $e) { } 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'), 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); $this->trans->t('You need to enter details of an existing account.'), 0, $e);
} }
@ -177,9 +179,8 @@ class MySQL extends AbstractDatabase {
} }
} }
} catch (\Exception $ex) { } catch (\Exception $ex) {
$this->logger->logException($ex, [ $this->logger->info('Can not create a new MySQL user, will continue with the provided user.', [
'message' => 'Can not create a new MySQL user, will continue with the provided user.', 'exception' => $ex,
'level' => ILogger::INFO,
'app' => 'mysql.setup', 'app' => 'mysql.setup',
]); ]);
} }

View File

@ -82,8 +82,9 @@ class PostgreSQL extends AbstractDatabase {
// the connection to dbname=postgres is not needed anymore // the connection to dbname=postgres is not needed anymore
$connection->close(); $connection->close();
} catch (\Exception $e) { } 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([ $this->config->setValues([
'dbuser' => $this->dbUser, 'dbuser' => $this->dbUser,
'dbpassword' => $this->dbPassword, 'dbpassword' => $this->dbPassword,
@ -97,7 +98,9 @@ class PostgreSQL extends AbstractDatabase {
try { try {
$connection->connect(); $connection->connect();
} catch (\Exception $e) { } 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'), 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); $this->trans->t('You need to enter details of an existing account.'), 0, $e);
} }
@ -110,16 +113,18 @@ class PostgreSQL extends AbstractDatabase {
try { try {
$query->execute(); $query->execute();
} catch (DatabaseException $e) { } catch (DatabaseException $e) {
$this->logger->error('Error while trying to create database'); $this->logger->error('Error while trying to create database', [
$this->logger->logException($e); 'exception' => $e,
]);
} }
} else { } else {
$query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE " . addslashes($this->dbName) . " FROM PUBLIC"); $query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE " . addslashes($this->dbName) . " FROM PUBLIC");
try { try {
$query->execute(); $query->execute();
} catch (DatabaseException $e) { } catch (DatabaseException $e) {
$this->logger->error('Error while trying to restrict database permissions'); $this->logger->error('Error while trying to restrict database permissions', [
$this->logger->logException($e); 'exception' => $e,
]);
} }
} }
} }
@ -161,8 +166,9 @@ class PostgreSQL extends AbstractDatabase {
$query->execute(); $query->execute();
} }
} catch (DatabaseException $e) { } catch (DatabaseException $e) {
$this->logger->error('Error while trying to create database user'); $this->logger->error('Error while trying to create database user', [
$this->logger->logException($e); 'exception' => $e,
]);
} }
} }
} }