| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 // no direct access 3 defined( '_JEXEC' ) or die( 'Restricted access' ); 4 5 //TODO: Rewrite this so its cleaner 6 7 // BigDump ver. 0.28b from 2007-06-08 8 // Staggered import of an large MySQL Dump (like phpMyAdmin 2.x Dump) 9 // Even through the webservers with hard runtime limit and those in safe mode 10 // Works fine with Internet Explorer 7.0 and Firefox 2.x 11 12 // Author: Alexey Ozerov (alexey at ozerov dot de) 13 // AJAX & CSV functionalities: Krzysiek Herod (kr81uni at wp dot pl) 14 // Copyright: GPL (C) 2003-2007 15 // More Infos: http://www.ozerov.de/bigdump.php 16 17 // This program is free software; you can redistribute it and/or modify it under the 18 // terms of the GNU General Public License as published by the Free Software Foundation; 19 // either version 2 of the License, or (at your option) any later version. 20 21 // THIS SCRIPT IS PROVIDED AS IS, WITHOUT ANY WARRANTY OR GUARANTEE OF ANY KIND 22 23 // USAGE 24 25 // 1. Adjust the database configuration in this file 26 // 2. Drop the old tables on the target database if your dump doesn't contain "DROP TABLE" 27 // 3. Create the working directory (e.g. dump) on your web-server 28 // 4. Upload bigdump.php and your dump files (.sql, .gz) via FTP to the working directory 29 // 5. Run the bigdump.php from your browser via URL like http://www.yourdomain.com/dump/bigdump.php 30 // 6. BigDump can start the next import session automatically if you enable the JavaScript 31 // 7. Wait for the script to finish, do not close the browser window 32 // 8. IMPORTANT: Remove bigdump.php and your dump files from the web-server 33 34 // If Timeout errors still occure you may need to adjust the $linepersession setting in this file 35 36 // LAST CHANGES 37 38 // *** Improved error message for file open errors 39 // *** Handle CSV files (you have to specify $csv_insert_table) 40 // *** Restart script in the background using AJAX 41 42 /** 43 * Big Dump Handler for Migration and Import 44 * Rewritten by Sam Moffatt from original work by Alexey Ozerov) for Joomla! 1.5 45 */ 46 47 //defined('_JEXEC') or die('Access Denied'); 48 49 // Database configuration 50 51 $db_server = ''; 52 $db_name = ''; 53 $db_username = ''; 54 $db_password = ''; 55 ?> 56 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 57 <html xmlns="http://www.w3.org/1999/xhtml"> 58 <head> 59 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 60 <title><?php JText::_('Migration load script') ?></title> 61 <script type="text/javascript" src="includes/js/installation.js"></script> 62 </head> 63 <body> 64 <?php 65 66 // Other Settings 67 68 $csv_insert_table = ''; // Destination table for CSV files 69 $ajax = false; // AJAX mode: import will be done without refreshing the website 70 //$filename = ''; // Specify the dump filename to suppress the file selection dialog 71 $linespersession = 3000; // Lines to be executed per one import session 72 $delaypersession = 0; // You can specify a sleep time in milliseconds after each session 73 // Works only if JavaScript is activated. Use to reduce server overrun 74 75 // Allowed comment delimiters: lines starting with these strings will be dropped by BigDump 76 77 $comment[] = '#'; // Standard comment lines are dropped by default 78 $comment[] = '-- '; 79 // $comment[]='---'; // Uncomment this line if using proprietary dump created by outdated mysqldump 80 // $comment[]='/*!'; // Or add your own string to leave out other proprietary things 81 82 // Connection character set should be the same as the dump file character set (utf8, latin1, cp1251, koi8r etc.) 83 // See http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html for the full list 84 85 $db_connection_charset = ''; 86 87 // ******************************************************************************************* 88 // If not familiar with PHP please don't change anything below this line 89 // ******************************************************************************************* 90 91 ob_start(); 92 93 define('VERSION', '0.28b'); 94 define('DATA_CHUNK_LENGTH', 16384); // How many chars are read per time 95 define('MAX_QUERY_LINES', 300); // How many lines may be considered to be one query (except text lines) 96 define('TESTMODE', false); // Set to true to process the file without actually accessing the database 97 98 header("Expires: Mon, 1 Dec 2003 01:00:00 GMT"); 99 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 100 header("Cache-Control: no-store, no-cache, must-revalidate"); 101 header("Cache-Control: post-check=0, pre-check=0", false); 102 header("Pragma: no-cache"); 103 104 //@ini_set('auto_detect_line_endings', true); 105 //@set_time_limit(0); 106 107 // Clean and strip anything we don't want from user's input [0.27b] 108 foreach ($_REQUEST as $key => $val) { 109 $val = preg_replace("/[^_A-Za-z0-9-\.&=]/i", '', $val); 110 $_REQUEST[$key] = $val; 111 } 112 113 // Determine filename to execute for loading... 114 $filename = JPATH_BASE . DS . 'sql' . DS . 'migration' . DS . 'migrate.sql'; 115 $_REQUEST['fn'] = $filename; 116 $error = false; 117 $file = false; 118 // Single file mode 119 120 if (!$error && !isset ($_REQUEST["fn"]) && $filename != "") { 121 echo ("<p><a href=\"" . str_replace(array('"', '<', '>', "'"), '', $_SERVER["PHP_SELF"]) . "?start=1&fn=$filename&foffset=0&totalqueries=0\">Start Import</a> from $filename into $db_name at $db_server</p>\n"); 122 } 123 124 // Open the file 125 126 if (!$error && isset ($_REQUEST["fn"])) { 127 128 // Recognize GZip filename 129 130 if (preg_match("#\.gz$#i", $_REQUEST["fn"])) 131 $gzipmode = true; 132 else 133 $gzipmode = false; 134 if ((!$gzipmode && !$file = fopen($_REQUEST["fn"], "rt")) || ($gzipmode && !$file = gzopen($_REQUEST["fn"], "rt"))) { 135 echo ("<p class=\"error\">". JText::sprintf("Cant open file for import", $_REQUEST["fn"]) ."</p>\n"); 136 echo ("<p>". JText::_('CHECKDUMPFILE') . 137 " .<br />". JText::_('NEEDTOUPLOADFILE')."</p>\n"); 138 $error = true; 139 } 140 141 // Get the file size (can't do it fast on gzipped files, no idea how) 142 143 else 144 if ((!$gzipmode && fseek($file, 0, SEEK_END) == 0) || ($gzipmode && gzseek($file, 0) == 0)) { 145 if (!$gzipmode) 146 $filesize = ftell($file); 147 else 148 $filesize = gztell($file); // Always zero, ignore 149 } else { 150 echo ("<p class=\"error\">". JText::_('FILESIZEUNKNOWN') . $_REQUEST["fn"] . "</p>\n"); 151 $error = true; 152 } 153 } 154 155 // ******************************************************************************************* 156 // START IMPORT SESSION HERE 157 // ******************************************************************************************* 158 if (!$error && isset ($_REQUEST["start"]) && isset ($_REQUEST["foffset"]) && preg_match("#(\.(sql|gz|csv))$#i", $_REQUEST["fn"])) { 159 160 // Check start and foffset are numeric values 161 162 if (!is_numeric($_REQUEST["start"]) || !is_numeric($_REQUEST["foffset"])) { 163 echo ("<p class=\"error\">". JText::_('NONNUMERICOFFSET') ."</p>\n"); 164 $error = true; 165 } 166 167 if (!$error) { 168 $_REQUEST["start"] = floor($_REQUEST["start"]); 169 $_REQUEST["foffset"] = floor($_REQUEST["foffset"]); 170 } 171 172 // Check $_REQUEST["foffset"] upon $filesize (can't do it on gzipped files) 173 174 if (!$error && !$gzipmode && $_REQUEST["foffset"] > $filesize) { 175 echo ("<p class=\"error\">".JText::_('POINTEREOF')."</p>\n"); 176 $error = true; 177 } 178 179 // Set file pointer to $_REQUEST["foffset"] 180 181 if (!$error && ((!$gzipmode && fseek($file, $_REQUEST["foffset"]) != 0) || ($gzipmode && gzseek($file, $_REQUEST["foffset"]) != 0))) { 182 echo ("<p class=\"error\">". JText::_('UNABLETOSETOFFSET') . $_REQUEST["foffset"] . "</p>\n"); 183 $error = true; 184 } 185 186 // Start processing queries from $file 187 188 if (!$error) { 189 $query = ""; 190 $queries = 0; 191 $totalqueries = $_REQUEST["totalqueries"]; 192 $linenumber = $_REQUEST["start"]; 193 $querylines = 0; 194 $inparents = false; 195 196 // Stay processing as long as the $linespersession is not reached or the query is still incomplete 197 198 while ($linenumber < $_REQUEST["start"] + $linespersession || $query != "") { 199 200 // Read the whole next line 201 202 $dumpline = ""; 203 while (!feof($file) && substr($dumpline, -1) != "\n") { 204 if (!$gzipmode) 205 $dumpline .= fgets($file, DATA_CHUNK_LENGTH); 206 else 207 $dumpline .= gzgets($file, DATA_CHUNK_LENGTH); 208 } 209 if ($dumpline === "") 210 break; 211 212 // Handle DOS and Mac encoded linebreaks (I don't know if it will work on Win32 or Mac Servers) 213 214 $dumpline = str_replace("\r\n", "\n", $dumpline); 215 $dumpline = str_replace("\r", "\n", $dumpline); 216 217 // DIAGNOSTIC 218 // echo ("<p>Line $linenumber: $dumpline</p>\n"); 219 220 // Skip comments and blank lines only if NOT in parents 221 222 if (!$inparents) { 223 $skipline = false; 224 reset($comment); 225 foreach ($comment as $comment_value) { 226 if (!$inparents && (trim($dumpline) == "" || strpos($dumpline, $comment_value) === 0)) { 227 $skipline = true; 228 break; 229 } 230 } 231 if ($skipline) { 232 $linenumber++; 233 continue; 234 } 235 } 236 237 // Remove double back-slashes from the dumpline prior to count the quotes ('\\' can only be within strings) 238 239 $dumpline_deslashed = str_replace("\\\\", "", $dumpline); 240 241 // Count ' and \' in the dumpline to avoid query break within a text field ending by ; 242 // Please don't use double quotes ('"')to surround strings, it wont work 243 244 $parents = substr_count($dumpline_deslashed, "'") - substr_count($dumpline_deslashed, "\\'"); 245 if ($parents % 2 != 0) 246 $inparents = !$inparents; 247 248 // Add the line to query 249 250 $query .= $dumpline; 251 252 // Don't count the line if in parents (text fields may include unlimited linebreaks) 253 254 if (!$inparents) 255 $querylines++; 256 257 // Stop if query contains more lines as defined by MAX_QUERY_LINES 258 259 if ($querylines > MAX_QUERY_LINES) { 260 echo ("<p class=\"error\">". JText::_('STOPPEDATLINE') ." $linenumber. </p>"); 261 echo ("<p>". JText::sprintf('TOOMANYLINES',MAX_QUERY_LINES)."</p>"); 262 $error = true; 263 break; 264 } 265 $vars = $this->getVars(); 266 $DBtype = JArrayHelper::getValue($vars, 'DBtype', 'mysql'); 267 $DBhostname = JArrayHelper::getValue($vars, 'DBhostname', ''); 268 $DBuserName = JArrayHelper::getValue($vars, 'DBuserName', ''); 269 $DBpassword = JArrayHelper::getValue($vars, 'DBpassword', ''); 270 $DBname = JArrayHelper::getValue($vars, 'DBname', ''); 271 $DBPrefix = JArrayHelper::getValue($vars, 'DBPrefix', 'jos_'); 272 $DBOld = JArrayHelper::getValue($vars, 'DBOld', 'bu'); 273 //$migration = JArrayHelper::getValue($vars, 'migration', '0'); 274 $migration = JRequest::getVar( 'migration', 0, 'post', 'bool' ); 275 276 $db = & JInstallationHelper::getDBO($DBtype, $DBhostname, $DBuserName, $DBpassword, $DBname, $DBPrefix); 277 if(JError::isError($db)) jexit(JText::_('CONNECTION FAIL')); 278 279 // echo 'Done.<br />'; 280 // Execute query if end of query detected (; as last character) AND NOT in parents 281 282 if (ereg(";$", trim($dumpline)) && !$inparents) { 283 if (!TESTMODE) { 284 $db->setQuery(trim($query)); 285 // echo $query . '<br />'; 286 if (!$db->Query()) { 287 echo ("<p class=\"error\">".JText::_('Error at the line') ." $linenumber: ". trim($dumpline) . "</p>\n"); 288 echo ("<p>".JText::_('Query:') . trim(nl2br(htmlentities($query))) ."</p>\n"); 289 echo ("<p>MySQL: " . mysql_error() . "</p>\n"); 290 $error = true; 291 break; 292 } 293 $totalqueries++; 294 $queries++; 295 $query = ""; 296 $querylines = 0; 297 } 298 } 299 $linenumber++; 300 } 301 } 302 303 // Get the current file position 304 305 if (!$error) { 306 if (!$gzipmode) 307 $foffset = ftell($file); 308 else 309 $foffset = gztell($file); 310 if (!$foffset) { 311 echo ("<p class=\"error\">".JText::_('CANTREADPOINTER')."</p>\n"); 312 $error = true; 313 } 314 } 315 316 // Print statistics 317 318 // echo ("<p class=\"centr\"><b>Statistics</b></p>\n"); 319 320 if (!$error) { 321 $lines_this = $linenumber - $_REQUEST["start"]; 322 $lines_done = $linenumber -1; 323 $lines_togo = ' ? '; 324 $lines_tota = ' ? '; 325 326 $queries_this = $queries; 327 $queries_done = $totalqueries; 328 $queries_togo = ' ? '; 329 $queries_tota = ' ? '; 330 331 $bytes_this = $foffset - $_REQUEST["foffset"]; 332 $bytes_done = $foffset; 333 $kbytes_this = round($bytes_this / 1024, 2); 334 $kbytes_done = round($bytes_done / 1024, 2); 335 $mbytes_this = round($kbytes_this / 1024, 2); 336 $mbytes_done = round($kbytes_done / 1024, 2); 337 338 if (!$gzipmode) { 339 $bytes_togo = $filesize - $foffset; 340 $bytes_tota = $filesize; 341 $kbytes_togo = round($bytes_togo / 1024, 2); 342 $kbytes_tota = round($bytes_tota / 1024, 2); 343 $mbytes_togo = round($kbytes_togo / 1024, 2); 344 $mbytes_tota = round($kbytes_tota / 1024, 2); 345 346 $pct_this = ceil($bytes_this / $filesize * 100); 347 $pct_done = ceil($foffset / $filesize * 100); 348 $pct_togo = 100 - $pct_done; 349 $pct_tota = 100; 350 351 if ($bytes_togo == 0) { 352 $lines_togo = '0'; 353 $lines_tota = $linenumber -1; 354 $queries_togo = '0'; 355 $queries_tota = $totalqueries; 356 } 357 358 $pct_bar = "<div style=\"height:15px;width:$pct_done%;background-color:#000080;margin:0px;\"></div>"; 359 } else { 360 $bytes_togo = ' ? '; 361 $bytes_tota = ' ? '; 362 $kbytes_togo = ' ? '; 363 $kbytes_tota = ' ? '; 364 $mbytes_togo = ' ? '; 365 $mbytes_tota = ' ? '; 366 367 $pct_this = ' ? '; 368 $pct_done = ' ? '; 369 $pct_togo = ' ? '; 370 $pct_tota = 100; 371 $pct_bar = str_replace(' ', ' ', '<tt>[ Not available for gzipped files ]</tt>'); 372 } 373 /* 374 echo (" 375 <center> 376 <table width=\"520\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\"> 377 <tr><th class=\"bg4\"> </th><th class=\"bg4\">Session</th><th class=\"bg4\">Done</th><th class=\"bg4\">To go</th><th class=\"bg4\">Total</th></tr> 378 <tr><th class=\"bg4\">Lines</th><td class=\"bg3\">$lines_this</td><td class=\"bg3\">$lines_done</td><td class=\"bg3\">$lines_togo</td><td class=\"bg3\">$lines_tota</td></tr> 379 <tr><th class=\"bg4\">Queries</th><td class=\"bg3\">$queries_this</td><td class=\"bg3\">$queries_done</td><td class=\"bg3\">$queries_togo</td><td class=\"bg3\">$queries_tota</td></tr> 380 <tr><th class=\"bg4\">Bytes</th><td class=\"bg3\">$bytes_this</td><td class=\"bg3\">$bytes_done</td><td class=\"bg3\">$bytes_togo</td><td class=\"bg3\">$bytes_tota</td></tr> 381 <tr><th class=\"bg4\">KB</th><td class=\"bg3\">$kbytes_this</td><td class=\"bg3\">$kbytes_done</td><td class=\"bg3\">$kbytes_togo</td><td class=\"bg3\">$kbytes_tota</td></tr> 382 <tr><th class=\"bg4\">MB</th><td class=\"bg3\">$mbytes_this</td><td class=\"bg3\">$mbytes_done</td><td class=\"bg3\">$mbytes_togo</td><td class=\"bg3\">$mbytes_tota</td></tr> 383 <tr><th class=\"bg4\">%</th><td class=\"bg3\">$pct_this</td><td class=\"bg3\">$pct_done</td><td class=\"bg3\">$pct_togo</td><td class=\"bg3\">$pct_tota</td></tr> 384 <tr><th class=\"bg4\">% bar</th><td class=\"bgpctbar\" colspan=\"4\">$pct_bar</td></tr> 385 </table> 386 </center> 387 \n");*/ 388 389 // Finish message and restart the script 390 391 if ($linenumber < $_REQUEST["start"] + $linespersession) { 392 echo ("<div id=\"installer\"><p class=\"successcentr\">".JText::_('CONGRATSEOF')."</p>\n"); 393 // Do migration 394 if($migration) { 395 ?><br />Migration will continue shortly...</div> 396 <form action="index.php" method="post" name="migrateForm" id="migrateForm" class="form-validate" target="migrationtarget"> 397 <input type="hidden" name="task" value="postmigrate" /> 398 <input type="hidden" name="migration" value="<?php echo $migration ?>" /> 399 <input type="hidden" name="loadchecked" value="1" /> 400 <input type="hidden" name="dataLoaded" value="1" /> 401 <input type="hidden" name="DBtype" value="<?php echo $DBtype ?>" /> 402 <input type="hidden" name="DBhostname" value="<?php echo $DBhostname ?>" /> 403 <input type="hidden" name="DBuserName" value="<?php echo $DBuserName ?>" /> 404 <input type="hidden" name="DBpassword" value="<?php echo $DBpassword ?>" /> 405 <input type="hidden" name="DBname" value="<?php echo $DBname ?>" /> 406 <input type="hidden" name="DBPrefix" value="<?php echo $DBPrefix ?>" /> 407 </form> 408 <script language="JavaScript" type="text/javascript">window.setTimeout('submitForm(this.document.migrateForm,"postmigrate")',500);</script> 409 <?php 410 } else echo '<br />'. JText::_('FINALIZEINSTALL').'</div>'; 411 //echo ("<p class=\"centr\">Thank you for using this tool! Please rate <a href=\"http://www.hotscripts.com/Detailed/20922.html\" target=\"_blank\">Bigdump at Hotscripts.com</a></p>\n"); 412 //echo ("<p class=\"centr\">You can send me some bucks or euros as appreciation <a href=\"http://www.ozerov.de/bigdump.php\" target=\"_blank\">via PayPal</a></p>\n"); 413 $error = true; 414 } else { 415 if ($delaypersession != 0) 416 echo ("<p class=\"centr\">".JText::sprintf('DELAYMSG',$delaypersession)."</p>\n"); 417 ?><script language="JavaScript" type="text/javascript">window.setTimeout('submitForm(this.document.migrateForm,"dumpLoad")',500);</script> 418 <div id="installer"><p><?php echo JText::_('LOADSQLFILE') ?></p></div> 419 420 <form action="index.php" method="post" name="migrateForm" id="migrateForm" class="form-validate" target="migrationtarget"> 421 <input type="hidden" name="task" value="dumpLoad" /> 422 <input type="hidden" name="migration" value="<?php echo $migration ?>" /> 423 <input type="hidden" name="loadchecked" value="1" /> 424 <input type="hidden" name="dataLoaded" value="1" /> 425 <input type="hidden" name="DBtype" value="<?php echo $DBtype ?>" /> 426 <input type="hidden" name="DBhostname" value="<?php echo $DBhostname ?>" /> 427 <input type="hidden" name="DBuserName" value="<?php echo $DBuserName ?>" /> 428 <input type="hidden" name="DBpassword" value="<?php echo $DBpassword ?>" /> 429 <input type="hidden" name="DBname" value="<?php echo $DBname ?>" /> 430 <input type="hidden" name="DBPrefix" value="<?php echo $DBPrefix ?>" /> 431 <input type="hidden" name="start" value="<?php echo $linenumber ?>" /> 432 <input type="hidden" name="foffset" value="<?php echo $foffset ?>" /> 433 <input type="hidden" name="totalqueries" value="<?php echo $totalqueries ?>" /> 434 </form> 435 <?php 436 } 437 } else 438 echo ("<p class=\"error\">".JText::_('STOPPEDONERROR')."</p>\n"); 439 440 } 441 442 //if ($dbconnection) mysql_close(); 443 if ($file && !$gzipmode) 444 fclose($file); 445 else 446 if ($file && $gzipmode) 447 gzclose($file); 448 449 //ob_flush(); 450 //die(); 451
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |