Fixed error handling during normal and forced database upgrade.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Wed, 19 Nov 2008 14:16:51 +0000 (14:16 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Wed, 19 Nov 2008 14:16:51 +0000 (14:16 +0000)
admin/db/maintenance_db.inc

index 97eea2a8670811bcebedc209c975e935e909859d..1a73d00a9bc05c67f47f076413eb0a0e04b91e4d 100644 (file)
@@ -114,7 +114,13 @@ function db_import($filename, $connection, $force=true)
                "insert" => 'data_queries', 
                "update" => 'data_queries', 
                "drop table if exists" => 'drop_queries');
-
+       $ignored_mysql_errors = array( //errors ignored in normal (non forced) mode
+               '1022', // duplicate key
+               '1060', // duplicate column name
+               '1061', // duplicate key name
+               '1062', // duplicate key entry
+               '1091'  // can't drop key/column check if exists
+       );
        $data_queries = array();
        $drop_queries = array();
        $table_queries = array();
@@ -144,6 +150,8 @@ function db_import($filename, $connection, $force=true)
                                if (strtolower(substr($line, 0, strlen($cmd))) == $cmd) 
                                {
                                        $query_table = $table;
+                                       if (strstr(strtolower($line), ' drop column '))
+                                               $query_table = 'drop_queries';
                                        ${$query_table}[] = array('', $line_no+1);
                                        break;
                                }
@@ -161,13 +169,13 @@ function db_import($filename, $connection, $force=true)
                }
                
        }
-
-/*     {       // for debugging purposes
+/*
+       {       // for debugging purposes
        global $path_to_root;
-       $f = fopen($path_to_root.'/tmp/dbimport.txt', 'w');
+       $f = fopen($path_to_root.'/tmp/dbimport.txt', 'w+');
        fwrite($f, print_r($drop_queries,true) ."\n");
-       fwrite(print_r($table_queries,true) ."\n");
-       fwrite(print_r($data_queries,true));
+       fwrite($f, print_r($table_queries,true) ."\n");
+       fwrite($f, print_r($data_queries,true));
        fclose($f);
        }
 */
@@ -178,7 +186,8 @@ function db_import($filename, $connection, $force=true)
                {
                        if (!db_query($drop_query[0]))
                        {
-                               $sql_errors[] = array(db_error_msg($db), $drop_query[1]);
+                               if (!in_array(db_error_no(), $ignored_mysql_errors))
+                                       $sql_errors[] = array(db_error_no().':'.db_error_msg($db), $drop_query[1]);
                        }
                }
        }
@@ -190,7 +199,8 @@ function db_import($filename, $connection, $force=true)
                {
                        if (!db_query($table_query[0]))
                        {
-                               $sql_errors[] = array(db_error_msg($db), $table_query[1]);
+                               if (!$force || !in_array(db_error_no(), $ignored_mysql_errors))
+                                       $sql_errors[] = array(db_error_msg($db), $table_query[1]);
                        }
                }
        }
@@ -202,8 +212,8 @@ function db_import($filename, $connection, $force=true)
                {
                        if (!db_query($data_query[0]))
                        {
-                               $sql_errors[] = array(db_error_msg($db), $data_query[1]);
-                               break;
+                               if (!$force || !in_array(db_error_no(),$ignored_mysql_errors))
+                                       $sql_errors[] = array(db_error_msg($db), $data_query[1]);
                        }
                }
        }