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