]> git.joonet.de Git - adminer.git/commitdiff
Simplify process_fields()
authorJakub Vrana <jakub@vrana.cz>
Wed, 8 May 2013 18:43:53 +0000 (11:43 -0700)
committerJakub Vrana <jakub@vrana.cz>
Wed, 8 May 2013 18:43:53 +0000 (11:43 -0700)
adminer/create.inc.php
adminer/include/editing.inc.php
adminer/procedure.inc.php

index 67472e80240f14cd4d0a8fa17fae09e614a35065..208396b8b2b105948f940af57fc94fd94d914840 100644 (file)
@@ -17,8 +17,11 @@ if ($TABLE != "") {
 
 $row = $_POST;
 $row["fields"] = (array) $row["fields"];
+if ($row["auto_increment_col"]) {
+       $row["fields"][$row["auto_increment_col"]]["auto_increment"] = true;
+}
 
-if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] && !$_POST["down"]) {
+if ($_POST && !process_fields($row["fields"]) && !$error) {
        if ($_POST["drop"]) {
                query_redirect("DROP TABLE " . table($TABLE), substr(ME, 0, -1), lang('Table has been dropped.'));
        } else {
@@ -104,43 +107,38 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"]
 
 page_header(($TABLE != "" ? lang('Alter table') : lang('Create table')), $error, array("table" => $TABLE), $TABLE);
 
-if ($_POST) {
-       if ($row["auto_increment_col"]) {
-               $row["fields"][$row["auto_increment_col"]]["auto_increment"] = true;
-       }
-       process_fields($row["fields"]);
-       
-} elseif ($TABLE != "") {
-       $row = $orig_status;
-       $row["name"] = $TABLE;
-       $row["fields"] = array();
-       if (!$_GET["auto_increment"]) { // don't prefill by original Auto_increment for the sake of performance and not reusing deleted ids
-               $row["Auto_increment"] = "";
-       }
-       foreach ($orig_fields as $field) {
-               $field["has_default"] = isset($field["default"]);
-               $row["fields"][] = $field;
-       }
-       
-       if (support("partitioning")) {
-               $from = "FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = " . q(DB) . " AND TABLE_NAME = " . q($TABLE);
-               $result = $connection->query("SELECT PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $from ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1");
-               list($row["partition_by"], $row["partitions"], $row["partition"]) = $result->fetch_row();
-               $row["partition_names"] = array();
-               $row["partition_values"] = array();
-               foreach (get_rows("SELECT PARTITION_NAME, PARTITION_DESCRIPTION $from AND PARTITION_NAME != '' ORDER BY PARTITION_ORDINAL_POSITION") as $row1) {
-                       $row["partition_names"][] = $row1["PARTITION_NAME"];
-                       $row["partition_values"][] = $row1["PARTITION_DESCRIPTION"];
-               }
-               $row["partition_names"][] = "";
-       }
-       
-} else {
+if (!$_POST) {
        $row = array(
                "Engine" => $_COOKIE["adminer_engine"],
                "fields" => array(array("field" => "", "type" => (isset($types["int"]) ? "int" : (isset($types["integer"]) ? "integer" : "")))),
                "partition_names" => array(""),
        );
+       
+       if ($TABLE != "") {
+               $row = $orig_status;
+               $row["name"] = $TABLE;
+               $row["fields"] = array();
+               if (!$_GET["auto_increment"]) { // don't prefill by original Auto_increment for the sake of performance and not reusing deleted ids
+                       $row["Auto_increment"] = "";
+               }
+               foreach ($orig_fields as $field) {
+                       $field["has_default"] = isset($field["default"]);
+                       $row["fields"][] = $field;
+               }
+               
+               if (support("partitioning")) {
+                       $from = "FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = " . q(DB) . " AND TABLE_NAME = " . q($TABLE);
+                       $result = $connection->query("SELECT PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $from ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1");
+                       list($row["partition_by"], $row["partitions"], $row["partition"]) = $result->fetch_row();
+                       $row["partition_names"] = array();
+                       $row["partition_values"] = array();
+                       foreach (get_rows("SELECT PARTITION_NAME, PARTITION_DESCRIPTION $from AND PARTITION_NAME != '' ORDER BY PARTITION_ORDINAL_POSITION") as $row1) {
+                               $row["partition_names"][] = $row1["PARTITION_NAME"];
+                               $row["partition_values"][] = $row1["PARTITION_DESCRIPTION"];
+                       }
+                       $row["partition_names"][] = "";
+               }
+       }
 }
 
 $collations = collations();
index ef312a529a048c937cec8cb15827d26f1ad3e8fc..11698251f414268d5a25296341edacd694511d13 100644 (file)
@@ -260,7 +260,7 @@ function edit_fields($fields, $collations, $type = "TABLE", $foreign_keys = arra
 
 /** Move fields up and down or add field
 * @param array
-* @return null
+* @return bool
 */
 function process_fields(&$fields) {
        ksort($fields);
@@ -278,8 +278,7 @@ function process_fields(&$fields) {
                        }
                        $offset++;
                }
-       }
-       if ($_POST["down"]) {
+       } elseif ($_POST["down"]) {
                $found = false;
                foreach ($fields as $key => $field) {
                        if (isset($field["field"]) && $found) {
@@ -292,11 +291,13 @@ function process_fields(&$fields) {
                        }
                        $offset++;
                }
-       }
-       $fields = array_values($fields);
-       if ($_POST["add"]) {
+       } elseif ($_POST["add"]) {
+               $fields = array_values($fields);
                array_splice($fields, key($_POST["add"]), 0, array(array()));
+       } elseif (!$_POST["drop_col"]) {
+               return false;
        }
+       return true;
 }
 
 /** Callback used in routine()
index 9e1d08687d92a0d400d433f1bd8f502cedb96ec1..c3f56e3045892e1b842bb1552825df07f80d8e72 100644 (file)
@@ -4,22 +4,19 @@ $routine = (isset($_GET["function"]) ? "FUNCTION" : "PROCEDURE");
 $row = $_POST;
 $row["fields"] = (array) $row["fields"];
 
-if ($_POST) {
-       if (!$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] && !$_POST["down"]) {
-               $temp_name = "$row[name]_adminer_" . uniqid();
-               drop_create(
-                       "DROP $routine " . idf_escape($PROCEDURE),
-                       create_routine($routine, $row),
-                       create_routine($routine, array("name" => $temp_name) + $row),
-                       "DROP $routine " . idf_escape($temp_name),
-                       substr(ME, 0, -1),
-                       lang('Routine has been dropped.'),
-                       lang('Routine has been altered.'),
-                       lang('Routine has been created.'),
-                       $PROCEDURE
-               );
-       }
-       process_fields($row["fields"]);
+if ($_POST && !process_fields($row["fields"]) && !$error) {
+       $temp_name = "$row[name]_adminer_" . uniqid();
+       drop_create(
+               "DROP $routine " . idf_escape($PROCEDURE),
+               create_routine($routine, $row),
+               create_routine($routine, array("name" => $temp_name) + $row),
+               "DROP $routine " . idf_escape($temp_name),
+               substr(ME, 0, -1),
+               lang('Routine has been dropped.'),
+               lang('Routine has been altered.'),
+               lang('Routine has been created.'),
+               $PROCEDURE
+       );
 }
 
 page_header(($PROCEDURE != "" ? (isset($_GET["function"]) ? lang('Alter function') : lang('Alter procedure')) . ": " . h($PROCEDURE) : (isset($_GET["function"]) ? lang('Create function') : lang('Create procedure'))), $error);