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