Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurício Meneghini Fauth <mauricio@fauth.dev>2022-09-10 22:00:42 +0300
committerMaurício Meneghini Fauth <mauricio@fauth.dev>2022-09-10 22:00:42 +0300
commita8421efd56011cb2917f358ca26bea2a7168c230 (patch)
tree6bb7fdb83f783e5762d612ff288a43803ebffec7 /libraries/classes
parentd760df02ddbafa85ebba4149969aed5f2d6af02f (diff)
Move DBI getTriggers method into the Triggers class
DatabaseInterface::getTriggers -> Database\Triggers::getDetails Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'libraries/classes')
-rw-r--r--libraries/classes/Database/Triggers.php84
-rw-r--r--libraries/classes/DatabaseInterface.php68
-rw-r--r--libraries/classes/Dbal/DbalInterface.php11
-rw-r--r--libraries/classes/Operations.php3
-rw-r--r--libraries/classes/Plugins/Export/ExportHtmlword.php5
-rw-r--r--libraries/classes/Plugins/Export/ExportOdt.php5
-rw-r--r--libraries/classes/Plugins/Export/ExportSql.php3
-rw-r--r--libraries/classes/Plugins/Export/ExportTexytext.php5
-rw-r--r--libraries/classes/Plugins/Export/ExportXml.php3
-rw-r--r--libraries/classes/Plugins/Export/Helpers/Pdf.php3
-rw-r--r--libraries/classes/Table.php7
11 files changed, 99 insertions, 98 deletions
diff --git a/libraries/classes/Database/Triggers.php b/libraries/classes/Database/Triggers.php
index c16391ac9e..8e556dccd1 100644
--- a/libraries/classes/Database/Triggers.php
+++ b/libraries/classes/Database/Triggers.php
@@ -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;
@@ -21,6 +24,8 @@ use function sprintf;
use function str_contains;
use function trim;
+use const SORT_ASC;
+
/**
* Functions for trigger management.
*/
@@ -64,7 +69,7 @@ class Triggers
$this->handleEditor();
$this->export();
- $items = $this->dbi->getTriggers($GLOBALS['db'], $GLOBALS['table']);
+ $items = self::getDetails($this->dbi, $GLOBALS['db'], $GLOBALS['table']);
$hasTriggerPrivilege = Util::currentUserHasPrivilege('TRIGGER', $GLOBALS['db'], $GLOBALS['table']);
$isAjax = $this->response->isAjax() && empty($_REQUEST['ajax_page_request']);
@@ -186,7 +191,7 @@ class Triggers
if ($this->response->isAjax()) {
if ($GLOBALS['message']->isSuccess()) {
- $items = $this->dbi->getTriggers($GLOBALS['db'], $GLOBALS['table'], '');
+ $items = self::getDetails($this->dbi, $GLOBALS['db'], $GLOBALS['table'], '');
$trigger = false;
foreach ($items as $value) {
if ($value['name'] != $_POST['item_name']) {
@@ -310,7 +315,7 @@ class Triggers
public function getDataFromName($name): ?array
{
$temp = [];
- $items = $this->dbi->getTriggers($GLOBALS['db'], $GLOBALS['table'], '');
+ $items = self::getDetails($this->dbi, $GLOBALS['db'], $GLOBALS['table'], '');
foreach ($items as $value) {
if ($value['name'] != $name) {
continue;
@@ -487,7 +492,7 @@ class Triggers
}
$itemName = $_GET['item_name'];
- $triggers = $this->dbi->getTriggers($GLOBALS['db'], $GLOBALS['table'], '');
+ $triggers = self::getDetails($this->dbi, $GLOBALS['db'], $GLOBALS['table'], '');
$exportData = false;
foreach ($triggers as $trigger) {
@@ -531,4 +536,75 @@ class Triggers
$this->response->addHTML($message->getDisplay());
}
+
+ /**
+ * Returns details about the TRIGGERs for a specific table or database.
+ *
+ * @param string $db db name
+ * @param string $table table name
+ * @param string $delimiter the delimiter to use (may be empty)
+ *
+ * @return array information about triggers (may be empty)
+ */
+ public static function getDetails(
+ DatabaseInterface $dbi,
+ string $db,
+ string $table = '',
+ string $delimiter = '//'
+ ): array {
+ $result = [];
+ if (! $GLOBALS['cfg']['Server']['DisableIS']) {
+ $query = QueryGenerator::getInformationSchemaTriggersRequest(
+ $dbi->escapeString($db),
+ empty($table) ? null : $dbi->escapeString($table)
+ );
+ } else {
+ $query = 'SHOW TRIGGERS FROM ' . Util::backquote($db);
+ if ($table) {
+ $query .= " LIKE '" . $dbi->escapeString($table) . "';";
+ }
+ }
+
+ $triggers = $dbi->fetchResult($query);
+
+ foreach ($triggers as $trigger) {
+ if ($GLOBALS['cfg']['Server']['DisableIS']) {
+ $trigger['TRIGGER_NAME'] = $trigger['Trigger'];
+ $trigger['ACTION_TIMING'] = $trigger['Timing'];
+ $trigger['EVENT_MANIPULATION'] = $trigger['Event'];
+ $trigger['EVENT_OBJECT_TABLE'] = $trigger['Table'];
+ $trigger['ACTION_STATEMENT'] = $trigger['Statement'];
+ $trigger['DEFINER'] = $trigger['Definer'];
+ }
+
+ $oneResult = [];
+ $oneResult['name'] = $trigger['TRIGGER_NAME'];
+ $oneResult['table'] = $trigger['EVENT_OBJECT_TABLE'];
+ $oneResult['action_timing'] = $trigger['ACTION_TIMING'];
+ $oneResult['event_manipulation'] = $trigger['EVENT_MANIPULATION'];
+ $oneResult['definition'] = $trigger['ACTION_STATEMENT'];
+ $oneResult['definer'] = $trigger['DEFINER'];
+
+ // do not prepend the schema name; this way, importing the
+ // definition into another schema will work
+ $oneResult['full_trigger_name'] = Util::backquote($trigger['TRIGGER_NAME']);
+ $oneResult['drop'] = 'DROP TRIGGER IF EXISTS '
+ . $oneResult['full_trigger_name'];
+ $oneResult['create'] = 'CREATE TRIGGER '
+ . $oneResult['full_trigger_name'] . ' '
+ . $trigger['ACTION_TIMING'] . ' '
+ . $trigger['EVENT_MANIPULATION']
+ . ' ON ' . Util::backquote($trigger['EVENT_OBJECT_TABLE'])
+ . "\n" . ' FOR EACH ROW '
+ . $trigger['ACTION_STATEMENT'] . "\n" . $delimiter . "\n";
+
+ $result[] = $oneResult;
+ }
+
+ // Sort results by name
+ $name = array_column($result, 'name');
+ array_multisort($name, SORT_ASC, $result);
+
+ return $result;
+ }
}
diff --git a/libraries/classes/DatabaseInterface.php b/libraries/classes/DatabaseInterface.php
index 01ee453f23..cec845d427 100644
--- a/libraries/classes/DatabaseInterface.php
+++ b/libraries/classes/DatabaseInterface.php
@@ -26,7 +26,6 @@ use PhpMyAdmin\Utils\SessionCache;
use RuntimeException;
use function __;
-use function array_column;
use function array_diff;
use function array_keys;
use function array_map;
@@ -1524,73 +1523,6 @@ class DatabaseInterface implements DbalInterface
}
/**
- * returns details about the TRIGGERs for a specific table or database
- *
- * @param string $db db name
- * @param string $table table name
- * @param string $delimiter the delimiter to use (may be empty)
- *
- * @return array information about triggers (may be empty)
- */
- public function getTriggers(string $db, string $table = '', string $delimiter = '//'): array
- {
- $result = [];
- if (! $GLOBALS['cfg']['Server']['DisableIS']) {
- $query = QueryGenerator::getInformationSchemaTriggersRequest(
- $this->escapeString($db),
- empty($table) ? null : $this->escapeString($table)
- );
- } else {
- $query = 'SHOW TRIGGERS FROM ' . Util::backquote($db);
- if ($table) {
- $query .= " LIKE '" . $this->escapeString($table) . "';";
- }
- }
-
- $triggers = $this->fetchResult($query);
-
- foreach ($triggers as $trigger) {
- if ($GLOBALS['cfg']['Server']['DisableIS']) {
- $trigger['TRIGGER_NAME'] = $trigger['Trigger'];
- $trigger['ACTION_TIMING'] = $trigger['Timing'];
- $trigger['EVENT_MANIPULATION'] = $trigger['Event'];
- $trigger['EVENT_OBJECT_TABLE'] = $trigger['Table'];
- $trigger['ACTION_STATEMENT'] = $trigger['Statement'];
- $trigger['DEFINER'] = $trigger['Definer'];
- }
-
- $oneResult = [];
- $oneResult['name'] = $trigger['TRIGGER_NAME'];
- $oneResult['table'] = $trigger['EVENT_OBJECT_TABLE'];
- $oneResult['action_timing'] = $trigger['ACTION_TIMING'];
- $oneResult['event_manipulation'] = $trigger['EVENT_MANIPULATION'];
- $oneResult['definition'] = $trigger['ACTION_STATEMENT'];
- $oneResult['definer'] = $trigger['DEFINER'];
-
- // do not prepend the schema name; this way, importing the
- // definition into another schema will work
- $oneResult['full_trigger_name'] = Util::backquote($trigger['TRIGGER_NAME']);
- $oneResult['drop'] = 'DROP TRIGGER IF EXISTS '
- . $oneResult['full_trigger_name'];
- $oneResult['create'] = 'CREATE TRIGGER '
- . $oneResult['full_trigger_name'] . ' '
- . $trigger['ACTION_TIMING'] . ' '
- . $trigger['EVENT_MANIPULATION']
- . ' ON ' . Util::backquote($trigger['EVENT_OBJECT_TABLE'])
- . "\n" . ' FOR EACH ROW '
- . $trigger['ACTION_STATEMENT'] . "\n" . $delimiter . "\n";
-
- $result[] = $oneResult;
- }
-
- // Sort results by name
- $name = array_column($result, 'name');
- array_multisort($name, SORT_ASC, $result);
-
- return $result;
- }
-
- /**
* gets the current user with host
*
* @return string the current user i.e. user@host
diff --git a/libraries/classes/Dbal/DbalInterface.php b/libraries/classes/Dbal/DbalInterface.php
index 0d8ff5c266..ebd462b6de 100644
--- a/libraries/classes/Dbal/DbalInterface.php
+++ b/libraries/classes/Dbal/DbalInterface.php
@@ -462,17 +462,6 @@ interface DbalInterface
): ?string;
/**
- * returns details about the TRIGGERs for a specific table or database
- *
- * @param string $db db name
- * @param string $table table name
- * @param string $delimiter the delimiter to use (may be empty)
- *
- * @return array information about triggers (may be empty)
- */
- public function getTriggers(string $db, string $table = '', string $delimiter = '//'): array;
-
- /**
* gets the current user with host
*
* @return string the current user i.e. user@host
diff --git a/libraries/classes/Operations.php b/libraries/classes/Operations.php
index 609abbc054..a437aaf17a 100644
--- a/libraries/classes/Operations.php
+++ b/libraries/classes/Operations.php
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace PhpMyAdmin;
use PhpMyAdmin\ConfigStorage\Relation;
+use PhpMyAdmin\Database\Triggers;
use PhpMyAdmin\Engines\Innodb;
use PhpMyAdmin\Partitioning\Partition;
use PhpMyAdmin\Plugins\Export\ExportSql;
@@ -205,7 +206,7 @@ class Operations
// keep the triggers from the original db+table
// (third param is empty because delimiters are only intended
// for importing via the mysql client or our Import feature)
- $triggers = $this->dbi->getTriggers($db, (string) $each_table, '');
+ $triggers = Triggers::getDetails($this->dbi, $db, (string) $each_table, '');
if (
! Table::moveCopy(
diff --git a/libraries/classes/Plugins/Export/ExportHtmlword.php b/libraries/classes/Plugins/Export/ExportHtmlword.php
index bf2bee977e..1186ca52ab 100644
--- a/libraries/classes/Plugins/Export/ExportHtmlword.php
+++ b/libraries/classes/Plugins/Export/ExportHtmlword.php
@@ -7,6 +7,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Plugins\Export;
+use PhpMyAdmin\Database\Triggers;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Plugins\ExportPlugin;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
@@ -472,7 +473,7 @@ class ExportHtmlword extends ExportPlugin
$dump .= '<td class="print"><strong>' . __('Definition') . '</strong></td>';
$dump .= '</tr>';
- $triggers = $GLOBALS['dbi']->getTriggers($db, $table);
+ $triggers = Triggers::getDetails($GLOBALS['dbi'], $db, $table);
foreach ($triggers as $trigger) {
$dump .= '<tr class="print-category">';
@@ -546,7 +547,7 @@ class ExportHtmlword extends ExportPlugin
break;
case 'triggers':
$dump = '';
- $triggers = $GLOBALS['dbi']->getTriggers($db, $table);
+ $triggers = Triggers::getDetails($GLOBALS['dbi'], $db, $table);
if ($triggers) {
$dump .= '<h2>'
. __('Triggers') . ' ' . htmlspecialchars($table_alias)
diff --git a/libraries/classes/Plugins/Export/ExportOdt.php b/libraries/classes/Plugins/Export/ExportOdt.php
index 6b48a408c2..c26496af40 100644
--- a/libraries/classes/Plugins/Export/ExportOdt.php
+++ b/libraries/classes/Plugins/Export/ExportOdt.php
@@ -7,6 +7,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Plugins\Export;
+use PhpMyAdmin\Database\Triggers;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\FieldMetadata;
use PhpMyAdmin\OpenDocument;
@@ -600,7 +601,7 @@ class ExportOdt extends ExportPlugin
. '</table:table-cell>'
. '</table:table-row>';
- $triggers = $GLOBALS['dbi']->getTriggers($db, $table);
+ $triggers = Triggers::getDetails($GLOBALS['dbi'], $db, $table);
foreach ($triggers as $trigger) {
$GLOBALS['odt_buffer'] .= '<table:table-row>';
@@ -690,7 +691,7 @@ class ExportOdt extends ExportPlugin
);
break;
case 'triggers':
- $triggers = $GLOBALS['dbi']->getTriggers($db, $table);
+ $triggers = Triggers::getDetails($GLOBALS['dbi'], $db, $table);
if ($triggers) {
$GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2"'
. ' text:is-list-header="true">'
diff --git a/libraries/classes/Plugins/Export/ExportSql.php b/libraries/classes/Plugins/Export/ExportSql.php
index fb4f7850e1..8ecc9acb6d 100644
--- a/libraries/classes/Plugins/Export/ExportSql.php
+++ b/libraries/classes/Plugins/Export/ExportSql.php
@@ -8,6 +8,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Plugins\Export;
use PhpMyAdmin\Charsets;
+use PhpMyAdmin\Database\Triggers;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\FieldMetadata;
use PhpMyAdmin\Plugins\ExportPlugin;
@@ -2064,7 +2065,7 @@ class ExportSql extends ExportPlugin
case 'triggers':
$dump = '';
$delimiter = '$$';
- $triggers = $GLOBALS['dbi']->getTriggers($db, $table, $delimiter);
+ $triggers = Triggers::getDetails($GLOBALS['dbi'], $db, $table, $delimiter);
if ($triggers) {
$dump .= $this->possibleCRLF()
. $this->exportComment()
diff --git a/libraries/classes/Plugins/Export/ExportTexytext.php b/libraries/classes/Plugins/Export/ExportTexytext.php
index 2e864c707f..6280520c78 100644
--- a/libraries/classes/Plugins/Export/ExportTexytext.php
+++ b/libraries/classes/Plugins/Export/ExportTexytext.php
@@ -7,6 +7,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Plugins\Export;
+use PhpMyAdmin\Database\Triggers;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Plugins\ExportPlugin;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
@@ -453,7 +454,7 @@ class ExportTexytext extends ExportPlugin
$dump .= '|' . __('Definition');
$dump .= "\n|------\n";
- $triggers = $GLOBALS['dbi']->getTriggers($db, $table);
+ $triggers = Triggers::getDetails($GLOBALS['dbi'], $db, $table);
foreach ($triggers as $trigger) {
$dump .= '|' . $trigger['name'];
@@ -530,7 +531,7 @@ class ExportTexytext extends ExportPlugin
break;
case 'triggers':
$dump = '';
- $triggers = $GLOBALS['dbi']->getTriggers($db, $table);
+ $triggers = Triggers::getDetails($GLOBALS['dbi'], $db, $table);
if ($triggers) {
$dump .= '== ' . __('Triggers') . ' ' . $table_alias . "\n\n";
$dump .= $this->getTriggers($db, $table);
diff --git a/libraries/classes/Plugins/Export/ExportXml.php b/libraries/classes/Plugins/Export/ExportXml.php
index 8574c38e4b..3241eaf2bc 100644
--- a/libraries/classes/Plugins/Export/ExportXml.php
+++ b/libraries/classes/Plugins/Export/ExportXml.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Plugins\Export;
+use PhpMyAdmin\Database\Triggers;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Plugins\ExportPlugin;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
@@ -307,7 +308,7 @@ class ExportXml extends ExportPlugin
}
// Export triggers
- $triggers = $GLOBALS['dbi']->getTriggers($GLOBALS['db'], $table);
+ $triggers = Triggers::getDetails($GLOBALS['dbi'], $GLOBALS['db'], $table);
if (! $triggers) {
continue;
}
diff --git a/libraries/classes/Plugins/Export/Helpers/Pdf.php b/libraries/classes/Plugins/Export/Helpers/Pdf.php
index 7f566f5320..1e09d807f5 100644
--- a/libraries/classes/Plugins/Export/Helpers/Pdf.php
+++ b/libraries/classes/Plugins/Export/Helpers/Pdf.php
@@ -8,6 +8,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Plugins\Export\Helpers;
use PhpMyAdmin\ConfigStorage\Relation;
+use PhpMyAdmin\Database\Triggers;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Dbal\ResultInterface;
use PhpMyAdmin\FieldMetadata;
@@ -335,7 +336,7 @@ class Pdf extends PdfLib
*/
public function getTriggers($db, $table): void
{
- $triggers = $GLOBALS['dbi']->getTriggers($db, $table);
+ $triggers = Triggers::getDetails($GLOBALS['dbi'], $db, $table);
if ($triggers === []) {
return; //prevents printing blank trigger list for any table
}
diff --git a/libraries/classes/Table.php b/libraries/classes/Table.php
index ea9c259ab1..2dd86fe6ea 100644
--- a/libraries/classes/Table.php
+++ b/libraries/classes/Table.php
@@ -8,6 +8,7 @@ use PhpMyAdmin\ConfigStorage\Features\DisplayFeature;
use PhpMyAdmin\ConfigStorage\Features\RelationFeature;
use PhpMyAdmin\ConfigStorage\Features\UiPreferencesFeature;
use PhpMyAdmin\ConfigStorage\Relation;
+use PhpMyAdmin\Database\Triggers;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Html\MySQLDocumentation;
use PhpMyAdmin\Plugins\Export\ExportSql;
@@ -1497,11 +1498,7 @@ class Table implements Stringable
}
// If the table is moved to a different database drop its triggers first
- $triggers = $this->dbi->getTriggers(
- $this->getDbName(),
- $this->getName(),
- ''
- );
+ $triggers = Triggers::getDetails($this->dbi, $this->getDbName(), $this->getName(), '');
$handleTriggers = $this->getDbName() != $newDb && $triggers;
if ($handleTriggers) {
foreach ($triggers as $trigger) {