diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-08-02 22:45:30 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-08-02 22:45:30 +0300 |
commit | c550d41d1ddece5c85dbd00cdc984ed7e953aaef (patch) | |
tree | c15b4066b7f7d05682095f75fec3e2dd337ff2cc /libraries | |
parent | 66970049cce943d4b63d1c03496f405235bd3b32 (diff) |
Extract normalization's add new primary action
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/classes/Controllers/Normalization/AddNewPrimaryController.php | 41 | ||||
-rw-r--r-- | libraries/classes/Controllers/Normalization/MainController.php | 18 | ||||
-rw-r--r-- | libraries/routes.php | 1 | ||||
-rw-r--r-- | libraries/services_controllers.php | 8 |
4 files changed, 50 insertions, 18 deletions
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' => [ |