Merge pull request #18461 from kamil-tekiela/Globals-in-Manage

Globals in ManageController
This commit is contained in:
Maurício Meneghini Fauth 2023-06-13 22:22:40 -03:00 committed by GitHub
commit 78e446e073
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 45 deletions

View File

@ -60,12 +60,7 @@ class ManageController extends AbstractController
{
$GLOBALS['cf'] ??= null;
$GLOBALS['error'] ??= null;
$GLOBALS['json'] ??= null;
$GLOBALS['lang'] ??= null;
$GLOBALS['new_config'] ??= null;
$GLOBALS['return_url'] ??= null;
$GLOBALS['form_display'] ??= null;
$GLOBALS['all_ok'] ??= null;
$GLOBALS['query'] ??= null;
$route = $request->getRoute();
@ -111,7 +106,7 @@ class ManageController extends AbstractController
if ($request->hasBodyParam('submit_import')) {
// load from JSON file
$GLOBALS['json'] = '';
$json = '';
if (
$request->hasBodyParam('import_type')
&& $request->getParsedBodyParam('import_type') === 'text_file'
@ -128,18 +123,18 @@ class ManageController extends AbstractController
$GLOBALS['error'] = $importHandle->getError();
} else {
// read JSON from uploaded file
$GLOBALS['json'] = $importHandle->getRawContent();
$json = $importHandle->getRawContent();
}
} else {
// read from POST value (json)
$GLOBALS['json'] = $request->getParsedBodyParam('json');
$json = $request->getParsedBodyParam('json');
}
// hide header message
$_SESSION['userprefs_autoload'] = true;
$configuration = json_decode($GLOBALS['json'], true);
$GLOBALS['return_url'] = $request->getParsedBodyParam('return_url');
$configuration = json_decode($json, true);
$returnUrl = $request->getParsedBodyParam('return_url');
if (! is_array($configuration)) {
if (! isset($GLOBALS['error'])) {
$GLOBALS['error'] = __('Could not import configuration');
@ -147,29 +142,29 @@ class ManageController extends AbstractController
} else {
// sanitize input values: treat them as though
// they came from HTTP POST request
$GLOBALS['form_display'] = new UserFormList($GLOBALS['cf']);
$GLOBALS['new_config'] = $GLOBALS['cf']->getFlatDefaultConfig();
$formDisplay = new UserFormList($GLOBALS['cf']);
$newConfig = $GLOBALS['cf']->getFlatDefaultConfig();
if ($request->hasBodyParam('import_merge')) {
$GLOBALS['new_config'] = array_merge($GLOBALS['new_config'], $GLOBALS['cf']->getConfigArray());
$newConfig = array_merge($newConfig, $GLOBALS['cf']->getConfigArray());
}
$GLOBALS['new_config'] = array_merge($GLOBALS['new_config'], $configuration);
$newConfig = array_merge($newConfig, $configuration);
$postParamBackup = $_POST;
foreach ($GLOBALS['new_config'] as $k => $v) {
foreach ($newConfig as $k => $v) {
$_POST[str_replace('/', '-', (string) $k)] = $v;
}
$GLOBALS['cf']->resetConfigData();
$GLOBALS['all_ok'] = $GLOBALS['form_display']->process(true, false);
$GLOBALS['all_ok'] = $GLOBALS['all_ok'] && ! $GLOBALS['form_display']->hasErrors();
$allOk = $formDisplay->process(true, false);
$allOk = $allOk && ! $formDisplay->hasErrors();
$_POST = $postParamBackup;
if (! $GLOBALS['all_ok'] && $request->hasBodyParam('fix_errors')) {
$GLOBALS['form_display']->fixErrors();
$GLOBALS['all_ok'] = true;
if (! $allOk && $request->hasBodyParam('fix_errors')) {
$formDisplay->fixErrors();
$allOk = true;
}
if (! $GLOBALS['all_ok']) {
if (! $allOk) {
// mimic original form and post json in a hidden field
$relationParameters = $this->relation->getRelationParameters();
@ -180,10 +175,10 @@ class ManageController extends AbstractController
]);
echo $this->template->render('preferences/manage/error', [
'form_errors' => $GLOBALS['form_display']->displayErrors(),
'json' => $GLOBALS['json'],
'form_errors' => $formDisplay->displayErrors(),
'json' => $json,
'import_merge' => $request->getParsedBodyParam('import_merge'),
'return_url' => $GLOBALS['return_url'],
'return_url' => $returnUrl,
]);
return;
@ -207,9 +202,9 @@ class ManageController extends AbstractController
// save settings
$result = $this->userPreferences->save($GLOBALS['cf']->getConfigArray());
if ($result === true) {
if ($GLOBALS['return_url']) {
$GLOBALS['query'] = Util::splitURLQuery($GLOBALS['return_url']);
$GLOBALS['return_url'] = parse_url($GLOBALS['return_url'], PHP_URL_PATH);
if ($returnUrl) {
$GLOBALS['query'] = Util::splitURLQuery($returnUrl);
$returnUrl = parse_url($returnUrl, PHP_URL_PATH);
foreach ($GLOBALS['query'] as $q) {
$pos = mb_strpos($q, '=');
@ -221,12 +216,12 @@ class ManageController extends AbstractController
$redirectParams[$k] = mb_substr($q, $pos + 1);
}
} else {
$GLOBALS['return_url'] = 'index.php?route=/preferences/manage';
$returnUrl = 'index.php?route=/preferences/manage';
}
// reload config
$this->config->loadUserPreferences($this->themeManager);
$this->userPreferences->redirect($GLOBALS['return_url'] ?? '', $redirectParams);
$this->userPreferences->redirect($returnUrl ?? '', $redirectParams);
return;
}

View File

@ -1650,6 +1650,21 @@ parameters:
count: 1
path: libraries/classes/Controllers/Preferences/ManageController.php
-
message: "#^Parameter \\#1 \\$json of function json_decode expects string, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/Preferences/ManageController.php
-
message: "#^Parameter \\#1 \\$url of function parse_url expects string, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/Preferences/ManageController.php
-
message: "#^Parameter \\#1 \\$url of static method PhpMyAdmin\\\\Util\\:\\:splitURLQuery\\(\\) expects string, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/Preferences/ManageController.php
-
message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, \\(int\\|string\\) given\\.$#"
count: 1

View File

@ -2388,42 +2388,31 @@
</file>
<file src="libraries/classes/Controllers/Preferences/ManageController.php">
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['all_ok']]]></code>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['form_display']]]></code>
<code><![CDATA[$GLOBALS['json']]]></code>
<code><![CDATA[$GLOBALS['new_config']]]></code>
<code><![CDATA[$GLOBALS['query']]]></code>
<code><![CDATA[$GLOBALS['return_url']]]></code>
</InvalidArrayOffset>
<MixedArgument>
<code><![CDATA[$GLOBALS['json']]]></code>
<code><![CDATA[$GLOBALS['return_url']]]></code>
<code><![CDATA[$GLOBALS['return_url']]]></code>
<code><![CDATA[$configuration['ThemeDefault']]]></code>
<code><![CDATA[$configuration['ThemeDefault']]]></code>
<code>$json</code>
<code>$returnUrl</code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code>$key</code>
</MixedArgumentTypeCoercion>
<MixedAssignment>
<code><![CDATA[$GLOBALS['all_ok']]]></code>
<code><![CDATA[$GLOBALS['cf']]]></code>
<code><![CDATA[$GLOBALS['form_display']]]></code>
<code><![CDATA[$GLOBALS['json']]]></code>
<code><![CDATA[$GLOBALS['json']]]></code>
<code><![CDATA[$GLOBALS['new_config']]]></code>
<code><![CDATA[$GLOBALS['query']]]></code>
<code><![CDATA[$GLOBALS['return_url']]]></code>
<code><![CDATA[$GLOBALS['return_url']]]></code>
<code><![CDATA[$_POST[str_replace('/', '-', (string) $k)]]]></code>
<code>$configuration</code>
<code>$json</code>
<code><![CDATA[$redirectParams['lang']]]></code>
<code>$returnUrl</code>
<code>$v</code>
<code>$val</code>
</MixedAssignment>
<PossiblyFalseArgument>
<code><![CDATA[$GLOBALS['json']]]></code>
<code>$json</code>
</PossiblyFalseArgument>
<PossiblyFalseOperand>
<code>$pos</code>