|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Loevgaard\DandomainConsignmentBundle\Command; |
|
6
|
|
|
|
|
7
|
|
|
use Loevgaard\DandomainConsignment\Entity\Generated\ReportInterface; |
|
8
|
|
|
use Loevgaard\DandomainConsignment\Repository\ReportRepository; |
|
9
|
|
|
use Loevgaard\DandomainConsignmentBundle\ConsignmentService\ConsignmentServiceCollection; |
|
10
|
|
|
use Loevgaard\DandomainConsignmentBundle\Exception\NonExistentConsignmentServiceException; |
|
11
|
|
|
use Loevgaard\DandomainConsignmentBundle\Exception\NonExistentReportException; |
|
12
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
15
|
|
|
use Symfony\Component\Console\Logger\ConsoleLogger; |
|
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
17
|
|
|
|
|
18
|
|
|
class GenerateFileCommand extends ContainerAwareCommand |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var ReportRepository |
|
22
|
|
|
*/ |
|
23
|
|
|
private $reportRepository; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var ConsignmentServiceCollection |
|
27
|
|
|
*/ |
|
28
|
|
|
private $consignmentServiceCollection; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct(ReportRepository $reportRepository, ConsignmentServiceCollection $consignmentServiceCollection) |
|
31
|
|
|
{ |
|
32
|
|
|
parent::__construct(); |
|
33
|
|
|
|
|
34
|
|
|
$this->reportRepository = $reportRepository; |
|
35
|
|
|
$this->consignmentServiceCollection = $consignmentServiceCollection; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
protected function configure() |
|
39
|
|
|
{ |
|
40
|
|
|
$this |
|
41
|
|
|
->setName('loevgaard:dandomain-consignment:generate-file') |
|
42
|
|
|
->setDescription('Generates a report file from an existing report') |
|
43
|
|
|
->addArgument('report', InputArgument::REQUIRED, 'The report to generate') |
|
44
|
|
|
; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param InputInterface $input |
|
49
|
|
|
* @param OutputInterface $output |
|
50
|
|
|
* |
|
51
|
|
|
* @return int|null|void |
|
52
|
|
|
* |
|
53
|
|
|
* @throws NonExistentReportException |
|
54
|
|
|
* @throws NonExistentConsignmentServiceException |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
57
|
|
|
{ |
|
58
|
|
|
$reportId = (int) $input->getArgument('report'); |
|
59
|
|
|
|
|
60
|
|
|
/** @var ReportInterface $report */ |
|
61
|
|
|
$report = $this->reportRepository->find($reportId); |
|
62
|
|
|
|
|
63
|
|
|
if (!$report) { |
|
64
|
|
|
throw new NonExistentReportException('The report with id '.$reportId.' does not exist'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
// find the consignment service |
|
68
|
|
|
$consignmentService = $this->consignmentServiceCollection->findConsignmentService($report->getManufacturer()); |
|
69
|
|
|
$consignmentService->setLogger(new ConsoleLogger($output)); |
|
70
|
|
|
|
|
71
|
|
|
// generate the report |
|
72
|
|
|
$reportFile = $consignmentService->generateReportFile($report); |
|
73
|
|
|
|
|
74
|
|
|
$output->writeln('Report saved to '.$reportFile->getPathname()); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|