|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\Cli\CampaignConfigValidation; |
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\Console\Command\Command; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
use WMDE\Fundraising\Frontend\BucketTesting\Validation\CampaignErrorCollection; |
|
13
|
|
|
use WMDE\Fundraising\Frontend\BucketTesting\Validation\CampaignValidator; |
|
14
|
|
|
use WMDE\Fundraising\Frontend\BucketTesting\Validation\LoggingCampaignConfigurationLoader; |
|
15
|
|
|
use WMDE\Fundraising\Frontend\Infrastructure\EnvironmentBootstrapper; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @license GPL-2.0-or-later |
|
19
|
|
|
*/ |
|
20
|
|
|
class ValidateCampaignConfigCommand extends Command { |
|
21
|
|
|
|
|
22
|
|
|
private const NAME = 'app:validate:campaigns'; |
|
23
|
|
|
private const RETURN_CODE_OK = 0; |
|
24
|
|
|
private const RETURN_CODE_ERROR = 1; |
|
25
|
|
|
|
|
26
|
|
|
protected function configure(): void { |
|
27
|
|
|
$this->setName( self::NAME ) |
|
28
|
|
|
->setDescription( 'Validate campaign configuration files' ) |
|
29
|
|
|
->setHelp( |
|
30
|
|
|
'This command validates the Campaign configuration files for errors after they have been merged' |
|
31
|
|
|
) |
|
32
|
|
|
->setDefinition( |
|
33
|
|
|
new InputDefinition( |
|
34
|
|
|
[ |
|
35
|
|
|
new InputArgument( |
|
36
|
|
|
'environment', |
|
37
|
|
|
InputArgument::OPTIONAL, |
|
38
|
|
|
'Specify a specific campaign environment which is to be tested', |
|
39
|
|
|
'prod' |
|
40
|
|
|
) |
|
41
|
|
|
] |
|
42
|
|
|
) |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function execute( InputInterface $input, OutputInterface $output ): int { |
|
47
|
|
|
$environment = $input->getArgument( 'environment' ); |
|
48
|
|
|
$errorLogger = new CampaignErrorCollection(); |
|
49
|
|
|
$bootstrapper = new EnvironmentBootstrapper( $environment ); |
|
|
|
|
|
|
50
|
|
|
$factory = $bootstrapper->newFunFunFactory(); |
|
51
|
|
|
$factory->setCampaignConfigurationLoader( |
|
52
|
|
|
new LoggingCampaignConfigurationLoader( |
|
53
|
|
|
$factory->getCampaignConfigurationLoader(), $errorLogger |
|
54
|
|
|
) |
|
55
|
|
|
); |
|
56
|
|
|
|
|
57
|
|
|
$campaignCollection = $factory->getCampaignCollection(); |
|
58
|
|
|
if ( $errorLogger->hasErrors() === false ) { |
|
59
|
|
|
$validator = new CampaignValidator( $campaignCollection, $errorLogger ); |
|
60
|
|
|
|
|
61
|
|
|
if ( $validator->isPassing() ) { |
|
62
|
|
|
return self::RETURN_CODE_OK; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
foreach ( $errorLogger->getErrors() as $error ) { |
|
67
|
|
|
$output->writeln( $error ); |
|
68
|
|
|
} |
|
69
|
|
|
$output->writeln( 'Campaign YAML validation failed.' ); |
|
70
|
|
|
return self::RETURN_CODE_ERROR; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|