Changeset:
        1efcbb4bca6b
        
https://sourceforge.net/p/mrbs/hg-code/ci/1efcbb4bca6b5b04e7eb69fe6f0731ef1accdb42
Author:
        Campbell Morrison <[email protected]>
Date:
        Thu Oct 22 18:44:42 2015 +0100
Log message:

Added flushing of output to provide some feedback during long upgrades of large 
databases

diffstat:

 web/upgrade.inc |  34 ++++++++++++++++++++++------------
 1 files changed, 22 insertions(+), 12 deletions(-)

diffs (80 lines):

diff -r 1d910a13bd26 -r 1efcbb4bca6b web/upgrade.inc
--- a/web/upgrade.inc   Thu Oct 22 16:36:04 2015 +0100
+++ b/web/upgrade.inc   Thu Oct 22 18:44:42 2015 +0100
@@ -6,6 +6,19 @@
 // Upgrade between database schema versions.
 //
 // Returns FALSE on error, TRUE is successful
+
+function upgrade_echo($message)
+{
+  echo $message;
+  // Flush the message, so that there's some progress information
+  // output to the browser even when the upgrade is taking a while
+  if (ob_get_length() !== FALSE)
+  {
+    ob_flush();
+  }
+  flush();
+}
+
 function upgrade_database($local, $from, $to, $upgrade_handle)
 {
   // $local is a boolean specifying whether the upgrades are global MRBS ones 
($local == FALSE)
@@ -24,9 +37,9 @@
     
   for ($ver = ($from+1); $ver <= $to; $ver++)
   {
-    print "<p>" .
-          (($local) ? get_vocab("upgrade_to_local_version") : 
get_vocab("upgrade_to_version")) .
-          ": $ver";
+    upgrade_echo("<p>" .
+                 (($local) ? get_vocab("upgrade_to_local_version") : 
get_vocab("upgrade_to_version")) .
+                 ": $ver");
 
     if ($local)
     {
@@ -42,7 +55,7 @@
     if (!$handle)
     {
       // No need to localise, should never happen!
-      print "Fatal error: Failed to open '$filename' for reading.\n";
+      upgrade_echo("Fatal error: Failed to open '$filename' for reading.\n");
       return FALSE;
     }
     $file_size = filesize($filename);
@@ -68,17 +81,14 @@
         if ($res === FALSE)
         {
           // No need to localise, should hopefully never happen
-          print "<br>Tried:<pre>
-".htmlspecialchars($query)."
-</pre> and got error:<pre>
-".sql_error($upgrade_handle)."
-</pre>\n";
+          upgrade_echo("<br>Tried:<pre>" . htmlspecialchars($query) . "</pre> 
and got error:" .
+                       "<pre>" . sql_error($upgrade_handle) . "</pre>\n");
           return FALSE;
         }
       }
     }
 
-    print "<br>".get_vocab("ok");
+    upgrade_echo("<br>" . get_vocab("ok"));
     if ($ver > 1)
     {
       $variable_name = ($local) ? "local_db_version" : "db_version";
@@ -87,11 +97,11 @@
       if ($res == -1)
       {
         // No need to localise, should never happen
-        print "<span class=\"error\">Failed to update database version 
variable.</span>";
+        upgrade_echo("<span class=\"error\">Failed to update database version 
variable.</span>");
         return FALSE;
       }
     }
-    print "</p>\n";
+    upgrade_echo("</p>\n");
     
     // Now execute the PHP file if there is one
     if (file_exists($php_filename))

------------------------------------------------------------------------------
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to