]> git.mxchange.org Git - friendica.git/commitdiff
dbstructure: New tables wasn't created due to some bugs
authorMichael Vogel <icarus@dabo.de>
Sun, 15 Jun 2014 08:47:20 +0000 (10:47 +0200)
committerMichael Vogel <icarus@dabo.de>
Sun, 15 Jun 2014 08:47:20 +0000 (10:47 +0200)
include/dbstructure.php

index 83a75e4d1b8a5fe4edf128feae927e6fa0651ce4..40762a9e940a64993f398b6bd2e39470319cfd9c 100644 (file)
@@ -15,9 +15,6 @@ function dbstructure_run(&$argv, &$argc) {
                        unset($db_host, $db_user, $db_pass, $db_data);
        }
 
-       load_config('config');
-       load_config('system');
-
        update_structure(true, true);
 }
 
@@ -115,11 +112,11 @@ function update_structure($verbose, $action) {
        // Compare it
        foreach ($definition AS $name => $structure) {
                $sql3="";
-               if (!isset($database[$name]))
+               if (!isset($database[$name])) {
                        $r = db_create_table($name, $structure["fields"], $verbose, $action);
                         if(false === $r)
                                $errors .=  t('Errors encountered creating database tables.').$name.EOL;
-               else {
+               else {
                        // Compare the field structure field by field
                        foreach ($structure["fields"] AS $fieldname => $parameters) {
                                if (!isset($database[$name]["fields"][$fieldname])) {
@@ -155,14 +152,17 @@ function update_structure($verbose, $action) {
                                }
 
                // Create the index
-               foreach ($structure["indexes"] AS $indexname => $fieldnames)
+               foreach ($structure["indexes"] AS $indexname => $fieldnames) {
                        if (!isset($database[$name]["indexes"][$indexname])) {
                                $sql2=db_create_index($indexname, $fieldnames);
-                               if ($sql3 == "")
-                                       $sql3 = "ALTER TABLE `".$name."` ".$sql2;
-                               else
-                                       $sql3 .= ", ".$sql2;
+                               if ($sql2 != "") {
+                                       if ($sql3 == "")
+                                               $sql3 = "ALTER TABLE `".$name."` ".$sql2;
+                                       else
+                                               $sql3 .= ", ".$sql2;
+                               }
                        }
+               }
 
                if ($sql3 != "") {
                        $sql3 .= ";";
@@ -212,7 +212,7 @@ function db_create_table($name, $fields, $verbose, $action) {
                $sql .= "`".dbesc($fieldname)."` ".db_field_command($field);
        }
 
-       $sql = sprintf("ADD TABLE IF NOT EXISTS `%s` (\n", dbesc($name)).$sql."\n) DEFAULT CHARSET=utf8";
+       $sql = sprintf("CREATE TABLE IF NOT EXISTS `%s` (\n", dbesc($name)).$sql."\n) DEFAULT CHARSET=utf8";
 
        if ($verbose)
                echo $sql.";\n";