@@ -17,32 +17,32 @@ |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - protected function configure() |
|
24 | - { |
|
25 | - $this |
|
26 | - ->setName('patches:apply-all') |
|
27 | - ->setDescription('Apply pending patches.') |
|
28 | - ->setDefinition(array( |
|
29 | - |
|
30 | - )) |
|
31 | - ->setHelp(<<<EOT |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + protected function configure() |
|
24 | + { |
|
25 | + $this |
|
26 | + ->setName('patches:apply-all') |
|
27 | + ->setDescription('Apply pending patches.') |
|
28 | + ->setDefinition(array( |
|
29 | + |
|
30 | + )) |
|
31 | + ->setHelp(<<<EOT |
|
32 | 32 | Apply pending patches. You can select the type of patches to be applied using the options. Default patches are always applied. |
33 | 33 | |
34 | 34 | Use patches:apply if you want to cherry-pick a particular patch. |
35 | 35 | EOT |
36 | - ); |
|
37 | - |
|
38 | - $this->registerOptions(); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * {@inheritdoc} |
|
43 | - */ |
|
44 | - protected function execute(InputInterface $input, OutputInterface $output) |
|
45 | - { |
|
46 | - $this->applyAll($input, $output); |
|
47 | - } |
|
36 | + ); |
|
37 | + |
|
38 | + $this->registerOptions(); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * {@inheritdoc} |
|
43 | + */ |
|
44 | + protected function execute(InputInterface $input, OutputInterface $output) |
|
45 | + { |
|
46 | + $this->applyAll($input, $output); |
|
47 | + } |
|
48 | 48 | } |
@@ -12,81 +12,81 @@ |
||
12 | 12 | |
13 | 13 | class AbstractApplyAllCommand extends Command |
14 | 14 | { |
15 | - /** |
|
16 | - * @var PatchService |
|
17 | - */ |
|
18 | - protected $patchService; |
|
19 | - |
|
20 | - public function __construct(PatchService $patchService) |
|
21 | - { |
|
22 | - $this->patchService = $patchService; |
|
23 | - parent::__construct(); |
|
24 | - } |
|
25 | - |
|
26 | - protected function registerOptions(): void |
|
27 | - { |
|
28 | - foreach ($this->patchService->getTypes() as $type) { |
|
29 | - if ($type->getName() !== '') { |
|
30 | - $this->addOption($type->getName(), null, InputOption::VALUE_NONE, 'Applies patches of type "'.$type->getName().'". '.$type->getDescription()); |
|
31 | - } |
|
32 | - } |
|
33 | - } |
|
34 | - |
|
35 | - protected function applyAll(InputInterface $input, OutputInterface $output) |
|
36 | - { |
|
37 | - $types = []; |
|
38 | - foreach ($this->patchService->getTypes() as $type) { |
|
39 | - if ($type->getName() !== '' && $input->getOption($type->getName())) { |
|
40 | - $types[] = $type->getName(); |
|
41 | - } |
|
42 | - } |
|
43 | - |
|
44 | - try { |
|
45 | - |
|
46 | - [ |
|
47 | - 'applied' => $appliedPatchArray, |
|
48 | - 'skipped' => $skippedPatchArray |
|
49 | - ] = $this->patchService->applyAll($types); |
|
50 | - |
|
51 | - } catch (\Exception $e) { |
|
52 | - $output->writeln(sprintf( |
|
53 | - 'An error occurred while applying patch: <error>%s</error>', $e->getMessage() |
|
54 | - )); |
|
55 | - throw $e; |
|
56 | - } |
|
57 | - |
|
58 | - $msg = $this->getNotificationMessage($appliedPatchArray, $skippedPatchArray); |
|
59 | - if ($msg) { |
|
60 | - $output->writeln($msg); |
|
61 | - } else { |
|
62 | - $output->writeln('<info>No patches to apply</info>'); |
|
63 | - } |
|
64 | - } |
|
65 | - |
|
66 | - private function getNotificationMessage(array $appliedPatchArray, array $skippedPatchArray): string |
|
67 | - { |
|
68 | - $nbPatchesApplied = array_sum($appliedPatchArray); |
|
69 | - $nbPatchesSkipped = array_sum($skippedPatchArray); |
|
70 | - $msg = ''; |
|
71 | - if ($nbPatchesApplied !== 0) { |
|
72 | - $patchArr = []; |
|
73 | - foreach ($appliedPatchArray as $name => $number) { |
|
74 | - $name = $name ?: 'default'; |
|
75 | - $patchArr[] = $name.': <info>'.$number.'</info>'; |
|
76 | - } |
|
77 | - |
|
78 | - $msg .= sprintf('<info>%d</info> patch%s applied (%s)', $nbPatchesApplied, ($nbPatchesApplied > 1)?'es':'', implode(', ', $patchArr))."\n"; |
|
79 | - } |
|
80 | - if ($nbPatchesSkipped !== 0) { |
|
81 | - $patchArr = []; |
|
82 | - foreach ($skippedPatchArray as $name => $number) { |
|
83 | - $name = $name ?: 'default'; |
|
84 | - $patchArr[] = $name.': <info>'.$number.'</info>'; |
|
85 | - } |
|
86 | - |
|
87 | - $msg .= sprintf('<info>%d</info><comment> patch%s skipped</comment> (%s)', $nbPatchesSkipped, ($nbPatchesSkipped > 1)?'es':'', implode(', ', $patchArr)); |
|
88 | - } |
|
89 | - |
|
90 | - return $msg; |
|
91 | - } |
|
15 | + /** |
|
16 | + * @var PatchService |
|
17 | + */ |
|
18 | + protected $patchService; |
|
19 | + |
|
20 | + public function __construct(PatchService $patchService) |
|
21 | + { |
|
22 | + $this->patchService = $patchService; |
|
23 | + parent::__construct(); |
|
24 | + } |
|
25 | + |
|
26 | + protected function registerOptions(): void |
|
27 | + { |
|
28 | + foreach ($this->patchService->getTypes() as $type) { |
|
29 | + if ($type->getName() !== '') { |
|
30 | + $this->addOption($type->getName(), null, InputOption::VALUE_NONE, 'Applies patches of type "'.$type->getName().'". '.$type->getDescription()); |
|
31 | + } |
|
32 | + } |
|
33 | + } |
|
34 | + |
|
35 | + protected function applyAll(InputInterface $input, OutputInterface $output) |
|
36 | + { |
|
37 | + $types = []; |
|
38 | + foreach ($this->patchService->getTypes() as $type) { |
|
39 | + if ($type->getName() !== '' && $input->getOption($type->getName())) { |
|
40 | + $types[] = $type->getName(); |
|
41 | + } |
|
42 | + } |
|
43 | + |
|
44 | + try { |
|
45 | + |
|
46 | + [ |
|
47 | + 'applied' => $appliedPatchArray, |
|
48 | + 'skipped' => $skippedPatchArray |
|
49 | + ] = $this->patchService->applyAll($types); |
|
50 | + |
|
51 | + } catch (\Exception $e) { |
|
52 | + $output->writeln(sprintf( |
|
53 | + 'An error occurred while applying patch: <error>%s</error>', $e->getMessage() |
|
54 | + )); |
|
55 | + throw $e; |
|
56 | + } |
|
57 | + |
|
58 | + $msg = $this->getNotificationMessage($appliedPatchArray, $skippedPatchArray); |
|
59 | + if ($msg) { |
|
60 | + $output->writeln($msg); |
|
61 | + } else { |
|
62 | + $output->writeln('<info>No patches to apply</info>'); |
|
63 | + } |
|
64 | + } |
|
65 | + |
|
66 | + private function getNotificationMessage(array $appliedPatchArray, array $skippedPatchArray): string |
|
67 | + { |
|
68 | + $nbPatchesApplied = array_sum($appliedPatchArray); |
|
69 | + $nbPatchesSkipped = array_sum($skippedPatchArray); |
|
70 | + $msg = ''; |
|
71 | + if ($nbPatchesApplied !== 0) { |
|
72 | + $patchArr = []; |
|
73 | + foreach ($appliedPatchArray as $name => $number) { |
|
74 | + $name = $name ?: 'default'; |
|
75 | + $patchArr[] = $name.': <info>'.$number.'</info>'; |
|
76 | + } |
|
77 | + |
|
78 | + $msg .= sprintf('<info>%d</info> patch%s applied (%s)', $nbPatchesApplied, ($nbPatchesApplied > 1)?'es':'', implode(', ', $patchArr))."\n"; |
|
79 | + } |
|
80 | + if ($nbPatchesSkipped !== 0) { |
|
81 | + $patchArr = []; |
|
82 | + foreach ($skippedPatchArray as $name => $number) { |
|
83 | + $name = $name ?: 'default'; |
|
84 | + $patchArr[] = $name.': <info>'.$number.'</info>'; |
|
85 | + } |
|
86 | + |
|
87 | + $msg .= sprintf('<info>%d</info><comment> patch%s skipped</comment> (%s)', $nbPatchesSkipped, ($nbPatchesSkipped > 1)?'es':'', implode(', ', $patchArr)); |
|
88 | + } |
|
89 | + |
|
90 | + return $msg; |
|
91 | + } |
|
92 | 92 | } |
93 | 93 | \ No newline at end of file |
@@ -15,34 +15,34 @@ |
||
15 | 15 | */ |
16 | 16 | class ResetPatchesCommand extends AbstractApplyAllCommand |
17 | 17 | { |
18 | - /** |
|
19 | - * {@inheritdoc} |
|
20 | - */ |
|
21 | - protected function configure() |
|
22 | - { |
|
23 | - $this |
|
24 | - ->setName('patches:reset') |
|
25 | - ->setDescription('Reset database and reapply all patches.') |
|
26 | - ->setDefinition(array( |
|
18 | + /** |
|
19 | + * {@inheritdoc} |
|
20 | + */ |
|
21 | + protected function configure() |
|
22 | + { |
|
23 | + $this |
|
24 | + ->setName('patches:reset') |
|
25 | + ->setDescription('Reset database and reapply all patches.') |
|
26 | + ->setDefinition(array( |
|
27 | 27 | |
28 | - )) |
|
29 | - ->setHelp(<<<EOT |
|
28 | + )) |
|
29 | + ->setHelp(<<<EOT |
|
30 | 30 | Reset the database and reapplies all pending patches. You can select the type of patches to be applied using the options. Default patches are always applied. |
31 | 31 | |
32 | 32 | Use patches:apply-all if you want to apply remaining patches without resetting the database. |
33 | 33 | EOT |
34 | - ); |
|
34 | + ); |
|
35 | 35 | |
36 | - $this->registerOptions(); |
|
37 | - } |
|
36 | + $this->registerOptions(); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * {@inheritdoc} |
|
41 | - */ |
|
42 | - protected function execute(InputInterface $input, OutputInterface $output) |
|
43 | - { |
|
44 | - $this->patchService->reset(); |
|
39 | + /** |
|
40 | + * {@inheritdoc} |
|
41 | + */ |
|
42 | + protected function execute(InputInterface $input, OutputInterface $output) |
|
43 | + { |
|
44 | + $this->patchService->reset(); |
|
45 | 45 | |
46 | - $this->applyAll($input, $output); |
|
47 | - } |
|
46 | + $this->applyAll($input, $output); |
|
47 | + } |
|
48 | 48 | } |