Move DBI getEvents method into the Events class

DatabaseInterface::getEvents -> Database\Events::getDetails

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2022-09-10 12:48:44 -03:00
parent 81192a142b
commit d760df02dd
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
6 changed files with 61 additions and 71 deletions

View File

@ -81,7 +81,7 @@ final class EventsController extends AbstractController
$this->events->handleEditor();
$this->events->export();
$items = $this->dbi->getEvents($GLOBALS['db']);
$items = $this->events->getDetails($GLOBALS['db']);
$this->render('database/events/index', [
'db' => $GLOBALS['db'],

View File

@ -7,11 +7,14 @@ namespace PhpMyAdmin\Database;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Message;
use PhpMyAdmin\Query\Generator as QueryGenerator;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
use PhpMyAdmin\Util;
use function __;
use function array_column;
use function array_multisort;
use function count;
use function explode;
use function htmlspecialchars;
@ -23,6 +26,8 @@ use function str_contains;
use function strtoupper;
use function trim;
use const SORT_ASC;
/**
* Functions for event management.
*/
@ -174,7 +179,7 @@ class Events
if ($this->response->isAjax()) {
if ($GLOBALS['message']->isSuccess()) {
$events = $this->dbi->getEvents($GLOBALS['db'], $_POST['item_name']);
$events = $this->getDetails($GLOBALS['db'], $_POST['item_name']);
$event = $events[0];
$this->response->addJSON(
'name',
@ -596,4 +601,45 @@ class Events
$this->response->addHTML($message->getDisplay());
}
/**
* Returns details about the EVENTs for a specific database.
*
* @param string $db db name
* @param string $name event name
*
* @return array information about EVENTs
*/
public function getDetails(string $db, string $name = ''): array
{
if (! $GLOBALS['cfg']['Server']['DisableIS']) {
$query = QueryGenerator::getInformationSchemaEventsRequest(
$this->dbi->escapeString($db),
empty($name) ? null : $this->dbi->escapeString($name)
);
} else {
$query = 'SHOW EVENTS FROM ' . Util::backquote($db);
if ($name) {
$query .= " WHERE `Name` = '"
. $this->dbi->escapeString($name) . "'";
}
}
$result = [];
$events = $this->dbi->fetchResult($query);
foreach ($events as $event) {
$result[] = [
'name' => $event['Name'],
'type' => $event['Type'],
'status' => $event['Status'],
];
}
// Sort results by name
$name = array_column($result, 'name');
array_multisort($name, SORT_ASC, $result);
return $result;
}
}

View File

@ -1523,47 +1523,6 @@ class DatabaseInterface implements DbalInterface
return is_string($result) ? $result : null;
}
/**
* returns details about the EVENTs for a specific database
*
* @param string $db db name
* @param string $name event name
*
* @return array information about EVENTs
*/
public function getEvents(string $db, string $name = ''): array
{
if (! $GLOBALS['cfg']['Server']['DisableIS']) {
$query = QueryGenerator::getInformationSchemaEventsRequest(
$this->escapeString($db),
empty($name) ? null : $this->escapeString($name)
);
} else {
$query = 'SHOW EVENTS FROM ' . Util::backquote($db);
if ($name) {
$query .= " WHERE `Name` = '"
. $this->escapeString($name) . "'";
}
}
$result = [];
$events = $this->fetchResult($query);
foreach ($events as $event) {
$result[] = [
'name' => $event['Name'],
'type' => $event['Type'],
'status' => $event['Status'],
];
}
// Sort results by name
$name = array_column($result, 'name');
array_multisort($name, SORT_ASC, $result);
return $result;
}
/**
* returns details about the TRIGGERs for a specific table or database
*

View File

@ -461,16 +461,6 @@ interface DbalInterface
$link = DatabaseInterface::CONNECT_USER
): ?string;
/**
* returns details about the EVENTs for a specific database
*
* @param string $db db name
* @param string $name event name
*
* @return array information about EVENTs
*/
public function getEvents(string $db, string $name = ''): array;
/**
* returns details about the TRIGGERs for a specific table or database
*

View File

@ -1965,6 +1965,11 @@ parameters:
count: 1
path: libraries/classes/Database/Events.php
-
message: "#^Method PhpMyAdmin\\\\Database\\\\Events\\:\\:getDetails\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Database/Events.php
-
message: "#^Method PhpMyAdmin\\\\Database\\\\Events\\:\\:getEditorForm\\(\\) has parameter \\$item with no value type specified in iterable type array\\.$#"
count: 1
@ -2535,11 +2540,6 @@ parameters:
count: 1
path: libraries/classes/DatabaseInterface.php
-
message: "#^Method PhpMyAdmin\\\\DatabaseInterface\\:\\:getEvents\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/DatabaseInterface.php
-
message: "#^Method PhpMyAdmin\\\\DatabaseInterface\\:\\:getProceduresOrFunctions\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
@ -2680,11 +2680,6 @@ parameters:
count: 1
path: libraries/classes/Dbal/DbalInterface.php
-
message: "#^Method PhpMyAdmin\\\\Dbal\\\\DbalInterface\\:\\:getEvents\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Dbal/DbalInterface.php
-
message: "#^Method PhpMyAdmin\\\\Dbal\\\\DbalInterface\\:\\:getProceduresOrFunctions\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1

View File

@ -4908,7 +4908,10 @@
<code>$event['name']</code>
<code>$itemName</code>
</MixedArgument>
<MixedArrayAccess occurrences="1">
<MixedArrayAccess occurrences="4">
<code>$event['Name']</code>
<code>$event['Status']</code>
<code>$event['Type']</code>
<code>$event['name']</code>
</MixedArrayAccess>
<MixedArrayAssignment occurrences="9">
@ -4922,10 +4925,11 @@
<code>$GLOBALS['errors'][]</code>
<code>$GLOBALS['errors'][]</code>
</MixedArrayAssignment>
<MixedAssignment occurrences="18">
<MixedAssignment occurrences="19">
<code>$GLOBALS['errors']</code>
<code>$GLOBALS['errors']</code>
<code>$event</code>
<code>$event</code>
<code>$itemName</code>
<code>$item['item_original_name']</code>
<code>$retval[$index]</code>
@ -5630,10 +5634,7 @@
<code>uksort($eachTables, 'strnatcasecmp')</code>
<code>usort($tables, 'strnatcasecmp')</code>
</MixedArgumentTypeCoercion>
<MixedArrayAccess occurrences="28">
<code>$event['Name']</code>
<code>$event['Status']</code>
<code>$event['Type']</code>
<MixedArrayAccess occurrences="25">
<code>$link</code>
<code>$oneShow['Db']</code>
<code>$oneShow['Name']</code>
@ -5680,13 +5681,12 @@
<code>$this-&gt;links[$link]</code>
<code>$this-&gt;links[$link]</code>
</MixedArrayOffset>
<MixedAssignment occurrences="35">
<MixedAssignment occurrences="34">
<code>$aLength</code>
<code>$bLength</code>
<code>$database</code>
<code>$databaseName</code>
<code>$databases[$databaseName]['SCHEMA_NAME']</code>
<code>$event</code>
<code>$grant</code>
<code>$grant</code>
<code>$keyIndex</code>