diff --git a/libraries/classes/Controllers/Export/ExportController.php b/libraries/classes/Controllers/Export/ExportController.php
index ba9c793e1a..11f43f1686 100644
--- a/libraries/classes/Controllers/Export/ExportController.php
+++ b/libraries/classes/Controllers/Export/ExportController.php
@@ -14,6 +14,7 @@ use PhpMyAdmin\Export;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Message;
use PhpMyAdmin\Plugins;
+use PhpMyAdmin\Plugins\Export\ExportSql;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Sanitize;
use PhpMyAdmin\SqlParser\Parser;
@@ -113,6 +114,10 @@ final class ExportController extends AbstractController
return;
}
+ if ($request->hasBodyParam('sql_backquotes') && $exportPlugin instanceof ExportSql) {
+ $exportPlugin->useSqlBackquotes(true);
+ }
+
/**
* valid compression methods
*/
@@ -827,10 +832,6 @@ final class ExportController extends AbstractController
$GLOBALS['sql_auto_increment'] = $postParams['sql_auto_increment'];
}
- if (isset($postParams['sql_backquotes'])) {
- $GLOBALS['sql_backquotes'] = $postParams['sql_backquotes'];
- }
-
if (isset($postParams['sql_truncate'])) {
$GLOBALS['sql_truncate'] = $postParams['sql_truncate'];
}
diff --git a/libraries/classes/Plugins/Export/ExportSql.php b/libraries/classes/Plugins/Export/ExportSql.php
index 66987fd347..e6fab98a5e 100644
--- a/libraries/classes/Plugins/Export/ExportSql.php
+++ b/libraries/classes/Plugins/Export/ExportSql.php
@@ -69,12 +69,7 @@ class ExportSql extends ExportPlugin
*/
private bool $sentCharset = false;
- private bool $useSqlBackquotes = true;
-
- protected function init(): void
- {
- $this->useSqlBackquotes = isset($GLOBALS['sql_backquotes']);
- }
+ private bool $useSqlBackquotes = false;
/** @psalm-return non-empty-lowercase-string */
public function getName(): string
@@ -82,6 +77,11 @@ class ExportSql extends ExportPlugin
return 'sql';
}
+ public function useSqlBackquotes(bool $useSqlBackquotes): void
+ {
+ $this->useSqlBackquotes = $useSqlBackquotes;
+ }
+
protected function setProperties(): ExportPluginProperties
{
$GLOBALS['plugin_param'] ??= null;
diff --git a/libraries/classes/Table.php b/libraries/classes/Table.php
index a9c84604d2..02a8053bb6 100644
--- a/libraries/classes/Table.php
+++ b/libraries/classes/Table.php
@@ -937,7 +937,6 @@ class Table implements Stringable
}
// Setting required export settings.
- $GLOBALS['sql_backquotes'] = 1;
$GLOBALS['asfile'] = 1;
// Ensuring the target database is valid.
diff --git a/libraries/classes/Tracker.php b/libraries/classes/Tracker.php
index 34a13cd9ef..85f1087bd2 100644
--- a/libraries/classes/Tracker.php
+++ b/libraries/classes/Tracker.php
@@ -184,7 +184,6 @@ class Tracker
$trackingSet = '',
bool $isView = false,
): bool {
- $GLOBALS['sql_backquotes'] ??= null;
$GLOBALS['export_type'] ??= null;
$relation = new Relation($GLOBALS['dbi']);
@@ -200,7 +199,7 @@ class Tracker
return false;
}
- $GLOBALS['sql_backquotes'] = true;
+ $exportSqlPlugin->useSqlBackquotes(true);
$date = Util::date('Y-m-d H:i:s');
@@ -223,8 +222,6 @@ class Tracker
$snapshot = serialize($snapshot);
// Get DROP TABLE / DROP VIEW and CREATE TABLE SQL statements
- $GLOBALS['sql_backquotes'] = true;
-
$createSql = '';
if ($GLOBALS['cfg']['Server']['tracking_add_drop_table'] == true && $isView === false) {
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 1d5cf09eeb..0c73f5c449 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -1973,7 +1973,6 @@
-
@@ -9999,7 +9998,6 @@
-
@@ -13964,7 +13962,6 @@
-
@@ -13986,7 +13983,6 @@
-
$data
$trackingEnabled
diff --git a/test/classes/Plugins/Export/ExportSqlTest.php b/test/classes/Plugins/Export/ExportSqlTest.php
index 2fbfe4d5c0..3a10af82c8 100644
--- a/test/classes/Plugins/Export/ExportSqlTest.php
+++ b/test/classes/Plugins/Export/ExportSqlTest.php
@@ -69,7 +69,6 @@ class ExportSqlTest extends AbstractTestCase
$GLOBALS['plugin_param']['export_type'] = 'table';
$GLOBALS['plugin_param']['single_table'] = false;
$GLOBALS['sql_constraints'] = null;
- $GLOBALS['sql_backquotes'] = null;
$GLOBALS['sql_indexes'] = null;
$GLOBALS['sql_auto_increments'] = null;
@@ -78,6 +77,7 @@ class ExportSqlTest extends AbstractTestCase
new Export($GLOBALS['dbi']),
new Transformations(),
);
+ $this->object->useSqlBackquotes(false);
}
/**
@@ -473,7 +473,6 @@ class ExportSqlTest extends AbstractTestCase
{
$GLOBALS['sql_compatibility'] = 'NONE';
$GLOBALS['sql_drop_database'] = true;
- $GLOBALS['sql_backquotes'] = true;
$GLOBALS['sql_create_database'] = true;
$GLOBALS['sql_create_table'] = true;
$GLOBALS['sql_create_view'] = true;
@@ -491,12 +490,7 @@ class ExportSqlTest extends AbstractTestCase
$GLOBALS['dbi'] = $dbi;
- // Reset the object
- $this->object = new ExportSql(
- new Relation($GLOBALS['dbi']),
- new Export($GLOBALS['dbi']),
- new Transformations(),
- );
+ $this->object->useSqlBackquotes(true);
ob_start();
$this->assertTrue(
@@ -518,7 +512,6 @@ class ExportSqlTest extends AbstractTestCase
// case2: no backquotes
unset($GLOBALS['sql_compatibility']);
$GLOBALS['cfg']['Server']['DisableIS'] = true;
- unset($GLOBALS['sql_backquotes']);
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
@@ -533,12 +526,7 @@ class ExportSqlTest extends AbstractTestCase
$GLOBALS['dbi'] = $dbi;
- // Reset the object
- $this->object = new ExportSql(
- new Relation($GLOBALS['dbi']),
- new Export($GLOBALS['dbi']),
- new Transformations(),
- );
+ $this->object->useSqlBackquotes(false);
ob_start();
$this->assertTrue(
@@ -561,15 +549,9 @@ class ExportSqlTest extends AbstractTestCase
public function testExportDBHeader(): void
{
$GLOBALS['sql_compatibility'] = 'MSSQL';
- $GLOBALS['sql_backquotes'] = true;
$GLOBALS['sql_include_comments'] = true;
- // Reset the object
- $this->object = new ExportSql(
- new Relation($GLOBALS['dbi']),
- new Export($GLOBALS['dbi']),
- new Transformations(),
- );
+ $this->object->useSqlBackquotes(true);
ob_start();
$this->assertTrue(
@@ -583,14 +565,8 @@ class ExportSqlTest extends AbstractTestCase
// case 2
unset($GLOBALS['sql_compatibility']);
- unset($GLOBALS['sql_backquotes']);
- // Reset the object
- $this->object = new ExportSql(
- new Relation($GLOBALS['dbi']),
- new Export($GLOBALS['dbi']),
- new Transformations(),
- );
+ $this->object->useSqlBackquotes(false);
ob_start();
$this->assertTrue(
@@ -791,7 +767,6 @@ class ExportSqlTest extends AbstractTestCase
$GLOBALS['sql_compatibility'] = 'MSSQL';
$GLOBALS['sql_auto_increment'] = true;
$GLOBALS['sql_drop_table'] = true;
- $GLOBALS['sql_backquotes'] = true;
$GLOBALS['sql_if_not_exists'] = true;
$GLOBALS['sql_include_comments'] = true;
if (isset($GLOBALS['sql_constraints'])) {
@@ -845,12 +820,7 @@ SQL;
$GLOBALS['dbi'] = $this->createDatabaseInterface($dbiDummy);
$GLOBALS['cfg']['Server']['DisableIS'] = false;
- // Reset the object
- $this->object = new ExportSql(
- new Relation($GLOBALS['dbi']),
- new Export($GLOBALS['dbi']),
- new Transformations(),
- );
+ $this->object->useSqlBackquotes(true);
$result = $this->object->getTableDef('db', 'table', true, true, false);
@@ -875,7 +845,6 @@ SQL;
$GLOBALS['sql_compatibility'] = '';
$GLOBALS['sql_auto_increment'] = true;
$GLOBALS['sql_drop_table'] = true;
- $GLOBALS['sql_backquotes'] = false;
$GLOBALS['sql_if_not_exists'] = true;
$GLOBALS['sql_include_comments'] = true;
@@ -900,12 +869,7 @@ SQL;
$GLOBALS['dbi'] = $this->createDatabaseInterface($dbiDummy);
$GLOBALS['cfg']['Server']['DisableIS'] = false;
- // Reset the object
- $this->object = new ExportSql(
- new Relation($GLOBALS['dbi']),
- new Export($GLOBALS['dbi']),
- new Transformations(),
- );
+ $this->object->useSqlBackquotes(false);
$result = $this->object->getTableDef('db', 'table', true, true, false);
@@ -977,15 +941,9 @@ SQL;
public function testExportStructure(): void
{
$GLOBALS['sql_compatibility'] = 'MSSQL';
- $GLOBALS['sql_backquotes'] = true;
$GLOBALS['sql_include_comments'] = true;
- // Reset the object
- $this->object = new ExportSql(
- new Relation($GLOBALS['dbi']),
- new Export($GLOBALS['dbi']),
- new Transformations(),
- );
+ $this->object->useSqlBackquotes(true);
// case 1
ob_start();
@@ -1006,17 +964,11 @@ SQL;
// case 2
unset($GLOBALS['sql_compatibility']);
- unset($GLOBALS['sql_backquotes']);
$GLOBALS['sql_create_trigger'] = true;
$GLOBALS['sql_drop_table'] = true;
- // Reset the object
- $this->object = new ExportSql(
- new Relation($GLOBALS['dbi']),
- new Export($GLOBALS['dbi']),
- new Transformations(),
- );
+ $this->object->useSqlBackquotes(false);
ob_start();
$this->assertTrue(
@@ -1042,14 +994,8 @@ SQL;
// case 3
$GLOBALS['sql_views_as_tables'] = false;
- $GLOBALS['sql_backquotes'] = null;
- // Reset the object
- $this->object = new ExportSql(
- new Relation($GLOBALS['dbi']),
- new Export($GLOBALS['dbi']),
- new Transformations(),
- );
+ $this->object->useSqlBackquotes(false);
ob_start();
$this->assertTrue(
@@ -1192,7 +1138,6 @@ SQL;
$GLOBALS['dbi'] = $dbi;
$GLOBALS['sql_compatibility'] = 'MSSQL';
- $GLOBALS['sql_backquotes'] = true;
$GLOBALS['sql_max_query_size'] = 50000;
$GLOBALS['sql_views_as_tables'] = true;
$GLOBALS['sql_type'] = 'INSERT';
@@ -1203,12 +1148,7 @@ SQL;
$GLOBALS['sql_hex_for_binary'] = true;
$GLOBALS['cfg']['Server']['DisableIS'] = false;
- // Reset the object
- $this->object = new ExportSql(
- new Relation($GLOBALS['dbi']),
- new Export($GLOBALS['dbi']),
- new Transformations(),
- );
+ $this->object->useSqlBackquotes(true);
ob_start();
$this->object->exportData('db', 'table', 'example.com/err', 'SELECT a FROM b WHERE 1');
@@ -1300,7 +1240,6 @@ SQL;
$GLOBALS['dbi'] = $dbi;
$GLOBALS['sql_compatibility'] = 'MSSQL';
- $GLOBALS['sql_backquotes'] = true;
$GLOBALS['sql_views_as_tables'] = true;
$GLOBALS['sql_type'] = 'UPDATE';
$GLOBALS['sql_delayed'] = ' DELAYED';
@@ -1310,12 +1249,7 @@ SQL;
$GLOBALS['sql_hex_for_binary'] = true;
$GLOBALS['cfg']['Server']['DisableIS'] = false;
- // Reset the object
- $this->object = new ExportSql(
- new Relation($GLOBALS['dbi']),
- new Export($GLOBALS['dbi']),
- new Transformations(),
- );
+ $this->object->useSqlBackquotes(true);
ob_start();
$this->object->exportData('db', 'table', 'example.com/err', 'SELECT a FROM b WHERE 1');
@@ -1358,14 +1292,8 @@ SQL;
$GLOBALS['sql_include_comments'] = true;
$oldVal = $GLOBALS['sql_compatibility'] ?? '';
$GLOBALS['sql_compatibility'] = 'NONE';
- $GLOBALS['sql_backquotes'] = true;
- // Reset the object
- $this->object = new ExportSql(
- new Relation($GLOBALS['dbi']),
- new Export($GLOBALS['dbi']),
- new Transformations(),
- );
+ $this->object->useSqlBackquotes(true);
ob_start();
$this->assertTrue(