Skip to content

Commit 160d6ef

Browse files
Merge pull request #17666 from MauricioFauth/normalization
Extract some actions from NormalizationController class
2 parents 650d833 + efc04db commit 160d6ef

22 files changed

Lines changed: 702 additions & 112 deletions

js/src/normalization.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,12 @@ function goTo3NFStep1 (newTables) {
4040
tables = [window.CommonParams.get('table')];
4141
}
4242
$.post(
43-
'index.php?route=/normalization',
43+
'index.php?route=/normalization/3nf/step1',
4444
{
4545
'ajax_request': true,
4646
'db': window.CommonParams.get('db'),
4747
'server': window.CommonParams.get('server'),
4848
'tables': tables,
49-
'step': '3.1'
5049
}, function (data) {
5150
$('#page_content').find('h3').html(window.Messages.str3NFNormalization);
5251
$('#mainContent').find('legend').html(data.legendText);
@@ -80,13 +79,12 @@ function goTo3NFStep1 (newTables) {
8079

8180
function goTo2NFStep1 () {
8281
$.post(
83-
'index.php?route=/normalization',
82+
'index.php?route=/normalization/2nf/step1',
8483
{
8584
'ajax_request': true,
8685
'db': window.CommonParams.get('db'),
8786
'table': window.CommonParams.get('table'),
8887
'server': window.CommonParams.get('server'),
89-
'step': '2.1'
9088
}, function (data) {
9189
$('#page_content h3').html(window.Messages.str2NFNormalization);
9290
$('#mainContent legend').html(data.legendText);
@@ -133,13 +131,12 @@ function goToFinish1NF () {
133131

134132
function goToStep4 () {
135133
$.post(
136-
'index.php?route=/normalization',
134+
'index.php?route=/normalization/1nf/step4',
137135
{
138136
'ajax_request': true,
139137
'db': window.CommonParams.get('db'),
140138
'table': window.CommonParams.get('table'),
141139
'server': window.CommonParams.get('server'),
142-
'step4': true
143140
}, function (data) {
144141
$('#mainContent legend').html(data.legendText);
145142
$('#mainContent h4').html(data.headText);
@@ -157,13 +154,12 @@ window.goToStep4 = goToStep4;
157154

158155
function goToStep3 () {
159156
$.post(
160-
'index.php?route=/normalization',
157+
'index.php?route=/normalization/1nf/step3',
161158
{
162159
'ajax_request': true,
163160
'db': window.CommonParams.get('db'),
164161
'table': window.CommonParams.get('table'),
165162
'server': window.CommonParams.get('server'),
166-
'step3': true
167163
}, function (data) {
168164
$('#mainContent legend').html(data.legendText);
169165
$('#mainContent h4').html(data.headText);
@@ -181,13 +177,12 @@ function goToStep3 () {
181177

182178
function goToStep2 (extra) {
183179
$.post(
184-
'index.php?route=/normalization',
180+
'index.php?route=/normalization/1nf/step2',
185181
{
186182
'ajax_request': true,
187183
'db': window.CommonParams.get('db'),
188184
'table': window.CommonParams.get('table'),
189-
'server': window.CommonParams.get('server'),
190-
'step2': true
185+
'server': window.CommonParams.get('server')
191186
}, function (data) {
192187
$('#mainContent legend').html(data.legendText);
193188
$('#mainContent h4').html(data.headText);
@@ -322,10 +317,10 @@ function goTo2NFStep2 (pd, primaryKey) {
322317
'table': window.CommonParams.get('table'),
323318
'server': window.CommonParams.get('server'),
324319
'pd': JSON.stringify(pd),
325-
'getNewTables2NF':1 };
320+
};
326321
$.ajax({
327322
type: 'POST',
328-
url: 'index.php?route=/normalization',
323+
url: 'index.php?route=/normalization/2nf/new-tables',
329324
data: datastring,
330325
async:false,
331326
success: function (data) {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Controllers\Normalization\FirstNormalForm;
6+
7+
use PhpMyAdmin\Controllers\AbstractController;
8+
use PhpMyAdmin\Http\ServerRequest;
9+
use PhpMyAdmin\Normalization;
10+
use PhpMyAdmin\ResponseRenderer;
11+
use PhpMyAdmin\Template;
12+
13+
use function in_array;
14+
15+
final class FirstStepController extends AbstractController
16+
{
17+
/** @var Normalization */
18+
private $normalization;
19+
20+
public function __construct(ResponseRenderer $response, Template $template, Normalization $normalization)
21+
{
22+
parent::__construct($response, $template);
23+
$this->normalization = $normalization;
24+
}
25+
26+
public function __invoke(ServerRequest $request): void
27+
{
28+
$this->addScriptFiles(['normalization.js', 'vendor/jquery/jquery.uitablefilter.js']);
29+
30+
$normalForm = '1nf';
31+
if (isset($_POST['normalizeTo']) && in_array($_POST['normalizeTo'], ['1nf', '2nf', '3nf'])) {
32+
$normalForm = $_POST['normalizeTo'];
33+
}
34+
35+
$html = $this->normalization->getHtmlFor1NFStep1($GLOBALS['db'], $GLOBALS['table'], $normalForm);
36+
$this->response->addHTML($html);
37+
}
38+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Controllers\Normalization\FirstNormalForm;
6+
7+
use PhpMyAdmin\Controllers\AbstractController;
8+
use PhpMyAdmin\Http\ServerRequest;
9+
use PhpMyAdmin\Normalization;
10+
use PhpMyAdmin\ResponseRenderer;
11+
use PhpMyAdmin\Template;
12+
13+
final class FourthStepController extends AbstractController
14+
{
15+
/** @var Normalization */
16+
private $normalization;
17+
18+
public function __construct(ResponseRenderer $response, Template $template, Normalization $normalization)
19+
{
20+
parent::__construct($response, $template);
21+
$this->normalization = $normalization;
22+
}
23+
24+
public function __invoke(ServerRequest $request): void
25+
{
26+
$res = $this->normalization->getHtmlContentsFor1NFStep4($GLOBALS['db'], $GLOBALS['table']);
27+
$this->response->addJSON($res);
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Controllers\Normalization\FirstNormalForm;
6+
7+
use PhpMyAdmin\Controllers\AbstractController;
8+
use PhpMyAdmin\Http\ServerRequest;
9+
use PhpMyAdmin\Normalization;
10+
use PhpMyAdmin\ResponseRenderer;
11+
use PhpMyAdmin\Template;
12+
13+
final class SecondStepController extends AbstractController
14+
{
15+
/** @var Normalization */
16+
private $normalization;
17+
18+
public function __construct(ResponseRenderer $response, Template $template, Normalization $normalization)
19+
{
20+
parent::__construct($response, $template);
21+
$this->normalization = $normalization;
22+
}
23+
24+
public function __invoke(ServerRequest $request): void
25+
{
26+
$res = $this->normalization->getHtmlContentsFor1NFStep2($GLOBALS['db'], $GLOBALS['table']);
27+
$this->response->addJSON($res);
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Controllers\Normalization\FirstNormalForm;
6+
7+
use PhpMyAdmin\Controllers\AbstractController;
8+
use PhpMyAdmin\Http\ServerRequest;
9+
use PhpMyAdmin\Normalization;
10+
use PhpMyAdmin\ResponseRenderer;
11+
use PhpMyAdmin\Template;
12+
13+
final class ThirdStepController extends AbstractController
14+
{
15+
/** @var Normalization */
16+
private $normalization;
17+
18+
public function __construct(ResponseRenderer $response, Template $template, Normalization $normalization)
19+
{
20+
parent::__construct($response, $template);
21+
$this->normalization = $normalization;
22+
}
23+
24+
public function __invoke(ServerRequest $request): void
25+
{
26+
$res = $this->normalization->getHtmlContentsFor1NFStep3($GLOBALS['db'], $GLOBALS['table']);
27+
$this->response->addJSON($res);
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Controllers\Normalization\SecondNormalForm;
6+
7+
use PhpMyAdmin\Controllers\AbstractController;
8+
use PhpMyAdmin\Http\ServerRequest;
9+
use PhpMyAdmin\Normalization;
10+
use PhpMyAdmin\ResponseRenderer;
11+
use PhpMyAdmin\Template;
12+
13+
final class FirstStepController extends AbstractController
14+
{
15+
/** @var Normalization */
16+
private $normalization;
17+
18+
public function __construct(ResponseRenderer $response, Template $template, Normalization $normalization)
19+
{
20+
parent::__construct($response, $template);
21+
$this->normalization = $normalization;
22+
}
23+
24+
public function __invoke(ServerRequest $request): void
25+
{
26+
$res = $this->normalization->getHtmlFor2NFstep1($GLOBALS['db'], $GLOBALS['table']);
27+
$this->response->addJSON($res);
28+
}
29+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Controllers\Normalization\SecondNormalForm;
6+
7+
use PhpMyAdmin\Controllers\AbstractController;
8+
use PhpMyAdmin\Http\ServerRequest;
9+
use PhpMyAdmin\Normalization;
10+
use PhpMyAdmin\ResponseRenderer;
11+
use PhpMyAdmin\Template;
12+
13+
use function json_decode;
14+
15+
final class NewTablesController extends AbstractController
16+
{
17+
/** @var Normalization */
18+
private $normalization;
19+
20+
public function __construct(ResponseRenderer $response, Template $template, Normalization $normalization)
21+
{
22+
parent::__construct($response, $template);
23+
$this->normalization = $normalization;
24+
}
25+
26+
public function __invoke(ServerRequest $request): void
27+
{
28+
$partialDependencies = json_decode($_POST['pd'], true);
29+
$html = $this->normalization->getHtmlForNewTables2NF($partialDependencies, $GLOBALS['table']);
30+
$this->response->addHTML($html);
31+
}
32+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Controllers\Normalization\ThirdNormalForm;
6+
7+
use PhpMyAdmin\Controllers\AbstractController;
8+
use PhpMyAdmin\Http\ServerRequest;
9+
use PhpMyAdmin\Normalization;
10+
use PhpMyAdmin\ResponseRenderer;
11+
use PhpMyAdmin\Template;
12+
13+
final class FirstStepController extends AbstractController
14+
{
15+
/** @var Normalization */
16+
private $normalization;
17+
18+
public function __construct(ResponseRenderer $response, Template $template, Normalization $normalization)
19+
{
20+
parent::__construct($response, $template);
21+
$this->normalization = $normalization;
22+
}
23+
24+
public function __invoke(ServerRequest $request): void
25+
{
26+
$tables = $_POST['tables'];
27+
$res = $this->normalization->getHtmlFor3NFstep1($GLOBALS['db'], $tables);
28+
$this->response->addJSON($res);
29+
}
30+
}

libraries/classes/Controllers/NormalizationController.php

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use function __;
1515
use function _pgettext;
16-
use function in_array;
1716
use function intval;
1817
use function json_decode;
1918
use function json_encode;
@@ -83,14 +82,6 @@ public function __invoke(ServerRequest $request): void
8382
return;
8483
}
8584

86-
if (isset($_POST['getNewTables2NF'])) {
87-
$partialDependencies = json_decode($_POST['pd'], true);
88-
$html = $this->normalization->getHtmlForNewTables2NF($partialDependencies, $GLOBALS['table']);
89-
echo $html;
90-
91-
return;
92-
}
93-
9485
if (isset($_POST['getNewTables3NF'])) {
9586
$dependencies = json_decode($_POST['pd']);
9687
$tables = json_decode($_POST['tables'], true);
@@ -104,11 +95,6 @@ public function __invoke(ServerRequest $request): void
10495

10596
$this->addScriptFiles(['normalization.js', 'vendor/jquery/jquery.uitablefilter.js']);
10697

107-
$normalForm = '1nf';
108-
if (isset($_POST['normalizeTo']) && in_array($_POST['normalizeTo'], ['1nf', '2nf', '3nf'])) {
109-
$normalForm = $_POST['normalizeTo'];
110-
}
111-
11298
if (isset($_POST['createNewTables2NF'])) {
11399
$partialDependencies = json_decode($_POST['pd'], true);
114100
$tablesName = json_decode($_POST['newTablesName']);
@@ -149,49 +135,6 @@ public function __invoke(ServerRequest $request): void
149135
return;
150136
}
151137

152-
if (isset($_POST['step1'])) {
153-
$html = $this->normalization->getHtmlFor1NFStep1($GLOBALS['db'], $GLOBALS['table'], $normalForm);
154-
$this->response->addHTML($html);
155-
156-
return;
157-
}
158-
159-
if (isset($_POST['step2'])) {
160-
$res = $this->normalization->getHtmlContentsFor1NFStep2($GLOBALS['db'], $GLOBALS['table']);
161-
$this->response->addJSON($res);
162-
163-
return;
164-
}
165-
166-
if (isset($_POST['step3'])) {
167-
$res = $this->normalization->getHtmlContentsFor1NFStep3($GLOBALS['db'], $GLOBALS['table']);
168-
$this->response->addJSON($res);
169-
170-
return;
171-
}
172-
173-
if (isset($_POST['step4'])) {
174-
$res = $this->normalization->getHtmlContentsFor1NFStep4($GLOBALS['db'], $GLOBALS['table']);
175-
$this->response->addJSON($res);
176-
177-
return;
178-
}
179-
180-
if (isset($_POST['step']) && $_POST['step'] == '2.1') {
181-
$res = $this->normalization->getHtmlFor2NFstep1($GLOBALS['db'], $GLOBALS['table']);
182-
$this->response->addJSON($res);
183-
184-
return;
185-
}
186-
187-
if (isset($_POST['step']) && $_POST['step'] == '3.1') {
188-
$tables = $_POST['tables'];
189-
$res = $this->normalization->getHtmlFor3NFstep1($GLOBALS['db'], $tables);
190-
$this->response->addJSON($res);
191-
192-
return;
193-
}
194-
195138
$this->render('table/normalization/normalization', [
196139
'db' => $GLOBALS['db'],
197140
'table' => $GLOBALS['table'],

0 commit comments

Comments
 (0)