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