TriggersController.php 2.6 KB

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