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