diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-08-22 15:58:50 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-08-25 16:13:46 +0200 |
commit | 4f260dce6e43ddef835105a1d4dc13f2b8742526 (patch) | |
tree | e69cf7ca3be76975519dba86179fc39609efe7f8 | |
parent | 4ba30d40cfc892bee0ea28486e63c479e1aadd20 (diff) | |
download | nextcloud-server-4f260dce6e43ddef835105a1d4dc13f2b8742526.tar.gz nextcloud-server-4f260dce6e43ddef835105a1d4dc13f2b8742526.zip |
Moving to string key for arguments of GenericEvent in Repair
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r-- | build/psalm-baseline.xml | 17 | ||||
-rw-r--r-- | core/Command/Maintenance/Repair.php | 12 | ||||
-rw-r--r-- | core/Command/Upgrade.php | 16 | ||||
-rw-r--r-- | core/ajax/update.php | 39 | ||||
-rw-r--r-- | lib/private/Repair.php | 24 | ||||
-rw-r--r-- | lib/private/Updater.php | 16 | ||||
-rw-r--r-- | lib/private/legacy/OC_App.php | 2 |
7 files changed, 51 insertions, 75 deletions
diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 39947ac0315..d70c2822bfa 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -3946,23 +3946,6 @@ <code>$path</code> </InvalidReturnStatement> </file> - <file src="lib/private/Updater.php"> - <InvalidScalarArgument occurrences="13"> - <code>0</code> - <code>0</code> - <code>0</code> - <code>0</code> - <code>0</code> - <code>0</code> - <code>0</code> - <code>0</code> - <code>0</code> - <code>1</code> - <code>1</code> - <code>1</code> - <code>1</code> - </InvalidScalarArgument> - </file> <file src="lib/private/Updater/VersionCheck.php"> <InvalidScalarArgument occurrences="2"> <code>microtime(true)</code> diff --git a/core/Command/Maintenance/Repair.php b/core/Command/Maintenance/Repair.php index 2c1fda7c8e4..6dac3085ca8 100644 --- a/core/Command/Maintenance/Repair.php +++ b/core/Command/Maintenance/Repair.php @@ -122,26 +122,26 @@ class Repair extends Command { } switch ($event->getSubject()) { case '\OC\Repair::startProgress': - $this->progress->start($event->getArgument(0)); + $this->progress->start($event->getArgument('max')); break; case '\OC\Repair::advance': - $this->progress->advance($event->getArgument(0)); + $this->progress->advance($event->getArgument('step')); break; case '\OC\Repair::finishProgress': $this->progress->finish(); $this->output->writeln(''); break; case '\OC\Repair::step': - $this->output->writeln(' - ' . $event->getArgument(0)); + $this->output->writeln(' - ' . $event->getArgument('step')); break; case '\OC\Repair::info': - $this->output->writeln(' - ' . $event->getArgument(0)); + $this->output->writeln(' - ' . $event->getArgument('message')); break; case '\OC\Repair::warning': - $this->output->writeln(' - WARNING: ' . $event->getArgument(0)); + $this->output->writeln(' - WARNING: ' . $event->getArgument('message')); break; case '\OC\Repair::error': - $this->output->writeln('<error> - ERROR: ' . $event->getArgument(0) . '</error>'); + $this->output->writeln('<error> - ERROR: ' . $event->getArgument('message') . '</error>'); break; } } diff --git a/core/Command/Upgrade.php b/core/Command/Upgrade.php index 69a7f1f656f..f848ab21ea6 100644 --- a/core/Command/Upgrade.php +++ b/core/Command/Upgrade.php @@ -125,16 +125,16 @@ class Upgrade extends Command { switch ($event->getSubject()) { case '\OC\Repair::startProgress': $progress->setMessage('Starting ...'); - $output->writeln($event->getArgument(1)); + $output->writeln($event->getArgument('step')); $output->writeln(''); - $progress->start($event->getArgument(0)); + $progress->start($event->getArgument('max')); break; case '\OC\Repair::advance': - $desc = $event->getArgument(1); + $desc = $event->getArgument('desc'); if (!empty($desc)) { $progress->setMessage($desc); } - $progress->advance($event->getArgument(0)); + $progress->advance($event->getArgument('step')); break; case '\OC\Repair::finishProgress': @@ -144,19 +144,19 @@ class Upgrade extends Command { break; case '\OC\Repair::step': if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { - $output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>'); + $output->writeln('<info>Repair step: ' . $event->getArgument('step') . '</info>'); } break; case '\OC\Repair::info': if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { - $output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>'); + $output->writeln('<info>Repair info: ' . $event->getArgument('message') . '</info>'); } break; case '\OC\Repair::warning': - $output->writeln('<error>Repair warning: ' . $event->getArgument(0) . '</error>'); + $output->writeln('<error>Repair warning: ' . $event->getArgument('message') . '</error>'); break; case '\OC\Repair::error': - $output->writeln('<error>Repair error: ' . $event->getArgument(0) . '</error>'); + $output->writeln('<error>Repair error: ' . $event->getArgument('message') . '</error>'); break; } }; diff --git a/core/ajax/update.php b/core/ajax/update.php index a8352cb40be..8682f47353d 100644 --- a/core/ajax/update.php +++ b/core/ajax/update.php @@ -30,6 +30,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ +use OCP\IEventSource; +use OCP\IL10N; use OCP\ILogger; use Symfony\Component\EventDispatcher\GenericEvent; @@ -48,36 +50,31 @@ $eventSource = \OC::$server->createEventSource(); $eventSource->send('success', $l->t('Preparing update')); class FeedBackHandler { - /** @var integer */ - private $progressStateMax = 100; - /** @var integer */ - private $progressStateStep = 0; - /** @var string */ - private $currentStep; - /** @var \OCP\IEventSource */ - private $eventSource; - /** @var \OCP\IL10N */ - private $l10n; - - public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) { + private int $progressStateMax = 100; + private int $progressStateStep = 0; + private string $currentStep = ''; + private IEventSource $eventSource; + private IL10N $l10n; + + public function __construct(IEventSource $eventSource, IL10N $l10n) { $this->eventSource = $eventSource; $this->l10n = $l10n; } - public function handleRepairFeedback($event) { + public function handleRepairFeedback($event): void { if (!$event instanceof GenericEvent) { return; } switch ($event->getSubject()) { case '\OC\Repair::startProgress': - $this->progressStateMax = $event->getArgument(0); + $this->progressStateMax = $event->getArgument('max'); $this->progressStateStep = 0; - $this->currentStep = $event->getArgument(1); + $this->currentStep = (string)$event->getArgument('step'); break; case '\OC\Repair::advance': - $this->progressStateStep += $event->getArgument(0); - $desc = $event->getArgument(1); + $this->progressStateStep += $event->getArgument('step'); + $desc = $event->getArgument('desc'); if (empty($desc)) { $desc = $this->currentStep; } @@ -88,16 +85,16 @@ class FeedBackHandler { $this->eventSource->send('success', $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); break; case '\OC\Repair::step': - $this->eventSource->send('success', $this->l10n->t('Repair step:') . ' ' . $event->getArgument(0)); + $this->eventSource->send('success', $this->l10n->t('Repair step:') . ' ' . $event->getArgument('step')); break; case '\OC\Repair::info': - $this->eventSource->send('success', $this->l10n->t('Repair info:') . ' ' . $event->getArgument(0)); + $this->eventSource->send('success', $this->l10n->t('Repair info:') . ' ' . $event->getArgument('message')); break; case '\OC\Repair::warning': - $this->eventSource->send('notice', $this->l10n->t('Repair warning:') . ' ' . $event->getArgument(0)); + $this->eventSource->send('notice', $this->l10n->t('Repair warning:') . ' ' . $event->getArgument('message')); break; case '\OC\Repair::error': - $this->eventSource->send('notice', $this->l10n->t('Repair error:') . ' ' . $event->getArgument(0)); + $this->eventSource->send('notice', $this->l10n->t('Repair error:') . ' ' . $event->getArgument('message')); break; } } diff --git a/lib/private/Repair.php b/lib/private/Repair.php index 98a1f4ce036..496e9b15e2e 100644 --- a/lib/private/Repair.php +++ b/lib/private/Repair.php @@ -112,19 +112,19 @@ class Repair implements IOutput { */ public function run() { if (count($this->repairSteps) === 0) { - $this->emit('\OC\Repair', 'info', ['No repair steps available']); + $this->emit('\OC\Repair', 'info', ['message' => 'No repair steps available']); return; } // run each repair step foreach ($this->repairSteps as $step) { $this->currentStep = $step->getName(); - $this->emit('\OC\Repair', 'step', [$this->currentStep]); + $this->emit('\OC\Repair', 'step', ['step' => $this->currentStep]); try { $step->run($this); } catch (\Exception $e) { $this->logger->error("Exception while executing repair step " . $step->getName(), ['exception' => $e]); - $this->emit('\OC\Repair', 'error', [$e->getMessage()]); + $this->emit('\OC\Repair', 'error', ['message' => $e->getMessage()]); } } } @@ -250,20 +250,16 @@ class Repair implements IOutput { } /** - * @param string $scope - * @param string $method - * @param array $arguments + * @param array<string, mixed> $arguments */ - public function emit($scope, $method, array $arguments = []) { - if (!is_null($this->dispatcher)) { - $this->dispatcher->dispatch("$scope::$method", + public function emit(string $scope, string $method, array $arguments = []): void { + $this->dispatcher->dispatch("$scope::$method", new GenericEvent("$scope::$method", $arguments)); - } } public function info($string) { // for now just emit as we did in the past - $this->emit('\OC\Repair', 'info', [$string]); + $this->emit('\OC\Repair', 'info', ['message' => $string]); } /** @@ -271,7 +267,7 @@ class Repair implements IOutput { */ public function warning($message) { // for now just emit as we did in the past - $this->emit('\OC\Repair', 'warning', [$message]); + $this->emit('\OC\Repair', 'warning', ['message' => $message]); } /** @@ -279,7 +275,7 @@ class Repair implements IOutput { */ public function startProgress($max = 0) { // for now just emit as we did in the past - $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]); + $this->emit('\OC\Repair', 'startProgress', ['max' => $max, 'step' => $this->currentStep]); } /** @@ -288,7 +284,7 @@ class Repair implements IOutput { */ public function advance($step = 1, $description = '') { // for now just emit as we did in the past - $this->emit('\OC\Repair', 'advance', [$step, $description]); + $this->emit('\OC\Repair', 'advance', ['step' => $step, 'desc' => $description]); } /** diff --git a/lib/private/Updater.php b/lib/private/Updater.php index b25bb76e957..0889e87383f 100644 --- a/lib/private/Updater.php +++ b/lib/private/Updater.php @@ -293,7 +293,7 @@ class Updater extends BasicEmitter { $repair->run(); //Invalidate update feed - $this->config->setAppValue('core', 'lastupdatedat', 0); + $this->config->setAppValue('core', 'lastupdatedat', '0'); // Check for code integrity if not disabled if (\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { @@ -482,30 +482,30 @@ class Updater extends BasicEmitter { } switch ($event->getSubject()) { case '\OC\Repair::startProgress': - $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); + $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument('max') . ' (' . $event->getArgument('step') . ')', ['app' => 'updater']); break; case '\OC\Repair::advance': - $desc = $event->getArgument(1); + $desc = $event->getArgument('desc'); if (empty($desc)) { $desc = ''; } - $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); + $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument('step') . ')', ['app' => 'updater']); break; case '\OC\Repair::finishProgress': $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); break; case '\OC\Repair::step': - $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); + $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument('step'), ['app' => 'updater']); break; case '\OC\Repair::info': - $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); + $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument('message'), ['app' => 'updater']); break; case '\OC\Repair::warning': - $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); + $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument('message'), ['app' => 'updater']); break; case '\OC\Repair::error': - $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); + $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument('message'), ['app' => 'updater']); break; } }; diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index 482fc4e88e7..cd53dc0afc4 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -1055,7 +1055,7 @@ class OC_App { try { $r->addStep($step); } catch (Exception $ex) { - $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); + $r->emit('\OC\Repair', 'error', ['message' => $ex->getMessage()]); \OC::$server->getLogger()->logException($ex); } } |