Remove codegen_format global variable

Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
This commit is contained in:
Maurício Meneghini Fauth 2024-12-18 15:24:30 -03:00
parent 7d7da4a367
commit 020451c7bd
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
6 changed files with 29 additions and 36 deletions

View File

@ -11859,12 +11859,6 @@ parameters:
count: 2
path: src/Plugins/Export/ExportCodegen.php
-
message: '#^Cannot cast mixed to int\.$#'
identifier: cast.int
count: 1
path: src/Plugins/Export/ExportCodegen.php
-
message: '#^Parameter \#1 \$str of static method PhpMyAdmin\\Plugins\\Export\\ExportCodegen\:\:cgMakeIdentifier\(\) expects string, string\|null given\.$#'
identifier: argument.type

View File

@ -1441,7 +1441,6 @@
</MixedArrayAssignment>
<MixedAssignment>
<code><![CDATA[$GLOBALS['charset']]]></code>
<code><![CDATA[$GLOBALS['codegen_format']]]></code>
<code><![CDATA[$GLOBALS['compression']]]></code>
<code><![CDATA[$GLOBALS['csv_columns']]]></code>
<code><![CDATA[$GLOBALS['csv_enclosed']]]></code>
@ -6884,9 +6883,6 @@
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
</DeprecatedMethod>
<NoValue>
<code><![CDATA[$format]]></code>
</NoValue>
<PossiblyNullArgument>
<code><![CDATA[$row[0]]]></code>
<code><![CDATA[$row[0]]]></code>
@ -6896,12 +6892,6 @@
<PossiblyUnusedReturnValue>
<code><![CDATA[bool]]></code>
</PossiblyUnusedReturnValue>
<RedundantCast>
<code><![CDATA[(int) $GLOBALS['codegen_format']]]></code>
</RedundantCast>
<RedundantCondition>
<code><![CDATA[$format === self::HANDLER_NHIBERNATE_XML]]></code>
</RedundantCondition>
</file>
<file src="src/Plugins/Export/ExportCsv.php">
<DeprecatedMethod>

View File

@ -44,7 +44,6 @@
cached_affected_rows: int|numeric-string,
charset: string,
charset_connection: string,
codegen_format: 0|1,
collation_connection: string,
complete_query: string,
compression: 'none'|'zip'|'gzip',

View File

@ -494,10 +494,6 @@ final class ExportController implements InvocableController
$GLOBALS['xkana'] = $postParams['xkana'];
}
if (isset($postParams['codegen_format'])) {
$GLOBALS['codegen_format'] = $postParams['codegen_format'];
}
if (isset($postParams['excel_null'])) {
$GLOBALS['excel_null'] = $postParams['excel_null'];
}

View File

@ -21,6 +21,7 @@ use PhpMyAdmin\Util;
use function __;
use function implode;
use function is_numeric;
use function preg_match;
use function preg_replace;
use function sprintf;
@ -39,6 +40,9 @@ class ExportCodegen extends ExportPlugin
private const HANDLER_NHIBERNATE_CS = 0;
private const HANDLER_NHIBERNATE_XML = 1;
/** @var self::HANDLER_NHIBERNATE_* */
private int $format = self::HANDLER_NHIBERNATE_CS;
/** @psalm-return non-empty-lowercase-string */
public function getName(): string
{
@ -140,17 +144,11 @@ class ExportCodegen extends ExportPlugin
string $sqlQuery,
array $aliases = [],
): bool {
$format = (int) $GLOBALS['codegen_format'];
if ($format === self::HANDLER_NHIBERNATE_CS) {
return $this->export->outputHandler($this->handleNHibernateCSBody($db, $table, $aliases));
}
if ($format === self::HANDLER_NHIBERNATE_XML) {
if ($this->format === self::HANDLER_NHIBERNATE_XML) {
return $this->export->outputHandler($this->handleNHibernateXMLBody($db, $table, $aliases));
}
return $this->export->outputHandler(sprintf('%s is not supported.', $format));
return $this->export->outputHandler($this->handleNHibernateCSBody($db, $table, $aliases));
}
/**
@ -354,5 +352,22 @@ class ExportCodegen extends ExportPlugin
$exportConfig['codegen_structure_or_data'] ?? null,
StructureOrData::Data,
);
$this->format = $this->setFormat(
$request->getParsedBodyParam('codegen_format'),
$exportConfig['codegen_format'] ?? null,
);
}
/** @return self::HANDLER_NHIBERNATE_* */
private function setFormat(mixed $fromRequest, mixed $fromConfig): int
{
$value = self::HANDLER_NHIBERNATE_CS;
if (is_numeric($fromRequest)) {
$value = (int) $fromRequest;
} elseif (is_numeric($fromConfig)) {
$value = (int) $fromConfig;
}
return $value === self::HANDLER_NHIBERNATE_XML ? self::HANDLER_NHIBERNATE_XML : self::HANDLER_NHIBERNATE_CS;
}
}

View File

@ -7,6 +7,7 @@ namespace PhpMyAdmin\Tests\Plugins\Export;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Plugins\Export\ExportCodegen;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup;
@ -166,13 +167,17 @@ class ExportCodegenTest extends AbstractTestCase
public function testExportData(): void
{
$GLOBALS['codegen_format'] = 1;
$GLOBALS['output_kanji_conversion'] = false;
$GLOBALS['output_charset_conversion'] = false;
$GLOBALS['buffer_needed'] = false;
$GLOBALS['asfile'] = true;
$GLOBALS['save_on_server'] = false;
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody(['codegen_format' => '1']);
$this->object->setExportOptions($request, []);
ob_start();
$this->object->exportData('test_db', 'test_table', 'SELECT * FROM `test_db`.`test_table`;');
$result = ob_get_clean();
@ -196,12 +201,6 @@ class ExportCodegenTest extends AbstractTestCase
. '</hibernate-mapping>',
$result,
);
$GLOBALS['codegen_format'] = 4;
$this->object->exportData('test_db', 'test_table', 'SELECT * FROM `test_db`.`test_table`;');
$this->expectOutputString('4 is not supported.');
}
public function testCgMakeIdentifier(): void