Completed
Push — 2.1 ( af0451...313882 )
by David
03:41 queued 01:46
created
src/Mouf/Utils/Patcher/Commands/AbstractApplyAllCommand.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -12,81 +12,81 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
src/Mouf/Utils/Patcher/Commands/ResetPatchesCommand.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -15,34 +15,34 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Mouf/Utils/Patcher/Controllers/PatchController.php 1 patch
Indentation   +97 added lines, -98 removed lines patch added patch discarded remove patch
@@ -20,7 +20,6 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.