Skip to content
Merged
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
27 changes: 25 additions & 2 deletions lib/Command/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@

namespace OCA\UserMigration\Command;

use OC\Core\Command\Base;
use OCA\UserMigration\Service\UserMigrationService;
use OCA\UserMigration\TempExportDestination;
use OCP\ITempManager;
use OCP\IUser;
use OCP\IUserManager;
use OCP\UserMigration\IMigrator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Command\HelpCommand;
use Symfony\Component\Console\Formatter\WrappableOutputFormatterInterface;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -41,7 +41,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class Export extends Command {
class Export extends Base {
private IUserManager $userManager;
private UserMigrationService $migrationService;
private ITempManager $tempManager;
Expand All @@ -68,6 +68,13 @@ protected function configure(): void {
'List the available data types, pass <comment>--list=full</comment> to show more information',
false,
)
->addOption(
'output',
null,
InputOption::VALUE_OPTIONAL,
'Output format (plain, json or json_pretty, default is plain)',
$this->defaultOutputFormat,
)
->addOption(
'types',
't',
Expand Down Expand Up @@ -114,12 +121,28 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$migrators = $this->migrationService->getMigrators();

$list = $input->getOption('list');
$outputOption = $input->getOption('output');
if ($list !== false) {
switch (true) {
case $list === null:
if ($outputOption !== static::OUTPUT_FORMAT_PLAIN) {
$this->writeArrayInOutputFormat($input, $io, array_map(fn (IMigrator $migrator) => $migrator->getId(), $migrators), '');
return 0;
}
$io->writeln(array_map(fn (IMigrator $migrator) => $migrator->getId(), $migrators));
return 0;
case $list === 'full':
if ($outputOption !== static::OUTPUT_FORMAT_PLAIN) {
$migratorMap = [];
foreach ($migrators as $migrator) {
$migratorMap[$migrator->getId()] = [
'name' => $migrator->getDisplayName(),
'description' => $migrator->getDescription(),
];
}
$this->writeArrayInOutputFormat($input, $io, $migratorMap, '');
return 0;
}
$io->table(
['Name', 'Id', 'Description'],
array_map(
Expand Down
5 changes: 5 additions & 0 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@
<code>getId</code>
</UndefinedInterfaceMethod>
</file>
<file src="lib/Command/Export.php">
<InvalidArgument occurrences="1">
<code>$this</code>
</InvalidArgument>
</file>
Comment on lines +37 to +41
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that triggered?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed the failure in the CI. Is it not possible to add the property to the stub?
Otherwise we should just move OC\Core\Command\Base to OCP, it makes sense to make it available for applications.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok moving Command\Base to OCP was refused in nextcloud/server#32332 so we have to wait on nextcloud/server#32780
In the mean time add the property in the stub if possible, if not add it to the baseline.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that triggered?

It's from the call to $help->setCommand($this)

In the mean time add the property in the stub if possible, if not add it to the baseline.

Stubbed

</files>
21 changes: 20 additions & 1 deletion tests/stubs/stub.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ namespace OC\Hooks {
}

namespace OC\Cache {

use OCP\ICache;

class CappedMemoryCache implements ICache, \ArrayAccess {
Expand All @@ -136,3 +135,23 @@ namespace OC\Cache {
public static function isAvailable(): bool {}
}
}

namespace OC\Core\Command {
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Base {
public const OUTPUT_FORMAT_PLAIN = 'plain';
public const OUTPUT_FORMAT_JSON = 'json';
public const OUTPUT_FORMAT_JSON_PRETTY = 'json_pretty';

protected string $defaultOutputFormat = static::OUTPUT_FORMAT_PLAIN;

public function __construct() {}
protected function configure() {}
public function run(InputInterface $input, OutputInterface $output) {}
public function setName(string $name) {}
public function getHelper(string $name) {}
protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, array $items, string $prefix = ' - ') {}
}
}