$val) { $val = preg_replace("/[^_A-Za-z0-9-\.&=]/i", '', $val); $_REQUEST[$key] = $val; } // Determine filename to execute for loading... $filename = JPATH_BASE . DS . 'sql' . DS . 'migration' . DS . 'migrate.sql'; $_REQUEST['fn'] = $filename; $error = false; $file = false; // Single file mode if (!$error && !isset ($_REQUEST["fn"]) && $filename != "") { echo ("

', "'"), '', $_SERVER["PHP_SELF"]) . "?start=1&fn=$filename&foffset=0&totalqueries=0\">Start Import from $filename into $db_name at $db_server

\n"); } // Open the file if (!$error && isset ($_REQUEST["fn"])) { // Recognize GZip filename if (preg_match("#\.gz$#i", $_REQUEST["fn"])) $gzipmode = true; else $gzipmode = false; if ((!$gzipmode && !$file = fopen($_REQUEST["fn"], "rt")) || ($gzipmode && !$file = gzopen($_REQUEST["fn"], "rt"))) { echo ("

". JText::sprintf("Cant open file for import", $_REQUEST["fn"]) ."

\n"); echo ("

". JText::_('CHECKDUMPFILE') . " .
". JText::_('NEEDTOUPLOADFILE')."

\n"); $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 ("

". JText::_('FILESIZEUNKNOWN') . $_REQUEST["fn"] . "

\n"); $error = true; } } // ******************************************************************************************* // START IMPORT SESSION HERE // ******************************************************************************************* if (!$error && isset ($_REQUEST["start"]) && isset ($_REQUEST["foffset"]) && preg_match("#(\.(sql|gz|csv))$#i", $_REQUEST["fn"])) { // Check start and foffset are numeric values if (!is_numeric($_REQUEST["start"]) || !is_numeric($_REQUEST["foffset"])) { echo ("

". JText::_('NONNUMERICOFFSET') ."

\n"); $error = true; } if (!$error) { $_REQUEST["start"] = floor($_REQUEST["start"]); $_REQUEST["foffset"] = floor($_REQUEST["foffset"]); } // Check $_REQUEST["foffset"] upon $filesize (can't do it on gzipped files) if (!$error && !$gzipmode && $_REQUEST["foffset"] > $filesize) { echo ("

".JText::_('POINTEREOF')."

\n"); $error = true; } // Set file pointer to $_REQUEST["foffset"] if (!$error && ((!$gzipmode && fseek($file, $_REQUEST["foffset"]) != 0) || ($gzipmode && gzseek($file, $_REQUEST["foffset"]) != 0))) { echo ("

". JText::_('UNABLETOSETOFFSET') . $_REQUEST["foffset"] . "

\n"); $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; // 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); // DIAGNOSTIC // echo ("

Line $linenumber: $dumpline

\n"); // 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 ("

". JText::_('STOPPEDATLINE') ." $linenumber.

"); echo ("

". JText::sprintf('TOOMANYLINES',MAX_QUERY_LINES)."

"); $error = true; break; } $vars = $this->getVars(); $DBtype = JArrayHelper::getValue($vars, 'DBtype', 'mysql'); $DBhostname = JArrayHelper::getValue($vars, 'DBhostname', ''); $DBuserName = JArrayHelper::getValue($vars, 'DBuserName', ''); $DBpassword = JArrayHelper::getValue($vars, 'DBpassword', ''); $DBname = JArrayHelper::getValue($vars, 'DBname', ''); $DBPrefix = JArrayHelper::getValue($vars, 'DBPrefix', 'jos_'); $DBOld = JArrayHelper::getValue($vars, 'DBOld', 'bu'); //$migration = JArrayHelper::getValue($vars, 'migration', '0'); $migration = JRequest::getVar( 'migration', 0, 'post', 'bool' ); $db = & JInstallationHelper::getDBO($DBtype, $DBhostname, $DBuserName, $DBpassword, $DBname, $DBPrefix); if(JError::isError($db)) jexit(JText::_('CONNECTION FAIL')); // echo 'Done.
'; // Execute query if end of query detected (; as last character) AND NOT in parents if (ereg(";$", trim($dumpline)) && !$inparents) { if (!TESTMODE) { $db->setQuery(trim($query)); // echo $query . '
'; if (!$db->Query()) { echo ("

