]> git.mxchange.org Git - friendica.git/blobdiff - include/dbstructure.php
fixed parser error, need parentheses
[friendica.git] / include / dbstructure.php
index e8f1738a7dee01c5f5ee3bc72167250ca03e2a9d..6a14220c241bcdef90757555074e3a0a000da964 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
-use \Friendica\Core\Config;
+use Friendica\App;
+use Friendica\Core\Config;
 
 require_once("boot.php");
 require_once("include/text.php");
@@ -398,6 +399,14 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
                                $sql3 .= ";";
                        }
 
+                       $field_list = '';
+                       if ($is_unique && $ignore == '') {
+                               foreach ($structure['fields'] AS $fieldname => $parameters) {
+                                       $field_list .= 'ANY_VALUE(`' . $fieldname . '`),';
+                               }
+                               $field_list = rtrim($field_list, ',');
+                       }
+
                        if ($verbose) {
                                // Ensure index conversion to unique removes duplicates
                                if ($is_unique) {
@@ -414,7 +423,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
                                        if ($ignore != "") {
                                                echo "SET session old_alter_table=0;\n";
                                        } else {
-                                               echo "INSERT INTO `".$temp_name."` SELECT * FROM `".$name."`".$group_by.";\n";
+                                               echo "INSERT INTO `".$temp_name."` SELECT ".$field_list." FROM `".$name."`".$group_by.";\n";
                                                echo "DROP TABLE `".$name."`;\n";
                                                echo "RENAME TABLE `".$temp_name."` TO `".$name."`;\n";
                                        }
@@ -445,7 +454,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
                                        if ($ignore != "") {
                                                $db->q("SET session old_alter_table=0;");
                                        } else {
-                                               $r = $db->q("INSERT INTO `".$temp_name."` SELECT * FROM `".$name."`".$group_by.";");
+                                               $r = $db->q("INSERT INTO `".$temp_name."` SELECT ".$field_list." FROM `".$name."`".$group_by.";");
                                                if (!dbm::is_result($r)) {
                                                        $errors .= print_update_error($db, $sql3);
                                                        return $errors;
@@ -1737,7 +1746,7 @@ function dbstructure_run(&$argv, &$argc) {
        global $a, $db;
 
        if (is_null($a)) {
-               $a = new App;
+               $a = new App(dirname(__DIR__));
        }
 
        if (is_null($db)) {