Pass ServerRequest object to Indexes::doSaveData() method

This removes the need to call Application::getRequest().

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2023-08-06 13:17:12 -03:00
parent e8ebb663cc
commit f570bf64bf
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
5 changed files with 23 additions and 20 deletions

View File

@ -88,6 +88,7 @@ final class IndexRenameController extends AbstractController
if (isset($_POST['do_save_data'])) {
$oldIndexName = $request->getParsedBodyParam('old_index', '');
$this->indexes->doSaveData(
$request,
$index,
true,
$GLOBALS['db'],

View File

@ -94,6 +94,7 @@ class IndexesController extends AbstractController
if (isset($_POST['do_save_data'])) {
$this->indexes->doSaveData(
$request,
$index,
false,
$GLOBALS['db'],

View File

@ -4,11 +4,11 @@ declare(strict_types=1);
namespace PhpMyAdmin\Table;
use PhpMyAdmin\Application;
use PhpMyAdmin\Controllers\Table\StructureController;
use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Index;
use PhpMyAdmin\Message;
@ -37,6 +37,7 @@ final class Indexes
* @param bool $renameMode Rename the Index mode
*/
public function doSaveData(
ServerRequest $request,
Index $index,
bool $renameMode,
string $db,
@ -85,8 +86,7 @@ final class Indexes
}
$this->dbi->query($sqlQuery);
$response = ResponseRenderer::getInstance();
if ($response->isAjax()) {
if ($request->isAjax()) {
$message = Message::success(
__('Table %1$s has been altered successfully.'),
);
@ -113,7 +113,7 @@ final class Indexes
/** @var StructureController $controller */
$controller = Core::getContainerBuilder()->get(StructureController::class);
$controller(Application::getRequest());
$controller($request);
}
public function executeAddIndexSql(string|DatabaseName $db, string $sql): Message

View File

@ -7761,17 +7761,17 @@ parameters:
path: libraries/classes/Controllers/Table/IndexRenameController.php
-
message: "#^Parameter \\#3 \\$db of method PhpMyAdmin\\\\Table\\\\Indexes\\:\\:doSaveData\\(\\) expects string, mixed given\\.$#"
message: "#^Parameter \\#4 \\$db of method PhpMyAdmin\\\\Table\\\\Indexes\\:\\:doSaveData\\(\\) expects string, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/Table/IndexRenameController.php
-
message: "#^Parameter \\#4 \\$table of method PhpMyAdmin\\\\Table\\\\Indexes\\:\\:doSaveData\\(\\) expects string, mixed given\\.$#"
message: "#^Parameter \\#5 \\$table of method PhpMyAdmin\\\\Table\\\\Indexes\\:\\:doSaveData\\(\\) expects string, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/Table/IndexRenameController.php
-
message: "#^Parameter \\#6 \\$oldIndexName of method PhpMyAdmin\\\\Table\\\\Indexes\\:\\:doSaveData\\(\\) expects string, mixed given\\.$#"
message: "#^Parameter \\#7 \\$oldIndexName of method PhpMyAdmin\\\\Table\\\\Indexes\\:\\:doSaveData\\(\\) expects string, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/Table/IndexRenameController.php
@ -7836,12 +7836,12 @@ parameters:
path: libraries/classes/Controllers/Table/IndexesController.php
-
message: "#^Parameter \\#3 \\$db of method PhpMyAdmin\\\\Table\\\\Indexes\\:\\:doSaveData\\(\\) expects string, mixed given\\.$#"
message: "#^Parameter \\#4 \\$db of method PhpMyAdmin\\\\Table\\\\Indexes\\:\\:doSaveData\\(\\) expects string, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/Table/IndexesController.php
-
message: "#^Parameter \\#4 \\$table of method PhpMyAdmin\\\\Table\\\\Indexes\\:\\:doSaveData\\(\\) expects string, mixed given\\.$#"
message: "#^Parameter \\#5 \\$table of method PhpMyAdmin\\\\Table\\\\Indexes\\:\\:doSaveData\\(\\) expects string, mixed given\\.$#"
count: 1
path: libraries/classes/Controllers/Table/IndexesController.php
@ -32225,18 +32225,18 @@ parameters:
count: 1
path: test/classes/Table/IndexesTest.php
-
message: "#^Parameter \\#3 \\$db of method PhpMyAdmin\\\\Table\\\\Indexes\\:\\:doSaveData\\(\\) expects string, mixed given\\.$#"
count: 2
path: test/classes/Table/IndexesTest.php
-
message: "#^Parameter \\#3 \\$dbi of class PhpMyAdmin\\\\Table\\\\Indexes constructor expects PhpMyAdmin\\\\DatabaseInterface, mixed given\\.$#"
count: 1
path: test/classes/Table/IndexesTest.php
-
message: "#^Parameter \\#4 \\$table of method PhpMyAdmin\\\\Table\\\\Indexes\\:\\:doSaveData\\(\\) expects string, mixed given\\.$#"
message: "#^Parameter \\#4 \\$db of method PhpMyAdmin\\\\Table\\\\Indexes\\:\\:doSaveData\\(\\) expects string, mixed given\\.$#"
count: 2
path: test/classes/Table/IndexesTest.php
-
message: "#^Parameter \\#5 \\$table of method PhpMyAdmin\\\\Table\\\\Indexes\\:\\:doSaveData\\(\\) expects string, mixed given\\.$#"
count: 2
path: test/classes/Table/IndexesTest.php

View File

@ -5,8 +5,8 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Table;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Index;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Table;
use PhpMyAdmin\Table\Indexes;
use PhpMyAdmin\Template;
@ -70,19 +70,20 @@ class IndexesTest extends AbstractTestCase
$indexes = new Indexes($response, new Template(), $GLOBALS['dbi']);
$request = ServerRequestFactory::create()->createServerRequest('GET', 'http://example.com/')
->withQueryParams(['ajax_request' => '1']);
// Preview SQL
$indexes->doSaveData($index, false, $GLOBALS['db'], $GLOBALS['table'], true);
$indexes->doSaveData($request, $index, false, $GLOBALS['db'], $GLOBALS['table'], true);
$jsonArray = $response->getJSONResult();
$this->assertArrayHasKey('sql_data', $jsonArray);
$this->assertStringContainsString($sqlQuery, $jsonArray['sql_data']);
// Alter success
$response->clear();
ResponseRenderer::getInstance()->setAjax(true);
$indexes->doSaveData($index, false, $GLOBALS['db'], $GLOBALS['table'], false);
$indexes->doSaveData($request, $index, false, $GLOBALS['db'], $GLOBALS['table'], false);
$jsonArray = $response->getJSONResult();
$this->assertArrayHasKey('index_table', $jsonArray);
$this->assertArrayHasKey('message', $jsonArray);
ResponseRenderer::getInstance()->setAjax(false);
}
}