diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-03-17 17:26:27 +0100 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-03-24 16:21:25 +0100 |
commit | ea23523c70ee562092510ccf88e7aa469aae9ce6 (patch) | |
tree | da0ce15036d2f7b82ef1a0e44adb497c8e951cb3 /lib/private | |
parent | eb961e47003ee5b6d7328caf10ecd5f53cc93666 (diff) | |
download | nextcloud-server-ea23523c70ee562092510ccf88e7aa469aae9ce6.tar.gz nextcloud-server-ea23523c70ee562092510ccf88e7aa469aae9ce6.zip |
Adapt more code to migration to LoggerInterface
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/DB/Connection.php | 69 | ||||
-rw-r--r-- | lib/private/DB/MigrationService.php | 3 | ||||
-rw-r--r-- | lib/private/Files/Cache/Cache.php | 5 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/Swift.php | 3 | ||||
-rw-r--r-- | lib/private/Repair.php | 9 | ||||
-rw-r--r-- | lib/private/TemplateLayout.php | 5 |
6 files changed, 48 insertions, 46 deletions
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index 6f89ba64e80..0cd310550b6 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -49,12 +49,12 @@ use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Result; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Statement; -use OC\DB\QueryBuilder\QueryBuilder; -use OC\SystemConfig; use OCP\DB\QueryBuilder\IQueryBuilder; -use OCP\ILogger; use OCP\IRequestId; use OCP\PreConditionNotMetException; +use OC\DB\QueryBuilder\QueryBuilder; +use OC\SystemConfig; +use Psr\Log\LoggerInterface; class Connection extends \Doctrine\DBAL\Connection { /** @var string */ @@ -66,8 +66,7 @@ class Connection extends \Doctrine\DBAL\Connection { /** @var SystemConfig */ private $systemConfig; - /** @var ILogger */ - private $logger; + private LoggerInterface $logger; protected $lockedTable = null; @@ -78,6 +77,34 @@ class Connection extends \Doctrine\DBAL\Connection { protected $queriesExecuted = 0; /** + * Initializes a new instance of the Connection class. + * + * @throws \Exception + */ + public function __construct( + array $params, + Driver $driver, + ?Configuration $config = null, + ?EventManager $eventManager = null + ) { + if (!isset($params['adapter'])) { + throw new \Exception('adapter not set'); + } + if (!isset($params['tablePrefix'])) { + throw new \Exception('tablePrefix not set'); + } + /** + * @psalm-suppress InternalMethod + */ + parent::__construct($params, $driver, $config, $eventManager); + $this->adapter = new $params['adapter']($this); + $this->tablePrefix = $params['tablePrefix']; + + $this->systemConfig = \OC::$server->getSystemConfig(); + $this->logger = \OC::$server->get(LoggerInterface::class); + } + + /** * @throws Exception */ public function connect() { @@ -126,7 +153,7 @@ class Connection extends \Doctrine\DBAL\Connection { */ public function createQueryBuilder() { $backtrace = $this->getCallerBacktrace(); - \OC::$server->getLogger()->debug('Doctrine QueryBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); + $this->logger->debug('Doctrine QueryBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); $this->queriesBuilt++; return parent::createQueryBuilder(); } @@ -139,7 +166,7 @@ class Connection extends \Doctrine\DBAL\Connection { */ public function getExpressionBuilder() { $backtrace = $this->getCallerBacktrace(); - \OC::$server->getLogger()->debug('Doctrine ExpressionBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); + $this->logger->debug('Doctrine ExpressionBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); $this->queriesBuilt++; return parent::getExpressionBuilder(); } @@ -169,34 +196,6 @@ class Connection extends \Doctrine\DBAL\Connection { } /** - * Initializes a new instance of the Connection class. - * - * @param array $params The connection parameters. - * @param \Doctrine\DBAL\Driver $driver - * @param \Doctrine\DBAL\Configuration $config - * @param \Doctrine\Common\EventManager $eventManager - * @throws \Exception - */ - public function __construct(array $params, Driver $driver, Configuration $config = null, - EventManager $eventManager = null) { - if (!isset($params['adapter'])) { - throw new \Exception('adapter not set'); - } - if (!isset($params['tablePrefix'])) { - throw new \Exception('tablePrefix not set'); - } - /** - * @psalm-suppress InternalMethod - */ - parent::__construct($params, $driver, $config, $eventManager); - $this->adapter = new $params['adapter']($this); - $this->tablePrefix = $params['tablePrefix']; - - $this->systemConfig = \OC::$server->getSystemConfig(); - $this->logger = \OC::$server->getLogger(); - } - - /** * Prepares an SQL statement. * * @param string $statement The SQL statement to prepare. diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php index 5e146112120..a0f905115cc 100644 --- a/lib/private/DB/MigrationService.php +++ b/lib/private/DB/MigrationService.php @@ -43,6 +43,7 @@ use OCP\AppFramework\App; use OCP\AppFramework\QueryException; use OCP\Migration\IMigrationStep; use OCP\Migration\IOutput; +use Psr\Log\LoggerInterface; class MigrationService { @@ -73,7 +74,7 @@ class MigrationService { $this->connection = $connection; $this->output = $output; if (null === $this->output) { - $this->output = new SimpleOutput(\OC::$server->getLogger(), $appName); + $this->output = new SimpleOutput(\OC::$server->get(LoggerInterface::class), $appName); } if ($appName === 'core') { diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 7c2e635549a..949079dfa22 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -58,6 +58,7 @@ use OCP\Files\Search\ISearchOperator; use OCP\Files\Search\ISearchQuery; use OCP\Files\Storage\IStorage; use OCP\IDBConnection; +use Psr\Log\LoggerInterface; /** * Metadata cache for a storage @@ -128,7 +129,7 @@ class Cache implements ICache { return new CacheQueryBuilder( $this->connection, \OC::$server->getSystemConfig(), - \OC::$server->getLogger() + \OC::$server->get(LoggerInterface::class) ); } @@ -590,7 +591,7 @@ class Cache implements ICache { $query = $this->getQueryBuilder(); $query->delete('filecache_extended') ->where($query->expr()->in('fileid', $query->createParameter('childIds'))); - + foreach (array_chunk($childIds, 1000) as $childIdChunk) { $query->setParameter('childIds', $childIdChunk, IQueryBuilder::PARAM_INT_ARRAY); $query->execute(); diff --git a/lib/private/Files/ObjectStore/Swift.php b/lib/private/Files/ObjectStore/Swift.php index a3c8d92f3d2..b463cb9d44d 100644 --- a/lib/private/Files/ObjectStore/Swift.php +++ b/lib/private/Files/ObjectStore/Swift.php @@ -32,6 +32,7 @@ use Icewind\Streams\RetryWrapper; use OCP\Files\NotFoundException; use OCP\Files\ObjectStore\IObjectStore; use OCP\Files\StorageAuthException; +use Psr\Log\LoggerInterface; const SWIFT_SEGMENT_SIZE = 1073741824; // 1GB @@ -48,7 +49,7 @@ class Swift implements IObjectStore { $this->swiftFactory = $connectionFactory ?: new SwiftFactory( \OC::$server->getMemCacheFactory()->createDistributed('swift::'), $params, - \OC::$server->getLogger() + \OC::$server->get(LoggerInterface::class) ); $this->params = $params; } diff --git a/lib/private/Repair.php b/lib/private/Repair.php index 408d0f1b7aa..d5856f0e7aa 100644 --- a/lib/private/Repair.php +++ b/lib/private/Repair.php @@ -93,13 +93,12 @@ class Repair implements IOutput { /** @var string */ private $currentStep; - private $logger; + private LoggerInterface $logger; /** * Creates a new repair step runner * * @param IRepairStep[] $repairSteps array of RepairStep instances - * @param EventDispatcherInterface $dispatcher */ public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher, LoggerInterface $logger) { $this->repairSteps = $repairSteps; @@ -171,7 +170,7 @@ class Repair implements IOutput { */ public static function getRepairSteps() { return [ - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), + new Collation(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->getDatabaseConnection(), false), new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), @@ -197,7 +196,7 @@ class Repair implements IOutput { new ClearGeneratedAvatarCache(\OC::$server->getConfig(), \OC::$server->query(AvatarManager::class)), new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()), new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()), - new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getLogger()), + new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->get(LoggerInterface::class)), new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()), new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OC::$server->query(ITimeFactory::class)), new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OC::$server->query(IManager::class)), @@ -238,7 +237,7 @@ class Repair implements IOutput { $connectionAdapter = \OC::$server->get(ConnectionAdapter::class); $config = \OC::$server->getConfig(); $steps = [ - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connectionAdapter, true), + new Collation(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), $connectionAdapter, true), new SqliteAutoincrement($connection), new SaveAccountsTableData($connectionAdapter, $config), new DropAccountTermsTable($connectionAdapter), diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index d7a86ff92bf..cf06f021590 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -57,6 +57,7 @@ use OCP\IUserSession; use OCP\Support\Subscription\IRegistry; use OCP\UserStatus\IManager as IUserStatusManager; use OCP\Util; +use Psr\Log\LoggerInterface; class TemplateLayout extends \OC_Template { private static $versionHash = ''; @@ -345,7 +346,7 @@ class TemplateLayout extends \OC_Template { } $locator = new \OC\Template\CSSResourceLocator( - \OC::$server->getLogger(), + \OC::$server->get(LoggerInterface::class), $theme, [ \OC::$SERVERROOT => \OC::$WEBROOT ], [ \OC::$SERVERROOT => \OC::$WEBROOT ], @@ -380,7 +381,7 @@ class TemplateLayout extends \OC_Template { $theme = \OC_Util::getTheme(); $locator = new \OC\Template\JSResourceLocator( - \OC::$server->getLogger(), + \OC::$server->get(LoggerInterface::class), $theme, [ \OC::$SERVERROOT => \OC::$WEBROOT ], [ \OC::$SERVERROOT => \OC::$WEBROOT ], |