1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Command; |
4
|
|
|
|
5
|
|
|
use App\Document\Provider; |
6
|
|
|
use App\Mercure\ProviderPublisher; |
7
|
|
|
use App\Messenger\Message\ProviderImportation; |
8
|
|
|
use Doctrine\ODM\MongoDB\DocumentManager; |
9
|
|
|
use Symfony\Component\Console\Command\Command; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
13
|
|
|
use Symfony\Component\Messenger\MessageBusInterface; |
14
|
|
|
|
15
|
|
|
class RequestReloadProvidersCommand extends Command |
16
|
|
|
{ |
17
|
|
|
protected $bus; |
18
|
|
|
private $publisher; |
19
|
|
|
private $manager; |
20
|
|
|
|
21
|
|
|
public function __construct(DocumentManager $manager, MessageBusInterface $bus, ProviderPublisher $publisher) |
22
|
|
|
{ |
23
|
|
|
$this->manager = $manager; |
24
|
|
|
$this->bus = $bus; |
25
|
|
|
$this->publisher = $publisher; |
26
|
|
|
parent::__construct(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
protected function configure() |
30
|
|
|
{ |
31
|
|
|
$this |
32
|
|
|
->setName('app:request-reload-providers') |
33
|
|
|
->setDescription('Reload all providers.'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
37
|
|
|
{ |
38
|
|
|
$io = new SymfonyStyle($input, $output); |
39
|
|
|
|
40
|
|
|
$io->title('Request update of all providers'); |
41
|
|
|
|
42
|
|
|
// do not use findAll for memory usage |
43
|
|
|
$providers = $this->manager->getRepository('App:Provider') |
44
|
|
|
->createQueryBuilder() |
45
|
|
|
->getQuery() |
46
|
|
|
->execute(); |
47
|
|
|
|
48
|
|
|
/** @var Provider $provider */ |
49
|
|
|
foreach ($providers as $provider) { |
50
|
|
|
$io->text('Request for '.$provider->getName()); |
51
|
|
|
$provider->setUpdateInProgress(true); |
52
|
|
|
$this->manager->flush(); |
53
|
|
|
$this->bus->dispatch(new ProviderImportation($provider->getName())); |
54
|
|
|
$this->publisher->publishProviderUpdate($provider); |
55
|
|
|
$this->manager->detach($provider); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|