Refactor ExportSql - part 1 (#17955)

* Add getTableStatus method

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Remove unused $errorUrl parameter

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Remove unused parameter $table

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Add string return types

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Refactor exportUseStatement

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Specify param types for exportConfigurationMetadata

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* param types for getTableDefForView

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Param types for getTableComments

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Small fixes

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Extract addCompatOptions() method

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Remove no longer needed suppress

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Merge if statements by SonarLint

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Update phpstan-baseline.neon

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Specify param types for exportRoutineSQL

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Specify param types for generateComment

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Specify param types for replaceWithAliases

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Update psalm-baseline.xml

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Kamil Tekiela 2022-12-14 14:56:22 +00:00 committed by GitHub
parent 9e31295234
commit a84cae6c2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 184 additions and 253 deletions

View File

@ -72,12 +72,7 @@ class ExportSql extends ExportPlugin
protected function init(): void
{
// Avoids undefined variables, use NULL so isset() returns false
if (isset($GLOBALS['sql_backquotes'])) {
return;
}
$GLOBALS['sql_backquotes'] = null;
$GLOBALS['sql_backquotes'] = $GLOBALS['sql_backquotes'] ?? null;
}
/**
@ -210,28 +205,8 @@ class ExportSql extends ExportPlugin
// compatibility maximization
$compats = $GLOBALS['dbi']->getCompatibilities();
if (count($compats) > 0) {
$values = [];
foreach ($compats as $val) {
$values[$val] = $val;
}
$leaf = new SelectPropertyItem(
'compatibility',
__(
'Database system or older MySQL server to maximize output compatibility with:'
)
);
$leaf->setValues($values);
$leaf->setDoc(
[
'manual_MySQL_Database_Administration',
'Server_SQL_mode',
]
);
$generalOptions->addProperty($leaf);
unset($values);
if ($compats !== []) {
$this->addCompatOptions($compats, $generalOptions);
}
// what to dump (structure/data/both)
@ -524,23 +499,23 @@ class ExportSql extends ExportPlugin
/**
* Generates SQL for routines export
*
* @param string $db Database
* @param array $aliases Aliases of db/table/columns
* @param string $name Verbose name of exported routine
* @param array $routines List of routines to export
* @param string $delimiter Delimiter to use in SQL
* @param string $db Database
* @param array $aliases Aliases of db/table/columns
* @param string $name Verbose name of exported routine
* @param string[] $routines List of routines to export
* @param string $delimiter Delimiter to use in SQL
* @psalm-param 'FUNCTION'|'PROCEDURE' $type
*
* @return string SQL query
*/
protected function exportRoutineSQL(
$db,
string $db,
array $aliases,
string $type,
$name,
string $name,
array $routines,
$delimiter
) {
string $delimiter
): string {
$text = $this->exportComment()
. $this->exportComment($name)
. $this->exportComment();
@ -561,8 +536,8 @@ class ExportSql extends ExportPlugin
$definition = Routines::getProcedureDefinition($GLOBALS['dbi'], $db, $routine);
}
$createQuery = $this->replaceWithAliases($definition, $aliases, $db, '', $flag);
if (! empty($createQuery) && $GLOBALS['cfg']['Export']['remove_definer_from_definitions']) {
$createQuery = $this->replaceWithAliases($definition, $aliases, $db, $flag);
if ($createQuery !== '' && $GLOBALS['cfg']['Export']['remove_definer_from_definitions']) {
// Remove definer clause from routine definitions
$parser = new Parser($createQuery);
$statement = $parser->statements[0];
@ -639,7 +614,7 @@ class ExportSql extends ExportPlugin
$text .= 'DELIMITER ;' . "\n";
}
if (! empty($text)) {
if ($text !== '') {
return $this->export->outputHandler($text);
}
@ -682,7 +657,7 @@ class ExportSql extends ExportPlugin
*
* @return string crlf or nothing
*/
private function possibleCRLF()
private function possibleCRLF(): string
{
if (isset($GLOBALS['sql_include_comments']) && $GLOBALS['sql_include_comments']) {
return "\n";
@ -762,7 +737,7 @@ class ExportSql extends ExportPlugin
. $this->exportComment(__('PHP Version:') . ' ' . PHP_VERSION)
. $this->possibleCRLF();
if (isset($GLOBALS['sql_header_comment']) && ! empty($GLOBALS['sql_header_comment'])) {
if (! empty($GLOBALS['sql_header_comment'])) {
// '\n' is not a newline (like "\n" would be), it's the characters
// backslash and n, as explained on the export interface
$lines = explode('\n', $GLOBALS['sql_header_comment']);
@ -837,7 +812,7 @@ class ExportSql extends ExportPlugin
*/
public function exportDBCreate($db, $exportType, $dbAlias = ''): bool
{
if (empty($dbAlias)) {
if ($dbAlias === '') {
$dbAlias = $db;
}
@ -892,10 +867,10 @@ class ExportSql extends ExportPlugin
* @param string $db db to use
* @param string $compat sql compatibility
*/
private function exportUseStatement($db, $compat): bool
private function exportUseStatement(string $db, string $compat): bool
{
if (isset($GLOBALS['sql_compatibility']) && $GLOBALS['sql_compatibility'] === 'NONE') {
$result = $this->export->outputHandler(
if ($compat === 'NONE') {
return $this->export->outputHandler(
'USE '
. Util::backquoteCompat(
$db,
@ -904,11 +879,9 @@ class ExportSql extends ExportPlugin
)
. ';' . "\n"
);
} else {
$result = $this->export->outputHandler('USE ' . $db . ';' . "\n");
}
return $result;
return $this->export->outputHandler('USE ' . $db . ';' . "\n");
}
/**
@ -919,7 +892,7 @@ class ExportSql extends ExportPlugin
*/
public function exportDBHeader($db, $dbAlias = ''): bool
{
if (empty($dbAlias)) {
if ($dbAlias === '') {
$dbAlias = $db;
}
@ -1000,7 +973,11 @@ class ExportSql extends ExportPlugin
}
$eventDef = Events::getDefinition($GLOBALS['dbi'], $db, $eventName);
if (! empty($eventDef) && $GLOBALS['cfg']['Export']['remove_definer_from_definitions']) {
if (
$eventDef !== null
&& $eventDef !== ''
&& $GLOBALS['cfg']['Export']['remove_definer_from_definitions']
) {
// remove definer clause from the event definition
$parser = new Parser($eventDef);
$statement = $parser->statements[0];
@ -1014,7 +991,7 @@ class ExportSql extends ExportPlugin
$text .= 'DELIMITER ;' . "\n";
}
if (! empty($text)) {
if ($text !== '') {
return $this->export->outputHandler($text);
}
@ -1024,9 +1001,9 @@ class ExportSql extends ExportPlugin
/**
* Exports metadata from Configuration Storage
*
* @param string $db database being exported
* @param string|array $tables table(s) being exported
* @param array $metadataTypes types of metadata to export
* @param string $db database being exported
* @param string|string[] $tables table(s) being exported
* @param string[] $metadataTypes types of metadata to export
*/
public function exportMetadata(
$db,
@ -1073,11 +1050,11 @@ class ExportSql extends ExportPlugin
*
* @param string $db database being exported
* @param string|null $table table being exported
* @param array $metadataTypes types of metadata to export
* @param string[] $metadataTypes types of metadata to export
*/
private function exportConfigurationMetadata(
$db,
$table,
string $db,
?string $table,
array $metadataTypes
): bool {
$relationParameters = $this->relation->getRelationParameters();
@ -1101,10 +1078,9 @@ class ExportSql extends ExportPlugin
$aliases = [];
$comment = $this->possibleCRLF()
. $this->exportComment();
$comment = $this->possibleCRLF() . $this->exportComment();
if (isset($table)) {
if ($table !== null) {
$comment .= $this->exportComment(
sprintf(
__('Metadata for table %s'),
@ -1245,7 +1221,7 @@ class ExportSql extends ExportPlugin
*
* @return string resulting definition
*/
public function getTableDefStandIn($db, $view, $aliases = [])
public function getTableDefStandIn($db, $view, $aliases = []): string
{
$dbAlias = $db;
$viewAlias = $view;
@ -1288,10 +1264,10 @@ class ExportSql extends ExportPlugin
* @return string resulting schema
*/
private function getTableDefForView(
$db,
$view,
string $db,
string $view,
array $aliases = []
) {
): string {
$dbAlias = $db;
$viewAlias = $view;
$this->initAlias($aliases, $dbAlias, $viewAlias);
@ -1358,8 +1334,6 @@ class ExportSql extends ExportPlugin
*
* @param string $db the database name
* @param string $table the table name
* @param string $errorUrl the url to go back in case
* of error
* @param bool $showDates whether to include creation/
* update/check dates
* @param bool $addSemicolon whether to add semicolon and
@ -1374,13 +1348,12 @@ class ExportSql extends ExportPlugin
public function getTableDef(
$db,
$table,
$errorUrl,
$showDates = false,
$addSemicolon = true,
$view = false,
$updateIndexesIncrements = true,
array $aliases = []
) {
): string {
$GLOBALS['sql_drop_table'] = $GLOBALS['sql_drop_table'] ?? null;
$GLOBALS['sql_backquotes'] = $GLOBALS['sql_backquotes'] ?? null;
$GLOBALS['sql_constraints'] = $GLOBALS['sql_constraints'] ?? null;
@ -1394,52 +1367,9 @@ class ExportSql extends ExportPlugin
$tableAlias = $table;
$this->initAlias($aliases, $dbAlias, $tableAlias);
$schemaCreate = '';
$newCrlf = "\n";
$compat = $GLOBALS['sql_compatibility'] ?? 'NONE';
$result = $GLOBALS['dbi']->tryQuery(
'SHOW TABLE STATUS FROM ' . Util::backquote($db)
. ' WHERE Name = ' . $GLOBALS['dbi']->quoteString((string) $table)
);
if ($result != false) {
if ($result->numRows() > 0) {
$tmpres = $result->fetchAssoc();
if ($showDates && isset($tmpres['Create_time']) && ! empty($tmpres['Create_time'])) {
$schemaCreate .= $this->exportComment(
__('Creation:') . ' '
. Util::localisedDate(
strtotime($tmpres['Create_time'])
)
);
$newCrlf = $this->exportComment() . "\n";
}
if ($showDates && isset($tmpres['Update_time']) && ! empty($tmpres['Update_time'])) {
$schemaCreate .= $this->exportComment(
__('Last update:') . ' '
. Util::localisedDate(
strtotime($tmpres['Update_time'])
)
);
$newCrlf = $this->exportComment() . "\n";
}
if ($showDates && isset($tmpres['Check_time']) && ! empty($tmpres['Check_time'])) {
$schemaCreate .= $this->exportComment(
__('Last check:') . ' '
. Util::localisedDate(
strtotime($tmpres['Check_time'])
)
);
$newCrlf = $this->exportComment() . "\n";
}
}
}
$schemaCreate .= $newCrlf;
$schemaCreate = $this->getTableStatus($db, $table, $showDates);
if (! empty($GLOBALS['sql_drop_table']) && $GLOBALS['dbi']->getTable($db, $table)->isView()) {
$schemaCreate .= 'DROP VIEW IF EXISTS '
@ -1559,7 +1489,7 @@ class ExportSql extends ExportPlugin
}
// Substitute aliases in `CREATE` query.
$createQuery = $this->replaceWithAliases($createQuery, $aliases, $db, $table, $flag);
$createQuery = $this->replaceWithAliases($createQuery, $aliases, $db, $flag);
// One warning per view.
if ($flag && $view) {
@ -1669,7 +1599,7 @@ class ExportSql extends ExportPlugin
// Creating the parts that add constraints.
$constraints[] = $field::build($field);
unset($statement->fields[$key]);
} elseif (! empty($field->key)) {
} elseif ($field->key !== null) {
// Creating the parts that add indexes (must not be
// constraints).
if ($field->key->type === 'FULLTEXT KEY') {
@ -1688,15 +1618,13 @@ class ExportSql extends ExportPlugin
}
// Creating the parts that drop foreign keys.
if (! empty($field->key)) {
if ($field->key->type === 'FOREIGN KEY') {
$dropped[] = 'FOREIGN KEY ' . Context::escape($field->name);
unset($statement->fields[$key]);
}
if ($field->key !== null && $field->key->type === 'FOREIGN KEY') {
$dropped[] = 'FOREIGN KEY ' . Context::escape($field->name);
unset($statement->fields[$key]);
}
// Dropping AUTO_INCREMENT.
if (empty($field->options)) {
if ($field->options === null) {
continue;
}
@ -1723,7 +1651,7 @@ class ExportSql extends ExportPlugin
$alterFooter = ';' . "\n";
// Generating constraints-related query.
if (! empty($constraints)) {
if ($constraints !== []) {
$GLOBALS['sql_constraints_query'] = $alterHeader . "\n" . ' ADD '
. implode(',' . "\n" . ' ADD ', $constraints)
. $alterFooter;
@ -1740,13 +1668,13 @@ class ExportSql extends ExportPlugin
// Generating indexes-related query.
$GLOBALS['sql_indexes_query'] = '';
if (! empty($indexes)) {
if ($indexes !== []) {
$GLOBALS['sql_indexes_query'] .= $alterHeader . "\n" . ' ADD '
. implode(',' . "\n" . ' ADD ', $indexes)
. $alterFooter;
}
if (! empty($indexesFulltext)) {
if ($indexesFulltext !== []) {
// InnoDB supports one FULLTEXT index creation at a time.
// So FULLTEXT indexes are created one-by-one after other
// indexes where created.
@ -1755,7 +1683,7 @@ class ExportSql extends ExportPlugin
. $alterFooter;
}
if (! empty($indexes) || ! empty($indexesFulltext)) {
if ($indexes !== [] || $indexesFulltext !== []) {
$GLOBALS['sql_indexes'] = $this->generateComment(
$GLOBALS['sql_indexes'],
__('Indexes for dumped tables'),
@ -1766,7 +1694,7 @@ class ExportSql extends ExportPlugin
}
// Generating drop foreign keys-related query.
if (! empty($dropped)) {
if ($dropped !== []) {
$GLOBALS['sql_drop_foreign_keys'] = $alterHeader . "\n" . ' DROP '
. implode(',' . "\n" . ' DROP ', $dropped)
. $alterFooter;
@ -1779,15 +1707,10 @@ class ExportSql extends ExportPlugin
if (
isset($GLOBALS['sql_auto_increment'])
&& ($statement->entityOptions->has('AUTO_INCREMENT') !== false)
&& (! isset($GLOBALS['table_data']) || in_array($table, $GLOBALS['table_data']))
) {
if (
! isset($GLOBALS['table_data'])
|| (isset($GLOBALS['table_data'])
&& in_array($table, $GLOBALS['table_data']))
) {
$sqlAutoIncrementsQuery .= ', AUTO_INCREMENT='
. $statement->entityOptions->has('AUTO_INCREMENT');
}
$sqlAutoIncrementsQuery .= ', AUTO_INCREMENT='
. $statement->entityOptions->has('AUTO_INCREMENT');
}
$sqlAutoIncrementsQuery .= ';' . "\n";
@ -1804,7 +1727,7 @@ class ExportSql extends ExportPlugin
// Removing the `AUTO_INCREMENT` attribute from the `CREATE TABLE`
// too.
if (
! empty($statement->entityOptions)
$statement->entityOptions !== null
&& (empty($GLOBALS['sql_if_not_exists'])
|| empty($GLOBALS['sql_auto_increment']))
) {
@ -1836,12 +1759,12 @@ class ExportSql extends ExportPlugin
* @return string resulting comments
*/
private function getTableComments(
$db,
$table,
$doRelation = false,
$doMime = false,
string $db,
string $table,
bool $doRelation = false,
bool $doMime = false,
array $aliases = []
) {
): string {
$GLOBALS['sql_backquotes'] = $GLOBALS['sql_backquotes'] ?? null;
$dbAlias = $db;
@ -1859,14 +1782,12 @@ class ExportSql extends ExportPlugin
$table
);
$mimeMap = null;
if ($doMime && $relationParameters->browserTransformationFeature !== null) {
$mimeMap = $this->transformations->getMime($db, $table, true);
if ($mimeMap === null) {
unset($mimeMap);
}
}
if (isset($mimeMap) && count($mimeMap) > 0) {
if ($mimeMap !== null && $mimeMap !== []) {
$schemaCreate .= $this->possibleCRLF()
. $this->exportComment()
. $this->exportComment(
@ -2028,7 +1949,7 @@ class ExportSql extends ExportPlugin
__('Table structure for table') . ' ' . $formattedTableName
);
$dump .= $this->exportComment();
$dump .= $this->getTableDef($db, $table, $errorUrl, $dates, true, false, true, $aliases);
$dump .= $this->getTableDef($db, $table, $dates, true, false, true, $aliases);
$dump .= $this->getTableComments($db, $table, $relation, $mime, $aliases);
break;
case 'triggers':
@ -2050,7 +1971,7 @@ class ExportSql extends ExportPlugin
}
$triggerQuery .= 'DELIMITER ' . $delimiter . "\n";
$triggerQuery .= $this->replaceWithAliases($trigger['create'], $aliases, $db, $table, $flag);
$triggerQuery .= $this->replaceWithAliases($trigger['create'], $aliases, $db, $flag);
if ($flag) {
$usedAlias = true;
}
@ -2087,7 +2008,7 @@ class ExportSql extends ExportPlugin
. Util::backquote($tableAlias) . ';' . "\n";
}
$dump .= $this->getTableDef($db, $table, $errorUrl, $dates, true, true, true, $aliases);
$dump .= $this->getTableDef($db, $table, $dates, true, true, true, $aliases);
} else {
$dump .= $this->exportComment(
sprintf(
@ -2452,7 +2373,7 @@ class ExportSql extends ExportPlugin
*
* @return string MSSQL compatible create table statement
*/
private function makeCreateTableMSSQLCompatible(string $createQuery)
private function makeCreateTableMSSQLCompatible(string $createQuery): string
{
// In MSSQL
// 1. No 'IF NOT EXISTS' in CREATE TABLE
@ -2541,21 +2462,19 @@ class ExportSql extends ExportPlugin
/**
* replaces db/table/column names with their aliases
*
* @param string $sqlQuery SQL query in which aliases are to be substituted
* @param array $aliases Alias information for db/table/column
* @param string $db the database name
* @param string $table the tablename
* @param string $flag the flag denoting whether any replacement was done
* @param string $sqlQuery SQL query in which aliases are to be substituted
* @param array $aliases Alias information for db/table/column
* @param string $db the database name
* @param bool|null $flag the flag denoting whether any replacement was done
*
* @return string query replaced with aliases
*/
public function replaceWithAliases(
$sqlQuery,
string $sqlQuery,
array $aliases,
$db,
$table = '',
&$flag = null
) {
string $db,
?bool &$flag = null
): string {
$flag = false;
/**
@ -2620,15 +2539,16 @@ class ExportSql extends ExportPlugin
$fields = $statement->fields;
foreach ($fields as $field) {
// Column name.
if (! empty($field->type)) {
if (! empty($aliases[$oldDatabase]['tables'][$oldTable]['columns'][$field->name])) {
$field->name = $aliases[$oldDatabase]['tables'][$oldTable]['columns'][$field->name];
$flag = true;
}
if (
$field->type !== null
&& ! empty($aliases[$oldDatabase]['tables'][$oldTable]['columns'][$field->name])
) {
$field->name = $aliases[$oldDatabase]['tables'][$oldTable]['columns'][$field->name];
$flag = true;
}
// Key's columns.
if (! empty($field->key)) {
if ($field->key !== null) {
foreach ($field->key->columns as $key => $column) {
if (! isset($column['name'])) {
// In case the column has no name field
@ -2646,7 +2566,7 @@ class ExportSql extends ExportPlugin
}
// References.
if (empty($field->references)) {
if ($field->references === null) {
continue;
}
@ -2719,7 +2639,7 @@ class ExportSql extends ExportPlugin
}
$alias = $this->getAlias($aliases, $token->value);
if (empty($alias)) {
if ($alias === '') {
continue;
}
@ -2740,17 +2660,15 @@ class ExportSql extends ExportPlugin
* @param string $comment2 Comment for current table
* @param string $tableAlias Table alias
* @param string $compat Compatibility mode
*
* @return string
*/
protected function generateComment(
?string $sqlStatement,
$comment1,
$comment2,
$tableAlias,
$compat
) {
if (! isset($sqlStatement)) {
string $comment1,
string $comment2,
string $tableAlias,
string $compat
): string {
if ($sqlStatement === null) {
if (isset($GLOBALS['no_constraints_comments'])) {
$sqlStatement = '';
} else {
@ -2777,4 +2695,76 @@ class ExportSql extends ExportPlugin
return $sqlStatement;
}
private function getTableStatus(string $db, string $table, bool $showDates): string
{
$newCrlf = "\n";
$schemaCreate = '';
$result = $GLOBALS['dbi']->tryQuery(
'SHOW TABLE STATUS FROM ' . Util::backquote($db)
. ' WHERE Name = ' . $GLOBALS['dbi']->quoteString($table)
);
if ($result !== false && $result->numRows() > 0) {
$tmpres = $result->fetchAssoc();
if ($showDates && isset($tmpres['Create_time']) && ! empty($tmpres['Create_time'])) {
$schemaCreate .= $this->exportComment(
__('Creation:') . ' '
. Util::localisedDate(
strtotime($tmpres['Create_time'])
)
);
$newCrlf = $this->exportComment() . "\n";
}
if ($showDates && isset($tmpres['Update_time']) && ! empty($tmpres['Update_time'])) {
$schemaCreate .= $this->exportComment(
__('Last update:') . ' '
. Util::localisedDate(
strtotime($tmpres['Update_time'])
)
);
$newCrlf = $this->exportComment() . "\n";
}
if ($showDates && isset($tmpres['Check_time']) && ! empty($tmpres['Check_time'])) {
$schemaCreate .= $this->exportComment(
__('Last check:') . ' '
. Util::localisedDate(
strtotime($tmpres['Check_time'])
)
);
$newCrlf = $this->exportComment() . "\n";
}
}
return $schemaCreate . $newCrlf;
}
/**
* @param string[] $compats
*/
private function addCompatOptions(array $compats, OptionsPropertyMainGroup $generalOptions): void
{
$values = [];
foreach ($compats as $val) {
$values[$val] = $val;
}
$leaf = new SelectPropertyItem(
'compatibility',
__(
'Database system or older MySQL server to maximize output compatibility with:'
)
);
$leaf->setValues($values);
$leaf->setDoc(
[
'manual_MySQL_Database_Administration',
'Server_SQL_mode',
]
);
$generalOptions->addProperty($leaf);
}
}

View File

@ -39,9 +39,6 @@ abstract class ExportPlugin implements Plugin
/** @var Transformations */
protected $transformations;
/**
* @psalm-suppress InvalidArrayOffset, MixedAssignment, MixedMethodCall
*/
final public function __construct(Relation $relation, Export $export, Transformations $transformations)
{
$this->relation = $relation;
@ -176,9 +173,9 @@ abstract class ExportPlugin implements Plugin
/**
* Exports metadata from Configuration Storage
*
* @param string $db database being exported
* @param string|array $tables table(s) being exported
* @param array $metadataTypes types of metadata to export
* @param string $db database being exported
* @param string|string[] $tables table(s) being exported
* @param string[] $metadataTypes types of metadata to export
*/
public function exportMetadata(
$db,

View File

@ -1056,7 +1056,6 @@ class Table implements Stringable
$sqlStructure = $exportSqlPlugin->getTableDef(
$sourceDb,
$sourceTable,
"\n",
$GLOBALS['errorUrl'],
false,
false

View File

@ -245,7 +245,7 @@ class Tracker
. 'DROP VIEW IF EXISTS ' . Util::backquote($tableName) . ";\n";
}
$createSql .= self::getLogComment() . $exportSqlPlugin->getTableDef($dbName, $tableName, '');
$createSql .= self::getLogComment() . $exportSqlPlugin->getTableDef($dbName, $tableName);
// Save version
$trackingFeature = $relation->getRelationParameters()->trackingFeature;

View File

@ -5980,41 +5980,16 @@ parameters:
count: 1
path: libraries/classes/Plugins/Export/ExportSql.php
-
message: "#^Casting to string something that's already string\\.$#"
count: 1
path: libraries/classes/Plugins/Export/ExportSql.php
-
message: "#^Method PhpMyAdmin\\\\Plugins\\\\Export\\\\ExportSql\\:\\:exportConfigurationMetadata\\(\\) has parameter \\$metadataTypes with no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Plugins/Export/ExportSql.php
-
message: "#^Method PhpMyAdmin\\\\Plugins\\\\Export\\\\ExportSql\\:\\:exportData\\(\\) has parameter \\$aliases with no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Plugins/Export/ExportSql.php
-
message: "#^Method PhpMyAdmin\\\\Plugins\\\\Export\\\\ExportSql\\:\\:exportMetadata\\(\\) has parameter \\$metadataTypes with no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Plugins/Export/ExportSql.php
-
message: "#^Method PhpMyAdmin\\\\Plugins\\\\Export\\\\ExportSql\\:\\:exportMetadata\\(\\) has parameter \\$tables with no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Plugins/Export/ExportSql.php
-
message: "#^Method PhpMyAdmin\\\\Plugins\\\\Export\\\\ExportSql\\:\\:exportRoutineSQL\\(\\) has parameter \\$aliases with no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Plugins/Export/ExportSql.php
-
message: "#^Method PhpMyAdmin\\\\Plugins\\\\Export\\\\ExportSql\\:\\:exportRoutineSQL\\(\\) has parameter \\$routines with no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Plugins/Export/ExportSql.php
-
message: "#^Method PhpMyAdmin\\\\Plugins\\\\Export\\\\ExportSql\\:\\:exportRoutines\\(\\) has parameter \\$aliases with no value type specified in iterable type array\\.$#"
count: 1
@ -6225,16 +6200,6 @@ parameters:
count: 1
path: libraries/classes/Plugins/ExportPlugin.php
-
message: "#^Method PhpMyAdmin\\\\Plugins\\\\ExportPlugin\\:\\:exportMetadata\\(\\) has parameter \\$metadataTypes with no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Plugins/ExportPlugin.php
-
message: "#^Method PhpMyAdmin\\\\Plugins\\\\ExportPlugin\\:\\:exportMetadata\\(\\) has parameter \\$tables with no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Plugins/ExportPlugin.php
-
message: "#^Method PhpMyAdmin\\\\Plugins\\\\ExportPlugin\\:\\:exportRoutines\\(\\) has parameter \\$aliases with no value type specified in iterable type array\\.$#"
count: 1

View File

@ -6403,10 +6403,11 @@
<code>$table</code>
<code>$view</code>
</MixedArgument>
<MixedArgumentTypeCoercion occurrences="3">
<MixedArgumentTypeCoercion occurrences="4">
<code>$dbSelect</code>
<code>$nonGeneratedCols</code>
<code>$nonGeneratedCols</code>
<code>$tables</code>
</MixedArgumentTypeCoercion>
<MixedArrayAccess occurrences="1">
<code>$aliases[$db-&gt;getName()]['alias']</code>
@ -9611,7 +9612,7 @@
<code>$GLOBALS['cfg']['Export']</code>
<code>$GLOBALS['cfg']['Export']</code>
</InvalidArrayOffset>
<MixedArgument occurrences="51">
<MixedArgument occurrences="44">
<code>$GLOBALS['sql_auto_increments']</code>
<code>$GLOBALS['sql_auto_increments']</code>
<code>$GLOBALS['sql_backquotes']</code>
@ -9648,37 +9649,30 @@
<code>$engine</code>
<code>$eventName</code>
<code>$eventName</code>
<code>$mimeField</code>
<code>$mimeMap</code>
<code>$mime['mimetype']</code>
<code>$oneKey['ref_index_list'][$index]</code>
<code>$oneKey['ref_table_name']</code>
<code>$relFieldAlias</code>
<code>$relFieldAlias</code>
<code>$rel['foreign_field']</code>
<code>$rel['foreign_table']</code>
<code>$routine</code>
<code>$routine</code>
<code>$routine</code>
<code>$table</code>
<code>$token-&gt;value</code>
<code>$trigger['create']</code>
</MixedArgument>
<MixedArgumentTypeCoercion occurrences="5">
<MixedArgumentTypeCoercion occurrences="6">
<code>$autoIncrement</code>
<code>$compats</code>
<code>$constraints</code>
<code>$dropped</code>
<code>$indexes</code>
<code>$indexesFulltext</code>
</MixedArgumentTypeCoercion>
<MixedArrayAccess occurrences="14">
<MixedArrayAccess occurrences="13">
<code>$GLOBALS['cfg']['Export']['remove_definer_from_definitions']</code>
<code>$GLOBALS['cfg']['Export']['remove_definer_from_definitions']</code>
<code>$GLOBALS['cfg']['Export']['remove_definer_from_definitions']</code>
<code>$aliases[$oldDatabase]['tables']</code>
<code>$columnAliases[$column['name']]</code>
<code>$definition['Type']</code>
<code>$mime['mimetype']</code>
<code>$oneKey['index_list']</code>
<code>$oneKey['ref_index_list']</code>
<code>$oneKey['ref_table_name']</code>
@ -9687,20 +9681,20 @@
<code>$trigger['create']</code>
<code>$trigger['drop']</code>
</MixedArrayAccess>
<MixedArrayOffset occurrences="4">
<MixedArrayOffset occurrences="3">
<code>$aliases[$db]['tables'][$table]['columns'][$field]</code>
<code>$aliases[$db]['tables'][$view]['columns'][$colAlias]</code>
<code>$oneKey['ref_index_list'][$index]</code>
<code>$values[$val]</code>
</MixedArrayOffset>
<MixedArrayTypeCoercion occurrences="1">
<code>$row[$j]</code>
</MixedArrayTypeCoercion>
<MixedAssignment occurrences="35">
<MixedAssignment occurrences="30">
<code>$GLOBALS['sql_auto_increments']</code>
<code>$GLOBALS['sql_backquotes']</code>
<code>$GLOBALS['sql_backquotes']</code>
<code>$GLOBALS['sql_backquotes']</code>
<code>$GLOBALS['sql_backquotes']</code>
<code>$GLOBALS['sql_drop_table']</code>
<code>$GLOBALS['sql_indexes']</code>
<code>$GLOBALS['sql_indexes_query']</code>
@ -9716,22 +9710,16 @@
<code>$field-&gt;name</code>
<code>$field-&gt;references-&gt;table-&gt;table</code>
<code>$index</code>
<code>$mime</code>
<code>$mimeField</code>
<code>$newDatabase</code>
<code>$newTable</code>
<code>$oneKey</code>
<code>$rel</code>
<code>$relFieldAlias</code>
<code>$relFieldAlias</code>
<code>$routine</code>
<code>$statement-&gt;name-&gt;database</code>
<code>$statement-&gt;name-&gt;table</code>
<code>$statement-&gt;table-&gt;table</code>
<code>$table</code>
<code>$trigger</code>
<code>$val</code>
<code>$values[$val]</code>
</MixedAssignment>
<MixedOperand occurrences="6">
<code>$column['Collation']</code>
@ -9785,7 +9773,8 @@
<code>$statement-&gt;name-&gt;table</code>
<code>$statement-&gt;table-&gt;table</code>
</PossiblyNullPropertyFetch>
<PossiblyNullReference occurrences="6">
<PossiblyNullReference occurrences="7">
<code>has</code>
<code>has</code>
<code>has</code>
<code>remove</code>
@ -9796,13 +9785,6 @@
<PropertyTypeCoercion occurrences="1">
<code>$field-&gt;key-&gt;columns</code>
</PropertyTypeCoercion>
<RedundantCastGivenDocblockType occurrences="1">
<code>(string) $table</code>
</RedundantCastGivenDocblockType>
<ReferenceConstraintViolation occurrences="2">
<code>return $sqlQuery;</code>
<code>return $statement-&gt;build();</code>
</ReferenceConstraintViolation>
<UnnecessaryVarAnnotation occurrences="2">
<code>CreateDefinition</code>
<code>FieldMetadata[]</code>

View File

@ -839,7 +839,7 @@ class ExportSqlTest extends AbstractTestCase
$GLOBALS['dbi'] = $dbi;
$GLOBALS['cfg']['Server']['DisableIS'] = false;
$result = $this->object->getTableDef('db', 'table', 'example.com/err', true, true, false);
$result = $this->object->getTableDef('db', 'table', true, true, false);
$this->assertStringContainsString('-- Creation: Jan 01, 2000 at 10:00 AM', $result);
@ -941,7 +941,7 @@ class ExportSqlTest extends AbstractTestCase
$GLOBALS['dbi'] = $dbi;
$GLOBALS['cfg']['Server']['DisableIS'] = false;
$result = $this->object->getTableDef('db', 'table', 'example.com/err', true, true, false);
$result = $this->object->getTableDef('db', 'table', true, true, false);
$this->assertStringContainsString('-- Error reading structure for table db.table: error occurred', $result);
}
@ -1566,7 +1566,6 @@ class ExportSqlTest extends AbstractTestCase
];
$db = 'a';
$table = 'foo';
$sql_query = "CREATE TABLE IF NOT EXISTS foo (\n"
. "baz tinyint(3) unsigned NOT NULL COMMENT 'Primary Key',\n"
. 'xyz varchar(255) COLLATE latin1_general_ci NOT NULL '
@ -1577,7 +1576,7 @@ class ExportSqlTest extends AbstractTestCase
. "REFERENCES dept_master (baz)\n"
. ') ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE='
. "latin1_general_ci COMMENT='List' AUTO_INCREMENT=5";
$result = $this->object->replaceWithAliases($sql_query, $aliases, $db, $table);
$result = $this->object->replaceWithAliases($sql_query, $aliases, $db);
$this->assertEquals(
"CREATE TABLE IF NOT EXISTS `bartest` (\n" .
@ -1589,7 +1588,7 @@ class ExportSqlTest extends AbstractTestCase
$result
);
$result = $this->object->replaceWithAliases($sql_query, [], '', '');
$result = $this->object->replaceWithAliases($sql_query, [], '');
$this->assertEquals(
"CREATE TABLE IF NOT EXISTS foo (\n" .
@ -1601,7 +1600,6 @@ class ExportSqlTest extends AbstractTestCase
$result
);
$table = 'bar';
$sql_query = 'CREATE TRIGGER `BEFORE_bar_INSERT` '
. 'BEFORE INSERT ON `bar` '
. 'FOR EACH ROW BEGIN '
@ -1611,7 +1609,7 @@ class ExportSqlTest extends AbstractTestCase
. 'IF @cnt<>0 THEN '
. 'SET NEW.xy=1; '
. 'END IF; END';
$result = $this->object->replaceWithAliases($sql_query, $aliases, $db, $table);
$result = $this->object->replaceWithAliases($sql_query, $aliases, $db);
$this->assertEquals(
'CREATE TRIGGER `BEFORE_bar_INSERT` BEFORE INSERT ON `f` FOR EACH ROW BEGIN ' .