@@ -1,10 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Mouf\Utils\Patcher\Commands; |
3 | 3 | |
4 | -use Mouf\Utils\Patcher\PatchInterface; |
|
5 | 4 | use Mouf\Utils\Patcher\PatchService; |
6 | -use Symfony\Component\Console\Helper\Table; |
|
7 | -use Symfony\Component\Console\Input\InputArgument; |
|
8 | 5 | use Symfony\Component\Console\Input\InputOption; |
9 | 6 | use Symfony\Component\Console\Output\OutputInterface; |
10 | 7 | use Symfony\Component\Console\Input\InputInterface; |
@@ -15,71 +15,71 @@ |
||
15 | 15 | */ |
16 | 16 | class ResetPatchesCommand extends Command |
17 | 17 | { |
18 | - /** |
|
19 | - * @var PatchService |
|
20 | - */ |
|
21 | - private $patchService; |
|
18 | + /** |
|
19 | + * @var PatchService |
|
20 | + */ |
|
21 | + private $patchService; |
|
22 | 22 | |
23 | - public function __construct(PatchService $patchService) |
|
24 | - { |
|
25 | - $this->patchService = $patchService; |
|
26 | - parent::__construct(); |
|
27 | - } |
|
23 | + public function __construct(PatchService $patchService) |
|
24 | + { |
|
25 | + $this->patchService = $patchService; |
|
26 | + parent::__construct(); |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected function configure() |
|
34 | - { |
|
35 | - $this |
|
36 | - ->setName('patches:reset') |
|
37 | - ->setDescription('Reset database and reapply all patches.') |
|
38 | - ->setDefinition(array( |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected function configure() |
|
34 | + { |
|
35 | + $this |
|
36 | + ->setName('patches:reset') |
|
37 | + ->setDescription('Reset database and reapply all patches.') |
|
38 | + ->setDefinition(array( |
|
39 | 39 | |
40 | - )) |
|
41 | - ->setHelp(<<<EOT |
|
40 | + )) |
|
41 | + ->setHelp(<<<EOT |
|
42 | 42 | 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. |
43 | 43 | |
44 | 44 | Use patches:apply-all if you want to apply remaining patches without resetting the database. |
45 | 45 | EOT |
46 | - ); |
|
46 | + ); |
|
47 | 47 | |
48 | - foreach ($this->patchService->getTypes() as $type) { |
|
49 | - if ($type->getName() !== '') { |
|
50 | - $this->addOption($type->getName(), null, InputOption::VALUE_NONE, 'Applies patches of type "'.$type->getName().'". '.$type->getDescription()); |
|
51 | - } |
|
52 | - } |
|
53 | - } |
|
48 | + foreach ($this->patchService->getTypes() as $type) { |
|
49 | + if ($type->getName() !== '') { |
|
50 | + $this->addOption($type->getName(), null, InputOption::VALUE_NONE, 'Applies patches of type "'.$type->getName().'". '.$type->getDescription()); |
|
51 | + } |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * {@inheritdoc} |
|
57 | - */ |
|
58 | - protected function execute(InputInterface $input, OutputInterface $output) |
|
59 | - { |
|
60 | - $this->patchService->reset(); |
|
55 | + /** |
|
56 | + * {@inheritdoc} |
|
57 | + */ |
|
58 | + protected function execute(InputInterface $input, OutputInterface $output) |
|
59 | + { |
|
60 | + $this->patchService->reset(); |
|
61 | 61 | |
62 | - $patchesArray = $this->patchService->getView(); |
|
62 | + $patchesArray = $this->patchService->getView(); |
|
63 | 63 | |
64 | - $count = 0; |
|
65 | - try { |
|
66 | - foreach ($patchesArray as $patch) { |
|
67 | - $this->patchService->apply($patch['uniqueName']); |
|
68 | - $count++; |
|
69 | - } |
|
70 | - } catch (\Exception $e) { |
|
71 | - $output->writeln(sprintf( |
|
72 | - 'An error occurred while applying patch <info>%s</info>: <error>%s</error>', $patch['uniqueName'], $e->getMessage() |
|
73 | - )); |
|
74 | - throw $e; |
|
75 | - } |
|
64 | + $count = 0; |
|
65 | + try { |
|
66 | + foreach ($patchesArray as $patch) { |
|
67 | + $this->patchService->apply($patch['uniqueName']); |
|
68 | + $count++; |
|
69 | + } |
|
70 | + } catch (\Exception $e) { |
|
71 | + $output->writeln(sprintf( |
|
72 | + 'An error occurred while applying patch <info>%s</info>: <error>%s</error>', $patch['uniqueName'], $e->getMessage() |
|
73 | + )); |
|
74 | + throw $e; |
|
75 | + } |
|
76 | 76 | |
77 | - if ($count) { |
|
78 | - $output->writeln(sprintf( |
|
79 | - 'Database has been reset, <info>%d</info> patches successfully applied', $count |
|
80 | - )); |
|
81 | - } else { |
|
82 | - $output->writeln('<info>Database has been reset, no patches to apply</info>'); |
|
83 | - } |
|
84 | - } |
|
77 | + if ($count) { |
|
78 | + $output->writeln(sprintf( |
|
79 | + 'Database has been reset, <info>%d</info> patches successfully applied', $count |
|
80 | + )); |
|
81 | + } else { |
|
82 | + $output->writeln('<info>Database has been reset, no patches to apply</info>'); |
|
83 | + } |
|
84 | + } |
|
85 | 85 | } |
@@ -15,71 +15,71 @@ |
||
15 | 15 | */ |
16 | 16 | class ApplyAllPatchesCommand extends Command |
17 | 17 | { |
18 | - /** |
|
19 | - * @var PatchService |
|
20 | - */ |
|
21 | - private $patchService; |
|
18 | + /** |
|
19 | + * @var PatchService |
|
20 | + */ |
|
21 | + private $patchService; |
|
22 | 22 | |
23 | - public function __construct(PatchService $patchService) |
|
24 | - { |
|
25 | - $this->patchService = $patchService; |
|
26 | - parent::__construct(); |
|
27 | - } |
|
23 | + public function __construct(PatchService $patchService) |
|
24 | + { |
|
25 | + $this->patchService = $patchService; |
|
26 | + parent::__construct(); |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected function configure() |
|
34 | - { |
|
35 | - $this |
|
36 | - ->setName('patches:apply-all') |
|
37 | - ->setDescription('Apply pending patches.') |
|
38 | - ->setDefinition(array( |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected function configure() |
|
34 | + { |
|
35 | + $this |
|
36 | + ->setName('patches:apply-all') |
|
37 | + ->setDescription('Apply pending patches.') |
|
38 | + ->setDefinition(array( |
|
39 | 39 | |
40 | - )) |
|
41 | - ->setHelp(<<<EOT |
|
40 | + )) |
|
41 | + ->setHelp(<<<EOT |
|
42 | 42 | Apply pending patches. You can select the type of patches to be applied using the options. Default patches are always applied. |
43 | 43 | |
44 | 44 | Use patches:apply if you want to cherry-pick a particular patch. |
45 | 45 | EOT |
46 | - ); |
|
46 | + ); |
|
47 | 47 | |
48 | - foreach ($this->patchService->getTypes() as $type) { |
|
49 | - if ($type->getName() !== '') { |
|
50 | - $this->addOption($type->getName(), null, InputOption::VALUE_NONE, 'Applies patches of type "'.$type->getName().'". '.$type->getDescription()); |
|
51 | - } |
|
52 | - } |
|
53 | - } |
|
48 | + foreach ($this->patchService->getTypes() as $type) { |
|
49 | + if ($type->getName() !== '') { |
|
50 | + $this->addOption($type->getName(), null, InputOption::VALUE_NONE, 'Applies patches of type "'.$type->getName().'". '.$type->getDescription()); |
|
51 | + } |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * {@inheritdoc} |
|
57 | - */ |
|
58 | - protected function execute(InputInterface $input, OutputInterface $output) |
|
59 | - { |
|
60 | - $patchesArray = $this->patchService->getView(); |
|
55 | + /** |
|
56 | + * {@inheritdoc} |
|
57 | + */ |
|
58 | + protected function execute(InputInterface $input, OutputInterface $output) |
|
59 | + { |
|
60 | + $patchesArray = $this->patchService->getView(); |
|
61 | 61 | |
62 | - $count = 0; |
|
63 | - try { |
|
64 | - foreach ($patchesArray as $patch) { |
|
65 | - if ($patch['status'] == PatchInterface::STATUS_AWAITING || $patch['status'] == PatchInterface::STATUS_ERROR) { |
|
66 | - $this->patchService->apply($patch['uniqueName']); |
|
67 | - $count++; |
|
68 | - } |
|
69 | - } |
|
70 | - } catch (\Exception $e) { |
|
71 | - $output->writeln(sprintf( |
|
72 | - 'An error occurred while applying patch <info>%s</info>: <error>%s</error>', $patch['uniqueName'], $e->getMessage() |
|
73 | - )); |
|
74 | - throw $e; |
|
75 | - } |
|
62 | + $count = 0; |
|
63 | + try { |
|
64 | + foreach ($patchesArray as $patch) { |
|
65 | + if ($patch['status'] == PatchInterface::STATUS_AWAITING || $patch['status'] == PatchInterface::STATUS_ERROR) { |
|
66 | + $this->patchService->apply($patch['uniqueName']); |
|
67 | + $count++; |
|
68 | + } |
|
69 | + } |
|
70 | + } catch (\Exception $e) { |
|
71 | + $output->writeln(sprintf( |
|
72 | + 'An error occurred while applying patch <info>%s</info>: <error>%s</error>', $patch['uniqueName'], $e->getMessage() |
|
73 | + )); |
|
74 | + throw $e; |
|
75 | + } |
|
76 | 76 | |
77 | - if ($count) { |
|
78 | - $output->writeln(sprintf( |
|
79 | - '<info>%d</info> patches successfully applied', $count |
|
80 | - )); |
|
81 | - } else { |
|
82 | - $output->writeln('<info>No patches to apply</info>'); |
|
83 | - } |
|
84 | - } |
|
77 | + if ($count) { |
|
78 | + $output->writeln(sprintf( |
|
79 | + '<info>%d</info> patches successfully applied', $count |
|
80 | + )); |
|
81 | + } else { |
|
82 | + $output->writeln('<info>No patches to apply</info>'); |
|
83 | + } |
|
84 | + } |
|
85 | 85 | } |
@@ -30,42 +30,42 @@ discard block |
||
30 | 30 | * @ExtendedAction {"name":"View patches list", "url":"patcher/", "default":false} |
31 | 31 | */ |
32 | 32 | class PatchService implements MoufValidatorInterface { |
33 | - const IFEXISTS_EXCEPTION = "exception"; |
|
34 | - const IFEXISTS_IGNORE = "ignore"; |
|
33 | + const IFEXISTS_EXCEPTION = "exception"; |
|
34 | + const IFEXISTS_IGNORE = "ignore"; |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
37 | + /** |
|
38 | 38 | * The list of patches declared for this application. |
39 | 39 | * |
40 | 40 | * @var PatchInterface[] |
41 | 41 | */ |
42 | 42 | private $patchs = []; |
43 | 43 | |
44 | - /** |
|
45 | - * The list of exiting patch types for this application. |
|
46 | - * |
|
47 | - * @var PatchType[] |
|
48 | - */ |
|
44 | + /** |
|
45 | + * The list of exiting patch types for this application. |
|
46 | + * |
|
47 | + * @var PatchType[] |
|
48 | + */ |
|
49 | 49 | private $types = []; |
50 | 50 | |
51 | - /** |
|
52 | - * The list of listeners on the patch service. |
|
53 | - * |
|
54 | - * @var array|PatchListenerInterface[] |
|
55 | - */ |
|
56 | - private $listeners; |
|
51 | + /** |
|
52 | + * The list of listeners on the patch service. |
|
53 | + * |
|
54 | + * @var array|PatchListenerInterface[] |
|
55 | + */ |
|
56 | + private $listeners; |
|
57 | 57 | |
58 | - /** |
|
59 | - * @param PatchType[] $types |
|
60 | - * @param PatchListenerInterface[] $listeners |
|
61 | - */ |
|
62 | - public function __construct(array $types, array $listeners = []) |
|
63 | - { |
|
64 | - $this->types = $types; |
|
65 | - $this->listeners = $listeners; |
|
66 | - } |
|
58 | + /** |
|
59 | + * @param PatchType[] $types |
|
60 | + * @param PatchListenerInterface[] $listeners |
|
61 | + */ |
|
62 | + public function __construct(array $types, array $listeners = []) |
|
63 | + { |
|
64 | + $this->types = $types; |
|
65 | + $this->listeners = $listeners; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
68 | + /** |
|
69 | 69 | * The list of patches declared for this application. |
70 | 70 | * @param PatchInterface[] $patchs |
71 | 71 | * @return PatchService |
@@ -75,26 +75,26 @@ discard block |
||
75 | 75 | return $this; |
76 | 76 | } |
77 | 77 | |
78 | - /** |
|
79 | - * The list of exiting patch types for this application. |
|
80 | - * |
|
81 | - * @return PatchType[] |
|
82 | - */ |
|
83 | - public function getTypes(): array |
|
84 | - { |
|
85 | - return $this->types; |
|
86 | - } |
|
78 | + /** |
|
79 | + * The list of exiting patch types for this application. |
|
80 | + * |
|
81 | + * @return PatchType[] |
|
82 | + */ |
|
83 | + public function getTypes(): array |
|
84 | + { |
|
85 | + return $this->types; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @internal Returns a serialized list of types for the patch UI. |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public function _getSerializedTypes(): array |
|
93 | - { |
|
94 | - return array_map(function(PatchType $type) { |
|
95 | - return $type->jsonSerialize(); |
|
96 | - }, $this->types); |
|
97 | - } |
|
88 | + /** |
|
89 | + * @internal Returns a serialized list of types for the patch UI. |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public function _getSerializedTypes(): array |
|
93 | + { |
|
94 | + return array_map(function(PatchType $type) { |
|
95 | + return $type->jsonSerialize(); |
|
96 | + }, $this->types); |
|
97 | + } |
|
98 | 98 | |
99 | 99 | /** |
100 | 100 | * Adds this patch to the list of existing patches. |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | |
224 | 224 | /** |
225 | 225 | * Returns a PHP array representing the patchs. |
226 | - * |
|
227 | - * @internal |
|
226 | + * |
|
227 | + * @internal |
|
228 | 228 | */ |
229 | 229 | public function getView(): array { |
230 | 230 | $view = array(); |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | "description"=>$description, |
259 | 259 | "error_message"=>$error_message, |
260 | 260 | "edit_url"=>$editUrl, |
261 | - "patch_type"=>$patchType |
|
261 | + "patch_type"=>$patchType |
|
262 | 262 | ); |
263 | 263 | $view[] = $patchView; |
264 | 264 | } |
@@ -293,14 +293,14 @@ discard block |
||
293 | 293 | $patch->revert(); |
294 | 294 | } |
295 | 295 | |
296 | - /** |
|
297 | - * Reset all patches to a not applied state. |
|
298 | - * |
|
299 | - * Note: this does NOT run the "revert" method on each patch but DOES trigger a "reset" event. |
|
300 | - */ |
|
296 | + /** |
|
297 | + * Reset all patches to a not applied state. |
|
298 | + * |
|
299 | + * Note: this does NOT run the "revert" method on each patch but DOES trigger a "reset" event. |
|
300 | + */ |
|
301 | 301 | public function reset(): void { |
302 | - foreach ($this->listeners as $listener) { |
|
303 | - $listener->onReset(); |
|
304 | - } |
|
305 | - } |
|
302 | + foreach ($this->listeners as $listener) { |
|
303 | + $listener->onReset(); |
|
304 | + } |
|
305 | + } |
|
306 | 306 | } |
@@ -20,56 +20,56 @@ |
||
20 | 20 | |
21 | 21 | class PatchInstaller3 implements PackageInstallerInterface |
22 | 22 | { |
23 | - /** |
|
24 | - * (non-PHPdoc) |
|
25 | - * @see \Mouf\Installer\PackageInstallerInterface::install() |
|
26 | - * @param MoufManager $moufManager |
|
27 | - * @throws \Mouf\MoufException |
|
28 | - */ |
|
29 | - public static function install(MoufManager $moufManager) |
|
30 | - { |
|
31 | - // Let's create the instance. |
|
32 | - $patchDefaultType = InstallUtils::getOrCreateInstance('patch.default_type', PatchType::class, $moufManager); |
|
33 | - $patchDefaultType->getConstructorArgumentProperty('name')->setValue(''); |
|
34 | - $patchDefaultType->getConstructorArgumentProperty('description')->setValue('Patches that should be always applied should have this type. Typically, use this type for DDL changes or reference data insertion.'); |
|
23 | + /** |
|
24 | + * (non-PHPdoc) |
|
25 | + * @see \Mouf\Installer\PackageInstallerInterface::install() |
|
26 | + * @param MoufManager $moufManager |
|
27 | + * @throws \Mouf\MoufException |
|
28 | + */ |
|
29 | + public static function install(MoufManager $moufManager) |
|
30 | + { |
|
31 | + // Let's create the instance. |
|
32 | + $patchDefaultType = InstallUtils::getOrCreateInstance('patch.default_type', PatchType::class, $moufManager); |
|
33 | + $patchDefaultType->getConstructorArgumentProperty('name')->setValue(''); |
|
34 | + $patchDefaultType->getConstructorArgumentProperty('description')->setValue('Patches that should be always applied should have this type. Typically, use this type for DDL changes or reference data insertion.'); |
|
35 | 35 | |
36 | - $patchTestDataType = InstallUtils::getOrCreateInstance('patch.testdata_type', PatchType::class, $moufManager); |
|
37 | - $patchTestDataType->getConstructorArgumentProperty('name')->setValue('test_data'); |
|
38 | - $patchTestDataType->getConstructorArgumentProperty('description')->setValue('Use this type to mark patches that contain test data that should only be used in staging environment.'); |
|
36 | + $patchTestDataType = InstallUtils::getOrCreateInstance('patch.testdata_type', PatchType::class, $moufManager); |
|
37 | + $patchTestDataType->getConstructorArgumentProperty('name')->setValue('test_data'); |
|
38 | + $patchTestDataType->getConstructorArgumentProperty('description')->setValue('Use this type to mark patches that contain test data that should only be used in staging environment.'); |
|
39 | 39 | |
40 | - $patchService = InstallUtils::getOrCreateInstance('patchService', PatchService::class, $moufManager); |
|
40 | + $patchService = InstallUtils::getOrCreateInstance('patchService', PatchService::class, $moufManager); |
|
41 | 41 | |
42 | - if (empty($patchService->getConstructorArgumentProperty('types')->getValue())) { |
|
43 | - $patchService->getConstructorArgumentProperty('types')->setValue([ $patchDefaultType, $patchTestDataType ]); |
|
44 | - } |
|
42 | + if (empty($patchService->getConstructorArgumentProperty('types')->getValue())) { |
|
43 | + $patchService->getConstructorArgumentProperty('types')->setValue([ $patchDefaultType, $patchTestDataType ]); |
|
44 | + } |
|
45 | 45 | |
46 | - $consoleUtils = new ConsoleUtils($moufManager); |
|
46 | + $consoleUtils = new ConsoleUtils($moufManager); |
|
47 | 47 | |
48 | - $listPatchesCommand = $moufManager->createInstance(ListPatchesCommand::class); |
|
49 | - $listPatchesCommand->getConstructorArgumentProperty("patchService")->setValue($patchService); |
|
50 | - $consoleUtils->registerCommand($listPatchesCommand); |
|
48 | + $listPatchesCommand = $moufManager->createInstance(ListPatchesCommand::class); |
|
49 | + $listPatchesCommand->getConstructorArgumentProperty("patchService")->setValue($patchService); |
|
50 | + $consoleUtils->registerCommand($listPatchesCommand); |
|
51 | 51 | |
52 | - $applyAllPatchesCommand = $moufManager->createInstance(ApplyAllPatchesCommand::class); |
|
53 | - $applyAllPatchesCommand->getConstructorArgumentProperty("patchService")->setValue($patchService); |
|
54 | - $consoleUtils->registerCommand($applyAllPatchesCommand); |
|
52 | + $applyAllPatchesCommand = $moufManager->createInstance(ApplyAllPatchesCommand::class); |
|
53 | + $applyAllPatchesCommand->getConstructorArgumentProperty("patchService")->setValue($patchService); |
|
54 | + $consoleUtils->registerCommand($applyAllPatchesCommand); |
|
55 | 55 | |
56 | - $applyPatchCommand = $moufManager->createInstance(ApplyPatchCommand::class); |
|
57 | - $applyPatchCommand->getConstructorArgumentProperty("patchService")->setValue($patchService); |
|
58 | - $consoleUtils->registerCommand($applyPatchCommand); |
|
56 | + $applyPatchCommand = $moufManager->createInstance(ApplyPatchCommand::class); |
|
57 | + $applyPatchCommand->getConstructorArgumentProperty("patchService")->setValue($patchService); |
|
58 | + $consoleUtils->registerCommand($applyPatchCommand); |
|
59 | 59 | |
60 | - $skipPatchCommand = $moufManager->createInstance(SkipPatchCommand::class); |
|
61 | - $skipPatchCommand->getConstructorArgumentProperty("patchService")->setValue($patchService); |
|
62 | - $consoleUtils->registerCommand($skipPatchCommand); |
|
60 | + $skipPatchCommand = $moufManager->createInstance(SkipPatchCommand::class); |
|
61 | + $skipPatchCommand->getConstructorArgumentProperty("patchService")->setValue($patchService); |
|
62 | + $consoleUtils->registerCommand($skipPatchCommand); |
|
63 | 63 | |
64 | - $revertPatchCommand = $moufManager->createInstance(RevertPatchCommand::class); |
|
65 | - $revertPatchCommand->getConstructorArgumentProperty("patchService")->setValue($patchService); |
|
66 | - $consoleUtils->registerCommand($revertPatchCommand); |
|
64 | + $revertPatchCommand = $moufManager->createInstance(RevertPatchCommand::class); |
|
65 | + $revertPatchCommand->getConstructorArgumentProperty("patchService")->setValue($patchService); |
|
66 | + $consoleUtils->registerCommand($revertPatchCommand); |
|
67 | 67 | |
68 | - $resetPatchCommand = $moufManager->createInstance(ResetPatchesCommand::class); |
|
69 | - $resetPatchCommand->getConstructorArgumentProperty("patchService")->setValue($patchService); |
|
70 | - $consoleUtils->registerCommand($resetPatchCommand); |
|
68 | + $resetPatchCommand = $moufManager->createInstance(ResetPatchesCommand::class); |
|
69 | + $resetPatchCommand->getConstructorArgumentProperty("patchService")->setValue($patchService); |
|
70 | + $consoleUtils->registerCommand($resetPatchCommand); |
|
71 | 71 | |
72 | - // Let's rewrite the MoufComponents.php file to save the component |
|
73 | - $moufManager->rewriteMouf(); |
|
74 | - } |
|
72 | + // Let's rewrite the MoufComponents.php file to save the component |
|
73 | + $moufManager->rewriteMouf(); |
|
74 | + } |
|
75 | 75 | } |
@@ -19,7 +19,6 @@ discard block |
||
19 | 19 | |
20 | 20 | /** |
21 | 21 | * The controller to track which patchs have been applied. |
22 | - |
|
23 | 22 | */ |
24 | 23 | class PatchController extends AbstractMoufInstanceController { |
25 | 24 | |
@@ -98,96 +97,96 @@ discard block |
||
98 | 97 | header('Location: .?name='.urlencode($name)); |
99 | 98 | } |
100 | 99 | |
101 | - /** |
|
102 | - * Displays the page to select the patch types to be applied. |
|
103 | - * |
|
104 | - * @Action |
|
105 | - * @Logged |
|
106 | - * @param string $name |
|
107 | - * @param string $selfedit |
|
108 | - * @param string $action One of "reset" or "apply" |
|
109 | - */ |
|
110 | - public function runAllPatches($name, $selfedit, $action) { |
|
111 | - $this->initController($name, $selfedit); |
|
112 | - |
|
113 | - $patchService = new InstanceProxy($name, $selfedit == "true"); |
|
114 | - $this->patchesArray = $patchService->getView(); |
|
115 | - |
|
116 | - $types = $patchService->_getSerializedTypes(); |
|
117 | - |
|
118 | - foreach ($types as $type) { |
|
119 | - $this->nbPatchesByType[$type['name']] = 0; |
|
120 | - } |
|
121 | - |
|
122 | - $nbNoneDefaultPatches = 0; |
|
123 | - |
|
124 | - foreach ($this->patchesArray as $patch) { |
|
125 | - if ($action === 'reset' || $patch['status'] === PatchInterface::STATUS_AWAITING || $patch['status'] === PatchInterface::STATUS_ERROR) { |
|
126 | - $type = $patch['patch_type']; |
|
127 | - if ($type !== '') { |
|
128 | - $nbNoneDefaultPatches++; |
|
129 | - } |
|
130 | - $this->nbPatchesByType[$type]++; |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - // If all patches to be applied are default patches, let's do this right now. |
|
135 | - if ($nbNoneDefaultPatches === 0) { |
|
136 | - $this->applyAllPatches($name, [''], $action, $selfedit); |
|
137 | - return; |
|
138 | - } |
|
139 | - |
|
140 | - ksort($this->nbPatchesByType); |
|
141 | - |
|
142 | - $this->action = $action; |
|
143 | - |
|
144 | - // Otherwise, let's display a screen to select the patch types to be applied. |
|
145 | - $this->content->addFile(__DIR__."/../../../../views/applyPatches.php", $this); |
|
146 | - $this->template->toHtml(); |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * Runs all patches in a row. |
|
152 | - * |
|
153 | - * @Action |
|
154 | - * @Logged |
|
155 | - * @param string $name |
|
156 | - * @param array $types |
|
157 | - * @param string $action One of "reset" or "apply" |
|
158 | - * @param string $selfedit |
|
159 | - */ |
|
100 | + /** |
|
101 | + * Displays the page to select the patch types to be applied. |
|
102 | + * |
|
103 | + * @Action |
|
104 | + * @Logged |
|
105 | + * @param string $name |
|
106 | + * @param string $selfedit |
|
107 | + * @param string $action One of "reset" or "apply" |
|
108 | + */ |
|
109 | + public function runAllPatches($name, $selfedit, $action) { |
|
110 | + $this->initController($name, $selfedit); |
|
111 | + |
|
112 | + $patchService = new InstanceProxy($name, $selfedit == "true"); |
|
113 | + $this->patchesArray = $patchService->getView(); |
|
114 | + |
|
115 | + $types = $patchService->_getSerializedTypes(); |
|
116 | + |
|
117 | + foreach ($types as $type) { |
|
118 | + $this->nbPatchesByType[$type['name']] = 0; |
|
119 | + } |
|
120 | + |
|
121 | + $nbNoneDefaultPatches = 0; |
|
122 | + |
|
123 | + foreach ($this->patchesArray as $patch) { |
|
124 | + if ($action === 'reset' || $patch['status'] === PatchInterface::STATUS_AWAITING || $patch['status'] === PatchInterface::STATUS_ERROR) { |
|
125 | + $type = $patch['patch_type']; |
|
126 | + if ($type !== '') { |
|
127 | + $nbNoneDefaultPatches++; |
|
128 | + } |
|
129 | + $this->nbPatchesByType[$type]++; |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + // If all patches to be applied are default patches, let's do this right now. |
|
134 | + if ($nbNoneDefaultPatches === 0) { |
|
135 | + $this->applyAllPatches($name, [''], $action, $selfedit); |
|
136 | + return; |
|
137 | + } |
|
138 | + |
|
139 | + ksort($this->nbPatchesByType); |
|
140 | + |
|
141 | + $this->action = $action; |
|
142 | + |
|
143 | + // Otherwise, let's display a screen to select the patch types to be applied. |
|
144 | + $this->content->addFile(__DIR__."/../../../../views/applyPatches.php", $this); |
|
145 | + $this->template->toHtml(); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * Runs all patches in a row. |
|
151 | + * |
|
152 | + * @Action |
|
153 | + * @Logged |
|
154 | + * @param string $name |
|
155 | + * @param array $types |
|
156 | + * @param string $action One of "reset" or "apply" |
|
157 | + * @param string $selfedit |
|
158 | + */ |
|
160 | 159 | public function applyAllPatches($name, array $types, $action, $selfedit) { |
161 | 160 | $patchService = new InstanceProxy($name, $selfedit == "true"); |
162 | 161 | |
163 | - if ($action === 'reset') { |
|
164 | - $patchService->reset(); |
|
165 | - } |
|
162 | + if ($action === 'reset') { |
|
163 | + $patchService->reset(); |
|
164 | + } |
|
166 | 165 | |
167 | 166 | $this->patchesArray = $patchService->getView(); |
168 | 167 | |
169 | 168 | // Array of count of applied and skipped patches. Key is the patch type. |
170 | 169 | $appliedPatchArray = []; |
171 | - $skippedPatchArray = []; |
|
170 | + $skippedPatchArray = []; |
|
172 | 171 | |
173 | 172 | try { |
174 | 173 | foreach ($this->patchesArray as $patch) { |
175 | - if ($patch['status'] === PatchInterface::STATUS_AWAITING || $patch['status'] === PatchInterface::STATUS_ERROR) { |
|
176 | - $type = $patch['patch_type']; |
|
177 | - if (in_array($type, $types) || $type === '') { |
|
178 | - $patchService->apply($patch['uniqueName']); |
|
179 | - if (!isset($appliedPatchArray[$type])) { |
|
180 | - $appliedPatchArray[$type] = 0; |
|
181 | - } |
|
182 | - $appliedPatchArray[$type]++; |
|
183 | - } else { |
|
184 | - $patchService->skip($patch['uniqueName']); |
|
185 | - if (!isset($skippedPatchArray[$type])) { |
|
186 | - $skippedPatchArray[$type] = 0; |
|
187 | - } |
|
188 | - $skippedPatchArray[$type]++; |
|
189 | - } |
|
190 | - } |
|
174 | + if ($patch['status'] === PatchInterface::STATUS_AWAITING || $patch['status'] === PatchInterface::STATUS_ERROR) { |
|
175 | + $type = $patch['patch_type']; |
|
176 | + if (in_array($type, $types) || $type === '') { |
|
177 | + $patchService->apply($patch['uniqueName']); |
|
178 | + if (!isset($appliedPatchArray[$type])) { |
|
179 | + $appliedPatchArray[$type] = 0; |
|
180 | + } |
|
181 | + $appliedPatchArray[$type]++; |
|
182 | + } else { |
|
183 | + $patchService->skip($patch['uniqueName']); |
|
184 | + if (!isset($skippedPatchArray[$type])) { |
|
185 | + $skippedPatchArray[$type] = 0; |
|
186 | + } |
|
187 | + $skippedPatchArray[$type]++; |
|
188 | + } |
|
189 | + } |
|
191 | 190 | } |
192 | 191 | |
193 | 192 | } catch (\Exception $e) { |
@@ -195,37 +194,37 @@ discard block |
||
195 | 194 | set_user_message($htmlMessage); |
196 | 195 | } |
197 | 196 | |
198 | - $this->displayNotificationMessage($appliedPatchArray, $skippedPatchArray); |
|
197 | + $this->displayNotificationMessage($appliedPatchArray, $skippedPatchArray); |
|
199 | 198 | |
200 | - header('Location: .?name='.urlencode($name)); |
|
199 | + header('Location: .?name='.urlencode($name)); |
|
201 | 200 | } |
202 | 201 | |
203 | 202 | private function displayNotificationMessage(array $appliedPatchArray, array $skippedPatchArray) |
204 | - { |
|
205 | - $nbPatchesApplied = array_sum($appliedPatchArray); |
|
206 | - $nbPatchesSkipped = array_sum($skippedPatchArray); |
|
207 | - $msg = ''; |
|
208 | - if ($nbPatchesApplied !== 0) { |
|
209 | - $patchArr = []; |
|
210 | - foreach ($appliedPatchArray as $name => $number) { |
|
211 | - $name = $name ?: 'default'; |
|
212 | - $patchArr[] = plainstring_to_htmlprotected($name).': '.$number; |
|
213 | - } |
|
214 | - |
|
215 | - $msg .= sprintf('%d patch(es) applied (%s)', $nbPatchesApplied, implode(', ', $patchArr)); |
|
216 | - } |
|
217 | - if ($nbPatchesSkipped !== 0) { |
|
218 | - $patchArr = []; |
|
219 | - foreach ($skippedPatchArray as $name => $number) { |
|
220 | - $name = $name ?: 'default'; |
|
221 | - $patchArr[] = plainstring_to_htmlprotected($name).': '.$number; |
|
222 | - } |
|
223 | - |
|
224 | - $msg .= sprintf('%d patch(es) skipped (%s)', $nbPatchesSkipped, implode(', ', $patchArr)); |
|
225 | - } |
|
226 | - |
|
227 | - if ($msg !== '') { |
|
228 | - set_user_message($msg, UserMessageInterface::SUCCESS); |
|
229 | - } |
|
230 | - } |
|
203 | + { |
|
204 | + $nbPatchesApplied = array_sum($appliedPatchArray); |
|
205 | + $nbPatchesSkipped = array_sum($skippedPatchArray); |
|
206 | + $msg = ''; |
|
207 | + if ($nbPatchesApplied !== 0) { |
|
208 | + $patchArr = []; |
|
209 | + foreach ($appliedPatchArray as $name => $number) { |
|
210 | + $name = $name ?: 'default'; |
|
211 | + $patchArr[] = plainstring_to_htmlprotected($name).': '.$number; |
|
212 | + } |
|
213 | + |
|
214 | + $msg .= sprintf('%d patch(es) applied (%s)', $nbPatchesApplied, implode(', ', $patchArr)); |
|
215 | + } |
|
216 | + if ($nbPatchesSkipped !== 0) { |
|
217 | + $patchArr = []; |
|
218 | + foreach ($skippedPatchArray as $name => $number) { |
|
219 | + $name = $name ?: 'default'; |
|
220 | + $patchArr[] = plainstring_to_htmlprotected($name).': '.$number; |
|
221 | + } |
|
222 | + |
|
223 | + $msg .= sprintf('%d patch(es) skipped (%s)', $nbPatchesSkipped, implode(', ', $patchArr)); |
|
224 | + } |
|
225 | + |
|
226 | + if ($msg !== '') { |
|
227 | + set_user_message($msg, UserMessageInterface::SUCCESS); |
|
228 | + } |
|
229 | + } |
|
231 | 230 | } |
232 | 231 | \ No newline at end of file |
@@ -8,16 +8,16 @@ |
||
8 | 8 | */ |
9 | 9 | interface PatchListenerInterface |
10 | 10 | { |
11 | - /** |
|
12 | - * Triggered when the 'reset()' method is called on the PatchService |
|
13 | - */ |
|
14 | - public function onReset(): void; |
|
11 | + /** |
|
12 | + * Triggered when the 'reset()' method is called on the PatchService |
|
13 | + */ |
|
14 | + public function onReset(): void; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Triggered when one or many patches have been applied. |
|
18 | - * |
|
19 | - * @param PatchInterface[] $patches |
|
20 | - */ |
|
21 | - //public function onPatchesApplied(array $patches): void; |
|
16 | + /** |
|
17 | + * Triggered when one or many patches have been applied. |
|
18 | + * |
|
19 | + * @param PatchInterface[] $patches |
|
20 | + */ |
|
21 | + //public function onPatchesApplied(array $patches): void; |
|
22 | 22 | |
23 | 23 | } |
24 | 24 | \ No newline at end of file |