[geeklog-cvs] geeklog: Ported updated install script over from Matt's GSoC 200...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Sat Oct 11 13:23:16 EDT 2008


details:   http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/0102c409a695
changeset: 6435:0102c409a695
user:      Dirk Haun <dirk at haun-online.de>
date:      Sat Oct 11 19:22:54 2008 +0200
description:
Ported updated install script over from Matt's GSoC 2008 project.

diffstat:

8 files changed, 3339 insertions(+), 1222 deletions(-)
public_html/admin/install/bigdump.php          |  395 +++++
public_html/admin/install/index.php            | 1792 +++++++++---------------
public_html/admin/install/install-plugins.php  |  529 +++++++
public_html/admin/install/language/english.php |  134 +
public_html/admin/install/layout/style.css     |  296 ++-
public_html/admin/install/lib-install.php      |  758 ++++++++++
public_html/admin/install/migrate.php          |  637 ++++++++
public_html/admin/install/success.php          |   20 

diffs (truncated from 5029 to 300 lines):

diff -r 9fe12b441d71 -r 0102c409a695 public_html/admin/install/bigdump.php
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/public_html/admin/install/bigdump.php	Sat Oct 11 19:22:54 2008 +0200
@@ -0,0 +1,395 @@
+<?php
+
+/* Reminder: always indent with 4 spaces (no tabs). */
+// +---------------------------------------------------------------------------+
+// | Geeklog 1.5                                                               |
+// +---------------------------------------------------------------------------+
+// | bigdump.php                                                               |
+// |                                                                           |
+// | Staggered import for large MySQL Dumps                                    |
+// +---------------------------------------------------------------------------+
+// | Copyright (C) 2008 by the following authors:                              |
+// |                                                                           |
+// | Authors: Alexey Ozerov - alexey AT ozerov DOT de (BigDump author)         |
+// |          Matt West     - matt.danger.west AT gmail DOT com                |
+// +---------------------------------------------------------------------------+
+// |                                                                           |
+// | This program is free software; you can redistribute it and/or             |
+// | modify it under the terms of the GNU General Public License               |
+// | as published by the Free Software Foundation; either version 2            |
+// | of the License, or (at your option) any later version.                    |
+// |                                                                           |
+// | This program is distributed in the hope that it will be useful,           |
+// | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
+// | GNU General Public License for more details.                              |
+// |                                                                           |
+// | You should have received a copy of the GNU General Public License         |
+// | along with this program; if not, write to the Free Software Foundation,   |
+// | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
+// |                                                                           |
+// +---------------------------------------------------------------------------+
+//
+
+//
+// BigDump ver. 0.29b from 2008-01-19
+// Staggered import of an large MySQL Dump (like phpMyAdmin 2.x Dump)
+// Even through the webservers with hard runtime limit and those in safe mode
+// Works fine with Internet Explorer 7.0 and Firefox 2.x
+//
+// Author:       Alexey Ozerov (alexey at ozerov dot de) 
+//               AJAX & CSV functionalities: Krzysiek Herod (kr81uni at wp dot pl) 
+// Copyright:    GPL (C) 2003-2008
+// More Infos:   http://www.ozerov.de/bigdump.php
+//
+// THIS SCRIPT IS PROVIDED AS IS, WITHOUT ANY WARRANTY OR GUARANTEE OF ANY KIND
+//
+
+// Database configuration
+require_once '../../../db-config.php';
+require_once 'lib-install.php';
+$db_server   = $_DB_host;
+$db_name     = $_DB_name;
+$db_username = $_DB_user;
+$db_password = $_DB_pass;
+
+$site_url    = (isset($_REQUEST['site_url']) ? $_REQUEST['site_url'] : '');
+$site_admin_url   = (isset($_REQUEST['site_admin_url']) ? $_REQUEST['site_admin_url'] : '');
+
+// Other settings (optional)
+$filename         = '';     // Specify the dump filename to suppress the file selection dialog
+$csv_insert_table = '';     // Destination table for CSV files
+$linespersession  = 3000;   // Lines to be executed per one import session
+$delaypersession  = 0;      // You can specify a sleep time in milliseconds after each session
+                            // Works only if JavaScript is activated. Use to reduce server overrun
+
+// Allowed comment delimiters: lines starting with these strings will be dropped by BigDump
+$comment[]='#';                       // Standard comment lines are dropped by default
+$comment[]='-- ';
+// $comment[]='---';                  // Uncomment this line if using proprietary dump created by outdated mysqldump
+// $comment[]='CREATE DATABASE';      // Uncomment this line if your dump contains create database queries in order to ignore them
+// $comment[]='/*!';                  // Or add your own string to leave out other proprietary things
+
+// Connection character set should be the same as the dump file character set (utf8, latin1, cp1251, koi8r etc.)
+// See http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html for the full list
+$db_connection_charset = '';
+
+// *******************************************************************************************
+// If not familiar with PHP please don't change anything below this line
+// *******************************************************************************************
+
+//define ('VERSION','0.29b');
+define ('DATA_CHUNK_LENGTH',16384);  // How many chars are read per time
+define ('MAX_QUERY_LINES',300);      // How many lines may be considered to be one query (except text lines)
+define ('TESTMODE',false);           // Set to true to process the file without actually accessing the database
+ at ini_set('auto_detect_line_endings', true);
+ at set_time_limit(0);
+
+echo INST_getHeader($LANG_MIGRATE[17]);
+
+$error = false;
+$file  = false;
+
+// Get the current directory
+if (isset($_SERVER["CGIA"]))
+  $upload_dir=dirname($_SERVER["CGIA"]);
+else if (isset($_SERVER["ORIG_PATH_TRANSLATED"]))
+  $upload_dir=dirname($_SERVER["ORIG_PATH_TRANSLATED"]);
+else if (isset($_SERVER["ORIG_SCRIPT_FILENAME"]))
+  $upload_dir=dirname($_SERVER["ORIG_SCRIPT_FILENAME"]);
+else if (isset($_SERVER["PATH_TRANSLATED"]))
+  $upload_dir=dirname($_SERVER["PATH_TRANSLATED"]);
+else 
+  $upload_dir=dirname($_SERVER["SCRIPT_FILENAME"]);
+
+
+// Connect to the database
+if (!$error && !TESTMODE) {
+  $dbconnection = @mysql_connect($db_server,$db_username,$db_password);
+  if ($dbconnection) 
+    $db = mysql_select_db($db_name);
+  if (!$dbconnection || !$db) {
+    echo INST_getAlertMsg($LANG_ERROR[9] . mysql_error() . '<br' . XHTML .'>' . $LANG_ERROR[10]);
+    $error=true;
+  }
+  if (!$error && $db_connection_charset!=='')
+    @mysql_query("SET NAMES $db_connection_charset", $dbconnection);
+} else {
+  $dbconnection = false;
+}
+
+// Single file mode
+if (!$error && !isset ($_REQUEST["fn"]) && $filename!="") {
+  echo '<p><a href="' . $_SERVER['PHP_SELF'] . '?start=1&fn=' . urlencode($filename) . '&foffset=0&totalqueries=0\">' . $LANG_BIGDUMP[0] . '</a>' . $LANG_BIGDUMP[1] . $filename . $LANG_BIGDUMP[2] . $db_name . $LANG_BIGDUMP[3] . $db_server . LB;
+}
+
+
+// Open the file
+if (!$error && isset($_REQUEST["start"])) { 
+  // Set current filename ($filename overrides $_REQUEST["fn"] if set)
+  if ($filename != "")
+    $curfilename = $filename;
+  else if (isset($_REQUEST["fn"]))
+    $curfilename = urldecode($_REQUEST["fn"]);
+  else
+    $curfilename = "";
+
+  // Recognize GZip filename
+  if (eregi("\.gz$",$curfilename)) 
+    $gzipmode = true;
+  else
+    $gzipmode = false;
+
+  if ((!$gzipmode && !$file=@fopen($curfilename,"rt")) || ($gzipmode && !$file=@gzopen($curfilename,"rt"))) {
+    echo INST_getAlertMsg($LANG_BIGDUMP[5] . $curfilename . $LANG_BIGDUMP[6]);
+    $error = true;
+  }
+
+  // Get the file size (can't do it fast on gzipped files, no idea how)
+  else if ((!$gzipmode && @fseek($file, 0, SEEK_END)==0) || ($gzipmode && @gzseek($file, 0)==0)) {
+    if (!$gzipmode) $filesize = ftell($file);
+    else $filesize = gztell($file);                   // Always zero, ignore
+  } else {
+        echo INST_getAlertMsg($LANG_BIGDUMP[4] . $curfilename);
+    $error = true;
+  }
+}
+
+// *******************************************************************************************
+// START IMPORT SESSION HERE
+// *******************************************************************************************
+
+if (!$error && isset($_REQUEST["start"]) && isset($_REQUEST["foffset"]) && eregi("(\.(sql|gz|csv))$",$curfilename)) {
+
+  // Check start and foffset are numeric values
+  if (!is_numeric($_REQUEST["start"]) || !is_numeric($_REQUEST["foffset"])) {
+    echo INST_getAlertMsg($LANG_BIGDUMP[7]);
+    $error=true;
+  }
+
+  if (!$error) {
+    $_REQUEST["start"]   = floor($_REQUEST["start"]);
+    $_REQUEST["foffset"] = floor($_REQUEST["foffset"]);
+    echo '<p>' . $LANG_BIGDUMP[8] . ' <b>' . $curfilename . '</b></p>' . LB;
+  }
+
+  // Check $_REQUEST["foffset"] upon $filesize (can't do it on gzipped files)
+  if (!$error && !$gzipmode && $_REQUEST["foffset"]>$filesize) {
+    echo INST_getAlertMsg($LANG_BIGDUMP[9]);
+    $error=true;
+  }
+
+  // Set file pointer to $_REQUEST["foffset"]
+  if (!$error && ((!$gzipmode && fseek($file, $_REQUEST["foffset"])!=0) || ($gzipmode && gzseek($file, $_REQUEST["foffset"])!=0))) {
+    echo INST_getAlertMsg($LANG_BIGDUMP[10] . $_REQUEST["foffset"]);
+    $error = true;
+  }
+
+  // Start processing queries from $file
+  if (!$error) {
+    $query="";
+    $queries=0;
+    $totalqueries=$_REQUEST["totalqueries"];
+    $linenumber=$_REQUEST["start"];
+    $querylines=0;
+    $inparents=false;
+
+    // Stay processing as long as the $linespersession is not reached or the query is still incomplete
+    while ($linenumber<$_REQUEST["start"]+$linespersession || $query!="") {
+
+      // Read the whole next line
+      $dumpline = "";
+      while (!feof($file) && substr ($dumpline, -1) != "\n") {
+        if (!$gzipmode)
+          $dumpline .= fgets($file, DATA_CHUNK_LENGTH);
+        else
+          $dumpline .= gzgets($file, DATA_CHUNK_LENGTH);
+      }
+      if ($dumpline==="") break;
+
+      // Stop if csv file is used, but $csv_insert_table is not set
+      if (($csv_insert_table == "") && (eregi("(\.csv)$",$curfilename))) {
+        echo INST_getAlertMsg($LANG_BIGDUMP[11] . $linenumber . $LANG_BIGDUMP[12] . $csv_insert_table . $LANG_BIGDUMP[13]);
+        $error=true;
+        break;
+      }
+     
+      // Create an SQL query from CSV line
+      if (($csv_insert_table != "") && (eregi("(\.csv)$",$curfilename)))
+        $dumpline = 'INSERT INTO '.$csv_insert_table.' VALUES ('.$dumpline.');';
+
+      // Handle DOS and Mac encoded linebreaks (I don't know if it will work on Win32 or Mac Servers)
+      $dumpline=str_replace("\r\n", "\n", $dumpline);
+      $dumpline=str_replace("\r", "\n", $dumpline);
+            
+      // Skip comments and blank lines only if NOT in parents
+      if (!$inparents){
+        $skipline=false;
+        reset($comment);
+        foreach ($comment as $comment_value) {
+          if (!$inparents && (trim($dumpline)=="" || strpos ($dumpline, $comment_value) === 0)) {
+            $skipline=true;
+            break;
+          }
+        }
+        if ($skipline) {
+          $linenumber++;
+          continue;
+        }
+      }
+
+      // Remove double back-slashes from the dumpline prior to count the quotes ('\\' can only be within strings)
+      $dumpline_deslashed = str_replace ("\\\\","",$dumpline);
+
+      // Count ' and \' in the dumpline to avoid query break within a text field ending by ;
+      // Please don't use double quotes ('"')to surround strings, it wont work
+      $parents=substr_count ($dumpline_deslashed, "'")-substr_count ($dumpline_deslashed, "\\'");
+      if ($parents % 2 != 0)
+        $inparents=!$inparents;
+
+      // Add the line to query
+      $query .= $dumpline;
+
+      // Don't count the line if in parents (text fields may include unlimited linebreaks)
+      if (!$inparents)
+        $querylines++;
+      
+      // Stop if query contains more lines as defined by MAX_QUERY_LINES
+      if ($querylines>MAX_QUERY_LINES) {
+    echo INST_getAlertMsg($LANG_BIGDUMP[14] . $linenumber . $LANG_BIGDUMP[15] . MAX_QUERY_LINES . $LANG_BIGDUMP[16]);
+        $error=true;
+        break;
+      }
+
+      // Execute query if end of query detected (; as last character) AND NOT in parents
+      if (ereg(";$",trim($dumpline)) && !$inparents) {
+        if (!TESTMODE && !mysql_query(trim($query), $dbconnection)) {
+          echo INST_getAlertMsg($LANG_BIGDUMP[17] . $linenumber . ': ' . trim($dumpline) . '.<br ' . XHTML . '>' . $LANG_BIGDUMP[18] . trim(nl2br(htmlentities($query))) . '<br ' . XHTML . '>' . $LANG_BIGDUMP[19] . mysql_error());
+          $error=true;
+          break;
+        }
+        $totalqueries++;
+        $queries++;
+        $query="";
+        $querylines=0;
+      }
+      $linenumber++;
+    }
+  }
+
+  // Get the current file position
+  if (!$error) {
+    if (!$gzipmode) 
+      $foffset = ftell($file);
+    else
+      $foffset = gztell($file);
+    if (!$foffset) { 
+      echo INST_getAlertMsg($LANG_BIGDUMP[20]);
+      $error = true;
+    }
+  }
+
+// Print statistics
+
+  if (!$error) { 
+    $lines_this   = $linenumber-$_REQUEST["start"];
+    $lines_done   = $linenumber-1;



More information about the geeklog-cvs mailing list