Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurício Meneghini Fauth <mauricio@fauth.dev>2022-08-03 03:38:55 +0300
committerMaurício Meneghini Fauth <mauricio@fauth.dev>2022-08-03 03:38:55 +0300
commit28d53fe50bb5e87affd14d7b2bb241e9cf23ca66 (patch)
tree597b551fd60ee708212d515d77b8989aa8171418
parenta37e5681c8b1000661f710346281caf52b53c3fc (diff)
Extract normalization's create new column action
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
-rw-r--r--js/src/normalization.js3
-rw-r--r--libraries/classes/Controllers/Normalization/CreateNewColumnController.php35
-rw-r--r--libraries/classes/Controllers/Normalization/MainController.php13
-rw-r--r--libraries/routes.php1
-rw-r--r--libraries/services_controllers.php8
-rw-r--r--test/classes/Controllers/Normalization/CreateNewColumnControllerTest.php45
6 files changed, 90 insertions, 15 deletions
diff --git a/js/src/normalization.js b/js/src/normalization.js
index a64ac02acd..fd48a502a1 100644
--- a/js/src/normalization.js
+++ b/js/src/normalization.js
@@ -510,13 +510,12 @@ window.AJAX.registerOnload('normalization.js', function () {
}
var numField = $('#numField').val();
$.post(
- 'index.php?route=/normalization',
+ 'index.php?route=/normalization/create-new-column',
{
'ajax_request': true,
'db': window.CommonParams.get('db'),
'table': window.CommonParams.get('table'),
'server': window.CommonParams.get('server'),
- 'splitColumn': true,
'numFields': numField
},
function (data) {
diff --git a/libraries/classes/Controllers/Normalization/CreateNewColumnController.php b/libraries/classes/Controllers/Normalization/CreateNewColumnController.php
new file mode 100644
index 0000000000..ae03dc1d00
--- /dev/null
+++ b/libraries/classes/Controllers/Normalization/CreateNewColumnController.php
@@ -0,0 +1,35 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Controllers\Normalization;
+
+use PhpMyAdmin\Controllers\AbstractController;
+use PhpMyAdmin\Http\ServerRequest;
+use PhpMyAdmin\Normalization;
+use PhpMyAdmin\ResponseRenderer;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Url;
+
+use function intval;
+use function min;
+
+final class CreateNewColumnController extends AbstractController
+{
+ /** @var Normalization */
+ private $normalization;
+
+ public function __construct(ResponseRenderer $response, Template $template, Normalization $normalization)
+ {
+ parent::__construct($response, $template);
+ $this->normalization = $normalization;
+ }
+
+ public function __invoke(ServerRequest $request): void
+ {
+ $num_fields = min(4096, intval($_POST['numFields']));
+ $html = $this->normalization->getHtmlForCreateNewColumn($num_fields, $GLOBALS['db'], $GLOBALS['table']);
+ $html .= Url::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
+ $this->response->addHTML($html);
+ }
+}
diff --git a/libraries/classes/Controllers/Normalization/MainController.php b/libraries/classes/Controllers/Normalization/MainController.php
index cfc59e0759..571dde45d2 100644
--- a/libraries/classes/Controllers/Normalization/MainController.php
+++ b/libraries/classes/Controllers/Normalization/MainController.php
@@ -9,10 +9,6 @@ use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Normalization;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
-use PhpMyAdmin\Url;
-
-use function intval;
-use function min;
/**
* Normalization process (temporarily specific to 1NF).
@@ -30,15 +26,6 @@ class MainController extends AbstractController
public function __invoke(ServerRequest $request): void
{
- if (isset($_POST['splitColumn'])) {
- $num_fields = min(4096, intval($_POST['numFields']));
- $html = $this->normalization->getHtmlForCreateNewColumn($num_fields, $GLOBALS['db'], $GLOBALS['table']);
- $html .= Url::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
- echo $html;
-
- return;
- }
-
if (isset($_POST['findPdl'])) {
$html = $this->normalization->findPartialDependencies($GLOBALS['table'], $GLOBALS['db']);
echo $html;
diff --git a/libraries/routes.php b/libraries/routes.php
index e8d730e776..a71f637d20 100644
--- a/libraries/routes.php
+++ b/libraries/routes.php
@@ -143,6 +143,7 @@ return static function (RouteCollector $routes): void {
$routes->post('/3nf/step1', Normalization\ThirdNormalForm\FirstStepController::class);
$routes->post('/add-new-primary', Normalization\AddNewPrimaryController::class);
$routes->post('/get-columns', Normalization\GetColumnsController::class);
+ $routes->post('/create-new-column', Normalization\CreateNewColumnController::class);
$routes->post('/move-repeating-group', Normalization\MoveRepeatingGroup::class);
});
$routes->get('/phpinfo', PhpInfoController::class);
diff --git a/libraries/services_controllers.php b/libraries/services_controllers.php
index 79f6ee8d9f..ddc00d922f 100644
--- a/libraries/services_controllers.php
+++ b/libraries/services_controllers.php
@@ -672,6 +672,14 @@ return [
'$normalization' => '@normalization',
],
],
+ Normalization\CreateNewColumnController::class => [
+ 'class' => Normalization\CreateNewColumnController::class,
+ 'arguments' => [
+ '$response' => '@response',
+ '$template' => '@template',
+ '$normalization' => '@normalization',
+ ],
+ ],
Normalization\GetColumnsController::class => [
'class' => Normalization\GetColumnsController::class,
'arguments' => [
diff --git a/test/classes/Controllers/Normalization/CreateNewColumnControllerTest.php b/test/classes/Controllers/Normalization/CreateNewColumnControllerTest.php
new file mode 100644
index 0000000000..2a18d763bb
--- /dev/null
+++ b/test/classes/Controllers/Normalization/CreateNewColumnControllerTest.php
@@ -0,0 +1,45 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers\Normalization;
+
+use PhpMyAdmin\ConfigStorage\Relation;
+use PhpMyAdmin\Controllers\Normalization\CreateNewColumnController;
+use PhpMyAdmin\Http\ServerRequest;
+use PhpMyAdmin\Normalization;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Tests\AbstractTestCase;
+use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
+use PhpMyAdmin\Transformations;
+
+/**
+ * @covers \PhpMyAdmin\Controllers\Normalization\CreateNewColumnController
+ */
+class CreateNewColumnControllerTest extends AbstractTestCase
+{
+ public function testDefault(): void
+ {
+ $GLOBALS['cfg']['Server']['DisableIS'] = false;
+ $GLOBALS['col_priv'] = false;
+ $GLOBALS['db'] = 'test_db';
+ $GLOBALS['table'] = 'test_table';
+ $_POST['numFields'] = 1;
+
+ $dbiDummy = $this->createDbiDummy();
+
+ $dbi = $this->createDatabaseInterface($dbiDummy);
+ $GLOBALS['dbi'] = $dbi;
+ $response = new ResponseRenderer();
+ $template = new Template();
+
+ $controller = new CreateNewColumnController(
+ $response,
+ $template,
+ new Normalization($dbi, new Relation($dbi), new Transformations(), $template)
+ );
+ $controller($this->createStub(ServerRequest::class));
+
+ $this->assertStringContainsString('<table id="table_columns"', $response->getHTMLResult());
+ }
+}