| Total Complexity | 61 |
| Total Lines | 672 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like AlldbController 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 AlldbController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | class AlldbController extends BaseController |
||
| 16 | { |
||
| 17 | use ExportTrait; |
||
|
|
|||
| 18 | |||
| 19 | public $table_place = 'alldb-databases'; |
||
| 20 | |||
| 21 | public $controller_title = 'strdatabases'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Default method to render the controller according to the action parameter. |
||
| 25 | */ |
||
| 26 | public function render() |
||
| 27 | { |
||
| 28 | if ('tree' === $this->action) { |
||
| 29 | return $this->doTree(); |
||
| 30 | } |
||
| 31 | |||
| 32 | $header_template = 'header.twig'; |
||
| 33 | |||
| 34 | \ob_start(); |
||
| 35 | |||
| 36 | switch ($this->action) { |
||
| 37 | case 'export': |
||
| 38 | $this->doExport(); |
||
| 39 | |||
| 40 | break; |
||
| 41 | case 'save_create': |
||
| 42 | if (null !== $this->getPostParam('cancel')) { |
||
| 43 | $this->doDefault(); |
||
| 44 | } else { |
||
| 45 | $this->doSaveCreate(); |
||
| 46 | } |
||
| 47 | |||
| 48 | break; |
||
| 49 | case 'create': |
||
| 50 | $this->doCreate(); |
||
| 51 | |||
| 52 | break; |
||
| 53 | case 'drop': |
||
| 54 | if (isset($_REQUEST['drop'])) { |
||
| 55 | $this->doDrop(false); |
||
| 56 | } else { |
||
| 57 | $this->doDefault(); |
||
| 58 | } |
||
| 59 | |||
| 60 | break; |
||
| 61 | case 'confirm_drop': |
||
| 62 | $this->doDrop(true); |
||
| 63 | |||
| 64 | break; |
||
| 65 | case 'alter': |
||
| 66 | if (isset($_POST['oldname'], $_POST['newname']) && !isset($_POST['cancel'])) { |
||
| 67 | $this->doAlter(false); |
||
| 68 | } else { |
||
| 69 | $this->doDefault(); |
||
| 70 | } |
||
| 71 | |||
| 72 | break; |
||
| 73 | case 'confirm_alter': |
||
| 74 | $this->doAlter(true); |
||
| 75 | |||
| 76 | break; |
||
| 77 | |||
| 78 | default: |
||
| 79 | $header_template = 'header_datatables.twig'; |
||
| 80 | $this->doDefault(); |
||
| 81 | |||
| 82 | break; |
||
| 83 | } |
||
| 84 | $output = \ob_get_clean(); |
||
| 85 | |||
| 86 | $this->printHeader($this->headerTitle(), null, true, $header_template); |
||
| 87 | $this->printBody(); |
||
| 88 | echo $output; |
||
| 89 | |||
| 90 | return $this->printFooter(); |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Show default list of databases in the server. |
||
| 95 | * |
||
| 96 | * @param mixed $msg |
||
| 97 | */ |
||
| 98 | public function doDefault($msg = ''): void |
||
| 99 | { |
||
| 100 | $this->printTrail('server'); |
||
| 101 | $this->printTabs('server', 'databases'); |
||
| 102 | $this->printMsg($msg); |
||
| 103 | $data = $this->misc->getDatabaseAccessor(); |
||
| 104 | |||
| 105 | $databases = $data->getDatabases(); |
||
| 106 | |||
| 107 | $this->view->setReloadBrowser(true); |
||
| 108 | |||
| 109 | $href = $this->misc->getHREF(); |
||
| 110 | $redirecturl = $this->container->getDestinationWithLastTab('database'); |
||
| 111 | |||
| 112 | $columns = [ |
||
| 113 | 'database' => [ |
||
| 114 | 'title' => $this->lang['strdatabase'], |
||
| 115 | 'field' => Decorator::field('datname'), |
||
| 116 | 'url' => \containerInstance()->subFolder . $redirecturl . '&', |
||
| 117 | 'vars' => ['database' => 'datname'], |
||
| 118 | ], |
||
| 119 | 'owner' => [ |
||
| 120 | 'title' => $this->lang['strowner'], |
||
| 121 | 'field' => Decorator::field('datowner'), |
||
| 122 | ], |
||
| 123 | 'encoding' => [ |
||
| 124 | 'title' => $this->lang['strencoding'], |
||
| 125 | 'field' => Decorator::field('datencoding'), |
||
| 126 | ], |
||
| 127 | |||
| 128 | 'tablespace' => [ |
||
| 129 | 'title' => $this->lang['strtablespace'], |
||
| 130 | 'field' => Decorator::field('tablespace'), |
||
| 131 | ], |
||
| 132 | 'dbsize' => [ |
||
| 133 | 'title' => $this->lang['strsize'], |
||
| 134 | 'field' => Decorator::field('dbsize'), |
||
| 135 | 'type' => 'prettysize', |
||
| 136 | ], |
||
| 137 | 'lc_collate' => [ |
||
| 138 | 'title' => $this->lang['strcollation'], |
||
| 139 | 'field' => Decorator::field('datcollate'), |
||
| 140 | ], |
||
| 141 | 'lc_ctype' => [ |
||
| 142 | 'title' => $this->lang['strctype'], |
||
| 143 | 'field' => Decorator::field('datctype'), |
||
| 144 | ], |
||
| 145 | 'actions' => [ |
||
| 146 | 'title' => $this->lang['stractions'], |
||
| 147 | ], |
||
| 148 | 'comment' => [ |
||
| 149 | 'title' => $this->lang['strcomment'], |
||
| 150 | 'field' => Decorator::field('datcomment'), |
||
| 151 | ], |
||
| 152 | ]; |
||
| 153 | |||
| 154 | $actions = [ |
||
| 155 | 'multiactions' => [ |
||
| 156 | 'keycols' => ['database' => 'datname'], |
||
| 157 | 'url' => 'alldb', |
||
| 158 | 'default' => null, |
||
| 159 | ], |
||
| 160 | 'drop' => [ |
||
| 161 | 'content' => $this->lang['strdrop'], |
||
| 162 | 'attr' => [ |
||
| 163 | 'href' => [ |
||
| 164 | 'url' => 'alldb', |
||
| 165 | 'urlvars' => [ |
||
| 166 | 'subject' => 'database', |
||
| 167 | 'action' => 'confirm_drop', |
||
| 168 | 'dropdatabase' => Decorator::field('datname'), |
||
| 169 | ], |
||
| 170 | ], |
||
| 171 | ], |
||
| 172 | 'multiaction' => 'confirm_drop', |
||
| 173 | ], |
||
| 174 | 'privileges' => [ |
||
| 175 | 'content' => $this->lang['strprivileges'], |
||
| 176 | 'attr' => [ |
||
| 177 | 'href' => [ |
||
| 178 | 'url' => 'privileges', |
||
| 179 | 'urlvars' => [ |
||
| 180 | 'subject' => 'database', |
||
| 181 | 'database' => Decorator::field('datname'), |
||
| 182 | ], |
||
| 183 | ], |
||
| 184 | ], |
||
| 185 | ], |
||
| 186 | ]; |
||
| 187 | |||
| 188 | if ($data->hasAlterDatabase()) { |
||
| 189 | $actions['alter'] = [ |
||
| 190 | 'content' => $this->lang['stralter'], |
||
| 191 | 'attr' => [ |
||
| 192 | 'href' => [ |
||
| 193 | 'url' => 'alldb', |
||
| 194 | 'urlvars' => [ |
||
| 195 | 'subject' => 'database', |
||
| 196 | 'action' => 'confirm_alter', |
||
| 197 | 'alterdatabase' => Decorator::field('datname'), |
||
| 198 | ], |
||
| 199 | ], |
||
| 200 | ], |
||
| 201 | ]; |
||
| 202 | } |
||
| 203 | |||
| 204 | if (!$data->hasTablespaces()) { |
||
| 205 | unset($columns['tablespace']); |
||
| 206 | } |
||
| 207 | |||
| 208 | if (!$data->hasServerAdminFuncs()) { |
||
| 209 | unset($columns['dbsize']); |
||
| 210 | } |
||
| 211 | |||
| 212 | if (!$data->hasDatabaseCollation()) { |
||
| 213 | unset($columns['lc_collate'], $columns['lc_ctype']); |
||
| 214 | } |
||
| 215 | |||
| 216 | if (!isset($data->privlist['database'])) { |
||
| 217 | unset($actions['privileges']); |
||
| 218 | } |
||
| 219 | |||
| 220 | echo $this->printTable($databases, $columns, $actions, $this->table_place, $this->lang['strnodatabases']); |
||
| 221 | |||
| 222 | $navlinks = [ |
||
| 223 | 'create' => [ |
||
| 224 | 'attr' => [ |
||
| 225 | 'href' => [ |
||
| 226 | 'url' => 'alldb', |
||
| 227 | 'urlvars' => [ |
||
| 228 | 'action' => 'create', |
||
| 229 | 'server' => $_REQUEST['server'], |
||
| 230 | ], |
||
| 231 | ], |
||
| 232 | ], |
||
| 233 | 'content' => $this->lang['strcreatedatabase'], |
||
| 234 | ], |
||
| 235 | ]; |
||
| 236 | $this->printNavLinks($navlinks, $this->table_place, \get_defined_vars()); |
||
| 237 | } |
||
| 238 | |||
| 239 | /** |
||
| 240 | * @return \Slim\Http\Response|string |
||
| 241 | */ |
||
| 242 | public function doTree() |
||
| 259 | } |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Display a form for alter and perform actual alter. |
||
| 263 | * |
||
| 264 | * @param mixed $confirm |
||
| 265 | */ |
||
| 266 | public function doAlter($confirm): void |
||
| 267 | { |
||
| 268 | $data = $this->misc->getDatabaseAccessor(); |
||
| 269 | |||
| 270 | if ($confirm) { |
||
| 271 | $this->printTrail('database'); |
||
| 272 | $this->printTitle($this->lang['stralter'], 'pg.database.alter'); |
||
| 273 | |||
| 274 | echo '<form action="' . \containerInstance()->subFolder . '/src/views/alldb" method="post">' . \PHP_EOL; |
||
| 275 | echo '<table>' . \PHP_EOL; |
||
| 276 | echo \sprintf( |
||
| 277 | '<tr><th class="data left required">%s</th>', |
||
| 278 | $this->lang['strname'] |
||
| 279 | ) . \PHP_EOL; |
||
| 280 | echo '<td class="data1">'; |
||
| 281 | echo \sprintf( |
||
| 282 | '<input name="newname" size="32" maxlength="%s" value="', |
||
| 283 | $data->_maxNameLen |
||
| 284 | ), |
||
| 285 | \htmlspecialchars($_REQUEST['alterdatabase']), '" /></td></tr>' . \PHP_EOL; |
||
| 286 | |||
| 287 | if ($data->hasAlterDatabaseOwner() && $data->isSuperUser()) { |
||
| 288 | // Fetch all users |
||
| 289 | |||
| 290 | $rs = $data->getDatabaseOwner($_REQUEST['alterdatabase']); |
||
| 291 | $owner = isset($rs->fields['usename']) ? $rs->fields['usename'] : ''; |
||
| 292 | $users = $data->getUsers(); |
||
| 293 | |||
| 294 | echo \sprintf( |
||
| 295 | '<tr><th class="data left required">%s</th>', |
||
| 296 | $this->lang['strowner'] |
||
| 297 | ) . \PHP_EOL; |
||
| 298 | echo '<td class="data1"><select name="owner">'; |
||
| 299 | |||
| 300 | while (!$users->EOF) { |
||
| 301 | $uname = $users->fields['usename']; |
||
| 302 | echo '<option value="', \htmlspecialchars($uname), '"', |
||
| 303 | ($uname === $owner) ? ' selected="selected"' : '', '>', \htmlspecialchars($uname), '</option>' . \PHP_EOL; |
||
| 304 | $users->moveNext(); |
||
| 305 | } |
||
| 306 | echo '</select></td></tr>' . \PHP_EOL; |
||
| 307 | } |
||
| 308 | |||
| 309 | if ($data->hasSharedComments()) { |
||
| 310 | $rs = $data->getDatabaseComment($_REQUEST['alterdatabase']); |
||
| 311 | $comment = isset($rs->fields['description']) ? $rs->fields['description'] : ''; |
||
| 312 | echo \sprintf( |
||
| 313 | '<tr><th class="data left">%s</th>', |
||
| 314 | $this->lang['strcomment'] |
||
| 315 | ) . \PHP_EOL; |
||
| 316 | echo '<td class="data1">'; |
||
| 317 | echo '<textarea rows="3" cols="32" name="dbcomment">', |
||
| 318 | \htmlspecialchars($comment), '</textarea></td></tr>' . \PHP_EOL; |
||
| 319 | } |
||
| 320 | echo '</table>' . \PHP_EOL; |
||
| 321 | echo '<input type="hidden" name="action" value="alter" />' . \PHP_EOL; |
||
| 322 | echo $this->view->form; |
||
| 323 | echo '<input type="hidden" name="oldname" value="', |
||
| 324 | \htmlspecialchars($_REQUEST['alterdatabase']), '" />' . \PHP_EOL; |
||
| 325 | echo \sprintf( |
||
| 326 | '<input type="submit" name="alter" value="%s" />', |
||
| 327 | $this->lang['stralter'] |
||
| 328 | ) . \PHP_EOL; |
||
| 329 | echo \sprintf( |
||
| 330 | '<input type="submit" name="cancel" value="%s" />', |
||
| 331 | $this->lang['strcancel'] |
||
| 332 | ) . \PHP_EOL; |
||
| 333 | echo '</form>' . \PHP_EOL; |
||
| 334 | } else { |
||
| 335 | $this->coalesceArr($_POST, 'owner', ''); |
||
| 336 | |||
| 337 | $this->coalesceArr($_POST, 'dbcomment', ''); |
||
| 338 | |||
| 339 | if (0 === $data->alterDatabase($_POST['oldname'], $_POST['newname'], $_POST['owner'], $_POST['dbcomment'])) { |
||
| 340 | $this->view->setReloadBrowser(true); |
||
| 341 | $this->doDefault($this->lang['strdatabasealtered']); |
||
| 342 | } else { |
||
| 343 | $this->doDefault($this->lang['strdatabasealteredbad']); |
||
| 344 | } |
||
| 345 | } |
||
| 346 | } |
||
| 347 | |||
| 348 | /** |
||
| 349 | * Show confirmation of drop and perform actual drop. |
||
| 350 | * |
||
| 351 | * @param mixed $confirm |
||
| 352 | */ |
||
| 353 | public function doDrop($confirm) |
||
| 433 | } |
||
| 434 | } |
||
| 435 | //END DROP |
||
| 436 | } |
||
| 437 | } |
||
| 438 | |||
| 439 | // END FUNCTION |
||
| 440 | |||
| 441 | /** |
||
| 442 | * Displays a screen where they can enter a new database. |
||
| 443 | * |
||
| 444 | * @param mixed $msg |
||
| 445 | */ |
||
| 446 | public function doCreate($msg = ''): void |
||
| 447 | { |
||
| 448 | $data = $this->misc->getDatabaseAccessor(); |
||
| 449 | |||
| 450 | $this->printTrail('server'); |
||
| 451 | $this->printTitle($this->lang['strcreatedatabase'], 'pg.database.create'); |
||
| 452 | $this->printMsg($msg); |
||
| 453 | |||
| 454 | $this->coalesceArr($_POST, 'formName', ''); |
||
| 455 | |||
| 456 | // Default encoding is that in language file |
||
| 457 | $this->coalesceArr($_POST, 'formEncoding', ''); |
||
| 458 | $this->coalesceArr($_POST, 'formTemplate', 'template1'); |
||
| 459 | |||
| 460 | $this->coalesceArr($_POST, 'formSpc', ''); |
||
| 461 | |||
| 462 | $this->coalesceArr($_POST, 'formComment', ''); |
||
| 463 | |||
| 464 | // Fetch a list of databases in the cluster |
||
| 465 | $templatedbs = $data->getDatabases(false); |
||
| 466 | |||
| 467 | $tablespaces = null; |
||
| 468 | // Fetch all tablespaces from the database |
||
| 469 | if ($data->hasTablespaces()) { |
||
| 470 | $tablespaces = $data->getTablespaces(); |
||
| 471 | } |
||
| 472 | |||
| 473 | echo '<form action="' . \containerInstance()->subFolder . '/src/views/alldb" method="post">' . \PHP_EOL; |
||
| 474 | echo '<table>' . \PHP_EOL; |
||
| 475 | echo \sprintf( |
||
| 476 | ' <tr> |
||
| 477 | <th class="data left required">%s</th>', |
||
| 478 | $this->lang['strname'] |
||
| 479 | ) . \PHP_EOL; |
||
| 480 | echo \sprintf( |
||
| 481 | ' <td class="data1"><input name="formName" size="32" maxlength="%s" value="', |
||
| 482 | $data->_maxNameLen |
||
| 483 | ), |
||
| 484 | \htmlspecialchars($_POST['formName']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
||
| 485 | |||
| 486 | echo \sprintf( |
||
| 487 | ' <tr> |
||
| 488 | <th class="data left required">%s</th>', |
||
| 489 | $this->lang['strtemplatedb'] |
||
| 490 | ) . \PHP_EOL; |
||
| 491 | echo "\t\t<td class=\"data1\">" . \PHP_EOL; |
||
| 492 | echo "\t\t\t<select name=\"formTemplate\">" . \PHP_EOL; |
||
| 493 | // Always offer template0 and template1 |
||
| 494 | echo "\t\t\t\t<option value=\"template0\"", |
||
| 495 | ('template0' === $_POST['formTemplate']) ? ' selected="selected"' : '', '>template0</option>' . \PHP_EOL; |
||
| 496 | echo "\t\t\t\t<option value=\"template1\"", |
||
| 497 | ('template1' === $_POST['formTemplate']) ? ' selected="selected"' : '', '>template1</option>' . \PHP_EOL; |
||
| 498 | |||
| 499 | while (!$templatedbs->EOF) { |
||
| 500 | $dbname = \htmlspecialchars($templatedbs->fields['datname']); |
||
| 501 | |||
| 502 | if ('template1' !== $dbname) { |
||
| 503 | // filter out for $this->conf[show_system] users so we dont get duplicates |
||
| 504 | echo \sprintf( |
||
| 505 | ' <option value="%s"', |
||
| 506 | $dbname |
||
| 507 | ), |
||
| 508 | ($dbname === $_POST['formTemplate']) ? ' selected="selected"' : '', \sprintf( |
||
| 509 | '>%s</option>', |
||
| 510 | $dbname |
||
| 511 | ) . \PHP_EOL; |
||
| 512 | } |
||
| 513 | $templatedbs->moveNext(); |
||
| 514 | } |
||
| 515 | echo "\t\t\t</select>" . \PHP_EOL; |
||
| 516 | echo "\t\t</td>\n\t</tr>" . \PHP_EOL; |
||
| 517 | |||
| 518 | // ENCODING |
||
| 519 | echo \sprintf( |
||
| 520 | ' <tr> |
||
| 521 | <th class="data left required">%s</th>', |
||
| 522 | $this->lang['strencoding'] |
||
| 523 | ) . \PHP_EOL; |
||
| 524 | echo "\t\t<td class=\"data1\">" . \PHP_EOL; |
||
| 525 | echo "\t\t\t<select name=\"formEncoding\">" . \PHP_EOL; |
||
| 526 | echo "\t\t\t\t<option value=\"\"></option>" . \PHP_EOL; |
||
| 527 | |||
| 528 | foreach ($data->codemap as $key) { |
||
| 529 | echo "\t\t\t\t<option value=\"", \htmlspecialchars($key), '"', |
||
| 530 | ($key === $_POST['formEncoding']) ? ' selected="selected"' : '', '>', |
||
| 531 | $this->misc->printVal($key), '</option>' . \PHP_EOL; |
||
| 532 | } |
||
| 533 | echo "\t\t\t</select>" . \PHP_EOL; |
||
| 534 | echo "\t\t</td>\n\t</tr>" . \PHP_EOL; |
||
| 535 | |||
| 536 | if ($data->hasDatabaseCollation()) { |
||
| 537 | $this->coalesceArr($_POST, 'formCollate', ''); |
||
| 538 | |||
| 539 | $this->coalesceArr($_POST, 'formCType', ''); |
||
| 540 | |||
| 541 | // LC_COLLATE |
||
| 542 | echo \sprintf( |
||
| 543 | ' <tr> |
||
| 544 | <th class="data left">%s</th>', |
||
| 545 | $this->lang['strcollation'] |
||
| 546 | ) . \PHP_EOL; |
||
| 547 | echo "\t\t<td class=\"data1\">" . \PHP_EOL; |
||
| 548 | echo "\t\t\t<input name=\"formCollate\" value=\"", \htmlspecialchars($_POST['formCollate']), '" />' . \PHP_EOL; |
||
| 549 | echo "\t\t</td>\n\t</tr>" . \PHP_EOL; |
||
| 550 | |||
| 551 | // LC_CTYPE |
||
| 552 | echo \sprintf( |
||
| 553 | ' <tr> |
||
| 554 | <th class="data left">%s</th>', |
||
| 555 | $this->lang['strctype'] |
||
| 556 | ) . \PHP_EOL; |
||
| 557 | echo "\t\t<td class=\"data1\">" . \PHP_EOL; |
||
| 558 | echo "\t\t\t<input name=\"formCType\" value=\"", \htmlspecialchars($_POST['formCType']), '" />' . \PHP_EOL; |
||
| 559 | echo "\t\t</td>\n\t</tr>" . \PHP_EOL; |
||
| 560 | } |
||
| 561 | |||
| 562 | // Tablespace (if there are any) |
||
| 563 | if ($data->hasTablespaces() && 0 < $tablespaces->recordCount()) { |
||
| 564 | echo \sprintf( |
||
| 565 | ' <tr> |
||
| 566 | <th class="data left">%s</th>', |
||
| 567 | $this->lang['strtablespace'] |
||
| 568 | ) . \PHP_EOL; |
||
| 569 | echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"formSpc\">" . \PHP_EOL; |
||
| 570 | // Always offer the default (empty) option |
||
| 571 | echo "\t\t\t\t<option value=\"\"", |
||
| 572 | ('' === $_POST['formSpc']) ? ' selected="selected"' : '', '></option>' . \PHP_EOL; |
||
| 573 | // Display all other tablespaces |
||
| 574 | while (!$tablespaces->EOF) { |
||
| 575 | $spcname = \htmlspecialchars($tablespaces->fields['spcname'] ?? ''); |
||
| 576 | echo \sprintf( |
||
| 577 | ' <option value="%s"', |
||
| 578 | $spcname |
||
| 579 | ), |
||
| 580 | ($spcname === $_POST['formSpc']) ? ' selected="selected"' : '', \sprintf( |
||
| 581 | '>%s</option>', |
||
| 582 | $spcname |
||
| 583 | ) . \PHP_EOL; |
||
| 584 | $tablespaces->moveNext(); |
||
| 585 | } |
||
| 586 | echo "\t\t\t</select>\n\t\t</td>\n\t</tr>" . \PHP_EOL; |
||
| 587 | } |
||
| 588 | |||
| 589 | // Comments (if available) |
||
| 590 | if ($data->hasSharedComments()) { |
||
| 591 | echo \sprintf( |
||
| 592 | ' <tr> |
||
| 593 | <th class="data left">%s</th>', |
||
| 594 | $this->lang['strcomment'] |
||
| 595 | ) . \PHP_EOL; |
||
| 596 | echo "\t\t<td><textarea name=\"formComment\" rows=\"3\" cols=\"32\">", |
||
| 597 | \htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>" . \PHP_EOL; |
||
| 598 | } |
||
| 599 | |||
| 600 | echo '</table>' . \PHP_EOL; |
||
| 601 | echo '<p><input type="hidden" name="action" value="save_create" />' . \PHP_EOL; |
||
| 602 | echo $this->view->form; |
||
| 603 | echo \sprintf( |
||
| 604 | '<input type="submit" value="%s" />', |
||
| 605 | $this->lang['strcreate'] |
||
| 606 | ) . \PHP_EOL; |
||
| 607 | echo \sprintf( |
||
| 608 | '<input type="submit" name="cancel" value="%s" /></p>%s', |
||
| 609 | $this->lang['strcancel'], |
||
| 610 | \PHP_EOL |
||
| 611 | ); |
||
| 612 | echo '</form>' . \PHP_EOL; |
||
| 613 | } |
||
| 614 | |||
| 615 | /** |
||
| 616 | * Actually creates the new view in the database. |
||
| 617 | */ |
||
| 618 | public function doSaveCreate(): void |
||
| 619 | { |
||
| 620 | $data = $this->misc->getDatabaseAccessor(); |
||
| 621 | |||
| 622 | // Default tablespace to null if it isn't set |
||
| 623 | $this->coalesceArr($_POST, 'formSpc', ''); |
||
| 624 | |||
| 625 | // Default comment to blank if it isn't set |
||
| 626 | $this->coalesceArr($_POST, 'formComment', ''); |
||
| 627 | |||
| 628 | // Default collate to blank if it isn't set |
||
| 629 | $this->coalesceArr($_POST, 'formCollate', ''); |
||
| 630 | |||
| 631 | // Default ctype to blank if it isn't set |
||
| 632 | $this->coalesceArr($_POST, 'formCType', ''); |
||
| 633 | |||
| 634 | // Check that they've given a name and a definition |
||
| 635 | if ('' === $_POST['formName']) { |
||
| 636 | $this->doCreate($this->lang['strdatabaseneedsname']); |
||
| 637 | } else { |
||
| 638 | $status = $data->createDatabase( |
||
| 639 | $_POST['formName'], |
||
| 640 | $_POST['formEncoding'], |
||
| 641 | $_POST['formSpc'], |
||
| 642 | $_POST['formComment'], |
||
| 643 | $_POST['formTemplate'], |
||
| 644 | $_POST['formCollate'], |
||
| 645 | $_POST['formCType'] |
||
| 646 | ); |
||
| 647 | |||
| 648 | if (0 === $status) { |
||
| 649 | $this->view->setReloadBrowser(true); |
||
| 650 | $this->doDefault($this->lang['strdatabasecreated']); |
||
| 651 | } else { |
||
| 652 | $this->doCreate($this->lang['strdatabasecreatedbad']); |
||
| 653 | } |
||
| 654 | } |
||
| 655 | } |
||
| 656 | |||
| 657 | /** |
||
| 658 | * Displays options for cluster download. |
||
| 659 | * |
||
| 660 | * @param mixed $msg |
||
| 661 | */ |
||
| 662 | public function doExport($msg = ''): void |
||
| 687 | } |
||
| 688 | } |
||
| 689 |