diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-09-10 22:00:42 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-09-10 22:00:42 +0300 |
commit | a8421efd56011cb2917f358ca26bea2a7168c230 (patch) | |
tree | 6bb7fdb83f783e5762d612ff288a43803ebffec7 | |
parent | d760df02ddbafa85ebba4149969aed5f2d6af02f (diff) |
Move DBI getTriggers method into the Triggers class
DatabaseInterface::getTriggers -> Database\Triggers::getDetails
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
-rw-r--r-- | libraries/classes/Database/Triggers.php | 84 | ||||
-rw-r--r-- | libraries/classes/DatabaseInterface.php | 68 | ||||
-rw-r--r-- | libraries/classes/Dbal/DbalInterface.php | 11 | ||||
-rw-r--r-- | libraries/classes/Operations.php | 3 | ||||
-rw-r--r-- | libraries/classes/Plugins/Export/ExportHtmlword.php | 5 | ||||
-rw-r--r-- | libraries/classes/Plugins/Export/ExportOdt.php | 5 | ||||
-rw-r--r-- | libraries/classes/Plugins/Export/ExportSql.php | 3 | ||||
-rw-r--r-- | libraries/classes/Plugins/Export/ExportTexytext.php | 5 | ||||
-rw-r--r-- | libraries/classes/Plugins/Export/ExportXml.php | 3 | ||||
-rw-r--r-- | libraries/classes/Plugins/Export/Helpers/Pdf.php | 3 | ||||
-rw-r--r-- | libraries/classes/Table.php | 7 | ||||
-rw-r--r-- | phpstan-baseline.neon | 15 | ||||
-rw-r--r-- | psalm-baseline.xml | 102 | ||||
-rw-r--r-- | test/classes/Plugins/Export/ExportHtmlwordTest.php | 19 | ||||
-rw-r--r-- | test/classes/Plugins/Export/ExportOdtTest.php | 19 | ||||
-rw-r--r-- | test/classes/Plugins/Export/ExportTexytextTest.php | 19 | ||||
-rw-r--r-- | test/classes/Plugins/Export/ExportXmlTest.php | 34 | ||||
-rw-r--r-- | test/classes/TableTest.php | 84 |
18 files changed, 273 insertions, 216 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) { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 316db55f15..1149105943 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -2426,6 +2426,11 @@ parameters: path: libraries/classes/Database/Triggers.php - + message: "#^Method PhpMyAdmin\\\\Database\\\\Triggers\\:\\:getDetails\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: libraries/classes/Database/Triggers.php + + - message: "#^Method PhpMyAdmin\\\\Database\\\\Triggers\\:\\:getEditorForm\\(\\) has parameter \\$item with no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/Database/Triggers.php @@ -2566,11 +2571,6 @@ parameters: path: libraries/classes/DatabaseInterface.php - - message: "#^Method PhpMyAdmin\\\\DatabaseInterface\\:\\:getTriggers\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: libraries/classes/DatabaseInterface.php - - - message: "#^PHPDoc tag @var for variable \\$fields has no value type specified in iterable type array\\.$#" count: 2 path: libraries/classes/DatabaseInterface.php @@ -2701,11 +2701,6 @@ parameters: path: libraries/classes/Dbal/DbalInterface.php - - message: "#^Method PhpMyAdmin\\\\Dbal\\\\DbalInterface\\:\\:getTriggers\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: libraries/classes/Dbal/DbalInterface.php - - - message: "#^Method PhpMyAdmin\\\\Dbal\\\\DbalInterface\\:\\:getWarnings\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/Dbal/DbalInterface.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 10d7af7486..bc3199c1c8 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -5467,7 +5467,7 @@ </RedundantPropertyInitializationCheck> </file> <file src="libraries/classes/Database/Triggers.php"> - <MixedArgument occurrences="18"> + <MixedArgument occurrences="20"> <code>$GLOBALS['errors']</code> <code>$GLOBALS['errors']</code> <code>$GLOBALS['errors']</code> @@ -5486,8 +5486,10 @@ <code>$exportData</code> <code>$itemName</code> <code>$itemName</code> + <code>$trigger['EVENT_OBJECT_TABLE']</code> + <code>$trigger['TRIGGER_NAME']</code> </MixedArgument> - <MixedArrayAccess occurrences="13"> + <MixedArrayAccess occurrences="30"> <code>$temp['action_timing']</code> <code>$temp['create']</code> <code>$temp['definer']</code> @@ -5496,13 +5498,30 @@ <code>$temp['event_manipulation']</code> <code>$temp['name']</code> <code>$temp['table']</code> + <code>$trigger['ACTION_STATEMENT']</code> + <code>$trigger['ACTION_STATEMENT']</code> + <code>$trigger['ACTION_TIMING']</code> + <code>$trigger['ACTION_TIMING']</code> + <code>$trigger['DEFINER']</code> + <code>$trigger['Definer']</code> + <code>$trigger['EVENT_MANIPULATION']</code> + <code>$trigger['EVENT_MANIPULATION']</code> + <code>$trigger['EVENT_OBJECT_TABLE']</code> + <code>$trigger['EVENT_OBJECT_TABLE']</code> + <code>$trigger['Event']</code> + <code>$trigger['Statement']</code> + <code>$trigger['TRIGGER_NAME']</code> + <code>$trigger['TRIGGER_NAME']</code> + <code>$trigger['Table']</code> + <code>$trigger['Timing']</code> + <code>$trigger['Trigger']</code> <code>$trigger['create']</code> <code>$trigger['name']</code> <code>$trigger['table']</code> <code>$value['name']</code> <code>$value['name']</code> </MixedArrayAccess> - <MixedArrayAssignment occurrences="9"> + <MixedArrayAssignment occurrences="15"> <code>$GLOBALS['errors'][]</code> <code>$GLOBALS['errors'][]</code> <code>$GLOBALS['errors'][]</code> @@ -5512,8 +5531,14 @@ <code>$GLOBALS['errors'][]</code> <code>$GLOBALS['errors'][]</code> <code>$GLOBALS['errors'][]</code> + <code>$trigger['ACTION_STATEMENT']</code> + <code>$trigger['ACTION_TIMING']</code> + <code>$trigger['DEFINER']</code> + <code>$trigger['EVENT_MANIPULATION']</code> + <code>$trigger['EVENT_OBJECT_TABLE']</code> + <code>$trigger['TRIGGER_NAME']</code> </MixedArrayAssignment> - <MixedAssignment occurrences="22"> + <MixedAssignment occurrences="35"> <code>$GLOBALS['errors']</code> <code>$GLOBALS['errors']</code> <code>$create_item</code> @@ -5521,6 +5546,12 @@ <code>$item</code> <code>$itemName</code> <code>$item['item_original_name']</code> + <code>$oneResult['action_timing']</code> + <code>$oneResult['definer']</code> + <code>$oneResult['definition']</code> + <code>$oneResult['event_manipulation']</code> + <code>$oneResult['name']</code> + <code>$oneResult['table']</code> <code>$retval[$index]</code> <code>$retval['create']</code> <code>$retval['drop']</code> @@ -5534,14 +5565,24 @@ <code>$temp</code> <code>$trigger</code> <code>$trigger</code> + <code>$trigger</code> + <code>$trigger['ACTION_STATEMENT']</code> + <code>$trigger['ACTION_TIMING']</code> + <code>$trigger['DEFINER']</code> + <code>$trigger['EVENT_MANIPULATION']</code> + <code>$trigger['EVENT_OBJECT_TABLE']</code> + <code>$trigger['TRIGGER_NAME']</code> <code>$value</code> <code>$value</code> </MixedAssignment> - <MixedOperand occurrences="5"> + <MixedOperand occurrences="8"> <code>$_POST['item_definition']</code> <code>$_POST['item_event']</code> <code>$_POST['item_timing']</code> <code>$string</code> + <code>$trigger['ACTION_STATEMENT']</code> + <code>$trigger['ACTION_TIMING']</code> + <code>$trigger['EVENT_MANIPULATION']</code> <code>$trigger['drop']</code> </MixedOperand> <PossiblyNullArgument occurrences="5"> @@ -5580,7 +5621,7 @@ <InvalidReturnType occurrences="1"> <code>int|bool</code> </InvalidReturnType> - <MixedArgument occurrences="47"> + <MixedArgument occurrences="45"> <code>$_SERVER['SCRIPT_NAME']</code> <code>$a</code> <code>$arrayKeys</code> @@ -5622,8 +5663,6 @@ <code>$this->links[$link]</code> <code>$this->versionComment</code> <code>$this->versionString</code> - <code>$trigger['EVENT_OBJECT_TABLE']</code> - <code>$trigger['TRIGGER_NAME']</code> <code>$user</code> <code>$user</code> <code>$user</code> @@ -5634,7 +5673,7 @@ <code>uksort($eachTables, 'strnatcasecmp')</code> <code>usort($tables, 'strnatcasecmp')</code> </MixedArgumentTypeCoercion> - <MixedArrayAccess occurrences="25"> + <MixedArrayAccess occurrences="8"> <code>$link</code> <code>$oneShow['Db']</code> <code>$oneShow['Name']</code> @@ -5643,32 +5682,7 @@ <code>$tableData['Data_length']</code> <code>$tableData['Engine']</code> <code>$tableData['Index_length']</code> - <code>$trigger['ACTION_STATEMENT']</code> - <code>$trigger['ACTION_STATEMENT']</code> - <code>$trigger['ACTION_TIMING']</code> - <code>$trigger['ACTION_TIMING']</code> - <code>$trigger['DEFINER']</code> - <code>$trigger['Definer']</code> - <code>$trigger['EVENT_MANIPULATION']</code> - <code>$trigger['EVENT_MANIPULATION']</code> - <code>$trigger['EVENT_OBJECT_TABLE']</code> - <code>$trigger['EVENT_OBJECT_TABLE']</code> - <code>$trigger['Event']</code> - <code>$trigger['Statement']</code> - <code>$trigger['TRIGGER_NAME']</code> - <code>$trigger['TRIGGER_NAME']</code> - <code>$trigger['Table']</code> - <code>$trigger['Timing']</code> - <code>$trigger['Trigger']</code> </MixedArrayAccess> - <MixedArrayAssignment occurrences="6"> - <code>$trigger['ACTION_STATEMENT']</code> - <code>$trigger['ACTION_TIMING']</code> - <code>$trigger['DEFINER']</code> - <code>$trigger['EVENT_MANIPULATION']</code> - <code>$trigger['EVENT_OBJECT_TABLE']</code> - <code>$trigger['TRIGGER_NAME']</code> - </MixedArrayAssignment> <MixedArrayOffset occurrences="10"> <code>$databases[$databaseName]</code> <code>$resultRows[$row[$key]]</code> @@ -5681,7 +5695,7 @@ <code>$this->links[$link]</code> <code>$this->links[$link]</code> </MixedArrayOffset> - <MixedAssignment occurrences="34"> + <MixedAssignment occurrences="21"> <code>$aLength</code> <code>$bLength</code> <code>$database</code> @@ -5691,12 +5705,6 @@ <code>$grant</code> <code>$keyIndex</code> <code>$map['real_column']</code> - <code>$oneResult['action_timing']</code> - <code>$oneResult['definer']</code> - <code>$oneResult['definition']</code> - <code>$oneResult['event_manipulation']</code> - <code>$oneResult['name']</code> - <code>$oneResult['table']</code> <code>$oneShow</code> <code>$resultRows[$row[$key]]</code> <code>$resultRows[]</code> @@ -5708,26 +5716,16 @@ <code>$tableData</code> <code>$this->versionComment</code> <code>$this->versionString</code> - <code>$trigger</code> - <code>$trigger['ACTION_STATEMENT']</code> - <code>$trigger['ACTION_TIMING']</code> - <code>$trigger['DEFINER']</code> - <code>$trigger['EVENT_MANIPULATION']</code> - <code>$trigger['EVENT_OBJECT_TABLE']</code> - <code>$trigger['TRIGGER_NAME']</code> <code>$warningsCount</code> </MixedAssignment> <MixedInferredReturnType occurrences="2"> <code>array</code> <code>string</code> </MixedInferredReturnType> - <MixedOperand occurrences="6"> + <MixedOperand occurrences="3"> <code>$a['Data_length']</code> <code>$b['Data_length']</code> <code>$tableData['Data_length']</code> - <code>$trigger['ACTION_STATEMENT']</code> - <code>$trigger['ACTION_TIMING']</code> - <code>$trigger['EVENT_MANIPULATION']</code> </MixedOperand> <MixedPropertyFetch occurrences="1"> <code>$this->links[$link]->warning_count</code> diff --git a/test/classes/Plugins/Export/ExportHtmlwordTest.php b/test/classes/Plugins/Export/ExportHtmlwordTest.php index 47d8de8022..d24fffb876 100644 --- a/test/classes/Plugins/Export/ExportHtmlwordTest.php +++ b/test/classes/Plugins/Export/ExportHtmlwordTest.php @@ -596,23 +596,28 @@ class ExportHtmlwordTest extends AbstractTestCase public function testGetTriggers(): void { + $GLOBALS['cfg']['Server']['DisableIS'] = false; + $dbi = $this->getMockBuilder(DatabaseInterface::class) ->disableOriginalConstructor() ->getMock(); $triggers = [ [ - 'name' => 'tna"me', - 'action_timing' => 'ac>t', - 'event_manipulation' => 'manip&', - 'definition' => 'def', + 'TRIGGER_SCHEMA' => 'database', + 'TRIGGER_NAME' => 'tna"me', + 'EVENT_MANIPULATION' => 'manip&', + 'EVENT_OBJECT_TABLE' => 'table', + 'ACTION_TIMING' => 'ac>t', + 'ACTION_STATEMENT' => 'def', + 'EVENT_OBJECT_SCHEMA' => 'database', + 'DEFINER' => 'test_user@localhost', ], ]; $dbi->expects($this->once()) - ->method('getTriggers') - ->with('database', 'table') - ->will($this->returnValue($triggers)); + ->method('fetchResult') + ->willReturnOnConsecutiveCalls($triggers); $GLOBALS['dbi'] = $dbi; diff --git a/test/classes/Plugins/Export/ExportOdtTest.php b/test/classes/Plugins/Export/ExportOdtTest.php index 9f9c4c4a19..54c50a8d96 100644 --- a/test/classes/Plugins/Export/ExportOdtTest.php +++ b/test/classes/Plugins/Export/ExportOdtTest.php @@ -755,23 +755,28 @@ class ExportOdtTest extends AbstractTestCase public function testGetTriggers(): void { + $GLOBALS['cfg']['Server']['DisableIS'] = false; + $dbi = $this->getMockBuilder(DatabaseInterface::class) ->disableOriginalConstructor() ->getMock(); $triggers = [ [ - 'name' => 'tna"me', - 'action_timing' => 'ac>t', - 'event_manipulation' => 'manip&', - 'definition' => 'def', + 'TRIGGER_SCHEMA' => 'database', + 'TRIGGER_NAME' => 'tna"me', + 'EVENT_MANIPULATION' => 'manip&', + 'EVENT_OBJECT_TABLE' => 'ta<ble', + 'ACTION_TIMING' => 'ac>t', + 'ACTION_STATEMENT' => 'def', + 'EVENT_OBJECT_SCHEMA' => 'database', + 'DEFINER' => 'test_user@localhost', ], ]; $dbi->expects($this->once()) - ->method('getTriggers') - ->with('database', 'ta<ble') - ->will($this->returnValue($triggers)); + ->method('fetchResult') + ->willReturnOnConsecutiveCalls($triggers); $GLOBALS['dbi'] = $dbi; diff --git a/test/classes/Plugins/Export/ExportTexytextTest.php b/test/classes/Plugins/Export/ExportTexytextTest.php index ea50468b47..c8e92ffb7b 100644 --- a/test/classes/Plugins/Export/ExportTexytextTest.php +++ b/test/classes/Plugins/Export/ExportTexytextTest.php @@ -341,23 +341,28 @@ class ExportTexytextTest extends AbstractTestCase public function testGetTriggers(): void { + $GLOBALS['cfg']['Server']['DisableIS'] = false; + $dbi = $this->getMockBuilder(DatabaseInterface::class) ->disableOriginalConstructor() ->getMock(); $triggers = [ [ - 'name' => 'tna"me', - 'action_timing' => 'ac>t', - 'event_manipulation' => 'manip&', - 'definition' => 'def', + 'TRIGGER_SCHEMA' => 'database', + 'TRIGGER_NAME' => 'tna"me', + 'EVENT_MANIPULATION' => 'manip&', + 'EVENT_OBJECT_TABLE' => 'ta<ble', + 'ACTION_TIMING' => 'ac>t', + 'ACTION_STATEMENT' => 'def', + 'EVENT_OBJECT_SCHEMA' => 'database', + 'DEFINER' => 'test_user@localhost', ], ]; $dbi->expects($this->once()) - ->method('getTriggers') - ->with('database', 'ta<ble') - ->will($this->returnValue($triggers)); + ->method('fetchResult') + ->willReturnOnConsecutiveCalls($triggers); $GLOBALS['dbi'] = $dbi; diff --git a/test/classes/Plugins/Export/ExportXmlTest.php b/test/classes/Plugins/Export/ExportXmlTest.php index 41fcbf02d8..1920c9d32e 100644 --- a/test/classes/Plugins/Export/ExportXmlTest.php +++ b/test/classes/Plugins/Export/ExportXmlTest.php @@ -203,23 +203,22 @@ class ExportXmlTest extends AbstractTestCase ->disableOriginalConstructor() ->getMock(); - $dbi->expects($this->exactly(3)) - ->method('fetchResult') - ->willReturnOnConsecutiveCalls($result, $result, []); + $triggers = [ + [ + 'TRIGGER_SCHEMA' => 'd<"b', + 'TRIGGER_NAME' => 'trname', + 'EVENT_MANIPULATION' => 'INSERT', + 'EVENT_OBJECT_TABLE' => 'table', + 'ACTION_TIMING' => 'AFTER', + 'ACTION_STATEMENT' => 'BEGIN END', + 'EVENT_OBJECT_SCHEMA' => 'd<"b', + 'DEFINER' => 'test_user@localhost', + ], + ]; - $dbi->expects($this->once()) - ->method('getTriggers') - ->with('d<"b', 'table') - ->will( - $this->returnValue( - [ - [ - 'create' => 'crt', - 'name' => 'trname', - ], - ] - ) - ); + $dbi->expects($this->exactly(4)) + ->method('fetchResult') + ->willReturnOnConsecutiveCalls($result, $result, [], $triggers); $dbi->expects($this->exactly(2)) ->method('getProceduresOrFunctions') @@ -265,7 +264,8 @@ class ExportXmlTest extends AbstractTestCase ' &quot;tbl&quot;;' . "\n" . ' </pma:table>' . "\n" . ' <pma:trigger name="trname">' . "\n" . - ' ' . "\n" . + ' CREATE TRIGGER `trname` AFTER INSERT ON `table`' . "\n" . + ' FOR EACH ROW BEGIN END' . "\n" . ' </pma:trigger>' . "\n" . ' <pma:function name="fn">' . "\n" . ' fndef' . "\n" . diff --git a/test/classes/TableTest.php b/test/classes/TableTest.php index 75d0d2a759..e2ecfc050b 100644 --- a/test/classes/TableTest.php +++ b/test/classes/TableTest.php @@ -197,6 +197,70 @@ class TableTest extends AbstractTestCase ], ], ], + [ + 'SHOW TRIGGERS FROM `PMA` LIKE \'PMA_BookMark\';', + null, + null, + DatabaseInterface::CONNECT_USER, + [ + [ + 'Trigger' => 'name1', + 'Event' => 'INSERT', + 'Table' => 'PMA_BookMark', + 'Timing' => 'AFTER', + 'Statement' => 'BEGIN END', + 'Definer' => 'test_user@localhost', + ], + [ + 'Trigger' => 'name2', + 'Event' => 'INSERT', + 'Table' => 'PMA_BookMark', + 'Timing' => 'AFTER', + 'Statement' => 'BEGIN END', + 'Definer' => 'test_user@localhost', + ], + [ + 'Trigger' => 'name3', + 'Event' => 'INSERT', + 'Table' => 'PMA_BookMark', + 'Timing' => 'AFTER', + 'Statement' => 'BEGIN END', + 'Definer' => 'test_user@localhost', + ], + ], + ], + [ + 'SHOW TRIGGERS FROM `PMA` LIKE \'PMA_.BookMark\';', + null, + null, + DatabaseInterface::CONNECT_USER, + [ + [ + 'Trigger' => 'name1', + 'Event' => 'INSERT', + 'Table' => 'PMA_.BookMark', + 'Timing' => 'AFTER', + 'Statement' => 'BEGIN END', + 'Definer' => 'test_user@localhost', + ], + [ + 'Trigger' => 'name2', + 'Event' => 'INSERT', + 'Table' => 'PMA_.BookMark', + 'Timing' => 'AFTER', + 'Statement' => 'BEGIN END', + 'Definer' => 'test_user@localhost', + ], + [ + 'Trigger' => 'name3', + 'Event' => 'INSERT', + 'Table' => 'PMA_.BookMark', + 'Timing' => 'AFTER', + 'Statement' => 'BEGIN END', + 'Definer' => 'test_user@localhost', + ], + ], + ], ]; $resultStub = $this->createMock(DummyResult::class); @@ -241,24 +305,6 @@ class TableTest extends AbstractTestCase $dbi->expects($this->any())->method('tryQuery') ->will($this->returnValue($resultStub)); - $triggers = [ - [ - 'name' => 'name1', - 'create' => 'crate1', - ], - [ - 'name' => 'name2', - 'create' => 'crate2', - ], - [ - 'name' => 'name3', - 'create' => 'crate3', - ], - ]; - - $dbi->expects($this->any())->method('getTriggers') - ->will($this->returnValue($triggers)); - $dbi->expects($this->any())->method('query') ->will($this->returnValue($resultStub)); @@ -1031,6 +1077,8 @@ class TableTest extends AbstractTestCase */ public function testRename(): void { + $GLOBALS['cfg']['Server']['DisableIS'] = true; + $table = 'PMA_BookMark'; $db = 'PMA'; |