Fix merge conflicts
[phpmyadmin.git] / normalization.php
blob01c9ca3f3bd6d7f2dd9d8e6780301b0b364bb3c0
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Normalization process (temporarily specific to 1NF)
6 * @package PhpMyAdmin
7 */
8 declare(strict_types=1);
10 use PhpMyAdmin\Core;
11 use PhpMyAdmin\DatabaseInterface;
12 use PhpMyAdmin\Di\Container;
13 use PhpMyAdmin\Normalization;
14 use PhpMyAdmin\Response;
15 use PhpMyAdmin\Url;
17 if (! defined('ROOT_PATH')) {
18 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
21 global $db, $table;
23 require_once ROOT_PATH . 'libraries/common.inc.php';
25 $container = Container::getDefaultContainer();
26 $container->set(Response::class, Response::getInstance());
28 /** @var Response $response */
29 $response = $container->get(Response::class);
31 /** @var DatabaseInterface $dbi */
32 $dbi = $container->get(DatabaseInterface::class);
34 /** @var Normalization $normalization */
35 $normalization = $containerBuilder->get('normalization');
37 if (isset($_POST['getColumns'])) {
38 $html = '<option selected disabled>' . __('Select oneā€¦') . '</option>'
39 . '<option value="no_such_col">' . __('No such column') . '</option>';
40 //get column whose datatype falls under string category
41 $html .= $normalization->getHtmlForColumnsList(
42 $db,
43 $table,
44 _pgettext('string types', 'String')
46 echo $html;
47 exit;
49 if (isset($_POST['splitColumn'])) {
50 $num_fields = min(4096, intval($_POST['numFields']));
51 $html = $normalization->getHtmlForCreateNewColumn($num_fields, $db, $table);
52 $html .= Url::getHiddenInputs($db, $table);
53 echo $html;
54 exit;
56 if (isset($_POST['addNewPrimary'])) {
57 $num_fields = 1;
58 $columnMeta = [
59 'Field' => $table . "_id",
60 'Extra' => 'auto_increment',
62 $html = $normalization->getHtmlForCreateNewColumn(
63 $num_fields,
64 $db,
65 $table,
66 $columnMeta
68 $html .= Url::getHiddenInputs($db, $table);
69 echo $html;
70 exit;
72 if (isset($_POST['findPdl'])) {
73 $html = $normalization->findPartialDependencies($table, $db);
74 echo $html;
75 exit;
78 if (isset($_POST['getNewTables2NF'])) {
79 $partialDependencies = json_decode($_POST['pd']);
80 $html = $normalization->getHtmlForNewTables2NF($partialDependencies, $table);
81 echo $html;
82 exit;
85 if (isset($_POST['getNewTables3NF'])) {
86 $dependencies = json_decode($_POST['pd']);
87 $tables = json_decode($_POST['tables']);
88 $newTables = $normalization->getHtmlForNewTables3NF($dependencies, $tables, $db);
89 $response->disable();
90 Core::headerJSON();
91 echo json_encode($newTables);
92 exit;
95 $header = $response->getHeader();
96 $scripts = $header->getScripts();
97 $scripts->addFile('normalization.js');
98 $scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
99 $normalForm = '1nf';
100 if (Core::isValid($_POST['normalizeTo'], ['1nf', '2nf', '3nf'])) {
101 $normalForm = $_POST['normalizeTo'];
103 if (isset($_POST['createNewTables2NF'])) {
104 $partialDependencies = json_decode($_POST['pd']);
105 $tablesName = json_decode($_POST['newTablesName']);
106 $res = $normalization->createNewTablesFor2NF($partialDependencies, $tablesName, $table, $db);
107 $response->addJSON($res);
108 exit;
110 if (isset($_POST['createNewTables3NF'])) {
111 $newtables = json_decode($_POST['newTables']);
112 $res = $normalization->createNewTablesFor3NF($newtables, $db);
113 $response->addJSON($res);
114 exit;
116 if (isset($_POST['repeatingColumns'])) {
117 $repeatingColumns = $_POST['repeatingColumns'];
118 $newTable = $_POST['newTable'];
119 $newColumn = $_POST['newColumn'];
120 $primary_columns = $_POST['primary_columns'];
121 $res = $normalization->moveRepeatingGroup(
122 $repeatingColumns,
123 $primary_columns,
124 $newTable,
125 $newColumn,
126 $table,
129 $response->addJSON($res);
130 exit;
132 if (isset($_POST['step1'])) {
133 $html = $normalization->getHtmlFor1NFStep1($db, $table, $normalForm);
134 $response->addHTML($html);
135 } elseif (isset($_POST['step2'])) {
136 $res = $normalization->getHtmlContentsFor1NFStep2($db, $table);
137 $response->addJSON($res);
138 } elseif (isset($_POST['step3'])) {
139 $res = $normalization->getHtmlContentsFor1NFStep3($db, $table);
140 $response->addJSON($res);
141 } elseif (isset($_POST['step4'])) {
142 $res = $normalization->getHtmlContentsFor1NFStep4($db, $table);
143 $response->addJSON($res);
144 } elseif (isset($_POST['step']) && $_POST['step'] == '2.1') {
145 $res = $normalization->getHtmlFor2NFstep1($db, $table);
146 $response->addJSON($res);
147 } elseif (isset($_POST['step']) && $_POST['step'] == '3.1') {
148 $tables = $_POST['tables'];
149 $res = $normalization->getHtmlFor3NFstep1($db, $tables);
150 $response->addJSON($res);
151 } else {
152 $response->addHTML($normalization->getHtmlForNormalizeTable());