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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Developer\Console\Command;
use Magento\Developer\Model\Setup\Declaration\Schema\WhitelistGenerator;
use Magento\Framework\Config\FileResolverByModule;
use Magento\Framework\Exception\ConfigurationMismatchException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Command that allows to generate whitelist, that will be used, when declaration data is installed.
*
* If whitelist already exists, new values will be added to existing whitelist.
*/
class TablesWhitelistGenerateCommand extends Command
{
/**
* Module name key, that will be used in whitelist generate command.
*/
const MODULE_NAME_KEY = 'module-name';
/**
* @var WhitelistGenerator
*/
private $whitelistGenerator;
/**
* @param WhitelistGenerator $whitelistGenerator
* @param string|null $name
*/
public function __construct(
WhitelistGenerator $whitelistGenerator,
$name = null
) {
$this->whitelistGenerator = $whitelistGenerator;
parent::__construct($name);
}
/**
* Initialization of the command.
*
* @return void
*/
protected function configure()
{
$this->setName('setup:db-declaration:generate-whitelist')
->setDescription(
'Generate whitelist of tables and columns that are allowed to be edited by declaration installer'
)
->setDefinition(
[
new InputOption(
self::MODULE_NAME_KEY,
null,
InputOption::VALUE_OPTIONAL,
'Name of the module where whitelist will be generated',
FileResolverByModule::ALL_MODULES
)
]
);
parent::configure();
}
/**
* @inheritdoc
*/
protected function execute(InputInterface $input, OutputInterface $output) : int
{
$moduleName = $input->getOption(self::MODULE_NAME_KEY);
try {
$this->whitelistGenerator->generate($moduleName);
} catch (ConfigurationMismatchException $e) {
$output->writeln($e->getMessage());
return \Magento\Framework\Console\Cli::RETURN_FAILURE;
} catch (\Exception $e) {
return \Magento\Framework\Console\Cli::RETURN_FAILURE;
}
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
}
}