]> git.mxchange.org Git - friendica.git/blobdiff - include/dbstructure.php
Fix Issue #2816 - MySQL version typo
[friendica.git] / include / dbstructure.php
index f5a1d4fde4346af6d121ce35056f17ac4dde1b2d..9e0020fdbe21f5d0bb94780263ae99c30a3bb691 100644 (file)
@@ -130,6 +130,9 @@ function print_structure($database, $charset) {
 function update_structure($verbose, $action, $tables=null, $definition=null) {
        global $a, $db;
 
+       if ($action)
+               set_config('system', 'maintenance', 1);
+
        if (isset($a->config["system"]["db_charset"]))
                $charset = $a->config["system"]["db_charset"];
        else
@@ -162,6 +165,13 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
        if ($action)
                @$db->q($sql_config);
 
+       // MySQL >= 5.7.4 doesn't support the IGNORE keyword in ALTER TABLE statements
+       if (version_compare($db->getdb()->server_info, '5.7.4') >= 0) {
+               $ignore = '';
+       }else {
+               $ignore = ' IGNORE';
+       }
+
        // Compare it
        foreach ($definition AS $name => $structure) {
                $is_new_table = False;
@@ -186,7 +196,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
                                if ($current_index_definition != $new_index_definition && substr($indexname, 0, 6) != 'local_') {
                                        $sql2=db_drop_index($indexname);
                                        if ($sql3 == "")
-                                               $sql3 = "ALTER IGNORE TABLE `".$name."` ".$sql2;
+                                               $sql3 = "ALTER TABLE `".$name."` ".$sql2;
                                        else
                                                $sql3 .= ", ".$sql2;
                                }
@@ -196,7 +206,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
                                if (!isset($database[$name]["fields"][$fieldname])) {
                                        $sql2=db_add_table_field($fieldname, $parameters);
                                        if ($sql3 == "")
-                                               $sql3 = "ALTER IGNORE TABLE `".$name."` ".$sql2;
+                                               $sql3 = "ALTER TABLE `".$name."` ".$sql2;
                                        else
                                                $sql3 .= ", ".$sql2;
                                } else {
@@ -206,7 +216,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
                                        if ($current_field_definition != $new_field_definition) {
                                                $sql2=db_modify_table_field($fieldname, $parameters);
                                                if ($sql3 == "")
-                                                       $sql3 = "ALTER IGNORE TABLE `".$name."` ".$sql2;
+                                                       $sql3 = "ALTER TABLE `".$name."` ".$sql2;
                                                else
                                                        $sql3 .= ", ".$sql2;
                                        }
@@ -230,7 +240,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
                                        $sql2=db_create_index($indexname, $fieldnames);
                                        if ($sql2 != "") {
                                                if ($sql3 == "")
-                                                       $sql3 = "ALTER IGNORE TABLE `".$name."` ".$sql2;
+                                                       $sql3 = "ALTER" . $ignore . " TABLE `".$name."` ".$sql2;
                                                else
                                                        $sql3 .= ", ".$sql2;
                                        }
@@ -251,6 +261,9 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
                }
        }
 
+       if ($action)
+               set_config('system', 'maintenance', 0);
+
        return $errors;
 }
 
@@ -1518,7 +1531,8 @@ function dbstructure_run(&$argv, &$argc) {
        // print help
        echo $argv[0]." <command>\n";
        echo "\n";
-       echo "commands:\n";
+       echo "Commands:\n";
+       echo "dryrun            show database update schema queries without running them\n";
        echo "update            update database schema\n";
        echo "dumpsql           dump database schema\n";
        return;