@@ -15,45 +15,45 @@ |
||
15 | 15 | */ |
16 | 16 | class SkipPatchCommand 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 | - parent::__construct(); |
|
26 | - $this->patchService = $patchService; |
|
27 | - } |
|
23 | + public function __construct(PatchService $patchService) |
|
24 | + { |
|
25 | + parent::__construct(); |
|
26 | + $this->patchService = $patchService; |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected function configure() |
|
34 | - { |
|
35 | - $this |
|
36 | - ->setName('patches:skip') |
|
37 | - ->setDescription('Skip a patch.') |
|
38 | - ->addArgument( |
|
39 | - 'name', |
|
40 | - InputArgument::REQUIRED, |
|
41 | - 'The name of the patch instance to be skipped' |
|
42 | - ) |
|
43 | - ->setHelp(<<<EOT |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected function configure() |
|
34 | + { |
|
35 | + $this |
|
36 | + ->setName('patches:skip') |
|
37 | + ->setDescription('Skip a patch.') |
|
38 | + ->addArgument( |
|
39 | + 'name', |
|
40 | + InputArgument::REQUIRED, |
|
41 | + 'The name of the patch instance to be skipped' |
|
42 | + ) |
|
43 | + ->setHelp(<<<EOT |
|
44 | 44 | Skips a patch. You must pass in parameter the name of the patch. |
45 | 45 | EOT |
46 | - ); |
|
47 | - } |
|
46 | + ); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritdoc} |
|
51 | - */ |
|
52 | - protected function execute(InputInterface $input, OutputInterface $output) |
|
53 | - { |
|
54 | - $patchName = $input->getArgument('name'); |
|
55 | - $this->patchService->skip($patchName); |
|
49 | + /** |
|
50 | + * {@inheritdoc} |
|
51 | + */ |
|
52 | + protected function execute(InputInterface $input, OutputInterface $output) |
|
53 | + { |
|
54 | + $patchName = $input->getArgument('name'); |
|
55 | + $this->patchService->skip($patchName); |
|
56 | 56 | |
57 | - $output->writeln('Patch marked as skipped'); |
|
58 | - } |
|
57 | + $output->writeln('Patch marked as skipped'); |
|
58 | + } |
|
59 | 59 | } |
@@ -8,64 +8,64 @@ |
||
8 | 8 | |
9 | 9 | class PatchType implements \JsonSerializable |
10 | 10 | { |
11 | - /** |
|
12 | - * @var string |
|
13 | - */ |
|
14 | - private $name; |
|
15 | - /** |
|
16 | - * @var string |
|
17 | - */ |
|
18 | - private $description; |
|
11 | + /** |
|
12 | + * @var string |
|
13 | + */ |
|
14 | + private $name; |
|
15 | + /** |
|
16 | + * @var string |
|
17 | + */ |
|
18 | + private $description; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @Important |
|
22 | - * @param string $name The name of the patch type. Should not contain special characters or spaces. Note: the default type is an empty string. |
|
23 | - * @param string $description The description of the patch type |
|
24 | - * @throws PatchException |
|
25 | - */ |
|
26 | - public function __construct(string $name, string $description) |
|
27 | - { |
|
28 | - if (!preg_match('/^[a-z_\-0-9]*$/i', $name)) { |
|
29 | - throw new PatchException('A patch name can only contain alphanumeric characters and underscore. Name passed: "'.$name.'"'); |
|
30 | - } |
|
20 | + /** |
|
21 | + * @Important |
|
22 | + * @param string $name The name of the patch type. Should not contain special characters or spaces. Note: the default type is an empty string. |
|
23 | + * @param string $description The description of the patch type |
|
24 | + * @throws PatchException |
|
25 | + */ |
|
26 | + public function __construct(string $name, string $description) |
|
27 | + { |
|
28 | + if (!preg_match('/^[a-z_\-0-9]*$/i', $name)) { |
|
29 | + throw new PatchException('A patch name can only contain alphanumeric characters and underscore. Name passed: "'.$name.'"'); |
|
30 | + } |
|
31 | 31 | |
32 | - $this->name = $name; |
|
33 | - $this->description = $description; |
|
34 | - } |
|
32 | + $this->name = $name; |
|
33 | + $this->description = $description; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * The name of the patch type. Should not contain special characters or spaces. |
|
38 | - * |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - public function getName(): string |
|
42 | - { |
|
43 | - return $this->name; |
|
44 | - } |
|
36 | + /** |
|
37 | + * The name of the patch type. Should not contain special characters or spaces. |
|
38 | + * |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + public function getName(): string |
|
42 | + { |
|
43 | + return $this->name; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * The description of the patch type. |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public function getDescription(): string |
|
52 | - { |
|
53 | - return $this->description; |
|
54 | - } |
|
46 | + /** |
|
47 | + * The description of the patch type. |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public function getDescription(): string |
|
52 | + { |
|
53 | + return $this->description; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Specify data which should be serialized to JSON |
|
58 | - * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
|
59 | - * @return mixed data which can be serialized by <b>json_encode</b>, |
|
60 | - * which is a value of any type other than a resource. |
|
61 | - * @since 5.4.0 |
|
62 | - */ |
|
63 | - public function jsonSerialize() |
|
64 | - { |
|
65 | - return [ |
|
66 | - 'name' => $this->name, |
|
67 | - 'description' => $this->description, |
|
68 | - 'instanceName' => MoufManager::getMoufManager()->findInstanceName($this) |
|
69 | - ]; |
|
70 | - } |
|
56 | + /** |
|
57 | + * Specify data which should be serialized to JSON |
|
58 | + * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
|
59 | + * @return mixed data which can be serialized by <b>json_encode</b>, |
|
60 | + * which is a value of any type other than a resource. |
|
61 | + * @since 5.4.0 |
|
62 | + */ |
|
63 | + public function jsonSerialize() |
|
64 | + { |
|
65 | + return [ |
|
66 | + 'name' => $this->name, |
|
67 | + 'description' => $this->description, |
|
68 | + 'instanceName' => MoufManager::getMoufManager()->findInstanceName($this) |
|
69 | + ]; |
|
70 | + } |
|
71 | 71 | } |
@@ -15,66 +15,66 @@ |
||
15 | 15 | */ |
16 | 16 | class ListPatchesCommand 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 | - parent::__construct(); |
|
26 | - $this->patchService = $patchService; |
|
27 | - } |
|
23 | + public function __construct(PatchService $patchService) |
|
24 | + { |
|
25 | + parent::__construct(); |
|
26 | + $this->patchService = $patchService; |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected function configure() |
|
34 | - { |
|
35 | - $this |
|
36 | - ->setName('patches:list') |
|
37 | - ->setDescription('List all the patches.') |
|
38 | - ->setDefinition(array( |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected function configure() |
|
34 | + { |
|
35 | + $this |
|
36 | + ->setName('patches:list') |
|
37 | + ->setDescription('List all the patches.') |
|
38 | + ->setDefinition(array( |
|
39 | 39 | |
40 | - )) |
|
41 | - ->setHelp(<<<EOT |
|
40 | + )) |
|
41 | + ->setHelp(<<<EOT |
|
42 | 42 | List all patches declared in Mouf patch service. |
43 | 43 | |
44 | 44 | The command will display the status of each patch, i.e. whether it has been applied or skipped or is waiting to be applied. |
45 | 45 | EOT |
46 | - ); |
|
47 | - } |
|
46 | + ); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritdoc} |
|
51 | - */ |
|
52 | - protected function execute(InputInterface $input, OutputInterface $output) |
|
53 | - { |
|
54 | - $patches = $this->patchService->getView(); |
|
49 | + /** |
|
50 | + * {@inheritdoc} |
|
51 | + */ |
|
52 | + protected function execute(InputInterface $input, OutputInterface $output) |
|
53 | + { |
|
54 | + $patches = $this->patchService->getView(); |
|
55 | 55 | |
56 | - $rows = array_map(function($row) { |
|
57 | - return [ $row['uniqueName'], $this->renderStatus($row['status']), $row['patch_type'] ?: '(default)' ]; |
|
58 | - }, $patches); |
|
56 | + $rows = array_map(function($row) { |
|
57 | + return [ $row['uniqueName'], $this->renderStatus($row['status']), $row['patch_type'] ?: '(default)' ]; |
|
58 | + }, $patches); |
|
59 | 59 | |
60 | - $table = new Table($output); |
|
61 | - $table |
|
62 | - ->setHeaders(array('Patch', 'Status', 'Type')) |
|
63 | - ->setRows($rows) |
|
64 | - ; |
|
65 | - $table->render(); |
|
66 | - } |
|
60 | + $table = new Table($output); |
|
61 | + $table |
|
62 | + ->setHeaders(array('Patch', 'Status', 'Type')) |
|
63 | + ->setRows($rows) |
|
64 | + ; |
|
65 | + $table->render(); |
|
66 | + } |
|
67 | 67 | |
68 | - private function renderStatus($status) { |
|
69 | - $map = [ |
|
70 | - PatchInterface::STATUS_APPLIED => "<info>Applied</info>", |
|
71 | - PatchInterface::STATUS_SKIPPED => "<comment>Skipped</comment>", |
|
72 | - PatchInterface::STATUS_AWAITING => "Awaiting", |
|
73 | - PatchInterface::STATUS_ERROR => "<error>Skipped</error>", |
|
74 | - ]; |
|
75 | - if (!isset($map[$status])) { |
|
76 | - throw new \Exception('Unexpected status "'.$map[$status].'"'); |
|
77 | - } |
|
78 | - return $map[$status]; |
|
79 | - } |
|
68 | + private function renderStatus($status) { |
|
69 | + $map = [ |
|
70 | + PatchInterface::STATUS_APPLIED => "<info>Applied</info>", |
|
71 | + PatchInterface::STATUS_SKIPPED => "<comment>Skipped</comment>", |
|
72 | + PatchInterface::STATUS_AWAITING => "Awaiting", |
|
73 | + PatchInterface::STATUS_ERROR => "<error>Skipped</error>", |
|
74 | + ]; |
|
75 | + if (!isset($map[$status])) { |
|
76 | + throw new \Exception('Unexpected status "'.$map[$status].'"'); |
|
77 | + } |
|
78 | + return $map[$status]; |
|
79 | + } |
|
80 | 80 | } |
@@ -39,20 +39,20 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * Skips the patch (sets its status to "skipped"). |
41 | 41 | */ |
42 | - public function skip(): void; |
|
42 | + public function skip(): void; |
|
43 | 43 | |
44 | 44 | /** |
45 | 45 | * Reverts (cancels) the patch. |
46 | 46 | * Note: patchs do not have to provide a "revert" feature (see canRevert method). |
47 | 47 | */ |
48 | - public function revert(): void; |
|
48 | + public function revert(): void; |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Returns true if this patch can be canceled, false otherwise. |
52 | 52 | * |
53 | 53 | * @return boolean |
54 | 54 | */ |
55 | - public function canRevert(): bool; |
|
55 | + public function canRevert(): bool; |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Returns the status of this patch. |
@@ -65,28 +65,28 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return string |
67 | 67 | */ |
68 | - public function getStatus(): string; |
|
68 | + public function getStatus(): string; |
|
69 | 69 | |
70 | 70 | /** |
71 | 71 | * Returns a unique name for this patch. |
72 | 72 | * |
73 | 73 | * @return string |
74 | 74 | */ |
75 | - public function getUniqueName(): string; |
|
75 | + public function getUniqueName(): string; |
|
76 | 76 | |
77 | 77 | /** |
78 | 78 | * Returns a short description of the patch. |
79 | 79 | * |
80 | 80 | * @return string |
81 | 81 | */ |
82 | - public function getDescription(): string; |
|
82 | + public function getDescription(): string; |
|
83 | 83 | |
84 | 84 | /** |
85 | 85 | * Returns the error message of the last action performed, or null if last action was successful. |
86 | 86 | * |
87 | 87 | * @return string |
88 | 88 | */ |
89 | - public function getLastErrorMessage(): ?string; |
|
89 | + public function getLastErrorMessage(): ?string; |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Returns the URL that can be used to edit this patch. |
@@ -94,12 +94,12 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @return string |
96 | 96 | */ |
97 | - public function getEditUrl(): ?string; |
|
97 | + public function getEditUrl(): ?string; |
|
98 | 98 | |
99 | - /** |
|
100 | - * Returns the type of the patch. |
|
101 | - * |
|
102 | - * @return PatchType |
|
103 | - */ |
|
104 | - public function getPatchType() : PatchType; |
|
99 | + /** |
|
100 | + * Returns the type of the patch. |
|
101 | + * |
|
102 | + * @return PatchType |
|
103 | + */ |
|
104 | + public function getPatchType() : PatchType; |
|
105 | 105 | } |
@@ -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 | } |
@@ -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 |
@@ -2,16 +2,7 @@ |
||
2 | 2 | namespace Mouf\Utils\Patcher\Controllers; |
3 | 3 | |
4 | 4 | use Mouf\Controllers\AbstractMoufInstanceController; |
5 | - |
|
6 | -use Mouf\Database\TDBM\Utils\TDBMDaoGenerator; |
|
7 | - |
|
8 | 5 | use Mouf\Html\Widgets\MessageService\Service\UserMessageInterface; |
9 | -use Mouf\MoufManager; |
|
10 | - |
|
11 | -use Mouf\Mvc\Splash\Controllers\Controller; |
|
12 | - |
|
13 | -use Mouf\Reflection\MoufReflectionProxy; |
|
14 | - |
|
15 | 6 | use Mouf\Html\HtmlElement\HtmlBlock; |
16 | 7 | use Mouf\InstanceProxy; |
17 | 8 | use Mouf\Utils\Patcher\PatchException; |
@@ -20,7 +20,6 @@ discard block |
||
20 | 20 | |
21 | 21 | /** |
22 | 22 | * The controller to track which patchs have been applied. |
23 | - |
|
24 | 23 | */ |
25 | 24 | class PatchController extends AbstractMoufInstanceController { |
26 | 25 | |
@@ -99,115 +98,115 @@ discard block |
||
99 | 98 | header('Location: .?name='.urlencode($name)); |
100 | 99 | } |
101 | 100 | |
102 | - /** |
|
103 | - * Displays the page to select the patch types to be applied. |
|
104 | - * |
|
105 | - * @Action |
|
106 | - * @Logged |
|
107 | - * @param string $name |
|
108 | - * @param string $selfedit |
|
109 | - * @param string $action One of "reset" or "apply" |
|
110 | - */ |
|
111 | - public function runAllPatches($name, $selfedit, $action) { |
|
112 | - $this->initController($name, $selfedit); |
|
113 | - |
|
114 | - $patchService = new InstanceProxy($name, $selfedit == "true"); |
|
115 | - $this->patchesArray = $patchService->getView(); |
|
116 | - |
|
117 | - $types = $patchService->_getSerializedTypes(); |
|
118 | - |
|
119 | - foreach ($types as $type) { |
|
120 | - $this->nbPatchesByType[$type['name']] = 0; |
|
121 | - } |
|
122 | - |
|
123 | - $nbNoneDefaultPatches = 0; |
|
124 | - |
|
125 | - foreach ($this->patchesArray as $patch) { |
|
126 | - if ($action === 'reset' || $patch['status'] === PatchInterface::STATUS_AWAITING || $patch['status'] === PatchInterface::STATUS_ERROR) { |
|
127 | - $type = $patch['patch_type']; |
|
128 | - if ($type !== '') { |
|
129 | - $nbNoneDefaultPatches++; |
|
130 | - } |
|
131 | - $this->nbPatchesByType[$type]++; |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - // If all patches to be applied are default patches, let's do this right now. |
|
136 | - if ($nbNoneDefaultPatches === 0) { |
|
137 | - $this->applyAllPatches($name, [''], $action, $selfedit); |
|
138 | - return; |
|
139 | - } |
|
140 | - |
|
141 | - ksort($this->nbPatchesByType); |
|
142 | - |
|
143 | - $this->action = $action; |
|
144 | - |
|
145 | - // Otherwise, let's display a screen to select the patch types to be applied. |
|
146 | - $this->content->addFile(__DIR__."/../../../../views/applyPatches.php", $this); |
|
147 | - $this->template->toHtml(); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * Runs all patches in a row. |
|
153 | - * |
|
154 | - * @Action |
|
155 | - * @Logged |
|
156 | - * @param string $name |
|
157 | - * @param string[] $types |
|
158 | - * @param string $action One of "reset" or "apply" |
|
159 | - * @param string $selfedit |
|
160 | - */ |
|
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 string[] $types |
|
157 | + * @param string $action One of "reset" or "apply" |
|
158 | + * @param string $selfedit |
|
159 | + */ |
|
161 | 160 | public function applyAllPatches($name, array $types, $action, $selfedit) { |
162 | 161 | $patchService = new InstanceProxy($name, $selfedit == "true"); |
163 | 162 | /* @var $patchService PatchService */ |
164 | 163 | |
165 | - if ($action === 'reset') { |
|
166 | - $patchService->reset(); |
|
167 | - } |
|
168 | - try { |
|
164 | + if ($action === 'reset') { |
|
165 | + $patchService->reset(); |
|
166 | + } |
|
167 | + try { |
|
169 | 168 | |
170 | - [ |
|
171 | - 'applied' => $appliedPatchArray, |
|
172 | - 'skipped' => $skippedPatchArray |
|
173 | - ] = $patchService->applyAll($types); |
|
169 | + [ |
|
170 | + 'applied' => $appliedPatchArray, |
|
171 | + 'skipped' => $skippedPatchArray |
|
172 | + ] = $patchService->applyAll($types); |
|
174 | 173 | |
175 | - $this->displayNotificationMessage($appliedPatchArray, $skippedPatchArray); |
|
176 | - } catch (\Exception $e) { |
|
174 | + $this->displayNotificationMessage($appliedPatchArray, $skippedPatchArray); |
|
175 | + } catch (\Exception $e) { |
|
177 | 176 | $htmlMessage = "An error occured while applying the patch: ".$e->getMessage(); |
178 | 177 | set_user_message($htmlMessage); |
179 | 178 | } |
180 | 179 | |
181 | 180 | |
182 | - header('Location: .?name='.urlencode($name)); |
|
181 | + header('Location: .?name='.urlencode($name)); |
|
183 | 182 | } |
184 | 183 | |
185 | 184 | private function displayNotificationMessage(array $appliedPatchArray, array $skippedPatchArray) |
186 | - { |
|
187 | - $nbPatchesApplied = array_sum($appliedPatchArray); |
|
188 | - $nbPatchesSkipped = array_sum($skippedPatchArray); |
|
189 | - $msg = ''; |
|
190 | - if ($nbPatchesApplied !== 0) { |
|
191 | - $patchArr = []; |
|
192 | - foreach ($appliedPatchArray as $name => $number) { |
|
193 | - $name = $name ?: 'default'; |
|
194 | - $patchArr[] = plainstring_to_htmlprotected($name).': '.$number; |
|
195 | - } |
|
196 | - |
|
197 | - $msg .= sprintf('%d patch%s applied (%s)', $nbPatchesApplied, ($nbPatchesApplied > 1)?'es':'', implode(', ', $patchArr)); |
|
198 | - } |
|
199 | - if ($nbPatchesSkipped !== 0) { |
|
200 | - $patchArr = []; |
|
201 | - foreach ($skippedPatchArray as $name => $number) { |
|
202 | - $name = $name ?: 'default'; |
|
203 | - $patchArr[] = plainstring_to_htmlprotected($name).': '.$number; |
|
204 | - } |
|
205 | - |
|
206 | - $msg .= sprintf('%d patch%s skipped (%s)', $nbPatchesSkipped, ($nbPatchesSkipped > 1)?'es':'', implode(', ', $patchArr)); |
|
207 | - } |
|
208 | - |
|
209 | - if ($msg !== '') { |
|
210 | - set_user_message($msg, UserMessageInterface::SUCCESS); |
|
211 | - } |
|
212 | - } |
|
185 | + { |
|
186 | + $nbPatchesApplied = array_sum($appliedPatchArray); |
|
187 | + $nbPatchesSkipped = array_sum($skippedPatchArray); |
|
188 | + $msg = ''; |
|
189 | + if ($nbPatchesApplied !== 0) { |
|
190 | + $patchArr = []; |
|
191 | + foreach ($appliedPatchArray as $name => $number) { |
|
192 | + $name = $name ?: 'default'; |
|
193 | + $patchArr[] = plainstring_to_htmlprotected($name).': '.$number; |
|
194 | + } |
|
195 | + |
|
196 | + $msg .= sprintf('%d patch%s applied (%s)', $nbPatchesApplied, ($nbPatchesApplied > 1)?'es':'', implode(', ', $patchArr)); |
|
197 | + } |
|
198 | + if ($nbPatchesSkipped !== 0) { |
|
199 | + $patchArr = []; |
|
200 | + foreach ($skippedPatchArray as $name => $number) { |
|
201 | + $name = $name ?: 'default'; |
|
202 | + $patchArr[] = plainstring_to_htmlprotected($name).': '.$number; |
|
203 | + } |
|
204 | + |
|
205 | + $msg .= sprintf('%d patch%s skipped (%s)', $nbPatchesSkipped, ($nbPatchesSkipped > 1)?'es':'', implode(', ', $patchArr)); |
|
206 | + } |
|
207 | + |
|
208 | + if ($msg !== '') { |
|
209 | + set_user_message($msg, UserMessageInterface::SUCCESS); |
|
210 | + } |
|
211 | + } |
|
213 | 212 | } |
214 | 213 | \ No newline at end of file |
@@ -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 |
@@ -32,47 +32,47 @@ discard block |
||
32 | 32 | * @ExtendedAction {"name":"View patches list", "url":"patcher/", "default":false} |
33 | 33 | */ |
34 | 34 | class PatchService implements MoufValidatorInterface, DumpableInterface { |
35 | - const IFEXISTS_EXCEPTION = "exception"; |
|
36 | - const IFEXISTS_IGNORE = "ignore"; |
|
35 | + const IFEXISTS_EXCEPTION = "exception"; |
|
36 | + const IFEXISTS_IGNORE = "ignore"; |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
39 | + /** |
|
40 | 40 | * The list of patches declared for this application. |
41 | 41 | * |
42 | 42 | * @var PatchInterface[] |
43 | 43 | */ |
44 | 44 | private $patchs = []; |
45 | 45 | |
46 | - /** |
|
47 | - * The list of exiting patch types for this application. |
|
48 | - * |
|
49 | - * @var PatchType[] |
|
50 | - */ |
|
46 | + /** |
|
47 | + * The list of exiting patch types for this application. |
|
48 | + * |
|
49 | + * @var PatchType[] |
|
50 | + */ |
|
51 | 51 | private $types = []; |
52 | 52 | |
53 | - /** |
|
54 | - * The list of listeners on the patch service. |
|
55 | - * |
|
56 | - * @var array|PatchListenerInterface[] |
|
57 | - */ |
|
58 | - private $listeners; |
|
53 | + /** |
|
54 | + * The list of listeners on the patch service. |
|
55 | + * |
|
56 | + * @var array|PatchListenerInterface[] |
|
57 | + */ |
|
58 | + private $listeners; |
|
59 | 59 | |
60 | - /** |
|
61 | - * @var DumperInterface |
|
62 | - */ |
|
63 | - private $dumper; |
|
60 | + /** |
|
61 | + * @var DumperInterface |
|
62 | + */ |
|
63 | + private $dumper; |
|
64 | 64 | |
65 | - /** |
|
66 | - * @param PatchType[] $types |
|
67 | - * @param PatchListenerInterface[] $listeners |
|
68 | - */ |
|
69 | - public function __construct(array $types, array $listeners = []) |
|
70 | - { |
|
71 | - $this->types = $types; |
|
72 | - $this->listeners = $listeners; |
|
73 | - } |
|
65 | + /** |
|
66 | + * @param PatchType[] $types |
|
67 | + * @param PatchListenerInterface[] $listeners |
|
68 | + */ |
|
69 | + public function __construct(array $types, array $listeners = []) |
|
70 | + { |
|
71 | + $this->types = $types; |
|
72 | + $this->listeners = $listeners; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
75 | + /** |
|
76 | 76 | * The list of patches declared for this application. |
77 | 77 | * @param PatchInterface[] $patchs |
78 | 78 | * @return PatchService |
@@ -82,26 +82,26 @@ discard block |
||
82 | 82 | return $this; |
83 | 83 | } |
84 | 84 | |
85 | - /** |
|
86 | - * The list of exiting patch types for this application. |
|
87 | - * |
|
88 | - * @return PatchType[] |
|
89 | - */ |
|
90 | - public function getTypes(): array |
|
91 | - { |
|
92 | - return $this->types; |
|
93 | - } |
|
85 | + /** |
|
86 | + * The list of exiting patch types for this application. |
|
87 | + * |
|
88 | + * @return PatchType[] |
|
89 | + */ |
|
90 | + public function getTypes(): array |
|
91 | + { |
|
92 | + return $this->types; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * @internal Returns a serialized list of types for the patch UI. |
|
97 | - * @return array |
|
98 | - */ |
|
99 | - public function _getSerializedTypes(): array |
|
100 | - { |
|
101 | - return array_map(function(PatchType $type) { |
|
102 | - return $type->jsonSerialize(); |
|
103 | - }, $this->types); |
|
104 | - } |
|
95 | + /** |
|
96 | + * @internal Returns a serialized list of types for the patch UI. |
|
97 | + * @return array |
|
98 | + */ |
|
99 | + public function _getSerializedTypes(): array |
|
100 | + { |
|
101 | + return array_map(function(PatchType $type) { |
|
102 | + return $type->jsonSerialize(); |
|
103 | + }, $this->types); |
|
104 | + } |
|
105 | 105 | |
106 | 106 | /** |
107 | 107 | * Adds this patch to the list of existing patches. |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | |
231 | 231 | /** |
232 | 232 | * Returns a PHP array representing the patchs. |
233 | - * |
|
234 | - * @internal |
|
233 | + * |
|
234 | + * @internal |
|
235 | 235 | */ |
236 | 236 | public function getView(): array { |
237 | 237 | $view = array(); |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | "description"=>$description, |
266 | 266 | "error_message"=>$error_message, |
267 | 267 | "edit_url"=>$editUrl, |
268 | - "patch_type"=>$patchType |
|
268 | + "patch_type"=>$patchType |
|
269 | 269 | ); |
270 | 270 | $view[] = $patchView; |
271 | 271 | } |
@@ -279,9 +279,9 @@ discard block |
||
279 | 279 | public function apply($uniqueName): void { |
280 | 280 | $patch = $this->get($uniqueName); |
281 | 281 | if ($patch instanceof DumpableInterface && $this->dumper !== null) { |
282 | - $patch->setDumper($this->dumper); |
|
283 | - } |
|
284 | - // TODO: in next major version, get rid of the DumpableInterface and pass the dumper right in the apply method. |
|
282 | + $patch->setDumper($this->dumper); |
|
283 | + } |
|
284 | + // TODO: in next major version, get rid of the DumpableInterface and pass the dumper right in the apply method. |
|
285 | 285 | $patch->apply(); |
286 | 286 | } |
287 | 287 | |
@@ -291,9 +291,9 @@ discard block |
||
291 | 291 | */ |
292 | 292 | public function skip($uniqueName): void { |
293 | 293 | $patch = $this->get($uniqueName); |
294 | - if ($patch instanceof DumpableInterface && $this->dumper !== null) { |
|
295 | - $patch->setDumper($this->dumper); |
|
296 | - } |
|
294 | + if ($patch instanceof DumpableInterface && $this->dumper !== null) { |
|
295 | + $patch->setDumper($this->dumper); |
|
296 | + } |
|
297 | 297 | $patch->skip(); |
298 | 298 | } |
299 | 299 | |
@@ -304,66 +304,66 @@ discard block |
||
304 | 304 | */ |
305 | 305 | public function revert($uniqueName): void { |
306 | 306 | $patch = $this->get($uniqueName); |
307 | - if ($patch instanceof DumpableInterface && $this->dumper !== null) { |
|
308 | - $patch->setDumper($this->dumper); |
|
309 | - } |
|
307 | + if ($patch instanceof DumpableInterface && $this->dumper !== null) { |
|
308 | + $patch->setDumper($this->dumper); |
|
309 | + } |
|
310 | 310 | $patch->revert(); |
311 | 311 | } |
312 | 312 | |
313 | - /** |
|
314 | - * Apply all remaining patches (patches in state "awaiting" or in "error"). |
|
315 | - * The types of the patches can be passed as an array of string where the string is the name of the patch. |
|
316 | - * Patches with the "default" type are always applied. |
|
317 | - * |
|
318 | - * @param string[] $types |
|
319 | - * @return array An array containing 2 keys: "applied" and "skipped". Each key contains an associative array with the type of the patch and the number of patches of this type applied. |
|
320 | - */ |
|
313 | + /** |
|
314 | + * Apply all remaining patches (patches in state "awaiting" or in "error"). |
|
315 | + * The types of the patches can be passed as an array of string where the string is the name of the patch. |
|
316 | + * Patches with the "default" type are always applied. |
|
317 | + * |
|
318 | + * @param string[] $types |
|
319 | + * @return array An array containing 2 keys: "applied" and "skipped". Each key contains an associative array with the type of the patch and the number of patches of this type applied. |
|
320 | + */ |
|
321 | 321 | public function applyAll(array $types = []): array { |
322 | - // Array of count of applied and skipped patches. Key is the patch type. |
|
323 | - $appliedPatchArray = []; |
|
324 | - $skippedPatchArray = []; |
|
322 | + // Array of count of applied and skipped patches. Key is the patch type. |
|
323 | + $appliedPatchArray = []; |
|
324 | + $skippedPatchArray = []; |
|
325 | 325 | |
326 | - foreach ($this->patchs as $patch) { |
|
327 | - if ($patch->getStatus() === PatchInterface::STATUS_AWAITING || $patch->getStatus() === PatchInterface::STATUS_ERROR) { |
|
328 | - $type = $patch->getPatchType()->getName(); |
|
329 | - if ($type === '' || in_array($type, $types, true)) { |
|
330 | - $this->apply($patch->getUniqueName()); |
|
331 | - if (!isset($appliedPatchArray[$type])) { |
|
332 | - $appliedPatchArray[$type] = 0; |
|
333 | - } |
|
334 | - $appliedPatchArray[$type]++; |
|
335 | - } else { |
|
336 | - $this->skip($patch->getUniqueName()); |
|
337 | - if (!isset($skippedPatchArray[$type])) { |
|
338 | - $skippedPatchArray[$type] = 0; |
|
339 | - } |
|
340 | - $skippedPatchArray[$type]++; |
|
341 | - } |
|
342 | - } |
|
343 | - } |
|
326 | + foreach ($this->patchs as $patch) { |
|
327 | + if ($patch->getStatus() === PatchInterface::STATUS_AWAITING || $patch->getStatus() === PatchInterface::STATUS_ERROR) { |
|
328 | + $type = $patch->getPatchType()->getName(); |
|
329 | + if ($type === '' || in_array($type, $types, true)) { |
|
330 | + $this->apply($patch->getUniqueName()); |
|
331 | + if (!isset($appliedPatchArray[$type])) { |
|
332 | + $appliedPatchArray[$type] = 0; |
|
333 | + } |
|
334 | + $appliedPatchArray[$type]++; |
|
335 | + } else { |
|
336 | + $this->skip($patch->getUniqueName()); |
|
337 | + if (!isset($skippedPatchArray[$type])) { |
|
338 | + $skippedPatchArray[$type] = 0; |
|
339 | + } |
|
340 | + $skippedPatchArray[$type]++; |
|
341 | + } |
|
342 | + } |
|
343 | + } |
|
344 | 344 | |
345 | - return [ |
|
346 | - 'applied' => $appliedPatchArray, |
|
347 | - 'skipped' => $skippedPatchArray |
|
348 | - ]; |
|
349 | - } |
|
345 | + return [ |
|
346 | + 'applied' => $appliedPatchArray, |
|
347 | + 'skipped' => $skippedPatchArray |
|
348 | + ]; |
|
349 | + } |
|
350 | 350 | |
351 | - /** |
|
352 | - * Reset all patches to a not applied state. |
|
353 | - * |
|
354 | - * Note: this does NOT run the "revert" method on each patch but DOES trigger a "reset" event. |
|
355 | - */ |
|
351 | + /** |
|
352 | + * Reset all patches to a not applied state. |
|
353 | + * |
|
354 | + * Note: this does NOT run the "revert" method on each patch but DOES trigger a "reset" event. |
|
355 | + */ |
|
356 | 356 | public function reset(): void { |
357 | - foreach ($this->listeners as $listener) { |
|
358 | - if ($listener instanceof DumpableInterface && $this->dumper !== null) { |
|
359 | - $listener->setDumper($this->dumper); |
|
360 | - } |
|
361 | - $listener->onReset(); |
|
362 | - } |
|
363 | - } |
|
357 | + foreach ($this->listeners as $listener) { |
|
358 | + if ($listener instanceof DumpableInterface && $this->dumper !== null) { |
|
359 | + $listener->setDumper($this->dumper); |
|
360 | + } |
|
361 | + $listener->onReset(); |
|
362 | + } |
|
363 | + } |
|
364 | 364 | |
365 | - public function setDumper(DumperInterface $dumper) |
|
366 | - { |
|
367 | - $this->dumper = $dumper; |
|
368 | - } |
|
365 | + public function setDumper(DumperInterface $dumper) |
|
366 | + { |
|
367 | + $this->dumper = $dumper; |
|
368 | + } |
|
369 | 369 | } |