Fixed hangouts on php installations with zlib extension installed, fixed warnings...
[fa-stable.git] / admin / db / maintenance_db.inc
index 81fc0abc0f764f8c4d140a13ad3bca26ec65c17d..cd4afdacf477f1178da6fd18352834eddaa0abba 100644 (file)
@@ -178,7 +178,7 @@ function update_extensions($extensions) {
        }
 
        // update per company files
-       $cnt = count($db_connections);
+       $cnt = max(1, count($db_connections));
        for($i = 0; $i < $cnt; $i++) 
        {
                $newexts = $extensions;
@@ -253,14 +253,20 @@ function write_lang()
 
 function db_import($filename, $connection, $force=true)
 {
-       global $db, $go_debug;
+       global $db, $go_debug, $sql_trail;
+
+       $sql_trail = false;
 
        $allowed_commands = array(
                "create"  => 'table_queries', 
+               "delimiter" => 'table_queries',
                "alter table" => 'table_queries', 
                "insert" => 'data_queries', 
                "update" => 'data_queries', 
-               "drop table if exists" => 'drop_queries');
+               "drop table if exists" => 'drop_queries',
+               "drop function if exists" => 'drop_queries',
+               "drop trigger if exists" => 'drop_queries',
+               );
        $ignored_mysql_errors = array( //errors ignored in normal (non forced) mode
                '1022', // duplicate key
                '1050', // Table %s already exists
@@ -286,6 +292,7 @@ function db_import($filename, $connection, $force=true)
 
        // parse input file
        $query_table = '';
+       $delimiter = ';';
        foreach($lines as $line_no => $line)
        {
                $line = trim($line);
@@ -298,6 +305,10 @@ function db_import($filename, $connection, $force=true)
                        {
                                if (strtolower(substr($line, 0, strlen($cmd))) == $cmd) 
                                {
+                                       if ($cmd == 'delimiter') {
+                                               $delimiter = trim(substr($line, 10));
+                                               continue 2;
+                                       }
                                        $query_table = $table;
                                        ${$query_table}[] = array('', $line_no+1);
                                        break;
@@ -307,9 +318,10 @@ function db_import($filename, $connection, $force=true)
                 if($query_table != '')  // inside allowed query
                 {
                        $table = $query_table;
-                       if (substr($line, -1) == ';') // end of query found
+
+                       if (substr($line, -strlen($delimiter)) == $delimiter) // end of query found
                        {
-                               $line = substr($line, 0, strlen($line) - 1); // strip ';'
+                               $line = substr($line, 0, strlen($line) - strlen($delimiter)); // strip delimiter
                                $query_table = '';
                        }
                        ${$table}[count(${$table}) - 1][0] .= $line . "\n";
@@ -367,6 +379,7 @@ function db_import($filename, $connection, $force=true)
        }
        
        db_query("SET foreign_key_checks=1");
+       if ($delimiter != ';') db_query("delimiter ;"); // just for any case
 
        if (count($sql_errors)) {
                // display first failure message; the rest are probably derivative 
@@ -720,7 +733,7 @@ function save_to_file($backupfile, $zip, $fileData)
         $c_len = strlen($zdata);
 
         // dos time
-        $timearray = getdate($zip);
+        $timearray = getdate();
         $dostime = (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) |
             ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
         $dtime = dechex($dostime);