Total Complexity | 126 |
Total Lines | 838 |
Duplicated Lines | 24.58 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
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 |
||
6 | trait AdminTrait |
||
7 | { |
||
8 | |||
9 | /** |
||
10 | * Show confirmation of cluster and perform cluster |
||
11 | */ |
||
12 | public function doCluster($type, $confirm = false) |
||
|
|||
13 | { |
||
14 | $this->script = ($type == 'database') ? 'database.php' : 'tables.php'; |
||
1 ignored issue
–
show
|
|||
15 | |||
16 | $script = $this->script; |
||
17 | $misc = $this->misc; |
||
18 | $lang = $this->lang; |
||
1 ignored issue
–
show
|
|||
19 | $data = $misc->getDatabaseAccessor(); |
||
20 | |||
21 | View Code Duplication | if (($type == 'table') && empty($_REQUEST['table']) && empty($_REQUEST['ma'])) { |
|
22 | $this->doDefault($lang['strspecifytabletocluster']); |
||
23 | return; |
||
24 | } |
||
25 | |||
26 | if ($confirm) { |
||
27 | View Code Duplication | if (isset($_REQUEST['ma'])) { |
|
28 | $this->printTrail('schema'); |
||
29 | $this->printTitle($lang['strclusterindex'], 'pg.index.cluster'); |
||
30 | |||
31 | echo '<form action="' . SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
32 | foreach ($_REQUEST['ma'] as $v) { |
||
33 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
34 | echo '<p>', sprintf($lang['strconfclustertable'], $misc->printVal($a['table'])), "</p>\n"; |
||
35 | echo '<input type="hidden" name="table[]" value="', htmlspecialchars($a['table']), "\" />\n"; |
||
36 | } |
||
37 | } // END if multi cluster |
||
38 | else { |
||
39 | $this->printTrail($type); |
||
40 | $this->printTitle($lang['strclusterindex'], 'pg.index.cluster'); |
||
41 | |||
42 | echo '<form action="' . SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
43 | |||
44 | if ($type == 'table') { |
||
45 | echo '<p>', sprintf($lang['strconfclustertable'], $misc->printVal($_REQUEST['object'])), "</p>\n"; |
||
46 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['object']), "\" />\n"; |
||
47 | } else { |
||
48 | echo '<p>', sprintf($lang['strconfclusterdatabase'], $misc->printVal($_REQUEST['object'])), "</p>\n"; |
||
49 | echo "<input type=\"hidden\" name=\"table\" value=\"\" />\n"; |
||
50 | } |
||
51 | } |
||
52 | echo "<input type=\"hidden\" name=\"action\" value=\"cluster\" />\n"; |
||
53 | |||
54 | echo $misc->form; |
||
55 | |||
56 | echo "<input type=\"submit\" name=\"cluster\" value=\"{$lang['strcluster']}\" />\n"; //TODO |
||
57 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n"; |
||
58 | echo "</form>\n"; |
||
59 | } // END single cluster |
||
60 | else { |
||
61 | //If multi table cluster |
||
62 | if ($type == 'table') { |
||
63 | // cluster one or more table |
||
64 | if (is_array($_REQUEST['table'])) { |
||
65 | $msg = ''; |
||
66 | foreach ($_REQUEST['table'] as $o) { |
||
67 | $status = $data->clusterIndex($o); |
||
68 | if ($status == 0) { |
||
69 | $msg .= sprintf('%s: %s<br />', htmlentities($o, ENT_QUOTES, 'UTF-8'), $lang['strclusteredgood']); |
||
70 | } else { |
||
71 | $this->doDefault($type, sprintf('%s%s: %s<br />', $msg, htmlentities($o, ENT_QUOTES, 'UTF-8'), $lang['strclusteredbad'])); |
||
72 | return; |
||
73 | } |
||
74 | } |
||
75 | // Everything went fine, back to the Default page.... |
||
76 | $this->doDefault($msg); |
||
77 | View Code Duplication | } else { |
|
78 | $status = $data->clusterIndex($_REQUEST['object']); |
||
79 | if ($status == 0) { |
||
80 | $this->doAdmin($type, $lang['strclusteredgood']); |
||
81 | } else { |
||
82 | $this->doAdmin($type, $lang['strclusteredbad']); |
||
83 | } |
||
84 | } |
||
85 | View Code Duplication | } else { |
|
86 | // Cluster all tables in database |
||
87 | $status = $data->clusterIndex(); |
||
88 | if ($status == 0) { |
||
89 | $this->doAdmin($type, $lang['strclusteredgood']); |
||
90 | } else { |
||
91 | $this->doAdmin($type, $lang['strclusteredbad']); |
||
92 | } |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * Show confirmation of reindex and perform reindex |
||
99 | */ |
||
100 | public function doReindex($type, $confirm = false) |
||
101 | { |
||
102 | $this->script = ($type == 'database') ? 'database.php' : 'tables.php'; |
||
1 ignored issue
–
show
|
|||
103 | $script = $this->script; |
||
104 | $misc = $this->misc; |
||
105 | $lang = $this->lang; |
||
1 ignored issue
–
show
|
|||
106 | $data = $misc->getDatabaseAccessor(); |
||
107 | |||
108 | View Code Duplication | if (($type == 'table') && empty($_REQUEST['table']) && empty($_REQUEST['ma'])) { |
|
109 | $this->doDefault($lang['strspecifytabletoreindex']); |
||
110 | return; |
||
111 | } |
||
112 | |||
113 | if ($confirm) { |
||
114 | View Code Duplication | if (isset($_REQUEST['ma'])) { |
|
115 | $this->printTrail('schema'); |
||
116 | $this->printTitle($lang['strreindex'], 'pg.reindex'); |
||
117 | |||
118 | echo '<form action="' . SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
119 | foreach ($_REQUEST['ma'] as $v) { |
||
120 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
121 | echo '<p>', sprintf($lang['strconfreindextable'], $misc->printVal($a['table'])), "</p>\n"; |
||
122 | echo '<input type="hidden" name="table[]" value="', htmlspecialchars($a['table']), "\" />\n"; |
||
123 | } |
||
124 | } // END if multi reindex |
||
125 | else { |
||
126 | $this->printTrail($type); |
||
127 | $this->printTitle($lang['strreindex'], 'pg.reindex'); |
||
128 | |||
129 | echo '<form action="' . SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
130 | |||
131 | if ($type == 'table') { |
||
132 | echo '<p>', sprintf($lang['strconfreindextable'], $misc->printVal($_REQUEST['object'])), "</p>\n"; |
||
133 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['object']), "\" />\n"; |
||
134 | } else { |
||
135 | echo '<p>', sprintf($lang['strconfreindexdatabase'], $misc->printVal($_REQUEST['object'])), "</p>\n"; |
||
136 | echo "<input type=\"hidden\" name=\"table\" value=\"\" />\n"; |
||
137 | } |
||
138 | } |
||
139 | echo "<input type=\"hidden\" name=\"action\" value=\"reindex\" />\n"; |
||
140 | |||
141 | if ($data->hasForceReindex()) { |
||
142 | echo "<p><input type=\"checkbox\" id=\"reindex_force\" name=\"reindex_force\" /><label for=\"reindex_force\">{$lang['strforce']}</label></p>\n"; |
||
143 | } |
||
144 | |||
145 | echo $misc->form; |
||
146 | |||
147 | echo "<input type=\"submit\" name=\"reindex\" value=\"{$lang['strreindex']}\" />\n"; //TODO |
||
148 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n"; |
||
149 | echo "</form>\n"; |
||
150 | } // END single reindex |
||
151 | else { |
||
152 | //If multi table reindex |
||
153 | if (($type == 'table') && is_array($_REQUEST['table'])) { |
||
154 | $msg = ''; |
||
155 | foreach ($_REQUEST['table'] as $o) { |
||
156 | $status = $data->reindex(strtoupper($type), $o, isset($_REQUEST['reindex_force'])); |
||
157 | if ($status == 0) { |
||
158 | $msg .= sprintf('%s: %s<br />', htmlentities($o, ENT_QUOTES, 'UTF-8'), $lang['strreindexgood']); |
||
159 | } else { |
||
160 | $this->doDefault($type, sprintf('%s%s: %s<br />', $msg, htmlentities($o, ENT_QUOTES, 'UTF-8'), $lang['strreindexbad'])); |
||
161 | return; |
||
162 | } |
||
163 | } |
||
164 | // Everything went fine, back to the Default page.... |
||
165 | $misc->setReloadBrowser(true); |
||
166 | $this->doDefault($msg); |
||
167 | } else { |
||
168 | $status = $data->reindex(strtoupper($type), $_REQUEST['object'], isset($_REQUEST['reindex_force'])); |
||
169 | View Code Duplication | if ($status == 0) { |
|
170 | $misc->setReloadBrowser(true); |
||
171 | $this->doAdmin($type, $lang['strreindexgood']); |
||
172 | } else { |
||
173 | $this->doAdmin($type, $lang['strreindexbad']); |
||
174 | } |
||
175 | } |
||
176 | } |
||
177 | } |
||
178 | |||
179 | /** |
||
180 | * Show confirmation of analyze and perform analyze |
||
181 | */ |
||
182 | public function doAnalyze($type, $confirm = false) |
||
254 | } |
||
255 | } |
||
256 | } |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * Show confirmation of vacuum and perform actual vacuum |
||
261 | */ |
||
262 | public function doVacuum($type, $confirm = false) |
||
334 | } |
||
335 | } |
||
336 | } |
||
337 | } |
||
338 | |||
339 | /** |
||
340 | * Add or Edit autovacuum params and save them |
||
341 | */ |
||
342 | public function doEditAutovacuum($type, $confirm, $msg = '') |
||
343 | { |
||
344 | $this->script = ($type == 'database') ? 'database.php' : 'tables.php'; |
||
1 ignored issue
–
show
|
|||
345 | $script = $this->script; |
||
346 | |||
347 | $misc = $this->misc; |
||
348 | $lang = $this->lang; |
||
1 ignored issue
–
show
|
|||
349 | $data = $misc->getDatabaseAccessor(); |
||
350 | |||
351 | if (empty($_REQUEST['table'])) { |
||
352 | $this->doAdmin($type, '', $lang['strspecifyeditvacuumtable']); |
||
353 | return; |
||
354 | } |
||
355 | |||
356 | $script = ($type == 'database') ? 'database.php' : 'tables.php'; |
||
357 | |||
358 | if ($confirm) { |
||
359 | $this->printTrail($type); |
||
360 | $this->printTitle(sprintf($lang['streditvacuumtable'], $misc->printVal($_REQUEST['table']))); |
||
361 | $this->printMsg(sprintf($msg, $misc->printVal($_REQUEST['table']))); |
||
362 | |||
363 | if (empty($_REQUEST['table'])) { |
||
364 | $this->doAdmin($type, '', $lang['strspecifyeditvacuumtable']); |
||
365 | return; |
||
366 | } |
||
367 | |||
368 | $old_val = $data->getTableAutovacuum($_REQUEST['table']); |
||
369 | $defaults = $data->getAutovacuum(); |
||
370 | $old_val = $old_val->fields; |
||
371 | |||
372 | if (isset($old_val['autovacuum_enabled']) and ($old_val['autovacuum_enabled'] == 'off')) { |
||
373 | $enabled = ''; |
||
374 | $disabled = 'checked="checked"'; |
||
375 | } else { |
||
376 | $enabled = 'checked="checked"'; |
||
377 | $disabled = ''; |
||
378 | } |
||
379 | |||
380 | if (!isset($old_val['autovacuum_vacuum_threshold'])) { |
||
381 | $old_val['autovacuum_vacuum_threshold'] = ''; |
||
382 | } |
||
383 | |||
384 | if (!isset($old_val['autovacuum_vacuum_scale_factor'])) { |
||
385 | $old_val['autovacuum_vacuum_scale_factor'] = ''; |
||
386 | } |
||
387 | |||
388 | if (!isset($old_val['autovacuum_analyze_threshold'])) { |
||
389 | $old_val['autovacuum_analyze_threshold'] = ''; |
||
390 | } |
||
391 | |||
392 | if (!isset($old_val['autovacuum_analyze_scale_factor'])) { |
||
393 | $old_val['autovacuum_analyze_scale_factor'] = ''; |
||
394 | } |
||
395 | |||
396 | if (!isset($old_val['autovacuum_vacuum_cost_delay'])) { |
||
397 | $old_val['autovacuum_vacuum_cost_delay'] = ''; |
||
398 | } |
||
399 | |||
400 | if (!isset($old_val['autovacuum_vacuum_cost_limit'])) { |
||
401 | $old_val['autovacuum_vacuum_cost_limit'] = ''; |
||
402 | } |
||
403 | |||
404 | echo '<form action="' . SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
405 | echo $misc->form; |
||
406 | echo "<input type=\"hidden\" name=\"action\" value=\"editautovac\" />\n"; |
||
407 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), "\" />\n"; |
||
408 | |||
409 | echo "<br />\n<br />\n<table>\n"; |
||
410 | echo "\t<tr><td> </td>\n"; |
||
411 | echo "<th class=\"data\">{$lang['strnewvalues']}</th><th class=\"data\">{$lang['strdefaultvalues']}</th></tr>\n"; |
||
412 | echo "\t<tr><th class=\"data left\">{$lang['strenable']}</th>\n"; |
||
413 | echo "<td class=\"data1\">\n"; |
||
414 | echo "<label for=\"on\">on</label><input type=\"radio\" name=\"autovacuum_enabled\" id=\"on\" value=\"on\" {$enabled} />\n"; |
||
415 | echo "<label for=\"off\">off</label><input type=\"radio\" name=\"autovacuum_enabled\" id=\"off\" value=\"off\" {$disabled} /></td>\n"; |
||
416 | echo "<th class=\"data left\">{$defaults['autovacuum']}</th></tr>\n"; |
||
417 | echo "\t<tr><th class=\"data left\">{$lang['strvacuumbasethreshold']}</th>\n"; |
||
418 | echo "<td class=\"data1\"><input type=\"text\" name=\"autovacuum_vacuum_threshold\" value=\"{$old_val['autovacuum_vacuum_threshold']}\" /></td>\n"; |
||
419 | echo "<th class=\"data left\">{$defaults['autovacuum_vacuum_threshold']}</th></tr>\n"; |
||
420 | echo "\t<tr><th class=\"data left\">{$lang['strvacuumscalefactor']}</th>\n"; |
||
421 | echo "<td class=\"data1\"><input type=\"text\" name=\"autovacuum_vacuum_scale_factor\" value=\"{$old_val['autovacuum_vacuum_scale_factor']}\" /></td>\n"; |
||
422 | echo "<th class=\"data left\">{$defaults['autovacuum_vacuum_scale_factor']}</th></tr>\n"; |
||
423 | echo "\t<tr><th class=\"data left\">{$lang['stranalybasethreshold']}</th>\n"; |
||
424 | echo "<td class=\"data1\"><input type=\"text\" name=\"autovacuum_analyze_threshold\" value=\"{$old_val['autovacuum_analyze_threshold']}\" /></td>\n"; |
||
425 | echo "<th class=\"data left\">{$defaults['autovacuum_analyze_threshold']}</th></tr>\n"; |
||
426 | echo "\t<tr><th class=\"data left\">{$lang['stranalyzescalefactor']}</th>\n"; |
||
427 | echo "<td class=\"data1\"><input type=\"text\" name=\"autovacuum_analyze_scale_factor\" value=\"{$old_val['autovacuum_analyze_scale_factor']}\" /></td>\n"; |
||
428 | echo "<th class=\"data left\">{$defaults['autovacuum_analyze_scale_factor']}</th></tr>\n"; |
||
429 | echo "\t<tr><th class=\"data left\">{$lang['strvacuumcostdelay']}</th>\n"; |
||
430 | echo "<td class=\"data1\"><input type=\"text\" name=\"autovacuum_vacuum_cost_delay\" value=\"{$old_val['autovacuum_vacuum_cost_delay']}\" /></td>\n"; |
||
431 | echo "<th class=\"data left\">{$defaults['autovacuum_vacuum_cost_delay']}</th></tr>\n"; |
||
432 | echo "\t<tr><th class=\"data left\">{$lang['strvacuumcostlimit']}</th>\n"; |
||
433 | echo "<td class=\"datat1\"><input type=\"text\" name=\"autovacuum_vacuum_cost_limit\" value=\"{$old_val['autovacuum_vacuum_cost_limit']}\" /></td>\n"; |
||
434 | echo "<th class=\"data left\">{$defaults['autovacuum_vacuum_cost_limit']}</th></tr>\n"; |
||
435 | echo "</table>\n"; |
||
436 | echo '<br />'; |
||
437 | echo '<br />'; |
||
438 | echo "<input type=\"submit\" name=\"save\" value=\"{$lang['strsave']}\" />\n"; |
||
439 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
440 | |||
441 | echo "</form>\n"; |
||
442 | } else { |
||
443 | $status = $data->saveAutovacuum($_REQUEST['table'], $_POST['autovacuum_enabled'], $_POST['autovacuum_vacuum_threshold'], |
||
444 | $_POST['autovacuum_vacuum_scale_factor'], $_POST['autovacuum_analyze_threshold'], $_POST['autovacuum_analyze_scale_factor'], |
||
445 | $_POST['autovacuum_vacuum_cost_delay'], $_POST['autovacuum_vacuum_cost_limit']); |
||
446 | |||
447 | if ($status == 0) { |
||
448 | $this->doAdmin($type, '', sprintf($lang['strsetvacuumtablesaved'], $_REQUEST['table'])); |
||
449 | } else { |
||
450 | $this->doEditAutovacuum($type, true, $lang['strsetvacuumtablefail']); |
||
451 | } |
||
452 | } |
||
453 | } |
||
454 | |||
455 | /** |
||
456 | * confirm drop autovacuum params for a table and drop it |
||
457 | */ |
||
458 | public function doDropAutovacuum($type, $confirm) |
||
459 | { |
||
460 | $this->script = ($type == 'database') ? 'database.php' : 'tables.php'; |
||
1 ignored issue
–
show
|
|||
461 | $script = $this->script; |
||
462 | |||
463 | $misc = $this->misc; |
||
464 | $lang = $this->lang; |
||
1 ignored issue
–
show
|
|||
465 | $data = $misc->getDatabaseAccessor(); |
||
466 | |||
467 | if (empty($_REQUEST['table'])) { |
||
468 | $this->doAdmin($type, '', $lang['strspecifydelvacuumtable']); |
||
469 | return; |
||
470 | } |
||
471 | |||
472 | if ($confirm) { |
||
473 | $this->printTrail($type); |
||
474 | $this->printTabs($type, 'admin'); |
||
475 | |||
476 | $script = ($type == 'database') ? 'database.php' : 'tables.php'; |
||
477 | |||
478 | printf("<p>{$lang['strdelvacuumtable']}</p>\n", |
||
479 | $misc->printVal("\"{$_GET['schema']}\".\"{$_GET['table']}\"")); |
||
480 | |||
481 | echo "<form style=\"float: left\" action=\"{$script}\" method=\"post\">\n"; |
||
482 | echo "<input type=\"hidden\" name=\"action\" value=\"delautovac\" />\n"; |
||
483 | echo $misc->form; |
||
484 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), "\" />\n"; |
||
485 | echo '<input type="hidden" name="rel" value="', htmlspecialchars(serialize([$_REQUEST['schema'], $_REQUEST['table']])), "\" />\n"; |
||
486 | echo "<input type=\"submit\" name=\"yes\" value=\"{$lang['stryes']}\" />\n"; |
||
487 | echo "</form>\n"; |
||
488 | |||
489 | echo '<form action="' . SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
490 | echo "<input type=\"hidden\" name=\"action\" value=\"admin\" />\n"; |
||
491 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), "\" />\n"; |
||
492 | echo $misc->form; |
||
493 | echo "<input type=\"submit\" name=\"no\" value=\"{$lang['strno']}\" />\n"; |
||
494 | echo "</form>\n"; |
||
495 | } else { |
||
496 | $status = $data->dropAutovacuum($_POST['table']); |
||
497 | |||
498 | if ($status == 0) { |
||
499 | $this->doAdmin($type, '', sprintf($lang['strvacuumtablereset'], $misc->printVal($_POST['table']))); |
||
500 | } else { |
||
501 | $this->doAdmin($type, '', sprintf($lang['strdelvacuumtablefail'], $misc->printVal($_POST['table']))); |
||
502 | } |
||
503 | } |
||
504 | } |
||
505 | |||
506 | /** |
||
507 | * database/table administration and tuning tasks |
||
508 | * |
||
509 | * $Id: admin.php |
||
510 | */ |
||
511 | |||
512 | public function doAdmin($type, $msg = '') |
||
513 | { |
||
514 | $this->script = ($type == 'database') ? 'database.php' : 'tables.php'; |
||
1 ignored issue
–
show
|
|||
515 | |||
516 | $script = $this->script; |
||
517 | |||
518 | $misc = $this->misc; |
||
519 | $lang = $this->lang; |
||
1 ignored issue
–
show
|
|||
520 | |||
521 | $data = $misc->getDatabaseAccessor(); |
||
522 | |||
523 | $this->printTrail($type); |
||
524 | $this->printTabs($type, 'admin'); |
||
525 | $this->printMsg($msg); |
||
526 | |||
527 | if ($type == 'database') { |
||
528 | printf("<p>{$lang['stradminondatabase']}</p>\n", $misc->printVal($_REQUEST['object'])); |
||
529 | } else { |
||
530 | printf("<p>{$lang['stradminontable']}</p>\n", $misc->printVal($_REQUEST['object'])); |
||
531 | } |
||
532 | |||
533 | echo "<table style=\"width: 50%\">\n"; |
||
534 | echo "<tr>\n"; |
||
535 | echo '<th class="data">'; |
||
536 | $this->misc->printHelp($lang['strvacuum'], 'pg.admin.vacuum') . "</th>\n"; |
||
537 | echo '</th>'; |
||
538 | echo '<th class="data">'; |
||
539 | $this->misc->printHelp($lang['stranalyze'], 'pg.admin.analyze'); |
||
540 | echo '</th>'; |
||
541 | if ($data->hasRecluster()) { |
||
542 | echo '<th class="data">'; |
||
543 | $this->misc->printHelp($lang['strclusterindex'], 'pg.index.cluster'); |
||
544 | echo '</th>'; |
||
545 | } |
||
546 | echo '<th class="data">'; |
||
547 | $this->misc->printHelp($lang['strreindex'], 'pg.index.reindex'); |
||
548 | echo '</th>'; |
||
549 | echo '</tr>'; |
||
550 | |||
551 | // Vacuum |
||
552 | echo "<tr class=\"row1\">\n"; |
||
553 | echo "<td style=\"text-align: center; vertical-align: bottom\">\n"; |
||
554 | echo '<form action="' . SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
555 | |||
556 | echo "<p><input type=\"hidden\" name=\"action\" value=\"confirm_vacuum\" />\n"; |
||
557 | echo $misc->form; |
||
558 | if ($type == 'table') { |
||
559 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['object']), "\" />\n"; |
||
560 | echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n"; |
||
561 | } |
||
562 | echo "<input type=\"submit\" value=\"{$lang['strvacuum']}\" /></p>\n"; |
||
563 | echo "</form>\n"; |
||
564 | echo "</td>\n"; |
||
565 | |||
566 | // Analyze |
||
567 | echo "<td style=\"text-align: center; vertical-align: bottom\">\n"; |
||
568 | echo '<form action="' . SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
569 | echo "<p><input type=\"hidden\" name=\"action\" value=\"confirm_analyze\" />\n"; |
||
570 | echo $misc->form; |
||
571 | if ($type == 'table') { |
||
572 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['object']), "\" />\n"; |
||
573 | echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n"; |
||
574 | } |
||
575 | echo "<input type=\"submit\" value=\"{$lang['stranalyze']}\" /></p>\n"; |
||
576 | echo "</form>\n"; |
||
577 | echo "</td>\n"; |
||
578 | |||
579 | // Cluster |
||
580 | if ($data->hasRecluster()) { |
||
581 | $disabled = ''; |
||
582 | echo "<td style=\"text-align: center; vertical-align: bottom\">\n"; |
||
583 | echo '<form action="' . SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
584 | echo $misc->form; |
||
585 | if ($type == 'table') { |
||
586 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['object']), "\" />\n"; |
||
587 | echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n"; |
||
588 | if (!$data->alreadyClustered($_REQUEST['object'])) { |
||
589 | $disabled = 'disabled="disabled" '; |
||
590 | echo "{$lang['strnoclusteravailable']}<br />"; |
||
591 | } |
||
592 | } |
||
593 | echo "<p><input type=\"hidden\" name=\"action\" value=\"confirm_cluster\" />\n"; |
||
594 | echo "<input type=\"submit\" value=\"{$lang['strclusterindex']}\" $disabled/></p>\n"; |
||
595 | echo "</form>\n"; |
||
596 | echo "</td>\n"; |
||
597 | } |
||
598 | |||
599 | // Reindex |
||
600 | echo "<td style=\"text-align: center; vertical-align: bottom\">\n"; |
||
601 | echo '<form action="' . SUBFOLDER . "/src/views/{$script}\" method=\"post\">\n"; |
||
602 | echo "<p><input type=\"hidden\" name=\"action\" value=\"confirm_reindex\" />\n"; |
||
603 | echo $misc->form; |
||
604 | if ($type == 'table') { |
||
605 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['object']), "\" />\n"; |
||
606 | echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n"; |
||
607 | } |
||
608 | echo "<input type=\"submit\" value=\"{$lang['strreindex']}\" /></p>\n"; |
||
609 | echo "</form>\n"; |
||
610 | echo "</td>\n"; |
||
611 | echo "</tr>\n"; |
||
612 | echo "</table>\n"; |
||
613 | |||
614 | // Autovacuum |
||
615 | if ($data->hasAutovacuum()) { |
||
616 | // get defaults values for autovacuum |
||
617 | $defaults = $data->getAutovacuum(); |
||
618 | // Fetch the autovacuum properties from the database or table if != '' |
||
619 | if ($type == 'table') { |
||
620 | $autovac = $data->getTableAutovacuum($_REQUEST['table']); |
||
621 | } else { |
||
622 | $autovac = $data->getTableAutovacuum(); |
||
623 | } |
||
624 | |||
625 | echo "<br /><br /><h2>{$lang['strvacuumpertable']}</h2>"; |
||
626 | echo '<p>' . (($defaults['autovacuum'] == 'on') ? $lang['strturnedon'] : $lang['strturnedoff']) . '</p>'; |
||
627 | echo "<p class=\"message\">{$lang['strnotdefaultinred']}</p>"; |
||
628 | |||
629 | $enlight = function ($f, $p) { |
||
630 | if (isset($f[$p[0]]) and ($f[$p[0]] != $p[1])) { |
||
631 | return '<span style="color:#F33;font-weight:bold">' . htmlspecialchars($f[$p[0]]) . '</span>'; |
||
632 | } |
||
633 | |||
634 | return htmlspecialchars($p[1]); |
||
635 | }; |
||
636 | |||
637 | $columns = [ |
||
638 | 'namespace' => [ |
||
639 | 'title' => $lang['strschema'], |
||
640 | 'field' => Decorator::field('nspname'), |
||
641 | 'url' => SUBFOLDER . "/redirect/schema?{$misc->href}&", |
||
642 | 'vars' => ['schema' => 'nspname'], |
||
643 | ], |
||
644 | 'relname' => [ |
||
645 | 'title' => $lang['strtable'], |
||
646 | 'field' => Decorator::field('relname'), |
||
647 | 'url' => SUBFOLDER . "/redirect/table?{$misc->href}&", |
||
648 | 'vars' => ['table' => 'relname', 'schema' => 'nspname'], |
||
649 | ], |
||
650 | 'autovacuum_enabled' => [ |
||
651 | 'title' => $lang['strenabled'], |
||
652 | 'field' => Decorator::callback($enlight, ['autovacuum_enabled', $defaults['autovacuum']]), |
||
653 | 'type' => 'verbatim', |
||
654 | ], |
||
655 | 'autovacuum_vacuum_threshold' => [ |
||
656 | 'title' => $lang['strvacuumbasethreshold'], |
||
657 | 'field' => Decorator::callback($enlight, ['autovacuum_vacuum_threshold', $defaults['autovacuum_vacuum_threshold']]), |
||
658 | 'type' => 'verbatim', |
||
659 | ], |
||
660 | 'autovacuum_vacuum_scale_factor' => [ |
||
661 | 'title' => $lang['strvacuumscalefactor'], |
||
662 | 'field' => Decorator::callback($enlight, ['autovacuum_vacuum_scale_factor', $defaults['autovacuum_vacuum_scale_factor']]), |
||
663 | 'type' => 'verbatim', |
||
664 | ], |
||
665 | 'autovacuum_analyze_threshold' => [ |
||
666 | 'title' => $lang['stranalybasethreshold'], |
||
667 | 'field' => Decorator::callback($enlight, ['autovacuum_analyze_threshold', $defaults['autovacuum_analyze_threshold']]), |
||
668 | 'type' => 'verbatim', |
||
669 | ], |
||
670 | 'autovacuum_analyze_scale_factor' => [ |
||
671 | 'title' => $lang['stranalyzescalefactor'], |
||
672 | 'field' => Decorator::callback($enlight, ['autovacuum_analyze_scale_factor', $defaults['autovacuum_analyze_scale_factor']]), |
||
673 | 'type' => 'verbatim', |
||
674 | ], |
||
675 | 'autovacuum_vacuum_cost_delay' => [ |
||
676 | 'title' => $lang['strvacuumcostdelay'], |
||
677 | 'field' => Decorator::concat(Decorator::callback($enlight, ['autovacuum_vacuum_cost_delay', $defaults['autovacuum_vacuum_cost_delay']]), 'ms'), |
||
678 | 'type' => 'verbatim', |
||
679 | ], |
||
680 | 'autovacuum_vacuum_cost_limit' => [ |
||
681 | 'title' => $lang['strvacuumcostlimit'], |
||
682 | 'field' => Decorator::callback($enlight, ['autovacuum_vacuum_cost_limit', $defaults['autovacuum_vacuum_cost_limit']]), |
||
683 | 'type' => 'verbatim', |
||
684 | ], |
||
685 | ]; |
||
686 | |||
687 | // Maybe we need to check permissions here? |
||
688 | $columns['actions'] = ['title' => $lang['stractions']]; |
||
689 | |||
690 | $actions = [ |
||
691 | 'edit' => [ |
||
692 | 'content' => $lang['stredit'], |
||
693 | 'attr' => [ |
||
694 | 'href' => [ |
||
695 | 'url' => $script, |
||
696 | 'urlvars' => [ |
||
697 | 'subject' => $type, |
||
698 | 'action' => 'confeditautovac', |
||
699 | 'schema' => Decorator::field('nspname'), |
||
700 | 'table' => Decorator::field('relname'), |
||
701 | ], |
||
702 | ], |
||
703 | ], |
||
704 | ], |
||
705 | 'delete' => [ |
||
706 | 'content' => $lang['strdelete'], |
||
707 | 'attr' => [ |
||
708 | 'href' => [ |
||
709 | 'url' => $script, |
||
710 | 'urlvars' => [ |
||
711 | 'subject' => $type, |
||
712 | 'action' => 'confdelautovac', |
||
713 | 'schema' => Decorator::field('nspname'), |
||
714 | 'table' => Decorator::field('relname'), |
||
715 | ], |
||
716 | ], |
||
717 | ], |
||
718 | ], |
||
719 | ]; |
||
720 | |||
721 | if ($type == 'table') { |
||
722 | unset($actions['edit']['vars']['schema'], |
||
723 | $actions['delete']['vars']['schema'], |
||
724 | $columns['namespace'], |
||
725 | $columns['relname'] |
||
726 | ); |
||
727 | } |
||
728 | |||
729 | echo $this->printTable($autovac, $columns, $actions, 'admin-admin', $lang['strnovacuumconf']); |
||
730 | |||
731 | if (($type == 'table') and ($autovac->recordCount() == 0)) { |
||
732 | echo '<br />'; |
||
733 | echo "<a href=\"tables.php?action=confeditautovac&{$misc->href}&table=", htmlspecialchars($_REQUEST['table']) |
||
734 | , "\">{$lang['straddvacuumtable']}</a>"; |
||
735 | } |
||
736 | } |
||
737 | } |
||
738 | |||
739 | public function adminActions($action, $type) |
||
844 | } |
||
845 | } |
||
846 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: