wordmove 0.0.8 → 0.1.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/wordmove +2 -0
- data/lib/wordmove/assets/dump.php.erb +182 -0
- data/lib/wordmove/assets/import.php.erb +1076 -0
- data/lib/wordmove/cli.rb +27 -18
- data/lib/wordmove/deployer/base.rb +135 -0
- data/lib/wordmove/deployer/ftp.rb +117 -0
- data/lib/wordmove/deployer/ssh.rb +73 -0
- data/lib/wordmove/logger.rb +14 -22
- data/lib/wordmove/version.rb +1 -1
- data/wordmove.gemspec +4 -7
- metadata +13 -57
- data/lib/wordmove/deployer.rb +0 -149
data/bin/wordmove
CHANGED
@@ -0,0 +1,182 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
/**
|
4
|
+
* MySQL database dump.
|
5
|
+
*
|
6
|
+
* @author David Grudl
|
7
|
+
* @copyright Copyright (c) 2008 David Grudl
|
8
|
+
* @license New BSD License
|
9
|
+
* @link http://phpfashion.com/
|
10
|
+
* @version 0.9
|
11
|
+
*/
|
12
|
+
|
13
|
+
class MySQLDump
|
14
|
+
{
|
15
|
+
const MAX_SQL_SIZE = 1e6;
|
16
|
+
|
17
|
+
/** @var mysqli */
|
18
|
+
private $connection;
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Connects to database.
|
22
|
+
* @param mysqli connection
|
23
|
+
*/
|
24
|
+
public function __construct(mysqli $connection)
|
25
|
+
{
|
26
|
+
$this->connection = $connection;
|
27
|
+
|
28
|
+
if ($this->connection->connect_errno) {
|
29
|
+
throw new Exception($this->connection->connect_error);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Sends dump to browser.
|
35
|
+
* @param string filename
|
36
|
+
* @return void
|
37
|
+
*/
|
38
|
+
public function send($file)
|
39
|
+
{
|
40
|
+
$this->write(fopen('php://output', 'wb'));
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Writes dump to logical file.
|
45
|
+
* @param resource
|
46
|
+
* @return void
|
47
|
+
*/
|
48
|
+
public function write($handle)
|
49
|
+
{
|
50
|
+
if (!is_resource($handle) || get_resource_type($handle) !== 'stream') {
|
51
|
+
throw new Exception('Argument must be stream resource.');
|
52
|
+
}
|
53
|
+
|
54
|
+
if (!$this->connection->set_charset('utf8')) { // was added in MySQL 5.0.7 and PHP 5.0.5, fixed in PHP 5.1.5)
|
55
|
+
throw new Exception($this->connection->error);
|
56
|
+
}
|
57
|
+
|
58
|
+
$views = $tables = array();
|
59
|
+
|
60
|
+
$res = $this->connection->query('SHOW TABLES');
|
61
|
+
while ($row = $res->fetch_row()) {
|
62
|
+
$tables[] = $row[0];
|
63
|
+
}
|
64
|
+
$res->close();
|
65
|
+
|
66
|
+
$db = $this->connection->query('SELECT DATABASE()')->fetch_row();
|
67
|
+
fwrite($handle, "-- David Grudl MySQL Dump Utility\n"
|
68
|
+
. "-- Created at " . date('j.n.Y G:i') . "\n"
|
69
|
+
. (isset($_SERVER['HTTP_HOST']) ? "-- Host: $_SERVER[HTTP_HOST]\n" : '')
|
70
|
+
. "-- Server: " . $this->connection->server_info . "\n"
|
71
|
+
. "-- Codepage: " . $this->connection->character_set_name() . "\n"
|
72
|
+
. "-- Database: " . $db[0] . "\n"
|
73
|
+
. "-- Tables: " . implode(', ', $tables) . "\n"
|
74
|
+
. "\n"
|
75
|
+
. "SET NAMES utf8;\n"
|
76
|
+
. "SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO';\n"
|
77
|
+
. "SET FOREIGN_KEY_CHECKS=0;\n");
|
78
|
+
|
79
|
+
foreach ($tables as $table)
|
80
|
+
{
|
81
|
+
$res = $this->connection->query("SHOW CREATE TABLE `$table`");
|
82
|
+
$row = $res->fetch_assoc();
|
83
|
+
$res->close();
|
84
|
+
|
85
|
+
if (isset($row['Create View'])) {
|
86
|
+
$views[$table] = $row['Create View'];
|
87
|
+
continue;
|
88
|
+
}
|
89
|
+
|
90
|
+
fwrite($handle, "-- --------------------------------------------------------\n\n");
|
91
|
+
fwrite($handle, "DROP TABLE IF EXISTS `$table`;\n\n");
|
92
|
+
fwrite($handle, $row['Create Table'] . ";\n\n");
|
93
|
+
|
94
|
+
$numeric = array();
|
95
|
+
$res = $this->connection->query("SHOW COLUMNS FROM `$table`");
|
96
|
+
$cols = array();
|
97
|
+
while ($row = $res->fetch_assoc()) {
|
98
|
+
$col = $row['Field'];
|
99
|
+
$cols[] = '`' . str_replace('`', '``', $col) . '`';
|
100
|
+
preg_match('/^([a-z]+)/', $row['Type'], $matches);
|
101
|
+
$type = strtolower($matches[1]);
|
102
|
+
$numeric[$col] = in_array($type, array('byte','counter','serial','int','long','currency','real','money','float','double','decimal','numeric','number'));
|
103
|
+
}
|
104
|
+
$cols = '(' . implode(', ', $cols) . ')';
|
105
|
+
$res->close();
|
106
|
+
|
107
|
+
|
108
|
+
$size = 0;
|
109
|
+
$res = $this->connection->query("SELECT * FROM `$table`", MYSQLI_USE_RESULT);
|
110
|
+
while ($row = $res->fetch_assoc()) {
|
111
|
+
$s = '(';
|
112
|
+
foreach ($row as $key => $value) {
|
113
|
+
if ($value === NULL) {
|
114
|
+
$s .= "NULL,\t";
|
115
|
+
} elseif ($numeric[$key]) {
|
116
|
+
$s .= $value . ",\t";
|
117
|
+
} else {
|
118
|
+
$s .= "'" . $this->connection->real_escape_string($value) . "',\t";
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
if ($size == 0) {
|
123
|
+
$s = "INSERT INTO `$table` $cols VALUES\n$s";
|
124
|
+
} else {
|
125
|
+
$s = ",\n$s";
|
126
|
+
}
|
127
|
+
|
128
|
+
$len = strlen($s) - 1;
|
129
|
+
$s[$len - 1] = ')';
|
130
|
+
fwrite($handle, $s, $len);
|
131
|
+
|
132
|
+
$size += $len;
|
133
|
+
if ($size > self::MAX_SQL_SIZE) {
|
134
|
+
fwrite($handle, ";\n");
|
135
|
+
$size = 0;
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
if ($size) fwrite($handle, ";\n");
|
140
|
+
$res->close();
|
141
|
+
|
142
|
+
fwrite($handle, "\n\n");
|
143
|
+
}
|
144
|
+
|
145
|
+
foreach ($views as $view => $sql)
|
146
|
+
{
|
147
|
+
fwrite($handle, "-- --------------------------------------------------------\n\n");
|
148
|
+
fwrite($handle, "DROP VIEW IF EXISTS `$view`;\n\n$sql;\n\n");
|
149
|
+
}
|
150
|
+
|
151
|
+
fwrite($handle, "-- THE END\n");
|
152
|
+
fclose($handle);
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
function get_connection($db_host, $db_username, $db_password, $db_name, $error = NULL) {
|
157
|
+
$db_connection = new mysqli($db_host, $db_username, $db_password);
|
158
|
+
if (!$db_connection || !$db_connection->select_db($db_name)) {
|
159
|
+
if ($db_connection) {
|
160
|
+
$error = mysqli_connect_error();
|
161
|
+
} else {
|
162
|
+
$error = "Unable to connect to mysql database";
|
163
|
+
}
|
164
|
+
return NULL;
|
165
|
+
}
|
166
|
+
return $db_connection;
|
167
|
+
}
|
168
|
+
|
169
|
+
$db_host = '<%= escape_php db[:host] %>';
|
170
|
+
$db_username = '<%= escape_php db[:user] %>';
|
171
|
+
$db_password = '<%= escape_php db[:password] %>';
|
172
|
+
$db_name = '<%= escape_php_literal db[:name] %>';
|
173
|
+
$shared_key = '<%= password %>';
|
174
|
+
|
175
|
+
$mysql_error = '';
|
176
|
+
|
177
|
+
if ($_GET['shared_key'] == $shared_key) {
|
178
|
+
$connection = get_connection($db_host, $db_username, $db_password, $db_name, &$mysql_error);
|
179
|
+
$dump = new MySQLDump($connection);
|
180
|
+
$dump->send('dump.mysql');
|
181
|
+
}
|
182
|
+
|
@@ -0,0 +1,1076 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
$shared_key = '<%= password %>';
|
4
|
+
if ($_GET['shared_key'] != $shared_key) {
|
5
|
+
die();
|
6
|
+
}
|
7
|
+
|
8
|
+
// BigDump ver. 0.34b from 2011-09-04
|
9
|
+
|
10
|
+
// Database configuration
|
11
|
+
|
12
|
+
$db_server = '<%= escape_php db[:host] %>';
|
13
|
+
$db_username = '<%= escape_php db[:user] %>';
|
14
|
+
$db_password = '<%= escape_php db[:password] %>';
|
15
|
+
$db_name = '<%= escape_php db[:name] %>';
|
16
|
+
|
17
|
+
// Other settings (optional)
|
18
|
+
|
19
|
+
$filename = ''; // Specify the dump filename to suppress the file selection dialog
|
20
|
+
$ajax = true; // AJAX mode: import will be done without refreshing the website
|
21
|
+
$linespersession = 3000; // Lines to be executed per one import session
|
22
|
+
$delaypersession = 0; // You can specify a sleep time in milliseconds after each session
|
23
|
+
// Works only if JavaScript is activated. Use to reduce server overrun
|
24
|
+
|
25
|
+
// CSV related settings (only if you use a CSV dump)
|
26
|
+
|
27
|
+
$csv_insert_table = ''; // Destination table for CSV files
|
28
|
+
$csv_preempty_table = false; // true: delete all entries from table specified in $csv_insert_table before processing
|
29
|
+
$csv_delimiter = ','; // Field delimiter in CSV file
|
30
|
+
$csv_add_quotes = true; // If your CSV data already have quotes around each field set it to false
|
31
|
+
$csv_add_slashes = true; // If your CSV data already have slashes in front of ' and " set it to false
|
32
|
+
|
33
|
+
// Allowed comment markers: lines starting with these strings will be ignored by BigDump
|
34
|
+
|
35
|
+
$comment[]='#'; // Standard comment lines are dropped by default
|
36
|
+
$comment[]='-- ';
|
37
|
+
$comment[]='DELIMITER'; // Ignore DELIMITER switch as it's not a valid SQL statement
|
38
|
+
// $comment[]='---'; // Uncomment this line if using proprietary dump created by outdated mysqldump
|
39
|
+
// $comment[]='CREATE DATABASE'; // Uncomment this line if your dump contains create database queries in order to ignore them
|
40
|
+
$comment[]='/*!'; // Or add your own string to leave out other proprietary things
|
41
|
+
|
42
|
+
// Pre-queries: SQL queries to be executed at the beginning of each import session
|
43
|
+
|
44
|
+
// $pre_query[]='SET foreign_key_checks = 0';
|
45
|
+
// $pre_query[]='Add additional queries if you want here';
|
46
|
+
|
47
|
+
// Connection charset should be the same as the dump file charset (utf8, latin1, cp1251, koi8r etc.)
|
48
|
+
// See http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html for the full list
|
49
|
+
// Change this if you have problems with non-latin letters
|
50
|
+
|
51
|
+
$db_connection_charset = '<%= db[:charset] || utf8';
|
52
|
+
|
53
|
+
// Default query delimiter: this character at the line end tells Bigdump where a SQL statement ends
|
54
|
+
// Can be changed by DELIMITER statement in the dump file (normally used when defining procedures/functions)
|
55
|
+
|
56
|
+
$delimiter = ';';
|
57
|
+
|
58
|
+
// String quotes character
|
59
|
+
|
60
|
+
$string_quotes = '\''; // Change to '"' if your dump file uses double qoutes for strings
|
61
|
+
|
62
|
+
|
63
|
+
// *******************************************************************************************
|
64
|
+
// If not familiar with PHP please don't change anything below this line
|
65
|
+
// *******************************************************************************************
|
66
|
+
|
67
|
+
if ($ajax)
|
68
|
+
ob_start();
|
69
|
+
|
70
|
+
define ('VERSION','0.34b');
|
71
|
+
define ('DATA_CHUNK_LENGTH',16384); // How many chars are read per time
|
72
|
+
define ('MAX_QUERY_LINES',300); // How many lines may be considered to be one query (except text lines)
|
73
|
+
define ('TESTMODE',false); // Set to true to process the file without actually accessing the database
|
74
|
+
|
75
|
+
header("Expires: Mon, 1 Dec 2003 01:00:00 GMT");
|
76
|
+
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
77
|
+
header("Cache-Control: no-store, no-cache, must-revalidate");
|
78
|
+
header("Cache-Control: post-check=0, pre-check=0", false);
|
79
|
+
header("Pragma: no-cache");
|
80
|
+
|
81
|
+
@ini_set('auto_detect_line_endings', true);
|
82
|
+
@set_time_limit(0);
|
83
|
+
|
84
|
+
if (function_exists("date_default_timezone_set") && function_exists("date_default_timezone_get"))
|
85
|
+
@date_default_timezone_set(@date_default_timezone_get());
|
86
|
+
|
87
|
+
// Clean and strip anything we don't want from user's input [0.27b]
|
88
|
+
|
89
|
+
foreach ($_REQUEST as $key => $val)
|
90
|
+
{
|
91
|
+
$val = preg_replace("/[^_A-Za-z0-9-\.&= ;\$]/i",'', $val);
|
92
|
+
$_REQUEST[$key] = $val;
|
93
|
+
}
|
94
|
+
|
95
|
+
?>
|
96
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
97
|
+
<html>
|
98
|
+
<head>
|
99
|
+
<title>BigDump ver. <?php echo (VERSION); ?></title>
|
100
|
+
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=iso-8859-1"/>
|
101
|
+
<meta http-equiv="CONTENT-LANGUAGE" content="EN"/>
|
102
|
+
|
103
|
+
<meta http-equiv="Cache-Control" content="no-cache/"/>
|
104
|
+
<meta http-equiv="Pragma" content="no-cache"/>
|
105
|
+
<meta http-equiv="Expires" content="-1"/>
|
106
|
+
<meta name="robots" content="noindex, nofollow">
|
107
|
+
|
108
|
+
<style type="text/css">
|
109
|
+
<!--
|
110
|
+
|
111
|
+
body
|
112
|
+
{ background-color:#FFFFF0;
|
113
|
+
}
|
114
|
+
|
115
|
+
h1
|
116
|
+
{ font-size:20px;
|
117
|
+
line-height:24px;
|
118
|
+
font-family:Arial,Helvetica,sans-serif;
|
119
|
+
margin-top:5px;
|
120
|
+
margin-bottom:5px;
|
121
|
+
}
|
122
|
+
|
123
|
+
p,td,th
|
124
|
+
{ font-size:14px;
|
125
|
+
line-height:18px;
|
126
|
+
font-family:Arial,Helvetica,sans-serif;
|
127
|
+
margin-top:5px;
|
128
|
+
margin-bottom:5px;
|
129
|
+
text-align:justify;
|
130
|
+
vertical-align:top;
|
131
|
+
}
|
132
|
+
|
133
|
+
p.centr
|
134
|
+
{
|
135
|
+
text-align:center;
|
136
|
+
}
|
137
|
+
|
138
|
+
p.smlcentr
|
139
|
+
{ font-size:10px;
|
140
|
+
line-height:14px;
|
141
|
+
text-align:center;
|
142
|
+
}
|
143
|
+
|
144
|
+
p.error
|
145
|
+
{ color:#FF0000;
|
146
|
+
font-weight:bold;
|
147
|
+
}
|
148
|
+
|
149
|
+
p.success
|
150
|
+
{ color:#00DD00;
|
151
|
+
font-weight:bold;
|
152
|
+
}
|
153
|
+
|
154
|
+
p.successcentr
|
155
|
+
{ color:#00DD00;
|
156
|
+
background-color:#DDDDFF;
|
157
|
+
font-weight:bold;
|
158
|
+
text-align:center;
|
159
|
+
}
|
160
|
+
|
161
|
+
td
|
162
|
+
{ background-color:#F8F8F8;
|
163
|
+
text-align:left;
|
164
|
+
}
|
165
|
+
|
166
|
+
td.transparent
|
167
|
+
{ background-color:#FFFFF0;
|
168
|
+
}
|
169
|
+
|
170
|
+
th
|
171
|
+
{ font-weight:bold;
|
172
|
+
color:#FFFFFF;
|
173
|
+
background-color:#AAAAEE;
|
174
|
+
text-align:left;
|
175
|
+
}
|
176
|
+
|
177
|
+
td.right
|
178
|
+
{ text-align:right;
|
179
|
+
}
|
180
|
+
|
181
|
+
form
|
182
|
+
{ margin-top:5px;
|
183
|
+
margin-bottom:5px;
|
184
|
+
}
|
185
|
+
|
186
|
+
div.skin1
|
187
|
+
{
|
188
|
+
border-color:#3333EE;
|
189
|
+
border-width:5px;
|
190
|
+
border-style:solid;
|
191
|
+
background-color:#AAAAEE;
|
192
|
+
text-align:center;
|
193
|
+
vertical-align:middle;
|
194
|
+
padding:3px;
|
195
|
+
margin:1px;
|
196
|
+
}
|
197
|
+
|
198
|
+
td.bg3
|
199
|
+
{ background-color:#EEEE99;
|
200
|
+
text-align:left;
|
201
|
+
vertical-align:top;
|
202
|
+
width:20%;
|
203
|
+
}
|
204
|
+
|
205
|
+
th.bg4
|
206
|
+
{ background-color:#EEAA55;
|
207
|
+
text-align:left;
|
208
|
+
vertical-align:top;
|
209
|
+
width:20%;
|
210
|
+
}
|
211
|
+
|
212
|
+
td.bgpctbar
|
213
|
+
{ background-color:#EEEEAA;
|
214
|
+
text-align:left;
|
215
|
+
vertical-align:middle;
|
216
|
+
width:80%;
|
217
|
+
}
|
218
|
+
|
219
|
+
-->
|
220
|
+
</style>
|
221
|
+
|
222
|
+
</head>
|
223
|
+
|
224
|
+
<body>
|
225
|
+
|
226
|
+
<center>
|
227
|
+
|
228
|
+
<table width="780" cellspacing="0" cellpadding="0">
|
229
|
+
<tr><td class="transparent">
|
230
|
+
|
231
|
+
<!-- <h1>BigDump: Staggered MySQL Dump Importer ver. <?php echo (VERSION); ?></h1> -->
|
232
|
+
|
233
|
+
<?php
|
234
|
+
|
235
|
+
function skin_open() {
|
236
|
+
echo ('<div class="skin1">');
|
237
|
+
}
|
238
|
+
|
239
|
+
function skin_close() {
|
240
|
+
echo ('</div>');
|
241
|
+
}
|
242
|
+
|
243
|
+
skin_open();
|
244
|
+
echo ('<h1>BigDump: Staggered MySQL Dump Importer v'.VERSION.'</h1>');
|
245
|
+
skin_close();
|
246
|
+
|
247
|
+
$error = false;
|
248
|
+
$file = false;
|
249
|
+
|
250
|
+
// Check PHP version
|
251
|
+
|
252
|
+
if (!$error && !function_exists('version_compare'))
|
253
|
+
{ echo ("<p class=\"error\">PHP version 4.1.0 is required for BigDump to proceed. You have PHP ".phpversion()." installed. Sorry!</p>\n");
|
254
|
+
$error=true;
|
255
|
+
}
|
256
|
+
|
257
|
+
// Check if mysql extension is available
|
258
|
+
|
259
|
+
if (!$error && !function_exists('mysql_connect'))
|
260
|
+
{ echo ("<p class=\"error\">There is no mySQL extension available in your PHP installation. Sorry!</p>\n");
|
261
|
+
$error=true;
|
262
|
+
}
|
263
|
+
|
264
|
+
// Calculate PHP max upload size (handle settings like 10M or 100K)
|
265
|
+
|
266
|
+
if (!$error)
|
267
|
+
{ $upload_max_filesize=ini_get("upload_max_filesize");
|
268
|
+
if (preg_match("/([0-9]+)K/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024;
|
269
|
+
if (preg_match("/([0-9]+)M/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024;
|
270
|
+
if (preg_match("/([0-9]+)G/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024*1024;
|
271
|
+
}
|
272
|
+
|
273
|
+
// Get the current directory
|
274
|
+
|
275
|
+
if (isset($_SERVER["CGIA"]))
|
276
|
+
$upload_dir=dirname($_SERVER["CGIA"]);
|
277
|
+
else if (isset($_SERVER["ORIG_PATH_TRANSLATED"]))
|
278
|
+
$upload_dir=dirname($_SERVER["ORIG_PATH_TRANSLATED"]);
|
279
|
+
else if (isset($_SERVER["ORIG_SCRIPT_FILENAME"]))
|
280
|
+
$upload_dir=dirname($_SERVER["ORIG_SCRIPT_FILENAME"]);
|
281
|
+
else if (isset($_SERVER["PATH_TRANSLATED"]))
|
282
|
+
$upload_dir=dirname($_SERVER["PATH_TRANSLATED"]);
|
283
|
+
else
|
284
|
+
$upload_dir=dirname($_SERVER["SCRIPT_FILENAME"]);
|
285
|
+
|
286
|
+
// Handle file upload
|
287
|
+
|
288
|
+
if (!$error && isset($_REQUEST["uploadbutton"]))
|
289
|
+
{ if (is_uploaded_file($_FILES["dumpfile"]["tmp_name"]) && ($_FILES["dumpfile"]["error"])==0)
|
290
|
+
{
|
291
|
+
$uploaded_filename=str_replace(" ","_",$_FILES["dumpfile"]["name"]);
|
292
|
+
$uploaded_filename=preg_replace("/[^_A-Za-z0-9-\.]/i",'',$uploaded_filename);
|
293
|
+
$uploaded_filepath=str_replace("\\","/",$upload_dir."/".$uploaded_filename);
|
294
|
+
|
295
|
+
if (file_exists($uploaded_filename))
|
296
|
+
{ echo ("<p class=\"error\">File $uploaded_filename already exist! Delete and upload again!</p>\n");
|
297
|
+
}
|
298
|
+
else if (!preg_match("/(\.(sql|gz|csv))$/i",$uploaded_filename))
|
299
|
+
{ echo ("<p class=\"error\">You may only upload .sql .gz or .csv files.</p>\n");
|
300
|
+
}
|
301
|
+
else if (!@move_uploaded_file($_FILES["dumpfile"]["tmp_name"],$uploaded_filepath))
|
302
|
+
{ echo ("<p class=\"error\">Error moving uploaded file ".$_FILES["dumpfile"]["tmp_name"]." to the $uploaded_filepath</p>\n");
|
303
|
+
echo ("<p>Check the directory permissions for $upload_dir (must be 777)!</p>\n");
|
304
|
+
}
|
305
|
+
else
|
306
|
+
{ echo ("<p class=\"success\">Uploaded file saved as $uploaded_filename</p>\n");
|
307
|
+
}
|
308
|
+
}
|
309
|
+
else
|
310
|
+
{ echo ("<p class=\"error\">Error uploading file ".$_FILES["dumpfile"]["name"]."</p>\n");
|
311
|
+
}
|
312
|
+
}
|
313
|
+
|
314
|
+
|
315
|
+
// Handle file deletion (delete only in the current directory for security reasons)
|
316
|
+
|
317
|
+
if (!$error && isset($_REQUEST["delete"]) && $_REQUEST["delete"]!=basename($_SERVER["SCRIPT_FILENAME"]))
|
318
|
+
{ if (preg_match("/(\.(sql|gz|csv))$/i",$_REQUEST["delete"]) && @unlink(basename($_REQUEST["delete"])))
|
319
|
+
echo ("<p class=\"success\">".$_REQUEST["delete"]." was removed successfully</p>\n");
|
320
|
+
else
|
321
|
+
echo ("<p class=\"error\">Can't remove ".$_REQUEST["delete"]."</p>\n");
|
322
|
+
}
|
323
|
+
|
324
|
+
// Connect to the database, set charset and execute pre-queries
|
325
|
+
|
326
|
+
if (!$error && !TESTMODE)
|
327
|
+
{ $dbconnection = @mysql_connect($db_server,$db_username,$db_password);
|
328
|
+
if ($dbconnection)
|
329
|
+
$db = mysql_select_db($db_name);
|
330
|
+
if (!$dbconnection || !$db)
|
331
|
+
{ echo ("<p class=\"error\">Database connection failed due to ".mysql_error()."</p>\n");
|
332
|
+
echo ("<p>Edit the database settings in ".$_SERVER["SCRIPT_FILENAME"]." or contact your database provider.</p>\n");
|
333
|
+
$error=true;
|
334
|
+
}
|
335
|
+
if (!$error && $db_connection_charset!=='')
|
336
|
+
@mysql_query("SET NAMES $db_connection_charset", $dbconnection);
|
337
|
+
|
338
|
+
if (!$error && isset ($pre_query) && sizeof ($pre_query)>0)
|
339
|
+
{ reset($pre_query);
|
340
|
+
foreach ($pre_query as $pre_query_value)
|
341
|
+
{ if (!@mysql_query($pre_query_value, $dbconnection))
|
342
|
+
{ echo ("<p class=\"error\">Error with pre-query.</p>\n");
|
343
|
+
echo ("<p>Query: ".trim(nl2br(htmlentities($pre_query_value)))."</p>\n");
|
344
|
+
echo ("<p>MySQL: ".mysql_error()."</p>\n");
|
345
|
+
$error=true;
|
346
|
+
break;
|
347
|
+
}
|
348
|
+
}
|
349
|
+
}
|
350
|
+
}
|
351
|
+
else
|
352
|
+
{ $dbconnection = false;
|
353
|
+
}
|
354
|
+
|
355
|
+
|
356
|
+
// DIAGNOSTIC
|
357
|
+
// echo("<h1>Checkpoint!</h1>");
|
358
|
+
|
359
|
+
// List uploaded files in multifile mode
|
360
|
+
|
361
|
+
if (!$error && !isset($_REQUEST["fn"]) && $filename=="")
|
362
|
+
{ if ($dirhandle = opendir($upload_dir))
|
363
|
+
{
|
364
|
+
$files=array();
|
365
|
+
while (false !== ($files[] = readdir($dirhandle)));
|
366
|
+
closedir($dirhandle);
|
367
|
+
$dirhead=false;
|
368
|
+
|
369
|
+
if (sizeof($files)>0)
|
370
|
+
{
|
371
|
+
sort($files);
|
372
|
+
foreach ($files as $dirfile)
|
373
|
+
{
|
374
|
+
if ($dirfile != "." && $dirfile != ".." && $dirfile!=basename($_SERVER["SCRIPT_FILENAME"]) && preg_match("/\.(sql|gz|csv)$/i",$dirfile))
|
375
|
+
{ if (!$dirhead)
|
376
|
+
{ echo ("<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\">\n");
|
377
|
+
echo ("<tr><th>Filename</th><th>Size</th><th>Date&Time</th><th>Type</th><th> </th><th> </th>\n");
|
378
|
+
$dirhead=true;
|
379
|
+
}
|
380
|
+
echo ("<tr><td>$dirfile</td><td class=\"right\">".filesize($dirfile)."</td><td>".date ("Y-m-d H:i:s", filemtime($dirfile))."</td>");
|
381
|
+
|
382
|
+
if (preg_match("/\.sql$/i",$dirfile))
|
383
|
+
echo ("<td>SQL</td>");
|
384
|
+
elseif (preg_match("/\.gz$/i",$dirfile))
|
385
|
+
echo ("<td>GZip</td>");
|
386
|
+
elseif (preg_match("/\.csv$/i",$dirfile))
|
387
|
+
echo ("<td>CSV</td>");
|
388
|
+
else
|
389
|
+
echo ("<td>Misc</td>");
|
390
|
+
|
391
|
+
if ((preg_match("/\.gz$/i",$dirfile) && function_exists("gzopen")) || preg_match("/\.sql$/i",$dirfile) || preg_match("/\.csv$/i",$dirfile))
|
392
|
+
echo ("<td><a href=\"".$_SERVER["PHP_SELF"]."?start=1&fn=".urlencode($dirfile)."&foffset=0&totalqueries=0&delimiter=".urlencode($delimiter)."\">Start Import</a> into $db_name at $db_server</td>\n <td><a href=\"".$_SERVER["PHP_SELF"]."?delete=".urlencode($dirfile)."\">Delete file</a></td></tr>\n");
|
393
|
+
else
|
394
|
+
echo ("<td> </td>\n <td> </td></tr>\n");
|
395
|
+
}
|
396
|
+
}
|
397
|
+
}
|
398
|
+
|
399
|
+
if ($dirhead)
|
400
|
+
echo ("</table>\n");
|
401
|
+
else
|
402
|
+
echo ("<p>No uploaded SQL, GZ or CSV files found in the working directory</p>\n");
|
403
|
+
}
|
404
|
+
else
|
405
|
+
{ echo ("<p class=\"error\">Error listing directory $upload_dir</p>\n");
|
406
|
+
$error=true;
|
407
|
+
}
|
408
|
+
}
|
409
|
+
|
410
|
+
|
411
|
+
// Single file mode
|
412
|
+
|
413
|
+
if (!$error && !isset ($_REQUEST["fn"]) && $filename!="")
|
414
|
+
{ echo ("<p><a href=\"".$_SERVER["PHP_SELF"]."?start=1&fn=".urlencode($filename)."&foffset=0&totalqueries=0\">Start Import</a> from $filename into $db_name at $db_server</p>\n");
|
415
|
+
}
|
416
|
+
|
417
|
+
|
418
|
+
// File Upload Form
|
419
|
+
|
420
|
+
if (!$error && !isset($_REQUEST["fn"]) && $filename=="")
|
421
|
+
{
|
422
|
+
|
423
|
+
// Test permissions on working directory
|
424
|
+
|
425
|
+
do { $tempfilename=time().".tmp"; } while (file_exists($tempfilename));
|
426
|
+
if (!($tempfile=@fopen($tempfilename,"w")))
|
427
|
+
{ echo ("<p>Upload form disabled. Permissions for the working directory <i>$upload_dir</i> <b>must be set writable for the webserver</b> in order ");
|
428
|
+
echo ("to upload files here. Alternatively you can upload your dump files via FTP.</p>\n");
|
429
|
+
}
|
430
|
+
else
|
431
|
+
{ fclose($tempfile);
|
432
|
+
unlink ($tempfilename);
|
433
|
+
|
434
|
+
echo ("<p>You can now upload your dump file up to $upload_max_filesize bytes (".round ($upload_max_filesize/1024/1024)." Mbytes) ");
|
435
|
+
echo ("directly from your browser to the server. Alternatively you can upload your dump files of any size via FTP.</p>\n");
|
436
|
+
?>
|
437
|
+
<form method="POST" action="<?php echo ($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data">
|
438
|
+
<input type="hidden" name="MAX_FILE_SIZE" value="$upload_max_filesize">
|
439
|
+
<p>Dump file: <input type="file" name="dumpfile" accept="*/*" size=60"></p>
|
440
|
+
<p><input type="submit" name="uploadbutton" value="Upload"></p>
|
441
|
+
</form>
|
442
|
+
<?php
|
443
|
+
}
|
444
|
+
}
|
445
|
+
|
446
|
+
// Print the current mySQL connection charset
|
447
|
+
|
448
|
+
if (!$error && !TESTMODE && !isset($_REQUEST["fn"]))
|
449
|
+
{
|
450
|
+
$result = mysql_query("SHOW VARIABLES LIKE 'character_set_connection';");
|
451
|
+
$row = mysql_fetch_assoc($result);
|
452
|
+
if ($row)
|
453
|
+
{ $charset = $row['Value'];
|
454
|
+
echo ("<p>Note: The current mySQL connection charset is <i>$charset</i>. Your dump file must be encoded in <i>$charset</i> in order to avoid problems with non-latin characters. You can change the connection charset using the \$db_connection_charset variable in bigdump.php</p>\n");
|
455
|
+
}
|
456
|
+
}
|
457
|
+
|
458
|
+
// Open the file
|
459
|
+
|
460
|
+
if (!$error && isset($_REQUEST["start"]))
|
461
|
+
{
|
462
|
+
|
463
|
+
// Set current filename ($filename overrides $_REQUEST["fn"] if set)
|
464
|
+
|
465
|
+
if ($filename!="")
|
466
|
+
$curfilename=$filename;
|
467
|
+
else if (isset($_REQUEST["fn"]))
|
468
|
+
$curfilename=urldecode($_REQUEST["fn"]);
|
469
|
+
else
|
470
|
+
$curfilename="";
|
471
|
+
|
472
|
+
// Recognize GZip filename
|
473
|
+
|
474
|
+
if (preg_match("/\.gz$/i",$curfilename))
|
475
|
+
$gzipmode=true;
|
476
|
+
else
|
477
|
+
$gzipmode=false;
|
478
|
+
|
479
|
+
if ((!$gzipmode && !$file=@fopen($curfilename,"r")) || ($gzipmode && !$file=@gzopen($curfilename,"r")))
|
480
|
+
{ echo ("<p class=\"error\">Can't open ".$curfilename." for import</p>\n");
|
481
|
+
echo ("<p>Please, check that your dump file name contains only alphanumerical characters, and rename it accordingly, for example: $curfilename.".
|
482
|
+
"<br>Or, specify \$filename in bigdump.php with the full filename. ".
|
483
|
+
"<br>Or, you have to upload the $curfilename to the server first.</p>\n");
|
484
|
+
$error=true;
|
485
|
+
}
|
486
|
+
|
487
|
+
// Get the file size (can't do it fast on gzipped files, no idea how)
|
488
|
+
|
489
|
+
else if ((!$gzipmode && @fseek($file, 0, SEEK_END)==0) || ($gzipmode && @gzseek($file, 0)==0))
|
490
|
+
{ if (!$gzipmode) $filesize = ftell($file);
|
491
|
+
else $filesize = gztell($file); // Always zero, ignore
|
492
|
+
}
|
493
|
+
else
|
494
|
+
{ echo ("<p class=\"error\">I can't seek into $curfilename</p>\n");
|
495
|
+
$error=true;
|
496
|
+
}
|
497
|
+
}
|
498
|
+
|
499
|
+
// Stop if csv file is used, but $csv_insert_table is not set
|
500
|
+
|
501
|
+
if (($csv_insert_table == "") && (preg_match("/(\.csv)$/i",$curfilename)))
|
502
|
+
{ echo ("<p class=\"error\">You have to specify \$csv_insert_table when using a CSV file. </p>\n");
|
503
|
+
$error=true;
|
504
|
+
}
|
505
|
+
|
506
|
+
|
507
|
+
// *******************************************************************************************
|
508
|
+
// START IMPORT SESSION HERE
|
509
|
+
// *******************************************************************************************
|
510
|
+
|
511
|
+
if (!$error && isset($_REQUEST["start"]) && isset($_REQUEST["foffset"]) && preg_match("/(\.(sql|gz|csv))$/i",$curfilename))
|
512
|
+
{
|
513
|
+
|
514
|
+
// Check start and foffset are numeric values
|
515
|
+
|
516
|
+
if (!is_numeric($_REQUEST["start"]) || !is_numeric($_REQUEST["foffset"]))
|
517
|
+
{ echo ("<p class=\"error\">UNEXPECTED: Non-numeric values for start and foffset</p>\n");
|
518
|
+
$error=true;
|
519
|
+
}
|
520
|
+
else
|
521
|
+
{ $_REQUEST["start"] = floor($_REQUEST["start"]);
|
522
|
+
$_REQUEST["foffset"] = floor($_REQUEST["foffset"]);
|
523
|
+
}
|
524
|
+
|
525
|
+
// Set the current delimiter if defined
|
526
|
+
|
527
|
+
if (isset($_REQUEST["delimiter"]))
|
528
|
+
$delimiter = $_REQUEST["delimiter"];
|
529
|
+
|
530
|
+
// Empty CSV table if requested
|
531
|
+
|
532
|
+
if (!$error && $_REQUEST["start"]==1 && $csv_insert_table != "" && $csv_preempty_table)
|
533
|
+
{
|
534
|
+
$query = "DELETE FROM $csv_insert_table";
|
535
|
+
if (!TESTMODE && !mysql_query(trim($query), $dbconnection))
|
536
|
+
{ echo ("<p class=\"error\">Error when deleting entries from $csv_insert_table.</p>\n");
|
537
|
+
echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n");
|
538
|
+
echo ("<p>MySQL: ".mysql_error()."</p>\n");
|
539
|
+
$error=true;
|
540
|
+
}
|
541
|
+
}
|
542
|
+
|
543
|
+
// Print start message
|
544
|
+
|
545
|
+
if (!$error)
|
546
|
+
{ skin_open();
|
547
|
+
if (TESTMODE)
|
548
|
+
echo ("<p class=\"centr\">TEST MODE ENABLED</p>\n");
|
549
|
+
echo ("<p class=\"centr\">Processing file: <b>".$curfilename."</b></p>\n");
|
550
|
+
echo ("<p class=\"smlcentr\">Starting from line: ".$_REQUEST["start"]."</p>\n");
|
551
|
+
skin_close();
|
552
|
+
}
|
553
|
+
|
554
|
+
// Check $_REQUEST["foffset"] upon $filesize (can't do it on gzipped files)
|
555
|
+
|
556
|
+
if (!$error && !$gzipmode && $_REQUEST["foffset"]>$filesize)
|
557
|
+
{ echo ("<p class=\"error\">UNEXPECTED: Can't set file pointer behind the end of file</p>\n");
|
558
|
+
$error=true;
|
559
|
+
}
|
560
|
+
|
561
|
+
// Set file pointer to $_REQUEST["foffset"]
|
562
|
+
|
563
|
+
if (!$error && ((!$gzipmode && fseek($file, $_REQUEST["foffset"])!=0) || ($gzipmode && gzseek($file, $_REQUEST["foffset"])!=0)))
|
564
|
+
{ echo ("<p class=\"error\">UNEXPECTED: Can't set file pointer to offset: ".$_REQUEST["foffset"]."</p>\n");
|
565
|
+
$error=true;
|
566
|
+
}
|
567
|
+
|
568
|
+
// Start processing queries from $file
|
569
|
+
|
570
|
+
if (!$error)
|
571
|
+
{ $query="";
|
572
|
+
$queries=0;
|
573
|
+
$totalqueries=$_REQUEST["totalqueries"];
|
574
|
+
$linenumber=$_REQUEST["start"];
|
575
|
+
$querylines=0;
|
576
|
+
$inparents=false;
|
577
|
+
|
578
|
+
// Stay processing as long as the $linespersession is not reached or the query is still incomplete
|
579
|
+
|
580
|
+
while ($linenumber<$_REQUEST["start"]+$linespersession || $query!="")
|
581
|
+
{
|
582
|
+
|
583
|
+
// Read the whole next line
|
584
|
+
|
585
|
+
$dumpline = "";
|
586
|
+
while (!feof($file) && substr ($dumpline, -1) != "\n" && substr ($dumpline, -1) != "\r")
|
587
|
+
{ if (!$gzipmode)
|
588
|
+
$dumpline .= fgets($file, DATA_CHUNK_LENGTH);
|
589
|
+
else
|
590
|
+
$dumpline .= gzgets($file, DATA_CHUNK_LENGTH);
|
591
|
+
}
|
592
|
+
if ($dumpline==="") break;
|
593
|
+
|
594
|
+
// Remove UTF8 Byte Order Mark at the file beginning if any
|
595
|
+
|
596
|
+
if ($_REQUEST["foffset"]==0)
|
597
|
+
$dumpline=preg_replace('|^\xEF\xBB\xBF|','',$dumpline);
|
598
|
+
|
599
|
+
// Create an SQL query from CSV line
|
600
|
+
|
601
|
+
if (($csv_insert_table != "") && (preg_match("/(\.csv)$/i",$curfilename)))
|
602
|
+
{
|
603
|
+
if ($csv_add_slashes)
|
604
|
+
$dumpline = addslashes($dumpline);
|
605
|
+
$dumpline = explode($csv_delimiter,$dumpline);
|
606
|
+
if ($csv_add_quotes)
|
607
|
+
$dumpline = "'".implode("','",$dumpline)."'";
|
608
|
+
else
|
609
|
+
$dumpline = implode(",",$dumpline);
|
610
|
+
$dumpline = 'INSERT INTO '.$csv_insert_table.' VALUES ('.$dumpline.');';
|
611
|
+
}
|
612
|
+
|
613
|
+
// Handle DOS and Mac encoded linebreaks (I don't know if it really works on Win32 or Mac Servers)
|
614
|
+
|
615
|
+
$dumpline=str_replace("\r\n", "\n", $dumpline);
|
616
|
+
$dumpline=str_replace("\r", "\n", $dumpline);
|
617
|
+
|
618
|
+
// DIAGNOSTIC
|
619
|
+
// echo ("<p>Line $linenumber: $dumpline</p>\n");
|
620
|
+
|
621
|
+
// Recognize delimiter statement
|
622
|
+
|
623
|
+
if (!$inparents && strpos ($dumpline, "DELIMITER ") === 0)
|
624
|
+
$delimiter = str_replace ("DELIMITER ","",trim($dumpline));
|
625
|
+
|
626
|
+
// Skip comments and blank lines only if NOT in parents
|
627
|
+
|
628
|
+
if (!$inparents)
|
629
|
+
{ $skipline=false;
|
630
|
+
reset($comment);
|
631
|
+
foreach ($comment as $comment_value)
|
632
|
+
{
|
633
|
+
|
634
|
+
// DIAGNOSTIC
|
635
|
+
// echo ($comment_value);
|
636
|
+
if (trim($dumpline)=="" || strpos (trim($dumpline), $comment_value) === 0)
|
637
|
+
{ $skipline=true;
|
638
|
+
break;
|
639
|
+
}
|
640
|
+
}
|
641
|
+
if ($skipline)
|
642
|
+
{ $linenumber++;
|
643
|
+
|
644
|
+
// DIAGNOSTIC
|
645
|
+
// echo ("<p>Comment line skipped</p>\n");
|
646
|
+
|
647
|
+
continue;
|
648
|
+
}
|
649
|
+
}
|
650
|
+
|
651
|
+
// Remove double back-slashes from the dumpline prior to count the quotes ('\\' can only be within strings)
|
652
|
+
|
653
|
+
$dumpline_deslashed = str_replace ("\\\\","",$dumpline);
|
654
|
+
|
655
|
+
// Count ' and \' (or " and \") in the dumpline to avoid query break within a text field ending by $delimiter
|
656
|
+
|
657
|
+
$parents=substr_count ($dumpline_deslashed, $string_quotes)-substr_count ($dumpline_deslashed, "\\$string_quotes");
|
658
|
+
if ($parents % 2 != 0)
|
659
|
+
$inparents=!$inparents;
|
660
|
+
|
661
|
+
// Add the line to query
|
662
|
+
|
663
|
+
$query .= $dumpline;
|
664
|
+
|
665
|
+
// Don't count the line if in parents (text fields may include unlimited linebreaks)
|
666
|
+
|
667
|
+
if (!$inparents)
|
668
|
+
$querylines++;
|
669
|
+
|
670
|
+
// Stop if query contains more lines as defined by MAX_QUERY_LINES
|
671
|
+
|
672
|
+
if ($querylines>MAX_QUERY_LINES)
|
673
|
+
{
|
674
|
+
echo ("<p class=\"error\">Stopped at the line $linenumber. </p>");
|
675
|
+
echo ("<p>At this place the current query includes more than ".MAX_QUERY_LINES." dump lines. That can happen if your dump file was ");
|
676
|
+
echo ("created by some tool which doesn't place a semicolon followed by a linebreak at the end of each query, or if your dump contains ");
|
677
|
+
echo ("extended inserts or very long procedure definitions. Please read the <a href=\"http://www.ozerov.de/bigdump/usage/\">BigDump usage notes</a> ");
|
678
|
+
echo ("for more infos. Ask for our support services ");
|
679
|
+
echo ("in order to handle dump files containing extended inserts.</p>\n");
|
680
|
+
$error=true;
|
681
|
+
break;
|
682
|
+
}
|
683
|
+
|
684
|
+
// Execute query if end of query detected ($delimiter as last character) AND NOT in parents
|
685
|
+
|
686
|
+
// DIAGNOSTIC
|
687
|
+
// echo ("<p>Regex: ".'/'.preg_quote($delimiter).'$/'."</p>\n");
|
688
|
+
// echo ("<p>In Parents: ".($inparents?"true":"false")."</p>\n");
|
689
|
+
// echo ("<p>Line: $dumpline</p>\n");
|
690
|
+
|
691
|
+
if (preg_match('/'.preg_quote($delimiter).'$/',trim($dumpline)) && !$inparents)
|
692
|
+
{
|
693
|
+
|
694
|
+
// Cut off delimiter of the end of the query
|
695
|
+
|
696
|
+
$query = substr(trim($query),0,-1*strlen($delimiter));
|
697
|
+
|
698
|
+
// DIAGNOSTIC
|
699
|
+
// echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n");
|
700
|
+
|
701
|
+
if (!TESTMODE && !mysql_query($query, $dbconnection))
|
702
|
+
{ echo ("<p class=\"error\">Error at the line $linenumber: ". trim($dumpline)."</p>\n");
|
703
|
+
echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n");
|
704
|
+
echo ("<p>MySQL: ".mysql_error()."</p>\n");
|
705
|
+
$error=true;
|
706
|
+
break;
|
707
|
+
}
|
708
|
+
$totalqueries++;
|
709
|
+
$queries++;
|
710
|
+
$query="";
|
711
|
+
$querylines=0;
|
712
|
+
}
|
713
|
+
$linenumber++;
|
714
|
+
}
|
715
|
+
}
|
716
|
+
|
717
|
+
// Get the current file position
|
718
|
+
|
719
|
+
if (!$error)
|
720
|
+
{ if (!$gzipmode)
|
721
|
+
$foffset = ftell($file);
|
722
|
+
else
|
723
|
+
$foffset = gztell($file);
|
724
|
+
if (!$foffset)
|
725
|
+
{ echo ("<p class=\"error\">UNEXPECTED: Can't read the file pointer offset</p>\n");
|
726
|
+
$error=true;
|
727
|
+
}
|
728
|
+
}
|
729
|
+
|
730
|
+
// Print statistics
|
731
|
+
|
732
|
+
skin_open();
|
733
|
+
|
734
|
+
// echo ("<p class=\"centr\"><b>Statistics</b></p>\n");
|
735
|
+
|
736
|
+
if (!$error)
|
737
|
+
{
|
738
|
+
$lines_this = $linenumber-$_REQUEST["start"];
|
739
|
+
$lines_done = $linenumber-1;
|
740
|
+
$lines_togo = ' ? ';
|
741
|
+
$lines_tota = ' ? ';
|
742
|
+
|
743
|
+
$queries_this = $queries;
|
744
|
+
$queries_done = $totalqueries;
|
745
|
+
$queries_togo = ' ? ';
|
746
|
+
$queries_tota = ' ? ';
|
747
|
+
|
748
|
+
$bytes_this = $foffset-$_REQUEST["foffset"];
|
749
|
+
$bytes_done = $foffset;
|
750
|
+
$kbytes_this = round($bytes_this/1024,2);
|
751
|
+
$kbytes_done = round($bytes_done/1024,2);
|
752
|
+
$mbytes_this = round($kbytes_this/1024,2);
|
753
|
+
$mbytes_done = round($kbytes_done/1024,2);
|
754
|
+
|
755
|
+
if (!$gzipmode)
|
756
|
+
{
|
757
|
+
$bytes_togo = $filesize-$foffset;
|
758
|
+
$bytes_tota = $filesize;
|
759
|
+
$kbytes_togo = round($bytes_togo/1024,2);
|
760
|
+
$kbytes_tota = round($bytes_tota/1024,2);
|
761
|
+
$mbytes_togo = round($kbytes_togo/1024,2);
|
762
|
+
$mbytes_tota = round($kbytes_tota/1024,2);
|
763
|
+
|
764
|
+
$pct_this = ceil($bytes_this/$filesize*100);
|
765
|
+
$pct_done = ceil($foffset/$filesize*100);
|
766
|
+
$pct_togo = 100 - $pct_done;
|
767
|
+
$pct_tota = 100;
|
768
|
+
|
769
|
+
if ($bytes_togo==0)
|
770
|
+
{ $lines_togo = '0';
|
771
|
+
$lines_tota = $linenumber-1;
|
772
|
+
$queries_togo = '0';
|
773
|
+
$queries_tota = $totalqueries;
|
774
|
+
}
|
775
|
+
|
776
|
+
$pct_bar = "<div style=\"height:15px;width:$pct_done%;background-color:#000080;margin:0px;\"></div>";
|
777
|
+
}
|
778
|
+
else
|
779
|
+
{
|
780
|
+
$bytes_togo = ' ? ';
|
781
|
+
$bytes_tota = ' ? ';
|
782
|
+
$kbytes_togo = ' ? ';
|
783
|
+
$kbytes_tota = ' ? ';
|
784
|
+
$mbytes_togo = ' ? ';
|
785
|
+
$mbytes_tota = ' ? ';
|
786
|
+
|
787
|
+
$pct_this = ' ? ';
|
788
|
+
$pct_done = ' ? ';
|
789
|
+
$pct_togo = ' ? ';
|
790
|
+
$pct_tota = 100;
|
791
|
+
$pct_bar = str_replace(' ',' ','<tt>[ Not available for gzipped files ]</tt>');
|
792
|
+
}
|
793
|
+
|
794
|
+
echo ("
|
795
|
+
<center>
|
796
|
+
<table width=\"520\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\">
|
797
|
+
<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>
|
798
|
+
<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>
|
799
|
+
<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>
|
800
|
+
<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>
|
801
|
+
<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>
|
802
|
+
<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>
|
803
|
+
<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>
|
804
|
+
<tr><th class=\"bg4\">% bar</th><td class=\"bgpctbar\" colspan=\"4\">$pct_bar</td></tr>
|
805
|
+
</table>
|
806
|
+
</center>
|
807
|
+
\n");
|
808
|
+
|
809
|
+
// Finish message and restart the script
|
810
|
+
|
811
|
+
if ($linenumber<$_REQUEST["start"]+$linespersession)
|
812
|
+
{ echo ("<p class=\"successcentr\">Congratulations: End of file reached, assuming OK</p>\n");
|
813
|
+
echo ("<p class=\"successcentr\">IMPORTANT: REMOVE YOUR DUMP FILE and BIGDUMP SCRIPT FROM SERVER NOW!</p>\n");
|
814
|
+
echo ("<p class=\"centr\">Thank you for using this tool! Please rate <a href=\"http://www.hotscripts.com/listing/bigdump/?RID=403\" target=\"_blank\">Bigdump at Hotscripts.com</a></p>\n");
|
815
|
+
echo ("<p class=\"centr\">You can send me some bucks or euros as appreciation via PayPal. Thank you!</p>\n");
|
816
|
+
?>
|
817
|
+
|
818
|
+
<!-- Start Paypal donation code -->
|
819
|
+
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
|
820
|
+
<input type="hidden" name="cmd" value="_xclick" />
|
821
|
+
<input type="hidden" name="business" value="alexey@ozerov.de" />
|
822
|
+
<input type="hidden" name="item_name" value="BigDump Donation" />
|
823
|
+
<input type="hidden" name="no_shipping" value="1" />
|
824
|
+
<input type="hidden" name="no_note" value="0" />
|
825
|
+
<input type="hidden" name="tax" value="0" />
|
826
|
+
<input type="hidden" name="bn" value="PP-DonationsBF" />
|
827
|
+
<input type="hidden" name="lc" value="US" />
|
828
|
+
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but04.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" />
|
829
|
+
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
|
830
|
+
</form>
|
831
|
+
<!-- End Paypal donation code -->
|
832
|
+
|
833
|
+
<?php
|
834
|
+
|
835
|
+
$error=true; // This is a semi-error telling the script is finished
|
836
|
+
}
|
837
|
+
else
|
838
|
+
{ if ($delaypersession!=0)
|
839
|
+
echo ("<p class=\"centr\">Now I'm <b>waiting $delaypersession milliseconds</b> before starting next session...</p>\n");
|
840
|
+
if (!$ajax)
|
841
|
+
echo ("<script language=\"JavaScript\" type=\"text/javascript\">window.setTimeout('location.href=\"".$_SERVER["PHP_SELF"]."?start=$linenumber&fn=".urlencode($curfilename)."&foffset=$foffset&totalqueries=$totalqueries&delimiter=".urlencode($delimiter)."\";',500+$delaypersession);</script>\n");
|
842
|
+
|
843
|
+
echo ("<noscript>\n");
|
844
|
+
echo ("<p class=\"centr\"><a href=\"".$_SERVER["PHP_SELF"]."?start=$linenumber&fn=".urlencode($curfilename)."&foffset=$foffset&totalqueries=$totalqueries&delimiter=".urlencode($delimiter)."\">Continue from the line $linenumber</a> (Enable JavaScript to do it automatically)</p>\n");
|
845
|
+
echo ("</noscript>\n");
|
846
|
+
|
847
|
+
echo ("<p class=\"centr\">Press <b><a href=\"".$_SERVER["PHP_SELF"]."\">STOP</a></b> to abort the import <b>OR WAIT!</b></p>\n");
|
848
|
+
}
|
849
|
+
}
|
850
|
+
else
|
851
|
+
echo ("<p class=\"error\">Stopped on error</p>\n");
|
852
|
+
|
853
|
+
skin_close();
|
854
|
+
|
855
|
+
}
|
856
|
+
|
857
|
+
if ($error)
|
858
|
+
echo ("<p class=\"centr\"><a href=\"".$_SERVER["PHP_SELF"]."\">Start from the beginning</a> (DROP the old tables before restarting)</p>\n");
|
859
|
+
|
860
|
+
if ($dbconnection) mysql_close($dbconnection);
|
861
|
+
if ($file && !$gzipmode) fclose($file);
|
862
|
+
else if ($file && $gzipmode) gzclose($file);
|
863
|
+
|
864
|
+
?>
|
865
|
+
|
866
|
+
<p class="centr">© 2003-2011 <a href="mailto:alexey@ozerov.de">Alexey Ozerov</a></p>
|
867
|
+
|
868
|
+
</td></tr></table>
|
869
|
+
|
870
|
+
</center>
|
871
|
+
|
872
|
+
</body>
|
873
|
+
</html>
|
874
|
+
|
875
|
+
<?php
|
876
|
+
|
877
|
+
// If error or finished put out the whole output from above and stop
|
878
|
+
|
879
|
+
if ($error)
|
880
|
+
{
|
881
|
+
$out1 = ob_get_contents();
|
882
|
+
ob_end_clean();
|
883
|
+
echo $out1;
|
884
|
+
die;
|
885
|
+
}
|
886
|
+
|
887
|
+
// If Ajax enabled and in import progress creates responses (XML response or script for the initial page)
|
888
|
+
|
889
|
+
if ($ajax && isset($_REQUEST['start']))
|
890
|
+
{
|
891
|
+
if (isset($_REQUEST['ajaxrequest']))
|
892
|
+
{ ob_end_clean();
|
893
|
+
create_xml_response();
|
894
|
+
die;
|
895
|
+
}
|
896
|
+
else
|
897
|
+
create_ajax_script();
|
898
|
+
}
|
899
|
+
|
900
|
+
// Anyway put out the output from above
|
901
|
+
|
902
|
+
ob_flush();
|
903
|
+
|
904
|
+
// THE MAIN SCRIPT ENDS HERE
|
905
|
+
|
906
|
+
|
907
|
+
// *******************************************************************************************
|
908
|
+
// AJAX utilities
|
909
|
+
// *******************************************************************************************
|
910
|
+
|
911
|
+
function create_xml_response()
|
912
|
+
{
|
913
|
+
global $linenumber, $foffset, $totalqueries, $curfilename, $delimiter,
|
914
|
+
$lines_this, $lines_done, $lines_togo, $lines_tota,
|
915
|
+
$queries_this, $queries_done, $queries_togo, $queries_tota,
|
916
|
+
$bytes_this, $bytes_done, $bytes_togo, $bytes_tota,
|
917
|
+
$kbytes_this, $kbytes_done, $kbytes_togo, $kbytes_tota,
|
918
|
+
$mbytes_this, $mbytes_done, $mbytes_togo, $mbytes_tota,
|
919
|
+
$pct_this, $pct_done, $pct_togo, $pct_tota,$pct_bar;
|
920
|
+
|
921
|
+
header('Content-Type: application/xml');
|
922
|
+
header('Cache-Control: no-cache');
|
923
|
+
|
924
|
+
echo '<?xml version="1.0" encoding="ISO-8859-1"?>';
|
925
|
+
echo "<root>";
|
926
|
+
|
927
|
+
// data - for calculations
|
928
|
+
|
929
|
+
echo "<linenumber>$linenumber</linenumber>";
|
930
|
+
echo "<foffset>$foffset</foffset>";
|
931
|
+
echo "<fn>$curfilename</fn>";
|
932
|
+
echo "<totalqueries>$totalqueries</totalqueries>";
|
933
|
+
echo "<delimiter>$delimiter</delimiter>";
|
934
|
+
|
935
|
+
// results - for page update
|
936
|
+
|
937
|
+
echo "<elem1>$lines_this</elem1>";
|
938
|
+
echo "<elem2>$lines_done</elem2>";
|
939
|
+
echo "<elem3>$lines_togo</elem3>";
|
940
|
+
echo "<elem4>$lines_tota</elem4>";
|
941
|
+
|
942
|
+
echo "<elem5>$queries_this</elem5>";
|
943
|
+
echo "<elem6>$queries_done</elem6>";
|
944
|
+
echo "<elem7>$queries_togo</elem7>";
|
945
|
+
echo "<elem8>$queries_tota</elem8>";
|
946
|
+
|
947
|
+
echo "<elem9>$bytes_this</elem9>";
|
948
|
+
echo "<elem10>$bytes_done</elem10>";
|
949
|
+
echo "<elem11>$bytes_togo</elem11>";
|
950
|
+
echo "<elem12>$bytes_tota</elem12>";
|
951
|
+
|
952
|
+
echo "<elem13>$kbytes_this</elem13>";
|
953
|
+
echo "<elem14>$kbytes_done</elem14>";
|
954
|
+
echo "<elem15>$kbytes_togo</elem15>";
|
955
|
+
echo "<elem16>$kbytes_tota</elem16>";
|
956
|
+
|
957
|
+
echo "<elem17>$mbytes_this</elem17>";
|
958
|
+
echo "<elem18>$mbytes_done</elem18>";
|
959
|
+
echo "<elem19>$mbytes_togo</elem19>";
|
960
|
+
echo "<elem20>$mbytes_tota</elem20>";
|
961
|
+
|
962
|
+
echo "<elem21>$pct_this</elem21>";
|
963
|
+
echo "<elem22>$pct_done</elem22>";
|
964
|
+
echo "<elem23>$pct_togo</elem23>";
|
965
|
+
echo "<elem24>$pct_tota</elem24>";
|
966
|
+
echo "<elem_bar>".htmlentities($pct_bar)."</elem_bar>";
|
967
|
+
|
968
|
+
echo "</root>";
|
969
|
+
}
|
970
|
+
|
971
|
+
|
972
|
+
function create_ajax_script()
|
973
|
+
{
|
974
|
+
global $linenumber, $foffset, $totalqueries, $delaypersession, $curfilename, $delimiter;
|
975
|
+
?>
|
976
|
+
|
977
|
+
<script type="text/javascript" language="javascript">
|
978
|
+
|
979
|
+
// creates next action url (upload page, or XML response)
|
980
|
+
function get_url(linenumber,fn,foffset,totalqueries,delimiter) {
|
981
|
+
return "<?php echo $_SERVER['PHP_SELF'] ?>?start="+linenumber+"&fn="+fn+"&foffset="+foffset+"&totalqueries="+totalqueries+"&delimiter="+delimiter+"&ajaxrequest=true";
|
982
|
+
}
|
983
|
+
|
984
|
+
// extracts text from XML element (itemname must be unique)
|
985
|
+
function get_xml_data(itemname,xmld) {
|
986
|
+
return xmld.getElementsByTagName(itemname).item(0).firstChild.data;
|
987
|
+
}
|
988
|
+
|
989
|
+
function makeRequest(url) {
|
990
|
+
http_request = false;
|
991
|
+
if (window.XMLHttpRequest) {
|
992
|
+
// Mozilla etc.
|
993
|
+
http_request = new XMLHttpRequest();
|
994
|
+
if (http_request.overrideMimeType) {
|
995
|
+
http_request.overrideMimeType("text/xml");
|
996
|
+
}
|
997
|
+
} else if (window.ActiveXObject) {
|
998
|
+
// IE
|
999
|
+
try {
|
1000
|
+
http_request = new ActiveXObject("Msxml2.XMLHTTP");
|
1001
|
+
} catch(e) {
|
1002
|
+
try {
|
1003
|
+
http_request = new ActiveXObject("Microsoft.XMLHTTP");
|
1004
|
+
} catch(e) {}
|
1005
|
+
}
|
1006
|
+
}
|
1007
|
+
if (!http_request) {
|
1008
|
+
alert("Cannot create an XMLHTTP instance");
|
1009
|
+
return false;
|
1010
|
+
}
|
1011
|
+
http_request.onreadystatechange = server_response;
|
1012
|
+
http_request.open("GET", url, true);
|
1013
|
+
http_request.send(null);
|
1014
|
+
}
|
1015
|
+
|
1016
|
+
function server_response()
|
1017
|
+
{
|
1018
|
+
|
1019
|
+
// waiting for correct response
|
1020
|
+
if (http_request.readyState != 4)
|
1021
|
+
return;
|
1022
|
+
|
1023
|
+
if (http_request.status != 200)
|
1024
|
+
{
|
1025
|
+
alert("Page unavailable, or wrong url!")
|
1026
|
+
return;
|
1027
|
+
}
|
1028
|
+
|
1029
|
+
// r = xml response
|
1030
|
+
var r = http_request.responseXML;
|
1031
|
+
|
1032
|
+
//if received not XML but HTML with new page to show
|
1033
|
+
if (!r || r.getElementsByTagName('root').length == 0)
|
1034
|
+
{ var text = http_request.responseText;
|
1035
|
+
document.open();
|
1036
|
+
document.write(text);
|
1037
|
+
document.close();
|
1038
|
+
return;
|
1039
|
+
}
|
1040
|
+
|
1041
|
+
// update "Starting from line: "
|
1042
|
+
document.getElementsByTagName('p').item(1).innerHTML =
|
1043
|
+
"Starting from line: " +
|
1044
|
+
r.getElementsByTagName('linenumber').item(0).firstChild.nodeValue;
|
1045
|
+
|
1046
|
+
// update table with new values
|
1047
|
+
for(i = 1; i <= 24; i++)
|
1048
|
+
document.getElementsByTagName('td').item(i).firstChild.data = get_xml_data('elem'+i,r);
|
1049
|
+
|
1050
|
+
// update color bar
|
1051
|
+
document.getElementsByTagName('td').item(25).innerHTML =
|
1052
|
+
r.getElementsByTagName('elem_bar').item(0).firstChild.nodeValue;
|
1053
|
+
|
1054
|
+
// action url (XML response)
|
1055
|
+
url_request = get_url(
|
1056
|
+
get_xml_data('linenumber',r),
|
1057
|
+
get_xml_data('fn',r),
|
1058
|
+
get_xml_data('foffset',r),
|
1059
|
+
get_xml_data('totalqueries',r),
|
1060
|
+
get_xml_data('delimiter',r));
|
1061
|
+
|
1062
|
+
// ask for XML response
|
1063
|
+
window.setTimeout("makeRequest(url_request)",500+<?php echo $delaypersession; ?>);
|
1064
|
+
}
|
1065
|
+
|
1066
|
+
// First Ajax request from initial page
|
1067
|
+
|
1068
|
+
var http_request = false;
|
1069
|
+
var url_request = get_url(<?php echo ($linenumber.',"'.urlencode($curfilename).'",'.$foffset.','.$totalqueries.',"'.urlencode($delimiter).'"') ;?>);
|
1070
|
+
window.setTimeout("makeRequest(url_request)",500+<?php echo $delaypersession; ?>);
|
1071
|
+
</script>
|
1072
|
+
|
1073
|
+
<?php
|
1074
|
+
}
|
1075
|
+
|
1076
|
+
?>
|