1 | <?php |
||
25 | class ProvisionCommand extends Command |
||
26 | { |
||
27 | const HELP_MESSAGE = <<<'EOF' |
||
28 | The <info>%command.name% [path-to-folder]</info> command will scan the content of [path-to-folder] directory. |
||
29 | |||
30 | The script will look for <info>.env</info> file containing connection information in format: |
||
31 | <comment> |
||
32 | DATABASE_USER=[user] |
||
33 | DATABASE_PASSWORD=[password] |
||
34 | DATABASE_HOST=[host] |
||
35 | DATABASE_PORT=[port] |
||
36 | DATABASE_NAME=[database] |
||
37 | PROVISIONING_TABLE=changelog_database_deployments |
||
38 | PROVISIONING_TABLE_CANDIDATE_NUMBER_COLUMN=deploy_script_number |
||
39 | </comment> |
||
40 | |||
41 | If you want to create initial .env use <info>--init</info> |
||
42 | |||
43 | <info>%command.name% --init [path-to-folder]</info> |
||
44 | |||
45 | The next step is searching for sql files and trying to queue them in numerical order. |
||
46 | First n-th digits of a filename will be treated as candidate number. |
||
47 | This will be used then to check in database if a certain file was already deployed (PROVISIONING_TABLE_CANDIDATE_NUMBER_COLUMN). |
||
48 | Before the insert, it will print the formatted output of a file and result of internal syntax check. |
||
49 | Then you can either skip or execute each. |
||
50 | |||
51 | If you would like to skip already provisioned candidates use <info>--skip-provisioned</info> |
||
52 | If you would like to skip syntax checking (for speed purpose) of candidates use <info>--skip-syntax-check</info> |
||
53 | |||
54 | EOF; |
||
55 | |||
56 | /** @var Candidate[] */ |
||
57 | private $workingDirectoryCandidates = []; |
||
58 | |||
59 | /** @var WorkingDirectory */ |
||
60 | private $workingDirectory; |
||
61 | |||
62 | /** @var SymfonyStyle */ |
||
63 | private $io; |
||
64 | |||
65 | /** @var Connection */ |
||
66 | private $connection; |
||
67 | |||
68 | /** @var boolean */ |
||
69 | private $skipProvisionedCandidates = false; |
||
70 | |||
71 | /** @var CandidateBuilder */ |
||
72 | private $candidateBuilder; |
||
73 | |||
74 | /** @var DataRowsBuilder */ |
||
75 | private $dataRowsBuilder; |
||
76 | |||
77 | /** @var integer */ |
||
78 | private $queuedCandidatesCount = 0; |
||
79 | |||
80 | /** @var array */ |
||
81 | private $errorMessages = []; |
||
82 | |||
83 | /** @var ProvisionDispatcher */ |
||
84 | private $dispatcher; |
||
85 | |||
86 | |||
87 | |||
88 | /** |
||
89 | * @param string $name |
||
90 | * @param WorkingDirectory $workingDirectory |
||
91 | * @param Connection $connection |
||
92 | * @param CandidateBuilder $candidateBuilder |
||
93 | * @param DataRowsBuilder $dataRowsBuilder |
||
94 | * @param ProvisionDispatcher $dispatcher |
||
95 | */ |
||
96 | 1 | public function __construct( |
|
113 | |||
114 | |||
115 | 1 | protected function configure() |
|
135 | |||
136 | |||
137 | /** |
||
138 | * @param InputInterface $input |
||
139 | * @param OutputInterface $output |
||
140 | * @return int |
||
141 | */ |
||
142 | protected function execute(InputInterface $input, OutputInterface $output) |
||
161 | |||
162 | |||
163 | /** |
||
164 | * @param InputInterface $input |
||
165 | * @param OutputInterface $output |
||
166 | */ |
||
167 | protected function start(InputInterface $input, OutputInterface $output) |
||
175 | |||
176 | |||
177 | protected function fetchCandidates() |
||
190 | |||
191 | |||
192 | /** |
||
193 | * @param SplFileInfo $candidateFile |
||
194 | */ |
||
195 | protected function processCandidateFile($candidateFile) |
||
211 | |||
212 | |||
213 | protected function iterateOverWorkingDirectory() |
||
225 | |||
226 | |||
227 | protected function showSyntaxErrors() |
||
234 | |||
235 | |||
236 | /** |
||
237 | * @param InputInterface $input |
||
238 | */ |
||
239 | protected function processWorkingDirectory(InputInterface $input) |
||
245 | |||
246 | |||
247 | /** |
||
248 | * @param InputInterface $input |
||
249 | */ |
||
250 | private function loadOrCreateEnvironment(InputInterface $input) |
||
260 | |||
261 | |||
262 | private function setConnectionParameters() |
||
270 | |||
271 | |||
272 | private function processCandidates() |
||
282 | |||
283 | |||
284 | private function printAllCandidates() |
||
293 | } |
||
294 |