| Total Complexity | 61 | 
| Total Lines | 669 | 
| 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 | public function doTree() | ||
| 256 | } | ||
| 257 | |||
| 258 | /** | ||
| 259 | * Display a form for alter and perform actual alter. | ||
| 260 | * | ||
| 261 | * @param mixed $confirm | ||
| 262 | */ | ||
| 263 | public function doAlter($confirm): void | ||
| 264 |     { | ||
| 265 | $data = $this->misc->getDatabaseAccessor(); | ||
| 266 | |||
| 267 |         if ($confirm) { | ||
| 268 |             $this->printTrail('database'); | ||
| 269 | $this->printTitle($this->lang['stralter'], 'pg.database.alter'); | ||
| 270 | |||
| 271 | echo '<form action="' . \containerInstance()->subFolder . '/src/views/alldb" method="post">' . \PHP_EOL; | ||
| 272 | echo '<table>' . \PHP_EOL; | ||
| 273 | echo \sprintf( | ||
| 274 | '<tr><th class="data left required">%s</th>', | ||
| 275 | $this->lang['strname'] | ||
| 276 | ) . \PHP_EOL; | ||
| 277 | echo '<td class="data1">'; | ||
| 278 | echo \sprintf( | ||
| 279 | '<input name="newname" size="32" maxlength="%s" value="', | ||
| 280 | $data->_maxNameLen | ||
| 281 | ), | ||
| 282 | \htmlspecialchars($_REQUEST['alterdatabase']), '" /></td></tr>' . \PHP_EOL; | ||
| 283 | |||
| 284 |             if ($data->hasAlterDatabaseOwner() && $data->isSuperUser()) { | ||
| 285 | // Fetch all users | ||
| 286 | |||
| 287 | $rs = $data->getDatabaseOwner($_REQUEST['alterdatabase']); | ||
| 288 | $owner = isset($rs->fields['usename']) ? $rs->fields['usename'] : ''; | ||
| 289 | $users = $data->getUsers(); | ||
| 290 | |||
| 291 | echo \sprintf( | ||
| 292 | '<tr><th class="data left required">%s</th>', | ||
| 293 | $this->lang['strowner'] | ||
| 294 | ) . \PHP_EOL; | ||
| 295 | echo '<td class="data1"><select name="owner">'; | ||
| 296 | |||
| 297 |                 while (!$users->EOF) { | ||
| 298 | $uname = $users->fields['usename']; | ||
| 299 | echo '<option value="', \htmlspecialchars($uname), '"', | ||
| 300 | ($uname === $owner) ? ' selected="selected"' : '', '>', \htmlspecialchars($uname), '</option>' . \PHP_EOL; | ||
| 301 | $users->moveNext(); | ||
| 302 | } | ||
| 303 | echo '</select></td></tr>' . \PHP_EOL; | ||
| 304 | } | ||
| 305 | |||
| 306 |             if ($data->hasSharedComments()) { | ||
| 307 | $rs = $data->getDatabaseComment($_REQUEST['alterdatabase']); | ||
| 308 | $comment = isset($rs->fields['description']) ? $rs->fields['description'] : ''; | ||
| 309 | echo \sprintf( | ||
| 310 | '<tr><th class="data left">%s</th>', | ||
| 311 | $this->lang['strcomment'] | ||
| 312 | ) . \PHP_EOL; | ||
| 313 | echo '<td class="data1">'; | ||
| 314 | echo '<textarea rows="3" cols="32" name="dbcomment">', | ||
| 315 | \htmlspecialchars($comment), '</textarea></td></tr>' . \PHP_EOL; | ||
| 316 | } | ||
| 317 | echo '</table>' . \PHP_EOL; | ||
| 318 | echo '<input type="hidden" name="action" value="alter" />' . \PHP_EOL; | ||
| 319 | echo $this->view->form; | ||
| 320 | echo '<input type="hidden" name="oldname" value="', | ||
| 321 | \htmlspecialchars($_REQUEST['alterdatabase']), '" />' . \PHP_EOL; | ||
| 322 | echo \sprintf( | ||
| 323 | '<input type="submit" name="alter" value="%s" />', | ||
| 324 | $this->lang['stralter'] | ||
| 325 | ) . \PHP_EOL; | ||
| 326 | echo \sprintf( | ||
| 327 | '<input type="submit" name="cancel" value="%s" />', | ||
| 328 | $this->lang['strcancel'] | ||
| 329 | ) . \PHP_EOL; | ||
| 330 | echo '</form>' . \PHP_EOL; | ||
| 331 |         } else { | ||
| 332 | $this->coalesceArr($_POST, 'owner', ''); | ||
| 333 | |||
| 334 | $this->coalesceArr($_POST, 'dbcomment', ''); | ||
| 335 | |||
| 336 |             if (0 === $data->alterDatabase($_POST['oldname'], $_POST['newname'], $_POST['owner'], $_POST['dbcomment'])) { | ||
| 337 | $this->view->setReloadBrowser(true); | ||
| 338 | $this->doDefault($this->lang['strdatabasealtered']); | ||
| 339 |             } else { | ||
| 340 | $this->doDefault($this->lang['strdatabasealteredbad']); | ||
| 341 | } | ||
| 342 | } | ||
| 343 | } | ||
| 344 | |||
| 345 | /** | ||
| 346 | * Show confirmation of drop and perform actual drop. | ||
| 347 | * | ||
| 348 | * @param mixed $confirm | ||
| 349 | */ | ||
| 350 | public function doDrop($confirm) | ||
| 430 | } | ||
| 431 | } | ||
| 432 | //END DROP | ||
| 433 | } | ||
| 434 | } | ||
| 435 | |||
| 436 | // END FUNCTION | ||
| 437 | |||
| 438 | /** | ||
| 439 | * Displays a screen where they can enter a new database. | ||
| 440 | * | ||
| 441 | * @param mixed $msg | ||
| 442 | */ | ||
| 443 | public function doCreate($msg = ''): void | ||
| 444 |     { | ||
| 445 | $data = $this->misc->getDatabaseAccessor(); | ||
| 446 | |||
| 447 |         $this->printTrail('server'); | ||
| 448 | $this->printTitle($this->lang['strcreatedatabase'], 'pg.database.create'); | ||
| 449 | $this->printMsg($msg); | ||
| 450 | |||
| 451 | $this->coalesceArr($_POST, 'formName', ''); | ||
| 452 | |||
| 453 | // Default encoding is that in language file | ||
| 454 | $this->coalesceArr($_POST, 'formEncoding', ''); | ||
| 455 | $this->coalesceArr($_POST, 'formTemplate', 'template1'); | ||
| 456 | |||
| 457 | $this->coalesceArr($_POST, 'formSpc', ''); | ||
| 458 | |||
| 459 | $this->coalesceArr($_POST, 'formComment', ''); | ||
| 460 | |||
| 461 | // Fetch a list of databases in the cluster | ||
| 462 | $templatedbs = $data->getDatabases(false); | ||
| 463 | |||
| 464 | $tablespaces = null; | ||
| 465 | // Fetch all tablespaces from the database | ||
| 466 |         if ($data->hasTablespaces()) { | ||
| 467 | $tablespaces = $data->getTablespaces(); | ||
| 468 | } | ||
| 469 | |||
| 470 | echo '<form action="' . \containerInstance()->subFolder . '/src/views/alldb" method="post">' . \PHP_EOL; | ||
| 471 | echo '<table>' . \PHP_EOL; | ||
| 472 | echo \sprintf( | ||
| 473 | ' <tr> | ||
| 474 | <th class="data left required">%s</th>', | ||
| 475 | $this->lang['strname'] | ||
| 476 | ) . \PHP_EOL; | ||
| 477 | echo \sprintf( | ||
| 478 | ' <td class="data1"><input name="formName" size="32" maxlength="%s" value="', | ||
| 479 | $data->_maxNameLen | ||
| 480 | ), | ||
| 481 | \htmlspecialchars($_POST['formName']), "\" /></td>\n\t</tr>" . \PHP_EOL; | ||
| 482 | |||
| 483 | echo \sprintf( | ||
| 484 | ' <tr> | ||
| 485 | <th class="data left required">%s</th>', | ||
| 486 | $this->lang['strtemplatedb'] | ||
| 487 | ) . \PHP_EOL; | ||
| 488 | echo "\t\t<td class=\"data1\">" . \PHP_EOL; | ||
| 489 | echo "\t\t\t<select name=\"formTemplate\">" . \PHP_EOL; | ||
| 490 | // Always offer template0 and template1 | ||
| 491 | echo "\t\t\t\t<option value=\"template0\"", | ||
| 492 |         ('template0' === $_POST['formTemplate']) ? ' selected="selected"' : '', '>template0</option>' . \PHP_EOL; | ||
| 493 | echo "\t\t\t\t<option value=\"template1\"", | ||
| 494 |         ('template1' === $_POST['formTemplate']) ? ' selected="selected"' : '', '>template1</option>' . \PHP_EOL; | ||
| 495 | |||
| 496 |         while (!$templatedbs->EOF) { | ||
| 497 | $dbname = \htmlspecialchars($templatedbs->fields['datname']); | ||
| 498 | |||
| 499 |             if ('template1' !== $dbname) { | ||
| 500 | // filter out for $this->conf[show_system] users so we dont get duplicates | ||
| 501 | echo \sprintf( | ||
| 502 | ' <option value="%s"', | ||
| 503 | $dbname | ||
| 504 | ), | ||
| 505 | ($dbname === $_POST['formTemplate']) ? ' selected="selected"' : '', \sprintf( | ||
| 506 | '>%s</option>', | ||
| 507 | $dbname | ||
| 508 | ) . \PHP_EOL; | ||
| 509 | } | ||
| 510 | $templatedbs->moveNext(); | ||
| 511 | } | ||
| 512 | echo "\t\t\t</select>" . \PHP_EOL; | ||
| 513 | echo "\t\t</td>\n\t</tr>" . \PHP_EOL; | ||
| 514 | |||
| 515 | // ENCODING | ||
| 516 | echo \sprintf( | ||
| 517 | ' <tr> | ||
| 518 | <th class="data left required">%s</th>', | ||
| 519 | $this->lang['strencoding'] | ||
| 520 | ) . \PHP_EOL; | ||
| 521 | echo "\t\t<td class=\"data1\">" . \PHP_EOL; | ||
| 522 | echo "\t\t\t<select name=\"formEncoding\">" . \PHP_EOL; | ||
| 523 | echo "\t\t\t\t<option value=\"\"></option>" . \PHP_EOL; | ||
| 524 | |||
| 525 |         foreach ($data->codemap as $key) { | ||
| 526 | echo "\t\t\t\t<option value=\"", \htmlspecialchars($key), '"', | ||
| 527 | ($key === $_POST['formEncoding']) ? ' selected="selected"' : '', '>', | ||
| 528 | $this->misc->printVal($key), '</option>' . \PHP_EOL; | ||
| 529 | } | ||
| 530 | echo "\t\t\t</select>" . \PHP_EOL; | ||
| 531 | echo "\t\t</td>\n\t</tr>" . \PHP_EOL; | ||
| 532 | |||
| 533 |         if ($data->hasDatabaseCollation()) { | ||
| 534 | $this->coalesceArr($_POST, 'formCollate', ''); | ||
| 535 | |||
| 536 | $this->coalesceArr($_POST, 'formCType', ''); | ||
| 537 | |||
| 538 | // LC_COLLATE | ||
| 539 | echo \sprintf( | ||
| 540 | ' <tr> | ||
| 541 | <th class="data left">%s</th>', | ||
| 542 | $this->lang['strcollation'] | ||
| 543 | ) . \PHP_EOL; | ||
| 544 | echo "\t\t<td class=\"data1\">" . \PHP_EOL; | ||
| 545 | echo "\t\t\t<input name=\"formCollate\" value=\"", \htmlspecialchars($_POST['formCollate']), '" />' . \PHP_EOL; | ||
| 546 | echo "\t\t</td>\n\t</tr>" . \PHP_EOL; | ||
| 547 | |||
| 548 | // LC_CTYPE | ||
| 549 | echo \sprintf( | ||
| 550 | ' <tr> | ||
| 551 | <th class="data left">%s</th>', | ||
| 552 | $this->lang['strctype'] | ||
| 553 | ) . \PHP_EOL; | ||
| 554 | echo "\t\t<td class=\"data1\">" . \PHP_EOL; | ||
| 555 | echo "\t\t\t<input name=\"formCType\" value=\"", \htmlspecialchars($_POST['formCType']), '" />' . \PHP_EOL; | ||
| 556 | echo "\t\t</td>\n\t</tr>" . \PHP_EOL; | ||
| 557 | } | ||
| 558 | |||
| 559 | // Tablespace (if there are any) | ||
| 560 |         if ($data->hasTablespaces() && 0 < $tablespaces->recordCount()) { | ||
| 561 | echo \sprintf( | ||
| 562 | ' <tr> | ||
| 563 | <th class="data left">%s</th>', | ||
| 564 | $this->lang['strtablespace'] | ||
| 565 | ) . \PHP_EOL; | ||
| 566 | echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"formSpc\">" . \PHP_EOL; | ||
| 567 | // Always offer the default (empty) option | ||
| 568 | echo "\t\t\t\t<option value=\"\"", | ||
| 569 |             ('' === $_POST['formSpc']) ? ' selected="selected"' : '', '></option>' . \PHP_EOL; | ||
| 570 | // Display all other tablespaces | ||
| 571 |             while (!$tablespaces->EOF) { | ||
| 572 | $spcname = \htmlspecialchars($tablespaces->fields['spcname'] ?? ''); | ||
| 573 | echo \sprintf( | ||
| 574 | ' <option value="%s"', | ||
| 575 | $spcname | ||
| 576 | ), | ||
| 577 | ($spcname === $_POST['formSpc']) ? ' selected="selected"' : '', \sprintf( | ||
| 578 | '>%s</option>', | ||
| 579 | $spcname | ||
| 580 | ) . \PHP_EOL; | ||
| 581 | $tablespaces->moveNext(); | ||
| 582 | } | ||
| 583 | echo "\t\t\t</select>\n\t\t</td>\n\t</tr>" . \PHP_EOL; | ||
| 584 | } | ||
| 585 | |||
| 586 | // Comments (if available) | ||
| 587 |         if ($data->hasSharedComments()) { | ||
| 588 | echo \sprintf( | ||
| 589 | ' <tr> | ||
| 590 | <th class="data left">%s</th>', | ||
| 591 | $this->lang['strcomment'] | ||
| 592 | ) . \PHP_EOL; | ||
| 593 | echo "\t\t<td><textarea name=\"formComment\" rows=\"3\" cols=\"32\">", | ||
| 594 | \htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>" . \PHP_EOL; | ||
| 595 | } | ||
| 596 | |||
| 597 | echo '</table>' . \PHP_EOL; | ||
| 598 | echo '<p><input type="hidden" name="action" value="save_create" />' . \PHP_EOL; | ||
| 599 | echo $this->view->form; | ||
| 600 | echo \sprintf( | ||
| 601 | '<input type="submit" value="%s" />', | ||
| 602 | $this->lang['strcreate'] | ||
| 603 | ) . \PHP_EOL; | ||
| 604 | echo \sprintf( | ||
| 605 | '<input type="submit" name="cancel" value="%s" /></p>%s', | ||
| 606 | $this->lang['strcancel'], | ||
| 607 | \PHP_EOL | ||
| 608 | ); | ||
| 609 | echo '</form>' . \PHP_EOL; | ||
| 610 | } | ||
| 611 | |||
| 612 | /** | ||
| 613 | * Actually creates the new view in the database. | ||
| 614 | */ | ||
| 615 | public function doSaveCreate(): void | ||
| 616 |     { | ||
| 617 | $data = $this->misc->getDatabaseAccessor(); | ||
| 618 | |||
| 619 | // Default tablespace to null if it isn't set | ||
| 620 | $this->coalesceArr($_POST, 'formSpc', ''); | ||
| 621 | |||
| 622 | // Default comment to blank if it isn't set | ||
| 623 | $this->coalesceArr($_POST, 'formComment', ''); | ||
| 624 | |||
| 625 | // Default collate to blank if it isn't set | ||
| 626 | $this->coalesceArr($_POST, 'formCollate', ''); | ||
| 627 | |||
| 628 | // Default ctype to blank if it isn't set | ||
| 629 | $this->coalesceArr($_POST, 'formCType', ''); | ||
| 630 | |||
| 631 | // Check that they've given a name and a definition | ||
| 632 |         if ('' === $_POST['formName']) { | ||
| 633 | $this->doCreate($this->lang['strdatabaseneedsname']); | ||
| 634 |         } else { | ||
| 635 | $status = $data->createDatabase( | ||
| 636 | $_POST['formName'], | ||
| 637 | $_POST['formEncoding'], | ||
| 638 | $_POST['formSpc'], | ||
| 639 | $_POST['formComment'], | ||
| 640 | $_POST['formTemplate'], | ||
| 641 | $_POST['formCollate'], | ||
| 642 | $_POST['formCType'] | ||
| 643 | ); | ||
| 644 | |||
| 645 |             if (0 === $status) { | ||
| 646 | $this->view->setReloadBrowser(true); | ||
| 647 | $this->doDefault($this->lang['strdatabasecreated']); | ||
| 648 |             } else { | ||
| 649 | $this->doCreate($this->lang['strdatabasecreatedbad']); | ||
| 650 | } | ||
| 651 | } | ||
| 652 | } | ||
| 653 | |||
| 654 | /** | ||
| 655 | * Displays options for cluster download. | ||
| 656 | * | ||
| 657 | * @param mixed $msg | ||
| 658 | */ | ||
| 659 | public function doExport($msg = ''): void | ||
| 684 | } | ||
| 685 | } | ||
| 686 |