Create MoveMode enum
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
parent
81853e877b
commit
d485a95fae
@ -11,6 +11,7 @@ use PhpMyAdmin\Http\Response;
|
||||
use PhpMyAdmin\Http\ServerRequest;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Operations;
|
||||
use PhpMyAdmin\Table\MoveMode;
|
||||
use PhpMyAdmin\Table\TableMover;
|
||||
use PhpMyAdmin\UserPrivilegesFactory;
|
||||
|
||||
@ -40,7 +41,7 @@ final class CopyTableController implements InvocableController
|
||||
$selectedValue,
|
||||
$request->getParsedBodyParam('what'),
|
||||
false,
|
||||
'one_table',
|
||||
MoveMode::SingleTable,
|
||||
$request->getParsedBodyParam('drop_if_exists') === 'true',
|
||||
);
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ use PhpMyAdmin\Current;
|
||||
use PhpMyAdmin\Http\Response;
|
||||
use PhpMyAdmin\Http\ServerRequest;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Table\MoveMode;
|
||||
use PhpMyAdmin\Table\TableMover;
|
||||
|
||||
use function mb_strlen;
|
||||
@ -40,7 +41,7 @@ final class CopyTableWithPrefixController implements InvocableController
|
||||
$newTableName,
|
||||
'data',
|
||||
false,
|
||||
'one_table',
|
||||
MoveMode::SingleTable,
|
||||
$dropIfExists,
|
||||
);
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ use PhpMyAdmin\Engines\Innodb;
|
||||
use PhpMyAdmin\Identifiers\DatabaseName;
|
||||
use PhpMyAdmin\Partitioning\Partition;
|
||||
use PhpMyAdmin\Plugins\Export\ExportSql;
|
||||
use PhpMyAdmin\Table\MoveMode;
|
||||
use PhpMyAdmin\Table\Table;
|
||||
use PhpMyAdmin\Table\TableMover;
|
||||
use PhpMyAdmin\Triggers\Triggers;
|
||||
@ -201,7 +202,7 @@ class Operations
|
||||
$table,
|
||||
$copyMode ?? 'data',
|
||||
$move,
|
||||
'db_copy',
|
||||
MoveMode::WholeDatabase,
|
||||
isset($_POST['drop_if_exists']) && $_POST['drop_if_exists'] === 'true',
|
||||
)
|
||||
) {
|
||||
@ -276,7 +277,7 @@ class Operations
|
||||
$view,
|
||||
'structure',
|
||||
$move,
|
||||
'db_copy',
|
||||
MoveMode::WholeDatabase,
|
||||
true,
|
||||
);
|
||||
if (! $copyingSucceeded) {
|
||||
@ -895,7 +896,7 @@ class Operations
|
||||
(string) $_POST['new_name'],
|
||||
$_POST['what'],
|
||||
isset($_POST['submit_move']),
|
||||
'one_table',
|
||||
MoveMode::SingleTable,
|
||||
isset($_POST['drop_if_exists']) && $_POST['drop_if_exists'] === 'true',
|
||||
);
|
||||
|
||||
|
||||
11
src/Table/MoveMode.php
Normal file
11
src/Table/MoveMode.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Table;
|
||||
|
||||
enum MoveMode
|
||||
{
|
||||
case SingleTable;
|
||||
case WholeDatabase;
|
||||
}
|
||||
@ -36,7 +36,6 @@ class TableMover
|
||||
* @param string $targetTable target table
|
||||
* @param string $what what to be moved or copied (data, dataonly)
|
||||
* @param bool $move whether to move
|
||||
* @param string $mode mode
|
||||
*/
|
||||
public static function moveCopy(
|
||||
string $sourceDb,
|
||||
@ -45,7 +44,7 @@ class TableMover
|
||||
string $targetTable,
|
||||
string $what,
|
||||
bool $move,
|
||||
string $mode,
|
||||
MoveMode $mode,
|
||||
bool $addDropIfExists,
|
||||
): bool {
|
||||
$GLOBALS['errorUrl'] ??= null;
|
||||
@ -246,12 +245,12 @@ class TableMover
|
||||
$GLOBALS['sql_constraints_query'] = $statement->build() . ';';
|
||||
|
||||
// Executing it.
|
||||
if ($mode === 'one_table') {
|
||||
if ($mode === MoveMode::SingleTable) {
|
||||
$dbi->query($GLOBALS['sql_constraints_query']);
|
||||
}
|
||||
|
||||
$GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query'];
|
||||
if ($mode === 'one_table') {
|
||||
if ($mode === MoveMode::SingleTable) {
|
||||
unset($GLOBALS['sql_constraints_query']);
|
||||
}
|
||||
}
|
||||
@ -287,23 +286,19 @@ class TableMover
|
||||
$sqlIndex = $statement->build() . ';';
|
||||
|
||||
// Executing it.
|
||||
if ($mode === 'one_table' || $mode === 'db_copy') {
|
||||
$dbi->query($sqlIndex);
|
||||
}
|
||||
$dbi->query($sqlIndex);
|
||||
|
||||
$GLOBALS['sql_indexes'] .= $sqlIndex;
|
||||
}
|
||||
|
||||
$GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_indexes'];
|
||||
if ($mode === 'one_table' || $mode === 'db_copy') {
|
||||
unset($GLOBALS['sql_indexes']);
|
||||
}
|
||||
unset($GLOBALS['sql_indexes']);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// Phase 5: Adding AUTO_INCREMENT.
|
||||
|
||||
if (! empty($GLOBALS['sql_auto_increments']) && ($mode === 'one_table' || $mode === 'db_copy')) {
|
||||
if (! empty($GLOBALS['sql_auto_increments'])) {
|
||||
$parser = new Parser($GLOBALS['sql_auto_increments']);
|
||||
|
||||
/**
|
||||
|
||||
@ -12,6 +12,7 @@ use PhpMyAdmin\Dbal\ConnectionType;
|
||||
use PhpMyAdmin\ListDatabase;
|
||||
use PhpMyAdmin\Query\Cache;
|
||||
use PhpMyAdmin\SqlParser\Context;
|
||||
use PhpMyAdmin\Table\MoveMode;
|
||||
use PhpMyAdmin\Table\Table;
|
||||
use PhpMyAdmin\Table\TableMover;
|
||||
use PhpMyAdmin\Tests\AbstractTestCase;
|
||||
@ -1311,7 +1312,6 @@ class TableTest extends AbstractTestCase
|
||||
$targetDb = 'PMA_new';
|
||||
$what = 'dataonly';
|
||||
$move = true;
|
||||
$mode = 'one_table';
|
||||
|
||||
unset($GLOBALS['sql_drop_table']);
|
||||
|
||||
@ -1323,7 +1323,7 @@ class TableTest extends AbstractTestCase
|
||||
$this->mockedDbi->expects(self::any())->method('getTable')
|
||||
->willReturnMap($getTableMap);
|
||||
|
||||
$return = TableMover::moveCopy($sourceDb, $sourceTable, $targetDb, $targetTable, $what, $move, $mode, true);
|
||||
$return = TableMover::moveCopy($sourceDb, $sourceTable, $targetDb, $targetTable, $what, $move, MoveMode::SingleTable, true);
|
||||
|
||||
//successfully
|
||||
self::assertTrue($return);
|
||||
@ -1334,7 +1334,7 @@ class TableTest extends AbstractTestCase
|
||||
$sqlQuery = 'DROP VIEW `PMA`.`PMA_BookMark`';
|
||||
self::assertStringContainsString($sqlQuery, $GLOBALS['sql_query']);
|
||||
|
||||
$return = TableMover::moveCopy($sourceDb, $sourceTable, $targetDb, $targetTable, $what, false, $mode, true);
|
||||
$return = TableMover::moveCopy($sourceDb, $sourceTable, $targetDb, $targetTable, $what, false, MoveMode::SingleTable, true);
|
||||
|
||||
//successfully
|
||||
self::assertTrue($return);
|
||||
@ -1376,7 +1376,7 @@ class TableTest extends AbstractTestCase
|
||||
]);
|
||||
|
||||
$GLOBALS['sql_query'] = '';
|
||||
$return = TableMover::moveCopy('aa', 'ad', 'bb', 'ad', 'structure', true, 'db_copy', true);
|
||||
$return = TableMover::moveCopy('aa', 'ad', 'bb', 'ad', 'structure', true, MoveMode::WholeDatabase, true);
|
||||
self::assertTrue($return);
|
||||
self::assertStringContainsString('DROP TABLE IF EXISTS `bb`.`ad`;', $GLOBALS['sql_query']);
|
||||
self::assertStringContainsString(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user