@@ -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 |