2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Normalization process (temporarily specific to 1NF)
8 declare(strict_types
=1);
11 use PhpMyAdmin\DatabaseInterface
;
12 use PhpMyAdmin\Normalization
;
13 use PhpMyAdmin\Response
;
16 if (! defined('ROOT_PATH')) {
17 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
22 require_once ROOT_PATH
. 'libraries/common.inc.php';
24 /** @var Response $response */
25 $response = $containerBuilder->get(Response
::class);
27 /** @var DatabaseInterface $dbi */
28 $dbi = $containerBuilder->get(DatabaseInterface
::class);
30 /** @var Normalization $normalization */
31 $normalization = $containerBuilder->get('normalization');
33 if (isset($_POST['getColumns'])) {
34 $html = '<option selected disabled>' . __('Select oneā¦') . '</option>'
35 . '<option value="no_such_col">' . __('No such column') . '</option>';
36 //get column whose datatype falls under string category
37 $html .= $normalization->getHtmlForColumnsList(
40 _pgettext('string types', 'String')
45 if (isset($_POST['splitColumn'])) {
46 $num_fields = min(4096, intval($_POST['numFields']));
47 $html = $normalization->getHtmlForCreateNewColumn($num_fields, $db, $table);
48 $html .= Url
::getHiddenInputs($db, $table);
52 if (isset($_POST['addNewPrimary'])) {
55 'Field' => $table . "_id",
56 'Extra' => 'auto_increment',
58 $html = $normalization->getHtmlForCreateNewColumn(
64 $html .= Url
::getHiddenInputs($db, $table);
68 if (isset($_POST['findPdl'])) {
69 $html = $normalization->findPartialDependencies($table, $db);
74 if (isset($_POST['getNewTables2NF'])) {
75 $partialDependencies = json_decode($_POST['pd']);
76 $html = $normalization->getHtmlForNewTables2NF($partialDependencies, $table);
81 if (isset($_POST['getNewTables3NF'])) {
82 $dependencies = json_decode($_POST['pd']);
83 $tables = json_decode($_POST['tables']);
84 $newTables = $normalization->getHtmlForNewTables3NF($dependencies, $tables, $db);
87 echo json_encode($newTables);
91 $header = $response->getHeader();
92 $scripts = $header->getScripts();
93 $scripts->addFile('normalization.js');
94 $scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
96 if (Core
::isValid($_POST['normalizeTo'], ['1nf', '2nf', '3nf'])) {
97 $normalForm = $_POST['normalizeTo'];
99 if (isset($_POST['createNewTables2NF'])) {
100 $partialDependencies = json_decode($_POST['pd']);
101 $tablesName = json_decode($_POST['newTablesName']);
102 $res = $normalization->createNewTablesFor2NF($partialDependencies, $tablesName, $table, $db);
103 $response->addJSON($res);
106 if (isset($_POST['createNewTables3NF'])) {
107 $newtables = json_decode($_POST['newTables']);
108 $res = $normalization->createNewTablesFor3NF($newtables, $db);
109 $response->addJSON($res);
112 if (isset($_POST['repeatingColumns'])) {
113 $repeatingColumns = $_POST['repeatingColumns'];
114 $newTable = $_POST['newTable'];
115 $newColumn = $_POST['newColumn'];
116 $primary_columns = $_POST['primary_columns'];
117 $res = $normalization->moveRepeatingGroup(
125 $response->addJSON($res);
128 if (isset($_POST['step1'])) {
129 $html = $normalization->getHtmlFor1NFStep1($db, $table, $normalForm);
130 $response->addHTML($html);
131 } elseif (isset($_POST['step2'])) {
132 $res = $normalization->getHtmlContentsFor1NFStep2($db, $table);
133 $response->addJSON($res);
134 } elseif (isset($_POST['step3'])) {
135 $res = $normalization->getHtmlContentsFor1NFStep3($db, $table);
136 $response->addJSON($res);
137 } elseif (isset($_POST['step4'])) {
138 $res = $normalization->getHtmlContentsFor1NFStep4($db, $table);
139 $response->addJSON($res);
140 } elseif (isset($_POST['step']) && $_POST['step'] == '2.1') {
141 $res = $normalization->getHtmlFor2NFstep1($db, $table);
142 $response->addJSON($res);
143 } elseif (isset($_POST['step']) && $_POST['step'] == '3.1') {
144 $tables = $_POST['tables'];
145 $res = $normalization->getHtmlFor3NFstep1($db, $tables);
146 $response->addJSON($res);
148 $response->addHTML($normalization->getHtmlForNormalizeTable());