-
Notifications
You must be signed in to change notification settings - Fork 91
/
ScheduleFeedsCommand.php
67 lines (55 loc) · 2.08 KB
/
ScheduleFeedsCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
declare(strict_types=1);
namespace Shopsys\FrameworkBundle\Command;
use Shopsys\FrameworkBundle\Model\Feed\FeedFacade;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(name: 'shopsys:feed-schedule')]
class ScheduleFeedsCommand extends Command
{
private const OPTION_FEED_NAME = 'feed-name';
private const OPTION_ALL = 'all';
/**
* @param \Shopsys\FrameworkBundle\Model\Feed\FeedFacade $feedFacade
*/
public function __construct(
protected readonly FeedFacade $feedFacade,
) {
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function configure(): void
{
$this
->setDescription('Schedule feeds to be generated in the next cron run.')
->addOption(self::OPTION_FEED_NAME, null, InputOption::VALUE_OPTIONAL, 'name of feed to be scheduled')
->addOption(self::OPTION_ALL, null, InputOption::VALUE_NONE, 'schedule all feeds');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$optionAll = $input->getOption(self::OPTION_ALL);
$optionFeedName = $input->getOption(self::OPTION_FEED_NAME);
$symfonyStyle = new SymfonyStyle($input, $output);
if ($optionAll === true) {
$symfonyStyle->info('Marking all feeds for scheduling...');
$this->feedFacade->scheduleAllFeeds();
} elseif ($optionFeedName !== null) {
$symfonyStyle->info('Marking feed for scheduling...');
$this->feedFacade->scheduleFeedByName($optionFeedName);
} else {
$symfonyStyle->error('You have to specify either --all or --feed-name option.');
return Command::FAILURE;
}
$symfonyStyle->success('Done!');
return Command::SUCCESS;
}
}