diff options
Diffstat (limited to 'apps/files_external/lib/Command/Notify.php')
-rw-r--r-- | apps/files_external/lib/Command/Notify.php | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/apps/files_external/lib/Command/Notify.php b/apps/files_external/lib/Command/Notify.php index 340dd2fdca1..bba698fb25f 100644 --- a/apps/files_external/lib/Command/Notify.php +++ b/apps/files_external/lib/Command/Notify.php @@ -39,27 +39,24 @@ use OCP\Files\Storage\INotifyStorage; use OCP\Files\Storage\IStorage; use OCP\Files\StorageNotAvailableException; use OCP\IDBConnection; -use OCP\ILogger; use OCP\IUserManager; +use Psr\Log\LoggerInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class Notify extends Base { - /** @var GlobalStoragesService */ - private $globalService; - /** @var IDBConnection */ - private $connection; - /** @var ILogger */ - private $logger; + private GlobalStoragesService $globalService; + private IDBConnection $connection; + private LoggerInterface $logger; /** @var IUserManager */ private $userManager; public function __construct( GlobalStoragesService $globalService, IDBConnection $connection, - ILogger $logger, + LoggerInterface $logger, IUserManager $userManager ) { parent::__construct(); @@ -69,7 +66,7 @@ class Notify extends Base { $this->userManager = $userManager; } - protected function configure() { + protected function configure(): void { $this ->setName('files_external:notify') ->setDescription('Listen for active update notifications for a configured external mount') @@ -207,7 +204,7 @@ class Notify extends Base { return 0; } - private function createStorage(StorageConfig $mount) { + private function createStorage(StorageConfig $mount): IStorage { $class = $mount->getBackend()->getStorageClass(); return new $class($mount->getBackendOptions()); } @@ -221,7 +218,7 @@ class Notify extends Base { try { $storages = $this->getStorageIds($mountId, $parent); } catch (DriverException $ex) { - $this->logger->logException($ex, ['message' => 'Error while trying to find correct storage ids.', 'level' => ILogger::WARN]); + $this->logger->warning('Error while trying to find correct storage ids.', ['exception' => $ex]); $this->connection = $this->reconnectToDatabase($this->connection, $output); $output->writeln('<info>Needed to reconnect to the database</info>'); $storages = $this->getStorageIds($mountId, $path); @@ -292,37 +289,30 @@ class Notify extends Base { ->fetchAll(); } - /** - * @param array $storageIds - * @param string $parent - * @return int - */ - private function updateParent($storageIds, $parent) { - $pathHash = md5(trim(\OC_Util::normalizeUnicode($parent), '/')); + private function updateParent(array $storageIds, string $parent): int { + $pathHash = md5(trim((string)\OC_Util::normalizeUnicode($parent), '/')); $qb = $this->connection->getQueryBuilder(); return $qb ->update('filecache') ->set('size', $qb->createNamedParameter(-1, IQueryBuilder::PARAM_INT)) ->where($qb->expr()->in('storage', $qb->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY, ':storage_ids'))) ->andWhere($qb->expr()->eq('path_hash', $qb->createNamedParameter($pathHash, IQueryBuilder::PARAM_STR))) - ->execute(); + ->executeStatement(); } - /** - * @return \OCP\IDBConnection - */ - private function reconnectToDatabase(IDBConnection $connection, OutputInterface $output) { + private function reconnectToDatabase(IDBConnection $connection, OutputInterface $output): IDBConnection { try { $connection->close(); } catch (\Exception $ex) { - $this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while disconnecting from DB', 'level' => ILogger::WARN]); + $this->logger->warning('Error while disconnecting from DB', ['exception' => $ex]); $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); } - while (!$connection->isConnected()) { + $connected = false; + while (!$connected) { try { - $connection->connect(); + $connected = $connection->connect(); } catch (\Exception $ex) { - $this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while re-connecting to database', 'level' => ILogger::WARN]); + $this->logger->warning('Error while re-connecting to database', ['exception' => $ex]); $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); sleep(60); } |