Add Response return for UserPreferences::redirect()

Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
This commit is contained in:
Maurício Meneghini Fauth 2025-07-14 22:12:17 -03:00
parent 43ea6900cd
commit 4c789727e9
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
9 changed files with 15 additions and 20 deletions

View File

@ -61,9 +61,8 @@ final readonly class ExportController implements InvocableController
// reload config
$this->config->loadUserPreferences($this->themeManager);
$hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#');
$this->userPreferences->redirect('index.php?route=/preferences/export', null, $hash);
return $this->response->response();
return $this->userPreferences->redirect('index.php?route=/preferences/export', null, $hash);
}
}

View File

@ -61,9 +61,8 @@ final readonly class FeaturesController implements InvocableController
// reload config
$this->config->loadUserPreferences($this->themeManager);
$hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#');
$this->userPreferences->redirect('index.php?route=/preferences/features', null, $hash);
return $this->response->response();
return $this->userPreferences->redirect('index.php?route=/preferences/features', null, $hash);
}
}

View File

@ -61,9 +61,8 @@ final readonly class ImportController implements InvocableController
// reload config
$this->config->loadUserPreferences($this->themeManager);
$hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#');
$this->userPreferences->redirect('index.php?route=/preferences/import', null, $hash);
return $this->response->response();
return $this->userPreferences->redirect('index.php?route=/preferences/import', null, $hash);
}
}

View File

@ -61,9 +61,8 @@ final readonly class MainPanelController implements InvocableController
// reload config
$this->config->loadUserPreferences($this->themeManager);
$hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#');
$this->userPreferences->redirect('index.php?route=/preferences/main-panel', null, $hash);
return $this->response->response();
return $this->userPreferences->redirect('index.php?route=/preferences/main-panel', null, $hash);
}
}

View File

@ -219,9 +219,8 @@ final class ManageController implements InvocableController
// reload config
$this->config->loadUserPreferences($this->themeManager);
$this->userPreferences->redirect($returnUrl ?? '', $redirectParams);
return $this->response->response();
return $this->userPreferences->redirect($returnUrl ?? '', $redirectParams);
}
$error = $result;
@ -230,9 +229,8 @@ final class ManageController implements InvocableController
$result = $this->userPreferences->save([]);
if ($result === true) {
$this->config->removeCookie('pma_lang');
$this->userPreferences->redirect('index.php?route=/preferences/manage');
return $this->response->response();
return $this->userPreferences->redirect('index.php?route=/preferences/manage');
}
return $this->response->response();

View File

@ -61,9 +61,8 @@ final readonly class NavigationController implements InvocableController
// reload config
$this->config->loadUserPreferences($this->themeManager);
$hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#');
$this->userPreferences->redirect('index.php?route=/preferences/navigation', null, $hash);
return $this->response->response();
return $this->userPreferences->redirect('index.php?route=/preferences/navigation', null, $hash);
}
}

View File

@ -61,9 +61,8 @@ final readonly class SqlController implements InvocableController
// reload config
$this->config->loadUserPreferences($this->themeManager);
$hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#');
$this->userPreferences->redirect('index.php?route=/preferences/sql', null, $hash);
return $this->response->response();
return $this->userPreferences->redirect('index.php?route=/preferences/sql', null, $hash);
}
}

View File

@ -9,6 +9,7 @@ use PhpMyAdmin\Config\Forms\User\UserFormList;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Dbal\ConnectionType;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Identifiers\DatabaseName;
use function __;
@ -259,7 +260,7 @@ class UserPreferences
string $fileName,
array|null $params = null,
string|null $hash = null,
): void {
): Response {
// redirect
$urlParams = ['saved' => 1];
if (is_array($params)) {
@ -270,9 +271,12 @@ class UserPreferences
$hash = '#' . urlencode($hash);
}
ResponseRenderer::getInstance()->redirect(
$responseRenderer = ResponseRenderer::getInstance();
$responseRenderer->redirect(
'./' . $fileName . Url::getCommonRaw($urlParams, ! str_contains($fileName, '?') ? '?' : '&') . $hash,
);
return $responseRenderer->response();
}
/**

View File

@ -327,13 +327,12 @@ class UserPreferencesTest extends AbstractTestCase
$dbi = DatabaseInterface::getInstance();
$userPreferences = new UserPreferences($dbi, new Relation($dbi), new Template());
$userPreferences->redirect(
$response = $userPreferences->redirect(
'file.html',
['a' => 'b'],
'h ash',
);
$response = $responseStub->getResponse();
self::assertSame(['/phpmyadmin/file.html?a=b&saved=1&server=2#h+ash'], $response->getHeader('Location'));
self::assertSame(302, $response->getStatusCode());
}