".JText::_('Error at the line') ." $linenumber: ". trim($dumpline) . "

\n"); echo ("

".JText::_('Query:') . trim(nl2br(htmlentities($query))) ."

\n"); echo ("

MySQL: " . mysql_error() . "

\n"); $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 ("

".JText::_('CANTREADPOINTER')."

\n"); $error = true; } } // Print statistics // echo ("

Statistics

\n"); if (!$error) { $lines_this = $linenumber - $_REQUEST["start"]; $lines_done = $linenumber -1; $lines_togo = ' ? '; $lines_tota = ' ? '; $queries_this = $queries; $queries_done = $totalqueries; $queries_togo = ' ? '; $queries_tota = ' ? '; $bytes_this = $foffset - $_REQUEST["foffset"]; $bytes_done = $foffset; $kbytes_this = round($bytes_this / 1024, 2); $kbytes_done = round($bytes_done / 1024, 2); $mbytes_this = round($kbytes_this / 1024, 2); $mbytes_done = round($kbytes_done / 1024, 2); if (!$gzipmode) { $bytes_togo = $filesize - $foffset; $bytes_tota = $filesize; $kbytes_togo = round($bytes_togo / 1024, 2); $kbytes_tota = round($bytes_tota / 1024, 2); $mbytes_togo = round($kbytes_togo / 1024, 2); $mbytes_tota = round($kbytes_tota / 1024, 2); $pct_this = ceil($bytes_this / $filesize * 100); $pct_done = ceil($foffset / $filesize * 100); $pct_togo = 100 - $pct_done; $pct_tota = 100; if ($bytes_togo == 0) { $lines_togo = '0'; $lines_tota = $linenumber -1; $queries_togo = '0'; $queries_tota = $totalqueries; } $pct_bar = "
"; } else { $bytes_togo = ' ? '; $bytes_tota = ' ? '; $kbytes_togo = ' ? '; $kbytes_tota = ' ? '; $mbytes_togo = ' ? '; $mbytes_tota = ' ? '; $pct_this = ' ? '; $pct_done = ' ? '; $pct_togo = ' ? '; $pct_tota = 100; $pct_bar = str_replace(' ', ' ', '[ Not available for gzipped files ]'); } /* echo ("
SessionDoneTo goTotal
Lines$lines_this$lines_done$lines_togo$lines_tota
Queries$queries_this$queries_done$queries_togo$queries_tota
Bytes$bytes_this$bytes_done$bytes_togo$bytes_tota
KB$kbytes_this$kbytes_done$kbytes_togo$kbytes_tota
MB$mbytes_this$mbytes_done$mbytes_togo$mbytes_tota
%$pct_this$pct_done$pct_togo$pct_tota
% bar$pct_bar
\n");*/ // Finish message and restart the script if ($linenumber < $_REQUEST["start"] + $linespersession) { echo ("

".JText::_('CONGRATSEOF')."

\n"); // Do migration if($migration) { ?>
Migration will continue shortly...
'. JText::_('FINALIZEINSTALL').''; //echo ("

Thank you for using this tool! Please rate Bigdump at Hotscripts.com

\n"); //echo ("

You can send me some bucks or euros as appreciation via PayPal

\n"); $error = true; } else { if ($delaypersession != 0) echo ("

".JText::sprintf('DELAYMSG',$delaypersession)."

\n"); ?>

".JText::_('STOPPEDONERROR')."

\n"); } //if ($dbconnection) mysql_close(); if ($file && !$gzipmode) fclose($file); else if ($file && $gzipmode) gzclose($file); //ob_flush(); //die();