Add $oldIndexName as param
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
parent
b22dc9e4aa
commit
6e2d43bdd9
@ -4955,6 +4955,11 @@ parameters:
|
||||
count: 1
|
||||
path: src/Controllers/Table/IndexesController.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$oldIndexName of method PhpMyAdmin\\\\Table\\\\Indexes\\:\\:getSqlQueryForIndexCreateOrEdit\\(\\) expects string\\|null, mixed given\\.$#"
|
||||
count: 1
|
||||
path: src/Controllers/Table/IndexesController.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$params of static method PhpMyAdmin\\\\Url\\:\\:getCommon\\(\\) expects array\\<string, bool\\|int\\|string\\>, mixed given\\.$#"
|
||||
count: 1
|
||||
@ -15170,11 +15175,6 @@ parameters:
|
||||
count: 1
|
||||
path: src/Table/Indexes.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$identifier of static method PhpMyAdmin\\\\Util\\:\\:backquote\\(\\) expects string\\|Stringable\\|null, mixed given\\.$#"
|
||||
count: 1
|
||||
path: src/Table/Indexes.php
|
||||
|
||||
-
|
||||
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
|
||||
count: 2
|
||||
|
||||
@ -3596,6 +3596,7 @@
|
||||
</MixedAssignment>
|
||||
<PossiblyInvalidArgument>
|
||||
<code><![CDATA[$_POST['columns']]]></code>
|
||||
<code>$oldIndex</code>
|
||||
</PossiblyInvalidArgument>
|
||||
<PossiblyInvalidArrayOffset>
|
||||
<code><![CDATA[$_POST['index']['Index_choice']]]></code>
|
||||
@ -11462,9 +11463,6 @@
|
||||
</PossiblyUndefinedArrayOffset>
|
||||
</file>
|
||||
<file src="src/Table/Indexes.php">
|
||||
<PossiblyInvalidArgument>
|
||||
<code>$oldIndex</code>
|
||||
</PossiblyInvalidArgument>
|
||||
<PossiblyNullOperand>
|
||||
<code><![CDATA[$column->getSubPart()]]></code>
|
||||
</PossiblyNullOperand>
|
||||
|
||||
@ -103,8 +103,18 @@ class IndexesController extends AbstractController
|
||||
|
||||
if (isset($_POST['do_save_data'])) {
|
||||
$previewSql = $request->hasBodyParam('preview_sql');
|
||||
if (isset($_POST['old_index'])) {
|
||||
$oldIndex = is_array($_POST['old_index']) ? $_POST['old_index']['Key_name'] : $_POST['old_index'];
|
||||
} else {
|
||||
$oldIndex = null;
|
||||
}
|
||||
|
||||
$sqlQuery = $this->indexes->getSqlQueryForIndexCreateOrEdit(Current::$database, Current::$table, $index);
|
||||
$sqlQuery = $this->indexes->getSqlQueryForIndexCreateOrEdit(
|
||||
$oldIndex,
|
||||
$index,
|
||||
Current::$database,
|
||||
Current::$table,
|
||||
);
|
||||
|
||||
// If there is a request for SQL previewing.
|
||||
if ($previewSql) {
|
||||
|
||||
@ -15,7 +15,6 @@ use PhpMyAdmin\Util;
|
||||
use function __;
|
||||
use function implode;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function sprintf;
|
||||
|
||||
final class Indexes
|
||||
@ -36,8 +35,12 @@ final class Indexes
|
||||
*
|
||||
* @param Index $index current index
|
||||
*/
|
||||
public function getSqlQueryForIndexCreateOrEdit(string $dbName, string $tableName, Index $index): string
|
||||
{
|
||||
public function getSqlQueryForIndexCreateOrEdit(
|
||||
string|null $oldIndexName,
|
||||
Index $index,
|
||||
string $dbName,
|
||||
string $tableName,
|
||||
): string {
|
||||
// $sql_query is the one displayed in the query box
|
||||
$sqlQuery = sprintf(
|
||||
'ALTER TABLE %s.%s',
|
||||
@ -46,14 +49,13 @@ final class Indexes
|
||||
);
|
||||
|
||||
// Drops the old index
|
||||
if (isset($_POST['old_index'])) {
|
||||
$oldIndex = is_array($_POST['old_index']) ? $_POST['old_index']['Key_name'] : $_POST['old_index'];
|
||||
if ($oldIndex === 'PRIMARY') {
|
||||
if ($oldIndexName !== null) {
|
||||
if ($oldIndexName === 'PRIMARY') {
|
||||
$sqlQuery .= ' DROP PRIMARY KEY,';
|
||||
} else {
|
||||
$sqlQuery .= sprintf(
|
||||
' DROP INDEX %s,',
|
||||
Util::backquote($oldIndex),
|
||||
Util::backquote($oldIndexName),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -147,7 +149,7 @@ final class Indexes
|
||||
public function getSqlQueryForRename(string $oldIndexName, Index $index, string $db, string $table): string
|
||||
{
|
||||
if (! Compatibility::isCompatibleRenameIndex($this->dbi->getVersion())) {
|
||||
return $this->getSqlQueryForIndexCreateOrEdit($db, $table, $index);
|
||||
return $this->getSqlQueryForIndexCreateOrEdit($oldIndexName, $index, $db, $table);
|
||||
}
|
||||
|
||||
if ($oldIndexName === 'PRIMARY') {
|
||||
|
||||
@ -70,15 +70,14 @@ class IndexesTest extends AbstractTestCase
|
||||
$sqlQueryExpected = 'ALTER TABLE `pma_db`.`pma_table` DROP PRIMARY KEY, ADD PRIMARY KEY (`id`);';
|
||||
|
||||
$_POST['old_index'] = 'PRIMARY';
|
||||
$this->assertEquals($sqlQueryExpected, $indexes->getSqlQueryForIndexCreateOrEdit($db, $table, $index));
|
||||
|
||||
$_POST['old_index'] = [];
|
||||
$_POST['old_index']['Key_name'] = 'PRIMARY';
|
||||
$this->assertEquals($sqlQueryExpected, $indexes->getSqlQueryForIndexCreateOrEdit($db, $table, $index));
|
||||
$this->assertEquals(
|
||||
$sqlQueryExpected,
|
||||
$indexes->getSqlQueryForIndexCreateOrEdit('PRIMARY', $index, $db, $table),
|
||||
);
|
||||
|
||||
// Error message
|
||||
$index->setName('NOT PRIMARY'); // Cannot rename primary so the operation should fail
|
||||
$indexes->getSqlQueryForIndexCreateOrEdit($db, $table, $index);
|
||||
$indexes->getSqlQueryForIndexCreateOrEdit('PRIMARY', $index, $db, $table);
|
||||
$this->assertInstanceOf(Message::class, $indexes->getError());
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user