Files
tonehaus/src/Command/SyncExternalProviderCommand.php
T
2026-04-02 13:46:07 +01:00

50 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Command;
use App\Service\ExternalProviderManager;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(
name: 'app:sync-external-provider',
description: 'Applies effective external provider and resets catalog if provider changed.'
)]
class SyncExternalProviderCommand extends Command
{
public function __construct(
private readonly ExternalProviderManager $providerManager,
) {
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$result = $this->providerManager->syncEffectiveProviderAtStartup();
if ($result['reset']) {
$io->warning(sprintf(
'External provider changed from %s to %s. Reset catalog: deleted %d albums and %d reviews.',
$result['previous_provider'],
$result['effective_provider'],
$result['albums'],
$result['reviews']
));
return Command::SUCCESS;
}
$io->success(sprintf(
'External provider unchanged (%s). Catalog reset not required.',
$result['effective_provider']
));
return Command::SUCCESS;
}
}