All-in-One WP Migration - Version 2.0.2

Version Description

  • Added support for WordPress v4.0
Download this release

Release Info

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

Code changes from version 1.9.2 to 2.0.2

Files changed (111) hide show
  1. all-in-one-wp-migration.php +2 -2
  2. constants.php +88 -6
  3. lib/controller/class-ai1wm-export-controller.php +46 -25
  4. lib/controller/class-ai1wm-feedback-controller.php +7 -1
  5. lib/controller/class-ai1wm-import-controller.php +119 -17
  6. lib/controller/class-ai1wm-main-controller.php +39 -52
  7. lib/controller/class-ai1wm-message-controller.php +7 -5
  8. {trunk/lib → lib}/exception/class-ai1wm-export-exception.php +0 -0
  9. {trunk/lib → lib}/exception/class-ai1wm-import-exception.php +0 -0
  10. lib/model/class-ai1wm-error.php +6 -8
  11. lib/model/class-ai1wm-export.php +70 -264
  12. lib/model/class-ai1wm-feedback.php +11 -9
  13. lib/model/class-ai1wm-file.php +0 -123
  14. lib/model/class-ai1wm-import.php +128 -287
  15. {trunk/lib → lib}/model/class-ai1wm-logger.php +0 -0
  16. {trunk/lib → lib}/model/class-ai1wm-maintenance.php +0 -0
  17. lib/model/class-ai1wm-message.php +51 -19
  18. lib/model/class-ai1wm-report.php +5 -7
  19. lib/model/class-ai1wm-template.php +2 -2
  20. {trunk/lib → lib}/model/service/class-ai1wm-service-database.php +0 -0
  21. {trunk/lib → lib}/model/service/class-ai1wm-service-interface.php +0 -0
  22. {trunk/lib → lib}/model/service/class-ai1wm-service-media.php +0 -0
  23. {trunk/lib → lib}/model/service/class-ai1wm-service-package.php +0 -0
  24. {trunk/lib → lib}/model/service/class-ai1wm-service-plugins.php +0 -0
  25. {trunk/lib → lib}/model/service/class-ai1wm-service-sites.php +0 -0
  26. {trunk/lib → lib}/model/service/class-ai1wm-service-themes.php +0 -0
  27. lib/vendor/bandar/bandar/README.md +0 -100
  28. lib/vendor/mysqldump-factory/mysqldump-factory/README.md +0 -34
  29. lib/vendor/mysqldump-factory/mysqldump-factory/bump_version.sh +0 -63
  30. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpFactory.php +2 -2
  31. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpInterface.php +40 -2
  32. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpPDO.php +116 -38
  33. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpSQL.php +105 -13
  34. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlFileAdapter.php +2 -2
  35. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlQueryAdapter.php +2 -2
  36. {trunk/lib → lib}/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlUtility.php +0 -0
  37. lib/vendor/storage-factory/storage-factory/README.md +0 -32
  38. lib/vendor/storage-factory/storage-factory/bump-version.sh +0 -63
  39. lib/vendor/storage-factory/storage-factory/lib/StorageAbstract.php +10 -29
  40. lib/vendor/storage-factory/storage-factory/lib/StorageArea.php +56 -18
  41. lib/vendor/storage-factory/storage-factory/lib/StorageDirectory.php +17 -124
  42. lib/vendor/storage-factory/storage-factory/lib/StorageFile.php +26 -23
  43. {trunk/lib → lib}/vendor/storage-factory/storage-factory/lib/StorageUtility.php +0 -0
  44. lib/vendor/zip-factory/zip-factory/README.md +0 -31
  45. lib/vendor/zip-factory/zip-factory/bump-version.sh +0 -63
  46. lib/view/assets/css/export.min.css +1 -1
  47. lib/view/assets/css/import.min.css +1 -1
  48. lib/view/assets/font/servmask.eot +0 -0
  49. lib/view/assets/font/servmask.svg +7 -22
  50. lib/view/assets/font/servmask.ttf +0 -0
  51. lib/view/assets/font/servmask.woff +0 -0
  52. {trunk/lib → lib}/view/assets/img/ajax-loader.gif +0 -0
  53. lib/view/assets/javascript/export.min.js +1 -1
  54. lib/view/assets/javascript/import.min.js +1 -1
  55. lib/view/export/index.php +187 -96
  56. lib/view/import/index.php +159 -47
  57. loader.php +44 -4
  58. readme.txt +20 -17
  59. trunk/LICENSE +0 -675
  60. trunk/all-in-one-wp-migration.php +0 -53
  61. trunk/constants.php +0 -184
  62. trunk/lib/controller/class-ai1wm-export-controller.php +0 -111
  63. trunk/lib/controller/class-ai1wm-feedback-controller.php +0 -60
  64. trunk/lib/controller/class-ai1wm-import-controller.php +0 -189
  65. trunk/lib/controller/class-ai1wm-main-controller.php +0 -332
  66. trunk/lib/controller/class-ai1wm-message-controller.php +0 -44
  67. trunk/lib/controller/class-ai1wm-report-controller.php +0 -54
  68. trunk/lib/model/class-ai1wm-error.php +0 -85
  69. trunk/lib/model/class-ai1wm-export.php +0 -152
  70. trunk/lib/model/class-ai1wm-feedback.php +0 -71
  71. trunk/lib/model/class-ai1wm-import.php +0 -204
  72. trunk/lib/model/class-ai1wm-message.php +0 -94
  73. trunk/lib/model/class-ai1wm-report.php +0 -67
  74. trunk/lib/model/class-ai1wm-template.php +0 -46
  75. trunk/lib/vendor/bandar/bandar/LICENSE +0 -20
  76. trunk/lib/vendor/bandar/bandar/lib/Bandar.php +0 -223
  77. trunk/lib/vendor/bandar/bandar/lib/Exceptions/TemplateDoesNotExistException.php +0 -50
  78. trunk/lib/vendor/mysqldump-factory/mysqldump-factory/LICENSE +0 -20
  79. trunk/lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpFactory.php +0 -69
  80. trunk/lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpInterface.php +0 -303
  81. trunk/lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpPDO.php +0 -798
  82. trunk/lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpSQL.php +0 -738
  83. trunk/lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlFileAdapter.php +0 -74
  84. trunk/lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlQueryAdapter.php +0 -109
  85. trunk/lib/vendor/storage-factory/storage-factory/LICENSE +0 -20
  86. trunk/lib/vendor/storage-factory/storage-factory/lib/StorageAbstract.php +0 -70
  87. trunk/lib/vendor/storage-factory/storage-factory/lib/StorageArea.php +0 -130
  88. trunk/lib/vendor/storage-factory/storage-factory/lib/StorageDirectory.php +0 -100
  89. trunk/lib/vendor/storage-factory/storage-factory/lib/StorageFile.php +0 -100
  90. trunk/lib/vendor/zip-factory/zip-factory/LICENSE +0 -20
  91. trunk/lib/vendor/zip-factory/zip-factory/lib/ArchiverInterface.php +0 -118
  92. trunk/lib/vendor/zip-factory/zip-factory/lib/ArchiverPclZip.php +0 -218
  93. trunk/lib/vendor/zip-factory/zip-factory/lib/ArchiverZipArchive.php +0 -223
  94. trunk/lib/vendor/zip-factory/zip-factory/lib/ZipFactory.php +0 -70
  95. trunk/lib/vendor/zip-factory/zip-factory/lib/vendor/pclzip-2-8-2/gnu-lgpl.txt +0 -504
  96. trunk/lib/vendor/zip-factory/zip-factory/lib/vendor/pclzip-2-8-2/pclzip.lib.php +0 -5690
  97. trunk/lib/vendor/zip-factory/zip-factory/lib/vendor/pclzip-2-8-2/readme.txt +0 -421
  98. trunk/lib/view/assets/css/export.min.css +0 -1
  99. trunk/lib/view/assets/css/import.min.css +0 -1
  100. trunk/lib/view/assets/font/servmask.eot +0 -0
  101. trunk/lib/view/assets/font/servmask.svg +0 -22
  102. trunk/lib/view/assets/font/servmask.ttf +0 -0
  103. trunk/lib/view/assets/font/servmask.woff +0 -0
  104. trunk/lib/view/assets/javascript/export.min.js +0 -1
  105. trunk/lib/view/assets/javascript/import.min.js +0 -1
  106. trunk/lib/view/export/index.php +0 -341
  107. trunk/lib/view/import/index.php +0 -247
  108. trunk/loader.php +0 -161
  109. trunk/readme.txt +0 -174
  110. trunk/uninstall.php +0 -43
  111. uninstall.php +5 -6
