| Total Complexity | 103 |
| Total Lines | 1222 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like FulltextController 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 FulltextController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | class FulltextController extends BaseController |
||
| 17 | { |
||
| 18 | public $controller_title = 'strschemas'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Default method to render the controller according to the action parameter. |
||
| 22 | */ |
||
| 23 | public function render() |
||
| 135 | } |
||
| 136 | |||
| 137 | public function doDefault($msg = '') |
||
| 215 | } |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Generate XML for the browser tree. |
||
| 219 | */ |
||
| 220 | public function doTree() |
||
| 221 | { |
||
| 222 | $tabs = $this->misc->getNavTabs('fulltext'); |
||
| 223 | $items = $this->adjustTabsForTree($tabs); |
||
| 224 | |||
| 225 | $reqvars = $this->misc->getRequestVars('ftscfg'); |
||
| 226 | |||
| 227 | $attrs = [ |
||
| 228 | 'text' => Decorator::field('title'), |
||
| 229 | 'icon' => Decorator::field('icon'), |
||
| 230 | 'action' => Decorator::actionurl( |
||
| 231 | 'fulltext', |
||
| 232 | $reqvars, |
||
| 233 | Decorator::field('urlvars') |
||
| 234 | ), |
||
| 235 | 'branch' => Decorator::url( |
||
| 236 | 'fulltext', |
||
| 237 | $reqvars, |
||
| 238 | [ |
||
| 239 | 'action' => 'subtree', |
||
| 240 | 'what' => Decorator::field('icon'), // IZ: yeah, it's ugly, but I do not want to change navigation tabs arrays |
||
| 241 | ] |
||
| 242 | ), |
||
| 243 | ]; |
||
| 244 | |||
| 245 | return $this->printTree($items, $attrs, 'fts'); |
||
| 246 | } |
||
| 247 | |||
| 248 | public function doSubTree($what) |
||
| 249 | { |
||
| 250 | $data = $this->misc->getDatabaseAccessor(); |
||
| 251 | |||
| 252 | switch ($what) { |
||
| 253 | case 'FtsCfg': |
||
| 254 | $items = $data->getFtsConfigurations(false); |
||
| 255 | $urlvars = ['action' => 'viewconfig', 'ftscfg' => Decorator::field('name')]; |
||
| 256 | |||
| 257 | break; |
||
| 258 | case 'FtsDict': |
||
| 259 | $items = $data->getFtsDictionaries(false); |
||
| 260 | $urlvars = ['action' => 'viewdicts']; |
||
| 261 | |||
| 262 | break; |
||
| 263 | case 'FtsParser': |
||
| 264 | $items = $data->getFtsParsers(false); |
||
| 265 | $urlvars = ['action' => 'viewparsers']; |
||
| 266 | |||
| 267 | break; |
||
| 268 | default: |
||
| 269 | return; |
||
| 270 | } |
||
| 271 | |||
| 272 | $reqvars = $this->misc->getRequestVars('ftscfg'); |
||
| 273 | |||
| 274 | $attrs = [ |
||
| 275 | 'text' => Decorator::field('name'), |
||
| 276 | 'icon' => $what, |
||
| 277 | 'toolTip' => Decorator::field('comment'), |
||
| 278 | 'action' => Decorator::actionurl( |
||
| 279 | 'fulltext', |
||
| 280 | $reqvars, |
||
| 281 | $urlvars |
||
| 282 | ), |
||
| 283 | 'branch' => Decorator::ifempty( |
||
| 284 | Decorator::field('branch'), |
||
| 285 | '', |
||
| 286 | Decorator::url( |
||
| 287 | 'fulltext', |
||
| 288 | $reqvars, |
||
| 289 | [ |
||
| 290 | 'action' => 'subtree', |
||
| 291 | 'ftscfg' => Decorator::field('name'), |
||
| 292 | ] |
||
| 293 | ) |
||
| 294 | ), |
||
| 295 | ]; |
||
| 296 | |||
| 297 | return $this->printTree($items, $attrs, strtolower($what)); |
||
| 298 | } |
||
| 299 | |||
| 300 | public function doDropConfig($confirm) |
||
| 301 | { |
||
| 302 | $data = $this->misc->getDatabaseAccessor(); |
||
| 303 | |||
| 304 | if ($confirm) { |
||
| 305 | $this->printTrail('ftscfg'); |
||
| 306 | $this->printTitle($this->lang['strdrop'], 'pg.ftscfg.drop'); |
||
| 307 | |||
| 308 | echo '<p>', sprintf($this->lang['strconfdropftsconfig'], $this->misc->printVal($_REQUEST['ftscfg'])), "</p>\n"; |
||
| 309 | |||
| 310 | echo '<form action="' . \SUBFOLDER . "/src/views/fulltext\" method=\"post\">\n"; |
||
| 311 | echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$this->lang['strcascade']}</label></p>\n"; |
||
| 312 | echo "<p><input type=\"hidden\" name=\"action\" value=\"dropconfig\" />\n"; |
||
| 313 | echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), "\" />\n"; |
||
| 314 | echo '<input type="hidden" name="ftscfg" value="', htmlspecialchars($_REQUEST['ftscfg']), "\" />\n"; |
||
| 315 | echo $this->misc->form; |
||
| 316 | echo "<input type=\"submit\" name=\"drop\" value=\"{$this->lang['strdrop']}\" />\n"; |
||
| 317 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
| 318 | echo "</form>\n"; |
||
| 319 | } else { |
||
| 320 | $status = $data->dropFtsConfiguration($_POST['ftscfg'], isset($_POST['cascade'])); |
||
| 321 | if (0 == $status) { |
||
| 322 | $this->misc->setReloadBrowser(true); |
||
| 323 | $this->doDefault($this->lang['strftsconfigdropped']); |
||
| 324 | } else { |
||
| 325 | $this->doDefault($this->lang['strftsconfigdroppedbad']); |
||
| 326 | } |
||
| 327 | } |
||
| 328 | } |
||
| 329 | |||
| 330 | public function doDropDict($confirm) |
||
| 358 | } |
||
| 359 | } |
||
| 360 | } |
||
| 361 | |||
| 362 | /** |
||
| 363 | * Displays a screen where one can enter a new FTS configuration. |
||
| 364 | * |
||
| 365 | * @param mixed $msg |
||
| 366 | */ |
||
| 367 | public function doCreateConfig($msg = '') |
||
| 368 | { |
||
| 369 | $data = $this->misc->getDatabaseAccessor(); |
||
| 370 | |||
| 371 | $this->coalesceArr($_POST, 'formName', ''); |
||
| 372 | |||
| 373 | $this->coalesceArr($_POST, 'formParser', ''); |
||
| 374 | |||
| 375 | $this->coalesceArr($_POST, 'formTemplate', ''); |
||
| 376 | |||
| 377 | $this->coalesceArr($_POST, 'formWithMap', ''); |
||
| 378 | |||
| 379 | $this->coalesceArr($_POST, 'formComment', ''); |
||
| 380 | |||
| 381 | // Fetch all FTS configurations from the database |
||
| 382 | $ftscfgs = $data->getFtsConfigurations(); |
||
| 383 | // Fetch all FTS parsers from the database |
||
| 384 | $ftsparsers = $data->getFtsParsers(); |
||
| 385 | |||
| 386 | $this->printTrail('schema'); |
||
| 387 | $this->printTitle($this->lang['strftscreateconfig'], 'pg.ftscfg.create'); |
||
| 388 | $this->printMsg($msg); |
||
| 389 | |||
| 390 | echo '<form action="' . \SUBFOLDER . "/src/views/fulltext\" method=\"post\">\n"; |
||
| 391 | echo "<table>\n"; |
||
| 392 | // conf name |
||
| 393 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strname']}</th>\n"; |
||
| 394 | echo "\t\t<td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 395 | htmlspecialchars($_POST['formName']), "\" /></td>\n\t</tr>\n"; |
||
| 396 | |||
| 397 | // Template |
||
| 398 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strftstemplate']}</th>\n"; |
||
| 399 | echo "\t\t<td class=\"data1\">"; |
||
| 400 | |||
| 401 | $tpls = []; |
||
| 402 | $tplsel = ''; |
||
| 403 | while (!$ftscfgs->EOF) { |
||
| 404 | $data->fieldClean($ftscfgs->fields['schema']); |
||
| 405 | $data->fieldClean($ftscfgs->fields['name']); |
||
| 406 | $tplname = $ftscfgs->fields['schema'] . '.' . $ftscfgs->fields['name']; |
||
| 407 | $tpls[$tplname] = serialize([ |
||
| 408 | 'name' => $ftscfgs->fields['name'], |
||
| 409 | 'schema' => $ftscfgs->fields['schema'], |
||
| 410 | ]); |
||
| 411 | if ($_POST['formTemplate'] == $tpls[$tplname]) { |
||
| 412 | $tplsel = htmlspecialchars($tpls[$tplname]); |
||
| 413 | } |
||
| 414 | $ftscfgs->moveNext(); |
||
| 415 | } |
||
| 416 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($tpls, 'formTemplate', true, $tplsel, false); |
||
| 417 | echo "\n\t\t</td>\n\t</tr>\n"; |
||
| 418 | |||
| 419 | // Parser |
||
| 420 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strftsparser']}</th>\n"; |
||
| 421 | echo "\t\t<td class=\"data1\">\n"; |
||
| 422 | $ftsparsers_ = []; |
||
| 423 | $ftsparsel = ''; |
||
| 424 | while (!$ftsparsers->EOF) { |
||
| 425 | $data->fieldClean($ftsparsers->fields['schema']); |
||
| 426 | $data->fieldClean($ftsparsers->fields['name']); |
||
| 427 | $parsername = $ftsparsers->fields['schema'] . '.' . $ftsparsers->fields['name']; |
||
| 428 | |||
| 429 | $ftsparsers_[$parsername] = serialize([ |
||
| 430 | 'parser' => $ftsparsers->fields['name'], |
||
| 431 | 'schema' => $ftsparsers->fields['schema'], |
||
| 432 | ]); |
||
| 433 | if ($_POST['formParser'] == $ftsparsers_[$parsername]) { |
||
| 434 | $ftsparsel = htmlspecialchars($ftsparsers_[$parsername]); |
||
| 435 | } |
||
| 436 | $ftsparsers->moveNext(); |
||
| 437 | } |
||
| 438 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($ftsparsers_, 'formParser', true, $ftsparsel, false); |
||
| 439 | echo "\n\t\t</td>\n\t</tr>\n"; |
||
| 440 | |||
| 441 | // Comment |
||
| 442 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strcomment']}</th>\n"; |
||
| 443 | echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\">", |
||
| 444 | htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n"; |
||
| 445 | |||
| 446 | echo "</table>\n"; |
||
| 447 | echo "<p>\n"; |
||
| 448 | echo "<input type=\"hidden\" name=\"action\" value=\"createconfig\" />\n"; |
||
| 449 | echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), "\" />\n"; |
||
| 450 | echo $this->misc->form; |
||
| 451 | echo "<input type=\"submit\" name=\"create\" value=\"{$this->lang['strcreate']}\" />\n"; |
||
| 452 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />\n"; |
||
| 453 | echo "</p>\n"; |
||
| 454 | echo "</form>\n"; |
||
| 455 | } |
||
| 456 | |||
| 457 | /** |
||
| 458 | * Actually creates the new FTS configuration in the database. |
||
| 459 | */ |
||
| 460 | public function doSaveCreateConfig() |
||
| 461 | { |
||
| 462 | $data = $this->misc->getDatabaseAccessor(); |
||
| 463 | |||
| 464 | $err = ''; |
||
| 465 | // Check that they've given a name |
||
| 466 | if ('' == $_POST['formName']) { |
||
| 467 | $err .= "{$this->lang['strftsconfigneedsname']}<br />"; |
||
| 468 | } |
||
| 469 | |||
| 470 | if (('' != $_POST['formParser']) && ('' != $_POST['formTemplate'])) { |
||
| 471 | $err .= "{$this->lang['strftscantparsercopy']}<br />"; |
||
| 472 | } |
||
| 473 | |||
| 474 | if ($err !== '') { |
||
| 475 | return $this->doCreateConfig($err); |
||
| 476 | } |
||
| 477 | |||
| 478 | if ('' != $_POST['formParser']) { |
||
| 479 | $formParser = unserialize($_POST['formParser']); |
||
| 480 | } else { |
||
| 481 | $formParser = ''; |
||
| 482 | } |
||
| 483 | |||
| 484 | if ('' != $_POST['formTemplate']) { |
||
| 485 | $formTemplate = unserialize($_POST['formTemplate']); |
||
| 486 | } else { |
||
| 487 | $formTemplate = ''; |
||
| 488 | } |
||
| 489 | |||
| 490 | $status = $data->createFtsConfiguration($_POST['formName'], $formParser, $formTemplate, $_POST['formComment']); |
||
| 491 | if (0 == $status) { |
||
| 492 | $this->misc->setReloadBrowser(true); |
||
| 493 | $this->doDefault($this->lang['strftsconfigcreated']); |
||
| 494 | } else { |
||
| 495 | $this->doCreateConfig($this->lang['strftsconfigcreatedbad']); |
||
| 496 | } |
||
| 497 | } |
||
| 498 | |||
| 499 | /** |
||
| 500 | * Display a form to permit editing FTS configuration properies. |
||
| 501 | * |
||
| 502 | * @param mixed $msg |
||
| 503 | */ |
||
| 504 | public function doAlterConfig($msg = '') |
||
| 505 | { |
||
| 506 | $data = $this->misc->getDatabaseAccessor(); |
||
| 507 | |||
| 508 | $this->printTrail('ftscfg'); |
||
| 509 | $this->printTitle($this->lang['stralter'], 'pg.ftscfg.alter'); |
||
| 510 | $this->printMsg($msg); |
||
| 511 | |||
| 512 | $ftscfg = $data->getFtsConfigurationByName($_REQUEST['ftscfg']); |
||
| 513 | if ($ftscfg->recordCount() > 0) { |
||
| 514 | $this->coalesceArr($_POST, 'formComment', $ftscfg->fields['comment']); |
||
| 515 | |||
| 516 | $this->coalesceArr($_POST, 'ftscfg', $_REQUEST['ftscfg']); |
||
| 517 | |||
| 518 | $this->coalesceArr($_POST, 'formName', $_REQUEST['ftscfg']); |
||
| 519 | |||
| 520 | $this->coalesceArr($_POST, 'formParser', ''); |
||
| 521 | |||
| 522 | // Fetch all FTS parsers from the database |
||
| 523 | $ftsparsers = $data->getFtsParsers(); |
||
| 524 | |||
| 525 | echo '<form action="' . \SUBFOLDER . "/src/views/fulltext\" method=\"post\">\n"; |
||
| 526 | echo "<table>\n"; |
||
| 527 | |||
| 528 | echo "\t<tr>\n"; |
||
| 529 | echo "\t\t<th class=\"data left required\">{$this->lang['strname']}</th>\n"; |
||
| 530 | echo "\t\t<td class=\"data1\">"; |
||
| 531 | echo "\t\t\t<input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 532 | htmlspecialchars($_POST['formName']), "\" />\n"; |
||
| 533 | echo "\t\t</td>\n"; |
||
| 534 | echo "\t</tr>\n"; |
||
| 535 | |||
| 536 | // Comment |
||
| 537 | echo "\t<tr>\n"; |
||
| 538 | echo "\t\t<th class=\"data\">{$this->lang['strcomment']}</th>\n"; |
||
| 539 | echo "\t\t<td class=\"data1\"><textarea cols=\"32\" rows=\"3\"name=\"formComment\">", htmlspecialchars($_POST['formComment']), "</textarea></td>\n"; |
||
| 540 | echo "\t</tr>\n"; |
||
| 541 | echo "</table>\n"; |
||
| 542 | echo "<p><input type=\"hidden\" name=\"action\" value=\"alterconfig\" />\n"; |
||
| 543 | echo '<input type="hidden" name="ftscfg" value="', htmlspecialchars($_POST['ftscfg']), "\" />\n"; |
||
| 544 | echo $this->misc->form; |
||
| 545 | echo "<input type=\"submit\" name=\"alter\" value=\"{$this->lang['stralter']}\" />\n"; |
||
| 546 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
| 547 | echo "</form>\n"; |
||
| 548 | } else { |
||
| 549 | echo "<p>{$this->lang['strnodata']}</p>\n"; |
||
| 550 | } |
||
| 551 | } |
||
| 552 | |||
| 553 | /** |
||
| 554 | * Save the form submission containing changes to a FTS configuration. |
||
| 555 | */ |
||
| 556 | public function doSaveAlterConfig() |
||
| 557 | { |
||
| 558 | $data = $this->misc->getDatabaseAccessor(); |
||
| 559 | $status = $data->updateFtsConfiguration($_POST['ftscfg'], $_POST['formComment'], $_POST['formName']); |
||
| 560 | if (0 == $status) { |
||
| 561 | $this->doDefault($this->lang['strftsconfigaltered']); |
||
| 562 | } else { |
||
| 563 | $this->doAlterConfig($this->lang['strftsconfigalteredbad']); |
||
| 564 | } |
||
| 565 | } |
||
| 566 | |||
| 567 | /** |
||
| 568 | * View list of FTS parsers. |
||
| 569 | * |
||
| 570 | * @param mixed $msg |
||
| 571 | */ |
||
| 572 | public function doViewParsers($msg = '') |
||
| 573 | { |
||
| 574 | $data = $this->misc->getDatabaseAccessor(); |
||
| 575 | |||
| 576 | $this->printTrail('schema'); |
||
| 577 | $this->printTabs('schema', 'fulltext'); |
||
| 578 | $this->printTabs('fulltext', 'ftsparsers'); |
||
| 579 | $this->printMsg($msg); |
||
| 580 | |||
| 581 | $parsers = $data->getFtsParsers(false); |
||
| 582 | |||
| 583 | $columns = [ |
||
| 584 | 'schema' => [ |
||
| 585 | 'title' => $this->lang['strschema'], |
||
| 586 | 'field' => Decorator::field('schema'), |
||
| 587 | ], |
||
| 588 | 'name' => [ |
||
| 589 | 'title' => $this->lang['strname'], |
||
| 590 | 'field' => Decorator::field('name'), |
||
| 591 | ], |
||
| 592 | 'comment' => [ |
||
| 593 | 'title' => $this->lang['strcomment'], |
||
| 594 | 'field' => Decorator::field('comment'), |
||
| 595 | ], |
||
| 596 | ]; |
||
| 597 | |||
| 598 | $actions = []; |
||
| 599 | |||
| 600 | echo $this->printTable($parsers, $columns, $actions, 'fulltext-viewparsers', $this->lang['strftsnoparsers']); |
||
| 601 | |||
| 602 | //TODO: navlink to "create parser" |
||
| 603 | } |
||
| 604 | |||
| 605 | /** |
||
| 606 | * View list of FTS dictionaries. |
||
| 607 | * |
||
| 608 | * @param mixed $msg |
||
| 609 | */ |
||
| 610 | public function doViewDicts($msg = '') |
||
| 611 | { |
||
| 612 | $data = $this->misc->getDatabaseAccessor(); |
||
| 613 | |||
| 614 | $this->printTrail('schema'); |
||
| 615 | $this->printTabs('schema', 'fulltext'); |
||
| 616 | $this->printTabs('fulltext', 'ftsdicts'); |
||
| 617 | $this->printMsg($msg); |
||
| 618 | |||
| 619 | $dicts = $data->getFtsDictionaries(false); |
||
| 620 | |||
| 621 | $columns = [ |
||
| 622 | 'schema' => [ |
||
| 623 | 'title' => $this->lang['strschema'], |
||
| 624 | 'field' => Decorator::field('schema'), |
||
| 625 | ], |
||
| 626 | 'name' => [ |
||
| 627 | 'title' => $this->lang['strname'], |
||
| 628 | 'field' => Decorator::field('name'), |
||
| 629 | ], |
||
| 630 | 'actions' => [ |
||
| 631 | 'title' => $this->lang['stractions'], |
||
| 632 | ], |
||
| 633 | 'comment' => [ |
||
| 634 | 'title' => $this->lang['strcomment'], |
||
| 635 | 'field' => Decorator::field('comment'), |
||
| 636 | ], |
||
| 637 | ]; |
||
| 638 | |||
| 639 | $actions = [ |
||
| 640 | 'drop' => [ |
||
| 641 | 'content' => $this->lang['strdrop'], |
||
| 642 | 'attr' => [ |
||
| 643 | 'href' => [ |
||
| 644 | 'url' => 'fulltext', |
||
| 645 | 'urlvars' => [ |
||
| 646 | 'action' => 'dropdict', |
||
| 647 | 'ftsdict' => Decorator::field('name'), |
||
| 648 | ], |
||
| 649 | ], |
||
| 650 | ], |
||
| 651 | ], |
||
| 652 | 'alter' => [ |
||
| 653 | 'content' => $this->lang['stralter'], |
||
| 654 | 'attr' => [ |
||
| 655 | 'href' => [ |
||
| 656 | 'url' => 'fulltext', |
||
| 657 | 'urlvars' => [ |
||
| 658 | 'action' => 'alterdict', |
||
| 659 | 'ftsdict' => Decorator::field('name'), |
||
| 660 | ], |
||
| 661 | ], |
||
| 662 | ], |
||
| 663 | ], |
||
| 664 | ]; |
||
| 665 | |||
| 666 | echo $this->printTable($dicts, $columns, $actions, 'fulltext-viewdicts', $this->lang['strftsnodicts']); |
||
| 667 | |||
| 668 | $navlinks = [ |
||
| 669 | 'createdict' => [ |
||
| 670 | 'attr' => [ |
||
| 671 | 'href' => [ |
||
| 672 | 'url' => 'fulltext', |
||
| 673 | 'urlvars' => [ |
||
| 674 | 'action' => 'createdict', |
||
| 675 | 'server' => $_REQUEST['server'], |
||
| 676 | 'database' => $_REQUEST['database'], |
||
| 677 | 'schema' => $_REQUEST['schema'], |
||
| 678 | ], |
||
| 679 | ], |
||
| 680 | ], |
||
| 681 | 'content' => $this->lang['strftscreatedict'], |
||
| 682 | ], |
||
| 683 | ]; |
||
| 684 | |||
| 685 | $this->printNavLinks($navlinks, 'fulltext-viewdicts', get_defined_vars()); |
||
| 686 | } |
||
| 687 | |||
| 688 | /** |
||
| 689 | * View details of FTS configuration given. |
||
| 690 | * |
||
| 691 | * @param mixed $ftscfg |
||
| 692 | * @param mixed $msg |
||
| 693 | */ |
||
| 694 | public function doViewConfig($ftscfg, $msg = '') |
||
| 695 | { |
||
| 696 | $data = $this->misc->getDatabaseAccessor(); |
||
| 697 | |||
| 698 | $this->printTrail('ftscfg'); |
||
| 699 | $this->printTabs('schema', 'fulltext'); |
||
| 700 | $this->printTabs('fulltext', 'ftsconfigs'); |
||
| 701 | $this->printMsg($msg); |
||
| 702 | |||
| 703 | echo "<h3>{$this->lang['strftsconfigmap']}</h3>\n"; |
||
| 704 | |||
| 705 | $map = $data->getFtsConfigurationMap($ftscfg); |
||
| 706 | |||
| 707 | $columns = [ |
||
| 708 | 'name' => [ |
||
| 709 | 'title' => $this->lang['strftsmapping'], |
||
| 710 | 'field' => Decorator::field('name'), |
||
| 711 | ], |
||
| 712 | 'dictionaries' => [ |
||
| 713 | 'title' => $this->lang['strftsdicts'], |
||
| 714 | 'field' => Decorator::field('dictionaries'), |
||
| 715 | ], |
||
| 716 | 'actions' => [ |
||
| 717 | 'title' => $this->lang['stractions'], |
||
| 718 | ], |
||
| 719 | 'comment' => [ |
||
| 720 | 'title' => $this->lang['strcomment'], |
||
| 721 | 'field' => Decorator::field('description'), |
||
| 722 | ], |
||
| 723 | ]; |
||
| 724 | |||
| 725 | $actions = [ |
||
| 726 | 'drop' => [ |
||
| 727 | 'multiaction' => 'dropmapping', |
||
| 728 | 'content' => $this->lang['strdrop'], |
||
| 729 | 'attr' => [ |
||
| 730 | 'href' => [ |
||
| 731 | 'url' => 'fulltext', |
||
| 732 | 'urlvars' => [ |
||
| 733 | 'action' => 'dropmapping', |
||
| 734 | 'mapping' => Decorator::field('name'), |
||
| 735 | 'ftscfg' => Decorator::field('cfgname'), |
||
| 736 | ], |
||
| 737 | ], |
||
| 738 | ], |
||
| 739 | ], |
||
| 740 | 'alter' => [ |
||
| 741 | 'content' => $this->lang['stralter'], |
||
| 742 | 'attr' => [ |
||
| 743 | 'href' => [ |
||
| 744 | 'url' => 'fulltext', |
||
| 745 | 'urlvars' => [ |
||
| 746 | 'action' => 'altermapping', |
||
| 747 | 'mapping' => Decorator::field('name'), |
||
| 748 | 'ftscfg' => Decorator::field('cfgname'), |
||
| 749 | ], |
||
| 750 | ], |
||
| 751 | ], |
||
| 752 | ], |
||
| 753 | 'multiactions' => [ |
||
| 754 | 'keycols' => ['mapping' => 'name'], |
||
| 755 | 'url' => 'fulltext', |
||
| 756 | 'default' => null, |
||
| 757 | 'vars' => ['ftscfg' => $ftscfg], |
||
| 758 | ], |
||
| 759 | ]; |
||
| 760 | |||
| 761 | echo $this->printTable($map, $columns, $actions, 'fulltext-viewconfig', $this->lang['strftsemptymap']); |
||
| 762 | |||
| 763 | $navlinks = [ |
||
| 764 | 'addmapping' => [ |
||
| 765 | 'attr' => [ |
||
| 766 | 'href' => [ |
||
| 767 | 'url' => 'fulltext', |
||
| 768 | 'urlvars' => [ |
||
| 769 | 'action' => 'addmapping', |
||
| 770 | 'server' => $_REQUEST['server'], |
||
| 771 | 'database' => $_REQUEST['database'], |
||
| 772 | 'schema' => $_REQUEST['schema'], |
||
| 773 | 'ftscfg' => $ftscfg, |
||
| 774 | ], |
||
| 775 | ], |
||
| 776 | ], |
||
| 777 | 'content' => $this->lang['strftsaddmapping'], |
||
| 778 | ], |
||
| 779 | ]; |
||
| 780 | |||
| 781 | $this->printNavLinks($navlinks, 'fulltext-viewconfig', get_defined_vars()); |
||
| 782 | } |
||
| 783 | |||
| 784 | /** |
||
| 785 | * Displays a screen where one can enter a details of a new FTS dictionary. |
||
| 786 | * |
||
| 787 | * @param mixed $msg |
||
| 788 | */ |
||
| 789 | public function doCreateDict($msg = '') |
||
| 790 | { |
||
| 791 | $data = $this->misc->getDatabaseAccessor(); |
||
| 792 | |||
| 793 | $this->coalesceArr($_POST, 'formName', ''); |
||
| 794 | |||
| 795 | $this->coalesceArr($_POST, 'formIsTemplate', false); |
||
| 796 | |||
| 797 | $this->coalesceArr($_POST, 'formTemplate', ''); |
||
| 798 | |||
| 799 | $this->coalesceArr($_POST, 'formLexize', ''); |
||
| 800 | |||
| 801 | $this->coalesceArr($_POST, 'formInit', ''); |
||
| 802 | |||
| 803 | $this->coalesceArr($_POST, 'formOption', ''); |
||
| 804 | |||
| 805 | $this->coalesceArr($_POST, 'formComment', ''); |
||
| 806 | |||
| 807 | // Fetch all FTS dictionaries from the database |
||
| 808 | $ftstpls = $data->getFtsDictionaryTemplates(); |
||
| 809 | |||
| 810 | $this->printTrail('schema'); |
||
| 811 | // TODO: create doc links |
||
| 812 | $this->printTitle($this->lang['strftscreatedict'], 'pg.ftsdict.create'); |
||
| 813 | $this->printMsg($msg); |
||
| 814 | |||
| 815 | echo '<form action="' . \SUBFOLDER . "/src/views/fulltext\" method=\"post\">\n"; |
||
| 816 | echo "<table>\n"; |
||
| 817 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strname']}</th>\n"; |
||
| 818 | echo "\t\t<td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 819 | htmlspecialchars($_POST['formName']), '" /> ', |
||
| 820 | '<input type="checkbox" name="formIsTemplate" id="formIsTemplate"', $_POST['formIsTemplate'] ? ' checked="checked" ' : '', " />\n", |
||
| 821 | "<label for=\"formIsTemplate\">{$this->lang['strftscreatedicttemplate']}</label></td>\n\t</tr>\n"; |
||
| 822 | |||
| 823 | // Template |
||
| 824 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strftstemplate']}</th>\n"; |
||
| 825 | echo "\t\t<td class=\"data1\">"; |
||
| 826 | $tpls = []; |
||
| 827 | $tplsel = ''; |
||
| 828 | while (!$ftstpls->EOF) { |
||
| 829 | $data->fieldClean($ftstpls->fields['schema']); |
||
| 830 | $data->fieldClean($ftstpls->fields['name']); |
||
| 831 | $tplname = $ftstpls->fields['schema'] . '.' . $ftstpls->fields['name']; |
||
| 832 | $tpls[$tplname] = serialize([ |
||
| 833 | 'name' => $ftstpls->fields['name'], |
||
| 834 | 'schema' => $ftstpls->fields['schema'], |
||
| 835 | ]); |
||
| 836 | if ($_POST['formTemplate'] == $tpls[$tplname]) { |
||
| 837 | $tplsel = htmlspecialchars($tpls[$tplname]); |
||
| 838 | } |
||
| 839 | $ftstpls->moveNext(); |
||
| 840 | } |
||
| 841 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($tpls, 'formTemplate', true, $tplsel, false); |
||
| 842 | echo "\n\t\t</td>\n\t</tr>\n"; |
||
| 843 | |||
| 844 | // TODO: what about maxlengths? |
||
| 845 | // Lexize |
||
| 846 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strftslexize']}</th>\n"; |
||
| 847 | echo "\t\t<td class=\"data1\"><input name=\"formLexize\" size=\"32\" maxlength=\"1000\" value=\"", |
||
| 848 | htmlspecialchars($_POST['formLexize']), '" ', isset($_POST['formIsTemplate']) ? '' : ' disabled="disabled" ', |
||
| 849 | "/></td>\n\t</tr>\n"; |
||
| 850 | |||
| 851 | // Init |
||
| 852 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strftsinit']}</th>\n"; |
||
| 853 | echo "\t\t<td class=\"data1\"><input name=\"formInit\" size=\"32\" maxlength=\"1000\" value=\"", |
||
| 854 | htmlspecialchars($_POST['formInit']), '"', @$_POST['formIsTemplate'] ? '' : ' disabled="disabled" ', |
||
| 855 | "/></td>\n\t</tr>\n"; |
||
| 856 | |||
| 857 | // Option |
||
| 858 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strftsoptionsvalues']}</th>\n"; |
||
| 859 | echo "\t\t<td class=\"data1\"><input name=\"formOption\" size=\"32\" maxlength=\"1000\" value=\"", |
||
| 860 | htmlspecialchars($_POST['formOption']), "\" /></td>\n\t</tr>\n"; |
||
| 861 | |||
| 862 | // Comment |
||
| 863 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strcomment']}</th>\n"; |
||
| 864 | echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\">", |
||
| 865 | htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n"; |
||
| 866 | |||
| 867 | echo "</table>\n"; |
||
| 868 | echo "<p>\n"; |
||
| 869 | echo "<input type=\"hidden\" name=\"action\" value=\"createdict\" />\n"; |
||
| 870 | echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), "\" />\n"; |
||
| 871 | echo $this->misc->form; |
||
| 872 | echo "<input type=\"submit\" name=\"create\" value=\"{$this->lang['strcreate']}\" />\n"; |
||
| 873 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />\n"; |
||
| 874 | echo "</p>\n"; |
||
| 875 | echo "</form>\n", |
||
| 876 | "<script type=\"text/javascript\"> |
||
| 877 | function templateOpts() { |
||
| 878 | isTpl = document.getElementsByName('formIsTemplate')[0].checked; |
||
| 879 | document.getElementsByName('formTemplate')[0].disabled = isTpl; |
||
| 880 | document.getElementsByName('formOption')[0].disabled = isTpl; |
||
| 881 | document.getElementsByName('formLexize')[0].disabled = !isTpl; |
||
| 882 | document.getElementsByName('formInit')[0].disabled = !isTpl; |
||
| 883 | } |
||
| 884 | |||
| 885 | document.getElementsByName('formIsTemplate')[0].onchange = templateOpts; |
||
| 886 | |||
| 887 | templateOpts(); |
||
| 888 | </script>\n"; |
||
| 889 | } |
||
| 890 | |||
| 891 | /** |
||
| 892 | * Actually creates the new FTS dictionary in the database. |
||
| 893 | */ |
||
| 894 | public function doSaveCreateDict() |
||
| 895 | { |
||
| 896 | $data = $this->misc->getDatabaseAccessor(); |
||
| 897 | |||
| 898 | // Check that they've given a name |
||
| 899 | if ('' == $_POST['formName']) { |
||
| 900 | $this->doCreateDict($this->lang['strftsdictneedsname']); |
||
| 901 | } else { |
||
| 902 | $this->coalesceArr($_POST, 'formIsTemplate', false); |
||
| 903 | |||
| 904 | if (isset($_POST['formTemplate'])) { |
||
| 905 | $formTemplate = unserialize($_POST['formTemplate']); |
||
| 906 | } else { |
||
| 907 | $formTemplate = ''; |
||
| 908 | } |
||
| 909 | |||
| 910 | $this->coalesceArr($_POST, 'formLexize', ''); |
||
| 911 | |||
| 912 | $this->coalesceArr($_POST, 'formInit', ''); |
||
| 913 | |||
| 914 | $this->coalesceArr($_POST, 'formOption', ''); |
||
| 915 | |||
| 916 | $status = $data->createFtsDictionary( |
||
| 917 | $_POST['formName'], |
||
| 918 | $_POST['formIsTemplate'], |
||
| 919 | $formTemplate, |
||
| 920 | $_POST['formLexize'], |
||
| 921 | $_POST['formInit'], |
||
| 922 | $_POST['formOption'], |
||
| 923 | $_POST['formComment'] |
||
| 924 | ); |
||
| 925 | |||
| 926 | if (0 == $status) { |
||
| 927 | $this->misc->setReloadBrowser(true); |
||
| 928 | $this->doViewDicts($this->lang['strftsdictcreated']); |
||
| 929 | } else { |
||
| 930 | $this->doCreateDict($this->lang['strftsdictcreatedbad']); |
||
| 931 | } |
||
| 932 | } |
||
| 933 | } |
||
| 934 | |||
| 935 | /** |
||
| 936 | * Display a form to permit editing FTS dictionary properies. |
||
| 937 | * |
||
| 938 | * @param mixed $msg |
||
| 939 | */ |
||
| 940 | public function doAlterDict($msg = '') |
||
| 941 | { |
||
| 942 | $data = $this->misc->getDatabaseAccessor(); |
||
| 943 | |||
| 944 | $this->printTrail('ftscfg'); // TODO: change to smth related to dictionary |
||
| 945 | $this->printTitle($this->lang['stralter'], 'pg.ftsdict.alter'); |
||
| 946 | $this->printMsg($msg); |
||
| 947 | |||
| 948 | $ftsdict = $data->getFtsDictionaryByName($_REQUEST['ftsdict']); |
||
| 949 | if ($ftsdict->recordCount() > 0) { |
||
| 950 | $this->coalesceArr($_POST, 'formComment', $ftsdict->fields['comment']); |
||
| 951 | |||
| 952 | $this->coalesceArr($_POST, 'ftsdict', $_REQUEST['ftsdict']); |
||
| 953 | |||
| 954 | $this->coalesceArr($_POST, 'formName', $_REQUEST['ftsdict']); |
||
| 955 | |||
| 956 | echo '<form action="' . \SUBFOLDER . "/src/views/fulltext\" method=\"post\">\n"; |
||
| 957 | echo "<table>\n"; |
||
| 958 | |||
| 959 | echo "\t<tr>\n"; |
||
| 960 | echo "\t\t<th class=\"data left required\">{$this->lang['strname']}</th>\n"; |
||
| 961 | echo "\t\t<td class=\"data1\">"; |
||
| 962 | echo "\t\t\t<input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 963 | htmlspecialchars($_POST['formName']), "\" />\n"; |
||
| 964 | echo "\t\t</td>\n"; |
||
| 965 | echo "\t</tr>\n"; |
||
| 966 | |||
| 967 | // Comment |
||
| 968 | echo "\t<tr>\n"; |
||
| 969 | echo "\t\t<th class=\"data\">{$this->lang['strcomment']}</th>\n"; |
||
| 970 | echo "\t\t<td class=\"data1\"><textarea cols=\"32\" rows=\"3\"name=\"formComment\">", htmlspecialchars($_POST['formComment']), "</textarea></td>\n"; |
||
| 971 | echo "\t</tr>\n"; |
||
| 972 | echo "</table>\n"; |
||
| 973 | echo "<p><input type=\"hidden\" name=\"action\" value=\"alterdict\" />\n"; |
||
| 974 | echo '<input type="hidden" name="ftsdict" value="', htmlspecialchars($_POST['ftsdict']), "\" />\n"; |
||
| 975 | echo "<input type=\"hidden\" name=\"prev_action\" value=\"viewdicts\" /></p>\n"; |
||
| 976 | echo $this->misc->form; |
||
| 977 | echo "<input type=\"submit\" name=\"alter\" value=\"{$this->lang['stralter']}\" />\n"; |
||
| 978 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
| 979 | echo "</form>\n"; |
||
| 980 | } else { |
||
| 981 | echo "<p>{$this->lang['strnodata']}</p>\n"; |
||
| 982 | } |
||
| 983 | } |
||
| 984 | |||
| 985 | /** |
||
| 986 | * Save the form submission containing changes to a FTS dictionary. |
||
| 987 | */ |
||
| 988 | public function doSaveAlterDict() |
||
| 989 | { |
||
| 990 | $data = $this->misc->getDatabaseAccessor(); |
||
| 991 | |||
| 992 | $status = $data->updateFtsDictionary($_POST['ftsdict'], $_POST['formComment'], $_POST['formName']); |
||
| 993 | if (0 == $status) { |
||
| 994 | $this->doViewDicts($this->lang['strftsdictaltered']); |
||
| 995 | } else { |
||
| 996 | $this->doAlterDict($this->lang['strftsdictalteredbad']); |
||
| 997 | } |
||
| 998 | } |
||
| 999 | |||
| 1000 | /** |
||
| 1001 | * Show confirmation of drop and perform actual drop of FTS mapping. |
||
| 1002 | * |
||
| 1003 | * @param mixed $confirm |
||
| 1004 | */ |
||
| 1005 | public function doDropMapping($confirm) |
||
| 1062 | } |
||
| 1063 | } |
||
| 1064 | } |
||
| 1065 | } |
||
| 1066 | |||
| 1067 | public function doAlterMapping($msg = '') |
||
| 1068 | { |
||
| 1069 | $data = $this->misc->getDatabaseAccessor(); |
||
| 1070 | $this->printTrail('ftscfg'); |
||
| 1071 | $this->printTitle($this->lang['stralter'], 'pg.ftscfg.alter'); |
||
| 1072 | $this->printMsg($msg); |
||
| 1073 | |||
| 1074 | $ftsdicts = $data->getFtsDictionaries(); |
||
| 1075 | if ($ftsdicts->recordCount() > 0) { |
||
| 1076 | $this->coalesceArr($_POST, 'formMapping', @$_REQUEST['mapping']); |
||
| 1077 | |||
| 1078 | $this->coalesceArr($_POST, 'formDictionary', ''); |
||
| 1079 | |||
| 1080 | $this->coalesceArr($_POST, 'ftscfg', $_REQUEST['ftscfg']); |
||
| 1081 | |||
| 1082 | echo '<form action="' . \SUBFOLDER . "/src/views/fulltext\" method=\"post\">\n"; |
||
| 1083 | |||
| 1084 | echo "<table>\n"; |
||
| 1085 | echo "\t<tr>\n"; |
||
| 1086 | echo "\t\t<th class=\"data left required\">{$this->lang['strftsmapping']}</th>\n"; |
||
| 1087 | echo "\t\t<td class=\"data1\">"; |
||
| 1088 | |||
| 1089 | $ma_mappings = []; |
||
| 1090 | // Case of multiaction drop |
||
| 1091 | if (isset($_REQUEST['ma'])) { |
||
| 1092 | $ma_mappings_names = []; |
||
| 1093 | foreach ($_REQUEST['ma'] as $v) { |
||
| 1094 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
| 1095 | printf('<input type="hidden" name="formMapping[]" value="%s" />', htmlspecialchars($a['mapping'])); |
||
| 1096 | $ma_mappings[] = $data->getFtsMappingByName($_POST['ftscfg'], $a['mapping']); |
||
| 1097 | $ma_mappings_names[] = $a['mapping']; |
||
| 1098 | } |
||
| 1099 | echo implode(', ', $ma_mappings_names); |
||
| 1100 | } else { |
||
| 1101 | $mapping = $data->getFtsMappingByName($_POST['ftscfg'], $_POST['formMapping']); |
||
| 1102 | echo $mapping->fields['name']; |
||
| 1103 | echo '<input type="hidden" name="formMapping" value="', htmlspecialchars($_POST['formMapping']), "\" />\n"; |
||
| 1104 | } |
||
| 1105 | |||
| 1106 | echo "\t\t</td>\n"; |
||
| 1107 | echo "\t</tr>\n"; |
||
| 1108 | |||
| 1109 | // Dictionary |
||
| 1110 | echo "\t<tr>\n"; |
||
| 1111 | echo "\t\t<th class=\"data left required\">{$this->lang['strftsdict']}</th>\n"; |
||
| 1112 | echo "\t\t<td class=\"data1\">"; |
||
| 1113 | echo "\t\t\t<select name=\"formDictionary\">\n"; |
||
| 1114 | while (!$ftsdicts->EOF) { |
||
| 1115 | $ftsdict = htmlspecialchars($ftsdicts->fields['name']); |
||
| 1116 | echo "\t\t\t\t<option value=\"{$ftsdict}\"", |
||
| 1117 | ( |
||
| 1118 | $ftsdict == $_POST['formDictionary'] |
||
| 1119 | || $ftsdict == @$mapping->fields['dictionaries'] |
||
| 1120 | || $ftsdict == @$ma_mappings[0]->fields['dictionaries'] |
||
| 1121 | ) ? ' selected="selected"' : '', ">{$ftsdict}</option>\n"; |
||
| 1122 | $ftsdicts->moveNext(); |
||
| 1123 | } |
||
| 1124 | |||
| 1125 | echo "\t\t</td>\n"; |
||
| 1126 | echo "\t</tr>\n"; |
||
| 1127 | |||
| 1128 | echo "</table>\n"; |
||
| 1129 | echo "<p><input type=\"hidden\" name=\"action\" value=\"altermapping\" />\n"; |
||
| 1130 | echo '<input type="hidden" name="ftscfg" value="', htmlspecialchars($_POST['ftscfg']), "\" />\n"; |
||
| 1131 | echo "<input type=\"hidden\" name=\"prev_action\" value=\"viewconfig\" /></p>\n"; |
||
| 1132 | |||
| 1133 | echo $this->misc->form; |
||
| 1134 | echo "<input type=\"submit\" name=\"alter\" value=\"{$this->lang['stralter']}\" />\n"; |
||
| 1135 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
| 1136 | echo "</form>\n"; |
||
| 1137 | } else { |
||
| 1138 | echo "<p>{$this->lang['strftsnodictionaries']}</p>\n"; |
||
| 1139 | } |
||
| 1140 | } |
||
| 1141 | |||
| 1142 | /** |
||
| 1143 | * Save the form submission containing changes to a FTS mapping. |
||
| 1144 | */ |
||
| 1145 | public function doSaveAlterMapping() |
||
| 1146 | { |
||
| 1147 | $data = $this->misc->getDatabaseAccessor(); |
||
| 1148 | |||
| 1149 | $mappingArray = (is_array($_POST['formMapping']) ? $_POST['formMapping'] : [$_POST['formMapping']]); |
||
| 1150 | $status = $data->changeFtsMapping($_POST['ftscfg'], $mappingArray, 'alter', $_POST['formDictionary']); |
||
| 1151 | if (0 == $status) { |
||
| 1152 | $this->doViewConfig($_POST['ftscfg'], $this->lang['strftsmappingaltered']); |
||
| 1153 | } else { |
||
| 1154 | $this->doAlterMapping($this->lang['strftsmappingalteredbad']); |
||
| 1155 | } |
||
| 1156 | } |
||
| 1157 | |||
| 1158 | /** |
||
| 1159 | * Show the form to enter parameters of a new FTS mapping. |
||
| 1160 | * |
||
| 1161 | * @param mixed $msg |
||
| 1162 | */ |
||
| 1163 | public function doAddMapping($msg = '') |
||
| 1222 | } |
||
| 1223 | } |
||
| 1224 | |||
| 1225 | /** |
||
| 1226 | * Save the form submission containing parameters of a new FTS mapping. |
||
| 1227 | */ |
||
| 1228 | public function doSaveAddMapping() |
||
| 1238 | } |
||
| 1239 | } |
||
| 1240 | } |
||
| 1241 |