Total Complexity | 125 |
Total Lines | 916 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like AdminTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AdminTrait, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | trait AdminTrait |
||
15 | { |
||
16 | /** |
||
17 | * Show confirmation of cluster. |
||
18 | * |
||
19 | * @param mixed $type |
||
20 | */ |
||
21 | public function confirmCluster($type) |
||
22 | { |
||
23 | $this->script = ('database' == $type) ? 'database' : 'tables'; |
||
24 | |||
25 | $script = $this->script; |
||
26 | |||
27 | if (('table' == $type) && empty($_REQUEST['table']) && empty($_REQUEST['ma'])) { |
||
28 | $this->doDefault($this->lang['strspecifytabletocluster']); |
||
29 | |||
30 | return; |
||
31 | } |
||
32 | |||
33 | if (isset($_REQUEST['ma'])) { |
||
34 | $this->printTrail('schema'); |
||
35 | $this->printTitle($this->lang['strclusterindex'], 'pg.index.cluster'); |
||
36 | |||
37 | echo '<form action="'.\SUBFOLDER."/src/views/{$script}\" method=\"post\">".PHP_EOL; |
||
38 | foreach ($_REQUEST['ma'] as $v) { |
||
39 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
40 | echo '<p>', sprintf($this->lang['strconfclustertable'], $this->misc->printVal($a['table'])), '</p>'.PHP_EOL; |
||
41 | echo '<input type="hidden" name="table[]" value="', htmlspecialchars($a['table']), '" />'.PHP_EOL; |
||
42 | } // END if multi cluster |
||
43 | } else { |
||
44 | $this->printTrail($type); |
||
45 | $this->printTitle($this->lang['strclusterindex'], 'pg.index.cluster'); |
||
46 | |||
47 | echo '<form action="'.\SUBFOLDER."/src/views/{$script}\" method=\"post\">".PHP_EOL; |
||
48 | |||
49 | if ('table' == $type) { |
||
50 | echo '<p>', sprintf($this->lang['strconfclustertable'], $this->misc->printVal($_REQUEST['object'])), '</p>'.PHP_EOL; |
||
51 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['object']), '" />'.PHP_EOL; |
||
52 | } else { |
||
53 | echo '<p>', sprintf($this->lang['strconfclusterdatabase'], $this->misc->printVal($_REQUEST['object'])), '</p>'.PHP_EOL; |
||
54 | echo '<input type="hidden" name="table" value="" />'.PHP_EOL; |
||
55 | } |
||
56 | } |
||
57 | echo '<input type="hidden" name="action" value="cluster" />'.PHP_EOL; |
||
58 | |||
59 | echo $this->misc->form; |
||
60 | |||
61 | echo "<input type=\"submit\" name=\"cluster\" value=\"{$this->lang['strcluster']}\" />\n"; //TODO |
||
62 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />".PHP_EOL; |
||
63 | echo "</form>\n"; // END single cluster |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Show confirmation of reindex. |
||
68 | * |
||
69 | * @param mixed $type |
||
70 | */ |
||
71 | public function confirmReindex($type) |
||
72 | { |
||
73 | $this->script = ('database' == $type) ? 'database' : 'tables'; |
||
74 | $script = $this->script; |
||
75 | $this->misc = $this->misc; |
||
76 | $data = $this->misc->getDatabaseAccessor(); |
||
77 | |||
78 | if (('table' == $type) && empty($_REQUEST['table']) && empty($_REQUEST['ma'])) { |
||
79 | $this->doDefault($this->lang['strspecifytabletoreindex']); |
||
80 | |||
81 | return; |
||
82 | } |
||
83 | |||
84 | if (isset($_REQUEST['ma'])) { |
||
85 | $this->printTrail('schema'); |
||
86 | $this->printTitle($this->lang['strreindex'], 'pg.reindex'); |
||
87 | |||
88 | echo '<form action="'.\SUBFOLDER."/src/views/{$script}\" method=\"post\">".PHP_EOL; |
||
89 | foreach ($_REQUEST['ma'] as $v) { |
||
90 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
91 | echo '<p>', sprintf($this->lang['strconfreindextable'], $this->misc->printVal($a['table'])), '</p>'.PHP_EOL; |
||
92 | echo '<input type="hidden" name="table[]" value="', htmlspecialchars($a['table']), '" />'.PHP_EOL; |
||
93 | } // END if multi reindex |
||
94 | } else { |
||
95 | $this->printTrail($type); |
||
96 | $this->printTitle($this->lang['strreindex'], 'pg.reindex'); |
||
97 | |||
98 | echo '<form action="'.\SUBFOLDER."/src/views/{$script}\" method=\"post\">".PHP_EOL; |
||
99 | |||
100 | if ('table' == $type) { |
||
101 | echo '<p>', sprintf($this->lang['strconfreindextable'], $this->misc->printVal($_REQUEST['object'])), '</p>'.PHP_EOL; |
||
102 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['object']), '" />'.PHP_EOL; |
||
103 | } else { |
||
104 | echo '<p>', sprintf($this->lang['strconfreindexdatabase'], $this->misc->printVal($_REQUEST['object'])), '</p>'.PHP_EOL; |
||
105 | echo '<input type="hidden" name="table" value="" />'.PHP_EOL; |
||
106 | } |
||
107 | } |
||
108 | echo '<input type="hidden" name="action" value="reindex" />'.PHP_EOL; |
||
109 | |||
110 | if ($data->hasForceReindex()) { |
||
111 | echo "<p><input type=\"checkbox\" id=\"reindex_force\" name=\"reindex_force\" /><label for=\"reindex_force\">{$this->lang['strforce']}</label></p>".PHP_EOL; |
||
112 | } |
||
113 | |||
114 | echo $this->misc->form; |
||
115 | |||
116 | echo "<input type=\"submit\" name=\"reindex\" value=\"{$this->lang['strreindex']}\" />\n"; //TODO |
||
117 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />".PHP_EOL; |
||
118 | echo "</form>\n"; // END single reindex |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Show confirmation of analyze. |
||
123 | * |
||
124 | * @param mixed $type |
||
125 | */ |
||
126 | public function confirmAnalyze($type) |
||
127 | { |
||
128 | $this->script = ('database' == $type) ? 'database' : 'tables'; |
||
129 | |||
130 | $script = $this->script; |
||
131 | |||
132 | if (('table' == $type) && empty($_REQUEST['table']) && empty($_REQUEST['ma'])) { |
||
133 | $this->doDefault($this->lang['strspecifytabletoanalyze']); |
||
134 | |||
135 | return; |
||
136 | } |
||
137 | |||
138 | if (isset($_REQUEST['ma'])) { |
||
139 | $this->printTrail('schema'); |
||
140 | $this->printTitle($this->lang['stranalyze'], 'pg.analyze'); |
||
141 | |||
142 | echo '<form action="'.\SUBFOLDER."/src/views/{$script}\" method=\"post\">".PHP_EOL; |
||
143 | foreach ($_REQUEST['ma'] as $v) { |
||
144 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
145 | //\Kint::dump($a); |
||
146 | echo '<p>', sprintf($this->lang['strconfanalyzetable'], $this->misc->printVal($a['table'])), '</p>'.PHP_EOL; |
||
147 | echo '<input type="hidden" name="table[]" value="', htmlspecialchars($a['table']), '" />'.PHP_EOL; |
||
148 | } // END if multi analyze |
||
149 | } else { |
||
150 | $this->printTrail($type); |
||
151 | $this->printTitle($this->lang['stranalyze'], 'pg.analyze'); |
||
152 | |||
153 | echo '<form action="'.\SUBFOLDER."/src/views/{$script}\" method=\"post\">".PHP_EOL; |
||
154 | |||
155 | if ('table' == $type) { |
||
156 | echo '<p>', sprintf($this->lang['strconfanalyzetable'], $this->misc->printVal($_REQUEST['object'])), '</p>'.PHP_EOL; |
||
157 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['object']), '" />'.PHP_EOL; |
||
158 | } else { |
||
159 | echo '<p>', sprintf($this->lang['strconfanalyzedatabase'], $this->misc->printVal($_REQUEST['object'])), '</p>'.PHP_EOL; |
||
160 | echo '<input type="hidden" name="table" value="" />'.PHP_EOL; |
||
161 | } |
||
162 | } |
||
163 | echo '<input type="hidden" name="action" value="analyze" />'.PHP_EOL; |
||
164 | echo $this->misc->form; |
||
165 | |||
166 | echo "<input type=\"submit\" name=\"analyze\" value=\"{$this->lang['stranalyze']}\" />\n"; //TODO |
||
167 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />".PHP_EOL; |
||
168 | echo "</form>\n"; // END single analyze |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * Show confirmation of vacuum. |
||
173 | * |
||
174 | * @param mixed $type |
||
175 | */ |
||
176 | public function confirmVacuum($type) |
||
177 | { |
||
178 | $script = ('database' == $type) ? 'database' : 'tables'; |
||
179 | |||
180 | if (('table' == $type) && empty($_REQUEST['table']) && empty($_REQUEST['ma'])) { |
||
181 | $this->doDefault($this->lang['strspecifytabletovacuum']); |
||
182 | |||
183 | return; |
||
184 | } |
||
185 | |||
186 | if (isset($_REQUEST['ma'])) { |
||
187 | $this->printTrail('schema'); |
||
188 | $this->printTitle($this->lang['strvacuum'], 'pg.vacuum'); |
||
189 | |||
190 | echo '<form action="'.\SUBFOLDER."/src/views/{$script}\" method=\"post\">".PHP_EOL; |
||
191 | foreach ($_REQUEST['ma'] as $v) { |
||
192 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
193 | echo '<p>', sprintf($this->lang['strconfvacuumtable'], $this->misc->printVal($a['table'])), '</p>'.PHP_EOL; |
||
194 | echo '<input type="hidden" name="table[]" value="', htmlspecialchars($a['table']), '" />'.PHP_EOL; |
||
195 | } |
||
196 | } else { |
||
197 | // END if multi vacuum |
||
198 | $this->printTrail($type); |
||
199 | $this->printTitle($this->lang['strvacuum'], 'pg.vacuum'); |
||
200 | |||
201 | echo '<form action="'.\SUBFOLDER."/src/views/{$script}\" method=\"post\">".PHP_EOL; |
||
202 | |||
203 | if ('table' == $type) { |
||
204 | echo '<p>', sprintf($this->lang['strconfvacuumtable'], $this->misc->printVal($_REQUEST['object'])), '</p>'.PHP_EOL; |
||
205 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['object']), '" />'.PHP_EOL; |
||
206 | } else { |
||
207 | echo '<p>', sprintf($this->lang['strconfvacuumdatabase'], $this->misc->printVal($_REQUEST['object'])), '</p>'.PHP_EOL; |
||
208 | echo '<input type="hidden" name="table" value="" />'.PHP_EOL; |
||
209 | } |
||
210 | } |
||
211 | echo '<input type="hidden" name="action" value="vacuum" />'.PHP_EOL; |
||
212 | echo $this->misc->form; |
||
213 | echo "<p><input type=\"checkbox\" id=\"vacuum_full\" name=\"vacuum_full\" /> <label for=\"vacuum_full\">{$this->lang['strfull']}</label></p>".PHP_EOL; |
||
214 | echo "<p><input type=\"checkbox\" id=\"vacuum_analyze\" name=\"vacuum_analyze\" /> <label for=\"vacuum_analyze\">{$this->lang['stranalyze']}</label></p>".PHP_EOL; |
||
215 | echo "<p><input type=\"checkbox\" id=\"vacuum_freeze\" name=\"vacuum_freeze\" /> <label for=\"vacuum_freeze\">{$this->lang['strfreeze']}</label></p>".PHP_EOL; |
||
216 | echo "<input type=\"submit\" name=\"vacuum\" value=\"{$this->lang['strvacuum']}\" />".PHP_EOL; |
||
217 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />".PHP_EOL; |
||
218 | echo "</form>\n"; // END single vacuum |
||
219 | } |
||
220 | |||
221 | /** |
||
222 | * Add or Edit autovacuum params. |
||
223 | * |
||
224 | * @param mixed $type |
||
225 | * @param mixed $msg |
||
226 | */ |
||
227 | public function confirmEditAutovacuum($type, $msg = '') |
||
228 | { |
||
229 | $data = $this->misc->getDatabaseAccessor(); |
||
230 | |||
231 | if (empty($_REQUEST['table'])) { |
||
232 | $this->doAdmin($type, $this->lang['strspecifyeditvacuumtable']); |
||
233 | |||
234 | return; |
||
235 | } |
||
236 | |||
237 | $script = ('database' == $type) ? 'database' : 'tables'; |
||
238 | |||
239 | $this->printTrail($type); |
||
240 | $this->printTitle(sprintf($this->lang['streditvacuumtable'], $this->misc->printVal($_REQUEST['table']))); |
||
241 | $this->printMsg(sprintf($msg, $this->misc->printVal($_REQUEST['table']))); |
||
242 | |||
243 | if (empty($_REQUEST['table'])) { |
||
244 | $this->doAdmin($type, $this->lang['strspecifyeditvacuumtable']); |
||
245 | |||
246 | return; |
||
247 | } |
||
248 | |||
249 | $old_val = $data->getTableAutovacuum($_REQUEST['table']); |
||
250 | $defaults = $data->getAutovacuum(); |
||
251 | $old_val = $old_val->fields; |
||
252 | |||
253 | if (isset($old_val['autovacuum_enabled']) and ('off' == $old_val['autovacuum_enabled'])) { |
||
254 | $enabled = ''; |
||
255 | $disabled = 'checked="checked"'; |
||
256 | } else { |
||
257 | $enabled = 'checked="checked"'; |
||
258 | $disabled = ''; |
||
259 | } |
||
260 | |||
261 | if (!isset($old_val['autovacuum_vacuum_threshold'])) { |
||
262 | $old_val['autovacuum_vacuum_threshold'] = ''; |
||
263 | } |
||
264 | |||
265 | if (!isset($old_val['autovacuum_vacuum_scale_factor'])) { |
||
266 | $old_val['autovacuum_vacuum_scale_factor'] = ''; |
||
267 | } |
||
268 | |||
269 | if (!isset($old_val['autovacuum_analyze_threshold'])) { |
||
270 | $old_val['autovacuum_analyze_threshold'] = ''; |
||
271 | } |
||
272 | |||
273 | if (!isset($old_val['autovacuum_analyze_scale_factor'])) { |
||
274 | $old_val['autovacuum_analyze_scale_factor'] = ''; |
||
275 | } |
||
276 | |||
277 | if (!isset($old_val['autovacuum_vacuum_cost_delay'])) { |
||
278 | $old_val['autovacuum_vacuum_cost_delay'] = ''; |
||
279 | } |
||
280 | |||
281 | if (!isset($old_val['autovacuum_vacuum_cost_limit'])) { |
||
282 | $old_val['autovacuum_vacuum_cost_limit'] = ''; |
||
283 | } |
||
284 | |||
285 | echo '<form action="'.\SUBFOLDER."/src/views/{$script}\" method=\"post\">".PHP_EOL; |
||
286 | echo $this->misc->form; |
||
287 | echo '<input type="hidden" name="action" value="editautovac" />'.PHP_EOL; |
||
288 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), '" />'.PHP_EOL; |
||
289 | |||
290 | echo "<br />\n<br />\n<table>".PHP_EOL; |
||
291 | echo "\t<tr><td> </td>".PHP_EOL; |
||
292 | echo "<th class=\"data\">{$this->lang['strnewvalues']}</th><th class=\"data\">{$this->lang['strdefaultvalues']}</th></tr>".PHP_EOL; |
||
293 | echo "\t<tr><th class=\"data left\">{$this->lang['strenable']}</th>".PHP_EOL; |
||
294 | echo '<td class="data1">'.PHP_EOL; |
||
295 | echo "<label for=\"on\">on</label><input type=\"radio\" name=\"autovacuum_enabled\" id=\"on\" value=\"on\" {$enabled} />".PHP_EOL; |
||
296 | echo "<label for=\"off\">off</label><input type=\"radio\" name=\"autovacuum_enabled\" id=\"off\" value=\"off\" {$disabled} /></td>".PHP_EOL; |
||
297 | echo "<th class=\"data left\">{$defaults['autovacuum']}</th></tr>".PHP_EOL; |
||
298 | echo "\t<tr><th class=\"data left\">{$this->lang['strvacuumbasethreshold']}</th>".PHP_EOL; |
||
299 | echo "<td class=\"data1\"><input type=\"text\" name=\"autovacuum_vacuum_threshold\" value=\"{$old_val['autovacuum_vacuum_threshold']}\" /></td>".PHP_EOL; |
||
300 | echo "<th class=\"data left\">{$defaults['autovacuum_vacuum_threshold']}</th></tr>".PHP_EOL; |
||
301 | echo "\t<tr><th class=\"data left\">{$this->lang['strvacuumscalefactor']}</th>".PHP_EOL; |
||
302 | echo "<td class=\"data1\"><input type=\"text\" name=\"autovacuum_vacuum_scale_factor\" value=\"{$old_val['autovacuum_vacuum_scale_factor']}\" /></td>".PHP_EOL; |
||
303 | echo "<th class=\"data left\">{$defaults['autovacuum_vacuum_scale_factor']}</th></tr>".PHP_EOL; |
||
304 | echo "\t<tr><th class=\"data left\">{$this->lang['stranalybasethreshold']}</th>".PHP_EOL; |
||
305 | echo "<td class=\"data1\"><input type=\"text\" name=\"autovacuum_analyze_threshold\" value=\"{$old_val['autovacuum_analyze_threshold']}\" /></td>".PHP_EOL; |
||
306 | echo "<th class=\"data left\">{$defaults['autovacuum_analyze_threshold']}</th></tr>".PHP_EOL; |
||
307 | echo "\t<tr><th class=\"data left\">{$this->lang['stranalyzescalefactor']}</th>".PHP_EOL; |
||
308 | echo "<td class=\"data1\"><input type=\"text\" name=\"autovacuum_analyze_scale_factor\" value=\"{$old_val['autovacuum_analyze_scale_factor']}\" /></td>".PHP_EOL; |
||
309 | echo "<th class=\"data left\">{$defaults['autovacuum_analyze_scale_factor']}</th></tr>".PHP_EOL; |
||
310 | echo "\t<tr><th class=\"data left\">{$this->lang['strvacuumcostdelay']}</th>".PHP_EOL; |
||
311 | echo "<td class=\"data1\"><input type=\"text\" name=\"autovacuum_vacuum_cost_delay\" value=\"{$old_val['autovacuum_vacuum_cost_delay']}\" /></td>".PHP_EOL; |
||
312 | echo "<th class=\"data left\">{$defaults['autovacuum_vacuum_cost_delay']}</th></tr>".PHP_EOL; |
||
313 | echo "\t<tr><th class=\"data left\">{$this->lang['strvacuumcostlimit']}</th>".PHP_EOL; |
||
314 | echo "<td class=\"datat1\"><input type=\"text\" name=\"autovacuum_vacuum_cost_limit\" value=\"{$old_val['autovacuum_vacuum_cost_limit']}\" /></td>".PHP_EOL; |
||
315 | echo "<th class=\"data left\">{$defaults['autovacuum_vacuum_cost_limit']}</th></tr>".PHP_EOL; |
||
316 | echo '</table>'.PHP_EOL; |
||
317 | echo '<br />'; |
||
318 | echo '<br />'; |
||
319 | echo "<input type=\"submit\" name=\"save\" value=\"{$this->lang['strsave']}\" />".PHP_EOL; |
||
320 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>".PHP_EOL; |
||
321 | |||
322 | echo '</form>'.PHP_EOL; |
||
323 | } |
||
324 | |||
325 | /** |
||
326 | * Confirm drop autovacuum params for a table. |
||
327 | * |
||
328 | * @param mixed $type |
||
329 | */ |
||
330 | public function confirmDropAutovacuum($type) |
||
331 | { |
||
332 | $script = ('database' == $type) ? 'database' : 'tables'; |
||
333 | |||
334 | if (empty($_REQUEST['table'])) { |
||
335 | $this->doAdmin($type, $this->lang['strspecifydelvacuumtable']); |
||
336 | |||
337 | return; |
||
338 | } |
||
339 | |||
340 | $this->printTrail($type); |
||
341 | $this->printTabs($type, 'admin'); |
||
342 | |||
343 | printf( |
||
344 | "<p>{$this->lang['strdelvacuumtable']}</p>\n", |
||
345 | $this->misc->printVal("\"{$_GET['schema']}\".\"{$_GET['table']}\"") |
||
346 | ); |
||
347 | |||
348 | echo "<form style=\"float: left\" action=\"{$script}\" method=\"post\">".PHP_EOL; |
||
349 | echo '<input type="hidden" name="action" value="delautovac" />'.PHP_EOL; |
||
350 | echo $this->misc->form; |
||
351 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), '" />'.PHP_EOL; |
||
352 | echo '<input type="hidden" name="rel" value="', htmlspecialchars(serialize([$_REQUEST['schema'], $_REQUEST['table']])), '" />'.PHP_EOL; |
||
353 | echo "<input type=\"submit\" name=\"yes\" value=\"{$this->lang['stryes']}\" />".PHP_EOL; |
||
354 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />".PHP_EOL; |
||
355 | echo '</form>'.PHP_EOL; |
||
356 | } |
||
357 | |||
358 | /** |
||
359 | * perform cluster. |
||
360 | * |
||
361 | * @param mixed $type |
||
362 | */ |
||
363 | public function doCluster($type) |
||
408 | } |
||
409 | } |
||
410 | } |
||
411 | |||
412 | /** |
||
413 | * perform reindex. |
||
414 | * |
||
415 | * @param mixed $type |
||
416 | */ |
||
417 | public function doReindex($type) |
||
418 | { |
||
419 | $this->misc = $this->misc; |
||
420 | $data = $this->misc->getDatabaseAccessor(); |
||
421 | |||
422 | if (('table' == $type) && empty($_REQUEST['table']) && empty($_REQUEST['ma'])) { |
||
423 | $this->doDefault($this->lang['strspecifytabletoreindex']); |
||
424 | |||
425 | return; |
||
426 | } |
||
427 | |||
428 | //If multi table reindex |
||
429 | if (('table' == $type) && is_array($_REQUEST['table'])) { |
||
430 | $msg = ''; |
||
431 | foreach ($_REQUEST['table'] as $o) { |
||
432 | $status = $data->reindex(strtoupper($type), $o, isset($_REQUEST['reindex_force'])); |
||
433 | if (0 == $status) { |
||
434 | $msg .= sprintf('%s: %s<br />', htmlentities($o, ENT_QUOTES, 'UTF-8'), $this->lang['strreindexgood']); |
||
435 | } else { |
||
436 | $this->doDefault(sprintf('%s %s%s: %s<br />', $type, $msg, htmlentities($o, ENT_QUOTES, 'UTF-8'), $this->lang['strreindexbad'])); |
||
437 | |||
438 | return; |
||
439 | } |
||
440 | } |
||
441 | // Everything went fine, back to the Default page.... |
||
442 | $this->misc->setReloadBrowser(true); |
||
443 | $this->doDefault($msg); |
||
444 | } else { |
||
445 | $status = $data->reindex(strtoupper($type), $_REQUEST['object'], isset($_REQUEST['reindex_force'])); |
||
446 | if (0 == $status) { |
||
447 | $this->misc->setReloadBrowser(true); |
||
448 | $this->doAdmin($type, $this->lang['strreindexgood']); |
||
449 | } else { |
||
450 | $this->doAdmin($type, $this->lang['strreindexbad']); |
||
451 | } |
||
452 | } |
||
453 | } |
||
454 | |||
455 | /** |
||
456 | * perform analyze. |
||
457 | * |
||
458 | * @param mixed $type |
||
459 | */ |
||
460 | public function doAnalyze($type) |
||
494 | } |
||
495 | } |
||
496 | } |
||
497 | |||
498 | /** |
||
499 | * perform actual vacuum. |
||
500 | * |
||
501 | * @param mixed $type |
||
502 | */ |
||
503 | public function doVacuum($type) |
||
504 | { |
||
505 | $data = $this->misc->getDatabaseAccessor(); |
||
506 | |||
507 | if (('table' == $type) && empty($_REQUEST['table']) && empty($_REQUEST['ma'])) { |
||
508 | $this->doDefault($this->lang['strspecifytabletovacuum']); |
||
509 | |||
510 | return; |
||
511 | } |
||
512 | |||
513 | //If multi drop |
||
514 | if (is_array($_REQUEST['table'])) { |
||
515 | $msg = ''; |
||
516 | foreach ($_REQUEST['table'] as $t) { |
||
517 | $status = $data->vacuumDB($t, isset($_REQUEST['vacuum_analyze']), isset($_REQUEST['vacuum_full']), isset($_REQUEST['vacuum_freeze'])); |
||
518 | if (0 == $status) { |
||
519 | $msg .= sprintf('%s: %s<br />', htmlentities($t, ENT_QUOTES, 'UTF-8'), $this->lang['strvacuumgood']); |
||
520 | } else { |
||
521 | $this->doDefault(sprintf('%s %s%s: %s<br />', $type, $msg, htmlentities($t, ENT_QUOTES, 'UTF-8'), $this->lang['strvacuumbad'])); |
||
522 | |||
523 | return; |
||
524 | } |
||
525 | } |
||
526 | // Everything went fine, back to the Default page.... |
||
527 | $this->misc->setReloadBrowser(true); |
||
528 | $this->doDefault($msg); |
||
529 | } else { |
||
530 | //we must pass table here. When empty, vacuum the whole db |
||
531 | $status = $data->vacuumDB($_REQUEST['table'], isset($_REQUEST['vacuum_analyze']), isset($_REQUEST['vacuum_full']), isset($_REQUEST['vacuum_freeze'])); |
||
532 | if (0 == $status) { |
||
533 | $this->misc->setReloadBrowser(true); |
||
534 | $this->doAdmin($type, $this->lang['strvacuumgood']); |
||
535 | } else { |
||
536 | $this->doAdmin($type, $this->lang['strvacuumbad']); |
||
537 | } |
||
538 | } |
||
539 | } |
||
540 | |||
541 | /** |
||
542 | * persist changes in autovacuum settings. |
||
543 | * |
||
544 | * @param mixed $type |
||
545 | * @param mixed $confirm |
||
546 | * @param mixed $msg |
||
547 | */ |
||
548 | public function doEditAutovacuum($type) |
||
573 | } |
||
574 | } |
||
575 | |||
576 | /** |
||
577 | * drop autovacuum settings. |
||
578 | * |
||
579 | * @param mixed $type |
||
580 | */ |
||
581 | public function doDropAutovacuum($type) |
||
582 | { |
||
583 | $data = $this->misc->getDatabaseAccessor(); |
||
584 | |||
585 | if (empty($_REQUEST['table'])) { |
||
586 | $this->doAdmin($type, $this->lang['strspecifydelvacuumtable']); |
||
587 | |||
588 | return; |
||
589 | } |
||
590 | |||
591 | $status = $data->dropAutovacuum($_POST['table']); |
||
592 | |||
593 | if (0 == $status) { |
||
594 | $this->doAdmin($type, sprintf($this->lang['strvacuumtablereset'], $this->misc->printVal($_POST['table']))); |
||
595 | } else { |
||
596 | $this->doAdmin($type, sprintf($this->lang['strdelvacuumtablefail'], $this->misc->printVal($_POST['table']))); |
||
597 | } |
||
598 | } |
||
599 | |||
600 | /** |
||
601 | * Database/table administration and tuning tasks. |
||
602 | * |
||
603 | * Release: admin |
||
604 | * |
||
605 | * @param mixed $type |
||
606 | * @param mixed $msg |
||
607 | */ |
||
608 | public function doAdmin($type, $msg = '') |
||
609 | { |
||
610 | $this->script = ('database' == $type) ? 'database' : 'tables'; |
||
611 | |||
612 | $script = $this->script; |
||
613 | |||
614 | $data = $this->misc->getDatabaseAccessor(); |
||
615 | |||
616 | $this->printTrail($type); |
||
617 | $this->printTabs($type, 'admin'); |
||
618 | $this->printMsg($msg); |
||
619 | |||
620 | if ('database' == $type) { |
||
621 | printf("<p>{$this->lang['stradminondatabase']}</p>\n", $this->misc->printVal($_REQUEST['object'])); |
||
622 | } else { |
||
623 | printf("<p>{$this->lang['stradminontable']}</p>\n", $this->misc->printVal($_REQUEST['object'])); |
||
624 | } |
||
625 | |||
626 | echo '<table style="width: 50%">'.PHP_EOL; |
||
627 | echo '<tr>'.PHP_EOL; |
||
628 | echo '<th class="data">'; |
||
629 | $this->misc->printHelp($this->lang['strvacuum'], 'pg.admin.vacuum').'</th>'.PHP_EOL; |
||
630 | echo '</th>'; |
||
631 | echo '<th class="data">'; |
||
632 | $this->misc->printHelp($this->lang['stranalyze'], 'pg.admin.analyze'); |
||
633 | echo '</th>'; |
||
634 | |||
635 | $table_hidden_inputs = ($type === 'table') ? |
||
636 | sprintf('<input type="hidden" name="table" value="%s" />%s<input type="hidden" name="subject" value="table" />', htmlspecialchars($_REQUEST['object']), PHP_EOL, PHP_EOL) : ''; |
||
637 | |||
638 | list($recluster_help, $reclusterconf) = $this->_getReclusterConf($data, $type, $table_hidden_inputs); |
||
639 | |||
640 | echo $recluster_help; |
||
641 | |||
642 | echo '<th class="data">'; |
||
643 | $this->misc->printHelp($this->lang['strreindex'], 'pg.index.reindex'); |
||
644 | echo '</th>'; |
||
645 | echo '</tr>'; |
||
646 | |||
647 | // Vacuum |
||
648 | echo '<tr class="row1">'.PHP_EOL; |
||
649 | echo '<td style="text-align: center; vertical-align: bottom">'.PHP_EOL; |
||
650 | echo '<form action="'.\SUBFOLDER."/src/views/{$script}\" method=\"post\">".PHP_EOL; |
||
651 | |||
652 | echo '<p><input type="hidden" name="action" value="confirm_vacuum" />'.PHP_EOL; |
||
653 | echo $this->misc->form; |
||
654 | echo $table_hidden_inputs; |
||
655 | echo "<input type=\"submit\" value=\"{$this->lang['strvacuum']}\" /></p>".PHP_EOL; |
||
656 | echo '</form>'.PHP_EOL; |
||
657 | echo '</td>'.PHP_EOL; |
||
658 | |||
659 | // Analyze |
||
660 | echo '<td style="text-align: center; vertical-align: bottom">'.PHP_EOL; |
||
661 | echo '<form action="'.\SUBFOLDER."/src/views/{$script}\" method=\"post\">".PHP_EOL; |
||
662 | echo '<p><input type="hidden" name="action" value="confirm_analyze" />'.PHP_EOL; |
||
663 | echo $this->misc->form; |
||
664 | echo $table_hidden_inputs; |
||
665 | echo "<input type=\"submit\" value=\"{$this->lang['stranalyze']}\" /></p>".PHP_EOL; |
||
666 | echo '</form>'.PHP_EOL; |
||
667 | echo '</td>'.PHP_EOL; |
||
668 | |||
669 | // Cluster |
||
670 | echo $reclusterconf; |
||
671 | |||
672 | // Reindex |
||
673 | echo '<td style="text-align: center; vertical-align: bottom">'.PHP_EOL; |
||
674 | echo '<form action="'.\SUBFOLDER."/src/views/{$script}\" method=\"post\">".PHP_EOL; |
||
675 | echo '<p><input type="hidden" name="action" value="confirm_reindex" />'.PHP_EOL; |
||
676 | echo $this->misc->form; |
||
677 | echo $table_hidden_inputs; |
||
678 | echo "<input type=\"submit\" value=\"{$this->lang['strreindex']}\" /></p>".PHP_EOL; |
||
679 | echo '</form>'.PHP_EOL; |
||
680 | echo '</td>'.PHP_EOL; |
||
681 | echo '</tr>'.PHP_EOL; |
||
682 | echo '</table>'.PHP_EOL; |
||
683 | |||
684 | // Autovacuum |
||
685 | $this->_printAutoVacuumConf($data, $type); |
||
686 | } |
||
687 | |||
688 | public function adminActions($action, $type) |
||
762 | } |
||
763 | |||
764 | private function _getReclusterConf($data, $type, $table_hidden_inputs) |
||
765 | { |
||
766 | if (!$data->hasRecluster()) { |
||
787 | } |
||
788 | |||
789 | private function _printAutoVacuumConf($data, $type) |
||
916 | } |
||
917 | } |
||
918 | |||
919 | abstract public function doDefault($msg = ''); |
||
920 | |||
921 | abstract public function printTrail($trail = [], $do_print = true); |
||
922 | |||
923 | abstract public function printTitle($title, $help = null, $do_print = true); |
||
924 | |||
925 | abstract public function printMsg($msg, $do_print = true); |
||
926 | |||
927 | abstract public function printTabs($tabs, $activetab, $do_print = true); |
||
928 | |||
929 | abstract public function printTable(&$tabledata, &$columns, &$actions, $place, $nodata = '', $pre_fn = null); |
||
930 | } |
||
931 |