all-in-one-wp-migration.php CHANGED
@@ -2,10 +2,10 @@
2
/**
3
* Plugin Name: All-in-One WP Migration
4
* Plugin URI: https://servmask.com/
5
- * Description: Migration tool for all your blog data
6
* Author: ServMask
7
* Author URI: https://servmask.com/
8
- * Version: 1.9.2
9
*
10
* Copyright (C) 2014 ServMask Inc.
11
*
2
/**
3
* Plugin Name: All-in-One WP Migration
4
* Plugin URI: https://servmask.com/
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: 2.0.2
9
*
10
* Copyright (C) 2014 ServMask Inc.
11
*
constants.php CHANGED
@@ -24,15 +24,20 @@
24
*/
25
26
// ==================
27
- // = Plugin VERSION =
28
// ==================
29
- define( 'AI1WM_VERSION', '1.9.2' );
30
31
// ===============
32
// = Plugin Name =
33
// ===============
34
define( 'AI1WM_PLUGIN_NAME', 'all-in-one-wp-migration' );
35
36
// ===============
37
// = Storage Path =
38
// ===============
@@ -53,6 +58,11 @@ define( 'AI1WM_CONTROLLER_PATH', AI1WM_LIB_PATH . DIRECTORY_SEPARATOR . 'control
53
// ==============
54
define( 'AI1WM_MODEL_PATH', AI1WM_LIB_PATH . DIRECTORY_SEPARATOR . 'model' );
55
56
// =============
57
// = View Path =
58
// =============
@@ -84,19 +94,91 @@ define( 'AI1WM_REPORT_URL', 'https://servmask.com/ai1wm/report/create' );
84
define( 'AI1WM_TABLE_PREFIX', 'SERVMASK_PREFIX_' );
85
86
// ==============
87
- // = ServMask Storage Prefix =
88
// ==============
89
- define( 'AI1WM_STORAGE_PREFIX', 'wm_' );
90
91
// ===========================
92
// = WP_CONTENT_DIR Constant =
93
// ===========================
94
- if ( ! defined( 'WP_CONTENT_DIR' ) )
95
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
96
97
// ==========================
98
// = WP_PLUGIN_DIR Constant =
99
// ==========================
100
- if ( ! defined( 'WP_PLUGIN_DIR' ) )
101
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
102
24
*/
25
26
// ==================
27
+ // = Plugin Version =
28
// ==================
29
+ define( 'AI1WM_VERSION', '2.0.2' );
30
31
// ===============
32
// = Plugin Name =
33
// ===============
34
define( 'AI1WM_PLUGIN_NAME', 'all-in-one-wp-migration' );
35
36
+ // ===============
37
+ // = Storage Index =
38
+ // ===============
39
+ define( 'AI1WM_STORAGE_INDEX', 'index.php' );
40
+
41
// ===============
42
// = Storage Path =
43
// ===============
58
// ==============
59
define( 'AI1WM_MODEL_PATH', AI1WM_LIB_PATH . DIRECTORY_SEPARATOR . 'model' );
60
61
+ // ==============
62
+ // = Service Path =
63
+ // ==============
64
+ define( 'AI1WM_SERVICE_PATH', AI1WM_MODEL_PATH . DIRECTORY_SEPARATOR . 'service' );
65
+
66
// =============
67
// = View Path =
68
// =============
94
define( 'AI1WM_TABLE_PREFIX', 'SERVMASK_PREFIX_' );
95
96
// ==============
97
+ // = Archive Database Name =
98
+ // ==============
99
+ define( 'AI1WM_DATABASE_NAME', 'database.sql' );
100
+
101
+ // ==============
102
+ // = Archive Media Name =
103
+ // ==============
104
+ define( 'AI1WM_MEDIA_NAME', 'media' );
105
+
106
+ // ==============
107
+ // = Archive Sites Name =
108
+ // ==============
109
+ define( 'AI1WM_SITES_NAME', 'sites' );
110
+
111
+ // ==============
112
+ // = Archive Blogs Name =
113
+ // ==============
114
+ define( 'AI1WM_BLOGS_NAME', 'blogs.dir' );
115
+
116
+ // ==============
117
+ // = Archive Themes Name =
118
+ // ==============
119
+ define( 'AI1WM_THEMES_NAME', 'themes' );
120
+
121
+ // ==============
122
+ // = Archive Plugins Name =
123
+ // ==============
124
+ define( 'AI1WM_PLUGINS_NAME', 'plugins' );
125
+
126
+ // ==============
127
+ // = Archive Package Name =
128
+ // ==============
129
+ define( 'AI1WM_PACKAGE_NAME', 'package.json' );
130
+
131
+ // ==============
132
+ // = Export Options Key =
133
+ // ==============
134
+ define( 'AI1WM_EXPORT_OPTIONS', 'ai1wm_export_options' );
135
+
136
+ // ==============
137
+ // = Error Handler Key =
138
+ // ==============
139
+ define( 'AI1WM_ERROR_HANDLER', 'ai1wm_error_handler' );
140
+
141
+ // ==============
142
+ // = Exception Handler Key =
143
+ // ==============
144
+ define( 'AI1WM_EXCEPTION_HANDLER', 'ai1wm_exception_handler' );
145
+
146
+ // ==============
147
+ // = Maintenance Mode Key =
148
+ // ==============
149
+ define( 'AI1WM_MAINTENANCE_MODE', 'ai1wm_maintenance_mode' );
150
+
151
+ // ==============
152
+ // = Messages Key =
153
+ // ==============
154
+ define( 'AI1WM_MESSAGES', 'ai1wm_messages' );
155
+
156
+ // ==============
157
+ // = Max File Size =
158
+ // ==============
159
+ define( 'AI1WM_MAX_FILE_SIZE', '512MB' );
160
+
161
+ // ==============
162
+ // = Max Chunk Size =
163
+ // ==============
164
+ define( 'AI1WM_MAX_CHUNK_SIZE', '500KB' );
165
+
166
+ // ==============
167
+ // = Max Chunk Retries =
168
// ==============
169
+ define( 'AI1WM_MAX_CHUNK_RETRIES', '100' );
170
171
// ===========================
172
// = WP_CONTENT_DIR Constant =
173
// ===========================
174
+ if ( ! defined( 'WP_CONTENT_DIR' ) ) {
175
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
176
+ }
177
178
// ==========================
179
// = WP_PLUGIN_DIR Constant =
180
// ==========================
181
+ if ( ! defined( 'WP_PLUGIN_DIR' ) ) {
182
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
183
+ }
184
lib/controller/class-ai1wm-export-controller.php CHANGED
@@ -27,23 +27,20 @@ class Ai1wm_Export_Controller
27
{
28
public static function index() {
29
try {
30
- $storage = new StorageArea;
31
- $is_accessible = $storage->makeFile();
32
- $storage->flush();
33
} catch ( Exception $e ) {
34
$is_accessible = false;
35
}
36
37
- // Message
38
- $message = new Ai1wm_Message;
39
- $is_closed = $message->is_closed( Ai1wm_Message::MESSAGE_INFO );
40
41
Ai1wm_Template::render(
42
'export/index',
43
array(
44
- 'list_plugins' => get_plugins(),
45
'is_accessible' => $is_accessible,
46
- 'is_closed' => $is_closed,
47
)
48
);
49
}
@@ -55,36 +52,60 @@ class Ai1wm_Export_Controller
55
56
// Get options
57
if ( isset( $_POST['options'] ) && ( $options = $_POST['options'] ) ) {
58
- $storage = new StorageArea;
59
60
- // Export archive
61
- $model = new Ai1wm_Export;
62
- $file = $model->export( $storage, $options );
63
64
// Send the file to the user
65
header( 'Content-Description: File Transfer' );
66
header( 'Content-Type: application/octet-stream' );
67
- header(
68
- sprintf(
69
- 'Content-Disposition: attachment; filename=%s-%s.%s',
70
- Ai1wm_Export::EXPORT_ARCHIVE_NAME,
71
- time(),
72
- 'zip'
73
- )
74
- );
75
header( 'Content-Transfer-Encoding: binary' );
76
header( 'Expires: 0' );
77
header( 'Cache-Control: must-revalidate' );
78
header( 'Pragma: public' );
79
- header( 'Content-Length: ' . filesize( $file->getAs( 'string' ) ) );
80
81
// Clear output buffering and read file content
82
- if ( ob_get_length() > 0 ) {
83
- @ob_end_clean();
84
}
85
- readfile( $file->getAs( 'string' ) );
86
- $storage->flush();
87
exit;
88
}
89
}
90
}
27
{
28
public static function index() {
29
try {
30
+ $is_accessible = StorageArea::getInstance()->getRootPath();
31
} catch ( Exception $e ) {
32
$is_accessible = false;
33
}
34
35
+ // Messages
36
+ $model = new Ai1wm_Message;
37
+ $messages = $model->get_messages();
38
39
Ai1wm_Template::render(
40
'export/index',
41
array(
42
+ 'messages' => $messages,
43
'is_accessible' => $is_accessible,
44
)
45
);
46
}
52
53
// Get options
54
if ( isset( $_POST['options'] ) && ( $options = $_POST['options'] ) ) {
55
56
+ // Log options
57
+ Ai1wm_Logger::debug( AI1WM_EXPORT_OPTIONS, $options );
58
+
59
+ // Export site
60
+ $model = new Ai1wm_Export( $options );
61
+ $file = $model->export();
62
63
// Send the file to the user
64
header( 'Content-Description: File Transfer' );
65
header( 'Content-Type: application/octet-stream' );
66
+ header( 'Content-Disposition: attachment; filename=' . self::filename() );
67
header( 'Content-Transfer-Encoding: binary' );
68
header( 'Expires: 0' );
69
header( 'Cache-Control: must-revalidate' );
70
header( 'Pragma: public' );
71
+ header( 'Content-Length: ' . $file->getSize() );
72
73
// Clear output buffering and read file content
74
+ while ( @ob_end_clean() );
75
+
76
+ // Load file content
77
+ $handle = fopen( $file->getName(), 'rb' );
78
+ while ( ! feof( $handle ) ) {
79
+ echo fread( $handle, 8192 );
80
}
81
+ fclose( $handle );
82
+
83
+ // Flush storage
84
+ StorageArea::getInstance()->flush();
85
exit;
86
}
87
}
88
+
89
+ public static function filename() {
90
+ $url = parse_url( home_url() );
91
+ $name = array();
92
+
93
+ // Add domain
94
+ if ( isset( $url['host'] ) ) {
95
+ $name[] = $url['host'];
96
+ }
97
+
98
+ // Add path
99
+ if ( isset( $url['path'] ) ) {
100
+ $name[] = $url['path'];
101
+ }
102
+
103
+ // Add year, month and day
104
+ $name[] = date('Ymd');
105
+
106
+ // Add hours, minutes and seconds
107
+ $name[] = date('His');
108
+
109
+ return sprintf( '%s.zip', implode( '-', $name ) );
110
+ }
111
}
lib/controller/class-ai1wm-feedback-controller.php CHANGED
@@ -26,6 +26,12 @@
26
class Ai1wm_Feedback_Controller
27
{
28
public static function leave_feedback() {
29
// Set E-mail
30
$email = null;
31
if ( isset( $_POST['email'] ) ) {
@@ -46,7 +52,7 @@ class Ai1wm_Feedback_Controller
46
47
// Send Feedback
48
$model = new Ai1wm_Feedback;
49
- $result = $model->leave_feedback( $email, $message, $terms );
50
51
echo json_encode( $result );
52
exit;
26
class Ai1wm_Feedback_Controller
27
{
28
public static function leave_feedback() {
29
+ // Set Type
30
+ $type = null;
31
+ if ( isset( $_POST['type'] ) ) {
32
+ $type = trim( $_POST['type'] );
33
+ }
34
+
35
// Set E-mail
36
$email = null;
37
if ( isset( $_POST['email'] ) ) {
52
53
// Send Feedback
54
$model = new Ai1wm_Feedback;
55
+ $result = $model->leave_feedback( $type, $email, $message, $terms );
56
57
echo json_encode( $result );
58
exit;
lib/controller/class-ai1wm-import-controller.php CHANGED
@@ -27,9 +27,7 @@ class Ai1wm_Import_Controller
27
{
28
public static function index() {
29
try {
30
- $storage = new StorageArea;
31
- $is_accessible = $storage->makeFile();
32
- $storage->flush();
33
} catch ( Exception $e ) {
34
$is_accessible = false;
35
}
@@ -38,25 +36,28 @@ class Ai1wm_Import_Controller
38
'import/index',
39
array(
40
'is_accessible' => $is_accessible,
41
)
42
);
43
}
44
45
- public static function upload_file() {
46
global $wp_rewrite;
47
48
// Set default handlers
49
set_error_handler( array( 'Ai1wm_Error', 'error_handler' ) );
50
set_exception_handler( array( 'Ai1wm_Error', 'exception_handler' ) );
51
52
- $result = array();
53
54
- // Get options
55
- if ( isset( $_FILES['input_file'] ) && ( $input_file = $_FILES['input_file'] ) ) {
56
$options = array(
57
- 'chunk' => 0,
58
- 'chunks' => 0,
59
- 'name' => null,
60
);
61
62
// Ordinal number of the current chunk in the set (starts with zero)
@@ -69,19 +70,120 @@ class Ai1wm_Import_Controller
69
$options['chunks'] = intval( $_REQUEST['chunks'] );
70
}
71
72
- // Name of partial file
73
if ( isset( $_REQUEST['name'] ) ) {
74
- $options['name'] = $_REQUEST['name'];
75
}
76
77
- $model = new Ai1wm_Import;
78
- $result = $model->import( $input_file, $options );
79
80
- // Regenerate permalinks
81
- $wp_rewrite->flush_rules( true );
82
}
83
84
- echo json_encode( $result );
85
exit;
86
}
87
}
27
{
28
public static function index() {
29
try {
30
+ $is_accessible = StorageArea::getInstance()->getRootPath();
31
} catch ( Exception $e ) {
32
$is_accessible = false;
33
}
36
'import/index',
37
array(
38
'is_accessible' => $is_accessible,
39
+ 'max_file_size' => apply_filters( 'ai1wm_max_file_size', AI1WM_MAX_FILE_SIZE ),
40
)
41
);
42
}
43
44
+ public static function import() {
45
global $wp_rewrite;
46
47
// Set default handlers
48
set_error_handler( array( 'Ai1wm_Error', 'error_handler' ) );
49
set_exception_handler( array( 'Ai1wm_Error', 'exception_handler' ) );
50
51
+ $messages = array();
52
53
+ if ( isset( $_FILES['upload-file'] ) || isset( $_REQUEST['force'] ) ) {
54
$options = array(
55
+ 'chunk' => 0,
56
+ 'chunks' => 1,
57
+ 'import' => array(
58
+ 'file' => null,
59
+ 'force' => null,
60
+ ),
61
);
62
63
// Ordinal number of the current chunk in the set (starts with zero)
70
$options['chunks'] = intval( $_REQUEST['chunks'] );
71
}
72
73
+ // Import file
74
if ( isset( $_REQUEST['name'] ) ) {
75
+ $options['import']['file'] = $_REQUEST['name'];
76
}
77
78
+ // Force file
79
+ if ( isset( $_REQUEST['force'] ) ) {
80
+ $options['import']['force'] = $_REQUEST['force'];
81
+ }
82
+
83
+ try {
84
+ // Upload file
85
+ if ( self::upload( $options ) ) {
86
+
87
+ // Import site
88
+ $model = new Ai1wm_Import( $options );
89
+ if ( $model->import() ) {
90
+ $messages[] = array(
91
+ 'type' => 'success',
92
+ 'text' => sprintf(
93
+ _(
94
+ 'Your data has been imported successfuly!<br />' .
95
+ 'You need to perform two more steps:<br />' .
96
+ '<strong>1. You must save your permalinks structure twice. <a class="ai1wm-no-underline" href="%s#submit" target="_blank">Permalinks Settings</a></strong> (opens a new window)<br />' .
97
+ '<strong>2. <a class="ai1wm-no-underline" href="https://wordpress.org/support/view/plugin-reviews/all-in-one-wp-migration?rate=5#postform" target="_blank">Review the plugin</a>.</strong> (opens a new window)'
98
+ ),
99
+ admin_url( 'options-permalink.php' )
100
+ ),
101
+ );
102
+
103
+ // Flush storage
104
+ StorageArea::getInstance()->flush();
105
+ }
106
+ }
107
+ } catch ( Exception $e ) {
108
+ $messages[] = array(
109
+ 'type' => 'error',
110
+ 'text' => $e->getMessage(),
111
+ );
112
+ }
113
+ }
114
+
115
+ // Regenerate permalinks
116
+ $wp_rewrite->flush_rules( true );
117
+
118
+ // Display messages
119
+ echo json_encode( $messages );
120
+ exit;
121
+ }
122
123
+ public static function upload( $options ) {
124
+ $storage = StorageArea::getInstance();
125
+
126
+ // Partial upload file
127
+ $partial_file = $storage->makeFile( $options['import']['file'] );
128
+
129
+ // Upload file
130
+ if ( isset( $_FILES['upload-file'] ) ) {
131
+
132
+ // Has any upload error?
133
+ if ( empty( $_FILES['upload-file']['error'] ) ) {
134
+
135
+ // Flush storage
136
+ if ( $options['chunk'] === 0 ) {
137
+ $storage->flush();
138
+ }
139
+
140
+ // Open partial file
141
+ $out = fopen( $partial_file->getName(), $options['chunk'] == 0 ? 'wb' : 'ab' );
142
+ if ( $out ) {
143
+ // Read binary input stream and append it to temp file
144
+ $in = fopen( $_FILES['upload-file']['tmp_name'], 'rb' );
145
+ if ( $in ) {
146
+ while ( $buff = fread( $in, 4096 ) ) {
147
+ fwrite( $out, $buff );
148
+ }
149
+ }
150
+
151
+ fclose( $in );
152
+ fclose( $out );
153
+
154
+ // Remove temporary uploaded file
155
+ unlink( $_FILES['upload-file']['tmp_name'] );
156
+ } else {
157
+ throw new Ai1wm_Import_Exception(
158
+ sprintf(
159
+ _(
160
+ 'Site could not be imported!<br />' .
161
+ 'Please make sure that storage directory <strong>%s</strong> has read and write permissions.'
162
+ ),
163
+ AI1WM_STORAGE_PATH
164
+ )
165
+ );
166
+
167
+ // Flush storage
168
+ $storage->flush();
169
+ }
170
+ } else {
171
+ throw new Ai1wm_Import_Exception(
172
+ sprintf(
173
+ _(
174
+ 'Site could not be imported!<br />' .
175
+ 'Please contact ServMask Support and report the following error code: %d'
176
+ ),
177
+ $_FILES['upload-file']['error']
178
+ )
179
+ );
180
+ }
181
}
182
183
+ // Upload completed?
184
+ if ( ! $options['chunks'] || $options['chunk'] == $options['chunks'] - 1 ) {
185
+ return $partial_file;
186
+ }
187
exit;
188
}
189
}
lib/controller/class-ai1wm-main-controller.php CHANGED
@@ -25,7 +25,6 @@
25
26
class Ai1wm_Main_Controller
27
{
28
-
29
/**
30
* Main Application Controller
31
*
@@ -75,13 +74,10 @@ class Ai1wm_Main_Controller
75
add_action( 'init', array( $this, 'router' ) );
76
add_action( 'wp_ajax_leave_feedback', 'Ai1wm_Feedback_Controller::leave_feedback' );
77
add_action( 'wp_ajax_report_problem', 'Ai1wm_Report_Controller::report_problem' );
78
- add_action( 'wp_ajax_upload_file', 'Ai1wm_Import_Controller::upload_file' );
79
add_action( 'wp_ajax_close_message', 'Ai1wm_Message_Controller::close_message' );
80
-
81
- // Enable or disable maintenance mode
82
- if ( get_option( Ai1wm_Import::MAINTENANCE_MODE ) ) {
83
- add_action( 'get_header', array( $this, 'activate_maintenance_mode' ) );
84
- }
85
86
// Add a links to plugin list page
87
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
@@ -109,23 +105,6 @@ class Ai1wm_Main_Controller
109
return $this;
110
}
111
112
- /**
113
- * Enable or disable Wordpress maintenance mode
114
- * @return void
115
- */
116
- public function activate_maintenance_mode() {
117
- $title = _( 'Maintenance Mode' );
118
- $body = sprintf(
119
- '<h1>%s</h1><p>%s<br /><strong>%s%s</strong></p>',
120
- _( 'Website Under Maintenance' ),
121
- _( 'Hi, our Website is currently undergoing scheduled maintenance' ),
122
- _( 'Please check back very soon. ' ),
123
- _( 'Sorry for the inconvenience!' )
124
- );
125
-
126
- wp_die( $body, $title );
127
- }
128
-
129
/**
130
* Register plugin menus
131
*/
@@ -175,26 +154,20 @@ class Ai1wm_Main_Controller
175
*/
176
public function admin_head() {
177
global $wp_version;
178
- $_wp_version = $wp_version;
179
- if ( strlen( $_wp_version ) === '3' ) {
180
- $_wp_version += '.0';
181
- } else if ( strlen( $_wp_version ) === '1' ) {
182
- $_wp_version += '0.0';
183
- }
184
$url = AI1WM_URL . '/lib/view/assets';
185
?>
186
<style type="text/css" media="all">
187
@font-face {
188
font-family: 'servmask';
189
- src:url('<?php echo esc_url( $url ); ?>/font/servmask.eot');
190
- src:url('<?php echo esc_url( $url ); ?>/font/servmask.eot?#iefix') format('embedded-opentype'),
191
- url('<?php echo esc_url( $url ); ?>/font/servmask.woff') format('woff'),
192
- url('<?php echo esc_url( $url ); ?>/font/servmask.ttf') format('truetype'),
193
- url('<?php echo esc_url( $url ); ?>/font/servmask.svg#servmask') format('svg');
194
font-weight: normal;
195
font-style: normal;
196
}
197
- <?php if ( version_compare( $_wp_version, '3.8', '<' ) ) : ?>
198
.toplevel_page_site-migration-export > div.wp-menu-image {
199
background: none !important;
200
}
@@ -262,6 +235,12 @@ class Ai1wm_Main_Controller
262
),
263
);
264
wp_localize_script( 'ai1wm-js-export', 'ai1wm_message', $message_init );
265
}
266
267
/**
@@ -282,17 +261,19 @@ class Ai1wm_Main_Controller
282
'browse_button' => 'ai1wm-browse-button',
283
'container' => 'ai1wm-plupload-upload-ui',
284
'drop_element' => 'ai1wm-drag-drop-area',
285
- 'file_data_name' => 'input_file',
286
- 'multiple_queues' => false,
287
- 'max_file_size' => Ai1wm_Import::MAX_FILE_SIZE,
288
- 'chunk_size' => Ai1wm_Import::MAX_CHUNK_SIZE,
289
- 'max_retries' => Ai1wm_Import::MAX_CHUNK_RETRIES,
290
'url' => admin_url( 'admin-ajax.php' ),
291
- 'flash_swf_url' => includes_url(
292
- 'js/plupload/plupload.flash.swf'
293
- ),
294
- 'silverlight_xap_url' => includes_url(
295
- 'js/plupload/plupload.silverlight.xap'
296
),
297
'filters' => array(
298
array(
@@ -300,12 +281,6 @@ class Ai1wm_Main_Controller
300
'extensions' => 'zip',
301
),
302
),
303
- 'multipart' => true,
304
- 'urlstream_upload' => true,
305
- 'multipart_params' => array(
306
- 'action' => 'upload_file',
307
- 'name' => uniqid() . '.part',
308
- ),
309
);
310
wp_localize_script( 'ai1wm-js-import', 'ai1wm_uploader', $plupload_init );
311
$feedback_init = array(
@@ -320,6 +295,18 @@ class Ai1wm_Main_Controller
320
),
321
);
322
wp_localize_script( 'ai1wm-js-import', 'ai1wm_report', $report_init );
323
}
324
325
/**
25
26
class Ai1wm_Main_Controller
27
{
28
/**
29
* Main Application Controller
30
*
74
add_action( 'init', array( $this, 'router' ) );
75
add_action( 'wp_ajax_leave_feedback', 'Ai1wm_Feedback_Controller::leave_feedback' );
76
add_action( 'wp_ajax_report_problem', 'Ai1wm_Report_Controller::report_problem' );
77
+ add_action( 'wp_ajax_import', 'Ai1wm_Import_Controller::import' );
78
add_action( 'wp_ajax_close_message', 'Ai1wm_Message_Controller::close_message' );
79
+ add_action( 'wp_ajax_disable_maintenance', 'Ai1wm_Maintenance::disable' );
80
+ add_action( 'get_header', 'Ai1wm_Maintenance::display' );
81
82
// Add a links to plugin list page
83
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
105
return $this;
106
}
107
108
/**
109
* Register plugin menus
110
*/
154
*/
155
public function admin_head() {
156
global $wp_version;
157
$url = AI1WM_URL . '/lib/view/assets';
158
?>
159
<style type="text/css" media="all">
160
@font-face {
161
font-family: 'servmask';
162
+ src:url('<?php echo esc_url( $url ); ?>/font/servmask.eot?v=<?php echo AI1WM_VERSION; ?>');
163
+ src:url('<?php echo esc_url( $url ); ?>/font/servmask.eot?v=<?php echo AI1WM_VERSION; ?>#iefix') format('embedded-opentype'),
164
+ url('<?php echo esc_url( $url ); ?>/font/servmask.woff?v=<?php echo AI1WM_VERSION; ?>') format('woff'),
165
+ url('<?php echo esc_url( $url ); ?>/font/servmask.ttf?v=<?php echo AI1WM_VERSION; ?>') format('truetype'),
166
+ url('<?php echo esc_url( $url ); ?>/font/servmask.svg?v=<?php echo AI1WM_VERSION; ?>#servmask') format('svg');
167
font-weight: normal;
168
font-style: normal;
169
}
170
+ <?php if ( version_compare( $wp_version, '3.8', '<' ) ) : ?>
171
.toplevel_page_site-migration-export > div.wp-menu-image {
172
background: none !important;
173
}
235
),
236
);
237
wp_localize_script( 'ai1wm-js-export', 'ai1wm_message', $message_init );
238
+ $maintenance_init = array(
239
+ 'ajax' => array(
240
+ 'url' => admin_url( 'admin-ajax.php' ) . '?action=disable_maintenance',
241
+ ),
242
+ );
243
+ wp_localize_script( 'ai1wm-js-export', 'ai1wm_maintenance', $maintenance_init );
244
}
245
246
/**
261
'browse_button' => 'ai1wm-browse-button',
262
'container' => 'ai1wm-plupload-upload-ui',
263
'drop_element' => 'ai1wm-drag-drop-area',
264
+ 'file_data_name' => 'upload-file',
265
+ 'max_file_size' => apply_filters( 'ai1wm_max_file_size', AI1WM_MAX_FILE_SIZE ),
266
+ 'chunk_size' => apply_filters( 'ai1wm_max_chunk_size', AI1WM_MAX_CHUNK_SIZE ),
267
+ 'max_retries' => apply_filters( 'ai1wm_max_chunk_retries', AI1WM_MAX_CHUNK_RETRIES ),
268
'url' => admin_url( 'admin-ajax.php' ),
269
+ 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
270
+ 'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
271
+ 'multiple_queues' => false,
272
+ 'urlstream_upload' => true,
273
+ 'unique_names' => true,
274
+ 'multipart' => true,
275
+ 'multipart_params' => array(
276
+ 'action' => 'import',
277
),
278
'filters' => array(
279
array(
281
'extensions' => 'zip',
282
),
283
),
284
);
285
wp_localize_script( 'ai1wm-js-import', 'ai1wm_uploader', $plupload_init );
286
$feedback_init = array(
295
),
296
);
297
wp_localize_script( 'ai1wm-js-import', 'ai1wm_report', $report_init );
298
+ $maintenance_init = array(
299
+ 'ajax' => array(
300
+ 'url' => admin_url( 'admin-ajax.php' ) . '?action=disable_maintenance',
301
+ ),
302
+ );
303
+ wp_localize_script( 'ai1wm-js-import', 'ai1wm_maintenance', $maintenance_init );
304
+ $import_init = array(
305
+ 'ajax' => array(
306
+ 'url' => admin_url( 'admin-ajax.php' ) . '?action=import',
307
+ ),
308
+ );
309
+ wp_localize_script( 'ai1wm-js-import', 'ai1wm_import', $import_init );
310
}
311
312
/**
lib/controller/class-ai1wm-message-controller.php CHANGED
@@ -26,15 +26,17 @@
26
class Ai1wm_Message_Controller
27
{
28
public static function close_message() {
29
- // Set Type
30
- $type = null;
31
- if ( isset( $_POST['type'] ) ) {
32
- $type = trim( $_POST['type'] );
33
}
34
35
// Close message
36
$model = new Ai1wm_Message;
37
- $result = $model->close_message( $type );
38
39
echo json_encode( $result );
40
exit;
26
class Ai1wm_Message_Controller
27
{
28
public static function close_message() {
29
+ $errors = array();
30
+
31
+ // Set Key
32
+ $key = null;
33
+ if ( isset( $_POST['key'] ) ) {
34
+ $key = trim( $_POST['key'] );
35
}
36
37
// Close message
38
$model = new Ai1wm_Message;
39
+ $result = $model->close_message( $key );
40
41
echo json_encode( $result );
42
exit;
{trunk/lib → lib}/exception/class-ai1wm-export-exception.php RENAMED
File without changes
{trunk/lib → lib}/exception/class-ai1wm-import-exception.php RENAMED
File without changes
lib/model/class-ai1wm-error.php CHANGED
@@ -25,10 +25,8 @@
25
26
class Ai1wm_Error
27
{
28
- const ERROR_LIMIT = 20;
29
- const EXCEPTION_LIMIT = 20;
30
- const ERROR_HANDLER = 'ai1wm_error_handler';
31
- const EXCEPTION_HANDLER = 'ai1wm_exception_handler';
32
33
/**
34
* Custom Error Handler
@@ -40,7 +38,7 @@ class Ai1wm_Error
40
* @return void
41
*/
42
public static function error_handler( $code, $message, $file, $line ) {
43
- $errors = get_option( self::ERROR_HANDLER, array() );
44
45
// Limit errors
46
if ( count( $errors ) > self::ERROR_LIMIT ) {
@@ -56,7 +54,7 @@ class Ai1wm_Error
56
'time' => time(),
57
);
58
59
- update_option( self::ERROR_HANDLER, $errors );
60
}
61
62
/**
@@ -66,7 +64,7 @@ class Ai1wm_Error
66
* @return void
67
*/
68
public static function exception_handler( $e ) {
69
- $exceptions = get_option( self::EXCEPTION_HANDLER, array() );
70
71
// Limit errors
72
if ( count( $exceptions ) > self::EXCEPTION_LIMIT ) {
@@ -82,6 +80,6 @@ class Ai1wm_Error
82
'time' => time(),
83
);
84
85
- update_option( self::EXCEPTION_HANDLER, $exceptions );
86
}
87
}
25
26
class Ai1wm_Error
27
{
28
+ const ERROR_LIMIT = 10;
29
+ const EXCEPTION_LIMIT = 10;
30
31
/**
32
* Custom Error Handler
38
* @return void
39
*/
40
public static function error_handler( $code, $message, $file, $line ) {
41
+ $errors = get_option( AI1WM_ERROR_HANDLER, array() );
42
43
// Limit errors
44
if ( count( $errors ) > self::ERROR_LIMIT ) {
54
'time' => time(),
55
);
56
57
+ Ai1wm_Logger::error( AI1WM_ERROR_HANDLER, $errors );
58
}
59
60
/**
64
* @return void
65
*/
66
public static function exception_handler( $e ) {
67
+ $exceptions = get_option( AI1WM_EXCEPTION_HANDLER, array() );
68
69
// Limit errors
70
if ( count( $exceptions ) > self::EXCEPTION_LIMIT ) {
80
'time' => time(),
81
);
82
83
+ Ai1wm_Logger::error( AI1WM_EXCEPTION_HANDLER, $exceptions );
84
}
85
}
lib/model/class-ai1wm-export.php CHANGED
@@ -25,322 +25,128 @@
25
26
class Ai1wm_Export
27
{
28
- const EXPORT_ARCHIVE_NAME = 'dump';
29
- const EXPORT_DATABASE_NAME = 'database.sql';
30
- const EXPORT_PACKAGE_NAME = 'package.json';
31
- const EXPORT_MEDIA_NAME = 'media';
32
- const EXPORT_PLUGINS_NAME = 'plugins';
33
- const EXPORT_THEMES_NAME = 'themes';
34
- const EXPORT_LAST_OPTIONS = 'ai1wm_export_last_options';
35
36
/**
37
- * Export archive file (database, media, package.json)
38
*
39
- * @param StorageArea $storage Storage instance
40
- * @param array $options Export settings
41
- * @return StorageFile StorageFile instance
42
*/
43
- public function export( StorageArea $storage, array $options = array() ) {
44
- global $wp_version;
45
- $options['plugin_version'] = AI1WM_VERSION;
46
- $options['wp_version'] = $wp_version;
47
- $options['php_version'] = phpversion();
48
- $options['php_uname'] = php_uname();
49
- $options['max_execution_time'] = ini_get( 'max_execution_time' );
50
- $options['memory_limit'] = ini_get( 'memory_limit' );
51
- $options['memory_get_peak_usage'] = memory_get_peak_usage();
52
- $options['memory_get_usage'] = memory_get_usage();
53
- $options['ZipArchive'] = class_exists( 'ZipArchive' ) ? 1 : 0;
54
- $options['ZLIB_installed'] = function_exists( 'gzopen' ) ? 1 : 0;
55
- $options['PDO_available'] = class_exists( 'PDO' ) ? 1 : 0;
56
- $options['home_url'] = home_url();
57
58
- // Export last options
59
- update_option( self::EXPORT_LAST_OPTIONS, $options );
60
61
- // Flush storage directory
62
- StorageDirectory::flush( AI1WM_STORAGE_PATH, array( '.gitignore' ) );
63
64
- // Create output file
65
- $output_file = $storage->makeFile();
66
-
67
- // Make archive
68
try {
69
- $archive = ZipFactory::makeZipArchiver( $output_file->getAs( 'resource' ), ! class_exists( 'ZipArchive' ), true );
70
} catch ( Exception $e ) {
71
- $archive = ZipFactory::makeZipArchiver( $output_file->getAs( 'resource' ), true, true );
72
- }
73
-
74
- // Should we export database?
75
- if ( ! isset( $options['export-database'] ) ) {
76
- // Prepare database file
77
- $database_file = $this->prepare_database( $storage, $options );
78
-
79
- // Add database to archive
80
- $archive->addFile(
81
- $database_file->getAs( 'resource' ),
82
- self::EXPORT_DATABASE_NAME
83
- );
84
- }
85
-
86
- // Should we export media?
87
- if ( ! isset( $options['export-media'] ) ) {
88
- $archive->addDir(
89
- $this->prepare_media( $options ),
90
- self::EXPORT_MEDIA_NAME
91
- );
92
- }
93
-
94
- // Should we export themes?
95
- if ( ! isset( $options['export-themes'] ) ) {
96
- $archive->addDir(
97
- $this->prepare_themes( $options ),
98
- self::EXPORT_THEMES_NAME
99
- );
100
- }
101
-
102
- // Should we export plugins?
103
- if ( ! isset( $options['export-plugins'] ) ) {
104
- if ( ( $include = $this->get_plugins( array( AI1WM_PLUGIN_NAME ) ) ) ) {
105
- $archive->addDir(
106
- $this->prepare_plugins( $options ),
107
- self::EXPORT_PLUGINS_NAME,
108
- $include
109
- );
110
- }
111
}
112
113
- // Add package
114
- $archive->addFromString(
115
- self::EXPORT_PACKAGE_NAME,
116
- $this->prepare_package( $options )
117
- );
118
-
119
- return $output_file;
120
- }
121
-
122
- /**
123
- * Export database in SQL format
124
- *
125
- * @param StorageArea $storage Storage instance
126
- * @param array $options Export settings
127
- * @return StorageFile StorageFile instance
128
- */
129
- public function prepare_database( StorageArea $storage, array $options = array() ) {
130
- global $wpdb;
131
-
132
- $file = new Ai1wm_File;
133
- $database_file = $storage->makeFile();
134
-
135
- // Set include tables
136
- $includeTables = array();
137
- if ( isset( $options['include-tables'] ) ) {
138
- $includeTables = $options['include-tables'];
139
}
140
141
- // Set exclude tables
142
- $excludeTables = array();
143
- if ( isset( $options['exclude-tables' ] ) ) {
144
- $excludeTables = $options['exclude-tables'];
145
- }
146
147
- // Set no table data
148
- $noTableData = false;
149
- if ( isset( $options['no-table-data'] ) ) {
150
- $noTableData = true;
151
}
152
153
- $clauses = array();
154
155
- // Spam comments
156
- if ( isset( $options['export-spam-comments'] ) ) {
157
- $clauses[ $wpdb->comments ] = ' WHERE comment_approved != "spam" ORDER BY comment_ID ';
158
- $clauses[ $wpdb->commentmeta ] = sprintf(
159
- ' INNER JOIN `%1$s`
160
- ON `%1$s`.comment_ID = `%2$s`.comment_id AND `%1$s`.comment_approved != \'spam\'
161
- ORDER BY `%2$s`.meta_id ', $wpdb->comments, $wpdb->commentmeta
162
- );
163
- }
164
165
- // Post revisions
166
- if ( isset( $options['export-revisions'] ) ) {
167
- $clauses[ $wpdb->posts ] = ' WHERE post_type != "revision" ORDER BY ID ';
168
}
169
170
- // No table data, but leave Administrator account unchanged
171
- if ( $noTableData ) {
172
- $clauses = array();
173
- $clauses[ $wpdb->options ] = ' ORDER BY option_id ASC ';
174
- $clauses[ $wpdb->users ] = ' WHERE id = 1 ';
175
- $clauses[ $wpdb->usermeta ] = ' WHERE user_id = 1 ';
176
- }
177
178
- // Make connection
179
- try {
180
- $db = MysqlDumpFactory::makeMysqlDump(
181
- DB_HOST,
182
- DB_USER,
183
- DB_PASSWORD,
184
- DB_NAME,
185
- (
186
- class_exists(
187
- 'PDO'
188
- ) && in_array( 'mysql', PDO::getAvailableDrivers() )
189
- )
190
- );
191
- $db->getConnection();
192
- } catch ( Exception $e ) {
193
- // Use "old" mysql adapter
194
- $db = MysqlDumpFactory::makeMysqlDump( DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, false );
195
}
196
197
- // Set dump options
198
- $db->setFileName( $database_file->getAs( 'string' ) )
199
- ->setIncludeTables( $includeTables )
200
- ->setExcludeTables( $excludeTables )
201
- ->setNoTableData( $noTableData )
202
- ->setOldTablePrefix( $wpdb->prefix )
203
- ->setNewTablePrefix( AI1WM_TABLE_PREFIX )
204
- ->setQueryClauses( $clauses );
205
-
206
- // Export database into a file
207
- $db->export();
208
209
- // Replace Old/New Values
210
- if ( isset( $options['replace'] ) && ( $replace = $options['replace'] ) ) {
211
- $old_values = array();
212
- $new_values = array();
213
- for ( $i = 0; $i < count( $replace['old-value'] ); $i++ ) {
214
- if (
215
- ! empty( $replace['old-value'][$i] ) &&
216
- ! empty( $replace['new-value'][$i] ) &&
217
- $replace['old-value'][$i] != $replace['new-value'][$i]
218
- ) {
219
- $old_values[] = $replace['old-value'][$i];
220
- $new_values[] = $replace['new-value'][$i];
221
- }
222
- }
223
- // Do String Replacement
224
- if ( $old_values && $new_values ) {
225
- $database_file = $file->str_replace_file(
226
- $storage,
227
- $database_file,
228
- $old_values,
229
- $new_values
230
- );
231
-
232
- // Do find and replace
233
- $database_file = $file->preg_replace_file(
234
- $storage,
235
- $database_file,
236
- '/s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");/'
237
- );
238
}
239
}
240
241
- return $database_file;
242
- }
243
244
- /**
245
- * Unescape to avoid dump-text issues
246
- *
247
- * @param [type] $value [description]
248
- * @return [type] [description]
249
- */
250
- public static function unescape_mysql( $value ) {
251
- return str_replace(
252
- array( '\\\\', '\\0', "\\n", "\\r", '\Z', "\'", '\"', ),
253
- array( '\\', '\0', "\n", "\r", "\x1a", "'", '"', ),
254
- $value
255
- );
256
- }
257
-
258
- /**
259
- * Fix strange behaviour if you have escaped quotes in your replacement
260
- *
261
- * @param [type] $value [description]
262
- * @return [type] [description]
263
- */
264
- public static function unescape_quotes( $value ) {
265
- return str_replace( '\"', '"', $value );
266
}
267
268
/**
269
- * Export media library base directory
270
*
271
- * @param array $options Export settings
272
- * @return string Media base directory
273
*/
274
- public function prepare_media( array $options = array() ) {
275
- if ( ! isset( $options['export-media'] ) ) {
276
- $upload_dir = wp_upload_dir();
277
-
278
- return $upload_dir['basedir'];
279
- }
280
}
281
282
/**
283
- * Export themes root directory
284
*
285
- * @param array $options Export settings
286
- * @return string Themes root directory
287
*/
288
- public function prepare_themes( array $options = array() ) {
289
- if ( ! isset( $options['export-themes'] ) ) {
290
- $themes_dir = get_theme_root();
291
-
292
- return $themes_dir;
293
- }
294
}
295
296
/**
297
- * Export plugins root directory
298
*
299
- * @param array $options Export settings
300
- * @return string Plugins root directory
301
*/
302
- public function prepare_plugins( array $options = array() ) {
303
- if ( ! isset( $options['export-plugins'] ) ) {
304
- return WP_PLUGIN_DIR;
305
- }
306
}
307
308
/**
309
- * Export package json file which includes information about installed plugins and etc.
310
*
311
- * @param array $options Export settings
312
- * @return string Package config
313
*/
314
- public function prepare_package( array $options = array() ) {
315
- $config = array(
316
- 'Version' => AI1WM_VERSION,
317
- 'SiteURL' => site_url(),
318
- 'HomeURL' => home_url(),
319
- 'Domain' => parse_url( home_url(), PHP_URL_HOST ),
320
- );
321
-
322
- return json_encode( $config );
323
}
324
325
/**
326
- * Get available plugins
327
*
328
- * @param array $exclude Exclude plugins
329
- * @return array List of installed plugins
330
*/
331
- public function get_plugins( $exclude = array() ) {
332
- if ( ! function_exists( 'get_plugins' ) ) {
333
- require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
334
- }
335
-
336
- $plugins = array();
337
- foreach ( get_plugins() as $key => $plugin ) {
338
- $directory = dirname( $key );
339
- if ( $directory !== '.' && ! in_array( $directory, $exclude ) ) {
340
- $plugins[] = $directory;
341
- }
342
- }
343
-
344
- return $plugins;
345
}
346
}
25
26
class Ai1wm_Export
27
{
28
+ protected $options = array();
29
+
30
+ public function __construct( array $options = array() ) {
31
+ $this->options = $options;
32
+ }
33
34
/**
35
+ * Export site
36
*
37
+ * @return StorageFile
38
*/
39
+ public function export() {
40
+ $storage = StorageArea::getInstance();
41
42
+ // Enable maintenance mode
43
+ Ai1wm_Maintenance::enable();
44
45
+ // Create export file
46
+ $export_file = $storage->makeFile();
47
48
+ // Make archive file
49
try {
50
+ $zip = ZipFactory::makeZipArchiver( $export_file->getName(), ! class_exists( 'ZipArchive' ), true );
51
} catch ( Exception $e ) {
52
+ $zip = ZipFactory::makeZipArchiver( $export_file->getName(), true, true );
53
}
54
55
+ // Package
56
+ if ( $this->should_export_package() ) {
57
+ $service = new Ai1wm_Service_Package( $this->options );
58
+ $zip->addFromString( AI1WM_PACKAGE_NAME, $service->export() );
59
}
60
61
+ // Database
62
+ if ( $this->should_export_database() ) {
63
+ $service = new Ai1wm_Service_Database( $this->options );
64
65
+ // Add database to archive
66
+ $zip->addFile( $service->export(), AI1WM_DATABASE_NAME );
67
}
68
69
+ // Media
70
+ if ( $this->should_export_media() ) {
71
+ $service = new Ai1wm_Service_Media( $this->options );
72
73
+ // Add media to archive
74
+ $zip->addDir( $service->export(), AI1WM_MEDIA_NAME );
75
76
+ // Sites (Network mode)
77
+ $service = new Ai1wm_Service_Sites( $this->options );
78
+ if ( ( $sites = $service->export() ) ) {
79
+ // Add sites to archive
80
+ $zip->addDir( $sites, AI1WM_SITES_NAME );
81
+ }
82
}
83
84
+ // Themes
85
+ if ( $this->should_export_themes() ) {
86
+ $service = new Ai1wm_Service_Themes( $this->options );
87
88
+ // Add themes to archive
89
+ $zip->addDir( $service->export(), AI1WM_THEMES_NAME );
90
}
91
92
+ // Plugins
93
+ if ( $this->should_export_plugins() ) {
94
+ $service = new Ai1wm_Service_Plugins( $this->options );
95
96
+ // Add plugins to archive
97
+ if ( ( $plugins = $service->get_installed_plugins() ) ) {
98
+ $zip->addDir( $service->export(), AI1WM_PLUGINS_NAME, $plugins );
99
}
100
}
101
102
+ // Disable maintenance mode
103
+ Ai1wm_Maintenance::disable();
104
105
+ return $export_file;
106
}
107
108
/**
109
+ * Should export package?
110
*
111
+ * @return boolean
112
*/
113
+ public function should_export_package() {
114
+ return true;
115
}
116
117
/**
118
+ * Should export database?
119
*
120
+ * @return boolean
121
*/
122
+ public function should_export_database() {
123
+ return ! isset( $this->options['export-database'] );
124
}
125
126
/**
127
+ * Should export media?
128
*
129
+ * @return boolean
130
*/
131
+ public function should_export_media() {
132
+ return ! isset( $this->options['export-media'] );
133
}
134
135
/**
136
+ * Should export themes?
137
*
138
+ * @return boolean
139
*/
140
+ public function should_export_themes() {
141
+ return ! isset( $this->options['export-themes'] );
142
}
143
144
/**
145
+ * Should export plugins?
146
*
147
+ * @return boolean
148
*/
149
+ public function should_export_plugins() {
150
+ return ! isset( $this->options['export-plugins'] );
151
}
152
}
lib/model/class-ai1wm-feedback.php CHANGED
@@ -25,20 +25,22 @@
25
26
class Ai1wm_Feedback
27
{
28
-
29
/**
30
* Submit customer feedback to ServMask.com
31
*
32
* @param string $email User E-mail
33
* @param string $message User Message
34
* @param integer $terms User Accept Terms
35
- * @return void
36
*/
37
- public function leave_feedback( $email, $message, $terms ) {
38
$errors = array();
39
40
// Submit feedback to ServMask
41
- if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
42
$errors[] = 'Your email is not valid.';
43
} else if ( empty( $message ) ) {
44
$errors[] = 'Please enter comments in the text area.';
@@ -49,18 +51,18 @@ class Ai1wm_Feedback
49
AI1WM_FEEDBACK_URL,
50
array(
51
'body' => array(
52
'email' => $email,
53
'message' => $message,
54
- 'export_last_options' => json_encode( get_option( Ai1wm_Export::EXPORT_LAST_OPTIONS, array() ) ),
55
- 'error_handler' => json_encode( get_option( Ai1wm_Error::ERROR_HANDLER, array() ) ),
56
- 'exception_handler' => json_encode( get_option( Ai1wm_Error::EXCEPTION_HANDLER, array() ) ),
57
),
58
)
59
);
60
61
if ( is_wp_error( $response ) ) {
62
- $errors[] = 'Something went wrong: ' .
63
- $response->get_error_message();
64
}
65
}
66
25
26
class Ai1wm_Feedback
27
{
28
/**
29
* Submit customer feedback to ServMask.com
30
*
31
+ * @param string $type Feedback Type
32
* @param string $email User E-mail
33
* @param string $message User Message
34
* @param integer $terms User Accept Terms
35
+ * @return array
36
*/
37
+ public function leave_feedback( $type, $email, $message, $terms ) {
38
$errors = array();
39
40
// Submit feedback to ServMask
41
+ if ( empty( $type ) ) {
42
+ $errors[] = 'Feedback type is invalid.';
43
+ } else if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
44
$errors[] = 'Your email is not valid.';
45
} else if ( empty( $message ) ) {
46
$errors[] = 'Please enter comments in the text area.';
51
AI1WM_FEEDBACK_URL,
52
array(
53
'body' => array(
54
+ 'type' => $type,
55
'email' => $email,
56
'message' => $message,
57
+ 'export_options' => json_encode( get_option( AI1WM_EXPORT_OPTIONS, array() ) ),
58
+ 'error_handler' => json_encode( get_option( AI1WM_ERROR_HANDLER, array() ) ),
59
+ 'exception_handler' => json_encode( get_option( AI1WM_EXCEPTION_HANDLER, array() ) ),
60
),
61
)
62
);
63
64
if ( is_wp_error( $response ) ) {
65
+ $errors[] = 'Something went wrong: ' . $response->get_error_message();
66
}
67
}
68
lib/model/class-ai1wm-file.php DELETED
@@ -1,123 +0,0 @@
1
- <?php
2
- /**
3
- * Copyright (C) 2014 ServMask Inc.
4
- *
5
- * This program is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- *
18
- * ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
19
- * ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
20
- * ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
21
- * ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
22
- * ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
23
- * ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
24
- */
25
-
26
- class Ai1wm_File
27
- {
28
-
29
- /**
30
- * Replace a file, line by line with the str pattern and then writes the
31
- * output to a new file.
32
- *
33
- * @param StorageArea $storage Storage instance
34
- * @param StorageFile $file StorageFile instance
35
- * @param mixed $pattern Find and replace pattern
36
- * @param mixed $replacement Replace term
37
- * @return StorageFile StorageFile instance
38
- */
39
- public function str_replace_file( StorageArea $storage, StorageFile $file, $pattern, $replacement ) {
40
- $new_file = $storage->makeFile();
41
- $current_file = $file->getAs( 'resource' );
42
-
43
- while ( ! feof( $current_file ) ) {
44
- $line = stream_get_line( $current_file, 1000000, "\n" );
45
-
46
- // Append new line at the end of the line
47
- if ( strlen( $line ) < 1000000 && ! feof( $current_file ) ) {
48
- $line .= "\n";
49
- }
50
-
51
- if ( false === fwrite( $new_file->getAs( 'resource' ), str_replace( $pattern, $replacement, $line ) ) ) {
52
- wp_die(
53
- 'Writting to a file failed! Probably, there is no more free space left?',
54
- 'Out of disk space'
55
- );
56
- }
57
- }
58
-
59
- return $new_file;
60
- }
61
-
62
- /**
63
- * Replace a file, line by line with the regex pattern and then writes the
64
- * output to a new file.
65
- *
66
- * @param StorageArea $storage Storage instance
67
- * @param StorageFile $file StorageFile instance
68
- * @param string $pattern Find and replace pattern
69
- * @return StorageFile StorageFile instance
70
- */
71
- public function preg_replace_file( StorageArea $storage, StorageFile $file, $pattern ) {
72
- $new_file = $storage->makeFile();
73
- $current_file = $file->getAs( 'resource' );
74
-
75
- // Set file handle to the beginning of the file
76
- rewind( $current_file );
77
-
78
- while ( ! feof( $current_file ) ) {
79
- $line = stream_get_line( $current_file, 1000000, "\n" );
80
-
81
- // Append new line at the end of the line
82
- if ( strlen( $line ) < 1000000 && ! feof( $current_file ) ) {
83
- $line .= "\n";
84
- }
85
-
86
- $replaced = $this->_preg_replace( $line, $pattern );
87
- if ( false === fwrite( $new_file->getAs( 'resource' ), $replaced ) ) {
88
- wp_die(
89
- 'Writting to a file failed! Probably, there is no more free space left?',
90
- 'Out of disk space'
91
- );
92
- }
93
- }
94
-
95
- return $new_file;
96
- }
97
-
98
- /**
99
- * Find and replace line by line with pattern
100
- *
101
- * @param string $line Line to replace
102
- * @param string $pattern Pattern
103
- * @return string New line
104
- */
105
- public function _preg_replace( $line, $pattern ) {
106
- // PHP doesn't garbage collect functions created by create_function()
107
- static $callback = null;
108
-
109
- if ( $callback === null ) {
110
- $callback = create_function(
111
- '$matches',
112
- "return isset(\$matches[3]) ? 's:' .
113
- strlen( Ai1wm_Export::unescape_mysql( \$matches[3] ) ) .
114
- ':\"'.
115
- Ai1wm_Export::unescape_quotes( \$matches[3] ) .
116
- '\";' : \$matches[0];
117
- "
118
- );
119
- }
120
-
121
- return preg_replace_callback( $pattern, $callback, $line );
122
- }
123
- }
lib/model/class-ai1wm-import.php CHANGED
@@ -25,339 +25,180 @@
25
26
class Ai1wm_Import
27
{
28
- const MAX_FILE_SIZE = '512MB';
29
- const MAX_CHUNK_SIZE = '500KB';
30
- const MAX_CHUNK_RETRIES = 100;
31
- const MAINTENANCE_MODE = 'ai1wm_maintenance_mode';
32
33
/**
34
- * Import archive file (database, media, package.json)
35
*
36
- * @param array $input_file Upload file parameters
37
- * @param array $options Additional upload settings
38
- * @return array List of messages
39
*/
40
- public function import( $input_file, $options = array() ) {
41
- global $wpdb;
42
- $errors = array();
43
-
44
- if ( empty( $input_file['error'] ) ) {
45
- try {
46
- $storage = new StorageArea;
47
48
- // Flush storage directory
49
- if ( $options['chunk'] === 0 ) {
50
- StorageDirectory::flush( AI1WM_STORAGE_PATH, array( '.gitignore' ) );
51
- }
52
53
- // Partial file path
54
- $upload_file = $storage->makeFile( $options['name'] )->getAs( 'string' );
55
56
- // Open partial file
57
- $out = fopen( $upload_file, $options['chunk'] == 0 ? 'wb' : 'ab' );
58
- if ( $out ) {
59
- // Read binary input stream and append it to temp file
60
- $in = fopen( $input_file['tmp_name'], 'rb' );
61
- if ( $in ) {
62
- while ( $buff = fread( $in, 4096 ) ) {
63
- fwrite( $out, $buff );
64
- }
65
- }
66
-
67
- fclose( $in );
68
- fclose( $out );
69
-
70
- // Remove temporary uploaded file
71
- unlink( $input_file['tmp_name'] );
72
- } else {
73
- $errors[] = sprintf(
74
- _(
75
- 'Site could not be imported!<br />
76
- Please make sure that storage directory <strong>%s</strong> has read and write permissions.'
77
- ),
78
- AI1WM_STORAGE_PATH
79
- );
80
-
81
- // Clear storage
82
- $storage->flush();
83
- }
84
} catch ( Exception $e ) {
85
- $errors[] = sprintf(
86
- _(
87
- 'Site could not be imported!<br />
88
- Please make sure that storage directory <strong>%s</strong> has read and write permissions.'
89
- ),
90
- AI1WM_STORAGE_PATH
91
- );
92
-
93
- // Clear storage
94
- $storage->flush();
95
}
96
97
- // Check if file has been uploaded
98
- if ( empty( $errors ) && ( ! $options['chunks'] || $options['chunk'] == $options['chunks'] - 1 ) ) {
99
- // Create temporary directory
100
- $extract_to = $storage->makeDirectory()->getAs( 'string' );
101
-
102
- // Extract archive to a temporary directory
103
- try {
104
- try {
105
- $archive = ZipFactory::makeZipArchiver( $upload_file, ! class_exists( 'ZipArchive' ) );
106
- $archive->extractTo( $extract_to );
107
- $archive->close();
108
- } catch ( Exception $e ) {
109
- $archive = ZipFactory::makeZipArchiver( $upload_file, true );
110
- $archive->extractTo( $extract_to );
111
- $archive->close();
112
- }
113
- } catch ( Exception $e ) {
114
- $errors[] = _(
115
- 'Archive file is broken or is not compatible with
116
- "All In One WP Migration" plugin! Please verify your archive file.'
117
- );
118
- }
119
-
120
- if ( empty( $errors ) ) {
121
- // Verify whether this archive is valid
122
- if ( $this->is_valid( $extract_to ) ) {
123
- // Enable maintenance mode
124
- $this->maintenance_mode( true );
125
-
126
- // Parse package config file
127
- $config = $this->parse_package( $extract_to . Ai1wm_Export::EXPORT_PACKAGE_NAME );
128
-
129
- // Database import
130
- if ( is_file( $extract_to . Ai1wm_Export::EXPORT_DATABASE_NAME ) ) {
131
- // Backup database
132
- $model = new Ai1wm_Export;
133
- $database_file = $model->prepare_database( $storage );
134
-
135
- try {
136
- $db = MysqlDumpFactory::makeMysqlDump(
137
- DB_HOST,
138
- DB_USER,
139
- DB_PASSWORD,
140
- DB_NAME,
141
- (
142
- class_exists(
143
- 'PDO'
144
- ) && in_array( 'mysql', PDO::getAvailableDrivers() )
145
- )
146
- );
147
- $db->getConnection();
148
- } catch ( Exception $e ) {
149
- // Use "old" mysql adapter
150
- $db = MysqlDumpFactory::makeMysqlDump( DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, false );
151
- }
152
-
153
- // Flush database
154
- $db->flush();
155
-
156
- $old_values = array();
157
- $new_values = array();
158
-
159
- // Get Site URL
160
- if ( isset( $config['SiteURL'] ) && ( $config['SiteURL'] != site_url() ) ) {
161
- $old_values[] = $config['SiteURL'];
162
- $new_values[] = site_url();
163
- }
164
-
165
- // Get Home URL
166
- if ( isset( $config['HomeURL'] ) && ( $config['HomeURL'] != home_url() ) ) {
167
- $old_values[] = $config['HomeURL'];
168
- $new_values[] = home_url();
169
- }
170
-
171
- // Get Domain
172
- if ( isset( $config['Domain'] ) && ( $config['Domain'] != ( $domain = parse_url( home_url(), PHP_URL_HOST ) ) ) ) {
173
- $old_values[] = $config['Domain'];
174
- $new_values[] = $domain;
175
- }
176
-
177
- $file = new Ai1wm_File;
178
- $database_file = $storage->makeFile( Ai1wm_Export::EXPORT_DATABASE_NAME, $extract_to );
179
-
180
- // Replace Old/New Values
181
- if ( $old_values && $new_values ) {
182
- $database_file = $file->str_replace_file(
183
- $storage,
184
- $database_file,
185
- $old_values,
186
- $new_values
187
- );
188
-
189
- $database_file = $file->preg_replace_file(
190
- $storage,
191
- $database_file,
192
- '/s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");/'
193
- );
194
- }
195
-
196
- // Import database
197
- $db->setOldTablePrefix( AI1WM_TABLE_PREFIX )
198
- ->setNewTablePrefix( $wpdb->prefix )
199
- ->import( $database_file->getAs( 'string' ) );
200
- }
201
-
202
- // Media import
203
- if ( is_dir( $extract_to . Ai1wm_Export::EXPORT_MEDIA_NAME ) ) {
204
- // Media base directory
205
- $upload_dir = wp_upload_dir();
206
- $upload_basedir = $upload_dir['basedir'] . DIRECTORY_SEPARATOR;
207
- if ( ! is_dir( $upload_basedir ) ) {
208
- mkdir( $upload_basedir );
209
- }
210
-
211
- // Backup media files
212
- $backup_media_to = $storage->makeDirectory()->getAs( 'string' );
213
214
- StorageDirectory::copy( $upload_basedir, $backup_media_to );
215
216
- // Flush media files
217
- StorageDirectory::flush( $upload_basedir );
218
219
- // Import media files
220
- StorageDirectory::copy( $extract_to . Ai1wm_Export::EXPORT_MEDIA_NAME, $upload_basedir );
221
- }
222
223
- // Themes import
224
- if ( is_dir( $extract_to . Ai1wm_Export::EXPORT_THEMES_NAME ) ) {
225
- // Themes base directory
226
- $themes_dir = get_theme_root();
227
- $themes_basedir = $themes_dir . DIRECTORY_SEPARATOR;
228
- if ( ! is_dir( $themes_basedir ) ) {
229
- mkdir( $themes_basedir );
230
- }
231
232
- // Backup themes files
233
- $backup_themes_to = $storage->makeDirectory()->getAs( 'string' );
234
235
- StorageDirectory::copy( $themes_basedir, $backup_themes_to );
236
237
- // Flush themes files
238
- StorageDirectory::flush( $themes_basedir );
239
240
- // Import themes files
241
- StorageDirectory::copy( $extract_to . Ai1wm_Export::EXPORT_THEMES_NAME, $themes_basedir );
242
- }
243
244
- // Plugins import
245
- if ( is_dir( $extract_to . Ai1wm_Export::EXPORT_PLUGINS_NAME ) ) {
246
- // Backup plugin files
247
- $backup_plugins_to = $storage->makeDirectory()->getAs( 'string' );
248
249
- StorageDirectory::copy( WP_PLUGIN_DIR, $backup_plugins_to, array( AI1WM_PLUGIN_NAME ) );
250
251
- // Flush plugin files
252
- StorageDirectory::flush( WP_PLUGIN_DIR, array( AI1WM_PLUGIN_NAME ) );
253
254
- // Import plugin files
255
- StorageDirectory::copy( $extract_to . Ai1wm_Export::EXPORT_PLUGINS_NAME, WP_PLUGIN_DIR );
256
- }
257
258
- // Disable maintenance mode
259
- $this->maintenance_mode( false );
260
- } else {
261
- $errors[] = _( 'File is not compatible with "All In One WP Migration" plugin! Please verify your archive file.' );
262
- }
263
- }
264
265
- // Clear storage
266
- $storage->flush();
267
- }
268
} else {
269
- $errors[] = $this->code_to_message( $input_file['error'] );
270
}
271
-
272
- return array( 'errors' => $errors );
273
}
274
275
-
276
/**
277
- * Enable or disable WordPress maintenance mode
278
*
279
- * @param boolean $enabled Enable or disable maintenance mode
280
- * @return boolean True if option value has changed, false if not or if update failed
281
*/
282
- public function maintenance_mode( $enabled = true ) {
283
- return update_option( self::MAINTENANCE_MODE, $enabled );
284
}
285
286
/**
287
- * Verify whether directory contains necessary archive files
288
*
289
- * @param string $path Archive path
290
- * @return boolean Compatible archive
291
*/
292
- public function is_valid( $path ) {
293
- $required_objects = array(
294
- Ai1wm_Export::EXPORT_PACKAGE_NAME,
295
- );
296
-
297
- // Verify whether file or directory exist
298
- foreach ( $required_objects as $object ) {
299
- if ( ! file_exists( $path . $object ) ) {
300
- return false;
301
- }
302
- }
303
-
304
- return true;
305
}
306
307
/**
308
- * Parse package config file
309
*
310
- * @param string $file Path to package config file
311
- * @return array Config parameters
312
*/
313
- public function parse_package( $file ) {
314
- // Get config file
315
- $data = file_get_contents( $file );
316
-
317
- return json_decode( $data, true );
318
}
319
320
/**
321
- * Display message for upload error code
322
*
323
- * @param integer $code Upload error code
324
- * @return string Error message
325
*/
326
- public function code_to_message( $code ) {
327
- switch ( $code ) {
328
- case UPLOAD_ERR_INI_SIZE:
329
- $message = _( 'The uploaded file exceeds the upload_max_filesize directive in php.ini' );
330
- break;
331
-
332
- case UPLOAD_ERR_FORM_SIZE:
333
- $message = _( 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form' );
334
- break;
335
-
336
- case UPLOAD_ERR_PARTIAL:
337
- $message = _( 'The uploaded file was only partially uploaded' );
338
- break;
339
-
340
- case UPLOAD_ERR_NO_FILE:
341
- $message = _( 'No file was uploaded' );
342
- break;
343
-
344
- case UPLOAD_ERR_NO_TMP_DIR:
345
- $message = _( 'Missing a temporary folder' );
346
- break;
347
-
348
- case UPLOAD_ERR_CANT_WRITE:
349
- $message = _( 'Failed to write file to disk' );
350
- break;
351
-
352
- case UPLOAD_ERR_EXTENSION:
353
- $message = _( 'File upload stopped by extension' );
354
- break;
355
-
356
- default:
357
- $message = _( 'Unknown upload error' );
358
- break;
359
- }
360
361
- return $message;
362
}
363
}
25
26
class Ai1wm_Import
27
{
28
+ protected $options = array();
29
+
30
+ public function __construct( array $options = array() ) {
31
+ $this->options = $options;
32
+ }
33
34
/**
35
+ * Import site
36
*
37
+ * @return StorageFile
38
*/
39
+ public function import() {
40
+ global $wp_version;
41
42
+ $storage = StorageArea::getInstance();
43
44
+ // Create import file
45
+ $import_file = $storage->makeFile( $this->options['import']['file'] );
46
47
+ // Extract archive
48
+ try {
49
+ try {
50
+ $zip = ZipFactory::makeZipArchiver( $import_file->getName(), ! class_exists( 'ZipArchive' ) );
51
+ $zip->extractTo( $storage->getRootPath() );
52
+ $zip->close();
53
} catch ( Exception $e ) {
54
+ $zip = ZipFactory::makeZipArchiver( $import_file->getName(), true );
55
+ $zip->extractTo( $storage->getRootPath() );
56
+ $zip->close();
57
}
58
+ } catch ( Exception $e ) {
59
+ throw new Ai1wm_Import_Exception(
60
+ _(
61
+ 'Site could not be imported!<br />' .
62
+ 'Archive file is broken or is not compatible with the plugin! Please verify your archive file.'
63
+ )
64
+ );
65
+ }
66
67
+ // Verify package
68
+ if ( $this->should_import_package() ) {
69
70
+ // Enable maintenance mode
71
+ Ai1wm_Maintenance::enable();
72
73
+ // Database
74
+ if ( $this->should_import_database() ) {
75
+ $service = new Ai1wm_Service_Database( $this->options );
76
+ $service->import();
77
+ }
78
79
+ // Media
80
+ if ( $this->should_import_media() ) {
81
+ $service = new Ai1wm_Service_Media( $this->options );
82
+ $service->import();
83
+ }
84
85
+ // Sites (Network mode)
86
+ if ( $this->should_import_sites() ) {
87
+ $service = new Ai1wm_Service_Sites( $this->options );
88
+ $service->import();
89
+ }
90
91
+ // Themes
92
+ if ( $this->should_import_themes() ) {
93
+ $service = new Ai1wm_Service_Themes( $this->options );
94
+ $service->import();
95
+ }
96
97
+ // Plugins
98
+ if ( $this->should_import_plugins() ) {
99
+ $service = new Ai1wm_Service_Plugins( $this->options );
100
+ $service->import();
101
+ }
102
103
+ // Disable maintenance mode
104
+ Ai1wm_Maintenance::disable();
105
106
+ } else {
107
+ throw new Ai1wm_Import_Exception(
108
+ _(
109
+ 'Site could not be imported!<br />' .
110
+ 'Archive file is not compatible with the plugin! Please verify your archive file.'
111
+ )
112
+ );
113
+ }
114
115
+ return $import_file;
116
+ }
117
118
+ /**
119
+ * Should import package?
120
+ *
121
+ * @return boolean
122
+ */
123
+ public function should_import_package() {
124
+ global $wp_version;
125
126
+ // Has package.json file?
127
+ if ( ! is_file( StorageArea::getInstance()->getRootPath() . AI1WM_PACKAGE_NAME ) ) {
128
+ return false;
129
+ }
130
131
+ // Force import
132
+ if ( isset( $this->options['import']['force'] ) ) {
133
+ return true;
134
+ }
135
136
+ // Get configuration
137
+ $service = new Ai1wm_Service_Package( $this->options );
138
+ $config = $service->import();
139
140
+ // Verify WordPress version
141
+ if ( version_compare( $config['WordPress']['Version'], $wp_version, '<=' ) ) {
142
+ return true;
143
} else {
144
+ throw new Ai1wm_Import_Exception(
145
+ sprintf(
146
+ _(
147
+ 'You are trying to import data from WordPress v%1$s into WordPress v%2$s, while the process might work,' .
148
+ 'we do not recommend this. You should update your WordPress to version %1$s or above and then import the file.' .
149
+ 'If you still want to proceed, after making a backup, using the plugin,' .
150
+ '<button type="button" class="ai1wm-button-green-small" id="ai1wm-force-import" data-name="%3$s">CLICK HERE TO CONTINUE</button>'
151
+ ),
152
+ $config['WordPress']['Version'],
153
+ $wp_version,
154
+ $this->options['import']['file']
155
+ )
156
+ );
157
}
158
}
159
160
/**
161
+ * Should import database?
162
*
163
+ * @return boolean
164
*/
165
+ public function should_import_database() {
166
+ return is_file( StorageArea::getInstance()->getRootPath() . AI1WM_DATABASE_NAME );
167
}
168
169
/**
170
+ * Should import media?
171
*
172
+ * @return boolean
173
*/
174
+ public function should_import_media() {
175
+ return is_dir( StorageArea::getInstance()->getRootPath() . AI1WM_MEDIA_NAME );
176
}
177
178
/**
179
+ * Should import sites?
180
*
181
+ * @return boolean
182
*/
183
+ public function should_import_sites() {
184
+ return is_dir( StorageArea::getInstance()->getRootPath() . AI1WM_SITES_NAME );
185
}
186
187
/**
188
+ * Should import themes?
189
*
190
+ * @return boolean
191
*/
192
+ public function should_import_themes() {
193
+ return is_dir( StorageArea::getInstance()->getRootPath() . AI1WM_THEMES_NAME );
194
+ }
195
196
+ /**
197
+ * Should import plugins?
198
+ *
199
+ * @return boolean
200
+ */
201
+ public function should_import_plugins() {
202
+ return is_dir( StorageArea::getInstance()->getRootPath() . AI1WM_PLUGINS_NAME );
203
}
204
}
{trunk/lib → lib}/model/class-ai1wm-logger.php RENAMED
File without changes
{trunk/lib → lib}/model/class-ai1wm-maintenance.php RENAMED
File without changes
lib/model/class-ai1wm-message.php CHANGED
@@ -25,38 +25,70 @@
25
26
class Ai1wm_Message
27
{
28
- const MESSAGE_INFO = 'info';
29
- const MESSAGE_INFO_CLOSE = 'ai1wm_message_info_close';
30
31
/**
32
- * Close message dialog by type
33
*
34
- * @param string $type Type of message
35
* @return array
36
*/
37
- public function close_message( $type ) {
38
- $errors = array();
39
-
40
- if ( $type == self::MESSAGE_INFO ) {
41
- update_option( self::MESSAGE_INFO_CLOSE, true );
42
- } else {
43
- $errors[] = 'Unregonized message type.';
44
}
45
46
- return array( 'errors' => $errors );
47
}
48
49
/**
50
- * Is message dialog closed
51
*
52
- * @param string $type Type of message
53
- * @return boolean
54
*/
55
- public function is_closed( $type ) {
56
- if ( $type == self::MESSAGE_INFO ) {
57
- return get_option( self::MESSAGE_INFO_CLOSE );
58
}
59
60
- return false;
61
}
62
}
25
26
class Ai1wm_Message
27
{
28
+ protected $messages = array();
29
+
30
+ public function __construct() {
31
+ $this->messages = array(
32
+ 'SiteURLDepricated' => _(
33
+ 'Since version 1.8.0, Site URL is deprecated.' .
34
+ 'Upon import, the plugin auto-detects Site URL and makes necessary changes to the database.'
35
+ ),
36
+ );
37
+
38
+ // Prepare messages
39
+ $msgs = array();
40
+ $keys = get_option( AI1WM_MESSAGES );
41
+ foreach ( array_keys( $this->messages ) as $key ) {
42
+ if ( ! isset( $keys[$key] ) ) {
43
+ $msgs[$key] = true;
44
+ }
45
+ }
46
+
47
+ // Update messages
48
+ if ( $msgs ) {
49
+ update_option( AI1WM_MESSAGES, $msgs );
50
+ }
51
+ }
52
53
/**
54
+ * Get list of all active messages
55
*
56
* @return array
57
*/
58
+ public function get_messages() {
59
+ $msgs = array();
60
+ $keys = get_option( AI1WM_MESSAGES );
61
+ foreach ( $keys as $key => $active ) {
62
+ if ( isset( $this->messages[$key] ) && $active ) {
63
+ $msgs[$key] = $this->messages[$key];
64
+ }
65
}
66
67
+ return $msgs;
68
}
69
70
/**
71
+ * Close message by key
72
*
73
+ * @param string $key Message key
74
+ * @return array
75
*/
76
+ public function close_message( $key ) {
77
+ $errors = array();
78
+
79
+ $keys = get_option( AI1WM_MESSAGES );
80
+ if ( isset( $keys[$key] ) ) {
81
+ // Deactivate message from the list
82
+ $keys[$key] = false;
83
+
84
+ // Update keys
85
+ if ( ! update_option( AI1WM_MESSAGES, $keys ) ) {
86
+ $errors[] = 'Something went wrong! Please try again later.';
87
+ }
88
+ } else {
89
+ $errors[] = 'Message key does not exist in the list.';
90
}
91
92
+ return array( 'errors' => $errors );
93
}
94
}
lib/model/class-ai1wm-report.php CHANGED
@@ -25,14 +25,13 @@
25
26
class Ai1wm_Report
27
{
28
-
29
/**
30
* Submit customer report to ServMask.com
31
*
32
* @param string $email User E-mail
33
* @param string $message User Message
34
* @param integer $terms User Accept Terms
35
- * @return void
36
*/
37
public function report_problem( $email, $message, $terms ) {
38
$errors = array();
@@ -51,16 +50,15 @@ class Ai1wm_Report
51
'body' => array(
52
'email' => $email,
53
'message' => $message,
54
- 'export_last_options' => json_encode( get_option( Ai1wm_Export::EXPORT_LAST_OPTIONS, array() ) ),
55
- 'error_handler' => json_encode( get_option( Ai1wm_Error::ERROR_HANDLER, array() ) ),
56
- 'exception_handler' => json_encode( get_option( Ai1wm_Error::EXCEPTION_HANDLER, array() ) ),
57
),
58
)
59
);
60
61
if ( is_wp_error( $response ) ) {
62
- $errors[] = 'Something went wrong: ' .
63
- $response->get_error_message();
64
}
65
}
66
25
26
class Ai1wm_Report
27
{
28
/**
29
* Submit customer report to ServMask.com
30
*
31
* @param string $email User E-mail
32
* @param string $message User Message
33
* @param integer $terms User Accept Terms
34
+ * @return array
35
*/
36
public function report_problem( $email, $message, $terms ) {
37
$errors = array();
50
'body' => array(
51
'email' => $email,
52
'message' => $message,
53
+ 'export_options' => json_encode( get_option( AI1WM_EXPORT_OPTIONS, array() ) ),
54
+ 'error_handler' => json_encode( get_option( AI1WM_ERROR_HANDLER, array() ) ),
55
+ 'exception_handler' => json_encode( get_option( AI1WM_EXCEPTION_HANDLER, array() ) ),
56
),
57
)
58
);
59
60
if ( is_wp_error( $response ) ) {
61
+ $errors[] = 'Something went wrong: ' . $response->get_error_message();
62
}
63
}
64
lib/model/class-ai1wm-template.php CHANGED
@@ -28,8 +28,8 @@ class Ai1wm_Template extends Bandar
28
/**
29
* Renders a file and returns its contents bacl
30
* @param string $file View to render
31
- * @param [type] $args [description]
32
- * @return [type] [description]
33
*/
34
public static function render( $view, $args = array() ) {
35
parent::render( $view, $args );
28
/**
29
* Renders a file and returns its contents bacl
30
* @param string $file View to render
31
+ * @param array $args Set of arguments
32
+ * @return string Rendered view
33
*/
34
public static function render( $view, $args = array() ) {
35
parent::render( $view, $args );
{trunk/lib → lib}/model/service/class-ai1wm-service-database.php RENAMED
File without changes
{trunk/lib → lib}/model/service/class-ai1wm-service-interface.php RENAMED
File without changes
{trunk/lib → lib}/model/service/class-ai1wm-service-media.php RENAMED
File without changes
{trunk/lib → lib}/model/service/class-ai1wm-service-package.php RENAMED
File without changes
{trunk/lib → lib}/model/service/class-ai1wm-service-plugins.php RENAMED
File without changes