Total Complexity | 124 |
Total Lines | 877 |
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 and perform cluster. |
||
18 | * |
||
19 | * @param mixed $type |
||
20 | * @param mixed $confirm |
||
21 | */ |
||
22 | public function doCluster($type, $confirm = false) |
||
23 | { |
||
24 | $this->script = ('database' == $type) ? 'database' : 'tables'; |
||
25 | |||
26 | $script = $this->script; |
||
27 | |||
28 | $data = $this->misc->getDatabaseAccessor(); |
||
29 | |||
30 | if (('table' == $type) && empty($_REQUEST['table']) && empty($_REQUEST['ma'])) { |
||
31 | $this->doDefault($this->lang['strspecifytabletocluster']); |
||
32 | |||
33 | return; |
||
34 | } |
||
35 | |||
36 | if ($confirm) { |
||
37 | if (isset($_REQUEST['ma'])) { |
||
38 | $this->printTrail('schema'); |
||
39 | $this->printTitle($this->lang['strclusterindex'], 'pg.index.cluster'); |
||
40 | |||
41 | echo '<form action="' . \SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
42 | foreach ($_REQUEST['ma'] as $v) { |
||
43 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
44 | echo '<p>', sprintf($this->lang['strconfclustertable'], $this->misc->printVal($a['table'])), "</p>\n"; |
||
45 | echo '<input type="hidden" name="table[]" value="', htmlspecialchars($a['table']), "\" />\n"; |
||
46 | } // END if multi cluster |
||
47 | } else { |
||
48 | $this->printTrail($type); |
||
49 | $this->printTitle($this->lang['strclusterindex'], 'pg.index.cluster'); |
||
50 | |||
51 | echo '<form action="' . \SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
52 | |||
53 | if ('table' == $type) { |
||
54 | echo '<p>', sprintf($this->lang['strconfclustertable'], $this->misc->printVal($_REQUEST['object'])), "</p>\n"; |
||
55 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['object']), "\" />\n"; |
||
56 | } else { |
||
57 | echo '<p>', sprintf($this->lang['strconfclusterdatabase'], $this->misc->printVal($_REQUEST['object'])), "</p>\n"; |
||
58 | echo "<input type=\"hidden\" name=\"table\" value=\"\" />\n"; |
||
59 | } |
||
60 | } |
||
61 | echo "<input type=\"hidden\" name=\"action\" value=\"cluster\" />\n"; |
||
62 | |||
63 | echo $this->misc->form; |
||
64 | |||
65 | echo "<input type=\"submit\" name=\"cluster\" value=\"{$this->lang['strcluster']}\" />\n"; //TODO |
||
66 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />\n"; |
||
67 | echo "</form>\n"; // END single cluster |
||
68 | } else { |
||
69 | $msg = ''; |
||
70 | //If multi table cluster |
||
71 | if ('table' == $type) { |
||
72 | // cluster one or more table |
||
73 | if (is_array($_REQUEST['table'])) { |
||
74 | foreach ($_REQUEST['table'] as $o) { |
||
75 | list($status, $sql) = $data->clusterIndex($o); |
||
76 | $msg .= sprintf('%s<br />', htmlentities($sql, ENT_QUOTES, 'UTF-8')); |
||
77 | if (0 == $status) { |
||
78 | $msg .= sprintf('%s: %s<br />', htmlentities($o, ENT_QUOTES, 'UTF-8'), $this->lang['strclusteredgood']); |
||
79 | } else { |
||
80 | $this->doDefault(sprintf('%s %s%s: %s<br />', $type, $msg, htmlentities($o, ENT_QUOTES, 'UTF-8'), $this->lang['strclusteredbad'])); |
||
81 | |||
82 | return; |
||
83 | } |
||
84 | } |
||
85 | // Everything went fine, back to the Default page.... |
||
86 | $this->doDefault($msg); |
||
87 | } else { |
||
88 | list($status, $sql) = $data->clusterIndex($_REQUEST['object']); |
||
89 | $msg .= sprintf('%s<br />', htmlentities($sql, ENT_QUOTES, 'UTF-8')); |
||
90 | if (0 == $status) { |
||
91 | $this->doAdmin($type, $msg . $this->lang['strclusteredgood']); |
||
92 | } else { |
||
93 | $this->doAdmin($type, $msg . $this->lang['strclusteredbad']); |
||
94 | } |
||
95 | } |
||
96 | } else { |
||
97 | // Cluster all tables in database |
||
98 | list($status, $sql) = $data->clusterIndex(); |
||
99 | $msg .= sprintf('%s<br />', htmlentities($sql, ENT_QUOTES, 'UTF-8')); |
||
100 | if (0 == $status) { |
||
101 | $this->doAdmin($type, $msg . $this->lang['strclusteredgood']); |
||
102 | } else { |
||
103 | $this->doAdmin($type, $msg . $this->lang['strclusteredbad']); |
||
104 | } |
||
105 | } |
||
106 | } |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Show confirmation of reindex and perform reindex. |
||
111 | * |
||
112 | * @param mixed $type |
||
113 | * @param mixed $confirm |
||
114 | */ |
||
115 | public function doReindex($type, $confirm = false) |
||
116 | { |
||
117 | $this->script = ('database' == $type) ? 'database' : 'tables'; |
||
118 | $script = $this->script; |
||
119 | $this->misc = $this->misc; |
||
120 | $data = $this->misc->getDatabaseAccessor(); |
||
121 | |||
122 | if (('table' == $type) && empty($_REQUEST['table']) && empty($_REQUEST['ma'])) { |
||
123 | $this->doDefault($this->lang['strspecifytabletoreindex']); |
||
124 | |||
125 | return; |
||
126 | } |
||
127 | |||
128 | if ($confirm) { |
||
129 | if (isset($_REQUEST['ma'])) { |
||
130 | $this->printTrail('schema'); |
||
131 | $this->printTitle($this->lang['strreindex'], 'pg.reindex'); |
||
132 | |||
133 | echo '<form action="' . \SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
134 | foreach ($_REQUEST['ma'] as $v) { |
||
135 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
136 | echo '<p>', sprintf($this->lang['strconfreindextable'], $this->misc->printVal($a['table'])), "</p>\n"; |
||
137 | echo '<input type="hidden" name="table[]" value="', htmlspecialchars($a['table']), "\" />\n"; |
||
138 | } // END if multi reindex |
||
139 | } else { |
||
140 | $this->printTrail($type); |
||
141 | $this->printTitle($this->lang['strreindex'], 'pg.reindex'); |
||
142 | |||
143 | echo '<form action="' . \SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
144 | |||
145 | if ('table' == $type) { |
||
146 | echo '<p>', sprintf($this->lang['strconfreindextable'], $this->misc->printVal($_REQUEST['object'])), "</p>\n"; |
||
147 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['object']), "\" />\n"; |
||
148 | } else { |
||
149 | echo '<p>', sprintf($this->lang['strconfreindexdatabase'], $this->misc->printVal($_REQUEST['object'])), "</p>\n"; |
||
150 | echo "<input type=\"hidden\" name=\"table\" value=\"\" />\n"; |
||
151 | } |
||
152 | } |
||
153 | echo "<input type=\"hidden\" name=\"action\" value=\"reindex\" />\n"; |
||
154 | |||
155 | if ($data->hasForceReindex()) { |
||
156 | echo "<p><input type=\"checkbox\" id=\"reindex_force\" name=\"reindex_force\" /><label for=\"reindex_force\">{$this->lang['strforce']}</label></p>\n"; |
||
157 | } |
||
158 | |||
159 | echo $this->misc->form; |
||
160 | |||
161 | echo "<input type=\"submit\" name=\"reindex\" value=\"{$this->lang['strreindex']}\" />\n"; //TODO |
||
162 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />\n"; |
||
163 | echo "</form>\n"; // END single reindex |
||
164 | } else { |
||
165 | //If multi table reindex |
||
166 | if (('table' == $type) && is_array($_REQUEST['table'])) { |
||
167 | $msg = ''; |
||
168 | foreach ($_REQUEST['table'] as $o) { |
||
169 | $status = $data->reindex(strtoupper($type), $o, isset($_REQUEST['reindex_force'])); |
||
170 | if (0 == $status) { |
||
171 | $msg .= sprintf('%s: %s<br />', htmlentities($o, ENT_QUOTES, 'UTF-8'), $this->lang['strreindexgood']); |
||
172 | } else { |
||
173 | $this->doDefault(sprintf('%s %s%s: %s<br />', $type, $msg, htmlentities($o, ENT_QUOTES, 'UTF-8'), $this->lang['strreindexbad'])); |
||
174 | |||
175 | return; |
||
176 | } |
||
177 | } |
||
178 | // Everything went fine, back to the Default page.... |
||
179 | $this->misc->setReloadBrowser(true); |
||
180 | $this->doDefault($msg); |
||
181 | } else { |
||
182 | $status = $data->reindex(strtoupper($type), $_REQUEST['object'], isset($_REQUEST['reindex_force'])); |
||
183 | if (0 == $status) { |
||
184 | $this->misc->setReloadBrowser(true); |
||
185 | $this->doAdmin($type, $this->lang['strreindexgood']); |
||
186 | } else { |
||
187 | $this->doAdmin($type, $this->lang['strreindexbad']); |
||
188 | } |
||
189 | } |
||
190 | } |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * Show confirmation of analyze and perform analyze. |
||
195 | * |
||
196 | * @param mixed $type |
||
197 | * @param mixed $confirm |
||
198 | */ |
||
199 | public function doAnalyze($type, $confirm = false) |
||
270 | } |
||
271 | } |
||
272 | } |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * Show confirmation of vacuum and perform actual vacuum. |
||
277 | * |
||
278 | * @param mixed $type |
||
279 | * @param mixed $confirm |
||
280 | */ |
||
281 | public function doVacuum($type, $confirm = false) |
||
282 | { |
||
283 | $script = ('database' == $type) ? 'database' : 'tables'; |
||
284 | |||
285 | $data = $this->misc->getDatabaseAccessor(); |
||
286 | |||
287 | if (('table' == $type) && empty($_REQUEST['table']) && empty($_REQUEST['ma'])) { |
||
288 | $this->doDefault($this->lang['strspecifytabletovacuum']); |
||
289 | |||
290 | return; |
||
291 | } |
||
292 | |||
293 | if ($confirm) { |
||
294 | if (isset($_REQUEST['ma'])) { |
||
295 | $this->printTrail('schema'); |
||
296 | $this->printTitle($this->lang['strvacuum'], 'pg.vacuum'); |
||
297 | |||
298 | echo '<form action="' . \SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
299 | foreach ($_REQUEST['ma'] as $v) { |
||
300 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
301 | echo '<p>', sprintf($this->lang['strconfvacuumtable'], $this->misc->printVal($a['table'])), "</p>\n"; |
||
302 | echo '<input type="hidden" name="table[]" value="', htmlspecialchars($a['table']), "\" />\n"; |
||
303 | } |
||
304 | } else { |
||
305 | // END if multi vacuum |
||
306 | $this->printTrail($type); |
||
307 | $this->printTitle($this->lang['strvacuum'], 'pg.vacuum'); |
||
308 | |||
309 | echo '<form action="' . \SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
310 | |||
311 | if ('table' == $type) { |
||
312 | echo '<p>', sprintf($this->lang['strconfvacuumtable'], $this->misc->printVal($_REQUEST['object'])), "</p>\n"; |
||
313 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['object']), "\" />\n"; |
||
314 | } else { |
||
315 | echo '<p>', sprintf($this->lang['strconfvacuumdatabase'], $this->misc->printVal($_REQUEST['object'])), "</p>\n"; |
||
316 | echo "<input type=\"hidden\" name=\"table\" value=\"\" />\n"; |
||
317 | } |
||
318 | } |
||
319 | echo "<input type=\"hidden\" name=\"action\" value=\"vacuum\" />\n"; |
||
320 | echo $this->misc->form; |
||
321 | echo "<p><input type=\"checkbox\" id=\"vacuum_full\" name=\"vacuum_full\" /> <label for=\"vacuum_full\">{$this->lang['strfull']}</label></p>\n"; |
||
322 | echo "<p><input type=\"checkbox\" id=\"vacuum_analyze\" name=\"vacuum_analyze\" /> <label for=\"vacuum_analyze\">{$this->lang['stranalyze']}</label></p>\n"; |
||
323 | echo "<p><input type=\"checkbox\" id=\"vacuum_freeze\" name=\"vacuum_freeze\" /> <label for=\"vacuum_freeze\">{$this->lang['strfreeze']}</label></p>\n"; |
||
324 | echo "<input type=\"submit\" name=\"vacuum\" value=\"{$this->lang['strvacuum']}\" />\n"; |
||
325 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />\n"; |
||
326 | echo "</form>\n"; // END single vacuum |
||
327 | } else { |
||
328 | //If multi drop |
||
329 | if (is_array($_REQUEST['table'])) { |
||
330 | $msg = ''; |
||
331 | foreach ($_REQUEST['table'] as $t) { |
||
332 | $status = $data->vacuumDB($t, isset($_REQUEST['vacuum_analyze']), isset($_REQUEST['vacuum_full']), isset($_REQUEST['vacuum_freeze'])); |
||
333 | if (0 == $status) { |
||
334 | $msg .= sprintf('%s: %s<br />', htmlentities($t, ENT_QUOTES, 'UTF-8'), $this->lang['strvacuumgood']); |
||
335 | } else { |
||
336 | $this->doDefault(sprintf('%s %s%s: %s<br />', $type, $msg, htmlentities($t, ENT_QUOTES, 'UTF-8'), $this->lang['strvacuumbad'])); |
||
337 | |||
338 | return; |
||
339 | } |
||
340 | } |
||
341 | // Everything went fine, back to the Default page.... |
||
342 | $this->misc->setReloadBrowser(true); |
||
343 | $this->doDefault($msg); |
||
344 | } else { |
||
345 | //we must pass table here. When empty, vacuum the whole db |
||
346 | $status = $data->vacuumDB($_REQUEST['table'], isset($_REQUEST['vacuum_analyze']), isset($_REQUEST['vacuum_full']), isset($_REQUEST['vacuum_freeze'])); |
||
347 | if (0 == $status) { |
||
348 | $this->misc->setReloadBrowser(true); |
||
349 | $this->doAdmin($type, $this->lang['strvacuumgood']); |
||
350 | } else { |
||
351 | $this->doAdmin($type, $this->lang['strvacuumbad']); |
||
352 | } |
||
353 | } |
||
354 | } |
||
355 | } |
||
356 | |||
357 | /** |
||
358 | * Add or Edit autovacuum params and save them. |
||
359 | * |
||
360 | * @param mixed $type |
||
361 | * @param mixed $confirm |
||
362 | * @param mixed $msg |
||
363 | */ |
||
364 | public function doEditAutovacuum($type, $confirm, $msg = '') |
||
477 | } |
||
478 | } |
||
479 | } |
||
480 | |||
481 | /** |
||
482 | * confirm drop autovacuum params for a table and drop it. |
||
1 ignored issue
–
show
|
|||
483 | * |
||
484 | * @param mixed $type |
||
485 | * @param mixed $confirm |
||
486 | */ |
||
487 | public function doDropAutovacuum($type, $confirm) |
||
488 | { |
||
489 | $script = ('database' == $type) ? 'database' : 'tables'; |
||
490 | $data = $this->misc->getDatabaseAccessor(); |
||
491 | |||
492 | if (empty($_REQUEST['table'])) { |
||
493 | $this->doAdmin($type, $this->lang['strspecifydelvacuumtable']); |
||
494 | |||
495 | return; |
||
496 | } |
||
497 | |||
498 | if ($confirm) { |
||
499 | $this->printTrail($type); |
||
500 | $this->printTabs($type, 'admin'); |
||
501 | |||
502 | printf( |
||
503 | "<p>{$this->lang['strdelvacuumtable']}</p>\n", |
||
504 | $this->misc->printVal("\"{$_GET['schema']}\".\"{$_GET['table']}\"") |
||
505 | ); |
||
506 | |||
507 | echo "<form style=\"float: left\" action=\"{$script}\" method=\"post\">\n"; |
||
508 | echo "<input type=\"hidden\" name=\"action\" value=\"delautovac\" />\n"; |
||
509 | echo $this->misc->form; |
||
510 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), "\" />\n"; |
||
511 | echo '<input type="hidden" name="rel" value="', htmlspecialchars(serialize([$_REQUEST['schema'], $_REQUEST['table']])), "\" />\n"; |
||
512 | echo "<input type=\"submit\" name=\"yes\" value=\"{$this->lang['stryes']}\" />\n"; |
||
513 | echo "</form>\n"; |
||
514 | |||
515 | echo '<form action="' . \SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
516 | echo "<input type=\"hidden\" name=\"action\" value=\"admin\" />\n"; |
||
517 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), "\" />\n"; |
||
518 | echo $this->misc->form; |
||
519 | echo "<input type=\"submit\" name=\"no\" value=\"{$this->lang['strno']}\" />\n"; |
||
520 | echo "</form>\n"; |
||
521 | } else { |
||
522 | $status = $data->dropAutovacuum($_POST['table']); |
||
523 | |||
524 | if (0 == $status) { |
||
525 | $this->doAdmin($type, sprintf($this->lang['strvacuumtablereset'], $this->misc->printVal($_POST['table']))); |
||
526 | } else { |
||
527 | $this->doAdmin($type, sprintf($this->lang['strdelvacuumtablefail'], $this->misc->printVal($_POST['table']))); |
||
528 | } |
||
529 | } |
||
530 | } |
||
531 | |||
532 | /** |
||
533 | * database/table administration and tuning tasks. |
||
1 ignored issue
–
show
|
|||
534 | * |
||
535 | * @version $Id: admin |
||
536 | * |
||
537 | * @param mixed $type |
||
1 ignored issue
–
show
|
|||
538 | * @param mixed $msg |
||
539 | */ |
||
540 | public function doAdmin($type, $msg = '') |
||
541 | { |
||
542 | $this->script = ('database' == $type) ? 'database' : 'tables'; |
||
543 | |||
544 | $script = $this->script; |
||
545 | |||
546 | $data = $this->misc->getDatabaseAccessor(); |
||
547 | |||
548 | $this->printTrail($type); |
||
549 | $this->printTabs($type, 'admin'); |
||
550 | $this->printMsg($msg); |
||
551 | |||
552 | if ('database' == $type) { |
||
553 | printf("<p>{$this->lang['stradminondatabase']}</p>\n", $this->misc->printVal($_REQUEST['object'])); |
||
554 | } else { |
||
555 | printf("<p>{$this->lang['stradminontable']}</p>\n", $this->misc->printVal($_REQUEST['object'])); |
||
556 | } |
||
557 | |||
558 | echo "<table style=\"width: 50%\">\n"; |
||
559 | echo "<tr>\n"; |
||
560 | echo '<th class="data">'; |
||
561 | $this->misc->printHelp($this->lang['strvacuum'], 'pg.admin.vacuum') . "</th>\n"; |
||
562 | echo '</th>'; |
||
563 | echo '<th class="data">'; |
||
564 | $this->misc->printHelp($this->lang['stranalyze'], 'pg.admin.analyze'); |
||
565 | echo '</th>'; |
||
566 | if ($data->hasRecluster()) { |
||
567 | echo '<th class="data">'; |
||
568 | $this->misc->printHelp($this->lang['strclusterindex'], 'pg.index.cluster'); |
||
569 | echo '</th>'; |
||
570 | } |
||
571 | echo '<th class="data">'; |
||
572 | $this->misc->printHelp($this->lang['strreindex'], 'pg.index.reindex'); |
||
573 | echo '</th>'; |
||
574 | echo '</tr>'; |
||
575 | |||
576 | // Vacuum |
||
577 | echo "<tr class=\"row1\">\n"; |
||
578 | echo "<td style=\"text-align: center; vertical-align: bottom\">\n"; |
||
579 | echo '<form action="' . \SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
580 | |||
581 | echo "<p><input type=\"hidden\" name=\"action\" value=\"confirm_vacuum\" />\n"; |
||
582 | echo $this->misc->form; |
||
583 | if ('table' == $type) { |
||
584 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['object']), "\" />\n"; |
||
585 | echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n"; |
||
586 | } |
||
587 | echo "<input type=\"submit\" value=\"{$this->lang['strvacuum']}\" /></p>\n"; |
||
588 | echo "</form>\n"; |
||
589 | echo "</td>\n"; |
||
590 | |||
591 | // Analyze |
||
592 | echo "<td style=\"text-align: center; vertical-align: bottom\">\n"; |
||
593 | echo '<form action="' . \SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
594 | echo "<p><input type=\"hidden\" name=\"action\" value=\"confirm_analyze\" />\n"; |
||
595 | echo $this->misc->form; |
||
596 | if ('table' == $type) { |
||
597 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['object']), "\" />\n"; |
||
598 | echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n"; |
||
599 | } |
||
600 | echo "<input type=\"submit\" value=\"{$this->lang['stranalyze']}\" /></p>\n"; |
||
601 | echo "</form>\n"; |
||
602 | echo "</td>\n"; |
||
603 | |||
604 | // Cluster |
||
605 | if ($data->hasRecluster()) { |
||
606 | $disabled = ''; |
||
607 | echo "<td style=\"text-align: center; vertical-align: bottom\">\n"; |
||
608 | echo '<form action="' . \SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
609 | echo $this->misc->form; |
||
610 | if ('table' == $type) { |
||
611 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['object']), "\" />\n"; |
||
612 | echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n"; |
||
613 | if (!$data->alreadyClustered($_REQUEST['object'])) { |
||
614 | $disabled = 'disabled="disabled" '; |
||
615 | echo "{$this->lang['strnoclusteravailable']}<br />"; |
||
616 | } |
||
617 | } |
||
618 | echo "<p><input type=\"hidden\" name=\"action\" value=\"confirm_cluster\" />\n"; |
||
619 | echo "<input type=\"submit\" value=\"{$this->lang['strclusterindex']}\" ${disabled}/></p>\n"; |
||
620 | echo "</form>\n"; |
||
621 | echo "</td>\n"; |
||
622 | } |
||
623 | |||
624 | // Reindex |
||
625 | echo "<td style=\"text-align: center; vertical-align: bottom\">\n"; |
||
626 | echo '<form action="' . \SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
627 | echo "<p><input type=\"hidden\" name=\"action\" value=\"confirm_reindex\" />\n"; |
||
628 | echo $this->misc->form; |
||
629 | if ('table' == $type) { |
||
630 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['object']), "\" />\n"; |
||
631 | echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n"; |
||
632 | } |
||
633 | echo "<input type=\"submit\" value=\"{$this->lang['strreindex']}\" /></p>\n"; |
||
634 | echo "</form>\n"; |
||
635 | echo "</td>\n"; |
||
636 | echo "</tr>\n"; |
||
637 | echo "</table>\n"; |
||
638 | |||
639 | // Autovacuum |
||
640 | if ($data->hasAutovacuum()) { |
||
641 | // get defaults values for autovacuum |
||
642 | $defaults = $data->getAutovacuum(); |
||
643 | // Fetch the autovacuum properties from the database or table if != '' |
||
644 | if ('table' == $type) { |
||
645 | $autovac = $data->getTableAutovacuum($_REQUEST['table']); |
||
646 | } else { |
||
647 | $autovac = $data->getTableAutovacuum(); |
||
648 | } |
||
649 | |||
650 | echo "<br /><br /><h2>{$this->lang['strvacuumpertable']}</h2>"; |
||
651 | echo '<p>' . (('on' == $defaults['autovacuum']) ? $this->lang['strturnedon'] : $this->lang['strturnedoff']) . '</p>'; |
||
652 | echo "<p class=\"message\">{$this->lang['strnotdefaultinred']}</p>"; |
||
653 | |||
654 | $enlight = function ($f, $p) { |
||
655 | if (isset($f[$p[0]]) and ($f[$p[0]] != $p[1])) { |
||
656 | return '<span style="color:#F33;font-weight:bold">' . htmlspecialchars($f[$p[0]]) . '</span>'; |
||
657 | } |
||
658 | |||
659 | return htmlspecialchars($p[1]); |
||
660 | }; |
||
661 | |||
662 | $columns = [ |
||
663 | 'namespace' => [ |
||
664 | 'title' => $this->lang['strschema'], |
||
665 | 'field' => Decorator::field('nspname'), |
||
666 | 'url' => \SUBFOLDER . "/redirect/schema?{$this->misc->href}&", |
||
667 | 'vars' => ['schema' => 'nspname'], |
||
668 | ], |
||
669 | 'relname' => [ |
||
670 | 'title' => $this->lang['strtable'], |
||
671 | 'field' => Decorator::field('relname'), |
||
672 | 'url' => \SUBFOLDER . "/redirect/table?{$this->misc->href}&", |
||
673 | 'vars' => ['table' => 'relname', 'schema' => 'nspname'], |
||
674 | ], |
||
675 | 'autovacuum_enabled' => [ |
||
676 | 'title' => $this->lang['strenabled'], |
||
677 | 'field' => Decorator::callback($enlight, ['autovacuum_enabled', $defaults['autovacuum']]), |
||
678 | 'type' => 'verbatim', |
||
679 | ], |
||
680 | 'autovacuum_vacuum_threshold' => [ |
||
681 | 'title' => $this->lang['strvacuumbasethreshold'], |
||
682 | 'field' => Decorator::callback($enlight, ['autovacuum_vacuum_threshold', $defaults['autovacuum_vacuum_threshold']]), |
||
683 | 'type' => 'verbatim', |
||
684 | ], |
||
685 | 'autovacuum_vacuum_scale_factor' => [ |
||
686 | 'title' => $this->lang['strvacuumscalefactor'], |
||
687 | 'field' => Decorator::callback($enlight, ['autovacuum_vacuum_scale_factor', $defaults['autovacuum_vacuum_scale_factor']]), |
||
688 | 'type' => 'verbatim', |
||
689 | ], |
||
690 | 'autovacuum_analyze_threshold' => [ |
||
691 | 'title' => $this->lang['stranalybasethreshold'], |
||
692 | 'field' => Decorator::callback($enlight, ['autovacuum_analyze_threshold', $defaults['autovacuum_analyze_threshold']]), |
||
693 | 'type' => 'verbatim', |
||
694 | ], |
||
695 | 'autovacuum_analyze_scale_factor' => [ |
||
696 | 'title' => $this->lang['stranalyzescalefactor'], |
||
697 | 'field' => Decorator::callback($enlight, ['autovacuum_analyze_scale_factor', $defaults['autovacuum_analyze_scale_factor']]), |
||
698 | 'type' => 'verbatim', |
||
699 | ], |
||
700 | 'autovacuum_vacuum_cost_delay' => [ |
||
701 | 'title' => $this->lang['strvacuumcostdelay'], |
||
702 | 'field' => Decorator::concat(Decorator::callback($enlight, ['autovacuum_vacuum_cost_delay', $defaults['autovacuum_vacuum_cost_delay']]), 'ms'), |
||
703 | 'type' => 'verbatim', |
||
704 | ], |
||
705 | 'autovacuum_vacuum_cost_limit' => [ |
||
706 | 'title' => $this->lang['strvacuumcostlimit'], |
||
707 | 'field' => Decorator::callback($enlight, ['autovacuum_vacuum_cost_limit', $defaults['autovacuum_vacuum_cost_limit']]), |
||
708 | 'type' => 'verbatim', |
||
709 | ], |
||
710 | ]; |
||
711 | |||
712 | // Maybe we need to check permissions here? |
||
713 | $columns['actions'] = ['title' => $this->lang['stractions']]; |
||
714 | |||
715 | $actions = [ |
||
716 | 'edit' => [ |
||
717 | 'content' => $this->lang['stredit'], |
||
718 | 'attr' => [ |
||
719 | 'href' => [ |
||
720 | 'url' => $script, |
||
721 | 'urlvars' => [ |
||
722 | 'subject' => $type, |
||
723 | 'action' => 'confeditautovac', |
||
724 | 'schema' => Decorator::field('nspname'), |
||
725 | 'table' => Decorator::field('relname'), |
||
726 | ], |
||
727 | ], |
||
728 | ], |
||
729 | ], |
||
730 | 'delete' => [ |
||
731 | 'content' => $this->lang['strdelete'], |
||
732 | 'attr' => [ |
||
733 | 'href' => [ |
||
734 | 'url' => $script, |
||
735 | 'urlvars' => [ |
||
736 | 'subject' => $type, |
||
737 | 'action' => 'confdelautovac', |
||
738 | 'schema' => Decorator::field('nspname'), |
||
739 | 'table' => Decorator::field('relname'), |
||
740 | ], |
||
741 | ], |
||
742 | ], |
||
743 | ], |
||
744 | ]; |
||
745 | |||
746 | if ('table' == $type) { |
||
747 | unset($actions['edit']['vars']['schema'], |
||
1 ignored issue
–
show
|
|||
748 | $actions['delete']['vars']['schema'], |
||
749 | $columns['namespace'], |
||
750 | $columns['relname'] |
||
751 | ); |
||
752 | } |
||
753 | |||
754 | echo $this->printTable($autovac, $columns, $actions, 'admin-admin', $this->lang['strnovacuumconf']); |
||
755 | |||
756 | if (('table' == $type) and (0 == $autovac->recordCount())) { |
||
757 | echo '<br />'; |
||
758 | |||
759 | echo '<a href="' . \SUBFOLDER . "/src/views/tables?action=confeditautovac&{$this->misc->href}&table="; |
||
760 | echo htmlspecialchars($_REQUEST['table']); |
||
761 | echo "\">{$this->lang['straddvacuumtable']}</a>"; |
||
762 | } |
||
763 | } |
||
764 | } |
||
765 | |||
766 | public function adminActions($action, $type) |
||
878 | } |
||
879 | |||
880 | abstract public function doDefault($msg = ''); |
||
881 | |||
882 | abstract public function printTrail($trail = [], $do_print = true); |
||
883 | |||
884 | abstract public function printTitle($title, $help = null, $do_print = true); |
||
885 | |||
886 | abstract public function printMsg($msg, $do_print = true); |
||
887 | |||
888 | abstract public function printTabs($tabs, $activetab, $do_print = true); |
||
889 | |||
890 | abstract public function printTable(&$tabledata, &$columns, &$actions, $place, $nodata = null, $pre_fn = null); |
||
891 | } |
||
892 |