diff options
Diffstat (limited to 'core/Command')
-rw-r--r-- | core/Command/App/Update.php | 3 | ||||
-rw-r--r-- | core/Command/Background/Job.php | 8 | ||||
-rw-r--r-- | core/Command/Background/JobBase.php | 9 | ||||
-rw-r--r-- | core/Command/Broadcast/Test.php | 13 | ||||
-rw-r--r-- | core/Command/Db/ConvertType.php | 6 | ||||
-rw-r--r-- | core/Command/Encryption/ListModules.php | 2 | ||||
-rw-r--r-- | core/Command/Info/File.php | 3 | ||||
-rw-r--r-- | core/Command/Info/FileUtils.php | 108 | ||||
-rw-r--r-- | core/Command/Info/Storage.php | 49 | ||||
-rw-r--r-- | core/Command/Info/Storages.php | 43 | ||||
-rw-r--r-- | core/Command/Log/File.php | 5 | ||||
-rw-r--r-- | core/Command/Maintenance/Install.php | 3 | ||||
-rw-r--r-- | core/Command/Maintenance/Mimetype/GenerateMimetypeFileBuilder.php | 14 | ||||
-rw-r--r-- | core/Command/Maintenance/Mimetype/UpdateJS.php | 3 | ||||
-rw-r--r-- | core/Command/Maintenance/UpdateHtaccess.php | 3 | ||||
-rw-r--r-- | core/Command/Preview/Repair.php | 2 | ||||
-rw-r--r-- | core/Command/Upgrade.php | 37 | ||||
-rw-r--r-- | core/Command/User/Info.php | 3 | ||||
-rw-r--r-- | core/Command/User/LastSeen.php | 2 | ||||
-rw-r--r-- | core/Command/User/SyncAccountDataCommand.php | 9 | ||||
-rw-r--r-- | core/Command/User/Welcome.php | 13 |
21 files changed, 270 insertions, 68 deletions
diff --git a/core/Command/App/Update.php b/core/Command/App/Update.php index b2d02e222de..71c7f84e5b0 100644 --- a/core/Command/App/Update.php +++ b/core/Command/App/Update.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace OC\Core\Command\App; use OC\Installer; +use OCP\App\AppPathNotFoundException; use OCP\App\IAppManager; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Command\Command; @@ -64,7 +65,7 @@ class Update extends Command { $apps = [$singleAppId]; try { $this->manager->getAppPath($singleAppId); - } catch (\OCP\App\AppPathNotFoundException $e) { + } catch (AppPathNotFoundException $e) { $output->writeln($singleAppId . ' not installed'); return 1; } diff --git a/core/Command/Background/Job.php b/core/Command/Background/Job.php index 7fa005cf231..9a862f5a13a 100644 --- a/core/Command/Background/Job.php +++ b/core/Command/Background/Job.php @@ -10,6 +10,8 @@ namespace OC\Core\Command\Background; use OCP\BackgroundJob\IJob; use OCP\BackgroundJob\IJobList; +use OCP\BackgroundJob\QueuedJob; +use OCP\BackgroundJob\TimedJob; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -75,7 +77,7 @@ class Job extends Command { $output->writeln('<info>Job executed!</info>'); $output->writeln(''); - if ($job instanceof \OCP\BackgroundJob\TimedJob) { + if ($job instanceof TimedJob) { $this->printJobInfo($jobId, $job, $output); } } else { @@ -99,10 +101,10 @@ class Job extends Command { $output->writeln('Job class: ' . get_class($job)); $output->writeln('Arguments: ' . json_encode($job->getArgument())); - $isTimedJob = $job instanceof \OCP\BackgroundJob\TimedJob; + $isTimedJob = $job instanceof TimedJob; if ($isTimedJob) { $output->writeln('Type: timed'); - } elseif ($job instanceof \OCP\BackgroundJob\QueuedJob) { + } elseif ($job instanceof QueuedJob) { $output->writeln('Type: queued'); } else { $output->writeln('Type: job'); diff --git a/core/Command/Background/JobBase.php b/core/Command/Background/JobBase.php index d92bb77d4b6..81d16f874eb 100644 --- a/core/Command/Background/JobBase.php +++ b/core/Command/Background/JobBase.php @@ -10,12 +10,15 @@ declare(strict_types=1); namespace OC\Core\Command\Background; +use OC\Core\Command\Base; use OCP\BackgroundJob\IJob; use OCP\BackgroundJob\IJobList; +use OCP\BackgroundJob\QueuedJob; +use OCP\BackgroundJob\TimedJob; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Output\OutputInterface; -abstract class JobBase extends \OC\Core\Command\Base { +abstract class JobBase extends Base { public function __construct( protected IJobList $jobList, @@ -41,10 +44,10 @@ abstract class JobBase extends \OC\Core\Command\Base { $output->writeln('Job class: ' . get_class($job)); $output->writeln('Arguments: ' . json_encode($job->getArgument())); - $isTimedJob = $job instanceof \OCP\BackgroundJob\TimedJob; + $isTimedJob = $job instanceof TimedJob; if ($isTimedJob) { $output->writeln('Type: timed'); - } elseif ($job instanceof \OCP\BackgroundJob\QueuedJob) { + } elseif ($job instanceof QueuedJob) { $output->writeln('Type: queued'); } else { $output->writeln('Type: job'); diff --git a/core/Command/Broadcast/Test.php b/core/Command/Broadcast/Test.php index fb80ce26ff0..eb8b49bc3ee 100644 --- a/core/Command/Broadcast/Test.php +++ b/core/Command/Broadcast/Test.php @@ -44,16 +44,11 @@ class Test extends Command { $uid = $input->getArgument('uid'); $event = new class($name, $uid) extends ABroadcastedEvent { - /** @var string */ - private $name; - /** @var string */ - private $uid; - - public function __construct(string $name, - string $uid) { + public function __construct( + private string $name, + private string $uid, + ) { parent::__construct(); - $this->name = $name; - $this->uid = $uid; } public function broadcastAs(): string { diff --git a/core/Command/Db/ConvertType.php b/core/Command/Db/ConvertType.php index b5d1b9b9330..bca41407f68 100644 --- a/core/Command/Db/ConvertType.php +++ b/core/Command/Db/ConvertType.php @@ -13,9 +13,11 @@ use Doctrine\DBAL\Schema\Table; use OC\DB\Connection; use OC\DB\ConnectionFactory; use OC\DB\MigrationService; +use OC\DB\PgSqlTools; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\Types; use OCP\IConfig; +use OCP\Server; use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Command\Command; @@ -159,7 +161,7 @@ class ConvertType extends Command implements CompletionAwareInterface { $this->readPassword($input, $output); /** @var Connection $fromDB */ - $fromDB = \OC::$server->get(Connection::class); + $fromDB = Server::get(Connection::class); $toDB = $this->getToDBConnection($input, $output); if ($input->getOption('clear-schema')) { @@ -401,7 +403,7 @@ class ConvertType extends Command implements CompletionAwareInterface { $this->copyTable($fromDB, $toDB, $schema->getTable($table), $input, $output); } if ($input->getArgument('type') === 'pgsql') { - $tools = new \OC\DB\PgSqlTools($this->config); + $tools = new PgSqlTools($this->config); $tools->resynchronizeDatabaseSequences($toDB); } // save new database config diff --git a/core/Command/Encryption/ListModules.php b/core/Command/Encryption/ListModules.php index b1f35b05bc9..bf02c29f432 100644 --- a/core/Command/Encryption/ListModules.php +++ b/core/Command/Encryption/ListModules.php @@ -57,7 +57,7 @@ class ListModules extends Base { */ protected function writeModuleList(InputInterface $input, OutputInterface $output, $items) { if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) { - array_walk($items, function (&$item) { + array_walk($items, function (&$item): void { if (!$item['default']) { $item = $item['displayName']; } else { diff --git a/core/Command/Info/File.php b/core/Command/Info/File.php index c21c2e666fb..287bd0e29cb 100644 --- a/core/Command/Info/File.php +++ b/core/Command/Info/File.php @@ -9,6 +9,7 @@ namespace OC\Core\Command\Info; use OC\Files\ObjectStore\ObjectStoreStorage; use OC\Files\Storage\Wrapper\Encryption; +use OC\Files\Storage\Wrapper\Wrapper; use OC\Files\View; use OCA\Files_External\Config\ExternalMountPoint; use OCA\GroupFolders\Mount\GroupMountPoint; @@ -176,7 +177,7 @@ class File extends Command { if ($input->getOption('storage-tree')) { $storageTmp = $storage; $storageClass = get_class($storageTmp) . ' (cache:' . get_class($storageTmp->getCache()) . ')'; - while ($storageTmp instanceof \OC\Files\Storage\Wrapper\Wrapper) { + while ($storageTmp instanceof Wrapper) { $storageTmp = $storageTmp->getWrapperStorage(); $storageClass .= "\n\t" . '> ' . get_class($storageTmp) . ' (cache:' . get_class($storageTmp->getCache()) . ')'; } diff --git a/core/Command/Info/FileUtils.php b/core/Command/Info/FileUtils.php index 5de5f5fcaa6..bc07535a289 100644 --- a/core/Command/Info/FileUtils.php +++ b/core/Command/Info/FileUtils.php @@ -8,11 +8,13 @@ declare(strict_types=1); namespace OC\Core\Command\Info; +use OC\User\NoUserException; use OCA\Circles\MountManager\CircleMount; use OCA\Files_External\Config\ExternalMountPoint; use OCA\Files_Sharing\SharedMount; use OCA\GroupFolders\Mount\GroupMountPoint; use OCP\Constants; +use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\Config\IUserMountCache; use OCP\Files\FileInfo; use OCP\Files\Folder; @@ -21,22 +23,28 @@ use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountPoint; use OCP\Files\Node; use OCP\Files\NotFoundException; +use OCP\Files\NotPermittedException; +use OCP\IDBConnection; use OCP\Share\IShare; use OCP\Util; use Symfony\Component\Console\Output\OutputInterface; +/** + * @psalm-type StorageInfo array{numeric_id: int, id: string, available: bool, last_checked: ?\DateTime, files: int, mount_id: ?int} + */ class FileUtils { public function __construct( private IRootFolder $rootFolder, private IUserMountCache $userMountCache, + private IDBConnection $connection, ) { } /** * @param FileInfo $file * @return array<string, Node[]> - * @throws \OCP\Files\NotPermittedException - * @throws \OC\User\NoUserException + * @throws NotPermittedException + * @throws NoUserException */ public function getFilesByUser(FileInfo $file): array { $id = $file->getId(); @@ -218,4 +226,100 @@ class FileUtils { } return $count; } + + public function getNumericStorageId(string $id): ?int { + if (is_numeric($id)) { + return (int)$id; + } + $query = $this->connection->getQueryBuilder(); + $query->select('numeric_id') + ->from('storages') + ->where($query->expr()->eq('id', $query->createNamedParameter($id))); + $result = $query->executeQuery()->fetchOne(); + return $result ? (int)$result : null; + } + + /** + * @param int|null $limit + * @return ?StorageInfo + * @throws \OCP\DB\Exception + */ + public function getStorage(int $id): ?array { + $query = $this->connection->getQueryBuilder(); + $query->select('numeric_id', 's.id', 'available', 'last_checked', 'mount_id') + ->selectAlias($query->func()->count('fileid'), 'files') + ->from('storages', 's') + ->innerJoin('s', 'filecache', 'f', $query->expr()->eq('f.storage', 's.numeric_id')) + ->leftJoin('s', 'mounts', 'm', $query->expr()->eq('s.numeric_id', 'm.storage_id')) + ->where($query->expr()->eq('s.numeric_id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT))) + ->groupBy('s.numeric_id', 's.id', 's.available', 's.last_checked', 'mount_id'); + $row = $query->executeQuery()->fetch(); + if ($row) { + return [ + 'numeric_id' => $row['numeric_id'], + 'id' => $row['id'], + 'files' => $row['files'], + 'available' => (bool)$row['available'], + 'last_checked' => $row['last_checked'] ? new \DateTime('@' . $row['last_checked']) : null, + 'mount_id' => $row['mount_id'], + ]; + } else { + return null; + } + } + + /** + * @param int|null $limit + * @return \Iterator<StorageInfo> + * @throws \OCP\DB\Exception + */ + public function listStorages(?int $limit): \Iterator { + $query = $this->connection->getQueryBuilder(); + $query->select('numeric_id', 's.id', 'available', 'last_checked', 'mount_id') + ->selectAlias($query->func()->count('fileid'), 'files') + ->from('storages', 's') + ->innerJoin('s', 'filecache', 'f', $query->expr()->eq('f.storage', 's.numeric_id')) + ->leftJoin('s', 'mounts', 'm', $query->expr()->eq('s.numeric_id', 'm.storage_id')) + ->groupBy('s.numeric_id', 's.id', 's.available', 's.last_checked', 'mount_id') + ->orderBy('files', 'DESC'); + if ($limit !== null) { + $query->setMaxResults($limit); + } + $result = $query->executeQuery(); + while ($row = $result->fetch()) { + yield [ + 'numeric_id' => $row['numeric_id'], + 'id' => $row['id'], + 'files' => $row['files'], + 'available' => (bool)$row['available'], + 'last_checked' => $row['last_checked'] ? new \DateTime('@' . $row['last_checked']) : null, + 'mount_id' => $row['mount_id'], + ]; + } + } + + /** + * @param StorageInfo $storage + * @return array + */ + public function formatStorage(array $storage): array { + return [ + 'numeric_id' => $storage['numeric_id'], + 'id' => $storage['id'], + 'files' => $storage['files'], + 'available' => $storage['available'] ? 'true' : 'false', + 'last_checked' => $storage['last_checked']?->format(\DATE_ATOM), + 'external_mount_id' => $storage['mount_id'], + ]; + } + + /** + * @param \Iterator<StorageInfo> $storages + * @return \Iterator + */ + public function formatStorages(\Iterator $storages): \Iterator { + foreach ($storages as $storage) { + yield $this->formatStorage($storage); + } + } } diff --git a/core/Command/Info/Storage.php b/core/Command/Info/Storage.php new file mode 100644 index 00000000000..c1d0e1725ca --- /dev/null +++ b/core/Command/Info/Storage.php @@ -0,0 +1,49 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OC\Core\Command\Info; + +use OC\Core\Command\Base; +use OCP\IDBConnection; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class Storage extends Base { + public function __construct( + private readonly IDBConnection $connection, + private readonly FileUtils $fileUtils, + ) { + parent::__construct(); + } + + protected function configure(): void { + parent::configure(); + $this + ->setName('info:storage') + ->setDescription('Get information a single storage') + ->addArgument('storage', InputArgument::REQUIRED, 'Storage to get information for'); + } + + public function execute(InputInterface $input, OutputInterface $output): int { + $storage = $input->getArgument('storage'); + $storageId = $this->fileUtils->getNumericStorageId($storage); + if (!$storageId) { + $output->writeln('<error>No storage with id ' . $storage . ' found</error>'); + return 1; + } + + $info = $this->fileUtils->getStorage($storageId); + if (!$info) { + $output->writeln('<error>No storage with id ' . $storage . ' found</error>'); + return 1; + } + $this->writeArrayInOutputFormat($input, $output, $this->fileUtils->formatStorage($info)); + return 0; + } +} diff --git a/core/Command/Info/Storages.php b/core/Command/Info/Storages.php new file mode 100644 index 00000000000..ff767a2ff5d --- /dev/null +++ b/core/Command/Info/Storages.php @@ -0,0 +1,43 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OC\Core\Command\Info; + +use OC\Core\Command\Base; +use OCP\IDBConnection; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +class Storages extends Base { + public function __construct( + private readonly IDBConnection $connection, + private readonly FileUtils $fileUtils, + ) { + parent::__construct(); + } + + protected function configure(): void { + parent::configure(); + $this + ->setName('info:storages') + ->setDescription('List storages ordered by the number of files') + ->addOption('count', 'c', InputOption::VALUE_REQUIRED, 'Number of storages to display', 25) + ->addOption('all', 'a', InputOption::VALUE_NONE, 'Display all storages'); + } + + public function execute(InputInterface $input, OutputInterface $output): int { + $count = (int)$input->getOption('count'); + $all = $input->getOption('all'); + + $limit = $all ? null : $count; + $storages = $this->fileUtils->listStorages($limit); + $this->writeStreamingTableInOutputFormat($input, $output, $this->fileUtils->formatStorages($storages), 100); + return 0; + } +} diff --git a/core/Command/Log/File.php b/core/Command/Log/File.php index 8b4a38db611..ba5dad956e9 100644 --- a/core/Command/Log/File.php +++ b/core/Command/Log/File.php @@ -8,6 +8,7 @@ namespace OC\Core\Command\Log; use OCP\IConfig; +use OCP\Util; use Stecman\Component\Symfony\Console\BashCompletion\Completion; use Stecman\Component\Symfony\Console\BashCompletion\Completion\ShellPathCompletion; @@ -61,7 +62,7 @@ class File extends Command implements Completion\CompletionAwareInterface { } if (($rotateSize = $input->getOption('rotate-size')) !== null) { - $rotateSize = \OCP\Util::computerFileSize($rotateSize); + $rotateSize = Util::computerFileSize($rotateSize); $this->validateRotateSize($rotateSize); $toBeSet['log_rotate_size'] = $rotateSize; } @@ -87,7 +88,7 @@ class File extends Command implements Completion\CompletionAwareInterface { $rotateSize = $this->config->getSystemValue('log_rotate_size', 100 * 1024 * 1024); if ($rotateSize) { - $rotateString = \OCP\Util::humanFileSize($rotateSize); + $rotateString = Util::humanFileSize($rotateSize); } else { $rotateString = 'disabled'; } diff --git a/core/Command/Maintenance/Install.php b/core/Command/Maintenance/Install.php index d23a8d30070..84fd832e016 100644 --- a/core/Command/Maintenance/Install.php +++ b/core/Command/Maintenance/Install.php @@ -15,6 +15,7 @@ use OC\Console\TimestampFormatter; use OC\Migration\ConsoleOutput; use OC\Setup; use OC\SystemConfig; +use OCP\Server; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; @@ -51,7 +52,7 @@ class Install extends Command { protected function execute(InputInterface $input, OutputInterface $output): int { // validate the environment - $setupHelper = \OCP\Server::get(\OC\Setup::class); + $setupHelper = Server::get(Setup::class); $sysInfo = $setupHelper->getSystemInfo(true); $errors = $sysInfo['errors']; if (count($errors) > 0) { diff --git a/core/Command/Maintenance/Mimetype/GenerateMimetypeFileBuilder.php b/core/Command/Maintenance/Mimetype/GenerateMimetypeFileBuilder.php index 5b598d20672..60445b4b117 100644 --- a/core/Command/Maintenance/Mimetype/GenerateMimetypeFileBuilder.php +++ b/core/Command/Maintenance/Mimetype/GenerateMimetypeFileBuilder.php @@ -15,7 +15,7 @@ class GenerateMimetypeFileBuilder { * @param array<string,string> $aliases * @return string */ - public function generateFile(array $aliases): string { + public function generateFile(array $aliases, array $names): string { // Remove comments $aliases = array_filter($aliases, static function ($key) { // Single digit extensions will be treated as integers @@ -71,6 +71,15 @@ class GenerateMimetypeFileBuilder { sort($themes[$theme]); } + $namesOutput = ''; + foreach ($names as $key => $name) { + if (str_starts_with($key, '_')) { + // Skip internal names + continue; + } + $namesOutput .= "'$key': t('core', " . json_encode($name) . "),\n"; + } + //Generate the JS return '/** * This file is automatically generated @@ -83,7 +92,8 @@ class GenerateMimetypeFileBuilder { OC.MimeTypeList={ aliases: ' . json_encode($aliases, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . ', files: ' . json_encode($files, JSON_PRETTY_PRINT) . ', - themes: ' . json_encode($themes, JSON_PRETTY_PRINT) . ' + themes: ' . json_encode($themes, JSON_PRETTY_PRINT) . ', + names: {' . $namesOutput . '}, }; '; } diff --git a/core/Command/Maintenance/Mimetype/UpdateJS.php b/core/Command/Maintenance/Mimetype/UpdateJS.php index 35633f16355..2132ff54c6d 100644 --- a/core/Command/Maintenance/Mimetype/UpdateJS.php +++ b/core/Command/Maintenance/Mimetype/UpdateJS.php @@ -32,7 +32,8 @@ class UpdateJS extends Command { // Output the JS $generatedMimetypeFile = new GenerateMimetypeFileBuilder(); - file_put_contents(\OC::$SERVERROOT . '/core/js/mimetypelist.js', $generatedMimetypeFile->generateFile($aliases)); + $namings = $this->mimetypeDetector->getAllNamings(); + file_put_contents(\OC::$SERVERROOT . '/core/js/mimetypelist.js', $generatedMimetypeFile->generateFile($aliases, $namings)); $output->writeln('<info>mimetypelist.js is updated'); return 0; diff --git a/core/Command/Maintenance/UpdateHtaccess.php b/core/Command/Maintenance/UpdateHtaccess.php index 4939e368e2d..eeff3bf8c62 100644 --- a/core/Command/Maintenance/UpdateHtaccess.php +++ b/core/Command/Maintenance/UpdateHtaccess.php @@ -7,6 +7,7 @@ */ namespace OC\Core\Command\Maintenance; +use OC\Setup; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -19,7 +20,7 @@ class UpdateHtaccess extends Command { } protected function execute(InputInterface $input, OutputInterface $output): int { - if (\OC\Setup::updateHtaccess()) { + if (Setup::updateHtaccess()) { $output->writeln('.htaccess has been updated'); return 0; } else { diff --git a/core/Command/Preview/Repair.php b/core/Command/Preview/Repair.php index 3ccd8231300..a92a4cf8ed0 100644 --- a/core/Command/Preview/Repair.php +++ b/core/Command/Preview/Repair.php @@ -86,7 +86,7 @@ class Repair extends Command { $output->writeln(''); $output->writeln('Fetching previews that need to be migrated …'); - /** @var \OCP\Files\Folder $currentPreviewFolder */ + /** @var Folder $currentPreviewFolder */ $currentPreviewFolder = $this->rootFolder->get("appdata_$instanceId/preview"); $directoryListing = $currentPreviewFolder->getDirectoryListing(); diff --git a/core/Command/Upgrade.php b/core/Command/Upgrade.php index 6220c9a70d4..1b6fe369ceb 100644 --- a/core/Command/Upgrade.php +++ b/core/Command/Upgrade.php @@ -21,6 +21,7 @@ use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IURLGenerator; +use OCP\Server; use OCP\Util; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; @@ -63,11 +64,11 @@ class Upgrade extends Command { } $self = $this; - $updater = \OCP\Server::get(Updater::class); + $updater = Server::get(Updater::class); $incompatibleOverwrites = $this->config->getSystemValue('app_install_overwrite', []); /** @var IEventDispatcher $dispatcher */ - $dispatcher = \OC::$server->get(IEventDispatcher::class); + $dispatcher = Server::get(IEventDispatcher::class); $progress = new ProgressBar($output); $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%%"); $listener = function (MigratorExecuteSqlEvent $event) use ($progress, $output): void { @@ -132,17 +133,17 @@ class Upgrade extends Command { $dispatcher->addListener(RepairErrorEvent::class, $repairListener); - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($output) { + $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($output): void { $output->writeln('<info>Turned on maintenance mode</info>'); }); - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($output) { + $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($output): void { $output->writeln('<info>Turned off maintenance mode</info>'); }); - $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($output) { + $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($output): void { $output->writeln('<info>Maintenance mode is kept active</info>'); }); $updater->listen('\OC\Updater', 'updateEnd', - function ($success) use ($output, $self) { + function ($success) use ($output, $self): void { if ($success) { $message = '<info>Update successful</info>'; } else { @@ -150,42 +151,42 @@ class Upgrade extends Command { } $output->writeln($message); }); - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($output) { + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($output): void { $output->writeln('<info>Updating database schema</info>'); }); - $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($output) { + $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($output): void { $output->writeln('<info>Updated database</info>'); }); - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use ($output, &$incompatibleOverwrites) { + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use ($output, &$incompatibleOverwrites): void { if (!in_array($app, $incompatibleOverwrites)) { $output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>'); } }); - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($output) { + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($output): void { $output->writeln('<info>Update app ' . $app . ' from App Store</info>'); }); - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) { + $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output): void { $output->writeln("<info>Checking whether the database schema for <$app> can be updated (this can take a long time depending on the database size)</info>"); }); - $updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) { + $updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output): void { $output->writeln("<info>Updating <$app> ...</info>"); }); - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) { + $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output): void { $output->writeln("<info>Updated <$app> to $version</info>"); }); - $updater->listen('\OC\Updater', 'failure', function ($message) use ($output, $self) { + $updater->listen('\OC\Updater', 'failure', function ($message) use ($output, $self): void { $output->writeln("<error>$message</error>"); }); - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($output) { + $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($output): void { $output->writeln('<info>Setting log level to debug</info>'); }); - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($output) { + $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($output): void { $output->writeln('<info>Resetting log level</info>'); }); - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($output) { + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($output): void { $output->writeln('<info>Starting code integrity check...</info>'); }); - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($output) { + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($output): void { $output->writeln('<info>Finished code integrity check</info>'); }); diff --git a/core/Command/User/Info.php b/core/Command/User/Info.php index 6487b533fa2..220bbbf571d 100644 --- a/core/Command/User/Info.php +++ b/core/Command/User/Info.php @@ -6,6 +6,7 @@ namespace OC\Core\Command\User; use OC\Core\Command\Base; +use OCP\Files\NotFoundException; use OCP\IGroupManager; use OCP\IUser; use OCP\IUserManager; @@ -84,7 +85,7 @@ class Info extends Base { \OC_Util::setupFS($user->getUID()); try { $storage = \OC_Helper::getStorageInfo('/'); - } catch (\OCP\Files\NotFoundException $e) { + } catch (NotFoundException $e) { return []; } return [ diff --git a/core/Command/User/LastSeen.php b/core/Command/User/LastSeen.php index dbb611a4fff..984def72cd6 100644 --- a/core/Command/User/LastSeen.php +++ b/core/Command/User/LastSeen.php @@ -68,7 +68,7 @@ class LastSeen extends Base { return 1; } - $this->userManager->callForAllUsers(static function (IUser $user) use ($output) { + $this->userManager->callForAllUsers(static function (IUser $user) use ($output): void { $lastLogin = $user->getLastLogin(); if ($lastLogin === 0) { $output->writeln($user->getUID() . ' has never logged in.'); diff --git a/core/Command/User/SyncAccountDataCommand.php b/core/Command/User/SyncAccountDataCommand.php index 640b66581e1..3e3ba3961ee 100644 --- a/core/Command/User/SyncAccountDataCommand.php +++ b/core/Command/User/SyncAccountDataCommand.php @@ -16,15 +16,10 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class SyncAccountDataCommand extends Base { - protected IUserManager $userManager; - protected IAccountManager $accountManager; - public function __construct( - IUserManager $userManager, - IAccountManager $accountManager, + protected IUserManager $userManager, + protected IAccountManager $accountManager, ) { - $this->userManager = $userManager; - $this->accountManager = $accountManager; parent::__construct(); } diff --git a/core/Command/User/Welcome.php b/core/Command/User/Welcome.php index c383811f982..35ce32ff174 100644 --- a/core/Command/User/Welcome.php +++ b/core/Command/User/Welcome.php @@ -15,24 +15,15 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class Welcome extends Base { - /** @var IUserManager */ - protected $userManager; - - /** @var NewUserMailHelper */ - private $newUserMailHelper; - /** * @param IUserManager $userManager * @param NewUserMailHelper $newUserMailHelper */ public function __construct( - IUserManager $userManager, - NewUserMailHelper $newUserMailHelper, + protected IUserManager $userManager, + private NewUserMailHelper $newUserMailHelper, ) { parent::__construct(); - - $this->userManager = $userManager; - $this->newUserMailHelper = $newUserMailHelper; } /** |