Version Description
- 2011-09-23 =
- Bug fix: Breaks Export
Download this release
Release Info
Developer | bradt |
Plugin | WP Migrate DB |
Version | 0.2.2 |
Comparing to | |
See all releases |
Code changes from version 0.2.1 to 0.2.2
- readme.txt +16 -10
- screenshot-1.gif +0 -0
- screenshot-1.png +0 -0
- screenshot-2.gif +0 -0
- screenshot-2.png +0 -0
- trunk/readme.txt +0 -47
- trunk/screenshot-1.gif +0 -0
- trunk/screenshot-2.gif +0 -0
- trunk/wp-migrate-db.php +0 -584
- wp-migrate-db.php +12 -10
readme.txt
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
=== WP Migrate DB ===
|
2 |
Contributors: bradt
|
|
|
3 |
Tags: database, migrate, backup, mysql
|
4 |
Requires at least: 2.0.3
|
5 |
-
Tested up to: 2
|
6 |
-
Stable tag: 0.2.
|
7 |
-
Last Updated: 2009-03-20
|
8 |
|
9 |
-
|
10 |
|
11 |
== Description ==
|
12 |
|
@@ -31,17 +31,23 @@ Enjoy!
|
|
31 |
1. Main screen
|
32 |
2. Saving the exported database
|
33 |
|
34 |
-
==
|
35 |
|
36 |
-
|
|
|
37 |
|
|
|
38 |
* Moved to Wordpress.org hosting
|
39 |
|
40 |
-
|
41 |
-
|
42 |
* Moved menu link from "Settings" to "Tools"
|
43 |
* The random string of characters no longer appears in the filename on save.
|
44 |
|
45 |
-
|
46 |
-
|
47 |
* First release
|
|
|
|
|
|
|
|
|
|
|
|
1 |
=== WP Migrate DB ===
|
2 |
Contributors: bradt
|
3 |
+
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5VPMGLLK94XJC
|
4 |
Tags: database, migrate, backup, mysql
|
5 |
Requires at least: 2.0.3
|
6 |
+
Tested up to: 3.2
|
7 |
+
Stable tag: 0.2.2
|
|
|
8 |
|
9 |
+
Exports your database, does a find and replace on URLs and file paths, then allows you to save it to your computer.
|
10 |
|
11 |
== Description ==
|
12 |
|
31 |
1. Main screen
|
32 |
2. Saving the exported database
|
33 |
|
34 |
+
== Changelog ==
|
35 |
|
36 |
+
= 0.2.2 - 2011-09-23 =
|
37 |
+
* Bug fix: [Breaks Export](http://wordpress.org/support/topic/plugin-wp-migrate-db-breaks-export?replies=1)
|
38 |
|
39 |
+
= 0.2.1 - 2009-12-13 =
|
40 |
* Moved to Wordpress.org hosting
|
41 |
|
42 |
+
= 0.2 - 2009-04-03 =
|
|
|
43 |
* Moved menu link from "Settings" to "Tools"
|
44 |
* The random string of characters no longer appears in the filename on save.
|
45 |
|
46 |
+
= 0.1 - 2009-03-20 =
|
|
|
47 |
* First release
|
48 |
+
|
49 |
+
== Upgrade Notice ==
|
50 |
+
|
51 |
+
= 0.2.2 =
|
52 |
+
|
53 |
+
This version fixes a bug that breaks the WordPress core export feature. It is highly recommended that everyone upgrade.
|
screenshot-1.gif
DELETED
Binary file
|
screenshot-1.png
ADDED
Binary file
|
screenshot-2.gif
DELETED
Binary file
|
screenshot-2.png
ADDED
Binary file
|
trunk/readme.txt
DELETED
@@ -1,47 +0,0 @@
|
|
1 |
-
=== WP Migrate DB ===
|
2 |
-
Contributors: bradt
|
3 |
-
Tags: database, migrate, backup, mysql
|
4 |
-
Requires at least: 2.0.3
|
5 |
-
Tested up to: 2.8
|
6 |
-
Stable tag: 0.2.1
|
7 |
-
Last Updated: 2009-03-20
|
8 |
-
|
9 |
-
WP Migrate DB exports your database, does a find and replace on URLs and file paths, then allows you to save it to your computer.
|
10 |
-
|
11 |
-
== Description ==
|
12 |
-
|
13 |
-
WP Migrate DB exports your database as a MySQL data dump (much like phpMyAdmin), does a find and replace on URLs and file paths, then allows you to save it to your computer. It is perfect for developers who develop locally and need to to move their Wordpress site to a staging or production server.
|
14 |
-
|
15 |
-
It even takes into account serialized data and updates the string length values.
|
16 |
-
|
17 |
-
Example: <code>s:5:"hello"</code> becomes <code>s:11:"hello world"</code>
|
18 |
-
|
19 |
-
== Installation ==
|
20 |
-
|
21 |
-
1. Download wp-migrate-db.<version>.zip
|
22 |
-
2. Unzip the archive
|
23 |
-
3. Upload the wp-migrate-db folder to your wp-content/plugins directory
|
24 |
-
4. Activate the plugin through the WordPress admin interface
|
25 |
-
5. Access the WP Migrate DB menu option in Settings
|
26 |
-
|
27 |
-
Enjoy!
|
28 |
-
|
29 |
-
== Screenshots ==
|
30 |
-
|
31 |
-
1. Main screen
|
32 |
-
2. Saving the exported database
|
33 |
-
|
34 |
-
== Release Notes ==
|
35 |
-
|
36 |
-
**0.2.1 - 2009-12-13**
|
37 |
-
|
38 |
-
* Moved to Wordpress.org hosting
|
39 |
-
|
40 |
-
**0.2 - 2009-04-03**
|
41 |
-
|
42 |
-
* Moved menu link from "Settings" to "Tools"
|
43 |
-
* The random string of characters no longer appears in the filename on save.
|
44 |
-
|
45 |
-
**0.1 - 2009-03-20**
|
46 |
-
|
47 |
-
* First release
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
trunk/screenshot-1.gif
DELETED
Binary file
|
trunk/screenshot-2.gif
DELETED
Binary file
|
trunk/wp-migrate-db.php
DELETED
@@ -1,584 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Plugin Name: WP-Migrate-DB
|
4 |
-
Plugin URI: http://wordpress.org/extend/plugins/wp-migrate-db/
|
5 |
-
Description: Exports your database as a MySQL data dump (much like phpMyAdmin), does a find and replace on URLs and file paths, then allows you to save it to your computer.
|
6 |
-
Author: Brad Touesnard
|
7 |
-
Version: 0.2.1
|
8 |
-
Author URI: http://bradt.ca/
|
9 |
-
*/
|
10 |
-
|
11 |
-
// Copyright (c) 2008 Brad Touesnard. All rights reserved.
|
12 |
-
//
|
13 |
-
// Released under the GPL license
|
14 |
-
// http://www.opensource.org/licenses/gpl-license.php
|
15 |
-
//
|
16 |
-
// **********************************************************************
|
17 |
-
// This program is distributed in the hope that it will be useful, but
|
18 |
-
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
20 |
-
// **********************************************************************
|
21 |
-
//
|
22 |
-
// Borrowed a bunch of code from the WP-DB-Backup plugin
|
23 |
-
// which in turn borrowed from the phpMyAdmin project.
|
24 |
-
// Thanks to both for GPL.
|
25 |
-
|
26 |
-
|
27 |
-
// Define the directory seperator if it isn't already
|
28 |
-
if (!defined('DS')) {
|
29 |
-
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
|
30 |
-
define('DS', '\\');
|
31 |
-
}
|
32 |
-
else {
|
33 |
-
define('DS', '/');
|
34 |
-
}
|
35 |
-
}
|
36 |
-
|
37 |
-
if ( ! defined('ROWS_PER_SEGMENT') ) {
|
38 |
-
define('ROWS_PER_SEGMENT', 100);
|
39 |
-
}
|
40 |
-
|
41 |
-
class WP_Migrate_DB {
|
42 |
-
var $errors;
|
43 |
-
var $upload_dir;
|
44 |
-
var $upload_url;
|
45 |
-
var $filename;
|
46 |
-
var $nicename;
|
47 |
-
var $fp;
|
48 |
-
var $replaced;
|
49 |
-
|
50 |
-
function __construct() {
|
51 |
-
$this->errors = array();
|
52 |
-
$this->upload_dir = ( defined('WP_CONTENT_DIR') ) ? WP_CONTENT_DIR . '/uploads' : ABSPATH . 'wp-content' . DS . 'uploads';
|
53 |
-
$this->upload_url = ( defined('WP_CONTENT_URL') ) ? WP_CONTENT_URL . '/uploads' : get_option('siteurl') . '/wp-content/uploads';
|
54 |
-
|
55 |
-
$hash = substr( md5( md5( DB_PASSWORD ) ), -5 );
|
56 |
-
$this->filename = DB_NAME . '-migrate-' . $hash . '.sql';
|
57 |
-
$this->nicename = DB_NAME . '-migrate.sql';
|
58 |
-
|
59 |
-
$this->replaced['serialized']['count'] = 0;
|
60 |
-
$this->replaced['serialized']['strings'] = '';
|
61 |
-
$this->replaced['nonserialized']['count'] = 0;
|
62 |
-
}
|
63 |
-
|
64 |
-
function options_validate() {
|
65 |
-
if (!isset($_POST['old_url']) || !$_POST['old_url']) {
|
66 |
-
$this->errors['old_url'] = __('Please enter the current URL.', 'wp-migrate-db');
|
67 |
-
}
|
68 |
-
|
69 |
-
if (!isset($_POST['new_url']) || !$_POST['new_url']) {
|
70 |
-
$this->errors['new_url'] = __('Please enter a new URL.', 'wp-migrate-db');
|
71 |
-
}
|
72 |
-
|
73 |
-
if (!isset($_POST['old_path']) || !$_POST['old_path']) {
|
74 |
-
$this->errors['old_path'] = __('Please enter the current file path.', 'wp-migrate-db');
|
75 |
-
}
|
76 |
-
|
77 |
-
if (!isset($_POST['new_path']) || !$_POST['new_path']) {
|
78 |
-
$this->errors['new_path'] = __('Please enter a new file path.', 'wp-migrate-db');
|
79 |
-
}
|
80 |
-
}
|
81 |
-
|
82 |
-
function show_error($key) {
|
83 |
-
if (isset($this->errors[$key])) {
|
84 |
-
echo '<br /><span style="color: #cc0000; font-weight: bold;">', $this->errors[$key], '</span>';
|
85 |
-
}
|
86 |
-
}
|
87 |
-
|
88 |
-
function options_page() {
|
89 |
-
?>
|
90 |
-
|
91 |
-
<div class="wrap">
|
92 |
-
<h2 style="margin-bottom: 0.5em;">WP Migrate DB</h2>
|
93 |
-
|
94 |
-
<?php
|
95 |
-
if (isset($_POST['Submit'])) {
|
96 |
-
$this->options_validate();
|
97 |
-
|
98 |
-
if (empty($this->errors)) {
|
99 |
-
$this->fp = $this->open($this->upload_dir . DS . $this->filename);
|
100 |
-
$this->db_backup_header();
|
101 |
-
$this->db_backup();
|
102 |
-
$this->close($this->fp);
|
103 |
-
}
|
104 |
-
|
105 |
-
if (empty($this->errors)) {
|
106 |
-
?>
|
107 |
-
|
108 |
-
<div class="message updated">
|
109 |
-
|
110 |
-
<?php
|
111 |
-
if (isset($_POST['savefile']) && $_POST['savefile']) {
|
112 |
-
add_action('admin_head-settings_page_wp-migrate-db', array($this, 'admin_head'));
|
113 |
-
?>
|
114 |
-
<p>
|
115 |
-
Your database (SQL) file has been successfully generated.
|
116 |
-
Your download should begin any second.
|
117 |
-
</p>
|
118 |
-
<?php
|
119 |
-
}
|
120 |
-
else {
|
121 |
-
?>
|
122 |
-
<p>
|
123 |
-
Your database (SQL) file has been successfully generated.
|
124 |
-
<a href="<?php echo $this->upload_url, '/', $this->filename; ?>">Click
|
125 |
-
here to download.</a>
|
126 |
-
</p>
|
127 |
-
<?php
|
128 |
-
}
|
129 |
-
?>
|
130 |
-
|
131 |
-
</div>
|
132 |
-
|
133 |
-
<p>
|
134 |
-
<b>Non-Serialized Strings Replaced: <?php echo $this->replaced['nonserialized']['count']; ?></b><br />
|
135 |
-
<b>Serialized Strings Replaced: <?php echo $this->replaced['serialized']['count']; ?></b><br />
|
136 |
-
<textarea style="width: 100%; height: 200px;" wrap="off"><?php echo $this->replaced['serialized']['strings']; ?></textarea>
|
137 |
-
</p>
|
138 |
-
<?php
|
139 |
-
}
|
140 |
-
|
141 |
-
$form_values = $_POST;
|
142 |
-
}
|
143 |
-
else {
|
144 |
-
$form_values['old_url'] = get_bloginfo('siteurl');
|
145 |
-
|
146 |
-
$form_values['old_path'] = dirname(__FILE__);
|
147 |
-
$form_values['old_path'] = str_replace(DS . 'wp-migrate-db', '', $form_values['old_path']);
|
148 |
-
$form_values['old_path'] = realpath($form_values['old_path'] . '/../..');
|
149 |
-
|
150 |
-
if (get_bloginfo('siteurl') != get_bloginfo('wpurl')) {
|
151 |
-
$wp_dir = str_replace(get_bloginfo('siteurl'), '', get_bloginfo('wpurl'));
|
152 |
-
$wp_dir = str_replace('/', DS, $wp_dir);
|
153 |
-
$form_values['old_path'] = str_replace($wp_dir, '', $form_values['old_path']);
|
154 |
-
}
|
155 |
-
}
|
156 |
-
|
157 |
-
if (!isset($_POST['Submit']) || (isset($_POST['Submit']) && !empty($this->errors))) {
|
158 |
-
if (!is_writable($this->upload_dir)) {
|
159 |
-
?>
|
160 |
-
|
161 |
-
<div id="message" class="message error">
|
162 |
-
<p>
|
163 |
-
The directory <?php echo $this->upload_dir; ?> needs
|
164 |
-
to be writable.
|
165 |
-
</p>
|
166 |
-
</div>
|
167 |
-
|
168 |
-
<?php
|
169 |
-
}
|
170 |
-
|
171 |
-
if (!empty($this->errors)) {
|
172 |
-
?>
|
173 |
-
|
174 |
-
<div id="message" class="message error">
|
175 |
-
<p>
|
176 |
-
Sorry, there were errors with your form submission.
|
177 |
-
Please correct them below and try again.
|
178 |
-
</p>
|
179 |
-
</div>
|
180 |
-
|
181 |
-
<?php
|
182 |
-
}
|
183 |
-
?>
|
184 |
-
|
185 |
-
<p>
|
186 |
-
WP Migrate DB exports your database as a MySQL data dump (much like phpMyAdmin),
|
187 |
-
does a find and replace on URLs and file paths, then allows you to save
|
188 |
-
it to your computer. It even takes into account serialized data and updates the
|
189 |
-
string length values.
|
190 |
-
</p>
|
191 |
-
<p>
|
192 |
-
Example: <code>s:5:"hello"</code> becomes <code>s:11:"hello world"</code>
|
193 |
-
</p>
|
194 |
-
<form method="post">
|
195 |
-
<table class="form-table">
|
196 |
-
<tbody>
|
197 |
-
<tr valign="top">
|
198 |
-
<th scope="row">
|
199 |
-
<label for="old_url">Current address (URL)</label>
|
200 |
-
</th>
|
201 |
-
<td>
|
202 |
-
<input type="text" size="40" name="old_url" class="code" id="old_url" value="<?php echo htmlentities($form_values['old_url']); ?>" />
|
203 |
-
<?php $this->show_error('old_url'); ?>
|
204 |
-
</td>
|
205 |
-
</tr>
|
206 |
-
<tr valign="top">
|
207 |
-
<th scope="row">
|
208 |
-
<label for="new_url">New address (URL)</label>
|
209 |
-
</th>
|
210 |
-
<td>
|
211 |
-
<input type="text" size="40" name="new_url" class="code" id="new_url" value="<?php echo htmlentities($form_values['new_url']); ?>" />
|
212 |
-
<?php $this->show_error('new_url'); ?>
|
213 |
-
</td>
|
214 |
-
</tr>
|
215 |
-
</tbody>
|
216 |
-
</table>
|
217 |
-
|
218 |
-
<br /><br />
|
219 |
-
|
220 |
-
<table class="form-table">
|
221 |
-
<tbody>
|
222 |
-
<tr valign="top">
|
223 |
-
<th scope="row">
|
224 |
-
<label for="old_path">Current file path</label>
|
225 |
-
</th>
|
226 |
-
<td>
|
227 |
-
<input type="text" size="40" name="old_path" class="code" id="old_path" value="<?php echo htmlentities($form_values['old_path']); ?>" />
|
228 |
-
<?php $this->show_error('old_path'); ?>
|
229 |
-
</td>
|
230 |
-
</tr>
|
231 |
-
<tr valign="top">
|
232 |
-
<th scope="row">
|
233 |
-
<label for="new_path">New file path</label>
|
234 |
-
</th>
|
235 |
-
<td>
|
236 |
-
<input type="text" size="40" name="new_path" class="code" id="new_path" value="<?php echo htmlentities($form_values['new_path']); ?>" />
|
237 |
-
<?php $this->show_error('new_path'); ?>
|
238 |
-
</td>
|
239 |
-
</tr>
|
240 |
-
<tr valign="top">
|
241 |
-
<th scope="row"> </th>
|
242 |
-
<td>
|
243 |
-
<label for="savefile">
|
244 |
-
<input id="savefile" type="checkbox" checked="checked" value="1" name="savefile"/>
|
245 |
-
Save as file to your computer
|
246 |
-
</label>
|
247 |
-
</td>
|
248 |
-
</tr>
|
249 |
-
</tbody>
|
250 |
-
</table>
|
251 |
-
|
252 |
-
<p class="submit">
|
253 |
-
<input class="button" type="submit" value="Export Database" name="Submit"/>
|
254 |
-
</p>
|
255 |
-
</form>
|
256 |
-
<?php
|
257 |
-
}
|
258 |
-
?>
|
259 |
-
</div>
|
260 |
-
<?php
|
261 |
-
}
|
262 |
-
|
263 |
-
function replace_sql_strings($search, $replace, $subject) {
|
264 |
-
$search = mysql_real_escape_string($search);
|
265 |
-
|
266 |
-
$regex = '@s\:([0-9]+)\:"([^"]*' . preg_quote($search) . '[^"]*)"@';
|
267 |
-
//echo $regex, '<br />';
|
268 |
-
|
269 |
-
$count = preg_match_all($regex, $subject, $matches);
|
270 |
-
|
271 |
-
$this->replaced['serialized']['count'] += $count;
|
272 |
-
|
273 |
-
if ($count) {
|
274 |
-
for ($i = 0; $i < count($matches[0]); $i++) {
|
275 |
-
$old_line = $matches[0][$i];
|
276 |
-
$str = str_replace($search, $replace, $matches[2][$i]);
|
277 |
-
|
278 |
-
$new_line = sprintf('s:%s:"%s"', strlen($str), mysql_real_escape_string($str));
|
279 |
-
//str_replace($matches[0][$i], )
|
280 |
-
|
281 |
-
$subject = str_replace($old_line, $new_line, $subject, $count);
|
282 |
-
|
283 |
-
if ($count) {
|
284 |
-
$this->replaced['serialized']['strings'] .= $old_line . "\n";
|
285 |
-
$this->replaced['serialized']['strings'] .= $new_line . "\n\n";
|
286 |
-
}
|
287 |
-
}
|
288 |
-
}
|
289 |
-
|
290 |
-
$subject = str_replace($search, $replace, $subject, $count);
|
291 |
-
|
292 |
-
$this->replaced['nonserialized']['count'] += $count;
|
293 |
-
|
294 |
-
return $subject;
|
295 |
-
}
|
296 |
-
|
297 |
-
/**
|
298 |
-
* Taken partially from phpMyAdmin and partially from
|
299 |
-
* Alain Wolf, Zurich - Switzerland
|
300 |
-
* Website: http://restkultur.ch/personal/wolf/scripts/db_backup/
|
301 |
-
|
302 |
-
* Modified by Scott Merrill (http://www.skippy.net/)
|
303 |
-
* to use the WordPress $wpdb object
|
304 |
-
* @param string $table
|
305 |
-
* @param string $segment
|
306 |
-
* @return void
|
307 |
-
*/
|
308 |
-
function backup_table($table, $segment = 'none') {
|
309 |
-
global $wpdb;
|
310 |
-
|
311 |
-
$table_structure = $wpdb->get_results("DESCRIBE $table");
|
312 |
-
if (! $table_structure) {
|
313 |
-
$this->error(__('Error getting table details','wp-migrate-db') . ": $table");
|
314 |
-
return false;
|
315 |
-
}
|
316 |
-
|
317 |
-
if(($segment == 'none') || ($segment == 0)) {
|
318 |
-
// Add SQL statement to drop existing table
|
319 |
-
$this->stow("\n\n");
|
320 |
-
$this->stow("#\n");
|
321 |
-
$this->stow("# " . sprintf(__('Delete any existing table %s','wp-migrate-db'),$this->backquote($table)) . "\n");
|
322 |
-
$this->stow("#\n");
|
323 |
-
$this->stow("\n");
|
324 |
-
$this->stow("DROP TABLE IF EXISTS " . $this->backquote($table) . ";\n");
|
325 |
-
|
326 |
-
// Table structure
|
327 |
-
// Comment in SQL-file
|
328 |
-
$this->stow("\n\n");
|
329 |
-
$this->stow("#\n");
|
330 |
-
$this->stow("# " . sprintf(__('Table structure of table %s','wp-migrate-db'),$this->backquote($table)) . "\n");
|
331 |
-
$this->stow("#\n");
|
332 |
-
$this->stow("\n");
|
333 |
-
|
334 |
-
$create_table = $wpdb->get_results("SHOW CREATE TABLE $table", ARRAY_N);
|
335 |
-
if (false === $create_table) {
|
336 |
-
$err_msg = sprintf(__('Error with SHOW CREATE TABLE for %s.','wp-migrate-db'), $table);
|
337 |
-
$this->error($err_msg);
|
338 |
-
$this->stow("#\n# $err_msg\n#\n");
|
339 |
-
}
|
340 |
-
$this->stow($create_table[0][1] . ' ;');
|
341 |
-
|
342 |
-
if (false === $table_structure) {
|
343 |
-
$err_msg = sprintf(__('Error getting table structure of %s','wp-migrate-db'), $table);
|
344 |
-
$this->error($err_msg);
|
345 |
-
$this->stow("#\n# $err_msg\n#\n");
|
346 |
-
}
|
347 |
-
|
348 |
-
// Comment in SQL-file
|
349 |
-
$this->stow("\n\n");
|
350 |
-
$this->stow("#\n");
|
351 |
-
$this->stow('# ' . sprintf(__('Data contents of table %s','wp-migrate-db'),$this->backquote($table)) . "\n");
|
352 |
-
$this->stow("#\n");
|
353 |
-
}
|
354 |
-
|
355 |
-
if(($segment == 'none') || ($segment >= 0)) {
|
356 |
-
$defs = array();
|
357 |
-
$ints = array();
|
358 |
-
foreach ($table_structure as $struct) {
|
359 |
-
if ( (0 === strpos($struct->Type, 'tinyint')) ||
|
360 |
-
(0 === strpos(strtolower($struct->Type), 'smallint')) ||
|
361 |
-
(0 === strpos(strtolower($struct->Type), 'mediumint')) ||
|
362 |
-
(0 === strpos(strtolower($struct->Type), 'int')) ||
|
363 |
-
(0 === strpos(strtolower($struct->Type), 'bigint')) ) {
|
364 |
-
$defs[strtolower($struct->Field)] = ( null === $struct->Default ) ? 'NULL' : $struct->Default;
|
365 |
-
$ints[strtolower($struct->Field)] = "1";
|
366 |
-
}
|
367 |
-
}
|
368 |
-
|
369 |
-
|
370 |
-
// Batch by $row_inc
|
371 |
-
|
372 |
-
if($segment == 'none') {
|
373 |
-
$row_start = 0;
|
374 |
-
$row_inc = ROWS_PER_SEGMENT;
|
375 |
-
} else {
|
376 |
-
$row_start = $segment * ROWS_PER_SEGMENT;
|
377 |
-
$row_inc = ROWS_PER_SEGMENT;
|
378 |
-
}
|
379 |
-
|
380 |
-
do {
|
381 |
-
// don't include extra stuff, if so requested
|
382 |
-
$excs = (array) get_option('wp_db_backup_excs');
|
383 |
-
$where = '';
|
384 |
-
if ( is_array($excs['spam'] ) && in_array($table, $excs['spam']) ) {
|
385 |
-
$where = ' WHERE comment_approved != "spam"';
|
386 |
-
} elseif ( is_array($excs['revisions'] ) && in_array($table, $excs['revisions']) ) {
|
387 |
-
$where = ' WHERE post_type != "revision"';
|
388 |
-
}
|
389 |
-
|
390 |
-
if ( !ini_get('safe_mode')) @set_time_limit(15*60);
|
391 |
-
$table_data = $wpdb->get_results("SELECT * FROM $table $where LIMIT {$row_start}, {$row_inc}", ARRAY_A);
|
392 |
-
|
393 |
-
$entries = 'INSERT INTO ' . $this->backquote($table) . ' VALUES (';
|
394 |
-
// \x08\\x09, not required
|
395 |
-
$search = array("\x00", "\x0a", "\x0d", "\x1a");
|
396 |
-
$replace = array('\0', '\n', '\r', '\Z');
|
397 |
-
if($table_data) {
|
398 |
-
foreach ($table_data as $row) {
|
399 |
-
$values = array();
|
400 |
-
foreach ($row as $key => $value) {
|
401 |
-
if ($ints[strtolower($key)]) {
|
402 |
-
// make sure there are no blank spots in the insert syntax,
|
403 |
-
// yet try to avoid quotation marks around integers
|
404 |
-
$value = ( null === $value || '' === $value) ? $defs[strtolower($key)] : $value;
|
405 |
-
$values[] = ( '' === $value ) ? "''" : $value;
|
406 |
-
} else {
|
407 |
-
$values[] = "'" . str_replace($search, $replace, $this->sql_addslashes($value)) . "'";
|
408 |
-
}
|
409 |
-
}
|
410 |
-
$this->stow(" \n" . $entries . implode(', ', $values) . ') ;');
|
411 |
-
}
|
412 |
-
$row_start += $row_inc;
|
413 |
-
}
|
414 |
-
} while((count($table_data) > 0) and ($segment=='none'));
|
415 |
-
}
|
416 |
-
|
417 |
-
if(($segment == 'none') || ($segment < 0)) {
|
418 |
-
// Create footer/closing comment in SQL-file
|
419 |
-
$this->stow("\n");
|
420 |
-
$this->stow("#\n");
|
421 |
-
$this->stow("# " . sprintf(__('End of data contents of table %s','wp-migrate-db'),$this->backquote($table)) . "\n");
|
422 |
-
$this->stow("# --------------------------------------------------------\n");
|
423 |
-
$this->stow("\n");
|
424 |
-
}
|
425 |
-
} // end backup_table()
|
426 |
-
|
427 |
-
function db_backup() {
|
428 |
-
global $table_prefix, $wpdb;
|
429 |
-
|
430 |
-
$tables = $wpdb->get_results("SHOW TABLES", ARRAY_N);
|
431 |
-
$tables = array_map(create_function('$a', 'return $a[0];'), $tables);
|
432 |
-
|
433 |
-
/*
|
434 |
-
if (is_writable($this->backup_dir)) {
|
435 |
-
$this->fp = $this->open($this->backup_dir . $this->backup_filename);
|
436 |
-
if(!$this->fp) {
|
437 |
-
$this->error(__('Could not open the backup file for writing!','wp-migrate-db'));
|
438 |
-
return false;
|
439 |
-
}
|
440 |
-
} else {
|
441 |
-
$this->error(__('The backup directory is not writeable!','wp-migrate-db'));
|
442 |
-
return false;
|
443 |
-
}*/
|
444 |
-
|
445 |
-
foreach ($tables as $table) {
|
446 |
-
// Increase script execution time-limit to 15 min for every table.
|
447 |
-
if ( !ini_get('safe_mode')) @set_time_limit(15*60);
|
448 |
-
// Create the SQL statements
|
449 |
-
$this->stow("# --------------------------------------------------------\n");
|
450 |
-
$this->stow("# " . sprintf(__('Table: %s','wp-migrate-db'),$this->backquote($table)) . "\n");
|
451 |
-
$this->stow("# --------------------------------------------------------\n");
|
452 |
-
$this->backup_table($table);
|
453 |
-
}
|
454 |
-
|
455 |
-
//$this->close($this->fp);
|
456 |
-
|
457 |
-
if (count($this->errors)) {
|
458 |
-
return false;
|
459 |
-
} else {
|
460 |
-
//return $this->backup_filename;
|
461 |
-
return true;
|
462 |
-
}
|
463 |
-
|
464 |
-
} //wp_db_backup
|
465 |
-
|
466 |
-
function db_backup_header() {
|
467 |
-
$this->stow("# " . __('WordPress MySQL database migration','wp-migrate-db') . "\n", false);
|
468 |
-
$this->stow("# " . sprintf(__('From %s to %s','wp-migrate-db'), $_POST['old_url'], $_POST['new_url']) . "\n", false);
|
469 |
-
$this->stow("#\n", false);
|
470 |
-
$this->stow("# " . sprintf(__('Generated: %s','wp-migrate-db'),date("l j. F Y H:i T")) . "\n", false);
|
471 |
-
$this->stow("# " . sprintf(__('Hostname: %s','wp-migrate-db'),DB_HOST) . "\n", false);
|
472 |
-
$this->stow("# " . sprintf(__('Database: %s','wp-migrate-db'),$this->backquote(DB_NAME)) . "\n", false);
|
473 |
-
$this->stow("# --------------------------------------------------------\n\n", false);
|
474 |
-
}
|
475 |
-
|
476 |
-
function gzip() {
|
477 |
-
return false; //function_exists('gzopen');
|
478 |
-
}
|
479 |
-
|
480 |
-
function open($filename = '', $mode = 'w') {
|
481 |
-
if ('' == $filename) return false;
|
482 |
-
if ($this->gzip())
|
483 |
-
$fp = gzopen($filename, $mode);
|
484 |
-
else
|
485 |
-
$fp = fopen($filename, $mode);
|
486 |
-
return $fp;
|
487 |
-
}
|
488 |
-
|
489 |
-
function close($fp) {
|
490 |
-
if ($this->gzip()) gzclose($fp);
|
491 |
-
else fclose($fp);
|
492 |
-
}
|
493 |
-
|
494 |
-
function stow($query_line, $replace = true) {
|
495 |
-
if ($replace) {
|
496 |
-
$query_line = $this->replace_sql_strings($_POST['old_url'], $_POST['new_url'], $query_line);
|
497 |
-
$query_line = $this->replace_sql_strings($_POST['old_path'], $_POST['new_path'], $query_line);
|
498 |
-
}
|
499 |
-
|
500 |
-
if ($this->gzip()) {
|
501 |
-
if(! @gzwrite($this->fp, $query_line))
|
502 |
-
$this->errors['file_write'] = __('There was an error writing a line to the backup script:','wp-db-backup') . ' ' . $query_line . ' ' . $php_errormsg;
|
503 |
-
} else {
|
504 |
-
if(false === @fwrite($this->fp, $query_line))
|
505 |
-
$this->error['file_write'] = __('There was an error writing a line to the backup script:','wp-db-backup') . ' ' . $query_line . ' ' . $php_errormsg;
|
506 |
-
}
|
507 |
-
}
|
508 |
-
|
509 |
-
/**
|
510 |
-
* Add backquotes to tables and db-names in
|
511 |
-
* SQL queries. Taken from phpMyAdmin.
|
512 |
-
*/
|
513 |
-
function backquote($a_name) {
|
514 |
-
if (!empty($a_name) && $a_name != '*') {
|
515 |
-
if (is_array($a_name)) {
|
516 |
-
$result = array();
|
517 |
-
reset($a_name);
|
518 |
-
while(list($key, $val) = each($a_name))
|
519 |
-
$result[$key] = '`' . $val . '`';
|
520 |
-
return $result;
|
521 |
-
} else {
|
522 |
-
return '`' . $a_name . '`';
|
523 |
-
}
|
524 |
-
} else {
|
525 |
-
return $a_name;
|
526 |
-
}
|
527 |
-
}
|
528 |
-
|
529 |
-
/**
|
530 |
-
* Better addslashes for SQL queries.
|
531 |
-
* Taken from phpMyAdmin.
|
532 |
-
*/
|
533 |
-
function sql_addslashes($a_string = '', $is_like = false) {
|
534 |
-
if ($is_like) $a_string = str_replace('\\', '\\\\\\\\', $a_string);
|
535 |
-
else $a_string = str_replace('\\', '\\\\', $a_string);
|
536 |
-
return str_replace('\'', '\\\'', $a_string);
|
537 |
-
}
|
538 |
-
|
539 |
-
function download_file() {
|
540 |
-
set_time_limit(0);
|
541 |
-
$diskfile = $this->upload_dir . DS . $this->filename;
|
542 |
-
if (file_exists($diskfile)) {
|
543 |
-
header('Content-Description: File Transfer');
|
544 |
-
header('Content-Type: application/octet-stream');
|
545 |
-
header('Content-Length: ' . filesize($diskfile));
|
546 |
-
header("Content-Disposition: attachment; filename={$this->nicename}");
|
547 |
-
$success = readfile($diskfile);
|
548 |
-
unlink($diskfile);
|
549 |
-
exit;
|
550 |
-
}
|
551 |
-
else {
|
552 |
-
wp_die('Could not find the file to download.');
|
553 |
-
}
|
554 |
-
}
|
555 |
-
|
556 |
-
function admin_menu() {
|
557 |
-
if (function_exists('add_management_page')) {
|
558 |
-
add_management_page('WP Migrate DB','WP Migrate DB',8,'wp-migrate-db',array($this, 'options_page'));
|
559 |
-
}
|
560 |
-
}
|
561 |
-
|
562 |
-
function admin_head() {
|
563 |
-
$url = admin_url('tools.php?page=wp-migrate-db&download=true');
|
564 |
-
?>
|
565 |
-
<meta http-equiv="refresh" content="5;url=<?php echo $url; ?>"/>
|
566 |
-
<?php
|
567 |
-
}
|
568 |
-
}
|
569 |
-
|
570 |
-
global $wpmdb;
|
571 |
-
$wpmdb = new WP_Migrate_DB;
|
572 |
-
|
573 |
-
if (is_admin()) {
|
574 |
-
add_action('admin_menu', array($wpmdb, 'admin_menu'));
|
575 |
-
|
576 |
-
if (isset($_POST['savefile']) && $_POST['savefile']) {
|
577 |
-
add_action('admin_head-tools_page_wp-migrate-db', array($wpmdb, 'admin_head'));
|
578 |
-
}
|
579 |
-
|
580 |
-
if (isset($_GET['download']) && $_GET['download']) {
|
581 |
-
add_action('init', array($wpmdb, 'download_file'));
|
582 |
-
}
|
583 |
-
}
|
584 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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<?php
|
2 |
/*
|
3 |
Plugin Name: WP-Migrate-DB
|
4 |
-
Plugin URI: http://
|
5 |
Description: Exports your database as a MySQL data dump (much like phpMyAdmin), does a find and replace on URLs and file paths, then allows you to save it to your computer.
|
6 |
Author: Brad Touesnard
|
7 |
-
Version: 0.2
|
8 |
Author URI: http://bradt.ca/
|
9 |
*/
|
10 |
|
@@ -562,7 +562,7 @@ class WP_Migrate_DB {
|
|
562 |
function admin_head() {
|
563 |
$url = admin_url('tools.php?page=wp-migrate-db&download=true');
|
564 |
?>
|
565 |
-
<meta http-equiv="refresh" content="
|
566 |
<?php
|
567 |
}
|
568 |
}
|
@@ -573,12 +573,14 @@ $wpmdb = new WP_Migrate_DB;
|
|
573 |
if (is_admin()) {
|
574 |
add_action('admin_menu', array($wpmdb, 'admin_menu'));
|
575 |
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
|
|
|
|
583 |
}
|
584 |
?>
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: WP-Migrate-DB
|
4 |
+
Plugin URI: http://wordpress.org/extend/plugins/wp-migrate-db/
|
5 |
Description: Exports your database as a MySQL data dump (much like phpMyAdmin), does a find and replace on URLs and file paths, then allows you to save it to your computer.
|
6 |
Author: Brad Touesnard
|
7 |
+
Version: 0.2.2
|
8 |
Author URI: http://bradt.ca/
|
9 |
*/
|
10 |
|
562 |
function admin_head() {
|
563 |
$url = admin_url('tools.php?page=wp-migrate-db&download=true');
|
564 |
?>
|
565 |
+
<meta http-equiv="refresh" content="1;url=<?php echo $url; ?>"/>
|
566 |
<?php
|
567 |
}
|
568 |
}
|
573 |
if (is_admin()) {
|
574 |
add_action('admin_menu', array($wpmdb, 'admin_menu'));
|
575 |
|
576 |
+
if (isset($_GET['page']) && $_GET['page'] == 'wp-migrate-db') {
|
577 |
+
if (isset($_POST['savefile']) && $_POST['savefile']) {
|
578 |
+
add_action('admin_head-tools_page_wp-migrate-db', array($wpmdb, 'admin_head'));
|
579 |
+
}
|
580 |
+
|
581 |
+
if (isset($_GET['download']) && $_GET['download']) {
|
582 |
+
add_action('init', array($wpmdb, 'download_file'));
|
583 |
+
}
|
584 |
+
}
|
585 |
}
|
586 |
?>
|