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-02 22:45:30 +0300
committerMaurício Meneghini Fauth <mauricio@fauth.dev>2022-08-02 22:45:30 +0300
commitc550d41d1ddece5c85dbd00cdc984ed7e953aaef (patch)
treec15b4066b7f7d05682095f75fec3e2dd337ff2cc
parent66970049cce943d4b63d1c03496f405235bd3b32 (diff)
Extract normalization's add new primary 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/AddNewPrimaryController.php41
-rw-r--r--libraries/classes/Controllers/Normalization/MainController.php18
-rw-r--r--libraries/routes.php1
-rw-r--r--libraries/services_controllers.php8
-rw-r--r--test/classes/Controllers/Normalization/AddNewPrimaryControllerTest.php44
6 files changed, 95 insertions, 20 deletions
diff --git a/js/src/normalization.js b/js/src/normalization.js
index d119cd9d19..ac6c52e373 100644
--- a/js/src/normalization.js
+++ b/js/src/normalization.js
@@ -594,13 +594,12 @@ window.AJAX.registerOnload('normalization.js', function () {
$('#extra').on('click', '#addNewPrimary', function () {
$.post(
- 'index.php?route=/normalization',
+ 'index.php?route=/normalization/add-new-primary',
{
'ajax_request': true,
'db': window.CommonParams.get('db'),
'table': window.CommonParams.get('table'),
'server': window.CommonParams.get('server'),
- 'addNewPrimary': true
},
function (data) {
if (data.success === true) {
diff --git a/libraries/classes/Controllers/Normalization/AddNewPrimaryController.php b/libraries/classes/Controllers/Normalization/AddNewPrimaryController.php
new file mode 100644
index 0000000000..bbbdd9976c
--- /dev/null
+++ b/libraries/classes/Controllers/Normalization/AddNewPrimaryController.php
@@ -0,0 +1,41 @@
+<?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;
+
+final class AddNewPrimaryController 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 = 1;
+ $columnMeta = [
+ 'Field' => $GLOBALS['table'] . '_id',
+ 'Extra' => 'auto_increment',
+ ];
+ $html = $this->normalization->getHtmlForCreateNewColumn(
+ $num_fields,
+ $GLOBALS['db'],
+ $GLOBALS['table'],
+ $columnMeta
+ );
+ $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 e24f61cc27..1d36f0cfbb 100644
--- a/libraries/classes/Controllers/Normalization/MainController.php
+++ b/libraries/classes/Controllers/Normalization/MainController.php
@@ -55,24 +55,6 @@ class MainController extends AbstractController
return;
}
- if (isset($_POST['addNewPrimary'])) {
- $num_fields = 1;
- $columnMeta = [
- 'Field' => $GLOBALS['table'] . '_id',
- 'Extra' => 'auto_increment',
- ];
- $html = $this->normalization->getHtmlForCreateNewColumn(
- $num_fields,
- $GLOBALS['db'],
- $GLOBALS['table'],
- $columnMeta
- );
- $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 5ee9182923..236204281d 100644
--- a/libraries/routes.php
+++ b/libraries/routes.php
@@ -141,6 +141,7 @@ return static function (RouteCollector $routes): void {
$routes->post('/3nf/create-new-tables', Normalization\ThirdNormalForm\CreateNewTablesController::class);
$routes->post('/3nf/new-tables', Normalization\ThirdNormalForm\NewTablesController::class);
$routes->post('/3nf/step1', Normalization\ThirdNormalForm\FirstStepController::class);
+ $routes->post('/add-new-primary', Normalization\AddNewPrimaryController::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 4bd1d28ed3..df20d35ff4 100644
--- a/libraries/services_controllers.php
+++ b/libraries/services_controllers.php
@@ -664,6 +664,14 @@ return [
'$normalization' => '@normalization',
],
],
+ Normalization\AddNewPrimaryController::class => [
+ 'class' => Normalization\AddNewPrimaryController::class,
+ 'arguments' => [
+ '$response' => '@response',
+ '$template' => '@template',
+ '$normalization' => '@normalization',
+ ],
+ ],
Normalization\MoveRepeatingGroup::class => [
'class' => Normalization\MoveRepeatingGroup::class,
'arguments' => [
diff --git a/test/classes/Controllers/Normalization/AddNewPrimaryControllerTest.php b/test/classes/Controllers/Normalization/AddNewPrimaryControllerTest.php
new file mode 100644
index 0000000000..d55100fc08
--- /dev/null
+++ b/test/classes/Controllers/Normalization/AddNewPrimaryControllerTest.php
@@ -0,0 +1,44 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers\Normalization;
+
+use PhpMyAdmin\ConfigStorage\Relation;
+use PhpMyAdmin\Controllers\Normalization\AddNewPrimaryController;
+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\AddNewPrimaryController
+ */
+class AddNewPrimaryControllerTest extends AbstractTestCase
+{
+ public function testDefault(): void
+ {
+ $GLOBALS['cfg']['Server']['DisableIS'] = false;
+ $GLOBALS['col_priv'] = false;
+ $GLOBALS['db'] = 'test_db';
+ $GLOBALS['table'] = 'test_table';
+
+ $dbiDummy = $this->createDbiDummy();
+
+ $dbi = $this->createDatabaseInterface($dbiDummy);
+ $GLOBALS['dbi'] = $dbi;
+ $response = new ResponseRenderer();
+ $template = new Template();
+
+ $controller = new AddNewPrimaryController(
+ $response,
+ $template,
+ new Normalization($dbi, new Relation($dbi), new Transformations(), $template)
+ );
+ $controller($this->createStub(ServerRequest::class));
+
+ $this->assertStringContainsString('<table id="table_columns"', $response->getHTMLResult());
+ }
+}