Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ precedence = "aggregate"
SPDX-FileCopyrightText = "2023 Nextcloud GmbH and Nextcloud contributors"
SPDX-License-Identifier = "AGPL-3.0-or-later"

[[annotations]]
path = ["tests/stubs/oc_core_command_base.php"]
precedence = "aggregate"
SPDX-FileCopyrightText = "2026 Nextcloud GmbH and Nextcloud contributors"
SPDX-License-Identifier = "AGPL-3.0-or-later"

[[annotations]]
path = ["img/app.svg", "img/app-dark.svg"]
precedence = "aggregate"
Expand Down
4 changes: 2 additions & 2 deletions lib/Command/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

namespace OCA\NotifyPush\Command;

use OC\Core\Command\Base;
use OCA\NotifyPush\Queue\IQueue;
use Symfony\Component\Console\Command\Command;
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 Log extends Command {
class Log extends Base {
private $queue;

public function __construct(
Expand Down
11 changes: 9 additions & 2 deletions lib/Command/Metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

namespace OCA\NotifyPush\Command;

use OC\Core\Command\Base;
use OCA\NotifyPush\Queue\IQueue;
use OCA\NotifyPush\Queue\RedisQueue;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Metrics extends Command {
class Metrics extends Base {
private $queue;

public function __construct(
Expand Down Expand Up @@ -51,6 +51,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('<error>Invalid metrics received from push server</error>');
return 1;
}

// Output in the requested format if different from plain
if ($input->getOption('output') !== self::OUTPUT_FORMAT_PLAIN) {
$this->writeArrayInOutputFormat($input, $output, $metrics);
return 0;
}

$output->writeln('Active connection count: ' . $metrics['active_connection_count']);
$output->writeln('Active user count: ' . $metrics['active_user_count']);
$output->writeln('Total connection count: ' . $metrics['total_connection_count']);
Expand Down
4 changes: 2 additions & 2 deletions lib/Command/Reset.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

namespace OCA\NotifyPush\Command;

use OC\Core\Command\Base;
use OCA\NotifyPush\Queue\IQueue;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Reset extends Command {
class Reset extends Base {
private $queue;

public function __construct(
Expand Down
4 changes: 2 additions & 2 deletions lib/Command/SelfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

namespace OCA\NotifyPush\Command;

use OC\Core\Command\Base;
use OCP\IConfig;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class SelfTest extends Command {
class SelfTest extends Base {
private $test;
private $config;

Expand Down
4 changes: 2 additions & 2 deletions lib/Command/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

namespace OCA\NotifyPush\Command;

use OC\Core\Command\Base;
use OCA\NotifyPush\SetupWizard;
use OCP\IConfig;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Setup extends Command {
class Setup extends Base {
private $test;
private $config;
private $setupWizard;
Expand Down
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</extraFiles>
<stubs>
<file name="tests/stub.phpstub" preloadClasses="true"/>
<file name="tests/stubs/oc_core_command_base.php" />
<file name="tests/stubs/symfony_component_console_command_command.php" />
<file name="tests/stubs/symfony_component_console_helper_table.php" />
<file name="tests/stubs/symfony_component_console_input_inputargument.php" />
Expand Down
33 changes: 33 additions & 0 deletions tests/stubs/oc_core_command_base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace OC\Core\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Base class for Nextcloud commands with output formatting support
*/
class Base extends Command {
public const OUTPUT_FORMAT_PLAIN = 'plain';
public const OUTPUT_FORMAT_JSON = 'json';
public const OUTPUT_FORMAT_JSON_PRETTY = 'json_pretty';

protected string $defaultOutputFormat = self::OUTPUT_FORMAT_PLAIN;

protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, iterable $items, string $prefix = ' - '): void {
}

protected function writeTableInOutputFormat(InputInterface $input, OutputInterface $output, array $items): void {
}

protected function writeStreamingTableInOutputFormat(InputInterface $input, OutputInterface $output, \Iterator $items, int $tableGroupSize): void {
}

protected function writeStreamingJsonArray(InputInterface $input, OutputInterface $output, \Iterator $items): void {
}

public function chunkIterator(\Iterator $iterator, int $count): \Iterator {
}
}
Loading