All-in-One WP Migration - Version 1.2.0

Version Description

  • Increased upload limit of files from 150MB to 500MB
  • Use ZipArchive with fallback to PclZip (a few users notified us that they dont have ZipArchive enabled on their servers)
  • Use PDO with fallback to mysql (a few users notified us that they dont have PDO enabled on their servers, mysql is deprecated as of PHP v5.5 but we are supporting PHP v5.2.17).
  • Support for PHP v5.2.17 and WordPress v3.3 and above.
  • Fix a bug during export that causes plugins to not be exported on some hosts (the problem that you are experiencing).
Download this release

Release Info

Developer yani.iliev
Plugin Icon 128x128 All-in-One WP Migration
Version 1.2.0
Comparing to
See all releases

Code changes from version 1.1.0 to 1.2.0

Files changed (33) hide show
  1. all-in-one-wp-migration.php +1 -1
  2. constants.php +15 -2
  3. lib/controller/class-ai1wm-export-controller.php +4 -1
  4. lib/controller/class-ai1wm-main-controller.php +9 -3
  5. lib/model/class-ai1wm-export.php +82 -28
  6. lib/model/class-ai1wm-import.php +58 -18
  7. lib/vendor/mysqldump-factory/mysqldump-factory/LICENSE +20 -0
  8. lib/vendor/mysqldump-factory/mysqldump-factory/README.md +34 -0
  9. lib/vendor/mysqldump-factory/mysqldump-factory/bump_version.sh +63 -0
  10. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpFactory.php +69 -0
  11. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpInterface.php +196 -0
  12. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpPDO.php +497 -0
  13. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpSQL.php +490 -0
  14. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlFileAdapter.php +74 -0
  15. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlQueryAdapter.php +109 -0
  16. lib/vendor/mysqldump-php/mysqldump.php +0 -603
  17. lib/vendor/zip-factory/zip-factory/LICENSE +20 -0
  18. lib/vendor/zip-factory/zip-factory/README.md +31 -0
  19. lib/vendor/zip-factory/zip-factory/bump-version.sh +63 -0
  20. lib/vendor/zip-factory/zip-factory/lib/ArchiverInterface.php +117 -0
  21. lib/vendor/zip-factory/zip-factory/lib/ArchiverPclZip.php +191 -0
  22. lib/vendor/zip-factory/zip-factory/lib/ArchiverZipArchive.php +214 -0
  23. lib/vendor/zip-factory/zip-factory/lib/ZipFactory.php +69 -0
  24. lib/vendor/zip-factory/zip-factory/lib/vendor/pclzip-2-8-2/gnu-lgpl.txt +504 -0
  25. lib/vendor/zip-factory/zip-factory/lib/vendor/pclzip-2-8-2/pclzip.lib.php +5690 -0
  26. lib/vendor/zip-factory/zip-factory/lib/vendor/pclzip-2-8-2/readme.txt +421 -0
  27. lib/vendor/zipper/zipper.lib.php +0 -62
  28. lib/view/assets/css/export.min.css +1 -1
  29. lib/view/assets/css/import.min.css +1 -1
  30. lib/view/assets/javascript/import.min.js +1 -1
  31. lib/view/export/index.php +5 -8
  32. loader.php +49 -55
  33. readme.txt +35 -2
