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