| Total Complexity | 82 |
| Total Lines | 792 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 2 | Features | 0 |
Complex classes like DatabaseController 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 DatabaseController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class DatabaseController extends BaseController |
||
| 15 | { |
||
| 16 | use \PHPPgAdmin\Traits\AdminTrait; |
||
|
|
|||
| 17 | use \PHPPgAdmin\Traits\ExportTrait; |
||
| 18 | |||
| 19 | public $table_place = 'database-variables'; |
||
| 20 | |||
| 21 | public $fields; |
||
| 22 | |||
| 23 | public $controller_title = 'strdatabase'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Default method to render the controller according to the action parameter. |
||
| 27 | */ |
||
| 28 | public function render() |
||
| 29 | { |
||
| 30 | if ('tree' === $this->action) { |
||
| 31 | return $this->doTree(); |
||
| 32 | } |
||
| 33 | |||
| 34 | if ('refresh_locks' === $this->action) { |
||
| 35 | return $this->currentLocks(true); |
||
| 36 | } |
||
| 37 | |||
| 38 | if ('refresh_processes' === $this->action) { |
||
| 39 | return $this->currentProcesses(true); |
||
| 40 | } |
||
| 41 | $scripts = ''; |
||
| 42 | // normal flow |
||
| 43 | if ('locks' === $this->action || 'processes' === $this->action) { |
||
| 44 | $scripts .= '<script src="' . \containerInstance()->subFolder . '/assets/js/database.js" type="text/javascript"></script>'; |
||
| 45 | |||
| 46 | $refreshTime = $this->conf['ajax_refresh'] * 1500; |
||
| 47 | |||
| 48 | $scripts .= '<script type="text/javascript">' . \PHP_EOL; |
||
| 49 | $scripts .= "var Database = {\n"; |
||
| 50 | $scripts .= "ajax_time_refresh: {$refreshTime},\n"; |
||
| 51 | $scripts .= "str_start: {text:'{$this->lang['strstart']}',icon: '" . $this->view->icon('Execute') . "'},\n"; |
||
| 52 | $scripts .= "str_stop: {text:'{$this->lang['strstop']}',icon: '" . $this->view->icon('Stop') . "'},\n"; |
||
| 53 | $scripts .= "load_icon: '" . $this->view->icon('Loading') . "',\n"; |
||
| 54 | $scripts .= "server:'{$_REQUEST['server']}',\n"; |
||
| 55 | $scripts .= "dbname:'{$_REQUEST['database']}',\n"; |
||
| 56 | $scripts .= "action:'refresh_{$this->action}',\n"; |
||
| 57 | $scripts .= "errmsg: '" . \str_replace("'", "\\'", $this->lang['strconnectionfail']) . "'\n"; |
||
| 58 | $scripts .= "};\n"; |
||
| 59 | $scripts .= '</script>' . \PHP_EOL; |
||
| 60 | } |
||
| 61 | |||
| 62 | $header_template = 'header.twig'; |
||
| 63 | $footer_template = 'footer.twig'; |
||
| 64 | // @todo convert all these methods to return text instead of print text |
||
| 65 | \ob_start(); |
||
| 66 | |||
| 67 | switch ($this->action) { |
||
| 68 | case 'find': |
||
| 69 | if (isset($_REQUEST['term'])) { |
||
| 70 | $this->printFindForm(false); |
||
| 71 | } else { |
||
| 72 | $this->printFindForm(true); |
||
| 73 | } |
||
| 74 | |||
| 75 | break; |
||
| 76 | case 'sql': |
||
| 77 | $this->doSQL(); |
||
| 78 | $header_template = 'header_sqledit.twig'; |
||
| 79 | $footer_template = 'footer_sqledit.twig'; |
||
| 80 | |||
| 81 | break; |
||
| 82 | case 'variables': |
||
| 83 | $this->doVariables(); |
||
| 84 | |||
| 85 | break; |
||
| 86 | case 'processes': |
||
| 87 | $this->doProcesses(); |
||
| 88 | |||
| 89 | break; |
||
| 90 | case 'locks': |
||
| 91 | $this->doLocks(); |
||
| 92 | |||
| 93 | break; |
||
| 94 | case 'export': |
||
| 95 | $this->doExport(); |
||
| 96 | |||
| 97 | break; |
||
| 98 | case 'signal': |
||
| 99 | $this->doSignal(); |
||
| 100 | |||
| 101 | break; |
||
| 102 | |||
| 103 | default: |
||
| 104 | if (false === $this->adminActions($this->action, 'database')) { |
||
| 105 | $header_template = 'header_sqledit.twig'; |
||
| 106 | $footer_template = 'footer_sqledit.twig'; |
||
| 107 | $this->doSQL(); |
||
| 108 | } |
||
| 109 | |||
| 110 | break; |
||
| 111 | } |
||
| 112 | $output = \ob_get_clean(); |
||
| 113 | |||
| 114 | $this->printHeader($this->headerTitle(), $scripts, true, $header_template); |
||
| 115 | $this->printBody(); |
||
| 116 | |||
| 117 | echo $output; |
||
| 118 | |||
| 119 | $this->printFooter(true, $footer_template); |
||
| 120 | } |
||
| 121 | |||
| 122 | public function doTree($print = true) |
||
| 123 | { |
||
| 124 | $reqvars = $this->misc->getRequestVars('database'); |
||
| 125 | $tabs = $this->misc->getNavTabs('database'); |
||
| 126 | $items = $this->adjustTabsForTree($tabs); |
||
| 127 | |||
| 128 | $attrs = [ |
||
| 129 | 'text' => Decorator::field('title'), |
||
| 130 | 'icon' => Decorator::field('icon'), |
||
| 131 | 'action' => Decorator::actionurl( |
||
| 132 | Decorator::field('url'), |
||
| 133 | $reqvars, |
||
| 134 | Decorator::field('urlvars'), |
||
| 135 | [ |
||
| 136 | 'database' => $this->misc->getDatabase(), |
||
| 137 | ] |
||
| 138 | ), |
||
| 139 | 'branch' => Decorator::branchurl( |
||
| 140 | Decorator::field('url'), |
||
| 141 | $reqvars, |
||
| 142 | Decorator::field('urlvars'), |
||
| 143 | [ |
||
| 144 | 'action' => 'tree', |
||
| 145 | 'database' => $this->misc->getDatabase(), |
||
| 146 | ] |
||
| 147 | ), |
||
| 148 | ]; |
||
| 149 | |||
| 150 | return $this->printTree($items, $attrs, 'database', $print); |
||
| 151 | } |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Sends a signal to a process. |
||
| 155 | */ |
||
| 156 | public function doSignal(): void |
||
| 157 | { |
||
| 158 | $data = $this->misc->getDatabaseAccessor(); |
||
| 159 | |||
| 160 | $status = $data->sendSignal($_REQUEST['pid'], $_REQUEST['signal']); |
||
| 161 | |||
| 162 | if (0 === $status) { |
||
| 163 | $this->doProcesses($this->lang['strsignalsent']); |
||
| 164 | } else { |
||
| 165 | $this->doProcesses($this->lang['strsignalsentbad']); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Searches for a named database object. |
||
| 171 | * |
||
| 172 | * @param mixed $confirm |
||
| 173 | * @param mixed $msg |
||
| 174 | */ |
||
| 175 | public function printFindForm($confirm = true, $msg = '') |
||
| 176 | { |
||
| 177 | $data = $this->misc->getDatabaseAccessor(); |
||
| 178 | |||
| 179 | $this->coalesceArr($_REQUEST, 'term', ''); |
||
| 180 | |||
| 181 | $this->coalesceArr($_REQUEST, 'filter', ''); |
||
| 182 | |||
| 183 | $this->printTrail('database'); |
||
| 184 | $this->printTabs('database', 'find'); |
||
| 185 | $this->printMsg($msg); |
||
| 186 | |||
| 187 | echo '<form action="' . \containerInstance()->subFolder . '/src/views/database" method="post">' . \PHP_EOL; |
||
| 188 | echo '<p><input name="term" value="', \htmlspecialchars($_REQUEST['term']), |
||
| 189 | "\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" />" . \PHP_EOL; |
||
| 190 | // Output list of filters. This is complex due to all the 'has' and 'conf' feature possibilities |
||
| 191 | echo '<select name="filter">' . \PHP_EOL; |
||
| 192 | |||
| 193 | echo $this->_printTypeOption(''); |
||
| 194 | echo $this->_printTypeOption('COLUMN'); |
||
| 195 | echo $this->_printTypeOption('CONSTRAINT'); |
||
| 196 | echo $this->_printTypeOption('DOMAIN'); |
||
| 197 | echo $this->_printTypeOption('FUNCTION'); |
||
| 198 | echo $this->_printTypeOption('INDEX'); |
||
| 199 | echo $this->_printTypeOption('RULE'); |
||
| 200 | echo $this->_printTypeOption('SCHEMA'); |
||
| 201 | echo $this->_printTypeOption('SEQUENCE'); |
||
| 202 | echo $this->_printTypeOption('TABLE'); |
||
| 203 | echo $this->_printTypeOption('TRIGGER'); |
||
| 204 | echo $this->_printTypeOption('VIEW'); |
||
| 205 | |||
| 206 | if ($this->conf['show_advanced']) { |
||
| 207 | echo $this->_printTypeOption('AGGREGATE'); |
||
| 208 | echo $this->_printTypeOption('TYPE'); |
||
| 209 | echo $this->_printTypeOption('OPERATOR'); |
||
| 210 | echo $this->_printTypeOption('OPCLASS'); |
||
| 211 | echo $this->_printTypeOption('CONVERSION'); |
||
| 212 | echo $this->_printTypeOption('LANGUAGE'); |
||
| 213 | } |
||
| 214 | |||
| 215 | echo '</select>' . \PHP_EOL; |
||
| 216 | echo "<input type=\"submit\" value=\"{$this->lang['strfind']}\" />" . \PHP_EOL; |
||
| 217 | echo $this->view->form; |
||
| 218 | echo '<input type="hidden" name="action" value="find" /></p>' . \PHP_EOL; |
||
| 219 | echo '<input type="hidden" name="confirm" value="true" /></p>' . \PHP_EOL; |
||
| 220 | echo '</form>' . \PHP_EOL; |
||
| 221 | |||
| 222 | // Default focus |
||
| 223 | $this->setFocus('forms[0].term'); |
||
| 224 | |||
| 225 | // If a search term has been specified, then perform the search |
||
| 226 | // and display the results, grouped by object type |
||
| 227 | if (!$confirm && '' !== $_REQUEST['term']) { |
||
| 228 | return $this->doFind(); |
||
| 229 | } |
||
| 230 | } |
||
| 231 | |||
| 232 | public function doFind(): void |
||
| 233 | { |
||
| 234 | $data = $this->misc->getDatabaseAccessor(); |
||
| 235 | $rs = $data->findObject($_REQUEST['term'], $_REQUEST['filter']); |
||
| 236 | |||
| 237 | if (0 < $rs->recordCount()) { |
||
| 238 | $curr = ''; |
||
| 239 | |||
| 240 | while (!$rs->EOF) { |
||
| 241 | // Output a new header if the current type has changed, but not if it's just changed the rule type |
||
| 242 | if ($rs->fields['type'] !== $curr) { |
||
| 243 | // Short-circuit in the case of changing from table rules to view rules; table cols to view cols; |
||
| 244 | // table constraints to domain constraints |
||
| 245 | if ('RULEVIEW' === $rs->fields['type'] && 'RULETABLE' === $curr) { |
||
| 246 | $curr = $rs->fields['type']; |
||
| 247 | } elseif ('COLUMNVIEW' === $rs->fields['type'] && 'COLUMNTABLE' === $curr) { |
||
| 248 | $curr = $rs->fields['type']; |
||
| 249 | } elseif ('CONSTRAINTTABLE' === $rs->fields['type'] && 'CONSTRAINTDOMAIN' === $curr) { |
||
| 250 | $curr = $rs->fields['type']; |
||
| 251 | } else { |
||
| 252 | if ('' !== $curr) { |
||
| 253 | echo '</ul>' . \PHP_EOL; |
||
| 254 | } |
||
| 255 | |||
| 256 | $curr = $rs->fields['type']; |
||
| 257 | echo '<h3>'; |
||
| 258 | echo $this->_translatedType($curr); |
||
| 259 | echo '</h3>'; |
||
| 260 | echo '<ul>' . \PHP_EOL; |
||
| 261 | } |
||
| 262 | } |
||
| 263 | |||
| 264 | $this->_printHtmlForType($curr, $rs); |
||
| 265 | $rs->moveNext(); |
||
| 266 | } |
||
| 267 | echo '</ul>' . \PHP_EOL; |
||
| 268 | |||
| 269 | echo '<p>', $rs->recordCount(), ' ', $this->lang['strobjects'], '</p>' . \PHP_EOL; |
||
| 270 | } else { |
||
| 271 | echo "<p>{$this->lang['strnoobjects']}</p>" . \PHP_EOL; |
||
| 272 | } |
||
| 273 | } |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Displays options for database download. |
||
| 277 | * |
||
| 278 | * @param mixed $msg |
||
| 279 | */ |
||
| 280 | public function doExport($msg = ''): void |
||
| 281 | { |
||
| 282 | $this->printTrail('database'); |
||
| 283 | $this->printTabs('database', 'export'); |
||
| 284 | $this->printMsg($msg); |
||
| 285 | |||
| 286 | $subject = 'database'; |
||
| 287 | $object = $_REQUEST['database']; |
||
| 288 | |||
| 289 | echo $this->formHeader('dbexport'); |
||
| 290 | |||
| 291 | echo $this->dataOnly(true, true); |
||
| 292 | |||
| 293 | echo $this->structureOnly(); |
||
| 294 | |||
| 295 | echo $this->structureAndData(true); |
||
| 296 | |||
| 297 | // $server_info = $this->misc->getServerInfo(); |
||
| 298 | // echo $this->offerNoRoleExport(isset($server_info['pgVersion']) && floatval(substr($server_info['pgVersion'], 0, 3)) >= 10); |
||
| 299 | |||
| 300 | echo $this->displayOrDownload(!(\mb_strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && isset($_SERVER['HTTPS']))); |
||
| 301 | |||
| 302 | echo $this->formFooter($subject, $object); |
||
| 303 | } |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Show the current status of all database variables. |
||
| 307 | */ |
||
| 308 | public function doVariables(): void |
||
| 309 | { |
||
| 310 | $data = $this->misc->getDatabaseAccessor(); |
||
| 311 | |||
| 312 | // Fetch the variables from the database |
||
| 313 | $variables = $data->getVariables(); |
||
| 314 | $this->printTrail('database'); |
||
| 315 | $this->printTabs('database', 'variables'); |
||
| 316 | |||
| 317 | $columns = [ |
||
| 318 | 'variable' => [ |
||
| 319 | 'title' => $this->lang['strname'], |
||
| 320 | 'field' => Decorator::field('name'), |
||
| 321 | ], |
||
| 322 | 'value' => [ |
||
| 323 | 'title' => $this->lang['strsetting'], |
||
| 324 | 'field' => Decorator::field('setting'), |
||
| 325 | ], |
||
| 326 | ]; |
||
| 327 | |||
| 328 | $actions = []; |
||
| 329 | |||
| 330 | echo $this->printTable($variables, $columns, $actions, $this->table_place, $this->lang['strnodata']); |
||
| 331 | } |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Show all current database connections and any queries they |
||
| 335 | * are running. |
||
| 336 | * |
||
| 337 | * @param mixed $msg |
||
| 338 | */ |
||
| 339 | public function doProcesses($msg = ''): void |
||
| 340 | { |
||
| 341 | $this->printTrail('database'); |
||
| 342 | $this->printTabs('database', 'processes'); |
||
| 343 | $this->printMsg($msg); |
||
| 344 | |||
| 345 | if (0 === \mb_strlen($msg)) { |
||
| 346 | echo '<br /><a id="control" href=""><img src="' . $this->view->icon('Refresh') . "\" alt=\"{$this->lang['strrefresh']}\" title=\"{$this->lang['strrefresh']}\"/> {$this->lang['strrefresh']}</a>"; |
||
| 347 | } |
||
| 348 | |||
| 349 | echo '<div id="data_block">'; |
||
| 350 | $this->currentProcesses(); |
||
| 351 | echo '</div>'; |
||
| 352 | } |
||
| 353 | |||
| 354 | public function currentProcesses(bool $isAjax = false): void |
||
| 355 | { |
||
| 356 | $data = $this->misc->getDatabaseAccessor(); |
||
| 357 | |||
| 358 | // Display prepared transactions |
||
| 359 | if ($data->hasPreparedXacts()) { |
||
| 360 | echo "<h3>{$this->lang['strpreparedxacts']}</h3>" . \PHP_EOL; |
||
| 361 | $prep_xacts = $data->getPreparedXacts($_REQUEST['database']); |
||
| 362 | |||
| 363 | $columns = [ |
||
| 364 | 'transaction' => [ |
||
| 365 | 'title' => $this->lang['strxactid'], |
||
| 366 | 'field' => Decorator::field('transaction'), |
||
| 367 | ], |
||
| 368 | 'gid' => [ |
||
| 369 | 'title' => $this->lang['strgid'], |
||
| 370 | 'field' => Decorator::field('gid'), |
||
| 371 | ], |
||
| 372 | 'prepared' => [ |
||
| 373 | 'title' => $this->lang['strstarttime'], |
||
| 374 | 'field' => Decorator::field('prepared'), |
||
| 375 | ], |
||
| 376 | 'owner' => [ |
||
| 377 | 'title' => $this->lang['strowner'], |
||
| 378 | 'field' => Decorator::field('owner'), |
||
| 379 | ], |
||
| 380 | ]; |
||
| 381 | |||
| 382 | $actions = []; |
||
| 383 | |||
| 384 | echo $this->printTable($prep_xacts, $columns, $actions, 'database-processes-preparedxacts', $this->lang['strnodata']); |
||
| 385 | } |
||
| 386 | |||
| 387 | // Fetch the processes from the database |
||
| 388 | echo "<h3>{$this->lang['strprocesses']}</h3>" . \PHP_EOL; |
||
| 389 | $processes = $data->getProcesses($_REQUEST['database']); |
||
| 390 | |||
| 391 | $columns = [ |
||
| 392 | 'user' => [ |
||
| 393 | 'title' => $this->lang['strusername'], |
||
| 394 | 'field' => Decorator::field('usename'), |
||
| 395 | ], |
||
| 396 | 'process' => [ |
||
| 397 | 'title' => $this->lang['strprocess'], |
||
| 398 | 'field' => Decorator::field('pid'), |
||
| 399 | ], |
||
| 400 | 'application_name' => [ |
||
| 401 | 'title' => 'application', |
||
| 402 | 'field' => Decorator::field('application_name'), |
||
| 403 | ], |
||
| 404 | 'client_addr' => [ |
||
| 405 | 'title' => 'address', |
||
| 406 | 'field' => Decorator::field('client_addr'), |
||
| 407 | ], |
||
| 408 | 'blocked' => [ |
||
| 409 | 'title' => $this->lang['strblocked'], |
||
| 410 | 'field' => Decorator::field('waiting'), |
||
| 411 | ], |
||
| 412 | 'query' => [ |
||
| 413 | 'title' => $this->lang['strsql'], |
||
| 414 | 'field' => Decorator::field('query'), |
||
| 415 | ], |
||
| 416 | 'start_time' => [ |
||
| 417 | 'title' => $this->lang['strstarttime'], |
||
| 418 | 'field' => Decorator::field('query_start'), |
||
| 419 | ], |
||
| 420 | ]; |
||
| 421 | |||
| 422 | // Build possible actions for our process list |
||
| 423 | $columns['actions'] = ['title' => $this->lang['stractions']]; |
||
| 424 | |||
| 425 | $actions = []; |
||
| 426 | |||
| 427 | if ($data->hasUserSignals() || $data->isSuperUser()) { |
||
| 428 | $actions = [ |
||
| 429 | 'cancel' => [ |
||
| 430 | 'content' => $this->lang['strcancel'], |
||
| 431 | 'attr' => [ |
||
| 432 | 'href' => [ |
||
| 433 | 'url' => 'database', |
||
| 434 | 'urlvars' => [ |
||
| 435 | 'action' => 'signal', |
||
| 436 | 'signal' => 'CANCEL', |
||
| 437 | 'pid' => Decorator::field('pid'), |
||
| 438 | ], |
||
| 439 | ], |
||
| 440 | ], |
||
| 441 | ], |
||
| 442 | 'kill' => [ |
||
| 443 | 'content' => $this->lang['strkill'], |
||
| 444 | 'attr' => [ |
||
| 445 | 'href' => [ |
||
| 446 | 'url' => 'database', |
||
| 447 | 'urlvars' => [ |
||
| 448 | 'action' => 'signal', |
||
| 449 | 'signal' => 'KILL', |
||
| 450 | 'pid' => Decorator::field('pid'), |
||
| 451 | ], |
||
| 452 | ], |
||
| 453 | ], |
||
| 454 | ], |
||
| 455 | ]; |
||
| 456 | |||
| 457 | // Remove actions where not supported |
||
| 458 | if (!$data->hasQueryKill()) { |
||
| 459 | unset($actions['kill']); |
||
| 460 | } |
||
| 461 | |||
| 462 | if (!$data->hasQueryCancel()) { |
||
| 463 | unset($actions['cancel']); |
||
| 464 | } |
||
| 465 | } |
||
| 466 | |||
| 467 | if (0 === \count($actions)) { |
||
| 468 | unset($columns['actions']); |
||
| 469 | } |
||
| 470 | |||
| 471 | echo $this->printTable($processes, $columns, $actions, 'database-processes', $this->lang['strnodata']); |
||
| 472 | } |
||
| 473 | |||
| 474 | public function currentLocks(bool $isAjax = false): void |
||
| 475 | { |
||
| 476 | $data = $this->misc->getDatabaseAccessor(); |
||
| 477 | |||
| 478 | // Get the info from the pg_locks view |
||
| 479 | $variables = $data->getLocks(); |
||
| 480 | |||
| 481 | $columns = [ |
||
| 482 | 'namespace' => [ |
||
| 483 | 'title' => $this->lang['strschema'], |
||
| 484 | 'field' => Decorator::field('nspname'), |
||
| 485 | ], |
||
| 486 | 'tablename' => [ |
||
| 487 | 'title' => $this->lang['strtablename'], |
||
| 488 | 'field' => Decorator::field('tablename'), |
||
| 489 | ], |
||
| 490 | 'vxid' => [ |
||
| 491 | 'title' => $this->lang['strvirtualtransaction'], |
||
| 492 | 'field' => Decorator::field('virtualtransaction'), |
||
| 493 | ], |
||
| 494 | 'transactionid' => [ |
||
| 495 | 'title' => $this->lang['strtransaction'], |
||
| 496 | 'field' => Decorator::field('transaction'), |
||
| 497 | ], |
||
| 498 | 'processid' => [ |
||
| 499 | 'title' => $this->lang['strprocessid'], |
||
| 500 | 'field' => Decorator::field('pid'), |
||
| 501 | ], |
||
| 502 | 'mode' => [ |
||
| 503 | 'title' => $this->lang['strmode'], |
||
| 504 | 'field' => Decorator::field('mode'), |
||
| 505 | ], |
||
| 506 | 'granted' => [ |
||
| 507 | 'title' => $this->lang['strislockheld'], |
||
| 508 | 'field' => Decorator::field('granted'), |
||
| 509 | 'type' => 'yesno', |
||
| 510 | ], |
||
| 511 | ]; |
||
| 512 | |||
| 513 | if (!$data->hasVirtualTransactionId()) { |
||
| 514 | unset($columns['vxid']); |
||
| 515 | } |
||
| 516 | |||
| 517 | $actions = []; |
||
| 518 | echo $this->printTable($variables, $columns, $actions, 'database-locks', $this->lang['strnodata']); |
||
| 519 | } |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Show the existing table locks in the current database. |
||
| 523 | */ |
||
| 524 | public function doLocks(): void |
||
| 525 | { |
||
| 526 | $this->printTrail('database'); |
||
| 527 | $this->printTabs('database', 'locks'); |
||
| 528 | |||
| 529 | echo '<br /><a id="control" href=""><img src="' . $this->view->icon('Refresh') . "\" alt=\"{$this->lang['strrefresh']}\" title=\"{$this->lang['strrefresh']}\"/> {$this->lang['strrefresh']}</a>"; |
||
| 530 | |||
| 531 | echo '<div id="data_block">'; |
||
| 532 | $this->currentLocks(); |
||
| 533 | echo '</div>'; |
||
| 534 | } |
||
| 535 | |||
| 536 | /** |
||
| 537 | * Allow execution of arbitrary SQL statements on a database. |
||
| 538 | */ |
||
| 539 | public function doSQL(): void |
||
| 540 | { |
||
| 541 | if ((!isset($_SESSION['sqlquery'])) || isset($_REQUEST['new'])) { |
||
| 542 | $_SESSION['sqlquery'] = ''; |
||
| 543 | $_REQUEST['paginate'] = 'on'; |
||
| 544 | } |
||
| 545 | |||
| 546 | $this->printTrail('database'); |
||
| 547 | $this->printTabs('database', 'sql'); |
||
| 548 | echo "<p>{$this->lang['strentersql']}</p>" . \PHP_EOL; |
||
| 549 | echo '<form action="' . \containerInstance()->subFolder . '/src/views/sql" method="post" enctype="multipart/form-data" id="sqlform">' . \PHP_EOL; |
||
| 550 | echo "<p>{$this->lang['strsql']}<br />" . \PHP_EOL; |
||
| 551 | echo '<textarea style="width:95%;" rows="15" cols="50" name="query" id="query">', |
||
| 552 | \htmlspecialchars($_SESSION['sqlquery']), '</textarea></p>' . \PHP_EOL; |
||
| 553 | |||
| 554 | // Check that file uploads are enabled |
||
| 555 | if (\ini_get('file_uploads')) { |
||
| 556 | // Don't show upload option if max size of uploads is zero |
||
| 557 | $max_size = $this->misc->inisizeToBytes(\ini_get('upload_max_filesize')); |
||
| 558 | |||
| 559 | if (\is_float($max_size) && 0 < $max_size) { |
||
| 560 | echo "<p><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"{$max_size}\" />" . \PHP_EOL; |
||
| 561 | echo "<label for=\"script\">{$this->lang['struploadscript']}</label> <input id=\"script\" name=\"script\" type=\"file\" /></p>" . \PHP_EOL; |
||
| 562 | } |
||
| 563 | } |
||
| 564 | |||
| 565 | echo '<p><input type="checkbox" id="paginate" name="paginate"', (isset($_REQUEST['paginate']) ? ' checked="checked"' : ''), " /><label for=\"paginate\">{$this->lang['strpaginate']}</label></p>" . \PHP_EOL; |
||
| 566 | echo "<p><input type=\"submit\" name=\"execute\" accesskey=\"r\" value=\"{$this->lang['strexecute']}\" />" . \PHP_EOL; |
||
| 567 | echo $this->view->form; |
||
| 568 | echo "<input type=\"reset\" accesskey=\"q\" value=\"{$this->lang['strreset']}\" /></p>" . \PHP_EOL; |
||
| 569 | echo '</form>' . \PHP_EOL; |
||
| 570 | |||
| 571 | // Default focus |
||
| 572 | $this->setFocus('forms[0].query'); |
||
| 573 | } |
||
| 574 | |||
| 575 | /** |
||
| 576 | * This functions does pretty much nothing. It's meant to implement |
||
| 577 | * an abstract method of AdminTrait. |
||
| 578 | * |
||
| 579 | * @param string $msg The message |
||
| 580 | * |
||
| 581 | * @return string The message |
||
| 582 | */ |
||
| 583 | public function doDefault($msg = '') |
||
| 584 | { |
||
| 585 | return $msg; |
||
| 586 | } |
||
| 587 | |||
| 588 | private function _highlight($string, $term) |
||
| 589 | { |
||
| 590 | return \str_replace($term, "<b>{$term}</b>", $string); |
||
| 591 | } |
||
| 592 | |||
| 593 | private function _printTypeOption(string $curr) |
||
| 601 | } |
||
| 602 | |||
| 603 | private function _translatedType(string $curr) |
||
| 637 | } |
||
| 638 | |||
| 639 | private function _printHtmlForType($curr, $rs): void |
||
| 806 | } |
||
| 807 | //$this->dump(['curr' => $curr, 'destination' => $destination]); |
||
| 808 | } |
||
| 809 | } |
||
| 810 |