Version Description
- Add HTTPS URL replacement
- Fix an issue when PDO is not available
Download this release
Release Info
Developer | bangelov |
Plugin | All-in-One WP Migration |
Version | 4.10 |
Comparing to | |
See all releases |
Code changes from version 4.9 to 4.10
- all-in-one-wp-migration.php +6 -4
- constants.php +1 -1
- lib/model/class-ai1wm-export-abstract.php +12 -8
- lib/model/class-ai1wm-import-abstract.php +1 -1
- lib/model/service/class-ai1wm-service-database.php +100 -51
- lib/model/service/class-ai1wm-service-interface.php +1 -0
- lib/model/service/class-ai1wm-service-package.php +1 -0
- lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpFactory.php +34 -53
- lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpInterface.php +55 -124
- lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpPDO.php +430 -337
- lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpSQL.php +439 -342
- lib/vendor/mysqldump-factory/mysqldump-factory/lib/{MysqlUtility.php → MysqlDumpUtility.php} +18 -39
- lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlFileAdapter.php +0 -74
- lib/vendor/servmask/filter/class-ai1wm-extension-filter.php +1 -2
- lib/vendor/servmask/filter/class-ai1wm-recursive-exclude-filter.php +9 -3
- lib/vendor/servmask/iterator/class-ai1wm-recursive-directory-iterator.php +7 -1
- readme.txt +5 -1
all-in-one-wp-migration.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* Description: Migration tool for all your blog data. Import or Export your blog content with a single click.
|
6 |
* Author: ServMask
|
7 |
* Author URI: https://servmask.com/
|
8 |
-
* Version: 4.
|
9 |
* Text Domain: all-in-one-wp-migration
|
10 |
* Domain Path: /languages
|
11 |
* Network: True
|
@@ -32,11 +32,13 @@
|
|
32 |
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
|
33 |
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
34 |
*/
|
|
|
|
|
35 |
@set_time_limit( 0 );
|
36 |
@ini_set( 'max_input_time', '-1' );
|
37 |
|
38 |
// Plugin Basename
|
39 |
-
define( 'AI1WM_PLUGIN_BASENAME',
|
40 |
|
41 |
// Plugin Path
|
42 |
define( 'AI1WM_PATH', dirname( __FILE__ ) );
|
@@ -53,10 +55,10 @@ define( 'AI1WM_BACKUPS_URL', content_url( 'ai1wm-backups', __FILE__ ) );
|
|
53 |
// Themes Absolute Path
|
54 |
define( 'AI1WM_THEMES_PATH', get_theme_root() );
|
55 |
|
56 |
-
//
|
57 |
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'constants.php';
|
58 |
|
59 |
-
//
|
60 |
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'loader.php';
|
61 |
|
62 |
// ==========================================================================
|
5 |
* Description: Migration tool for all your blog data. Import or Export your blog content with a single click.
|
6 |
* Author: ServMask
|
7 |
* Author URI: https://servmask.com/
|
8 |
+
* Version: 4.10
|
9 |
* Text Domain: all-in-one-wp-migration
|
10 |
* Domain Path: /languages
|
11 |
* Network: True
|
32 |
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
|
33 |
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
34 |
*/
|
35 |
+
|
36 |
+
@ignore_user_abort( true );
|
37 |
@set_time_limit( 0 );
|
38 |
@ini_set( 'max_input_time', '-1' );
|
39 |
|
40 |
// Plugin Basename
|
41 |
+
define( 'AI1WM_PLUGIN_BASENAME', basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) );
|
42 |
|
43 |
// Plugin Path
|
44 |
define( 'AI1WM_PATH', dirname( __FILE__ ) );
|
55 |
// Themes Absolute Path
|
56 |
define( 'AI1WM_THEMES_PATH', get_theme_root() );
|
57 |
|
58 |
+
// Include constants
|
59 |
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'constants.php';
|
60 |
|
61 |
+
// Include loader
|
62 |
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'loader.php';
|
63 |
|
64 |
// ==========================================================================
|
constants.php
CHANGED
@@ -38,7 +38,7 @@ if ( function_exists( 'gethostname' ) && in_array( gethostname(), $local ) ) {
|
|
38 |
// ==================
|
39 |
// = Plugin Version =
|
40 |
// ==================
|
41 |
-
define( 'AI1WM_VERSION', '4.
|
42 |
|
43 |
// ===============
|
44 |
// = Plugin Name =
|
38 |
// ==================
|
39 |
// = Plugin Version =
|
40 |
// ==================
|
41 |
+
define( 'AI1WM_VERSION', '4.10' );
|
42 |
|
43 |
// ===============
|
44 |
// = Plugin Name =
|
lib/model/class-ai1wm-export-abstract.php
CHANGED
@@ -80,18 +80,22 @@ abstract class Ai1wm_Export_Abstract {
|
|
80 |
|
81 |
// Default filters
|
82 |
$filters = array(
|
|
|
83 |
'ai1wm-backups',
|
|
|
84 |
'managewp',
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
'
|
90 |
'themes' . DIRECTORY_SEPARATOR . 'index.php',
|
91 |
'plugins' . DIRECTORY_SEPARATOR . 'index.php',
|
92 |
'uploads' . DIRECTORY_SEPARATOR . 'index.php',
|
93 |
-
|
94 |
-
|
|
|
|
|
95 |
|
96 |
// Exclude media
|
97 |
if ( $this->should_exclude_media() ) {
|
@@ -407,7 +411,7 @@ abstract class Ai1wm_Export_Abstract {
|
|
407 |
}
|
408 |
|
409 |
// Resolve domain
|
410 |
-
$url = admin_url( 'admin-ajax.php?action=ai1wm_export
|
411 |
$hostname = parse_url( $url, PHP_URL_HOST );
|
412 |
$port = parse_url( $url, PHP_URL_PORT );
|
413 |
$ip = gethostbyname( $hostname );
|
80 |
|
81 |
// Default filters
|
82 |
$filters = array(
|
83 |
+
'index.php',
|
84 |
'ai1wm-backups',
|
85 |
+
'envato-backups',
|
86 |
'managewp',
|
87 |
+
'updraft',
|
88 |
+
'cache',
|
89 |
+
'backwpup',
|
90 |
+
'pb_backupbuddy',
|
91 |
+
'backupbuddy_backups',
|
92 |
'themes' . DIRECTORY_SEPARATOR . 'index.php',
|
93 |
'plugins' . DIRECTORY_SEPARATOR . 'index.php',
|
94 |
'uploads' . DIRECTORY_SEPARATOR . 'index.php',
|
95 |
+
'uploads' . DIRECTORY_SEPARATOR . 'backwpup',
|
96 |
+
'uploads' . DIRECTORY_SEPARATOR . 'pb_backupbuddy',
|
97 |
+
'uploads' . DIRECTORY_SEPARATOR . 'backupbuddy_backups',
|
98 |
+
);
|
99 |
|
100 |
// Exclude media
|
101 |
if ( $this->should_exclude_media() ) {
|
411 |
}
|
412 |
|
413 |
// Resolve domain
|
414 |
+
$url = add_query_arg( $this->args, admin_url( 'admin-ajax.php?action=ai1wm_export' ) );
|
415 |
$hostname = parse_url( $url, PHP_URL_HOST );
|
416 |
$port = parse_url( $url, PHP_URL_PORT );
|
417 |
$ip = gethostbyname( $hostname );
|
lib/model/class-ai1wm-import-abstract.php
CHANGED
@@ -396,7 +396,7 @@ abstract class Ai1wm_Import_Abstract {
|
|
396 |
}
|
397 |
|
398 |
// Resolve domain
|
399 |
-
$url = admin_url( 'admin-ajax.php?action=ai1wm_import
|
400 |
$hostname = parse_url( $url, PHP_URL_HOST );
|
401 |
$port = parse_url( $url, PHP_URL_PORT );
|
402 |
$ip = gethostbyname( $hostname );
|
396 |
}
|
397 |
|
398 |
// Resolve domain
|
399 |
+
$url = add_query_arg( $this->args, admin_url( 'admin-ajax.php?action=ai1wm_import' ) );
|
400 |
$hostname = parse_url( $url, PHP_URL_HOST );
|
401 |
$port = parse_url( $url, PHP_URL_PORT );
|
402 |
$ip = gethostbyname( $hostname );
|
lib/model/service/class-ai1wm-service-database.php
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
* Copyright (C) 2014 ServMask Inc.
|
4 |
*
|
@@ -23,42 +24,14 @@
|
|
23 |
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
24 |
*/
|
25 |
|
26 |
-
class Ai1wm_Service_Database implements Ai1wm_Service_Interface
|
27 |
-
{
|
28 |
-
protected $args = array();
|
29 |
|
30 |
-
protected $
|
31 |
|
32 |
-
protected $
|
33 |
|
34 |
public function __construct( array $args = array() ) {
|
35 |
$this->args = $args;
|
36 |
-
|
37 |
-
// Make connection
|
38 |
-
try {
|
39 |
-
// Use PDO adapter
|
40 |
-
$this->connection = MysqlDumpFactory::makeMysqlDump(
|
41 |
-
DB_HOST,
|
42 |
-
DB_USER,
|
43 |
-
DB_PASSWORD,
|
44 |
-
DB_NAME,
|
45 |
-
(
|
46 |
-
class_exists(
|
47 |
-
'PDO'
|
48 |
-
) && in_array( 'mysql', PDO::getAvailableDrivers() )
|
49 |
-
)
|
50 |
-
);
|
51 |
-
$this->connection->getConnection();
|
52 |
-
} catch ( Exception $e ) {
|
53 |
-
// Use mysql adapter
|
54 |
-
$this->connection = MysqlDumpFactory::makeMysqlDump(
|
55 |
-
DB_HOST,
|
56 |
-
DB_USER,
|
57 |
-
DB_PASSWORD,
|
58 |
-
DB_NAME,
|
59 |
-
false
|
60 |
-
);
|
61 |
-
}
|
62 |
}
|
63 |
|
64 |
/**
|
@@ -78,20 +51,78 @@ class Ai1wm_Service_Database implements Ai1wm_Service_Interface
|
|
78 |
|
79 |
// Get Site URL
|
80 |
if ( isset( $config['SiteURL'] ) && ( $config['SiteURL'] !== site_url() ) ) {
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
}
|
84 |
|
85 |
// Get Home URL
|
86 |
if ( isset( $config['HomeURL'] ) && ( $config['HomeURL'] !== home_url() ) ) {
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
}
|
90 |
|
91 |
// Get WordPress Content
|
92 |
if ( isset( $config['WordPress']['Content'] ) && ( $config['WordPress']['Content'] !== WP_CONTENT_DIR ) ) {
|
|
|
|
|
93 |
$old_values[] = $config['WordPress']['Content'];
|
94 |
$new_values[] = WP_CONTENT_DIR;
|
|
|
|
|
|
|
|
|
95 |
}
|
96 |
|
97 |
// Get user details
|
@@ -128,15 +159,25 @@ class Ai1wm_Service_Database implements Ai1wm_Service_Interface
|
|
128 |
// Get secret key
|
129 |
$secret_key = get_site_option( AI1WM_SECRET_KEY, false, false );
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
// Flush database
|
132 |
-
$
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
// Import database
|
135 |
-
$this->
|
136 |
-
->setNewTablePrefix( $wpdb->prefix )
|
137 |
-
->setOldReplaceValues( $old_values )
|
138 |
-
->setNewReplaceValues( $new_values )
|
139 |
-
->import( $this->storage()->database() );
|
140 |
|
141 |
// Clear WP options cache
|
142 |
wp_cache_flush();
|
@@ -176,6 +217,11 @@ class Ai1wm_Service_Database implements Ai1wm_Service_Interface
|
|
176 |
activate_plugin( AI1WMFE_PLUGIN_BASENAME );
|
177 |
}
|
178 |
|
|
|
|
|
|
|
|
|
|
|
179 |
// Set new user identity
|
180 |
if ( isset( $config['Export']['User']['Id'] ) && ( $id = $config['Export']['User']['Id'] ) ) {
|
181 |
|
@@ -251,18 +297,21 @@ class Ai1wm_Service_Database implements Ai1wm_Service_Interface
|
|
251 |
}
|
252 |
}
|
253 |
|
254 |
-
//
|
255 |
-
$
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
|
|
|
|
|
|
263 |
|
264 |
// Export database
|
265 |
-
$this->
|
266 |
}
|
267 |
|
268 |
/*
|
1 |
<?php
|
2 |
+
|
3 |
/**
|
4 |
* Copyright (C) 2014 ServMask Inc.
|
5 |
*
|
24 |
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
25 |
*/
|
26 |
|
27 |
+
class Ai1wm_Service_Database implements Ai1wm_Service_Interface {
|
|
|
|
|
28 |
|
29 |
+
protected $args = array();
|
30 |
|
31 |
+
protected $storage = null;
|
32 |
|
33 |
public function __construct( array $args = array() ) {
|
34 |
$this->args = $args;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
}
|
36 |
|
37 |
/**
|
51 |
|
52 |
// Get Site URL
|
53 |
if ( isset( $config['SiteURL'] ) && ( $config['SiteURL'] !== site_url() ) ) {
|
54 |
+
|
55 |
+
// Get domain
|
56 |
+
$old_domain = parse_url( $config['SiteURL'], PHP_URL_HOST );
|
57 |
+
$new_domain = parse_url( site_url(), PHP_URL_HOST );
|
58 |
+
|
59 |
+
// Add plain Site URL
|
60 |
+
$old_values[] = set_url_scheme( $config['SiteURL'], 'http' );
|
61 |
+
$new_values[] = set_url_scheme( site_url() );
|
62 |
+
|
63 |
+
// Add plain Site URL SSL
|
64 |
+
$old_values[] = set_url_scheme( $config['SiteURL'], 'https' );
|
65 |
+
$new_values[] = set_url_scheme( site_url() );
|
66 |
+
|
67 |
+
// Add encoded Site URL
|
68 |
+
$old_values[] = urlencode( set_url_scheme( $config['SiteURL'], 'http' ) );
|
69 |
+
$new_values[] = urlencode( set_url_scheme( site_url() ) );
|
70 |
+
|
71 |
+
// Add encoded Site URL SSL
|
72 |
+
$old_values[] = urlencode( set_url_scheme( $config['SiteURL'], 'https' ) );
|
73 |
+
$new_values[] = urlencode( set_url_scheme( site_url() ) );
|
74 |
+
|
75 |
+
// Add escaped Site URL
|
76 |
+
$old_values[] = addslashes( addcslashes( set_url_scheme( $config['SiteURL'], 'http' ), '/' ) );
|
77 |
+
$new_values[] = addslashes( addcslashes( set_url_scheme( site_url() ), '/' ) );
|
78 |
+
|
79 |
+
// Add escaped Site URL SSL
|
80 |
+
$old_values[] = addslashes( addcslashes( set_url_scheme( $config['SiteURL'], 'https' ), '/' ) );
|
81 |
+
$new_values[] = addslashes( addcslashes( set_url_scheme( site_url() ), '/' ) );
|
82 |
+
|
83 |
+
// Add email
|
84 |
+
$old_values[] = sprintf( "@%s", $old_domain );
|
85 |
+
$new_values[] = sprintf( "@%s", $new_domain );
|
86 |
}
|
87 |
|
88 |
// Get Home URL
|
89 |
if ( isset( $config['HomeURL'] ) && ( $config['HomeURL'] !== home_url() ) ) {
|
90 |
+
|
91 |
+
// Add plain Home URL
|
92 |
+
$old_values[] = set_url_scheme( $config['HomeURL'], 'http' );
|
93 |
+
$new_values[] = set_url_scheme( home_url() );
|
94 |
+
|
95 |
+
// Add plain Home URL SSL
|
96 |
+
$old_values[] = set_url_scheme( $config['HomeURL'], 'https' );
|
97 |
+
$new_values[] = set_url_scheme( home_url() );
|
98 |
+
|
99 |
+
// Add encoded Home URL
|
100 |
+
$old_values[] = urlencode( set_url_scheme( $config['HomeURL'], 'http' ) );
|
101 |
+
$new_values[] = urlencode( set_url_scheme( home_url() ) );
|
102 |
+
|
103 |
+
// Add encoded Home URL SSL
|
104 |
+
$old_values[] = urlencode( set_url_scheme( $config['HomeURL'], 'https' ) );
|
105 |
+
$new_values[] = urlencode( set_url_scheme( home_url() ) );
|
106 |
+
|
107 |
+
// Add escaped Home URL
|
108 |
+
$old_values[] = addslashes( addcslashes( set_url_scheme( $config['HomeURL'], 'http' ), '/' ) );
|
109 |
+
$new_values[] = addslashes( addcslashes( set_url_scheme( home_url() ), '/' ) );
|
110 |
+
|
111 |
+
// Add escaped Home URL SSL
|
112 |
+
$old_values[] = addslashes( addcslashes( set_url_scheme( $config['HomeURL'], 'https' ), '/' ) );
|
113 |
+
$new_values[] = addslashes( addcslashes( set_url_scheme( home_url() ), '/' ) );
|
114 |
}
|
115 |
|
116 |
// Get WordPress Content
|
117 |
if ( isset( $config['WordPress']['Content'] ) && ( $config['WordPress']['Content'] !== WP_CONTENT_DIR ) ) {
|
118 |
+
|
119 |
+
// Add plain WordPress Content
|
120 |
$old_values[] = $config['WordPress']['Content'];
|
121 |
$new_values[] = WP_CONTENT_DIR;
|
122 |
+
|
123 |
+
// Get escaped WordPress Content
|
124 |
+
$old_values[] = addslashes( addcslashes( $config['WordPress']['Content'], '\/' ) );
|
125 |
+
$new_values[] = addslashes( addcslashes( WP_CONTENT_DIR, '\/' ) );
|
126 |
}
|
127 |
|
128 |
// Get user details
|
159 |
// Get secret key
|
160 |
$secret_key = get_site_option( AI1WM_SECRET_KEY, false, false );
|
161 |
|
162 |
+
// Get database client
|
163 |
+
$client = MysqlDumpFactory::makeMysqlDump( DB_HOST, DB_USER, DB_PASSWORD, DB_NAME );
|
164 |
+
|
165 |
+
// Set database options
|
166 |
+
$client->setOldTablePrefixes( array( AI1WM_TABLE_PREFIX ) )
|
167 |
+
->setNewTablePrefixes( array( $wpdb->prefix ) )
|
168 |
+
->setOldReplaceValues( $old_values )
|
169 |
+
->setNewReplaceValues( $new_values );
|
170 |
+
|
171 |
// Flush database
|
172 |
+
if ( ( $version = $config['Plugin']['Version'] ) ) {
|
173 |
+
if ( $version !== 'develop' && version_compare( $version, '4.9', '<' ) ) {
|
174 |
+
$client->setIncludeTablePrefixes( array( $wpdb->prefix ) );
|
175 |
+
$client->flush();
|
176 |
+
}
|
177 |
+
}
|
178 |
|
179 |
// Import database
|
180 |
+
$client->import( $this->storage()->database() );
|
|
|
|
|
|
|
|
|
181 |
|
182 |
// Clear WP options cache
|
183 |
wp_cache_flush();
|
217 |
activate_plugin( AI1WMFE_PLUGIN_BASENAME );
|
218 |
}
|
219 |
|
220 |
+
// URL Extension
|
221 |
+
if ( is_plugin_active( AI1WMLE_PLUGIN_BASENAME ) ) {
|
222 |
+
activate_plugin( AI1WMLE_PLUGIN_BASENAME );
|
223 |
+
}
|
224 |
+
|
225 |
// Set new user identity
|
226 |
if ( isset( $config['Export']['User']['Id'] ) && ( $id = $config['Export']['User']['Id'] ) ) {
|
227 |
|
297 |
}
|
298 |
}
|
299 |
|
300 |
+
// Get database client
|
301 |
+
$client = MysqlDumpFactory::makeMysqlDump( DB_HOST, DB_USER, DB_PASSWORD, DB_NAME );
|
302 |
+
|
303 |
+
// Set database options
|
304 |
+
$client->setOldTablePrefixes( array( $wpdb->prefix ) )
|
305 |
+
->setNewTablePrefixes( array( AI1WM_TABLE_PREFIX ) )
|
306 |
+
->setOldReplaceValues( $old_values )
|
307 |
+
->setNewReplaceValues( $new_values )
|
308 |
+
->setIncludeTablePrefixes( array( $wpdb->prefix ) )
|
309 |
+
->setQueryClauses( $clauses )
|
310 |
+
->setTablePrefixColumns( $wpdb->options, array( 'option_name' ) )
|
311 |
+
->setTablePrefixColumns( $wpdb->usermeta, array( 'meta_key' ) );
|
312 |
|
313 |
// Export database
|
314 |
+
$client->export( $this->storage()->database() );
|
315 |
}
|
316 |
|
317 |
/*
|
lib/model/service/class-ai1wm-service-interface.php
CHANGED
@@ -23,6 +23,7 @@
|
|
23 |
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
|
24 |
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
25 |
*/
|
|
|
26 |
interface Ai1wm_Service_Interface {
|
27 |
|
28 |
public function import();
|
23 |
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
|
24 |
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
25 |
*/
|
26 |
+
|
27 |
interface Ai1wm_Service_Interface {
|
28 |
|
29 |
public function import();
|
lib/model/service/class-ai1wm-service-package.php
CHANGED
@@ -23,6 +23,7 @@
|
|
23 |
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
|
24 |
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
25 |
*/
|
|
|
26 |
class Ai1wm_Service_Package implements Ai1wm_Service_Interface {
|
27 |
|
28 |
protected $args = array();
|
23 |
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
|
24 |
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
25 |
*/
|
26 |
+
|
27 |
class Ai1wm_Service_Package implements Ai1wm_Service_Interface {
|
28 |
|
29 |
protected $args = array();
|
lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpFactory.php
CHANGED
@@ -1,69 +1,50 @@
|
|
1 |
<?php
|
2 |
-
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
3 |
|
4 |
/**
|
5 |
-
*
|
6 |
*
|
7 |
-
*
|
|
|
|
|
|
|
8 |
*
|
9 |
-
*
|
10 |
-
*
|
11 |
-
*
|
12 |
-
*
|
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 |
-
*
|
17 |
-
*
|
18 |
*
|
19 |
-
*
|
20 |
-
*
|
21 |
-
*
|
22 |
-
*
|
23 |
-
*
|
24 |
-
*
|
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: 2.2.0
|
33 |
-
* @link https://github.com/yani-/mysqldump-factory/
|
34 |
*/
|
35 |
|
36 |
-
|
37 |
-
|
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: 2.2.0
|
46 |
-
* @link https://github.com/yani-/mysqldump-factory/
|
47 |
-
*/
|
48 |
class MysqlDumpFactory
|
49 |
{
|
50 |
-
public static function makeMysqlDump($hostname = 'localhost', $username = '', $password = '', $database = ''
|
51 |
{
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
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 |
-
|
|
|
|
|
|
|
67 |
}
|
|
|
|
|
68 |
}
|
69 |
}
|
1 |
<?php
|
|
|
2 |
|
3 |
/**
|
4 |
+
* Copyright (C) 2014 ServMask Inc.
|
5 |
*
|
6 |
+
* This program is free software: you can redistribute it and/or modify
|
7 |
+
* it under the terms of the GNU General Public License as published by
|
8 |
+
* the Free Software Foundation, either version 3 of the License, or
|
9 |
+
* (at your option) any later version.
|
10 |
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
|
|
|
|
15 |
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18 |
*
|
19 |
+
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
|
20 |
+
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
|
21 |
+
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
|
22 |
+
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
|
23 |
+
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
|
24 |
+
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
*/
|
26 |
|
27 |
+
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MysqlDumpPDO.php';
|
28 |
+
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MysqlDumpSQL.php';
|
29 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
class MysqlDumpFactory
|
31 |
{
|
32 |
+
public static function makeMysqlDump($hostname = 'localhost', $username = '', $password = '', $database = '')
|
33 |
{
|
34 |
+
try {
|
35 |
+
// Is PDO available?
|
36 |
+
if (class_exists('PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
|
37 |
+
$client = new MysqlDumpPDO($hostname, $username, $password, $database);
|
38 |
+
} else {
|
39 |
+
$client = new MysqlDumpSQL($hostname, $username, $password, $database);
|
40 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
// Test connection
|
43 |
+
$client->getConnection();
|
44 |
+
} catch (Exception $e) {
|
45 |
+
$client = new MysqlDumpSQL($hostname, $username, $password, $database);
|
46 |
}
|
47 |
+
|
48 |
+
return $client;
|
49 |
}
|
50 |
}
|
lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpInterface.php
CHANGED
@@ -1,50 +1,29 @@
|
|
1 |
<?php
|
2 |
-
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
3 |
|
4 |
/**
|
5 |
-
*
|
6 |
*
|
7 |
-
*
|
|
|
|
|
|
|
8 |
*
|
9 |
-
*
|
10 |
-
*
|
11 |
-
*
|
12 |
-
*
|
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 |
-
*
|
17 |
-
*
|
18 |
*
|
19 |
-
*
|
20 |
-
*
|
21 |
-
*
|
22 |
-
*
|
23 |
-
*
|
24 |
-
*
|
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: 2.2.0
|
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: 2.2.0
|
46 |
-
* @link https://github.com/yani-/mysqldump-factory/
|
47 |
-
*/
|
48 |
interface MysqlDumpInterface
|
49 |
{
|
50 |
/**
|
@@ -58,57 +37,35 @@ interface MysqlDumpInterface
|
|
58 |
*/
|
59 |
public function __construct($hostname = 'localhost', $username = '', $password = '', $database = '');
|
60 |
|
61 |
-
/**
|
62 |
-
* Export database into a file
|
63 |
-
*
|
64 |
-
* @return void
|
65 |
-
*/
|
66 |
-
public function export();
|
67 |
-
|
68 |
-
/**
|
69 |
-
* Set output file name
|
70 |
-
*
|
71 |
-
* @param string $fileName Name of the output file
|
72 |
-
* @return MysqlDumpInterface
|
73 |
-
*/
|
74 |
-
public function setFileName($fileName);
|
75 |
-
|
76 |
-
/**
|
77 |
-
* Get output file name
|
78 |
-
*
|
79 |
-
* @return string
|
80 |
-
*/
|
81 |
-
public function getFileName();
|
82 |
-
|
83 |
/**
|
84 |
* Set old table prefix
|
85 |
*
|
86 |
-
* @param
|
87 |
* @return MysqlDumpInterface
|
88 |
*/
|
89 |
-
public function
|
90 |
|
91 |
/**
|
92 |
-
* Get old table
|
93 |
*
|
94 |
-
* @return
|
95 |
*/
|
96 |
-
public function
|
97 |
|
98 |
/**
|
99 |
-
* Set new table
|
100 |
*
|
101 |
-
* @param
|
102 |
* @return MysqlDumpInterface
|
103 |
*/
|
104 |
-
public function
|
105 |
|
106 |
/**
|
107 |
-
* Get new table
|
108 |
*
|
109 |
-
* @return
|
110 |
*/
|
111 |
-
public function
|
112 |
|
113 |
/**
|
114 |
* Set old replace values
|
@@ -173,88 +130,62 @@ interface MysqlDumpInterface
|
|
173 |
public function getTablePrefixColumns($table);
|
174 |
|
175 |
/**
|
176 |
-
*
|
177 |
*
|
178 |
-
* @
|
179 |
-
|
180 |
-
public function getVersion();
|
181 |
-
|
182 |
-
/**
|
183 |
-
* Get MySQL max allowed packaet
|
184 |
-
*
|
185 |
-
* @return integer
|
186 |
-
*/
|
187 |
-
public function getMaxAllowedPacket();
|
188 |
-
|
189 |
-
/**
|
190 |
-
* Get MySQL collation name
|
191 |
-
*
|
192 |
-
* @param string $collationName Collation name
|
193 |
-
* @return string
|
194 |
-
*/
|
195 |
-
public function getCollation($collationName);
|
196 |
-
|
197 |
-
/**
|
198 |
-
* Flush database
|
199 |
-
*
|
200 |
-
* @return void
|
201 |
*/
|
202 |
-
public function
|
203 |
|
204 |
/**
|
205 |
-
*
|
206 |
*
|
207 |
-
* @
|
208 |
-
* @return bool
|
209 |
*/
|
210 |
-
public function
|
211 |
|
212 |
/**
|
213 |
-
* Get
|
214 |
*
|
215 |
* @return array
|
216 |
*/
|
217 |
-
public function
|
218 |
|
219 |
/**
|
220 |
-
*
|
221 |
*
|
222 |
-
* @
|
223 |
-
* @param boolean $first Replace first occurrence
|
224 |
-
* @param boolean $start Replace start occurrence
|
225 |
-
* @return string
|
226 |
*/
|
227 |
-
public function
|
228 |
|
229 |
/**
|
230 |
-
*
|
231 |
*
|
232 |
-
* @param string
|
233 |
-
* @
|
234 |
-
* @return string
|
235 |
*/
|
236 |
-
public function
|
237 |
|
238 |
/**
|
239 |
-
*
|
240 |
*
|
241 |
-
* @param string $
|
242 |
-
* @return
|
243 |
*/
|
244 |
-
public function
|
245 |
|
246 |
/**
|
247 |
-
*
|
248 |
*
|
249 |
-
* @param string $
|
250 |
-
* @return
|
251 |
*/
|
252 |
-
public function
|
253 |
|
254 |
/**
|
255 |
-
*
|
256 |
*
|
257 |
-
* @return
|
258 |
*/
|
259 |
-
public function
|
260 |
}
|
1 |
<?php
|
|
|
2 |
|
3 |
/**
|
4 |
+
* Copyright (C) 2014 ServMask Inc.
|
5 |
*
|
6 |
+
* This program is free software: you can redistribute it and/or modify
|
7 |
+
* it under the terms of the GNU General Public License as published by
|
8 |
+
* the Free Software Foundation, either version 3 of the License, or
|
9 |
+
* (at your option) any later version.
|
10 |
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
|
|
|
|
15 |
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18 |
*
|
19 |
+
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
|
20 |
+
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
|
21 |
+
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
|
22 |
+
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
|
23 |
+
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
|
24 |
+
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
*/
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
interface MysqlDumpInterface
|
28 |
{
|
29 |
/**
|
37 |
*/
|
38 |
public function __construct($hostname = 'localhost', $username = '', $password = '', $database = '');
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
/**
|
41 |
* Set old table prefix
|
42 |
*
|
43 |
+
* @param array $prefixes List of table prefixes
|
44 |
* @return MysqlDumpInterface
|
45 |
*/
|
46 |
+
public function setOldTablePrefixes($prefixes);
|
47 |
|
48 |
/**
|
49 |
+
* Get old table prefixes
|
50 |
*
|
51 |
+
* @return array
|
52 |
*/
|
53 |
+
public function getOldTablePrefixes();
|
54 |
|
55 |
/**
|
56 |
+
* Set new table prefixes
|
57 |
*
|
58 |
+
* @param array $prefixes List of table prefixes
|
59 |
* @return MysqlDumpInterface
|
60 |
*/
|
61 |
+
public function setNewTablePrefixes($prefixes);
|
62 |
|
63 |
/**
|
64 |
+
* Get new table prefixes
|
65 |
*
|
66 |
+
* @return array
|
67 |
*/
|
68 |
+
public function getNewTablePrefixes();
|
69 |
|
70 |
/**
|
71 |
* Set old replace values
|
130 |
public function getTablePrefixColumns($table);
|
131 |
|
132 |
/**
|
133 |
+
* Set exclude table prefixes
|
134 |
*
|
135 |
+
* @param array $prefixes List of table prefixes
|
136 |
+
* @return MysqlDumpInterface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
*/
|
138 |
+
public function setExcludeTablePrefixes($prefixes);
|
139 |
|
140 |
/**
|
141 |
+
* Get exclude table prefixes
|
142 |
*
|
143 |
+
* @return array
|
|
|
144 |
*/
|
145 |
+
public function getExcludeTablePrefixes();
|
146 |
|
147 |
/**
|
148 |
+
* Get tables
|
149 |
*
|
150 |
* @return array
|
151 |
*/
|
152 |
+
public function getTables();
|
153 |
|
154 |
/**
|
155 |
+
* Get MySQL connection (lazy loading)
|
156 |
*
|
157 |
+
* @return resource
|
|
|
|
|
|
|
158 |
*/
|
159 |
+
public function getConnection();
|
160 |
|
161 |
/**
|
162 |
+
* Run MySQL query
|
163 |
*
|
164 |
+
* @param string $query SQL query
|
165 |
+
* @return resource
|
|
|
166 |
*/
|
167 |
+
public function query($query);
|
168 |
|
169 |
/**
|
170 |
+
* Export database into a file
|
171 |
*
|
172 |
+
* @param string $fileName Name of file
|
173 |
+
* @return bool
|
174 |
*/
|
175 |
+
public function export($fileName);
|
176 |
|
177 |
/**
|
178 |
+
* Import database from file
|
179 |
*
|
180 |
+
* @param string $fileName Name of file
|
181 |
+
* @return bool
|
182 |
*/
|
183 |
+
public function import($fileName);
|
184 |
|
185 |
/**
|
186 |
+
* Flush database
|
187 |
*
|
188 |
+
* @return void
|
189 |
*/
|
190 |
+
public function flush();
|
191 |
}
|
lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpPDO.php
CHANGED
@@ -1,85 +1,63 @@
|
|
1 |
<?php
|
2 |
-
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
3 |
|
4 |
/**
|
5 |
-
*
|
6 |
*
|
7 |
-
*
|
|
|
|
|
|
|
8 |
*
|
9 |
-
*
|
10 |
-
*
|
11 |
-
*
|
12 |
-
*
|
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 |
-
*
|
17 |
-
*
|
18 |
*
|
19 |
-
*
|
20 |
-
*
|
21 |
-
*
|
22 |
-
*
|
23 |
-
*
|
24 |
-
*
|
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: 2.2.0
|
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 . '
|
38 |
-
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MysqlUtility.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: 2.2.0
|
50 |
-
* @link https://github.com/yani-/mysqldump-factory/
|
51 |
-
*/
|
52 |
class MysqlDumpPDO implements MysqlDumpInterface
|
53 |
{
|
54 |
-
protected $hostname
|
55 |
|
56 |
-
protected $port
|
57 |
|
58 |
-
protected $socket
|
59 |
|
60 |
-
protected $username
|
61 |
|
62 |
-
protected $password
|
63 |
|
64 |
-
protected $database
|
65 |
|
66 |
-
protected $
|
67 |
|
68 |
-
protected $
|
69 |
|
70 |
-
protected $
|
71 |
|
72 |
-
protected $
|
73 |
|
74 |
-
protected $
|
75 |
|
76 |
-
protected $
|
77 |
|
78 |
-
protected $
|
79 |
|
80 |
-
protected $
|
81 |
|
82 |
-
protected $
|
83 |
|
84 |
/**
|
85 |
* Define MySQL credentials for the current connection
|
@@ -104,103 +82,49 @@ class MysqlDumpPDO implements MysqlDumpInterface
|
|
104 |
}
|
105 |
|
106 |
/**
|
107 |
-
*
|
108 |
-
*
|
109 |
-
* @return void
|
110 |
-
*/
|
111 |
-
public function export()
|
112 |
-
{
|
113 |
-
// Set File Adapter
|
114 |
-
$this->fileAdapter = new MysqlFileAdapter();
|
115 |
-
|
116 |
-
// Set output file
|
117 |
-
$this->fileAdapter->open($this->getFileName());
|
118 |
-
|
119 |
-
// Write Headers Formatting dump file
|
120 |
-
$this->fileAdapter->write($this->getHeader());
|
121 |
-
|
122 |
-
// Listing all tables from database
|
123 |
-
$tables = $this->listTables();
|
124 |
-
|
125 |
-
// Export Tables
|
126 |
-
foreach ($tables as $table) {
|
127 |
-
$isTable = $this->getTableStructure($table);
|
128 |
-
if ($isTable) {
|
129 |
-
$this->listValues($table);
|
130 |
-
}
|
131 |
-
}
|
132 |
-
|
133 |
-
// Close File Adapter
|
134 |
-
$this->fileAdapter->close();
|
135 |
-
}
|
136 |
-
|
137 |
-
/**
|
138 |
-
* Set output file name
|
139 |
-
*
|
140 |
-
* @param string $fileName Name of the output file
|
141 |
-
* @return MysqlDumpPDO
|
142 |
-
*/
|
143 |
-
public function setFileName($fileName)
|
144 |
-
{
|
145 |
-
$this->fileName = $fileName;
|
146 |
-
|
147 |
-
return $this;
|
148 |
-
}
|
149 |
-
|
150 |
-
/**
|
151 |
-
* Get output file name
|
152 |
-
*
|
153 |
-
* @return string
|
154 |
-
*/
|
155 |
-
public function getFileName()
|
156 |
-
{
|
157 |
-
return $this->fileName;
|
158 |
-
}
|
159 |
-
|
160 |
-
/**
|
161 |
-
* Set old table prefix
|
162 |
*
|
163 |
-
* @param
|
164 |
* @return MysqlDumpPDO
|
165 |
*/
|
166 |
-
public function
|
167 |
{
|
168 |
-
$this->
|
169 |
|
170 |
return $this;
|
171 |
}
|
172 |
|
173 |
/**
|
174 |
-
* Get old table
|
175 |
*
|
176 |
-
* @return
|
177 |
*/
|
178 |
-
public function
|
179 |
{
|
180 |
-
return $this->
|
181 |
}
|
182 |
|
183 |
/**
|
184 |
-
* Set new table
|
185 |
*
|
186 |
-
* @param
|
187 |
* @return MysqlDumpPDO
|
188 |
*/
|
189 |
-
public function
|
190 |
{
|
191 |
-
$this->
|
192 |
|
193 |
return $this;
|
194 |
}
|
195 |
|
196 |
/**
|
197 |
-
* Get new table
|
198 |
*
|
199 |
-
* @return
|
200 |
*/
|
201 |
-
public function
|
202 |
{
|
203 |
-
return $this->
|
204 |
}
|
205 |
|
206 |
/**
|
@@ -304,97 +228,312 @@ class MysqlDumpPDO implements MysqlDumpInterface
|
|
304 |
}
|
305 |
|
306 |
/**
|
307 |
-
*
|
308 |
*
|
309 |
-
* @
|
|
|
310 |
*/
|
311 |
-
public function
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
return $row['VersionName'];
|
317 |
-
}
|
318 |
-
}
|
319 |
-
} catch (Exception $e) {
|
320 |
-
$result = $this->getConnection()->query("SHOW VARIABLES LIKE 'version'");
|
321 |
-
while ($row = $result->fetch(PDO::FETCH_NUM)) {
|
322 |
-
if (isset($row[1])) {
|
323 |
-
return $row[1];
|
324 |
-
}
|
325 |
-
}
|
326 |
-
}
|
327 |
}
|
328 |
|
329 |
/**
|
330 |
-
* Get
|
331 |
*
|
332 |
-
* @return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
333 |
*/
|
334 |
-
public function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
335 |
try {
|
336 |
-
$result = $this->getConnection()->query(
|
|
|
|
|
337 |
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
338 |
-
if (isset($row['
|
339 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
340 |
}
|
341 |
}
|
342 |
} catch (Exception $e) {
|
343 |
-
$result = $this->getConnection()->query("SHOW
|
344 |
while ($row = $result->fetch(PDO::FETCH_NUM)) {
|
345 |
-
if (isset($row[
|
346 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
347 |
}
|
348 |
}
|
349 |
}
|
|
|
|
|
350 |
}
|
351 |
|
352 |
/**
|
353 |
-
* Get MySQL
|
354 |
*
|
355 |
-
* @
|
356 |
-
* @return string
|
357 |
*/
|
358 |
-
public function
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
while ($row = $result->fetch(PDO::FETCH_NUM)) {
|
371 |
-
if (isset($row[0])) {
|
372 |
-
return $row[0];
|
373 |
}
|
374 |
}
|
375 |
}
|
|
|
|
|
376 |
}
|
377 |
|
378 |
/**
|
379 |
-
*
|
380 |
*
|
381 |
-
* @
|
|
|
382 |
*/
|
383 |
-
public function
|
384 |
{
|
385 |
-
$
|
386 |
-
|
387 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
388 |
}
|
389 |
|
390 |
-
//
|
391 |
-
|
392 |
-
|
393 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
394 |
}
|
395 |
|
396 |
/**
|
397 |
-
* Import database from file
|
398 |
*
|
399 |
* @param string $fileName Name of file
|
400 |
* @return bool
|
@@ -427,8 +566,8 @@ class MysqlDumpPDO implements MysqlDumpInterface
|
|
427 |
// Check max allowed packet
|
428 |
if (strlen($query) <= $maxAllowedPacket) {
|
429 |
|
430 |
-
// Replace table
|
431 |
-
$query = $this->
|
432 |
|
433 |
// Replace table values
|
434 |
$query = $this->replaceTableValues($query, true);
|
@@ -446,17 +585,9 @@ class MysqlDumpPDO implements MysqlDumpInterface
|
|
446 |
} else {
|
447 |
$passed++;
|
448 |
}
|
|
|
449 |
} catch (PDOException $e) {
|
450 |
$failed++;
|
451 |
-
|
452 |
-
// Log the error
|
453 |
-
Ai1wm_Log::error(
|
454 |
-
sprintf(
|
455 |
-
'Exception while importing: %s with query: %s',
|
456 |
-
$e->getMessage(),
|
457 |
-
$query
|
458 |
-
)
|
459 |
-
);
|
460 |
}
|
461 |
|
462 |
} else {
|
@@ -479,61 +610,130 @@ class MysqlDumpPDO implements MysqlDumpInterface
|
|
479 |
}
|
480 |
|
481 |
/**
|
482 |
-
*
|
483 |
*
|
484 |
-
* @return
|
485 |
*/
|
486 |
-
public function
|
487 |
{
|
488 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
489 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
490 |
try {
|
491 |
$result = $this->getConnection()->query(
|
492 |
-
"SELECT
|
493 |
);
|
494 |
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
495 |
-
if (isset($row['
|
496 |
-
|
497 |
}
|
498 |
}
|
499 |
} catch (Exception $e) {
|
500 |
-
$result = $this->getConnection()->query("SHOW
|
501 |
while ($row = $result->fetch(PDO::FETCH_NUM)) {
|
502 |
if (isset($row[0])) {
|
503 |
-
|
504 |
}
|
505 |
}
|
506 |
}
|
507 |
-
|
508 |
-
return $tables;
|
509 |
}
|
510 |
|
511 |
/**
|
512 |
-
* Replace table
|
513 |
*
|
514 |
-
* @param string
|
515 |
-
* @param boolean $first
|
516 |
-
* @param boolean $
|
517 |
* @return string
|
518 |
*/
|
519 |
-
|
520 |
{
|
521 |
-
// Get table
|
522 |
-
$search = $this->
|
523 |
-
$replace = $this->
|
524 |
|
525 |
-
// Replace
|
526 |
if ($first) {
|
527 |
-
|
528 |
-
|
529 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
530 |
}
|
531 |
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
|
|
537 |
}
|
538 |
|
539 |
return $input;
|
@@ -550,7 +750,7 @@ class MysqlDumpPDO implements MysqlDumpInterface
|
|
550 |
* @param boolean $parse Parse value
|
551 |
* @return string
|
552 |
*/
|
553 |
-
|
554 |
{
|
555 |
// Get replace values
|
556 |
$old = $this->getOldReplaceValues();
|
@@ -574,10 +774,10 @@ class MysqlDumpPDO implements MysqlDumpInterface
|
|
574 |
$input = $this->parseSerializedValues($input);
|
575 |
|
576 |
// Replace values
|
577 |
-
return
|
578 |
}
|
579 |
|
580 |
-
return
|
581 |
}
|
582 |
|
583 |
return $input;
|
@@ -589,7 +789,7 @@ class MysqlDumpPDO implements MysqlDumpInterface
|
|
589 |
* @param string $input Table value
|
590 |
* @return string
|
591 |
*/
|
592 |
-
|
593 |
{
|
594 |
// Serialization format
|
595 |
$array = '(a:\d+:{.*?})';
|
@@ -606,13 +806,13 @@ class MysqlDumpPDO implements MysqlDumpInterface
|
|
606 |
* @param array $matches List of matches
|
607 |
* @return string
|
608 |
*/
|
609 |
-
|
610 |
{
|
611 |
// Unescape MySQL special characters
|
612 |
-
$input =
|
613 |
|
614 |
// Replace serialized values
|
615 |
-
$input =
|
616 |
|
617 |
// Prepare query values
|
618 |
return $this->getConnection()->quote($input);
|
@@ -624,7 +824,7 @@ class MysqlDumpPDO implements MysqlDumpInterface
|
|
624 |
* @param string $input SQL statement
|
625 |
* @return string
|
626 |
*/
|
627 |
-
|
628 |
{
|
629 |
return str_replace('utf8mb4', 'utf8', $input);
|
630 |
}
|
@@ -635,7 +835,7 @@ class MysqlDumpPDO implements MysqlDumpInterface
|
|
635 |
* @param string $input SQL statement
|
636 |
* @return string
|
637 |
*/
|
638 |
-
|
639 |
{
|
640 |
$pattern = array(
|
641 |
'/\s+CONSTRAINT(.+)REFERENCES(.+),/i',
|
@@ -646,30 +846,6 @@ class MysqlDumpPDO implements MysqlDumpInterface
|
|
646 |
return preg_replace($pattern, $replace, $input);
|
647 |
}
|
648 |
|
649 |
-
/**
|
650 |
-
* Get MySQL connection (lazy loading)
|
651 |
-
*
|
652 |
-
* @return PDO
|
653 |
-
*/
|
654 |
-
public function getConnection()
|
655 |
-
{
|
656 |
-
if ($this->connection === null) {
|
657 |
-
try {
|
658 |
-
// Make connection (Socket)
|
659 |
-
$this->connection = $this->makeConnection();
|
660 |
-
} catch (Exception $e) {
|
661 |
-
try {
|
662 |
-
// Make connection (TCP)
|
663 |
-
$this->connection = $this->makeConnection(false);
|
664 |
-
} catch (Exception $e) {
|
665 |
-
throw new Exception('Unable to connect to MySQL database server: ' . $e->getMessage());
|
666 |
-
}
|
667 |
-
}
|
668 |
-
}
|
669 |
-
|
670 |
-
return $this->connection;
|
671 |
-
}
|
672 |
-
|
673 |
/**
|
674 |
* Make MySQL connection
|
675 |
*
|
@@ -726,7 +902,8 @@ class MysqlDumpPDO implements MysqlDumpInterface
|
|
726 |
"-- http://servmask.com/\n" .
|
727 |
"--\n" .
|
728 |
"-- Host: {$this->hostname}\n" .
|
729 |
-
"-- Generation Time: " . date('r') . "\n
|
|
|
730 |
"--\n" .
|
731 |
"-- Database: `{$this->database}`\n" .
|
732 |
"--\n\n";
|
@@ -734,90 +911,6 @@ class MysqlDumpPDO implements MysqlDumpInterface
|
|
734 |
return $header;
|
735 |
}
|
736 |
|
737 |
-
/**
|
738 |
-
* Table structure extractor
|
739 |
-
*
|
740 |
-
* @param string $tableName Name of table to export
|
741 |
-
* @return bool
|
742 |
-
*/
|
743 |
-
protected function getTableStructure($tableName)
|
744 |
-
{
|
745 |
-
$result = $this->getConnection()->query("SHOW CREATE TABLE `$tableName`");
|
746 |
-
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
747 |
-
if (isset($row['Create Table'])) {
|
748 |
-
|
749 |
-
// Replace table prefix
|
750 |
-
$createTable = $this->replaceTablePrefix($row['Create Table'], true);
|
751 |
-
|
752 |
-
// Strip table constraints
|
753 |
-
$createTable = $this->stripTableConstraints($createTable);
|
754 |
-
|
755 |
-
// Write table structure
|
756 |
-
$this->fileAdapter->write($createTable);
|
757 |
-
|
758 |
-
// Write end of statement
|
759 |
-
$this->fileAdapter->write(";\n\n");
|
760 |
-
|
761 |
-
return true;
|
762 |
-
}
|
763 |
-
}
|
764 |
-
|
765 |
-
return false;
|
766 |
-
}
|
767 |
-
|
768 |
-
/**
|
769 |
-
* Table rows extractor
|
770 |
-
*
|
771 |
-
* @param string $tableName Name of table to export
|
772 |
-
* @return void
|
773 |
-
*/
|
774 |
-
protected function listValues($tableName)
|
775 |
-
{
|
776 |
-
// Set query
|
777 |
-
$query = "SELECT * FROM `$tableName` ";
|
778 |
-
|
779 |
-
// Apply additional query clauses
|
780 |
-
$clauses = $this->getQueryClauses();
|
781 |
-
if (isset($clauses[$tableName]) && ($queryClause = $clauses[$tableName])) {
|
782 |
-
$query .= $queryClause;
|
783 |
-
}
|
784 |
-
|
785 |
-
// Apply additional table prefix columns
|
786 |
-
$columns = $this->getTablePrefixColumns($tableName);
|
787 |
-
|
788 |
-
// Get results
|
789 |
-
$result = $this->getConnection()->query($query);
|
790 |
-
|
791 |
-
// Replace table name prefix
|
792 |
-
$tableName = $this->replaceTablePrefix($tableName, true);
|
793 |
-
|
794 |
-
// Generate insert statements
|
795 |
-
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
796 |
-
$items = array();
|
797 |
-
foreach ($row as $key => $value) {
|
798 |
-
// Replace table prefix columns
|
799 |
-
if (isset($columns[$key])) {
|
800 |
-
$value = $this->replaceTablePrefix($value, false, true);
|
801 |
-
}
|
802 |
-
|
803 |
-
// Replace table values
|
804 |
-
$items[] = is_null($value) ? 'NULL' : $this->getConnection()->quote($this->replaceTableValues($value));
|
805 |
-
}
|
806 |
-
|
807 |
-
// Set table values
|
808 |
-
$tableValues = implode(',', $items);
|
809 |
-
|
810 |
-
// Write insert statements
|
811 |
-
$this->fileAdapter->write("INSERT INTO `$tableName` VALUES ($tableValues);\n");
|
812 |
-
}
|
813 |
-
|
814 |
-
// Write end of statements
|
815 |
-
$this->fileAdapter->write("\n");
|
816 |
-
|
817 |
-
// Close result cursor
|
818 |
-
$result->closeCursor();
|
819 |
-
}
|
820 |
-
|
821 |
/**
|
822 |
* Parse data source name
|
823 |
*
|
1 |
<?php
|
|
|
2 |
|
3 |
/**
|
4 |
+
* Copyright (C) 2014 ServMask Inc.
|
5 |
*
|
6 |
+
* This program is free software: you can redistribute it and/or modify
|
7 |
+
* it under the terms of the GNU General Public License as published by
|
8 |
+
* the Free Software Foundation, either version 3 of the License, or
|
9 |
+
* (at your option) any later version.
|
10 |
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
|
|
|
|
15 |
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18 |
*
|
19 |
+
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
|
20 |
+
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
|
21 |
+
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
|
22 |
+
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
|
23 |
+
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
|
24 |
+
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
*/
|
26 |
|
27 |
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MysqlDumpInterface.php';
|
28 |
+
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MysqlDumpUtility.php';
|
|
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
class MysqlDumpPDO implements MysqlDumpInterface
|
31 |
{
|
32 |
+
protected $hostname = null;
|
33 |
|
34 |
+
protected $port = null;
|
35 |
|
36 |
+
protected $socket = null;
|
37 |
|
38 |
+
protected $username = null;
|
39 |
|
40 |
+
protected $password = null;
|
41 |
|
42 |
+
protected $database = null;
|
43 |
|
44 |
+
protected $connection = null;
|
45 |
|
46 |
+
protected $oldTablePrefixes = null;
|
47 |
|
48 |
+
protected $newTablePrefixes = null;
|
49 |
|
50 |
+
protected $oldReplaceValues = array();
|
51 |
|
52 |
+
protected $newReplaceValues = array();
|
53 |
|
54 |
+
protected $queryClauses = array();
|
55 |
|
56 |
+
protected $tablePrefixColumns = array();
|
57 |
|
58 |
+
protected $includeTablePrefixes = array();
|
59 |
|
60 |
+
protected $excludeTablePrefixes = array();
|
61 |
|
62 |
/**
|
63 |
* Define MySQL credentials for the current connection
|
82 |
}
|
83 |
|
84 |
/**
|
85 |
+
* Set old table prefixes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
*
|
87 |
+
* @param array $prefixes List of table prefixes
|
88 |
* @return MysqlDumpPDO
|
89 |
*/
|
90 |
+
public function setOldTablePrefixes($prefixes)
|
91 |
{
|
92 |
+
$this->oldTablePrefixes = $prefixes;
|
93 |
|
94 |
return $this;
|
95 |
}
|
96 |
|
97 |
/**
|
98 |
+
* Get old table prefixes
|
99 |
*
|
100 |
+
* @return array
|
101 |
*/
|
102 |
+
public function getOldTablePrefixes()
|
103 |
{
|
104 |
+
return $this->oldTablePrefixes;
|
105 |
}
|
106 |
|
107 |
/**
|
108 |
+
* Set new table prefixes
|
109 |
*
|
110 |
+
* @param array $prefix List of table prefixes
|
111 |
* @return MysqlDumpPDO
|
112 |
*/
|
113 |
+
public function setNewTablePrefixes($prefixes)
|
114 |
{
|
115 |
+
$this->newTablePrefixes = $prefixes;
|
116 |
|
117 |
return $this;
|
118 |
}
|
119 |
|
120 |
/**
|
121 |
+
* Get new table prefixes
|
122 |
*
|
123 |
+
* @return array
|
124 |
*/
|
125 |
+
public function getNewTablePrefixes()
|
126 |
{
|
127 |
+
return $this->newTablePrefixes;
|
128 |
}
|
129 |
|
130 |
/**
|
228 |
}
|
229 |
|
230 |
/**
|
231 |
+
* Set include table prefixes
|
232 |
*
|
233 |
+
* @param array $prefixes List of table prefixes
|
234 |
+
* @return MysqlDumpPDO
|
235 |
*/
|
236 |
+
public function setIncludeTablePrefixes($prefixes)
|
237 |
+
{
|
238 |
+
$this->includeTablePrefixes = $prefixes;
|
239 |
+
|
240 |
+
return $this;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
}
|
242 |
|
243 |
/**
|
244 |
+
* Get include table prefixes
|
245 |
*
|
246 |
+
* @return array
|
247 |
+
*/
|
248 |
+
public function getIncludeTablePrefixes()
|
249 |
+
{
|
250 |
+
return $this->includeTablePrefixes;
|
251 |
+
}
|
252 |
+
|
253 |
+
/**
|
254 |
+
* Set exclude table prefixes
|
255 |
+
*
|
256 |
+
* @param array $prefixes List of table prefixes
|
257 |
+
* @return MysqlDumpPDO
|
258 |
+
*/
|
259 |
+
public function setExcludeTablePrefixes($prefixes)
|
260 |
+
{
|
261 |
+
$this->excludeTablePrefixes = $prefixes;
|
262 |
+
|
263 |
+
return $this;
|
264 |
+
}
|
265 |
+
|
266 |
+
/**
|
267 |
+
* Get exclude table prefixes
|
268 |
+
*
|
269 |
+
* @return array
|
270 |
*/
|
271 |
+
public function getExcludeTablePrefixes()
|
272 |
+
{
|
273 |
+
return $this->excludeTablePrefixes;
|
274 |
+
}
|
275 |
+
|
276 |
+
/**
|
277 |
+
* Get tables
|
278 |
+
*
|
279 |
+
* @return array
|
280 |
+
*/
|
281 |
+
public function getTables()
|
282 |
+
{
|
283 |
+
$tables = array();
|
284 |
+
|
285 |
try {
|
286 |
+
$result = $this->getConnection()->query(
|
287 |
+
"SELECT TABLE_NAME AS TableName FROM `INFORMATION_SCHEMA`.`TABLES` WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = '{$this->database}'"
|
288 |
+
);
|
289 |
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
290 |
+
if (isset($row['TableName']) && ($tableName = $row['TableName'])) {
|
291 |
+
|
292 |
+
// Include table prefixes
|
293 |
+
if ($this->getIncludeTablePrefixes()) {
|
294 |
+
$include = false;
|
295 |
+
|
296 |
+
// Check table prefixes
|
297 |
+
foreach ($this->getIncludeTablePrefixes() as $prefix) {
|
298 |
+
if (strpos($tableName, $prefix) === 0) {
|
299 |
+
$include = true;
|
300 |
+
break;
|
301 |
+
}
|
302 |
+
}
|
303 |
+
|
304 |
+
// Skip current table
|
305 |
+
if ($include === false) {
|
306 |
+
continue;
|
307 |
+
}
|
308 |
+
}
|
309 |
+
|
310 |
+
// Exclude table prefixes
|
311 |
+
if ($this->getExcludeTablePrefixes()) {
|
312 |
+
$exclude = false;
|
313 |
+
|
314 |
+
// Check table prefixes
|
315 |
+
foreach ($this->getExcludeTablePrefixes() as $prefix) {
|
316 |
+
if (strpos($tableName, $prefix) === 0) {
|
317 |
+
$exclude = true;
|
318 |
+
break;
|
319 |
+
}
|
320 |
+
}
|
321 |
+
|
322 |
+
// Skip current table
|
323 |
+
if ($exclude === true) {
|
324 |
+
continue;
|
325 |
+
}
|
326 |
+
}
|
327 |
+
|
328 |
+
// Add table name
|
329 |
+
$tables[] = $tableName;
|
330 |
}
|
331 |
}
|
332 |
} catch (Exception $e) {
|
333 |
+
$result = $this->getConnection()->query("SHOW TABLES FROM `{$this->database}`");
|
334 |
while ($row = $result->fetch(PDO::FETCH_NUM)) {
|
335 |
+
if (isset($row[0]) && ($tableName = $row[0])) {
|
336 |
+
|
337 |
+
// Include table prefixes
|
338 |
+
if ($this->getIncludeTablePrefixes()) {
|
339 |
+
$include = false;
|
340 |
+
|
341 |
+
// Check table prefixes
|
342 |
+
foreach ($this->getIncludeTablePrefixes() as $prefix) {
|
343 |
+
if (strpos($tableName, $prefix) === 0) {
|
344 |
+
$include = true;
|
345 |
+
break;
|
346 |
+
}
|
347 |
+
}
|
348 |
+
|
349 |
+
// Skip current table
|
350 |
+
if ($include === false) {
|
351 |
+
continue;
|
352 |
+
}
|
353 |
+
}
|
354 |
+
|
355 |
+
// Exclude table prefixes
|
356 |
+
if ($this->getExcludeTablePrefixes()) {
|
357 |
+
$exclude = false;
|
358 |
+
|
359 |
+
// Check table prefixes
|
360 |
+
foreach ($this->getExcludeTablePrefixes() as $prefix) {
|
361 |
+
if (strpos($tableName, $prefix) === 0) {
|
362 |
+
$exclude = true;
|
363 |
+
break;
|
364 |
+
}
|
365 |
+
}
|
366 |
+
|
367 |
+
// Skip current table
|
368 |
+
if ($exclude === true) {
|
369 |
+
continue;
|
370 |
+
}
|
371 |
+
}
|
372 |
+
|
373 |
+
// Add table name
|
374 |
+
$tables[] = $tableName;
|
375 |
}
|
376 |
}
|
377 |
}
|
378 |
+
|
379 |
+
return $tables;
|
380 |
}
|
381 |
|
382 |
/**
|
383 |
+
* Get MySQL connection (lazy loading)
|
384 |
*
|
385 |
+
* @return PDO
|
|
|
386 |
*/
|
387 |
+
public function getConnection()
|
388 |
+
{
|
389 |
+
if ($this->connection === null) {
|
390 |
+
try {
|
391 |
+
// Make connection (Socket)
|
392 |
+
$this->connection = $this->makeConnection();
|
393 |
+
} catch (Exception $e) {
|
394 |
+
try {
|
395 |
+
// Make connection (TCP)
|
396 |
+
$this->connection = $this->makeConnection(false);
|
397 |
+
} catch (Exception $e) {
|
398 |
+
throw new Exception('Unable to connect to MySQL database server: ' . $e->getMessage());
|
|
|
|
|
|
|
399 |
}
|
400 |
}
|
401 |
}
|
402 |
+
|
403 |
+
return $this->connection;
|
404 |
}
|
405 |
|
406 |
/**
|
407 |
+
* Run MySQL query
|
408 |
*
|
409 |
+
* @param string $query SQL query
|
410 |
+
* @return resource
|
411 |
*/
|
412 |
+
public function query($query)
|
413 |
{
|
414 |
+
return $this->getConnection()->query($query);
|
415 |
+
}
|
416 |
+
|
417 |
+
/**
|
418 |
+
* Export database into a file
|
419 |
+
*
|
420 |
+
* @param string $fileName Name of file
|
421 |
+
* @return bool
|
422 |
+
*/
|
423 |
+
public function export($fileName)
|
424 |
+
{
|
425 |
+
// Set file handler
|
426 |
+
$fileHandler = fopen($fileName, 'wb');
|
427 |
+
if ($fileHandler === false) {
|
428 |
+
throw new Exception('Unable to open database file');
|
429 |
}
|
430 |
|
431 |
+
// Write headers
|
432 |
+
if (fwrite($fileHandler, $this->getHeader()) === false) {
|
433 |
+
throw new Exception('Unable to write database header information');
|
434 |
}
|
435 |
+
|
436 |
+
// Export tables
|
437 |
+
foreach ($this->getTables() as $tableName) {
|
438 |
+
|
439 |
+
// Replace table name prefixes
|
440 |
+
$newTableName = $this->replaceTablePrefixes($tableName, true);
|
441 |
+
|
442 |
+
// Get table structure
|
443 |
+
$structure = $this->getConnection()->query("SHOW CREATE TABLE `$tableName`");
|
444 |
+
$table = $structure->fetch(PDO::FETCH_ASSOC);
|
445 |
+
if (isset($table['Create Table'])) {
|
446 |
+
|
447 |
+
// Write table drop statement
|
448 |
+
$dropTable = "DROP TABLE IF EXISTS `$newTableName`;\n";
|
449 |
+
|
450 |
+
// Write table statement
|
451 |
+
if (fwrite($fileHandler, $dropTable) === false) {
|
452 |
+
throw new Exception('Unable to write database table statement');
|
453 |
+
}
|
454 |
+
|
455 |
+
// Replace create table prefixes
|
456 |
+
$createTable = $this->replaceTablePrefixes($table['Create Table'], true);
|
457 |
+
|
458 |
+
// Strip table constraints
|
459 |
+
$createTable = $this->stripTableConstraints($createTable);
|
460 |
+
|
461 |
+
// Write table structure
|
462 |
+
if (fwrite($fileHandler, $createTable) === false) {
|
463 |
+
throw new Exception('Unable to write database table structure');
|
464 |
+
}
|
465 |
+
|
466 |
+
// Write end of statement
|
467 |
+
if (fwrite($fileHandler, ";\n\n") === false) {
|
468 |
+
throw new Exception('Unable to write database end of statement');
|
469 |
+
}
|
470 |
+
|
471 |
+
// Close structure cursor
|
472 |
+
$structure->closeCursor();
|
473 |
+
} else {
|
474 |
+
// Close structure cursor
|
475 |
+
$structure->closeCursor();
|
476 |
+
|
477 |
+
break;
|
478 |
+
}
|
479 |
+
|
480 |
+
// Set query
|
481 |
+
$query = "SELECT * FROM `$tableName` ";
|
482 |
+
|
483 |
+
// Apply additional query clauses
|
484 |
+
$clauses = $this->getQueryClauses();
|
485 |
+
if (isset($clauses[$tableName]) && ($queryClause = $clauses[$tableName])) {
|
486 |
+
$query .= $queryClause;
|
487 |
+
}
|
488 |
+
|
489 |
+
// Apply additional table prefix columns
|
490 |
+
$columns = $this->getTablePrefixColumns($tableName);
|
491 |
+
|
492 |
+
// Get results
|
493 |
+
$result = $this->getConnection()->query($query);
|
494 |
+
|
495 |
+
// Generate insert statements
|
496 |
+
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
497 |
+
$items = array();
|
498 |
+
foreach ($row as $key => $value) {
|
499 |
+
// Replace table prefix columns
|
500 |
+
if (isset($columns[$key])) {
|
501 |
+
$value = $this->replaceTablePrefixes($value, true, 0);
|
502 |
+
}
|
503 |
+
|
504 |
+
// Replace table values
|
505 |
+
$items[] = is_null($value) ? 'NULL' : $this->getConnection()->quote($this->replaceTableValues($value));
|
506 |
+
}
|
507 |
+
|
508 |
+
// Set table values
|
509 |
+
$tableValues = implode(',', $items);
|
510 |
+
|
511 |
+
// Set insert statement
|
512 |
+
$tableInsert = "INSERT INTO `$newTableName` VALUES ($tableValues);\n";
|
513 |
+
|
514 |
+
// Write insert statement
|
515 |
+
if (fwrite($fileHandler, $tableInsert) === false) {
|
516 |
+
throw new Exception('Unable to write database insert statement');
|
517 |
+
}
|
518 |
+
}
|
519 |
+
|
520 |
+
// Write end of statements
|
521 |
+
if (fwrite($fileHandler, "\n") === false) {
|
522 |
+
throw new Exception('Unable to write database end of statement');
|
523 |
+
}
|
524 |
+
|
525 |
+
// Close result cursor
|
526 |
+
$result->closeCursor();
|
527 |
+
}
|
528 |
+
|
529 |
+
// Close file handler
|
530 |
+
fclose($fileHandler);
|
531 |
+
|
532 |
+
return true;
|
533 |
}
|
534 |
|
535 |
/**
|
536 |
+
* Import database from a file
|
537 |
*
|
538 |
* @param string $fileName Name of file
|
539 |
* @return bool
|
566 |
// Check max allowed packet
|
567 |
if (strlen($query) <= $maxAllowedPacket) {
|
568 |
|
569 |
+
// Replace table prefixes
|
570 |
+
$query = $this->replaceTablePrefixes($query);
|
571 |
|
572 |
// Replace table values
|
573 |
$query = $this->replaceTableValues($query, true);
|
585 |
} else {
|
586 |
$passed++;
|
587 |
}
|
588 |
+
|
589 |
} catch (PDOException $e) {
|
590 |
$failed++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
591 |
}
|
592 |
|
593 |
} else {
|
610 |
}
|
611 |
|
612 |
/**
|
613 |
+
* Flush database
|
614 |
*
|
615 |
+
* @return void
|
616 |
*/
|
617 |
+
public function flush()
|
618 |
{
|
619 |
+
$dropTables = array();
|
620 |
+
foreach ($this->getTables() as $tableName) {
|
621 |
+
$dropTables[] = "DROP TABLE IF EXISTS `$tableName`";
|
622 |
+
}
|
623 |
+
|
624 |
+
// Drop tables
|
625 |
+
foreach ($dropTables as $dropQuery) {
|
626 |
+
$this->getConnection()->query($dropQuery);
|
627 |
+
}
|
628 |
+
}
|
629 |
+
|
630 |
+
/**
|
631 |
+
* Get MySQL version
|
632 |
+
*
|
633 |
+
* @return string
|
634 |
+
*/
|
635 |
+
protected function getVersion() {
|
636 |
+
try {
|
637 |
+
$result = $this->getConnection()->query("SELECT @@version AS VersionName");
|
638 |
+
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
639 |
+
if (isset($row['VersionName'])) {
|
640 |
+
return $row['VersionName'];
|
641 |
+
}
|
642 |
+
}
|
643 |
+
} catch (Exception $e) {
|
644 |
+
$result = $this->getConnection()->query("SHOW VARIABLES LIKE 'version'");
|
645 |
+
while ($row = $result->fetch(PDO::FETCH_NUM)) {
|
646 |
+
if (isset($row[1])) {
|
647 |
+
return $row[1];
|
648 |
+
}
|
649 |
+
}
|
650 |
+
}
|
651 |
+
}
|
652 |
|
653 |
+
/**
|
654 |
+
* Get MySQL max allowed packaet
|
655 |
+
*
|
656 |
+
* @return integer
|
657 |
+
*/
|
658 |
+
protected function getMaxAllowedPacket() {
|
659 |
+
try {
|
660 |
+
$result = $this->getConnection()->query("SELECT @@max_allowed_packet AS MaxAllowedPacket");
|
661 |
+
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
662 |
+
if (isset($row['MaxAllowedPacket'])) {
|
663 |
+
return $row['MaxAllowedPacket'];
|
664 |
+
}
|
665 |
+
}
|
666 |
+
} catch (Exception $e) {
|
667 |
+
$result = $this->getConnection()->query("SHOW VARIABLES LIKE 'max_allowed_packet'");
|
668 |
+
while ($row = $result->fetch(PDO::FETCH_NUM)) {
|
669 |
+
if (isset($row[1])) {
|
670 |
+
return $row[1];
|
671 |
+
}
|
672 |
+
}
|
673 |
+
}
|
674 |
+
}
|
675 |
+
|
676 |
+
/**
|
677 |
+
* Get MySQL collation name
|
678 |
+
*
|
679 |
+
* @param string $collationName Collation name
|
680 |
+
* @return string
|
681 |
+
*/
|
682 |
+
protected function getCollation($collationName) {
|
683 |
try {
|
684 |
$result = $this->getConnection()->query(
|
685 |
+
"SELECT COLLATION_NAME AS CollationName FROM `INFORMATION_SCHEMA`.`COLLATIONS` WHERE COLLATION_NAME = '$collationName'"
|
686 |
);
|
687 |
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
688 |
+
if (isset($row['CollationName'])) {
|
689 |
+
return $row['CollationName'];
|
690 |
}
|
691 |
}
|
692 |
} catch (Exception $e) {
|
693 |
+
$result = $this->getConnection()->query("SHOW COLLATION LIKE '$collationName'");
|
694 |
while ($row = $result->fetch(PDO::FETCH_NUM)) {
|
695 |
if (isset($row[0])) {
|
696 |
+
return $row[0];
|
697 |
}
|
698 |
}
|
699 |
}
|
|
|
|
|
700 |
}
|
701 |
|
702 |
/**
|
703 |
+
* Replace table prefixes
|
704 |
*
|
705 |
+
* @param string $input Table value
|
706 |
+
* @param boolean $first Replace first occurrence at any position
|
707 |
+
* @param boolean $position Replace first occurrence at a specified position
|
708 |
* @return string
|
709 |
*/
|
710 |
+
protected function replaceTablePrefixes($input, $first = false, $position = false)
|
711 |
{
|
712 |
+
// Get table prefixes
|
713 |
+
$search = $this->getOldTablePrefixes();
|
714 |
+
$replace = $this->getNewTablePrefixes();
|
715 |
|
716 |
+
// Replace table prefixes
|
717 |
if ($first) {
|
718 |
+
|
719 |
+
// Replace first occurance at a specified position
|
720 |
+
if ($position !== false) {
|
721 |
+
for ($i = 0; $i < count($search); $i++) {
|
722 |
+
$current = strpos($input, $search[$i]);
|
723 |
+
if ($current === $position) {
|
724 |
+
$input = substr_replace($input, $replace[$i], $current, strlen($search[$i]));
|
725 |
+
}
|
726 |
+
}
|
727 |
+
|
728 |
+
return $input;
|
729 |
}
|
730 |
|
731 |
+
// Replace first occurance at any position
|
732 |
+
for ($i = 0; $i < count($search); $i++) {
|
733 |
+
$current = strpos($input, $search[$i]);
|
734 |
+
if ($current !== $position) {
|
735 |
+
$input = substr_replace($input, $replace[$i], $current, strlen($search[$i]));
|
736 |
+
}
|
737 |
}
|
738 |
|
739 |
return $input;
|
750 |
* @param boolean $parse Parse value
|
751 |
* @return string
|
752 |
*/
|
753 |
+
protected function replaceTableValues($input, $parse = false)
|
754 |
{
|
755 |
// Get replace values
|
756 |
$old = $this->getOldReplaceValues();
|
774 |
$input = $this->parseSerializedValues($input);
|
775 |
|
776 |
// Replace values
|
777 |
+
return MysqlDumpUtility::replaceValues($oldValues, $newValues, $input);
|
778 |
}
|
779 |
|
780 |
+
return MysqlDumpUtility::replaceSerializedValues($oldValues, $newValues, $input);
|
781 |
}
|
782 |
|
783 |
return $input;
|
789 |
* @param string $input Table value
|
790 |
* @return string
|
791 |
*/
|
792 |
+
protected function parseSerializedValues($input)
|
793 |
{
|
794 |
// Serialization format
|
795 |
$array = '(a:\d+:{.*?})';
|
806 |
* @param array $matches List of matches
|
807 |
* @return string
|
808 |
*/
|
809 |
+
protected function replaceSerializedValues($matches)
|
810 |
{
|
811 |
// Unescape MySQL special characters
|
812 |
+
$input = MysqlDumpUtility::unescapeMysql($matches[1]);
|
813 |
|
814 |
// Replace serialized values
|
815 |
+
$input = MysqlDumpUtility::replaceSerializedValues($this->getOldReplaceValues(), $this->getNewReplaceValues(), $input);
|
816 |
|
817 |
// Prepare query values
|
818 |
return $this->getConnection()->quote($input);
|
824 |
* @param string $input SQL statement
|
825 |
* @return string
|
826 |
*/
|
827 |
+
protected function replaceTableCollation($input)
|
828 |
{
|
829 |
return str_replace('utf8mb4', 'utf8', $input);
|
830 |
}
|
835 |
* @param string $input SQL statement
|
836 |
* @return string
|
837 |
*/
|
838 |
+
protected function stripTableConstraints($input)
|
839 |
{
|
840 |
$pattern = array(
|
841 |
'/\s+CONSTRAINT(.+)REFERENCES(.+),/i',
|
846 |
return preg_replace($pattern, $replace, $input);
|
847 |
}
|
848 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
849 |
/**
|
850 |
* Make MySQL connection
|
851 |
*
|
902 |
"-- http://servmask.com/\n" .
|
903 |
"--\n" .
|
904 |
"-- Host: {$this->hostname}\n" .
|
905 |
+
"-- Generation Time: " . date('r') . "\n" .
|
906 |
+
"-- PDO Extension\n\n" .
|
907 |
"--\n" .
|
908 |
"-- Database: `{$this->database}`\n" .
|
909 |
"--\n\n";
|
911 |
return $header;
|
912 |
}
|
913 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
914 |
/**
|
915 |
* Parse data source name
|
916 |
*
|
lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpSQL.php
CHANGED
@@ -1,81 +1,59 @@
|
|
1 |
<?php
|
2 |
-
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
3 |
|
4 |
/**
|
5 |
-
*
|
6 |
*
|
7 |
-
*
|
|
|
|
|
|
|
8 |
*
|
9 |
-
*
|
10 |
-
*
|
11 |
-
*
|
12 |
-
*
|
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 |
-
*
|
17 |
-
*
|
18 |
*
|
19 |
-
*
|
20 |
-
*
|
21 |
-
*
|
22 |
-
*
|
23 |
-
*
|
24 |
-
*
|
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: 2.2.0
|
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 . '
|
38 |
-
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MysqlUtility.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: 2.2.0
|
50 |
-
* @link https://github.com/yani-/mysqldump-factory/
|
51 |
-
*/
|
52 |
class MysqlDumpSQL implements MysqlDumpInterface
|
53 |
{
|
54 |
-
protected $hostname
|
55 |
|
56 |
-
protected $username
|
57 |
|
58 |
-
protected $password
|
59 |
|
60 |
-
protected $database
|
61 |
|
62 |
-
protected $
|
63 |
|
64 |
-
protected $
|
65 |
|
66 |
-
protected $
|
67 |
|
68 |
-
protected $
|
69 |
|
70 |
-
protected $
|
71 |
|
72 |
-
protected $
|
73 |
|
74 |
-
protected $
|
75 |
|
76 |
-
protected $
|
77 |
|
78 |
-
protected $
|
79 |
|
80 |
/**
|
81 |
* Define MySQL credentials for the current connection
|
@@ -96,103 +74,49 @@ class MysqlDumpSQL implements MysqlDumpInterface
|
|
96 |
}
|
97 |
|
98 |
/**
|
99 |
-
*
|
100 |
*
|
101 |
-
* @
|
102 |
-
*/
|
103 |
-
public function export()
|
104 |
-
{
|
105 |
-
// Set File Adapter
|
106 |
-
$this->fileAdapter = new MysqlFileAdapter();
|
107 |
-
|
108 |
-
// Set output file
|
109 |
-
$this->fileAdapter->open($this->getFileName());
|
110 |
-
|
111 |
-
// Write Headers Formatting dump file
|
112 |
-
$this->fileAdapter->write($this->getHeader());
|
113 |
-
|
114 |
-
// Listing all tables from database
|
115 |
-
$tables = $this->listTables();
|
116 |
-
|
117 |
-
// Export Tables
|
118 |
-
foreach ($tables as $table) {
|
119 |
-
$isTable = $this->getTableStructure($table);
|
120 |
-
if ($isTable) {
|
121 |
-
$this->listValues($table);
|
122 |
-
}
|
123 |
-
}
|
124 |
-
|
125 |
-
// Close File Adapter
|
126 |
-
$this->fileAdapter->close();
|
127 |
-
}
|
128 |
-
|
129 |
-
/**
|
130 |
-
* Set output file name
|
131 |
-
*
|
132 |
-
* @param string $fileName Name of the output file
|
133 |
* @return MysqlDumpSQL
|
134 |
*/
|
135 |
-
public function
|
136 |
{
|
137 |
-
$this->
|
138 |
|
139 |
return $this;
|
140 |
}
|
141 |
|
142 |
/**
|
143 |
-
* Get
|
144 |
*
|
145 |
-
* @return
|
146 |
-
*/
|
147 |
-
public function getFileName()
|
148 |
-
{
|
149 |
-
return $this->fileName;
|
150 |
-
}
|
151 |
-
|
152 |
-
/**
|
153 |
-
* Set old table prefix
|
154 |
-
*
|
155 |
-
* @param string $prefix Name of the table prefix
|
156 |
-
* @return MysqlDumpSQL
|
157 |
-
*/
|
158 |
-
public function setOldTablePrefix($prefix)
|
159 |
-
{
|
160 |
-
$this->oldTablePrefix = $prefix;
|
161 |
-
|
162 |
-
return $this;
|
163 |
-
}
|
164 |
-
|
165 |
-
/**
|
166 |
-
* Get old table prefix
|
167 |
-
*
|
168 |
-
* @return string
|
169 |
*/
|
170 |
-
public function
|
171 |
{
|
172 |
-
return $this->
|
173 |
}
|
174 |
|
175 |
/**
|
176 |
-
* Set new table
|
177 |
*
|
178 |
-
* @param
|
179 |
* @return MysqlDumpSQL
|
180 |
*/
|
181 |
-
public function
|
182 |
{
|
183 |
-
$this->
|
184 |
|
185 |
return $this;
|
186 |
}
|
187 |
|
188 |
/**
|
189 |
-
* Get new table
|
190 |
*
|
191 |
-
* @return
|
192 |
*/
|
193 |
-
public function
|
194 |
{
|
195 |
-
return $this->
|
196 |
}
|
197 |
|
198 |
/**
|
@@ -296,98 +220,316 @@ class MysqlDumpSQL implements MysqlDumpInterface
|
|
296 |
}
|
297 |
|
298 |
/**
|
299 |
-
*
|
300 |
*
|
301 |
-
* @
|
|
|
302 |
*/
|
303 |
-
public function
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
}
|
309 |
-
}
|
310 |
-
} else {
|
311 |
-
$result = mysql_unbuffered_query("SHOW VARIABLES LIKE 'version'", $this->getConnection());
|
312 |
-
while ($row = mysql_fetch_row($result)) {
|
313 |
-
if (isset($row[1])) {
|
314 |
-
return $row[1];
|
315 |
-
}
|
316 |
-
}
|
317 |
-
}
|
318 |
}
|
319 |
|
320 |
/**
|
321 |
-
* Get
|
322 |
*
|
323 |
-
* @return
|
324 |
*/
|
325 |
-
public function
|
326 |
-
|
327 |
-
|
328 |
-
if (isset($row['MaxAllowedPacket'])) {
|
329 |
-
return $row['MaxAllowedPacket'];
|
330 |
-
}
|
331 |
-
}
|
332 |
-
} else {
|
333 |
-
$result = mysql_unbuffered_query("SHOW VARIABLES LIKE 'max_allowed_packet'", $this->getConnection());
|
334 |
-
while ($row = mysql_fetch_row($result)) {
|
335 |
-
if (isset($row[1])) {
|
336 |
-
return $row[1];
|
337 |
-
}
|
338 |
-
}
|
339 |
-
}
|
340 |
}
|
341 |
|
342 |
/**
|
343 |
-
*
|
344 |
*
|
345 |
-
* @param
|
346 |
-
* @return
|
347 |
*/
|
348 |
-
public function
|
349 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
350 |
$result = mysql_unbuffered_query(
|
351 |
-
"SELECT
|
352 |
$this->getConnection()
|
353 |
);
|
354 |
|
355 |
if ($result) {
|
356 |
while ($row = mysql_fetch_assoc($result)) {
|
357 |
-
if (isset($row['
|
358 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
359 |
}
|
360 |
}
|
361 |
} else {
|
362 |
-
$result = mysql_unbuffered_query("SHOW
|
363 |
while ($row = mysql_fetch_row($result)) {
|
364 |
-
if (isset($row[0])) {
|
365 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
366 |
}
|
367 |
}
|
368 |
}
|
|
|
|
|
369 |
}
|
370 |
|
371 |
/**
|
372 |
-
*
|
373 |
*
|
374 |
-
* @return
|
375 |
*/
|
376 |
-
public function
|
377 |
{
|
378 |
-
$
|
379 |
-
|
380 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
381 |
}
|
382 |
|
383 |
-
|
384 |
-
|
385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
386 |
}
|
|
|
|
|
|
|
|
|
|
|
387 |
}
|
388 |
|
389 |
/**
|
390 |
-
* Import database from file
|
391 |
*
|
392 |
* @param string $fileName Name of file
|
393 |
* @return bool
|
@@ -420,8 +562,8 @@ class MysqlDumpSQL implements MysqlDumpInterface
|
|
420 |
// Check max allowed packet
|
421 |
if (strlen($query) <= $maxAllowedPacket) {
|
422 |
|
423 |
-
// Replace table
|
424 |
-
$query = $this->
|
425 |
|
426 |
// Replace table values
|
427 |
$query = $this->replaceTableValues($query, true);
|
@@ -431,21 +573,17 @@ class MysqlDumpSQL implements MysqlDumpInterface
|
|
431 |
$query = $this->replaceTableCollation($query);
|
432 |
}
|
433 |
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
$
|
|
|
|
|
|
|
|
|
438 |
|
439 |
-
|
440 |
-
|
441 |
-
sprintf(
|
442 |
-
'Exception while importing: %s with query: %s',
|
443 |
-
mysql_error($this->getConnection()),
|
444 |
-
$query
|
445 |
-
)
|
446 |
-
);
|
447 |
-
} else {
|
448 |
-
$passed++;
|
449 |
}
|
450 |
|
451 |
} else {
|
@@ -468,64 +606,131 @@ class MysqlDumpSQL implements MysqlDumpInterface
|
|
468 |
}
|
469 |
|
470 |
/**
|
471 |
-
*
|
472 |
*
|
473 |
-
* @return
|
474 |
*/
|
475 |
-
public function
|
476 |
{
|
477 |
-
$
|
|
|
|
|
|
|
478 |
|
479 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
480 |
$result = mysql_unbuffered_query(
|
481 |
-
"SELECT
|
482 |
$this->getConnection()
|
483 |
);
|
484 |
|
485 |
if ($result) {
|
486 |
while ($row = mysql_fetch_assoc($result)) {
|
487 |
-
if (isset($row['
|
488 |
-
|
489 |
}
|
490 |
}
|
491 |
} else {
|
492 |
-
$result = mysql_unbuffered_query("SHOW
|
493 |
while ($row = mysql_fetch_row($result)) {
|
494 |
if (isset($row[0])) {
|
495 |
-
|
496 |
}
|
497 |
}
|
498 |
}
|
499 |
-
|
500 |
-
return $tables;
|
501 |
}
|
502 |
|
503 |
/**
|
504 |
-
* Replace table
|
505 |
*
|
506 |
-
* @param string
|
507 |
-
* @param boolean $first
|
508 |
-
* @param boolean $
|
509 |
* @return string
|
510 |
*/
|
511 |
-
|
512 |
{
|
513 |
-
// Get table
|
514 |
-
$search = $this->
|
515 |
-
$replace = $this->
|
516 |
|
517 |
-
// Replace
|
518 |
if ($first) {
|
519 |
-
|
520 |
-
|
521 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
522 |
}
|
523 |
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
|
|
529 |
}
|
530 |
|
531 |
return $input;
|
@@ -542,7 +747,7 @@ class MysqlDumpSQL implements MysqlDumpInterface
|
|
542 |
* @param boolean $parse Parse value
|
543 |
* @return string
|
544 |
*/
|
545 |
-
|
546 |
{
|
547 |
// Get replace values
|
548 |
$old = $this->getOldReplaceValues();
|
@@ -566,10 +771,10 @@ class MysqlDumpSQL implements MysqlDumpInterface
|
|
566 |
$input = $this->parseSerializedValues($input);
|
567 |
|
568 |
// Replace values
|
569 |
-
return
|
570 |
}
|
571 |
|
572 |
-
return
|
573 |
}
|
574 |
|
575 |
return $input;
|
@@ -581,7 +786,7 @@ class MysqlDumpSQL implements MysqlDumpInterface
|
|
581 |
* @param string $input Table value
|
582 |
* @return string
|
583 |
*/
|
584 |
-
|
585 |
{
|
586 |
// Serialization format
|
587 |
$array = '(a:\d+:{.*?})';
|
@@ -598,13 +803,13 @@ class MysqlDumpSQL implements MysqlDumpInterface
|
|
598 |
* @param array $matches List of matches
|
599 |
* @return string
|
600 |
*/
|
601 |
-
|
602 |
{
|
603 |
// Unescape MySQL special characters
|
604 |
-
$input =
|
605 |
|
606 |
// Replace serialized values
|
607 |
-
$input =
|
608 |
|
609 |
// Prepare query values
|
610 |
return "'" . mysql_real_escape_string($input, $this->getConnection()) . "'";
|
@@ -616,7 +821,7 @@ class MysqlDumpSQL implements MysqlDumpInterface
|
|
616 |
* @param string $input SQL statement
|
617 |
* @return string
|
618 |
*/
|
619 |
-
|
620 |
{
|
621 |
return str_replace('utf8mb4', 'utf8', $input);
|
622 |
}
|
@@ -627,7 +832,7 @@ class MysqlDumpSQL implements MysqlDumpInterface
|
|
627 |
* @param string $input SQL statement
|
628 |
* @return string
|
629 |
*/
|
630 |
-
|
631 |
{
|
632 |
$pattern = array(
|
633 |
'/\s+CONSTRAINT(.+)REFERENCES(.+),/i',
|
@@ -638,31 +843,6 @@ class MysqlDumpSQL implements MysqlDumpInterface
|
|
638 |
return preg_replace($pattern, $replace, $input);
|
639 |
}
|
640 |
|
641 |
-
/**
|
642 |
-
* Get MySQL connection (lazy loading)
|
643 |
-
*
|
644 |
-
* @return resource
|
645 |
-
*/
|
646 |
-
public function getConnection()
|
647 |
-
{
|
648 |
-
if ($this->connection === null) {
|
649 |
-
// Make connection (Socket)
|
650 |
-
$this->connection = $this->makeConnection();
|
651 |
-
|
652 |
-
if ($this->connection === false) {
|
653 |
-
// Make connection (TCP)
|
654 |
-
$this->connection = $this->makeConnection(false);
|
655 |
-
|
656 |
-
// Unable to connect to MySQL database server
|
657 |
-
if ($this->connection === false) {
|
658 |
-
throw new Exception('Unable to connect to MySQL database server: ' . mysql_error($this->connection));
|
659 |
-
}
|
660 |
-
}
|
661 |
-
}
|
662 |
-
|
663 |
-
return $this->connection;
|
664 |
-
}
|
665 |
-
|
666 |
/**
|
667 |
* Make MySQL connection
|
668 |
*
|
@@ -705,95 +885,12 @@ class MysqlDumpSQL implements MysqlDumpInterface
|
|
705 |
"-- http://servmask.com/\n" .
|
706 |
"--\n" .
|
707 |
"-- Host: {$this->hostname}\n" .
|
708 |
-
"-- Generation Time: " . date('r') . "\n
|
|
|
709 |
"--\n" .
|
710 |
"-- Database: `{$this->database}`\n" .
|
711 |
"--\n\n";
|
712 |
|
713 |
return $header;
|
714 |
}
|
715 |
-
|
716 |
-
/**
|
717 |
-
* Table structure extractor
|
718 |
-
*
|
719 |
-
* @param string $tableName Name of table to export
|
720 |
-
* @return bool
|
721 |
-
*/
|
722 |
-
protected function getTableStructure($tableName)
|
723 |
-
{
|
724 |
-
$result = mysql_unbuffered_query("SHOW CREATE TABLE `$tableName`", $this->getConnection());
|
725 |
-
while ($row = mysql_fetch_assoc($result)) {
|
726 |
-
if (isset($row['Create Table'])) {
|
727 |
-
|
728 |
-
// Replace create table prefix
|
729 |
-
$createTable = $this->replaceTablePrefix($row['Create Table'], true);
|
730 |
-
|
731 |
-
// Strip table constraints
|
732 |
-
$createTable = $this->stripTableConstraints($createTable);
|
733 |
-
|
734 |
-
// Write table structure
|
735 |
-
$this->fileAdapter->write($createTable);
|
736 |
-
|
737 |
-
// Write end of statement
|
738 |
-
$this->fileAdapter->write(";\n\n");
|
739 |
-
|
740 |
-
return true;
|
741 |
-
}
|
742 |
-
}
|
743 |
-
|
744 |
-
return false;
|
745 |
-
}
|
746 |
-
|
747 |
-
/**
|
748 |
-
* Table rows extractor
|
749 |
-
*
|
750 |
-
* @param string $tableName Name of table to export
|
751 |
-
* @return void
|
752 |
-
*/
|
753 |
-
protected function listValues($tableName)
|
754 |
-
{
|
755 |
-
// Set query
|
756 |
-
$query = "SELECT * FROM `$tableName` ";
|
757 |
-
|
758 |
-
// Apply additional query clauses
|
759 |
-
$clauses = $this->getQueryClauses();
|
760 |
-
if (isset($clauses[$tableName]) && ($queryClause = $clauses[$tableName])) {
|
761 |
-
$query .= $queryClause;
|
762 |
-
}
|
763 |
-
|
764 |
-
// Apply additional table prefix columns
|
765 |
-
$columns = $this->getTablePrefixColumns($tableName);
|
766 |
-
|
767 |
-
// Get results
|
768 |
-
$result = mysql_unbuffered_query($query, $this->getConnection());
|
769 |
-
|
770 |
-
// Replace table name prefix
|
771 |
-
$tableName = $this->replaceTablePrefix($tableName, true);
|
772 |
-
|
773 |
-
// Generate insert statements
|
774 |
-
while ($row = mysql_fetch_assoc($result)) {
|
775 |
-
$items = array();
|
776 |
-
foreach ($row as $key => $value) {
|
777 |
-
// Replace table prefix columns
|
778 |
-
if (isset($columns[$key])) {
|
779 |
-
$value = $this->replaceTablePrefix($value, false, true);
|
780 |
-
}
|
781 |
-
|
782 |
-
// Replace table values
|
783 |
-
$items[] = is_null($value) ? 'NULL' : "'" . mysql_real_escape_string($this->replaceTableValues($value), $this->getConnection()) . "'";
|
784 |
-
}
|
785 |
-
|
786 |
-
// Set table values
|
787 |
-
$tableValues = implode(',', $items);
|
788 |
-
|
789 |
-
// Write insert statements
|
790 |
-
$this->fileAdapter->write("INSERT INTO `$tableName` VALUES ($tableValues);\n");
|
791 |
-
}
|
792 |
-
|
793 |
-
// Write end of statements
|
794 |
-
$this->fileAdapter->write("\n");
|
795 |
-
|
796 |
-
// Close result cursor
|
797 |
-
mysql_free_result($result);
|
798 |
-
}
|
799 |
}
|
1 |
<?php
|
|
|
2 |
|
3 |
/**
|
4 |
+
* Copyright (C) 2014 ServMask Inc.
|
5 |
*
|
6 |
+
* This program is free software: you can redistribute it and/or modify
|
7 |
+
* it under the terms of the GNU General Public License as published by
|
8 |
+
* the Free Software Foundation, either version 3 of the License, or
|
9 |
+
* (at your option) any later version.
|
10 |
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
|
|
|
|
15 |
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18 |
*
|
19 |
+
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
|
20 |
+
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
|
21 |
+
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
|
22 |
+
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
|
23 |
+
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
|
24 |
+
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
*/
|
26 |
|
27 |
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MysqlDumpInterface.php';
|
28 |
+
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MysqlDumpUtility.php';
|
|
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
class MysqlDumpSQL implements MysqlDumpInterface
|
31 |
{
|
32 |
+
protected $hostname = null;
|
33 |
|
34 |
+
protected $username = null;
|
35 |
|
36 |
+
protected $password = null;
|
37 |
|
38 |
+
protected $database = null;
|
39 |
|
40 |
+
protected $connection = null;
|
41 |
|
42 |
+
protected $oldTablePrefixes = null;
|
43 |
|
44 |
+
protected $newTablePrefixes = null;
|
45 |
|
46 |
+
protected $oldReplaceValues = array();
|
47 |
|
48 |
+
protected $newReplaceValues = array();
|
49 |
|
50 |
+
protected $queryClauses = array();
|
51 |
|
52 |
+
protected $tablePrefixColumns = array();
|
53 |
|
54 |
+
protected $includeTablePrefixes = array();
|
55 |
|
56 |
+
protected $excludeTablePrefixes = array();
|
57 |
|
58 |
/**
|
59 |
* Define MySQL credentials for the current connection
|
74 |
}
|
75 |
|
76 |
/**
|
77 |
+
* Set old table prefixes
|
78 |
*
|
79 |
+
* @param array $prefixes List of table prefixes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
* @return MysqlDumpSQL
|
81 |
*/
|
82 |
+
public function setOldTablePrefixes($prefixes)
|
83 |
{
|
84 |
+
$this->oldTablePrefixes = $prefixes;
|
85 |
|
86 |
return $this;
|
87 |
}
|
88 |
|
89 |
/**
|
90 |
+
* Get old table prefixes
|
91 |
*
|
92 |
+
* @return array
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
*/
|
94 |
+
public function getOldTablePrefixes()
|
95 |
{
|
96 |
+
return $this->oldTablePrefixes;
|
97 |
}
|
98 |
|
99 |
/**
|
100 |
+
* Set new table prefixes
|
101 |
*
|
102 |
+
* @param array $prefixes List of table prefixes
|
103 |
* @return MysqlDumpSQL
|
104 |
*/
|
105 |
+
public function setNewTablePrefixes($prefixes)
|
106 |
{
|
107 |
+
$this->newTablePrefixes = $prefixes;
|
108 |
|
109 |
return $this;
|
110 |
}
|
111 |
|
112 |
/**
|
113 |
+
* Get new table prefixes
|
114 |
*
|
115 |
+
* @return array
|
116 |
*/
|
117 |
+
public function getNewTablePrefixes()
|
118 |
{
|
119 |
+
return $this->newTablePrefixes;
|
120 |
}
|
121 |
|
122 |
/**
|
220 |
}
|
221 |
|
222 |
/**
|
223 |
+
* Set include table prefixes
|
224 |
*
|
225 |
+
* @param array $prefixes List of table prefixes
|
226 |
+
* @return MysqlDumpSQL
|
227 |
*/
|
228 |
+
public function setIncludeTablePrefixes($prefixes)
|
229 |
+
{
|
230 |
+
$this->includeTablePrefixes = $prefixes;
|
231 |
+
|
232 |
+
return $this;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
}
|
234 |
|
235 |
/**
|
236 |
+
* Get include table prefixes
|
237 |
*
|
238 |
+
* @return array
|
239 |
*/
|
240 |
+
public function getIncludeTablePrefixes()
|
241 |
+
{
|
242 |
+
return $this->includeTablePrefixes;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
}
|
244 |
|
245 |
/**
|
246 |
+
* Set exclude table prefixes
|
247 |
*
|
248 |
+
* @param array $prefixes List of table prefixes
|
249 |
+
* @return MysqlDumpSQL
|
250 |
*/
|
251 |
+
public function setExcludeTablePrefixes($prefixes)
|
252 |
+
{
|
253 |
+
$this->excludeTablePrefixes = $prefixes;
|
254 |
+
|
255 |
+
return $this;
|
256 |
+
}
|
257 |
+
|
258 |
+
/**
|
259 |
+
* Get exclude table prefixes
|
260 |
+
*
|
261 |
+
* @return array
|
262 |
+
*/
|
263 |
+
public function getExcludeTablePrefixes()
|
264 |
+
{
|
265 |
+
return $this->excludeTablePrefixes;
|
266 |
+
}
|
267 |
+
|
268 |
+
/**
|
269 |
+
* Get tables
|
270 |
+
*
|
271 |
+
* @return array
|
272 |
+
*/
|
273 |
+
public function getTables()
|
274 |
+
{
|
275 |
+
$tables = array();
|
276 |
+
|
277 |
+
// Get list of tables
|
278 |
$result = mysql_unbuffered_query(
|
279 |
+
"SELECT TABLE_NAME AS TableName FROM `INFORMATION_SCHEMA`.`TABLES` WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = '{$this->database}'",
|
280 |
$this->getConnection()
|
281 |
);
|
282 |
|
283 |
if ($result) {
|
284 |
while ($row = mysql_fetch_assoc($result)) {
|
285 |
+
if (isset($row['TableName']) && ($tableName = $row['TableName'])) {
|
286 |
+
|
287 |
+
// Include table prefixes
|
288 |
+
if ($this->getIncludeTablePrefixes()) {
|
289 |
+
$include = false;
|
290 |
+
|
291 |
+
// Check table prefixes
|
292 |
+
foreach ($this->getIncludeTablePrefixes() as $prefix) {
|
293 |
+
if (strpos($tableName, $prefix) === 0) {
|
294 |
+
$include = true;
|
295 |
+
break;
|
296 |
+
}
|
297 |
+
}
|
298 |
+
|
299 |
+
// Skip current table
|
300 |
+
if ($include === false) {
|
301 |
+
continue;
|
302 |
+
}
|
303 |
+
}
|
304 |
+
|
305 |
+
// Exclude table prefixes
|
306 |
+
if ($this->getExcludeTablePrefixes()) {
|
307 |
+
$exclude = false;
|
308 |
+
|
309 |
+
// Check table prefixes
|
310 |
+
foreach ($this->getExcludeTablePrefixes() as $prefix) {
|
311 |
+
if (strpos($tableName, $prefix) === 0) {
|
312 |
+
$exclude = true;
|
313 |
+
break;
|
314 |
+
}
|
315 |
+
}
|
316 |
+
|
317 |
+
// Skip current table
|
318 |
+
if ($exclude === true) {
|
319 |
+
continue;
|
320 |
+
}
|
321 |
+
}
|
322 |
+
|
323 |
+
// Add table name
|
324 |
+
$tables[] = $tableName;
|
325 |
}
|
326 |
}
|
327 |
} else {
|
328 |
+
$result = mysql_unbuffered_query("SHOW TABLES FROM `{$this->database}`", $this->getConnection());
|
329 |
while ($row = mysql_fetch_row($result)) {
|
330 |
+
if (isset($row[0]) && ($tableName = $row[0])) {
|
331 |
+
|
332 |
+
// Include table prefixes
|
333 |
+
if ($this->getIncludeTablePrefixes()) {
|
334 |
+
$include = false;
|
335 |
+
|
336 |
+
// Check table prefixes
|
337 |
+
foreach ($this->getIncludeTablePrefixes() as $prefix) {
|
338 |
+
if (strpos($tableName, $prefix) === 0) {
|
339 |
+
$include = true;
|
340 |
+
break;
|
341 |
+
}
|
342 |
+
}
|
343 |
+
|
344 |
+
// Skip current table
|
345 |
+
if ($include === false) {
|
346 |
+
continue;
|
347 |
+
}
|
348 |
+
}
|
349 |
+
|
350 |
+
// Exclude table prefixes
|
351 |
+
if ($this->getExcludeTablePrefixes()) {
|
352 |
+
$exclude = false;
|
353 |
+
|
354 |
+
// Check table prefixes
|
355 |
+
foreach ($this->getExcludeTablePrefixes() as $prefix) {
|
356 |
+
if (strpos($tableName, $prefix) === 0) {
|
357 |
+
$exclude = true;
|
358 |
+
break;
|
359 |
+
}
|
360 |
+
}
|
361 |
+
|
362 |
+
// Skip current table
|
363 |
+
if ($exclude === true) {
|
364 |
+
continue;
|
365 |
+
}
|
366 |
+
}
|
367 |
+
|
368 |
+
// Add table name
|
369 |
+
$tables[] = $tableName;
|
370 |
}
|
371 |
}
|
372 |
}
|
373 |
+
|
374 |
+
return $tables;
|
375 |
}
|
376 |
|
377 |
/**
|
378 |
+
* Get MySQL connection (lazy loading)
|
379 |
*
|
380 |
+
* @return resource
|
381 |
*/
|
382 |
+
public function getConnection()
|
383 |
{
|
384 |
+
if ($this->connection === null) {
|
385 |
+
// Make connection (Socket)
|
386 |
+
$this->connection = $this->makeConnection();
|
387 |
+
|
388 |
+
if ($this->connection === false) {
|
389 |
+
// Make connection (TCP)
|
390 |
+
$this->connection = $this->makeConnection(false);
|
391 |
+
|
392 |
+
// Unable to connect to MySQL database server
|
393 |
+
if ($this->connection === false) {
|
394 |
+
throw new Exception('Unable to connect to MySQL database server: ' . mysql_error($this->connection));
|
395 |
+
}
|
396 |
+
}
|
397 |
}
|
398 |
|
399 |
+
return $this->connection;
|
400 |
+
}
|
401 |
+
|
402 |
+
/**
|
403 |
+
* Run MySQL query
|
404 |
+
*
|
405 |
+
* @param string $query SQL query
|
406 |
+
* @return resource
|
407 |
+
*/
|
408 |
+
public function query($query)
|
409 |
+
{
|
410 |
+
return mysql_unbuffered_query($query, $this->getConnection());
|
411 |
+
}
|
412 |
+
|
413 |
+
/**
|
414 |
+
* Export database into a file
|
415 |
+
*
|
416 |
+
* @param string $fileName Name of file
|
417 |
+
* @return bool
|
418 |
+
*/
|
419 |
+
public function export($fileName)
|
420 |
+
{
|
421 |
+
// Set file handler
|
422 |
+
$fileHandler = fopen($fileName, 'wb');
|
423 |
+
if ($fileHandler === false) {
|
424 |
+
throw new Exception('Unable to open database file');
|
425 |
+
}
|
426 |
+
|
427 |
+
// Write headers
|
428 |
+
if (fwrite($fileHandler, $this->getHeader()) === false) {
|
429 |
+
throw new Exception('Unable to write database header information');
|
430 |
+
}
|
431 |
+
|
432 |
+
// Export tables
|
433 |
+
foreach ($this->getTables() as $tableName) {
|
434 |
+
|
435 |
+
// Replace table name prefixes
|
436 |
+
$newTableName = $this->replaceTablePrefixes($tableName, true);
|
437 |
+
|
438 |
+
// Get table structure
|
439 |
+
$structure = mysql_unbuffered_query("SHOW CREATE TABLE `$tableName`", $this->getConnection());
|
440 |
+
$table = mysql_fetch_assoc($structure);
|
441 |
+
if (isset($table['Create Table'])) {
|
442 |
+
|
443 |
+
// Write table drop statement
|
444 |
+
$dropTable = "DROP TABLE IF EXISTS `$newTableName`;\n";
|
445 |
+
|
446 |
+
// Write table statement
|
447 |
+
if (fwrite($fileHandler, $dropTable) === false) {
|
448 |
+
throw new Exception('Unable to write database table statement');
|
449 |
+
}
|
450 |
+
|
451 |
+
// Replace create table prefixes
|
452 |
+
$createTable = $this->replaceTablePrefixes($table['Create Table'], true);
|
453 |
+
|
454 |
+
// Strip table constraints
|
455 |
+
$createTable = $this->stripTableConstraints($createTable);
|
456 |
+
|
457 |
+
// Write table structure
|
458 |
+
if (fwrite($fileHandler, $createTable) === false) {
|
459 |
+
throw new Exception('Unable to write database table structure');
|
460 |
+
}
|
461 |
+
|
462 |
+
// Write end of statement
|
463 |
+
if (fwrite($fileHandler, ";\n\n") === false) {
|
464 |
+
throw new Exception('Unable to write database end of statement');
|
465 |
+
}
|
466 |
+
|
467 |
+
// Close structure cursor
|
468 |
+
mysql_free_result($structure);
|
469 |
+
} else {
|
470 |
+
// Close structure cursor
|
471 |
+
mysql_free_result($structure);
|
472 |
+
|
473 |
+
break;
|
474 |
+
}
|
475 |
+
|
476 |
+
// Set query
|
477 |
+
$query = "SELECT * FROM `$tableName` ";
|
478 |
+
|
479 |
+
// Apply additional query clauses
|
480 |
+
$clauses = $this->getQueryClauses();
|
481 |
+
if (isset($clauses[$tableName]) && ($queryClause = $clauses[$tableName])) {
|
482 |
+
$query .= $queryClause;
|
483 |
+
}
|
484 |
+
|
485 |
+
// Apply additional table prefix columns
|
486 |
+
$columns = $this->getTablePrefixColumns($tableName);
|
487 |
+
|
488 |
+
// Get results
|
489 |
+
$result = mysql_unbuffered_query($query, $this->getConnection());
|
490 |
+
|
491 |
+
// Generate insert statements
|
492 |
+
while ($row = mysql_fetch_assoc($result)) {
|
493 |
+
$items = array();
|
494 |
+
foreach ($row as $key => $value) {
|
495 |
+
// Replace table prefix columns
|
496 |
+
if (isset($columns[$key])) {
|
497 |
+
$value = $this->replaceTablePrefixes($value, true, 0);
|
498 |
+
}
|
499 |
+
|
500 |
+
// Replace table values
|
501 |
+
$items[] = is_null($value) ? 'NULL' : "'" . mysql_real_escape_string($this->replaceTableValues($value), $this->getConnection()) . "'";
|
502 |
+
}
|
503 |
+
|
504 |
+
// Set table values
|
505 |
+
$tableValues = implode(',', $items);
|
506 |
+
|
507 |
+
// Set insert statement
|
508 |
+
$tableInsert = "INSERT INTO `$newTableName` VALUES ($tableValues);\n";
|
509 |
+
|
510 |
+
// Write insert statement
|
511 |
+
if (fwrite($fileHandler, $tableInsert) === false) {
|
512 |
+
throw new Exception('Unable to write database insert statement');
|
513 |
+
}
|
514 |
+
}
|
515 |
+
|
516 |
+
// Write end of statements
|
517 |
+
if (fwrite($fileHandler, "\n") === false) {
|
518 |
+
throw new Exception('Unable to write database end of statement');
|
519 |
+
}
|
520 |
+
|
521 |
+
// Close result cursor
|
522 |
+
mysql_free_result($result);
|
523 |
}
|
524 |
+
|
525 |
+
// Close file handler
|
526 |
+
fclose($fileHandler);
|
527 |
+
|
528 |
+
return true;
|
529 |
}
|
530 |
|
531 |
/**
|
532 |
+
* Import database from a file
|
533 |
*
|
534 |
* @param string $fileName Name of file
|
535 |
* @return bool
|
562 |
// Check max allowed packet
|
563 |
if (strlen($query) <= $maxAllowedPacket) {
|
564 |
|
565 |
+
// Replace table prefixes
|
566 |
+
$query = $this->replaceTablePrefixes($query);
|
567 |
|
568 |
// Replace table values
|
569 |
$query = $this->replaceTableValues($query, true);
|
573 |
$query = $this->replaceTableCollation($query);
|
574 |
}
|
575 |
|
576 |
+
try {
|
577 |
+
// Run SQL query
|
578 |
+
$result = mysql_unbuffered_query($query, $this->getConnection());
|
579 |
+
if ($result === false) {
|
580 |
+
throw new Exception(var_export(array(mysql_errno($this->getConnection()), mysql_error($this->getConnection()))));
|
581 |
+
} else {
|
582 |
+
$passed++;
|
583 |
+
}
|
584 |
|
585 |
+
} catch (Exception $e) {
|
586 |
+
$failed++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
587 |
}
|
588 |
|
589 |
} else {
|
606 |
}
|
607 |
|
608 |
/**
|
609 |
+
* Flush database
|
610 |
*
|
611 |
+
* @return void
|
612 |
*/
|
613 |
+
public function flush()
|
614 |
{
|
615 |
+
$dropTables = array();
|
616 |
+
foreach ($this->getTables() as $tableName) {
|
617 |
+
$dropTables[] = "DROP TABLE IF EXISTS `$tableName`";
|
618 |
+
}
|
619 |
|
620 |
+
// Drop tables
|
621 |
+
foreach ($dropTables as $dropQuery) {
|
622 |
+
mysql_unbuffered_query($dropQuery, $this->getConnection());
|
623 |
+
}
|
624 |
+
}
|
625 |
+
|
626 |
+
/**
|
627 |
+
* Get MySQL version
|
628 |
+
*
|
629 |
+
* @return string
|
630 |
+
*/
|
631 |
+
protected function getVersion() {
|
632 |
+
if (($result = mysql_unbuffered_query("SELECT @@version AS VersionName", $this->getConnection()))) {
|
633 |
+
while ($row = mysql_fetch_assoc($result)) {
|
634 |
+
if (isset($row['VersionName'])) {
|
635 |
+
return $row['VersionName'];
|
636 |
+
}
|
637 |
+
}
|
638 |
+
} else {
|
639 |
+
$result = mysql_unbuffered_query("SHOW VARIABLES LIKE 'version'", $this->getConnection());
|
640 |
+
while ($row = mysql_fetch_row($result)) {
|
641 |
+
if (isset($row[1])) {
|
642 |
+
return $row[1];
|
643 |
+
}
|
644 |
+
}
|
645 |
+
}
|
646 |
+
}
|
647 |
+
|
648 |
+
/**
|
649 |
+
* Get MySQL max allowed packaet
|
650 |
+
*
|
651 |
+
* @return integer
|
652 |
+
*/
|
653 |
+
protected function getMaxAllowedPacket() {
|
654 |
+
if (($result = mysql_unbuffered_query("SELECT @@max_allowed_packet AS MaxAllowedPacket", $this->getConnection()))) {
|
655 |
+
while ($row = mysql_fetch_assoc($result)) {
|
656 |
+
if (isset($row['MaxAllowedPacket'])) {
|
657 |
+
return $row['MaxAllowedPacket'];
|
658 |
+
}
|
659 |
+
}
|
660 |
+
} else {
|
661 |
+
$result = mysql_unbuffered_query("SHOW VARIABLES LIKE 'max_allowed_packet'", $this->getConnection());
|
662 |
+
while ($row = mysql_fetch_row($result)) {
|
663 |
+
if (isset($row[1])) {
|
664 |
+
return $row[1];
|
665 |
+
}
|
666 |
+
}
|
667 |
+
}
|
668 |
+
}
|
669 |
+
|
670 |
+
/**
|
671 |
+
* Get MySQL collation name
|
672 |
+
*
|
673 |
+
* @param string $collationName Collation name
|
674 |
+
* @return string
|
675 |
+
*/
|
676 |
+
protected function getCollation($collationName) {
|
677 |
+
// Get collation name
|
678 |
$result = mysql_unbuffered_query(
|
679 |
+
"SELECT COLLATION_NAME AS CollationName FROM `INFORMATION_SCHEMA`.`COLLATIONS` WHERE COLLATION_NAME = '$collationName'",
|
680 |
$this->getConnection()
|
681 |
);
|
682 |
|
683 |
if ($result) {
|
684 |
while ($row = mysql_fetch_assoc($result)) {
|
685 |
+
if (isset($row['CollationName'])) {
|
686 |
+
return $row['CollationName'];
|
687 |
}
|
688 |
}
|
689 |
} else {
|
690 |
+
$result = mysql_unbuffered_query("SHOW COLLATION LIKE '$collationName'", $this->getConnection());
|
691 |
while ($row = mysql_fetch_row($result)) {
|
692 |
if (isset($row[0])) {
|
693 |
+
return $row[0];
|
694 |
}
|
695 |
}
|
696 |
}
|
|
|
|
|
697 |
}
|
698 |
|
699 |
/**
|
700 |
+
* Replace table prefixes
|
701 |
*
|
702 |
+
* @param string $input Table value
|
703 |
+
* @param boolean $first Replace first occurrence at any position
|
704 |
+
* @param boolean $position Replace first occurrence at a specified position
|
705 |
* @return string
|
706 |
*/
|
707 |
+
protected function replaceTablePrefixes($input, $first = false, $position = false)
|
708 |
{
|
709 |
+
// Get table prefixes
|
710 |
+
$search = $this->getOldTablePrefixes();
|
711 |
+
$replace = $this->getNewTablePrefixes();
|
712 |
|
713 |
+
// Replace table prefixes
|
714 |
if ($first) {
|
715 |
+
|
716 |
+
// Replace first occurance at a specified position
|
717 |
+
if ($position !== false) {
|
718 |
+
for ($i = 0; $i < count($search); $i++) {
|
719 |
+
$current = strpos($input, $search[$i]);
|
720 |
+
if ($current === $position) {
|
721 |
+
$input = substr_replace($input, $replace[$i], $current, strlen($search[$i]));
|
722 |
+
}
|
723 |
+
}
|
724 |
+
|
725 |
+
return $input;
|
726 |
}
|
727 |
|
728 |
+
// Replace first occurance at any position
|
729 |
+
for ($i = 0; $i < count($search); $i++) {
|
730 |
+
$current = strpos($input, $search[$i]);
|
731 |
+
if ($current !== $position) {
|
732 |
+
$input = substr_replace($input, $replace[$i], $current, strlen($search[$i]));
|
733 |
+
}
|
734 |
}
|
735 |
|
736 |
return $input;
|
747 |
* @param boolean $parse Parse value
|
748 |
* @return string
|
749 |
*/
|
750 |
+
protected function replaceTableValues($input, $parse = false)
|
751 |
{
|
752 |
// Get replace values
|
753 |
$old = $this->getOldReplaceValues();
|
771 |
$input = $this->parseSerializedValues($input);
|
772 |
|
773 |
// Replace values
|
774 |
+
return MysqlDumpUtility::replaceValues($oldValues, $newValues, $input);
|
775 |
}
|
776 |
|
777 |
+
return MysqlDumpUtility::replaceSerializedValues($oldValues, $newValues, $input);
|
778 |
}
|
779 |
|
780 |
return $input;
|
786 |
* @param string $input Table value
|
787 |
* @return string
|
788 |
*/
|
789 |
+
protected function parseSerializedValues($input)
|
790 |
{
|
791 |
// Serialization format
|
792 |
$array = '(a:\d+:{.*?})';
|
803 |
* @param array $matches List of matches
|
804 |
* @return string
|
805 |
*/
|
806 |
+
protected function replaceSerializedValues($matches)
|
807 |
{
|
808 |
// Unescape MySQL special characters
|
809 |
+
$input = MysqlDumpUtility::unescapeMysql($matches[1]);
|
810 |
|
811 |
// Replace serialized values
|
812 |
+
$input = MysqlDumpUtility::replaceSerializedValues($this->getOldReplaceValues(), $this->getNewReplaceValues(), $input);
|
813 |
|
814 |
// Prepare query values
|
815 |
return "'" . mysql_real_escape_string($input, $this->getConnection()) . "'";
|
821 |
* @param string $input SQL statement
|
822 |
* @return string
|
823 |
*/
|
824 |
+
protected function replaceTableCollation($input)
|
825 |
{
|
826 |
return str_replace('utf8mb4', 'utf8', $input);
|
827 |
}
|
832 |
* @param string $input SQL statement
|
833 |
* @return string
|
834 |
*/
|
835 |
+
protected function stripTableConstraints($input)
|
836 |
{
|
837 |
$pattern = array(
|
838 |
'/\s+CONSTRAINT(.+)REFERENCES(.+),/i',
|
843 |
return preg_replace($pattern, $replace, $input);
|
844 |
}
|
845 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
846 |
/**
|
847 |
* Make MySQL connection
|
848 |
*
|
885 |
"-- http://servmask.com/\n" .
|
886 |
"--\n" .
|
887 |
"-- Host: {$this->hostname}\n" .
|
888 |
+
"-- Generation Time: " . date('r') . "\n" .
|
889 |
+
"-- MySQL Extension\n\n" .
|
890 |
"--\n" .
|
891 |
"-- Database: `{$this->database}`\n" .
|
892 |
"--\n\n";
|
893 |
|
894 |
return $header;
|
895 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
896 |
}
|
lib/vendor/mysqldump-factory/mysqldump-factory/lib/{MysqlUtility.php → MysqlDumpUtility.php}
RENAMED
@@ -1,51 +1,30 @@
|
|
1 |
<?php
|
2 |
-
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
3 |
|
4 |
/**
|
5 |
-
*
|
6 |
*
|
7 |
-
*
|
|
|
|
|
|
|
8 |
*
|
9 |
-
*
|
10 |
-
*
|
11 |
-
*
|
12 |
-
*
|
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 |
-
*
|
17 |
-
*
|
18 |
*
|
19 |
-
*
|
20 |
-
*
|
21 |
-
*
|
22 |
-
*
|
23 |
-
*
|
24 |
-
*
|
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: 2.2.0
|
33 |
-
* @link https://github.com/yani-/mysqldump-factory/
|
34 |
*/
|
35 |
|
36 |
-
|
37 |
-
* Utility 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: 2.2.0
|
46 |
-
* @link https://github.com/yani-/mysqldump-factory/
|
47 |
-
*/
|
48 |
-
class MysqlUtility
|
49 |
{
|
50 |
/**
|
51 |
* Replace all occurrences of the search string with the replacement string.
|
1 |
<?php
|
|
|
2 |
|
3 |
/**
|
4 |
+
* Copyright (C) 2014 ServMask Inc.
|
5 |
*
|
6 |
+
* This program is free software: you can redistribute it and/or modify
|
7 |
+
* it under the terms of the GNU General Public License as published by
|
8 |
+
* the Free Software Foundation, either version 3 of the License, or
|
9 |
+
* (at your option) any later version.
|
10 |
*
|
11 |
+
* This program is distributed in the hope that it will be useful,
|
12 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
+
* GNU General Public License for more details.
|
|
|
|
|
15 |
*
|
16 |
+
* You should have received a copy of the GNU General Public License
|
17 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18 |
*
|
19 |
+
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
|
20 |
+
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
|
21 |
+
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
|
22 |
+
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
|
23 |
+
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
|
24 |
+
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
*/
|
26 |
|
27 |
+
class MysqlDumpUtility
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
{
|
29 |
/**
|
30 |
* Replace all occurrences of the search string with the replacement string.
|
lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlFileAdapter.php
DELETED
@@ -1,74 +0,0 @@
|
|
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: 2.2.0
|
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: 2.2.0
|
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/servmask/filter/class-ai1wm-extension-filter.php
CHANGED
@@ -35,8 +35,7 @@ class Ai1wm_Extension_Filter extends FilterIterator {
|
|
35 |
}
|
36 |
|
37 |
public function accept() {
|
38 |
-
|
39 |
-
if ( in_array( pathinfo( $filename, PATHINFO_EXTENSION ), $this->include ) ) {
|
40 |
return true;
|
41 |
}
|
42 |
|
35 |
}
|
36 |
|
37 |
public function accept() {
|
38 |
+
if ( in_array( pathinfo( $this->getInnerIterator()->getFilename(), PATHINFO_EXTENSION ), $this->include ) ) {
|
|
|
39 |
return true;
|
40 |
}
|
41 |
|
lib/vendor/servmask/filter/class-ai1wm-recursive-exclude-filter.php
CHANGED
@@ -27,15 +27,21 @@ class Ai1wm_Recursive_Exclude_Filter extends RecursiveFilterIterator {
|
|
27 |
|
28 |
protected $exclude = array();
|
29 |
|
30 |
-
public function __construct( RecursiveIterator $
|
31 |
-
parent::__construct( $
|
32 |
|
33 |
// Set exclude filter
|
34 |
$this->exclude = $exclude;
|
35 |
}
|
36 |
|
37 |
public function accept() {
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
}
|
40 |
|
41 |
public function getChildren() {
|
27 |
|
28 |
protected $exclude = array();
|
29 |
|
30 |
+
public function __construct( RecursiveIterator $iterator, $exclude = array() ) {
|
31 |
+
parent::__construct( $iterator );
|
32 |
|
33 |
// Set exclude filter
|
34 |
$this->exclude = $exclude;
|
35 |
}
|
36 |
|
37 |
public function accept() {
|
38 |
+
foreach ( $this->exclude as $filter ) {
|
39 |
+
if ( strpos( $this->getInnerIterator()->getSubPathname(), $filter ) === 0 ) {
|
40 |
+
return false;
|
41 |
+
}
|
42 |
+
}
|
43 |
+
|
44 |
+
return true;
|
45 |
}
|
46 |
|
47 |
public function getChildren() {
|
lib/vendor/servmask/iterator/class-ai1wm-recursive-directory-iterator.php
CHANGED
@@ -29,21 +29,27 @@ class Ai1wm_Recursive_Directory_Iterator extends RecursiveDirectoryIterator {
|
|
29 |
|
30 |
public function __construct( $path ) {
|
31 |
parent::__construct( $path );
|
|
|
|
|
32 |
$this->skipdots();
|
33 |
}
|
34 |
|
35 |
public function rewind() {
|
36 |
parent::rewind();
|
|
|
|
|
37 |
$this->skipdots();
|
38 |
}
|
39 |
|
40 |
public function next() {
|
41 |
parent::next();
|
|
|
|
|
42 |
$this->skipdots();
|
43 |
}
|
44 |
|
45 |
protected function skipdots() {
|
46 |
-
while ($this->isDot()) {
|
47 |
parent::next();
|
48 |
}
|
49 |
}
|
29 |
|
30 |
public function __construct( $path ) {
|
31 |
parent::__construct( $path );
|
32 |
+
|
33 |
+
// Skip current and parent directory
|
34 |
$this->skipdots();
|
35 |
}
|
36 |
|
37 |
public function rewind() {
|
38 |
parent::rewind();
|
39 |
+
|
40 |
+
// Skip current and parent directory
|
41 |
$this->skipdots();
|
42 |
}
|
43 |
|
44 |
public function next() {
|
45 |
parent::next();
|
46 |
+
|
47 |
+
// Skip current and parent directory
|
48 |
$this->skipdots();
|
49 |
}
|
50 |
|
51 |
protected function skipdots() {
|
52 |
+
while ( $this->isDot() ) {
|
53 |
parent::next();
|
54 |
}
|
55 |
}
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: yani.iliev, bangelov, pimjitsawang
|
|
3 |
Tags: db migration, migration, wordpress migration, db backup, db restore, website backup, website restore, website migration, website deploy, wordpress deploy, db backup, database export, database serialization, database find replace
|
4 |
Requires at least: 3.3
|
5 |
Tested up to: 4.3
|
6 |
-
Stable tag: 4.
|
7 |
License: GPLv2 or later
|
8 |
|
9 |
All-in-One WP Migration is the only tool that you will ever need to migrate a WordPress site.
|
@@ -60,6 +60,10 @@ All in One WP Plugin is the first plugin to offer true mobile experience on Word
|
|
60 |
3. Plugin Menu
|
61 |
|
62 |
== Changelog ==
|
|
|
|
|
|
|
|
|
63 |
= 4.6 =
|
64 |
* Fix an issue when the plugin was getting stuck on "Done creating an empty archive"
|
65 |
* Fix an issue when the plugin was getting stuck during import
|
3 |
Tags: db migration, migration, wordpress migration, db backup, db restore, website backup, website restore, website migration, website deploy, wordpress deploy, db backup, database export, database serialization, database find replace
|
4 |
Requires at least: 3.3
|
5 |
Tested up to: 4.3
|
6 |
+
Stable tag: 4.10
|
7 |
License: GPLv2 or later
|
8 |
|
9 |
All-in-One WP Migration is the only tool that you will ever need to migrate a WordPress site.
|
60 |
3. Plugin Menu
|
61 |
|
62 |
== Changelog ==
|
63 |
+
= 4.10 =
|
64 |
+
* Add HTTPS URL replacement
|
65 |
+
* Fix an issue when PDO is not available
|
66 |
+
|
67 |
= 4.6 =
|
68 |
* Fix an issue when the plugin was getting stuck on "Done creating an empty archive"
|
69 |
* Fix an issue when the plugin was getting stuck during import
|