TriggersController.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpMyAdmin\Controllers\Database;
  4. use PhpMyAdmin\Database\Triggers;
  5. use PhpMyAdmin\DatabaseInterface;
  6. use PhpMyAdmin\DbTableExists;
  7. use PhpMyAdmin\Response;
  8. use PhpMyAdmin\Template;
  9. use PhpMyAdmin\Url;
  10. use PhpMyAdmin\Util;
  11. use function in_array;
  12. use function strlen;
  13. /**
  14. * Triggers management.
  15. */
  16. class TriggersController extends AbstractController
  17. {
  18. /** @var DatabaseInterface */
  19. private $dbi;
  20. /**
  21. * @param Response $response
  22. * @param string $db Database name.
  23. * @param DatabaseInterface $dbi
  24. */
  25. public function __construct($response, Template $template, $db, $dbi)
  26. {
  27. parent::__construct($response, $template, $db);
  28. $this->dbi = $dbi;
  29. }
  30. public function index(): void
  31. {
  32. global $db, $table, $tables, $num_tables, $total_num_tables, $sub_part;
  33. global $tooltip_truename, $tooltip_aliasname, $pos;
  34. global $errors, $url_params, $err_url, $cfg;
  35. if (! $this->response->isAjax()) {
  36. /**
  37. * Displays the header and tabs
  38. */
  39. if (! empty($table) && in_array($table, $this->dbi->getTables($db))) {
  40. Util::checkParameters(['db', 'table']);
  41. $url_params = ['db' => $db, 'table' => $table];
  42. $err_url = Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table');
  43. $err_url .= Url::getCommon($url_params, '&');
  44. DbTableExists::check();
  45. } else {
  46. $table = '';
  47. Util::checkParameters(['db']);
  48. $err_url = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
  49. $err_url .= Url::getCommon(['db' => $db], '&');
  50. if (! $this->hasDatabase()) {
  51. return;
  52. }
  53. [
  54. $tables,
  55. $num_tables,
  56. $total_num_tables,
  57. $sub_part,,,
  58. $tooltip_truename,
  59. $tooltip_aliasname,
  60. $pos,
  61. ] = Util::getDbInfo($db, $sub_part ?? '');
  62. }
  63. } elseif (strlen($db) > 0) {
  64. $this->dbi->selectDb($db);
  65. }
  66. /**
  67. * Keep a list of errors that occurred while
  68. * processing an 'Add' or 'Edit' operation.
  69. */
  70. $errors = [];
  71. $triggers = new Triggers($this->dbi, $this->template, $this->response);
  72. $triggers->main();
  73. }
  74. }