all-in-one-wp-migration.php CHANGED
@@ -5,7 +5,7 @@
5
* Description: Migration tool for all your blog data
6
* Author: ServMask
7
* Author URI: http://servmask.com/
8
- * Version: 1.1.0
9
*
10
* Copyright (C) 2013 ServMask LLC
11
*
5
* Description: Migration tool for all your blog data
6
* Author: ServMask
7
* Author URI: http://servmask.com/
8
+ * Version: 1.2.0
9
*
10
* Copyright (C) 2013 ServMask LLC
11
*
constants.php CHANGED
@@ -56,9 +56,9 @@ define( 'BANDAR_TEMPLATES_PATH', AI1WM_LIB_PATH . DIRECTORY_SEPARATOR . 'view' )
56
// ==================
57
define( 'AI1WM_EXCEPTION_PATH', AI1WM_LIB_PATH . DIRECTORY_SEPARATOR . 'exception' );
58
59
- // ===================
60
// = Vendor Path =
61
- // ===================
62
define( 'AI1WM_VENDOR_PATH', AI1WM_LIB_PATH . DIRECTORY_SEPARATOR . 'vendor' );
63
64
// ==============
@@ -70,3 +70,16 @@ define( 'AI1WM_URL', plugins_url( '', __FILE__ ) );
70
// = ServMask Feedback Url =
71
// ==============
72
define( 'AI1WM_FEEDBACK_URL', 'https://servmask.com/ai1wm/feedback/create' );
56
// ==================
57
define( 'AI1WM_EXCEPTION_PATH', AI1WM_LIB_PATH . DIRECTORY_SEPARATOR . 'exception' );
58
59
+ // ===============
60
// = Vendor Path =
61
+ // ===============
62
define( 'AI1WM_VENDOR_PATH', AI1WM_LIB_PATH . DIRECTORY_SEPARATOR . 'vendor' );
63
64
// ==============
70
// = ServMask Feedback Url =
71
// ==============
72
define( 'AI1WM_FEEDBACK_URL', 'https://servmask.com/ai1wm/feedback/create' );
73
+
74
+ // ===========================
75
+ // = WP_CONTENT_DIR Constant =
76
+ // ===========================
77
+ if ( ! defined( 'WP_CONTENT_DIR' ) )
78
+ define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
79
+
80
+ // ==========================
81
+ // = WP_PLUGIN_DIR Constant =
82
+ // ==========================
83
+ if ( ! defined( 'WP_PLUGIN_DIR' ) )
84
+ define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
85
+
lib/controller/class-ai1wm-export-controller.php CHANGED
@@ -20,7 +20,10 @@ class Ai1wm_Export_Controller
20
{
21
public static function index() {
22
$model = new Ai1wm_Export;
23
- Ai1wm_Template::render( 'export/index' );
24
}
25
26
public static function export() {
20
{
21
public static function index() {
22
$model = new Ai1wm_Export;
23
+ Ai1wm_Template::render( 'export/index', array(
24
+ 'list_plugins' => get_plugins(),
25
+ )
26
+ );
27
}
28
29
public static function export() {
lib/controller/class-ai1wm-main-controller.php CHANGED
@@ -65,7 +65,7 @@ class Ai1wm_Main_Controller
65
add_action( 'wp_ajax_upload_file', 'Ai1wm_Import_Controller::upload_file' );
66
67
// Enable or disable maintenance mode
68
- if ( get_option( 'maintenance_mode' ) ) {
69
add_action( 'get_header', array( $this, 'activate_maintenance_mode' ) );
70
}
71
@@ -112,7 +112,7 @@ class Ai1wm_Main_Controller
112
113
// Set Message
114
$message = null;
115
- if ( isset( $_POST['email'] ) ) {
116
$message = trim( $_POST['message'] );
117
}
118
@@ -130,15 +130,21 @@ class Ai1wm_Main_Controller
130
} else if ( ! $terms ) {
131
$errors[] = 'Please accept feedback term conditions.';
132
} else {
133
- wp_remote_post(
134
AI1WM_FEEDBACK_URL,
135
array(
136
'body' => array(
137
'email' => $email,
138
'message' => $message,
139
),
140
)
141
);
142
}
143
144
echo json_encode( array( 'errors' => $errors ) );
65
add_action( 'wp_ajax_upload_file', 'Ai1wm_Import_Controller::upload_file' );
66
67
// Enable or disable maintenance mode
68
+ if ( get_option( Ai1wm_Import::MAINTENANCE_MODE ) ) {
69
add_action( 'get_header', array( $this, 'activate_maintenance_mode' ) );
70
}
71
112
113
// Set Message
114
$message = null;
115
+ if ( isset( $_POST['message'] ) ) {
116
$message = trim( $_POST['message'] );
117
}
118
130
} else if ( ! $terms ) {
131
$errors[] = 'Please accept feedback term conditions.';
132
} else {
133
+ $response = wp_remote_post(
134
AI1WM_FEEDBACK_URL,
135
array(
136
'body' => array(
137
'email' => $email,
138
'message' => $message,
139
+ 'export_last_options' => get_option( Ai1wm_Export::EXPORT_LAST_OPTIONS ),
140
),
141
)
142
);
143
+
144
+ if ( is_wp_error( $response ) ) {
145
+ $errors[] = 'Something went wrong: ' .
146
+ $response->get_error_message();
147
+ }
148
}
149
150
echo json_encode( array( 'errors' => $errors ) );
lib/model/class-ai1wm-export.php CHANGED
@@ -18,20 +18,24 @@
18
19
class Ai1wm_Export
20
{
21
- const EXPORT_ARCHIVE_NAME = 'dump';
22
-
23
const EXPORT_DATABASE_NAME = 'database.sql';
24
-
25
- const EXPORT_PACKAGE_NAME = 'package.json';
26
-
27
- const EXPORT_MEDIA_NAME = 'media';
28
-
29
- const EXPORT_THEMES_NAME = 'themes';
30
31
protected $connection = null;
32
33
public function __construct() {
34
- $this->connection = new Mysqldump( DB_NAME, DB_USER, DB_PASSWORD, DB_HOST, 'mysql' );
35
}
36
37
/**
@@ -42,7 +46,11 @@ class Ai1wm_Export
42
* @return string Absolute file path
43
*/
44
public function export( $output_file, array $options = array() ) {
45
- $archive = new Zipper( $output_file );
46
47
// Should we export database?
48
if ( ! isset( $options['export-database' ] ) ) {
@@ -69,6 +77,14 @@ class Ai1wm_Export
69
);
70
}
71
72
// Add package
73
$archive->addFromString(
74
self::EXPORT_PACKAGE_NAME,
@@ -88,17 +104,23 @@ class Ai1wm_Export
88
public function prepare_database( $output_file, array $options = array() ) {
89
global $wpdb;
90
91
- $settings = array(
92
- 'include-tables' => isset( $options['include-tables'] ) ? $options['include-tables'] : array(),
93
- 'exclude-tables' => isset( $options['exclude-tables'] ) ? $options['exclude-tables'] : array(),
94
- 'compress' => 'None',
95
- 'no-data' => isset( $options['export-table-data'] ),
96
- 'add-drop-table' => isset( $options['add-drop-table'] ),
97
- 'single-transaction' => isset( $options['export-single-transaction'] ),
98
- 'lock-tables' => isset( $options['export-lock-tables'] ),
99
- 'add-locks' => true,
100
- 'extended-insert' => true,
101
- );
102
103
$clauses = array();
104
@@ -125,9 +147,16 @@ class Ai1wm_Export
125
126
$output_meta = stream_get_meta_data( $output_file );
127
128
- // Export Database
129
- $this->connection->set( $settings );
130
- $this->connection->start( $output_meta['uri'], $clauses );
131
132
// Replace Old/New Values
133
if (
@@ -158,7 +187,20 @@ class Ai1wm_Export
158
// Replace serialized string values
159
$data = preg_replace(
160
'!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!e',
161
- "'s:'.strlen( $this->unescape_mysql( '$3' ) ).':\"'. $this->unescape_quotes( '$3' ) .'\";'",
162
$data
163
);
164
if ( $data ) {
@@ -169,7 +211,6 @@ class Ai1wm_Export
169
}
170
}
171
172
-
173
return $output_meta['uri'];
174
}
175
@@ -179,7 +220,7 @@ class Ai1wm_Export
179
* @param [type] $value [description]
180
* @return [type] [description]
181
*/
182
- public function unescape_mysql( $value ) {
183
return str_replace(
184
array( '\\\\', '\\0', "\\n", "\\r", '\Z', "\'", '\"', ),
185
array( '\\', '\0', "\n", "\r", "\x1a", "'", '"', ),
@@ -193,7 +234,7 @@ class Ai1wm_Export
193
* @param [type] $value [description]
194
* @return [type] [description]
195
*/
196
- public function unescape_quotes( $value ) {
197
return str_replace( '\"', '"', $value );
198
}
199
@@ -225,6 +266,19 @@ class Ai1wm_Export
225
}
226
}
227
228
/**
229
* Export package json file which includes information about installed plugins and etc.
230
*
18
19
class Ai1wm_Export
20
{
21
+ const EXPORT_ARCHIVE_NAME = 'dump';
22
const EXPORT_DATABASE_NAME = 'database.sql';
23
+ const EXPORT_PACKAGE_NAME = 'package.json';
24
+ const EXPORT_MEDIA_NAME = 'media';
25
+ const EXPORT_PLUGINS_NAME = 'plugins';
26
+ const EXPORT_THEMES_NAME = 'themes';
27
+ const EXPORT_LAST_OPTIONS = 'ai1wm_export_last_options';
28
29
protected $connection = null;
30
31
public function __construct() {
32
+ $this->connection = MysqlDumpFactory::makeMysqlDump(
33
+ DB_HOST,
34
+ DB_USER,
35
+ DB_PASSWORD,
36
+ DB_NAME,
37
+ class_exists( 'PDO' )
38
+ );
39
}
40
41
/**
46
* @return string Absolute file path
47
*/
48
public function export( $output_file, array $options = array() ) {
49
+ // Export last options
50
+ update_option( self::EXPORT_LAST_OPTIONS, json_encode( $options ) );
51
+
52
+ // Make archive
53
+ $archive = ZipFactory::makeZipArchiver( $output_file, ! class_exists( 'ZipArchive' ) );
54
55
// Should we export database?
56
if ( ! isset( $options['export-database' ] ) ) {
77
);
78
}
79
80
+ // Should we export plugins?
81
+ if ( ! isset( $options['export-plugins'] ) ) {
82
+ $archive->addDir(
83
+ $this->prepare_plugins( $options ),
84
+ self::EXPORT_PLUGINS_NAME
85
+ );
86
+ }
87
+
88
// Add package
89
$archive->addFromString(
90
self::EXPORT_PACKAGE_NAME,
104
public function prepare_database( $output_file, array $options = array() ) {
105
global $wpdb;
106
107
+ // Set include tables
108
+ $includeTables = array();
109
+ if ( isset( $options['include-tables'] ) ) {
110
+ $includeTables = $options['include-tables'];
111
+ }
112
+
113
+ // Set exclude tables
114
+ $excludeTables = array();
115
+ if ( isset( $options['exclude-tables' ] ) ) {
116
+ $excludeTables = $options['exclude-tables'];
117
+ }
118
+
119
+ // Set no table data
120
+ $noTableData = false;
121
+ if ( isset( $options['no-table-data'] ) ) {
122
+ $noTableData = true;
123
+ }
124
125
$clauses = array();
126
147
148
$output_meta = stream_get_meta_data( $output_file );
149
150
+ // Set dump options
151
+ $this->connection
152
+ ->setFileName( $output_meta['uri'] )
153
+ ->setIncludeTables( $includeTables )
154
+ ->setExcludeTables( $excludeTables )
155
+ ->setNoTableData( $noTableData )
156
+ ->setQueryClauses( $clauses );
157
+
158
+ // Make dump
159
+ $this->connection->dump();
160
161
// Replace Old/New Values
162
if (
187
// Replace serialized string values
188
$data = preg_replace(
189
'!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!e',
190
+ "'s:'.strlen( Ai1wm_Export::unescape_mysql( '$3' ) ).':\"'. Ai1wm_Export::unescape_quotes( '$3' ) .'\";'",
191
+ $data
192
+ );
193
+ if ( $data ) {
194
+ ftruncate( $output_file, 0 );
195
+ rewind( $output_file );
196
+ fwrite( $output_file, $data );
197
+ }
198
+ } else {
199
+ $data = stream_get_contents( $output_file );
200
+ // Replace serialized string values
201
+ $data = preg_replace(
202
+ '!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!e',
203
+ "'s:'.strlen( Ai1wm_Export::unescape_mysql( '$3' ) ).':\"'. Ai1wm_Export::unescape_quotes( '$3' ) .'\";'",
204
$data
205
);
206
if ( $data ) {
211
}
212
}
213
214
return $output_meta['uri'];
215
}
216
220
* @param [type] $value [description]
221
* @return [type] [description]
222
*/
223
+ public static function unescape_mysql( $value ) {
224
return str_replace(
225
array( '\\\\', '\\0', "\\n", "\\r", '\Z', "\'", '\"', ),
226
array( '\\', '\0', "\n", "\r", "\x1a", "'", '"', ),
234
* @param [type] $value [description]
235
* @return [type] [description]
236
*/
237
+ public static function unescape_quotes( $value ) {
238
return str_replace( '\"', '"', $value );
239
}
240
266
}
267
}
268
269
+ /**
270
+ * Export plugins root directory
271
+ *
272
+ * @param array $options Export settings
273
+ * @return string Plugins root directory
274
+ */
275
+ public function prepare_plugins( array $options = array() ) {
276
+ if ( ! isset( $options['export-plugins'] ) ) {
277
+
278
+ return WP_PLUGIN_DIR;
279
+ }
280
+ }
281
+
282
/**
283
* Export package json file which includes information about installed plugins and etc.
284
*
lib/model/class-ai1wm-import.php CHANGED
@@ -18,14 +18,19 @@
18
19
class Ai1wm_Import
20
{
21
- const MAX_FILE_SIZE = '128MB';
22
-
23
- const MAX_CHUNK_SIZE = '1MB';
24
-
25
const MAX_CHUNK_RETRIES = 10;
26
27
public function __construct() {
28
- $this->connection = new Mysqldump( DB_NAME, DB_USER, DB_PASSWORD, DB_HOST, 'mysql' );
29
}
30
31
/**
@@ -40,11 +45,11 @@ class Ai1wm_Import
40
41
if ( empty( $input_file['error'] ) ) {
42
// Partial file path
43
- $uploadfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR
44
- . $options['name'];
45
46
// Open partial file
47
- $out = fopen( $uploadfile, $options['chunk'] == 0 ? 'wb' : 'ab' );
48
if ( $out ) {
49
// Read binary input stream and append it to temp file
50
$in = fopen( $input_file['tmp_name'], 'rb' );
@@ -72,7 +77,7 @@ class Ai1wm_Import
72
}
73
74
// Extract archive to a temporary directory
75
- $archive = new Zipper( $uploadfile );
76
$archive->extractTo( $extract_to );
77
$archive->close();
78
@@ -106,7 +111,7 @@ class Ai1wm_Import
106
$this->connection->truncateDatabase();
107
108
// Import database
109
- $this->connection->importFromFile( $extract_to . Ai1wm_Export::EXPORT_DATABASE_NAME );
110
}
111
112
// Check if media files are present
@@ -146,6 +151,24 @@ class Ai1wm_Import
146
$this->copy_dir( $extract_to . Ai1wm_Export::EXPORT_THEMES_NAME, $themes_basedir );
147
}
148
149
if ( file_exists( $extract_to . Ai1wm_Export::EXPORT_PACKAGE_NAME ) ) {
150
151
// Install selected plugins
@@ -159,7 +182,7 @@ class Ai1wm_Import
159
$this->connection->truncateDatabase();
160
161
// Import "OLD" database
162
- $this->connection->importFromFile( $database_file );
163
}
164
165
if ( file_exists( $extract_to . Ai1wm_Export::EXPORT_MEDIA_NAME ) ) {
@@ -177,6 +200,14 @@ class Ai1wm_Import
177
// Import "OLD" themes files
178
$this->copy_dir( $backup_themes_to, $themes_basedir );
179
}
180
}
181
182
// Disable maintenance mode
@@ -194,13 +225,13 @@ class Ai1wm_Import
194
195
196
/**
197
- * Enable or disable Wordpress maintenance mode
198
*
199
* @param boolean $enabled Enable or disable maintenance mode
200
* @return boolean True if option value has changed, false if not or if update failed
201
*/
202
public function maintenance_mode( $enabled = true ) {
203
- return update_option( 'maintenance_mode', $enabled );
204
}
205
206
/**
@@ -211,12 +242,18 @@ class Ai1wm_Import
211
* @return void
212
*/
213
public function copy_dir( $from, $to ) {
214
$iterator = new RecursiveIteratorIterator(
215
- new RecursiveDirectoryIterator( $from, RecursiveDirectoryIterator::SKIP_DOTS ),
216
RecursiveIteratorIterator::SELF_FIRST
217
);
218
219
foreach ( $iterator as $item ) {
220
if ( $item->isDir() ) {
221
mkdir( $to . $iterator->getSubPathName() );
222
} else {
@@ -232,14 +269,18 @@ class Ai1wm_Import
232
* @return void
233
*/
234
public function truncate_dir( $dir ) {
235
$iterator = new RecursiveIteratorIterator(
236
- new RecursiveDirectoryIterator( $dir, RecursiveDirectoryIterator::SKIP_DOTS ),
237
RecursiveIteratorIterator::CHILD_FIRST
238
);
239
240
foreach ( $iterator as $item ) {
241
if ( $item->isDir() ) {
242
- rmdir ( $dir . $iterator->getSubPathName() );
243
} else {
244
unlink( $dir . $iterator->getSubPathName() );
245
}
@@ -253,7 +294,7 @@ class Ai1wm_Import
253
* @return void
254
*/
255
public function install_plugins( $path ) {
256
- $file = file_get_contents( $path );
257
$package = json_decode( $file, true );
258
259
// For Plugins API
@@ -300,7 +341,6 @@ class Ai1wm_Import
300
*/
301
public function is_valid( $path ) {
302
$required_objects = array(
303
- Ai1wm_Export::EXPORT_DATABASE_NAME,
304
Ai1wm_Export::EXPORT_PACKAGE_NAME,
305
);
306
18
19
class Ai1wm_Import
20
{
21
+ const MAX_FILE_SIZE = '512MB';
22
+ const MAX_CHUNK_SIZE = '1MB';
23
const MAX_CHUNK_RETRIES = 10;
24
+ const MAINTENANCE_MODE = 'ai1wm_maintenance_mode';
25
26
public function __construct() {
27
+ $this->connection = MysqlDumpFactory::makeMysqlDump(
28
+ DB_HOST,
29
+ DB_USER,
30
+ DB_PASSWORD,
31
+ DB_NAME,
32
+ class_exists( 'PDO' )
33
+ );
34
}
35
36
/**
45
46
if ( empty( $input_file['error'] ) ) {
47
// Partial file path
48
+ $upload_file = sys_get_temp_dir() . DIRECTORY_SEPARATOR
49
+ . $options['name'];
50
51
// Open partial file
52
+ $out = fopen( $upload_file, $options['chunk'] == 0 ? 'wb' : 'ab' );
53
if ( $out ) {
54
// Read binary input stream and append it to temp file
55
$in = fopen( $input_file['tmp_name'], 'rb' );
77
}
78
79
// Extract archive to a temporary directory
80
+ $archive = ZipFactory::makeZipArchiver( $upload_file, ! class_exists( 'ZipArchive' ) );
81
$archive->extractTo( $extract_to );
82
$archive->close();
83
111
$this->connection->truncateDatabase();
112
113
// Import database
114
+ $this->connection->import( $extract_to . Ai1wm_Export::EXPORT_DATABASE_NAME );
115
}
116
117
// Check if media files are present
151
$this->copy_dir( $extract_to . Ai1wm_Export::EXPORT_THEMES_NAME, $themes_basedir );
152
}
153
154
+ if ( file_exists( $extract_to . Ai1wm_Export::EXPORT_PLUGINS_NAME ) ) {
155
+ // Backup plugin files
156
+ $backup_plugins_to = sys_get_temp_dir() . DIRECTORY_SEPARATOR
157
+ . uniqid()
158
+ . DIRECTORY_SEPARATOR;
159
+ if ( ! is_dir( $backup_plugins_to ) ) {
160
+ mkdir( $backup_plugins_to );
161
+ }
162
+
163
+ $this->copy_dir( WP_PLUGIN_DIR, $backup_plugins_to );
164
+
165
+ // Truncate plugin files
166
+ $this->truncate_dir( WP_PLUGIN_DIR );
167
+
168
+ // Import plugin files
169
+ $this->copy_dir( $extract_to . Ai1wm_Export::EXPORT_PLUGINS_NAME, WP_PLUGIN_DIR );
170
+ }
171
+
172
if ( file_exists( $extract_to . Ai1wm_Export::EXPORT_PACKAGE_NAME ) ) {
173
174
// Install selected plugins
182
$this->connection->truncateDatabase();
183
184
// Import "OLD" database
185
+ $this->connection->import( $database_file );
186
}
187
188
if ( file_exists( $extract_to . Ai1wm_Export::EXPORT_MEDIA_NAME ) ) {
200
// Import "OLD" themes files
201
$this->copy_dir( $backup_themes_to, $themes_basedir );
202
}
203
+
204
+ if ( file_exists( $extract_to . Ai1wm_Export::EXPORT_PLUGINS_NAME ) ) {
205
+ // Truncate plugin files
206
+ $this->truncate_dir( WP_PLUGIN_DIR );
207
+
208
+ // Import "OLD" plugin files
209
+ $this->copy_dir( $backup_plugins_to, WP_PLUGIN_DIR );
210
+ }
211
}
212
213
// Disable maintenance mode
225
226
227
/**
228
+ * Enable or disable WordPress maintenance mode
229
*
230
* @param boolean $enabled Enable or disable maintenance mode
231
* @return boolean True if option value has changed, false if not or if update failed
232
*/
233
public function maintenance_mode( $enabled = true ) {
234
+ return update_option( self::MAINTENANCE_MODE, $enabled );
235
}
236
237
/**
242
* @return void
243
*/
244
public function copy_dir( $from, $to ) {
245
+ $from = trailingslashit( $from );
246
+ $to = trailingslashit( $to );
247
+
248
$iterator = new RecursiveIteratorIterator(
249
+ $rdi = new RecursiveDirectoryIterator( $from ),
250
RecursiveIteratorIterator::SELF_FIRST
251
);
252
253
foreach ( $iterator as $item ) {
254
+ // Skip dots
255
+ if ( $iterator->isDot() ) continue;
256
+
257
if ( $item->isDir() ) {
258
mkdir( $to . $iterator->getSubPathName() );
259
} else {
269
* @return void
270
*/
271
public function truncate_dir( $dir ) {
272
+ $dir = trailingslashit( $dir );
273
$iterator = new RecursiveIteratorIterator(
274
+ $rdi = new RecursiveDirectoryIterator( $dir ),
275
RecursiveIteratorIterator::CHILD_FIRST
276
);
277
278
foreach ( $iterator as $item ) {
279
+ // Skip dots
280
+ if ( $iterator->isDot() ) continue;
281
+
282
if ( $item->isDir() ) {
283
+ rmdir( $dir . $iterator->getSubPathName() );
284
} else {
285
unlink( $dir . $iterator->getSubPathName() );
286
}
294
* @return void
295
*/
296
public function install_plugins( $path ) {
297
+ $file = file_get_contents( $path );
298
$package = json_decode( $file, true );
299
300
// For Plugins API
341
*/
342
public function is_valid( $path ) {
343
$required_objects = array(
344
Ai1wm_Export::EXPORT_PACKAGE_NAME,
345
);
346
lib/vendor/mysqldump-factory/mysqldump-factory/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Yani Iliev, Bobby Angelov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
lib/vendor/mysqldump-factory/mysqldump-factory/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # MySQL Dump Factory
2
+
3
+ [![Build Status](https://travis-ci.org/yani-/mysqldump-factory.png?branch=master)](https://travis-ci.org/yani-/mysqldump-factory)
4
+ [![Latest Stable Version](https://poser.pugx.org/mysqldump-factory/mysqldump-factory/v/stable.png)](https://packagist.org/packages/mysqldump-factory/mysqldump-factory)
5
+ [![Total Downloads](https://poser.pugx.org/mysqldump-factory/mysqldump-factory/downloads.png)](https://packagist.org/packages/mysqldump-factory/mysqldump-factory)
6
+
7
+ MySQL Dump Factory class that creates either mysql or PDO classes
8
+
9
+ ### Requirements
10
+ PHP v5.2 and up. Tested on PHP v5.2.17, v5.3, v5.4, v5.5
11
+
12
+ ### Usage
13
+ ```php
14
+ require_once 'lib/MysqlDumpFactory.php';
15
+ $mc = MysqlDumpFactory::makeMysqlDump('dbhost', 'dbuser', 'dbpass', 'dbname',class_exists('PDO'));
16
+ ```
17
+
18
+ ### Tests
19
+ Coverage reports are stored inside the coverage folder.
20
+ ```bash
21
+ phpunit
22
+ ```
23
+
24
+ ### Contributing
25
+ For code guidelines refer to `.editorconfig`. This project is following PEAR code standard - http://pear.php.net/manual/en/standards.php
26
+ The project is following Vincent Driessen's branching model aka git flow - http://nvie.com/git-model/
27
+ Make sure to submit your pull requests against the **develop** branch
28
+
29
+ ### License
30
+ MIT
31
+
32
+ ### Authors
33
+ * Yani Iliev
34
+ * Bobby Angelov
lib/vendor/mysqldump-factory/mysqldump-factory/bump_version.sh ADDED
@@ -0,0 +1,63 @@
1
+ #!/bin/bash
2
+
3
+ if [ -z "$1" ]; then
4
+ echo -e "\033[0;31mUsage:\033[0m $0 (major|minor|patch)\033[0m"
5
+ echo -e "\033[4;32mCurrent version\033[0m:\033[0m \033[33m`git describe master`\033[0m"
6
+ exit -1
7
+ fi
8
+
9
+ # increment version depending on passed parameter
10
+ case "$1" in
11
+ major)
12
+ currentVersion=`git describe master`
13
+ bumpedVersion=`echo $currentVersion | ( IFS=".$IFS" ; read a b c && echo $((a + 1)).0.0 )`
14
+ ;;
15
+ minor)
16
+ currentVersion=`git describe master`
17
+ bumpedVersion=`echo $currentVersion | ( IFS=".$IFS" ; read a b c && echo $a.$((b + 1)).0 )`
18
+ ;;
19
+ patch)
20
+ currentVersion=`git describe master`
21
+ bumpedVersion=`echo $currentVersion | ( IFS=".$IFS" ; read a b c && echo $a.$b.$((c + 1)) )`
22
+ ;;
23
+ *)
24
+ echo -e "\033[0;31mUsage:\033[0m $0 (major|minor|patch)\033[0m"
25
+ echo -e "\033[4;32mCurrent version\033[0m:\033[0m \033[33m`git describe master`\033[0m"
26
+ exit -1
27
+ esac
28
+
29
+ # let's start a new release
30
+ git flow release start $bumpedVersion
31
+
32
+ # bump version in all files
33
+ for file in `find . -path ./coverage -prune -o -path ./.git -prune -o -type f`
34
+ do
35
+ filename=$(basename "$file")
36
+ ext="${filename##*.}"
37
+ if [ $ext != "png" -a $ext != "jpg" -a $ext != "jpeg" -a $ext != "gif" ]; then
38
+ if [ $ext != "DS_Store" -a $ext != "ttf" -a $ext != "node_modules" -a $ext != "git" ]; then
39
+ sed -i '' "s/GIT: $currentVersion/GIT: $bumpedVersion/g" $file
40
+ fi
41
+ fi
42
+ done
43
+
44
+ # bump version in package.json
45
+ sed -i '' "s/\"version\": \"$currentVersion\"/\"version\": \"$bumpedVersion\"/g" package.json
46
+
47
+ # add changed files to git
48
+ git add . && git commit -m "Bumped version from $currentVersion to $bumpedVersion"
49
+
50
+ # finish the release
51
+ git flow release finish -F -m "$bumpedVersion" $bumpedVersion
52
+
53
+ # publish develop branch
54
+ git checkout develop && git push origin develop
55
+
56
+ # publish master
57
+ git checkout master && git push origin master
58
+
59
+ # publish tags
60
+ git push origin --tags
61
+
62
+ # Announce the result
63
+ echo -e "\033[4;32mSuccessfully released\033[0m:\033[0m \033[33m$bumpedVersion\033[0m"
lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpFactory.php ADDED
@@ -0,0 +1,69 @@
1
+ <?php
2
+ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
+
4
+ /**
5
+ * Factory class main file
6
+ *
7
+ * PHP version 5
8
+ *
9
+ * LICENSE: Permission is hereby granted, free of charge, to any person obtaining
10
+ * a copy of this software and associated documentation files (the "Software"), to
11
+ * deal in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
13
+ * of the Software, and to permit persons to whom the Software is furnished to do so,
14
+ * subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
21
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
22
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
23
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+ *
26
+ * @category Databases
27
+ * @package MysqlDumpFactory
28
+ * @author Yani Iliev <yani@iliev.me>
29
+ * @author Bobby Angelov <bobby@servmask.com>
30
+ * @copyright 2014 Yani Iliev, Bobby Angelov
31
+ * @license https://raw.github.com/yani-/mysqldump-factory/master/LICENSE The MIT License (MIT)
32
+ * @version GIT: 1.0.4
33
+ * @link https://github.com/yani-/mysqldump-factory/
34
+ */
35
+
36
+ /**
37
+ * Factory Main class
38
+ *
39
+ * @category Databases
40
+ * @package MysqlDumpFactory
41
+ * @author Yani Iliev <yani@iliev.me>
42
+ * @author Bobby Angelov <bobby@servmask.com>
43
+ * @copyright 2014 Yani Iliev, Bobby Angelov
44
+ * @license https://raw.github.com/yani-/mysqldump-factory/master/LICENSE The MIT License (MIT)
45
+ * @version GIT: 1.0.4
46
+ * @link https://github.com/yani-/mysqldump-factory/
47
+ */
48
+ class MysqlDumpFactory
49
+ {
50
+ public static function makeMysqlDump($hostname = 'localhost', $username = '', $password = '', $database = '', $pdo = false)
51
+ {
52
+ // is PDO class available?
53
+ if ($pdo) {
54
+ require_once
55
+ dirname(__FILE__) .
56
+ DIRECTORY_SEPARATOR .
57
+ 'MysqlDumpPDO.php';
58
+
59
+ return new MysqlDumpPDO($hostname, $username, $password, $database);
60
+ } else {
61
+ require_once
62
+ dirname(__FILE__) .
63
+ DIRECTORY_SEPARATOR .
64
+ 'MysqlDumpSQL.php';
65
+
66
+ return new MysqlDumpSQL($hostname, $username, $password, $database);
67
+ }
68
+ }
69
+ }
lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpInterface.php ADDED
@@ -0,0 +1,196 @@
1
+ <?php
2
+ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
+
4
+ /**
5
+ * MysqlDump interface
6
+ *
7
+ * PHP version 5
8
+ *
9
+ * LICENSE: Permission is hereby granted, free of charge, to any person obtaining
10
+ * a copy of this software and associated documentation files (the "Software"), to
11
+ * deal in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
13
+ * of the Software, and to permit persons to whom the Software is furnished to do so,
14
+ * subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
21
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
22
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
23
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+ *
26
+ * @category Databases
27
+ * @package MysqlDumpFactory
28
+ * @author Yani Iliev <yani@iliev.me>
29
+ * @author Bobby Angelov <bobby@servmask.com>
30
+ * @copyright 2014 Yani Iliev, Bobby Angelov
31
+ * @license https://raw.github.com/yani-/mysqldump-factory/master/LICENSE The MIT License (MIT)
32
+ * @version GIT: 1.0.4
33
+ * @link https://github.com/yani-/mysqldump-factory/
34
+ */
35
+
36
+ /**
37
+ * MysqlDump interface
38
+ *
39
+ * @category Databases
40
+ * @package MysqlDumpFactory
41
+ * @author Yani Iliev <yani@iliev.me>
42
+ * @author Bobby Angelov <bobby@servmask.com>
43
+ * @copyright 2014 Yani Iliev, Bobby Angelov
44
+ * @license https://raw.github.com/yani-/mysqldump-factory/master/LICENSE The MIT License (MIT)
45
+ * @version GIT: 1.0.4
46
+ * @link https://github.com/yani-/mysqldump-factory/
47
+ */
48
+ interface MysqlDumpInterface
49
+ {
50
+ const MAXLINESIZE = 1000000;
51
+
52
+ /**
53
+ * Define MySQL credentials for the current connection
54
+ *
55
+ * @param string $hostname MySQL Hostname
56
+ * @param string $username MySQL Username
57
+ * @param string $password MySQL Password
58
+ * @param string $database MySQL Database
59
+ * @return void
60
+ */
61
+ public function __construct($hostname = 'localhost', $username = '', $password = '', $database = '');
62
+
63
+ /**
64
+ * Dump database into a file
65
+ *
66
+ * @return void
67
+ */
68
+ public function dump();
69
+
70
+ /**
71
+ * Set output file name
72
+ *
73
+ * @param string $fileName Name of the output file
74
+ * @return string
75
+ */
76
+ public function setFileName($fileName);
77
+
78
+ /**
79
+ * Get output file name
80
+ *
81
+ * @return string
82
+ */
83
+ public function getFileName();
84
+
85
+ /**
86
+ * Set query clauses
87
+ *
88
+ * @param array $clauses List of SQL query clauses
89
+ * @return array
90
+ */
91
+ public function setQueryClauses($clauses);
92
+
93
+ /**
94
+ * Get query clauses
95
+ *
96
+ * @return array
97
+ */
98
+ public function getQueryClauses();
99
+
100
+ /**
101
+ * Set include tables
102
+ *
103
+ * @param array $tables List of tables
104
+ * @return array
105
+ */
106
+ public function setIncludeTables($tables);
107
+
108
+ /**
109
+ * Get include tables
110
+ *
111
+ * @return array
112
+ */
113
+ public function getIncludeTables();
114
+
115
+ /**
116
+ * Set exclude tables
117
+ *
118
+ * @param array $tables List of tables
119
+ * @return array
120
+ */
121
+ public function setExcludeTables($tables);
122
+
123
+ /**
124
+ * Get exclude tables
125
+ *
126
+ * @return array
127
+ */
128
+ public function getExcludeTables();
129
+
130
+ /**
131
+ * Set no table data flag
132
+ *
133
+ * @param bool $flag Do not export table data
134
+ * @return bool
135
+ */
136
+ public function setNoTableData($flag);
137
+
138
+ /**
139
+ * Get no table data flag
140
+ *
141
+ * @return bool
142
+ */
143
+ public function getNoTableData();
144
+
145
+ /**
146
+ * Set add drop table flag
147
+ *
148
+ * @param bool $flag Add drop table SQL clause
149
+ * @return bool
150
+ */
151
+ public function setAddDropTable($flag);
152
+
153
+ /**
154
+ * Get add drop table flag
155
+ *
156
+ * @return bool
157
+ */
158
+ public function getAddDropTable();
159
+
160
+ /**
161
+ * Set extended insert flag
162
+ *
163
+ * @param bool $flag Add extended insert SQL clause
164
+ * @return bool
165
+ */
166
+ public function setExtendedInsert($flag);
167
+
168
+ /**
169
+ * Get extended insert flag
170
+ *
171
+ * @return bool
172
+ */
173
+ public function getExtendedInsert();
174
+
175
+ /**
176
+ * Truncate database
177
+ *
178
+ * @return void
179
+ */
180
+ public function truncateDatabase();
181
+
182
+ /**
183
+ * Import database from file
184
+ *
185
+ * @param string $fileName Name of file
186
+ * @return bool
187
+ */
188
+ public function import($fileName);
189
+
190
+ /**
191
+ * Get list of tables
192
+ *
193
+ * @return array
194
+ */
195
+ public function listTables();
196
+ }
lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpPDO.php ADDED
@@ -0,0 +1,497 @@
1
+ <?php
2
+ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
+
4
+ /**
5
+ * MysqlDumpPDO class
6
+ *
7
+ * PHP version 5
8
+ *
9
+ * LICENSE: Permission is hereby granted, free of charge, to any person obtaining
10
+ * a copy of this software and associated documentation files (the "Software"), to
11
+ * deal in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
13
+ * of the Software, and to permit persons to whom the Software is furnished to do so,
14
+ * subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
21
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
22
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
23
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+ *
26
+ * @category Databases
27
+ * @package MysqlDumpFactory
28
+ * @author Yani Iliev <yani@iliev.me>
29
+ * @author Bobby Angelov <bobby@servmask.com>
30
+ * @copyright 2014 Yani Iliev, Bobby Angelov
31
+ * @license https://raw.github.com/yani-/mysqldump-factory/master/LICENSE The MIT License (MIT)
32
+ * @version GIT: 1.0.4
33
+ * @link https://github.com/yani-/mysqldump-factory/
34
+ */
35
+
36
+ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MysqlDumpInterface.php';
37
+ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MysqlQueryAdapter.php';
38
+ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MysqlFileAdapter.php';
39
+
40
+ /**
41
+ * MysqlDumpPDO class
42
+ *
43
+ * @category Databases
44
+ * @package MysqlDumpFactory
45
+ * @author Yani Iliev <yani@iliev.me>
46
+ * @author Bobby Angelov <bobby@servmask.com>
47
+ * @copyright 2014 Yani Iliev, Bobby Angelov
48
+ * @license https://raw.github.com/yani-/mysqldump-factory/master/LICENSE The MIT License (MIT)
49
+ * @version GIT: 1.0.4
50
+ * @link https://github.com/yani-/mysqldump-factory/
51
+ */
52
+ class MysqlDumpPDO implements MysqlDumpInterface
53
+ {
54
+ protected $hostname = null;
55
+
56
+ protected $username = null;
57
+
58
+ protected $password = null;
59
+
60
+ protected $database = null;
61
+
62
+ protected $fileName = 'dump.sql';
63
+
64
+ protected $fileAdapter = null;
65
+
66
+ protected $queryAdapter = null;
67
+
68
+ protected $connection = null;
69
+
70
+ protected $queryClauses = array();
71
+
72
+ protected $includeTables = array();
73
+
74
+ protected $excludeTables = array();
75
+
76
+ protected $noTableData = false;
77
+
78
+ protected $addDropTable = false;
79
+
80
+ protected $extendedInsert = true;
81
+
82
+ /**
83
+ * Define MySQL credentials for the current connection
84
+ *
85
+ * @param string $hostname MySQL Hostname
86
+ * @param string $username MySQL Username
87
+ * @param string $password MySQL Password
88
+ * @param string $database MySQL Database
89
+ * @return void
90
+ */
91
+ public function __construct($hostname = 'localhost', $username = '', $password = '', $database = '')
92
+ {
93
+ // Set MySQL credentials
94
+ $this->hostname = $hostname;
95
+ $this->username = $username;
96
+ $this->password = $password;
97
+ $this->database = $database;
98
+
99
+ // Set Query Adapter
100
+ $this->queryAdapter = new MysqlQueryAdapter('mysql');
101
+ }
102
+
103
+ /**
104
+ * Dump database into a file
105
+ *
106
+ * @return void
107
+ */
108
+ public function dump()
109
+ {
110
+ // Set File Adapter
111
+ $this->fileAdapter = new MysqlFileAdapter();
112
+
113
+ // Set output file
114
+ $this->fileAdapter->open($this->getFileName());
115
+
116
+ // Write Headers Formating dump file
117
+ $this->fileAdapter->write($this->getHeader());
118
+
119
+ // Listing all tables from database
120
+ $tables = array();
121
+ foreach ($this->listTables() as $table) {
122
+ if (count($this->getIncludeTables()) === 0 || in_array($table, $this->getIncludeTables())) {
123
+ $tables[] = $table;
124
+ }
125
+ }
126
+
127
+ // Export Tables
128
+ foreach ($tables as $table) {
129
+ if (in_array($table, $this->getExcludeTables())) {
130
+ continue;
131
+ }
132
+
133
+ $isTable = $this->getTableStructure($table);
134
+ if (true === $isTable) {
135
+ $this->listValues($table);
136
+ }
137
+ }
138
+ }
139
+
140
+ /**
141
+ * Set output file name
142
+ *
143
+ * @param string $fileName Name of the output file
144
+ * @return string
145
+ */
146
+ public function setFileName($fileName)
147
+ {
148
+ $this->fileName = $fileName;
149
+
150
+ return $this;
151
+ }
152
+
153
+ /**
154
+ * Get output file name
155
+ *
156
+ * @return string
157
+ */
158
+ public function getFileName()
159
+ {
160
+ return $this->fileName;
161
+ }
162
+
163
+ /**
164
+ * Set query clauses
165
+ *
166
+ * @param array $clauses List of SQL query clauses
167
+ * @return array
168
+ */
169
+ public function setQueryClauses($clauses)
170
+ {
171
+ $this->queryClauses = $clauses;
172
+
173
+ return $this;
174
+ }
175
+
176
+ /**
177
+ * Get query clauses
178
+ *
179
+ * @return array
180
+ */
181
+ public function getQueryClauses()
182
+ {
183
+ return $this->queryClauses;
184
+ }
185
+
186
+ /**
187
+ * Set include tables
188
+ *
189
+ * @param array $tables List of tables
190
+ * @return array
191
+ */
192
+ public function setIncludeTables($tables)
193
+ {
194
+ $this->includeTables = $tables;
195
+
196
+ return $this;
197
+ }
198
+
199
+ /**
200
+ * Get include tables
201
+ *
202
+ * @return array
203
+ */
204
+ public function getIncludeTables()
205
+ {
206
+ return $this->includeTables;
207
+ }
208
+
209
+ /**
210
+ * Set exclude tables
211
+ *
212
+ * @param array $tables List of tables
213
+ * @return array
214
+ */
215
+ public function setExcludeTables($tables)
216
+ {
217
+ $this->excludeTables = $tables;
218
+
219
+ return $this;
220
+ }
221
+
222
+ /**
223
+ * Get exclude tables
224
+ *
225
+ * @return array
226
+ */
227
+ public function getExcludeTables()
228
+ {
229
+ return $this->excludeTables;
230
+ }
231
+
232
+ /**
233
+ * Set no table data flag
234
+ *
235
+ * @param bool $flag Do not export table data
236
+ * @return bool
237
+ */
238
+ public function setNoTableData($flag)
239
+ {
240
+ $this->noTableData = $flag;
241
+
242
+ return $this;
243
+ }
244
+
245
+ /**
246
+ * Get no table data flag
247
+ *
248
+ * @return bool
249
+ */
250
+ public function getNoTableData()
251
+ {
252
+ return $this->noTableData;
253
+ }
254
+
255
+ /**
256
+ * Set add drop table flag
257
+ *
258
+ * @param bool $flag Add drop table SQL clause
259
+ * @return bool
260
+ */
261
+ public function setAddDropTable($flag)
262
+ {
263
+ $this->addDropTable = $flag;
264
+
265
+ return $this;
266
+ }
267
+
268
+ /**
269
+ * Get add drop table flag
270
+ *
271
+ * @return bool
272
+ */
273
+ public function getAddDropTable()
274
+ {
275
+ return $this->addDropTable;
276
+ }
277
+
278
+ /**
279
+ * Set extended insert flag
280
+ *
281
+ * @param bool $flag Add extended insert SQL clause
282
+ * @return bool
283
+ */
284
+ public function setExtendedInsert($flag)
285
+ {
286
+ $this->extendedInsert = $flag;
287
+
288
+ return $this;
289
+ }
290
+
291
+ /**
292
+ * Get extended insert flag
293
+ *
294
+ * @return bool
295
+ */
296
+ public function getExtendedInsert()
297
+ {
298
+ return $this->extendedInsert;
299
+ }
300
+
301
+ /**
302
+ * Truncate database
303
+ *
304
+ * @return void
305
+ */
306
+ public function truncateDatabase()
307
+ {
308
+ $query = $this->queryAdapter->show_tables($this->database);
309
+ foreach ($this->getConnection()->query($query) as $row) {
310
+ // Drop table
311
+ $delete = $this->queryAdapter->drop_table($row['table_name']);
312
+ $this->getConnection()->query($delete);
313
+ }
314
+ }
315
+
316
+ /**
317
+ * Import database from file
318
+ *
319
+ * @param string $fileName Name of file
320
+ * @return bool
321
+ */
322
+ public function import($fileName)
323
+ {
324
+ $fileHandler = fopen($fileName, 'r');
325
+ if ($fileHandler) {
326
+ $query = null;
327
+
328
+ // Read database file line by line
329
+ while (($line = fgets($fileHandler)) !== false) {
330
+ $query .= $line;
331
+ if (preg_match('/;\s*#x2F;', $line)) {
332
+ try {
333
+ // Run SQL query
334
+ $result = $this->getConnection()->query($query);
335
+ if ($result) {
336
+ $query = null;
337
+ }
338
+ } catch (PDOException $e) {
339
+ continue;
340
+ }
341
+ }
342
+ }
343
+
344
+ return true;
345
+ }
346
+ }
347
+
348
+ /**
349
+ * Get list of tables
350
+ *
351
+ * @return array
352
+ */
353
+ public function listTables()
354
+ {
355
+ $tables = array();
356
+
357
+ $query = $this->queryAdapter->show_tables($this->database);
358
+ foreach ($this->getConnection()->query($query) as $row) {
359
+ $tables[] = $row['table_name'];
360
+ }
361
+
362
+ return $tables;
363
+ }
364
+
365
+ /**
366
+ * Create MySQL connection (lazy loading)
367
+ *
368
+ * @return mixed
369
+ */
370
+ public function getConnection()
371
+ {
372
+ if ($this->connection === null) {
373
+ try {
374
+ // Make connection
375
+ $this->connection = new PDO(
376
+ sprintf('mysql:host=%s;dbname=%s', $this->hostname, $this->database),
377
+ $this->username,
378
+ $this->password,
379
+ array(
380
+ PDO::ATTR_PERSISTENT => true,
381
+ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
382
+ )
383
+ );
384
+
385
+ // Set additional connection attributes
386
+ $this->connection->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_NATURAL);
387
+
388
+ // Set default encoding
389
+ $query = $this->queryAdapter->set_names( 'utf8' );
390
+ $this->connection->exec($query);
391
+ } catch (PDOException $e) {
392
+ throw new Exception('Unable to connect to MySQL database server: ' . $e->getMessage());
393
+ }
394
+ }
395
+
396
+ return $this->connection;
397
+ }
398
+
399
+ /**
400
+ * Returns header for dump file
401
+ *
402
+ * @return string
403
+ */
404
+ protected function getHeader()
405
+ {
406
+ // Some info about software, source and time
407
+ $header = "-- All In One WP Migration SQL Dump\n" .
408
+ "-- http://servmask.com/\n" .
409
+ "--\n" .
410
+ "-- Host: {$this->hostname}\n" .
411
+ "-- Generation Time: " . date('r') . "\n\n" .
412
+ "--\n" .
413
+ "-- Database: `{$this->database}`\n" .
414
+ "--\n\n";
415
+
416
+ return $header;
417
+ }
418
+
419
+ /**
420
+ * Table structure extractor
421
+ *
422
+ * @param string $tableName Name of table to export
423
+ * @return bool
424
+ */
425
+ protected function getTableStructure($tableName)
426
+ {
427
+ $query = $this->queryAdapter->show_create_table($tableName);
428
+ foreach ($this->getConnection()->query($query) as $row) {
429
+ if (isset($row['Create Table'])) {
430
+ $this->fileAdapter->write("-- " .
431
+ "--------------------------------------------------------" .
432
+ "\n\n" .
433
+ "--\n" .
434
+ "-- Table structure for table `$tableName`\n--\n\n");
435
+
436
+ if ($this->getAddDropTable()) {
437
+ $this->fileAdapter->write("DROP TABLE IF EXISTS `$tableName`;\n\n");
438
+ }
439
+
440
+ $this->fileAdapter->write($row['Create Table'] . ";\n\n");
441
+
442
+ return true;
443
+ }
444
+ }
445
+ }
446
+
447
+ /**
448
+ * Table rows extractor
449
+ *
450
+ * @param string $tableName Name of table to export
451
+ * @return void
452
+ */
453
+ protected function listValues($tableName)
454
+ {
455
+ $this->fileAdapter->write(
456
+ "--\n" .
457
+ "-- Dumping data for table `$tableName`\n" .
458
+ "--\n\n"
459
+ );
460
+
461
+ $insertFirst = true;
462
+ $lineSize = 0;
463
+ $query = "SELECT * FROM `$tableName` ";
464
+
465
+ // Apply additional query clauses
466
+ if ($this->getNoTableData()) {
467
+ $clauses = $this->getQueryClauses();
468
+ if (isset($clauses[$tableName]) && ($queryClause = $clauses[$tableName])) {
469
+ $query .= $queryClause;
470
+ }
471
+ }
472
+
473
+ // Generate insert statements
474
+ foreach ($this->getConnection()->query($query, PDO::FETCH_NUM) as $row) {
475
+ $items = array();
476
+ foreach ($row as $value) {
477
+ $items[] = is_null($value) ? 'NULL' : $this->getConnection()->quote($value);;
478
+ }
479
+
480
+ if ($insertFirst || !$this->getExtendedInsert()) {
481
+ $lineSize += $this->fileAdapter->write("INSERT INTO `$tableName` VALUES (" . implode(',', $items) . ')');
482
+ $insertFirst = false;
483
+ } else {
484
+ $lineSize += $this->fileAdapter->write(',(' . implode(',', $items) . ')');
485
+ }
486
+
487
+ if (($lineSize > MysqlDumpInterface::MAXLINESIZE) || !$this->getExtendedInsert()) {
488
+ $insertFirst = true;
489
+ $lineSize = $this->fileAdapter->write(";\n");
490
+ }
491
+ }
492
+
493
+ if (!$insertFirst) {
494
+ $this->fileAdapter->write(";\n");
495
+ }
496
+ }
497
+ }
lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpSQL.php ADDED
@@ -0,0 +1,490 @@
1
+ <?php
2
+ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
+
4
+ /**
5
+ * MysqlDumpSQL class
6
+ *
7
+ * PHP version 5
8
+ *
9
+ * LICENSE: Permission is hereby granted, free of charge, to any person obtaining
10
+ * a copy of this software and associated documentation files (the "Software"), to
11
+ * deal in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
13
+ * of the Software, and to permit persons to whom the Software is furnished to do so,
14
+ * subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
21
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
22
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
23
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+ *
26
+ * @category Databases
27
+ * @package MysqlDumpFactory
28
+ * @author Yani Iliev <yani@iliev.me>
29
+ * @author Bobby Angelov <bobby@servmask.com>
30
+ * @copyright 2014 Yani Iliev, Bobby Angelov
31
+ * @license https://raw.github.com/yani-/mysqldump-factory/master/LICENSE The MIT License (MIT)
32
+ * @version GIT: 1.0.4
33
+ * @link https://github.com/yani-/mysqldump-factory/
34
+ */
35
+
36
+ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MysqlDumpInterface.php';
37
+ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MysqlQueryAdapter.php';
38
+ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MysqlFileAdapter.php';
39
+
40
+ /**
41
+ * MysqlDumpSQL class
42
+ *
43
+ * @category Databases
44
+ * @package MysqlDumpFactory
45
+ * @author Yani Iliev <yani@iliev.me>
46
+ * @author Bobby Angelov <bobby@servmask.com>
47
+ * @copyright 2014 Yani Iliev, Bobby Angelov
48
+ * @license https://raw.github.com/yani-/mysqldump-factory/master/LICENSE The MIT License (MIT)
49
+ * @version GIT: 1.0.4
50
+ * @link https://github.com/yani-/mysqldump-factory/
51
+ */
52
+ class MysqlDumpSQL implements MysqlDumpInterface
53
+ {
54
+ protected $hostname = null;
55
+
56
+ protected $username = null;
57
+
58
+ protected $password = null;
59
+
60
+ protected $database = null;
61
+
62
+ protected $fileName = 'dump.sql';
63
+
64
+ protected $fileAdapter = null;
65
+
66
+ protected $queryAdapter = null;
67
+
68
+ protected $connection = null;
69
+
70
+ protected $queryClauses = array();
71
+
72
+ protected $includeTables = array();
73
+
74
+ protected $excludeTables = array();
75
+
76
+ protected $noTableData = false;
77
+
78
+ protected $addDropTable = false;
79
+
80
+ protected $extendedInsert = true;
81
+
82
+ /**
83
+ * Define MySQL credentials for the current connection
84
+ *
85
+ * @param string $hostname MySQL Hostname
86
+ * @param string $username MySQL Username
87
+ * @param string $password MySQL Password
88
+ * @param string $database MySQL Database
89
+ * @return void
90
+ */
91
+ public function __construct($hostname = 'localhost', $username = '', $password = '', $database = '')
92
+ {
93
+ // Set MySQL credentials
94
+ $this->hostname = $hostname;
95
+ $this->username = $username;
96
+ $this->password = $password;
97
+ $this->database = $database;
98
+
99
+ // Set Query Adapter
100
+ $this->queryAdapter = new MysqlQueryAdapter('mysql');
101
+ }
102
+
103
+ /**
104
+ * Dump database into a file
105
+ *
106
+ * @return void
107
+ */
108
+ public function dump()
109
+ {
110
+ // Set File Adapter
111
+ $this->fileAdapter = new MysqlFileAdapter();
112
+
113
+ // Set output file
114
+ $this->fileAdapter->open($this->getFileName());
115
+
116
+ // Write Headers Formating dump file
117
+ $this->fileAdapter->write($this->getHeader());
118
+
119
+ // Listing all tables from database
120
+ $tables = array();
121
+ foreach ($this->listTables() as $table) {
122
+ if (count($this->getIncludeTables()) === 0 || in_array($table, $this->getIncludeTables())) {
123
+ $tables[] = $table;
124
+ }
125
+ }
126
+
127
+ // Export Tables
128
+ foreach ($tables as $table) {
129
+ if (in_array($table, $this->getExcludeTables())) {
130
+ continue;
131
+ }
132
+
133
+ $isTable = $this->getTableStructure($table);
134
+ if (true === $isTable) {
135
+ $this->listValues($table);
136
+ }
137
+ }
138
+ }
139
+
140
+ /**
141
+ * Set output file name
142
+ *
143
+ * @param string $fileName Name of the output file
144
+ * @return string
145
+ */
146
+ public function setFileName($fileName)
147
+ {
148
+ $this->fileName = $fileName;
149
+
150
+ return $this;
151
+ }
152
+
153
+ /**
154
+ * Get output file name
155
+ *
156
+ * @return string
157
+ */
158
+ public function getFileName()
159
+ {
160
+ return $this->fileName;
161
+ }
162
+
163
+ /**
164
+ * Set query clauses
165
+ *
166
+ * @param array $clauses List of SQL query clauses
167
+ * @return array
168
+ */
169
+ public function setQueryClauses($clauses)
170
+ {
171
+ $this->queryClauses = $clauses;
172
+
173
+ return $this;
174
+ }
175
+
176
+ /**
177
+ * Get query clauses
178
+ *
179
+ * @return array
180
+ */
181
+ public function getQueryClauses()
182
+ {
183
+ return $this->queryClauses;
184
+ }
185
+
186
+ /**
187
+ * Set include tables
188
+ *
189
+ * @param array $tables List of tables
190
+ * @return array
191
+ */
192
+ public function setIncludeTables($tables)
193
+ {
194
+ $this->includeTables = $tables;
195
+
196
+ return $this;
197
+ }
198
+
199
+ /**
200
+ * Get include tables
201
+ *
202
+ * @return array
203
+ */
204
+ public function getIncludeTables()
205
+ {
206
+ return $this->includeTables;
207
+ }
208
+
209
+ /**
210
+ * Set exclude tables
211
+ *
212
+ * @param array $tables List of tables
213
+ * @return array
214
+ */
215
+ public function setExcludeTables($tables)
216
+ {
217
+ $this->excludeTables = $tables;
218
+
219
+ return $this;
220
+ }
221
+
222
+ /**
223
+ * Get exclude tables
224
+ *
225
+ * @return array
226
+ */
227
+ public function getExcludeTables()
228
+ {
229
+ return $this->excludeTables;
230
+ }
231
+
232
+ /**
233
+ * Set no table data flag
234
+ *
235
+ * @param bool $flag Do not export table data
236
+ * @return bool
237
+ */
238
+ public function setNoTableData($flag)
239
+ {
240
+ $this->noTableData = $flag;
241
+
242
+ return $this;
243
+ }
244
+
245
+ /**
246
+ * Get no table data flag
247
+ *
248
+ * @return bool
249
+ */
250
+ public function getNoTableData()
251
+ {
252
+ return $this->noTableData;
253
+ }
254
+
255
+ /**
256
+ * Set add drop table flag
257
+ *
258
+ * @param bool $flag Add drop table SQL clause
259
+ * @return bool
260
+ */
261
+ public function setAddDropTable($flag)
262
+ {
263
+ $this->addDropTable = $flag;
264
+
265
+ return $this;
266
+ }
267
+
268
+ /**
269
+ * Get add drop table flag
270
+ *
271
+ * @return bool
272
+ */
273
+ public function getAddDropTable()
274
+ {
275
+ return $this->addDropTable;
276
+ }
277
+
278
+ /**
279
+ * Set extended insert flag
280
+ *
281
+ * @param bool $flag Add extended insert SQL clause
282
+ * @return bool
283
+ */
284
+ public function setExtendedInsert($flag)
285
+ {
286
+ $this->extendedInsert = $flag;
287
+
288
+ return $this;
289
+ }
290
+
291
+ /**
292
+ * Get extended insert flag
293
+ *
294
+ * @return bool
295
+ */
296
+ public function getExtendedInsert()
297
+ {
298
+ return $this->extendedInsert;
299
+ }
300
+
301
+ /**
302
+ * Truncate database
303
+ *
304
+ * @return void
305
+ */
306
+ public function truncateDatabase()
307
+ {
308
+ $query = $this->queryAdapter->show_tables($this->database);
309
+ $result = mysql_query($query, $this->getConnection());
310
+ while ($row = mysql_fetch_assoc($result)) {
311
+ // Drop table
312
+ $delete = $this->queryAdapter->drop_table($row['table_name']);
313
+ mysql_query($delete, $this->getConnection());
314
+ }
315
+ }
316
+
317
+ /**
318
+ * Import database from file
319
+ *
320
+ * @param string $fileName Name of file
321
+ * @return bool
322
+ */
323
+ public function import($fileName)
324
+ {
325
+ $fileHandler = fopen($fileName, 'r');
326
+ if ($fileHandler) {
327
+ $query = null;
328
+
329
+ // Read database file line by line
330
+ while (($line = fgets($fileHandler)) !== false) {
331
+ $query .= $line;
332
+ if (preg_match('/;\s*#x2F;', $line)) {
333
+ // Run SQL query
334
+ $result = mysql_query($query, $this->getConnection());
335
+ if ($result) {
336
+ $query = null;
337
+ }
338
+ }
339
+ }
340
+
341
+ return true;
342
+ }
343
+ }
344
+
345
+ /**
346
+ * Get list of tables
347
+ *
348
+ * @return array
349
+ */
350
+ public function listTables()
351
+ {
352
+ $tables = array();
353
+
354
+ $query = $this->queryAdapter->show_tables($this->database);
355
+ $result = mysql_query($query, $this->getConnection());
356
+ while ($row = mysql_fetch_assoc($result)) {
357
+ $tables[] = $row['table_name'];
358
+ }
359
+
360
+ return $tables;
361
+ }
362
+
363
+ /**
364
+ * Create MySQL connection (lazy loading)
365
+ *
366
+ * @return mixed
367
+ */
368
+ protected function getConnection()
369
+ {
370
+ if ($this->connection === null) {
371
+ // Make connection
372
+ $this->connection = mysql_pconnect($this->hostname, $this->username, $this->password);
373
+
374
+ // Select database and set default encoding
375
+ if ($this->connection) {
376
+ if (mysql_select_db($this->database, $this->connection)) {
377
+ $query = $this->queryAdapter->set_names( 'utf8' );
378
+ mysql_query($query, $this->connection);
379
+ } else {
380
+ throw new Exception('Could not select MySQL database: ' . mysql_error($this->connection));
381
+ }
382
+ } else {
383
+ throw new Exception('Unable to connect to MySQL database server: ' . mysql_error($this->connection));
384
+ }
385
+ }
386
+
387
+ return $this->connection;
388
+ }
389
+
390
+ /**
391
+ * Returns header for dump file
392
+ *
393
+ * @return string
394
+ */
395
+ protected function getHeader()
396
+ {
397
+ // Some info about software, source and time
398
+ $header = "-- All In One WP Migration SQL Dump\n" .
399
+ "-- http://servmask.com/\n" .
400
+ "--\n" .
401
+ "-- Host: {$this->hostname}\n" .
402
+ "-- Generation Time: " . date('r') . "\n\n" .
403
+ "--\n" .
404
+ "-- Database: `{$this->database}`\n" .
405
+ "--\n\n";
406
+
407
+ return $header;
408
+ }
409
+
410
+ /**
411
+ * Table structure extractor
412
+ *
413
+ * @param string $tableName Name of table to export
414
+ * @return bool
415
+ */
416
+ protected function getTableStructure($tableName)
417
+ {
418
+ $query = $this->queryAdapter->show_create_table($tableName);
419
+ $result = mysql_query($query, $this->getConnection());
420
+ while ($row = mysql_fetch_assoc($result)) {
421
+ if (isset($row['Create Table'])) {
422
+ $this->fileAdapter->write("-- " .
423
+ "--------------------------------------------------------" .
424
+ "\n\n" .
425
+ "--\n" .
426
+ "-- Table structure for table `$tableName`\n--\n\n");
427
+
428
+ if ($this->getAddDropTable()) {
429
+ $this->fileAdapter->write("DROP TABLE IF EXISTS `$tableName`;\n\n");
430
+ }
431
+
432
+ $this->fileAdapter->write($row['Create Table'] . ";\n\n");
433
+
434
+ return true;
435
+ }
436
+ }
437
+ }
438
+
439
+ /**
440
+ * Table rows extractor
441
+ *
442
+ * @param string $tableName Name of table to export
443
+ * @return void
444
+ */
445
+ protected function listValues($tableName)
446
+ {
447
+ $this->fileAdapter->write(
448
+ "--\n" .
449
+ "-- Dumping data for table `$tableName`\n" .
450
+ "--\n\n"
451
+ );
452
+
453
+ $insertFirst = true;
454
+ $lineSize = 0;
455
+ $query = "SELECT * FROM `$tableName` ";
456
+
457
+ // Apply additional query clauses
458
+ if ($this->getNoTableData()) {
459
+ $clauses = $this->getQueryClauses();
460
+ if (isset($clauses[$tableName]) && ($queryClause = $clauses[$tableName])) {
461
+ $query .= $queryClause;
462
+ }
463
+ }
464
+
465
+ // Generate insert statements
466
+ $result = mysql_query($query, $this->getConnection());
467
+ while ($row = mysql_fetch_row($result)) {
468
+ $items = array();
469
+ foreach ($row as $value) {
470
+ $items[] = is_null($value) ? 'NULL' : "'" . mysql_real_escape_string($value) . "'";
471
+ }
472
+
473
+ if ($insertFirst || !$this->getExtendedInsert()) {
474
+ $lineSize += $this->fileAdapter->write("INSERT INTO `$tableName` VALUES (" . implode(',', $items) . ')');
475
+ $insertFirst = false;
476
+ } else {
477
+ $lineSize += $this->fileAdapter->write(',(' . implode(',', $items) . ')');
478
+ }
479
+
480
+ if (($lineSize > MysqlDumpInterface::MAXLINESIZE) || !$this->getExtendedInsert()) {
481
+ $insertFirst = true;
482
+ $lineSize = $this->fileAdapter->write(";\n");
483
+ }
484
+ }
485
+
486
+ if (!$insertFirst) {
487
+ $this->fileAdapter->write(";\n");
488
+ }
489
+ }
490
+ }
lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlFileAdapter.php ADDED
@@ -0,0 +1,74 @@
1
+ <?php
2
+ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
+
4
+ /**
5
+ * MysqlFileAdapter class
6
+ *
7
+ * PHP version 5
8
+ *
9
+ * LICENSE: Permission is hereby granted, free of charge, to any person obtaining
10
+ * a copy of this software and associated documentation files (the "Software"), to
11
+ * deal in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
13
+ * of the Software, and to permit persons to whom the Software is furnished to do so,
14
+ * subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
21
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
22
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
23
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+ *
26
+ * @category Databases
27
+ * @package MysqlDumpFactory
28
+ * @author Yani Iliev <yani@iliev.me>
29
+ * @author Bobby Angelov <bobby@servmask.com>
30
+ * @copyright 2014 Yani Iliev, Bobby Angelov
31
+ * @license https://raw.github.com/yani-/mysqldump-factory/master/LICENSE The MIT License (MIT)
32
+ * @version GIT: 1.0.4
33
+ * @link https://github.com/yani-/mysqldump-factory/
34
+ */
35
+
36
+ /**
37
+ * MysqlFileAdapter class
38
+ *
39
+ * @category Databases
40
+ * @package MysqlDumpFactory
41
+ * @author Yani Iliev <yani@iliev.me>
42
+ * @author Bobby Angelov <bobby@servmask.com>
43
+ * @copyright 2014 Yani Iliev, Bobby Angelov
44
+ * @license https://raw.github.com/yani-/mysqldump-factory/master/LICENSE The MIT License (MIT)
45
+ * @version GIT: 1.0.4
46
+ * @link https://github.com/yani-/mysqldump-factory/
47
+ */
48
+ class MysqlFileAdapter
49
+ {
50
+ protected $fileHandler = null;
51
+
52
+ public function open($fileName)
53
+ {
54
+ $this->fileHandler = fopen($fileName, 'wb');
55
+ if (false === $this->fileHandler) {
56
+ throw new Exception('Output file is not writable', 2);
57
+ }
58
+ }
59
+
60
+ public function write($str)
61
+ {
62
+ $bytesWritten = 0;
63
+ if (false === ($bytesWritten = fwrite($this->fileHandler, $str))) {
64
+ throw new Exception('Writting to file failed! Probably, there is no more free space left?', 4);
65
+ }
66
+
67
+ return $bytesWritten;
68
+ }
69
+
70
+ public function close()
71
+ {
72
+ return fclose($this->fileHandler);
73
+ }
74
+ }
lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlQueryAdapter.php ADDED
@@ -0,0 +1,109 @@