|
7 | 7 | use PhpMyAdmin\DatabaseInterface; |
8 | 8 | use PhpMyAdmin\Html\Generator; |
9 | 9 | use PhpMyAdmin\Message; |
| 10 | +use PhpMyAdmin\Query\Generator as QueryGenerator; |
10 | 11 | use PhpMyAdmin\ResponseRenderer; |
11 | 12 | use PhpMyAdmin\Template; |
12 | 13 | use PhpMyAdmin\Util; |
13 | 14 |
|
14 | 15 | use function __; |
| 16 | +use function array_column; |
| 17 | +use function array_multisort; |
15 | 18 | use function count; |
16 | 19 | use function explode; |
17 | 20 | use function htmlspecialchars; |
|
23 | 26 | use function strtoupper; |
24 | 27 | use function trim; |
25 | 28 |
|
| 29 | +use const SORT_ASC; |
| 30 | + |
26 | 31 | /** |
27 | 32 | * Functions for event management. |
28 | 33 | */ |
@@ -174,7 +179,7 @@ public function handleEditor(): void |
174 | 179 |
|
175 | 180 | if ($this->response->isAjax()) { |
176 | 181 | if ($GLOBALS['message']->isSuccess()) { |
177 | | - $events = $this->dbi->getEvents($GLOBALS['db'], $_POST['item_name']); |
| 182 | + $events = $this->getDetails($GLOBALS['db'], $_POST['item_name']); |
178 | 183 | $event = $events[0]; |
179 | 184 | $this->response->addJSON( |
180 | 185 | 'name', |
@@ -596,4 +601,45 @@ public function export(): void |
596 | 601 |
|
597 | 602 | $this->response->addHTML($message->getDisplay()); |
598 | 603 | } |
| 604 | + |
| 605 | + /** |
| 606 | + * Returns details about the EVENTs for a specific database. |
| 607 | + * |
| 608 | + * @param string $db db name |
| 609 | + * @param string $name event name |
| 610 | + * |
| 611 | + * @return array information about EVENTs |
| 612 | + */ |
| 613 | + public function getDetails(string $db, string $name = ''): array |
| 614 | + { |
| 615 | + if (! $GLOBALS['cfg']['Server']['DisableIS']) { |
| 616 | + $query = QueryGenerator::getInformationSchemaEventsRequest( |
| 617 | + $this->dbi->escapeString($db), |
| 618 | + empty($name) ? null : $this->dbi->escapeString($name) |
| 619 | + ); |
| 620 | + } else { |
| 621 | + $query = 'SHOW EVENTS FROM ' . Util::backquote($db); |
| 622 | + if ($name) { |
| 623 | + $query .= " WHERE `Name` = '" |
| 624 | + . $this->dbi->escapeString($name) . "'"; |
| 625 | + } |
| 626 | + } |
| 627 | + |
| 628 | + $result = []; |
| 629 | + $events = $this->dbi->fetchResult($query); |
| 630 | + |
| 631 | + foreach ($events as $event) { |
| 632 | + $result[] = [ |
| 633 | + 'name' => $event['Name'], |
| 634 | + 'type' => $event['Type'], |
| 635 | + 'status' => $event['Status'], |
| 636 | + ]; |
| 637 | + } |
| 638 | + |
| 639 | + // Sort results by name |
| 640 | + $name = array_column($result, 'name'); |
| 641 | + array_multisort($name, SORT_ASC, $result); |
| 642 | + |
| 643 | + return $result; |
| 644 | + } |
599 | 645 | } |
0 commit comments