Skip to content

Commit d760df0

Browse files
committed
Move DBI getEvents method into the Events class
DatabaseInterface::getEvents -> Database\Events::getDetails Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 81192a1 commit d760df0

File tree

6 files changed

+61
-71
lines changed

6 files changed

+61
-71
lines changed

libraries/classes/Controllers/Database/EventsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function __invoke(ServerRequest $request): void
8181
$this->events->handleEditor();
8282
$this->events->export();
8383

84-
$items = $this->dbi->getEvents($GLOBALS['db']);
84+
$items = $this->events->getDetails($GLOBALS['db']);
8585

8686
$this->render('database/events/index', [
8787
'db' => $GLOBALS['db'],

libraries/classes/Database/Events.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
use PhpMyAdmin\DatabaseInterface;
88
use PhpMyAdmin\Html\Generator;
99
use PhpMyAdmin\Message;
10+
use PhpMyAdmin\Query\Generator as QueryGenerator;
1011
use PhpMyAdmin\ResponseRenderer;
1112
use PhpMyAdmin\Template;
1213
use PhpMyAdmin\Util;
1314

1415
use function __;
16+
use function array_column;
17+
use function array_multisort;
1518
use function count;
1619
use function explode;
1720
use function htmlspecialchars;
@@ -23,6 +26,8 @@
2326
use function strtoupper;
2427
use function trim;
2528

29+
use const SORT_ASC;
30+
2631
/**
2732
* Functions for event management.
2833
*/
@@ -174,7 +179,7 @@ public function handleEditor(): void
174179

175180
if ($this->response->isAjax()) {
176181
if ($GLOBALS['message']->isSuccess()) {
177-
$events = $this->dbi->getEvents($GLOBALS['db'], $_POST['item_name']);
182+
$events = $this->getDetails($GLOBALS['db'], $_POST['item_name']);
178183
$event = $events[0];
179184
$this->response->addJSON(
180185
'name',
@@ -596,4 +601,45 @@ public function export(): void
596601

597602
$this->response->addHTML($message->getDisplay());
598603
}
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+
}
599645
}

libraries/classes/DatabaseInterface.php

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,47 +1523,6 @@ public function getDefinition(
15231523
return is_string($result) ? $result : null;
15241524
}
15251525

1526-
/**
1527-
* returns details about the EVENTs for a specific database
1528-
*
1529-
* @param string $db db name
1530-
* @param string $name event name
1531-
*
1532-
* @return array information about EVENTs
1533-
*/
1534-
public function getEvents(string $db, string $name = ''): array
1535-
{
1536-
if (! $GLOBALS['cfg']['Server']['DisableIS']) {
1537-
$query = QueryGenerator::getInformationSchemaEventsRequest(
1538-
$this->escapeString($db),
1539-
empty($name) ? null : $this->escapeString($name)
1540-
);
1541-
} else {
1542-
$query = 'SHOW EVENTS FROM ' . Util::backquote($db);
1543-
if ($name) {
1544-
$query .= " WHERE `Name` = '"
1545-
. $this->escapeString($name) . "'";
1546-
}
1547-
}
1548-
1549-
$result = [];
1550-
$events = $this->fetchResult($query);
1551-
1552-
foreach ($events as $event) {
1553-
$result[] = [
1554-
'name' => $event['Name'],
1555-
'type' => $event['Type'],
1556-
'status' => $event['Status'],
1557-
];
1558-
}
1559-
1560-
// Sort results by name
1561-
$name = array_column($result, 'name');
1562-
array_multisort($name, SORT_ASC, $result);
1563-
1564-
return $result;
1565-
}
1566-
15671526
/**
15681527
* returns details about the TRIGGERs for a specific table or database
15691528
*

libraries/classes/Dbal/DbalInterface.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -461,16 +461,6 @@ public function getDefinition(
461461
$link = DatabaseInterface::CONNECT_USER
462462
): ?string;
463463

464-
/**
465-
* returns details about the EVENTs for a specific database
466-
*
467-
* @param string $db db name
468-
* @param string $name event name
469-
*
470-
* @return array information about EVENTs
471-
*/
472-
public function getEvents(string $db, string $name = ''): array;
473-
474464
/**
475465
* returns details about the TRIGGERs for a specific table or database
476466
*

phpstan-baseline.neon

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,6 +1965,11 @@ parameters:
19651965
count: 1
19661966
path: libraries/classes/Database/Events.php
19671967

1968+
-
1969+
message: "#^Method PhpMyAdmin\\\\Database\\\\Events\\:\\:getDetails\\(\\) return type has no value type specified in iterable type array\\.$#"
1970+
count: 1
1971+
path: libraries/classes/Database/Events.php
1972+
19681973
-
19691974
message: "#^Method PhpMyAdmin\\\\Database\\\\Events\\:\\:getEditorForm\\(\\) has parameter \\$item with no value type specified in iterable type array\\.$#"
19701975
count: 1
@@ -2535,11 +2540,6 @@ parameters:
25352540
count: 1
25362541
path: libraries/classes/DatabaseInterface.php
25372542

2538-
-
2539-
message: "#^Method PhpMyAdmin\\\\DatabaseInterface\\:\\:getEvents\\(\\) return type has no value type specified in iterable type array\\.$#"
2540-
count: 1
2541-
path: libraries/classes/DatabaseInterface.php
2542-
25432543
-
25442544
message: "#^Method PhpMyAdmin\\\\DatabaseInterface\\:\\:getProceduresOrFunctions\\(\\) return type has no value type specified in iterable type array\\.$#"
25452545
count: 1
@@ -2680,11 +2680,6 @@ parameters:
26802680
count: 1
26812681
path: libraries/classes/Dbal/DbalInterface.php
26822682

2683-
-
2684-
message: "#^Method PhpMyAdmin\\\\Dbal\\\\DbalInterface\\:\\:getEvents\\(\\) return type has no value type specified in iterable type array\\.$#"
2685-
count: 1
2686-
path: libraries/classes/Dbal/DbalInterface.php
2687-
26882683
-
26892684
message: "#^Method PhpMyAdmin\\\\Dbal\\\\DbalInterface\\:\\:getProceduresOrFunctions\\(\\) return type has no value type specified in iterable type array\\.$#"
26902685
count: 1

psalm-baseline.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4908,7 +4908,10 @@
49084908
<code>$event['name']</code>
49094909
<code>$itemName</code>
49104910
</MixedArgument>
4911-
<MixedArrayAccess occurrences="1">
4911+
<MixedArrayAccess occurrences="4">
4912+
<code>$event['Name']</code>
4913+
<code>$event['Status']</code>
4914+
<code>$event['Type']</code>
49124915
<code>$event['name']</code>
49134916
</MixedArrayAccess>
49144917
<MixedArrayAssignment occurrences="9">
@@ -4922,10 +4925,11 @@
49224925
<code>$GLOBALS['errors'][]</code>
49234926
<code>$GLOBALS['errors'][]</code>
49244927
</MixedArrayAssignment>
4925-
<MixedAssignment occurrences="18">
4928+
<MixedAssignment occurrences="19">
49264929
<code>$GLOBALS['errors']</code>
49274930
<code>$GLOBALS['errors']</code>
49284931
<code>$event</code>
4932+
<code>$event</code>
49294933
<code>$itemName</code>
49304934
<code>$item['item_original_name']</code>
49314935
<code>$retval[$index]</code>
@@ -5630,10 +5634,7 @@
56305634
<code>uksort($eachTables, 'strnatcasecmp')</code>
56315635
<code>usort($tables, 'strnatcasecmp')</code>
56325636
</MixedArgumentTypeCoercion>
5633-
<MixedArrayAccess occurrences="28">
5634-
<code>$event['Name']</code>
5635-
<code>$event['Status']</code>
5636-
<code>$event['Type']</code>
5637+
<MixedArrayAccess occurrences="25">
56375638
<code>$link</code>
56385639
<code>$oneShow['Db']</code>
56395640
<code>$oneShow['Name']</code>
@@ -5680,13 +5681,12 @@
56805681
<code>$this-&gt;links[$link]</code>
56815682
<code>$this-&gt;links[$link]</code>
56825683
</MixedArrayOffset>
5683-
<MixedAssignment occurrences="35">
5684+
<MixedAssignment occurrences="34">
56845685
<code>$aLength</code>
56855686
<code>$bLength</code>
56865687
<code>$database</code>
56875688
<code>$databaseName</code>
56885689
<code>$databases[$databaseName]['SCHEMA_NAME']</code>
5689-
<code>$event</code>
56905690
<code>$grant</code>
56915691
<code>$grant</code>
56925692
<code>$keyIndex</code>

0 commit comments

Comments
 (0)