All-in-One WP Migration - Version 1.7.0

Version Description

  • Added storage layer to avoid permission issues with OS's directory used for temporary storage
  • Added additional checks to verify the consistency of the imported archive
  • Fixed a bug that caused the database to be exported without data
  • Removed unused variables from package.json file
Download this release

Release Info

Developer bangelov
Plugin Icon 128x128 All-in-One WP Migration
Version 1.7.0
Comparing to
See all releases

Code changes from version 1.6.0 to 1.7.0

Files changed (29) hide show
  1. all-in-one-wp-migration.php +1 -1
  2. constants.php +11 -1
  3. lib/controller/class-ai1wm-export-controller.php +15 -8
  4. lib/controller/class-ai1wm-import-controller.php +9 -2
  5. lib/model/class-ai1wm-export.php +57 -41
  6. lib/model/class-ai1wm-file.php +37 -41
  7. lib/model/class-ai1wm-import.php +211 -147
  8. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpPDO.php +8 -5
  9. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpSQL.php +8 -5
  10. lib/vendor/storage-factory/storage-factory/.editorconfig +26 -0
  11. lib/vendor/storage-factory/storage-factory/.travil.yml +10 -0
  12. lib/vendor/storage-factory/storage-factory/LICENSE +20 -0
  13. lib/vendor/storage-factory/storage-factory/README.md +32 -0
  14. lib/vendor/storage-factory/storage-factory/bump-version.sh +63 -0
  15. lib/vendor/storage-factory/storage-factory/composer.json +25 -0
  16. lib/vendor/storage-factory/storage-factory/lib/StorageAbstract.php +89 -0
  17. lib/vendor/storage-factory/storage-factory/lib/StorageArea.php +89 -0
  18. lib/vendor/storage-factory/storage-factory/lib/StorageDirectory.php +109 -0
  19. lib/vendor/storage-factory/storage-factory/lib/StorageFile.php +85 -0
  20. lib/vendor/storage-factory/storage-factory/phpunit.xml +29 -0
  21. lib/vendor/storage-factory/storage-factory/test/bootstrap.php +40 -0
  22. lib/vendor/storage-factory/storage-factory/test/test-storage-factory.php +67 -0
  23. lib/vendor/zip-factory/zip-factory/lib/ArchiverPclZip.php +36 -14
  24. lib/vendor/zip-factory/zip-factory/lib/ArchiverZipArchive.php +17 -19
  25. lib/vendor/zip-factory/zip-factory/lib/ZipFactory.php +1 -1
  26. lib/view/export/index.php +3 -4
  27. lib/view/import/index.php +3 -4
  28. loader.php +11 -0
  29. readme.txt +9 -3
all-in-one-wp-migration.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: Migration tool for all your blog data
6
  * Author: ServMask
7
  * Author URI: http://servmask.com/
8
- * Version: 1.6.0
9
  *
10
  * Copyright (C) 2013 ServMask LLC
11
  *
5
  * Description: Migration tool for all your blog data
6
  * Author: ServMask
7
  * Author URI: http://servmask.com/
8
+ * Version: 1.7.0
9
  *
10
  * Copyright (C) 2013 ServMask LLC
11
  *
constants.php CHANGED
@@ -26,7 +26,7 @@
26
  // ==================
27
  // = Plugin VERSION =
28
  // ==================
29
- define( 'AI1WM_VERSION', '1.6.0' );
30
 
31
  // ===============
32
  // = Plugin Name =
@@ -43,6 +43,11 @@ define( 'AI1WM_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
43
  // ===============
44
  define( 'AI1WM_PATH', dirname( __FILE__ ) );
45
 
 
 
 
 
 
46
  // ============
47
  // = Lib Path =
48
  // ============
@@ -93,6 +98,11 @@ define( 'AI1WM_REPORT_URL', 'https://servmask.com/ai1wm/report/create' );
93
  // ==============
94
  define( 'AI1WM_TABLE_PREFIX', 'SERVMASK_PREFIX_' );
95
 
 
 
 
 
 
96
  // ===========================
97
  // = WP_CONTENT_DIR Constant =
98
  // ===========================
26
  // ==================
27
  // = Plugin VERSION =
28
  // ==================
29
+ define( 'AI1WM_VERSION', '1.7.0' );
30
 
31
  // ===============
32
  // = Plugin Name =
43
  // ===============
44
  define( 'AI1WM_PATH', dirname( __FILE__ ) );
45
 
46
+ // ===============
47
+ // = Storage Path =
48
+ // ===============
49
+ define( 'AI1WM_STORAGE_PATH', AI1WM_PATH . DIRECTORY_SEPARATOR . 'storage' );
50
+
51
  // ============
52
  // = Lib Path =
53
  // ============
98
  // ==============
99
  define( 'AI1WM_TABLE_PREFIX', 'SERVMASK_PREFIX_' );
100
 
101
+ // ==============
102
+ // = ServMask Storage Prefix =
103
+ // ==============
104
+ define( 'AI1WM_STORAGE_PREFIX', 'wm_' );
105
+
106
  // ===========================
107
  // = WP_CONTENT_DIR Constant =
108
  // ===========================
lib/controller/class-ai1wm-export-controller.php CHANGED
@@ -26,12 +26,19 @@
26
  class Ai1wm_Export_Controller
27
  {
28
  public static function index() {
29
- $temp_dir = sys_get_temp_dir();
 
 
 
 
 
 
 
30
  Ai1wm_Template::render(
31
  'export/index',
32
  array(
33
- 'list_plugins' => get_plugins(),
34
- 'temp_dir' => is_readable( $temp_dir ) && is_writable( $temp_dir ),
35
  )
36
  );
37
  }
@@ -43,11 +50,11 @@ class Ai1wm_Export_Controller
43
 
44
  // Get options
45
  if ( isset( $_POST['options'] ) && ( $options = $_POST['options'] ) ) {
46
- $output_file = tempnam( sys_get_temp_dir(), 'wm_' );
47
 
48
  // Export archive
49
  $model = new Ai1wm_Export;
50
- $file = $model->export( $output_file, $options );
51
 
52
  // Send the file to the user
53
  header( 'Content-Description: File Transfer' );
@@ -64,14 +71,14 @@ class Ai1wm_Export_Controller
64
  header( 'Expires: 0' );
65
  header( 'Cache-Control: must-revalidate' );
66
  header( 'Pragma: public' );
67
- header( 'Content-Length: ' . filesize( $file ) );
68
 
69
  // Clear output buffering and read file content
70
  if ( ob_get_length() > 0 ) {
71
  @ob_end_clean();
72
  }
73
- readfile( $file );
74
- @unlink( $file );
75
  exit;
76
  }
77
  }
26
  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
  Ai1wm_Template::render(
38
  'export/index',
39
  array(
40
+ 'list_plugins' => get_plugins(),
41
+ 'is_accessible' => $is_accessible,
42
  )
43
  );
44
  }
50
 
51
  // Get options
52
  if ( isset( $_POST['options'] ) && ( $options = $_POST['options'] ) ) {
53
+ $storage = new StorageArea;
54
 
55
  // Export archive
56
  $model = new Ai1wm_Export;
57
+ $file = $model->export( $storage, $options );
58
 
59
  // Send the file to the user
60
  header( 'Content-Description: File Transfer' );
71
  header( 'Expires: 0' );
72
  header( 'Cache-Control: must-revalidate' );
73
  header( 'Pragma: public' );
74
+ header( 'Content-Length: ' . filesize( $file->getAs( 'string' ) ) );
75
 
76
  // Clear output buffering and read file content
77
  if ( ob_get_length() > 0 ) {
78
  @ob_end_clean();
79
  }
80
+ readfile( $file->getAs( 'string' ) );
81
+ $storage->flush();
82
  exit;
83
  }
84
  }
lib/controller/class-ai1wm-import-controller.php CHANGED
@@ -26,11 +26,18 @@
26
  class Ai1wm_Import_Controller
27
  {
28
  public static function index() {
29
- $temp_dir = sys_get_temp_dir();
 
 
 
 
 
 
 
30
  Ai1wm_Template::render(
31
  'import/index',
32
  array(
33
- 'temp_dir' => is_readable( $temp_dir ) && is_writable( $temp_dir ),
34
  )
35
  );
36
  }
26
  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
+ }
36
+
37
  Ai1wm_Template::render(
38
  'import/index',
39
  array(
40
+ 'is_accessible' => $is_accessible,
41
  )
42
  );
43
  }
lib/model/class-ai1wm-export.php CHANGED
@@ -52,11 +52,11 @@ class Ai1wm_Export
52
  /**
53
  * Export archive file (database, media, package.json)
54
  *
55
- * @param resource $output_file Pointer to file resource
56
- * @param array $options Export settings
57
- * @return string Absolute file path
58
  */
59
- public function export( $output_file, array $options = array() ) {
60
  global $wp_version;
61
  $options['plugin_version'] = AI1WM_VERSION;
62
  $options['wp_version'] = $wp_version;
@@ -69,15 +69,20 @@ class Ai1wm_Export
69
  // Export last options
70
  update_option( self::EXPORT_LAST_OPTIONS, $options );
71
 
 
 
 
72
  // Make archive
73
- $archive = ZipFactory::makeZipArchiver( $output_file, ! class_exists( 'ZipArchive' ), true );
74
 
75
  // Should we export database?
76
- if ( ! isset( $options['export-database' ] ) ) {
77
- $database_file = tmpfile();
78
- $database_file = $this->prepare_database( $database_file, $options );
 
 
79
  $archive->addFile(
80
- $database_file,
81
  self::EXPORT_DATABASE_NAME
82
  );
83
  }
@@ -102,7 +107,8 @@ class Ai1wm_Export
102
  if ( ! isset( $options['export-plugins'] ) ) {
103
  $archive->addDir(
104
  $this->prepare_plugins( $options ),
105
- self::EXPORT_PLUGINS_NAME
 
106
  );
107
  }
108
 
@@ -112,20 +118,21 @@ class Ai1wm_Export
112
  $this->prepare_package( $options )
113
  );
114
 
115
- return $archive->getArchive();
116
  }
117
 
118
  /**
119
  * Export database in SQL format
120
  *
121
- * @param resource $output_file Pointer to file resource
122
- * @param array $options Export settings
123
- * @return string Absolute file path
124
  */
125
- public function prepare_database( $output_file, array $options = array() ) {
126
  global $wpdb;
127
 
128
- $_f = new Ai1wm_File();
 
129
 
130
  // Set include tables
131
  $includeTables = array();
@@ -163,16 +170,16 @@ class Ai1wm_Export
163
  }
164
 
165
  // No table data, but leave Administrator account unchanged
166
- if ( isset( $options['export-table-data'] ) ) {
 
 
167
  $clauses[ $wpdb->users ] = ' WHERE id = 1 ';
168
  $clauses[ $wpdb->usermeta ] = ' WHERE user_id = 1 ';
169
  }
170
 
171
- $output_meta = stream_get_meta_data( $output_file );
172
-
173
  // Set dump options
174
  $this->connection
175
- ->setFileName( $output_meta['uri'] )
176
  ->setIncludeTables( $includeTables )
177
  ->setExcludeTables( $excludeTables )
178
  ->setNoTableData( $noTableData )
@@ -184,10 +191,7 @@ class Ai1wm_Export
184
  $this->connection->dump();
185
 
186
  // Replace Old/New Values
187
- if (
188
- isset( $options['replace'] ) &&
189
- ( $replace = $options['replace'] )
190
- ) {
191
  $old_values = array();
192
  $new_values = array();
193
  for ( $i = 0; $i < count( $replace['old-value'] ); $i++ ) {
@@ -202,7 +206,8 @@ class Ai1wm_Export
202
  }
203
  // Do String Replacement
204
  if ( $old_values && $new_values ) {
205
- $output_file = $_f->str_replace_file(
 
206
  $output_file,
207
  $old_values,
208
  $new_values
@@ -210,7 +215,9 @@ class Ai1wm_Export
210
  }
211
  }
212
 
213
- return $_f->preg_replace_file(
 
 
214
  $output_file,
215
  '/s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");/'
216
  );
@@ -276,7 +283,6 @@ class Ai1wm_Export
276
  */
277
  public function prepare_plugins( array $options = array() ) {
278
  if ( ! isset( $options['export-plugins'] ) ) {
279
-
280
  return WP_PLUGIN_DIR;
281
  }
282
  }
@@ -288,22 +294,32 @@ class Ai1wm_Export
288
  * @return string Package config
289
  */
290
  public function prepare_package( array $options = array() ) {
291
- $config = array();
292
-
293
- $config['Plugins'] = array();
294
- if ( ! isset( $options['export-plugins' ] ) ) {
295
- if ( isset( $options['include-plugins'] ) && ( $include_plugins = $options['include-plugins'] ) ) {
296
- foreach ( $include_plugins as $key => $plugin_name ) {
297
- $slug = current( explode( DIRECTORY_SEPARATOR, $key ) );
298
-
299
- $config['Plugins'][] = array(
300
- 'Name' => $plugin_name,
301
- 'Slug' => $slug,
302
- );
303
- }
 
 
 
 
 
 
 
 
 
 
304
  }
305
  }
306
 
307
- return json_encode( $config );
308
  }
309
  }
52
  /**
53
  * Export archive file (database, media, package.json)
54
  *
55
+ * @param StorageArea $storage Storage instance
56
+ * @param array $options Export settings
57
+ * @return StorageFile StorageFile instance
58
  */
59
+ public function export( StorageArea $storage, array $options = array() ) {
60
  global $wp_version;
61
  $options['plugin_version'] = AI1WM_VERSION;
62
  $options['wp_version'] = $wp_version;
69
  // Export last options
70
  update_option( self::EXPORT_LAST_OPTIONS, $options );
71
 
72
+ // Create output file
73
+ $output_file = $storage->makeFile();
74
+
75
  // Make archive
76
+ $archive = ZipFactory::makeZipArchiver( $output_file->getAs( 'resource' ), ! class_exists( 'ZipArchive' ), true );
77
 
78
  // Should we export database?
79
+ if ( ! isset( $options['export-database'] ) ) {
80
+ // Prepare database file
81
+ $database_file = $this->prepare_database( $storage, $options );
82
+
83
+ // Add database to archive
84
  $archive->addFile(
85
+ $database_file->getAs( 'resource' ),
86
  self::EXPORT_DATABASE_NAME
87
  );
88
  }
107
  if ( ! isset( $options['export-plugins'] ) ) {
108
  $archive->addDir(
109
  $this->prepare_plugins( $options ),
110
+ self::EXPORT_PLUGINS_NAME,
111
+ $this->get_plugins( array( AI1WM_PLUGIN_NAME ) )
112
  );
113
  }
114
 
118
  $this->prepare_package( $options )
119
  );
120
 
121
+ return $output_file;
122
  }
123
 
124
  /**
125
  * Export database in SQL format
126
  *
127
+ * @param StorageArea $storage Storage instance
128
+ * @param array $options Export settings
129
+ * @return StorageFile StorageFile instance
130
  */
131
+ public function prepare_database( StorageArea $storage, array $options = array() ) {
132
  global $wpdb;
133
 
134
+ $file = new Ai1wm_File;
135
+ $output_file = $storage->makeFile();
136
 
137
  // Set include tables
138
  $includeTables = array();
170
  }
171
 
172
  // No table data, but leave Administrator account unchanged
173
+ if ( $noTableData ) {
174
+ $clauses = array();
175
+ $clauses[ $wpdb->options ] = ' ORDER BY option_id ASC ';
176
  $clauses[ $wpdb->users ] = ' WHERE id = 1 ';
177
  $clauses[ $wpdb->usermeta ] = ' WHERE user_id = 1 ';
178
  }
179
 
 
 
180
  // Set dump options
181
  $this->connection
182
+ ->setFileName( $output_file->getAs( 'string' ) )
183
  ->setIncludeTables( $includeTables )
184
  ->setExcludeTables( $excludeTables )
185
  ->setNoTableData( $noTableData )
191
  $this->connection->dump();
192
 
193
  // Replace Old/New Values
194
+ if ( isset( $options['replace'] ) && ( $replace = $options['replace'] ) ) {
 
 
 
195
  $old_values = array();
196
  $new_values = array();
197
  for ( $i = 0; $i < count( $replace['old-value'] ); $i++ ) {
206
  }
207
  // Do String Replacement
208
  if ( $old_values && $new_values ) {
209
+ $output_file = $file->str_replace_file(
210
+ $storage,
211
  $output_file,
212
  $old_values,
213
  $new_values
215
  }
216
  }
217
 
218
+ // Do find and replace
219
+ return $file->preg_replace_file(
220
+ $storage,
221
  $output_file,
222
  '/s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");/'
223
  );
283
  */
284
  public function prepare_plugins( array $options = array() ) {
285
  if ( ! isset( $options['export-plugins'] ) ) {
 
286
  return WP_PLUGIN_DIR;
287
  }
288
  }
294
  * @return string Package config
295
  */
296
  public function prepare_package( array $options = array() ) {
297
+ $config = array(
298
+ 'Version' => AI1WM_VERSION,
299
+ );
300
+
301
+ return json_encode( $config );
302
+ }
303
+
304
+ /**
305
+ * Get available plugins
306
+ *
307
+ * @param array $exclude Exclude plugins
308
+ * @return array List of installed plugins
309
+ */
310
+ public function get_plugins( $exclude = array() ) {
311
+ if ( ! function_exists( 'get_plugins' ) ) {
312
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
313
+ }
314
+
315
+ $plugins = array();
316
+ foreach ( get_plugins() as $key => $plugin ) {
317
+ $directory = current( explode( DIRECTORY_SEPARATOR, $key ) );
318
+ if ( ! in_array( $directory, $exclude ) ) {
319
+ $plugins[] = $directory;
320
  }
321
  }
322
 
323
+ return $plugins;
324
  }
325
  }
lib/model/class-ai1wm-file.php CHANGED
@@ -27,29 +27,28 @@ class Ai1wm_File
27
  {
28
 
29
  /**
30
- * [str_replace_file description]
31
- * @param [type] $fh [description]
32
- * @param [type] $pattern [description]
33
- * @param [type] $replacement [description]
34
- * @return [type] [description]
 
 
 
35
  */
36
- public function str_replace_file( $fh, $pattern, $replacement ) {
37
- $_new_file = tmpfile();
 
38
 
39
- while ( ! feof( $fh ) ) {
40
- $line = stream_get_line( $fh, 1000000, '\n' );
41
 
42
  // append new line at the end of the line
43
- if ( strlen( $line ) < 1000000 && ! feof( $fh ) ) {
44
  $line .= '\n';
45
  }
46
 
47
- if (
48
- false === fwrite(
49
- $_new_file,
50
- str_replace( $pattern, $replacement, $line )
51
- )
52
- ) {
53
  wp_die(
54
  'Writting to a file failed! Probably, there is no more free space left?',
55
  'Out of disk space'
@@ -57,55 +56,52 @@ class Ai1wm_File
57
  }
58
  }
59
 
60
- return $_new_file;
61
  }
62
 
63
  /**
64
  * Replace a file, line by line with the regex pattern and then writes the
65
  * output to a new file.
66
  *
67
- * @param [type] $fh [description]
68
- * @param [type] $pattern [description]
69
- *
70
- * @return [type] [description]
71
  */
72
- public function preg_replace_file( $fh, $pattern ) {
73
- $_new_file = tmpfile();
 
74
 
75
- // set filehandle to the beginning of the file
76
- rewind( $fh );
77
 
78
- while ( ! feof( $fh ) ) {
79
- $line = stream_get_line( $fh, 1000000, '\n' );
80
- // append new line at the end of the line
81
- if ( strlen( $line ) < 1000000 && ! feof( $fh ) ) {
82
  $line .= '\n';
83
  }
84
 
85
  $replaced = $this->_preg_replace( $line, $pattern );
86
- if (
87
- false === fwrite(
88
- $_new_file,
89
- $replaced
90
- )
91
- ) {
92
  wp_die(
93
  'Writting to a file failed! Probably, there is no more free space left?',
94
  'Out of disk space'
95
  );
96
  }
97
  }
98
- return $_new_file;
99
  }
100
 
101
  /**
102
- * [_preg_replace description]
103
- * @param [type] $line [description]
104
- * @param [type] $pattern [description]
105
- * @return [type] [description]
 
106
  */
107
  public function _preg_replace( $line, $pattern ) {
108
- //php doesn't garbage collect functions created by create_function()
109
  static $callback = null;
110
 
111
  if ( $callback === null ) {
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 string $pattern Find and replace pattern
36
+ * @param string $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'
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
+ // Append new line at the end of the line
81
+ if ( strlen( $line ) < 1000000 && ! feof( $current_file ) ) {
82
  $line .= '\n';
83
  }
84
 
85
  $replaced = $this->_preg_replace( $line, $pattern );
86
+ if ( false === fwrite( $new_file->getAs( 'resource' ), $replaced ) ) {
 
 
 
 
 
87
  wp_die(
88
  'Writting to a file failed! Probably, there is no more free space left?',
89
  'Out of disk space'
90
  );
91
  }
92
  }
93
+ return $new_file;
94
  }
95
 
96
  /**
97
+ * Find and replace line by line with pattern
98
+ *
99
+ * @param string $line Line to replace
100
+ * @param string $pattern Pattern
101
+ * @return string New line
102
  */
103
  public function _preg_replace( $line, $pattern ) {
104
+ // PHP doesn't garbage collect functions created by create_function()
105
  static $callback = null;
106
 
107
  if ( $callback === null ) {
lib/model/class-ai1wm-import.php CHANGED
@@ -56,184 +56,198 @@ class Ai1wm_Import
56
  $errors = array();
57
 
58
  if ( empty( $input_file['error'] ) ) {
59
- // Partial file path
60
- $upload_file = sys_get_temp_dir() . DIRECTORY_SEPARATOR
61
- . $options['name'];
62
-
63
- // Open partial file
64
- $out = fopen( $upload_file, $options['chunk'] == 0 ? 'wb' : 'ab' );
65
- if ( $out ) {
66
- // Read binary input stream and append it to temp file
67
- $in = fopen( $input_file['tmp_name'], 'rb' );
68
- if ( $in ) {
69
- while ( $buff = fread( $in, 4096 ) ) {
70
- fwrite( $out, $buff );
 
 
 
71
  }
72
- }
73
 
74
- fclose( $in );
75
- fclose( $out );
76
 
77
- // Remove temporary uploaded file
78
- unlink( $input_file['tmp_name'] );
79
- } else {
 
 
 
 
 
 
 
 
 
 
 
 
80
  $errors[] = sprintf(
81
  _(
82
- 'File could not be imported!<br />
83
- Please make sure that PHP temporary directory <strong>%s</strong> has read and write permissions.
84
- <a href="https://servmask.com/blog/setting-permissions-for-temp-folder-on-windows" target="_blank">See how?</a>'
85
  ),
86
- sys_get_temp_dir()
87
  );
 
 
 
88
  }
89
 
90
  // Check if file has been uploaded
91
  if ( empty( $errors ) && ( ! $options['chunks'] || $options['chunk'] == $options['chunks'] - 1 ) ) {
92
  // Create temporary directory
93
- $extract_to = sys_get_temp_dir() . DIRECTORY_SEPARATOR
94
- . uniqid()
95
- . DIRECTORY_SEPARATOR;
96
- if ( ! is_dir( $extract_to ) ) {
97
- mkdir( $extract_to );
 
 
 
 
 
 
 
98
  }
99
 
100
- // Extract archive to a temporary directory
101
- $archive = ZipFactory::makeZipArchiver( $upload_file, ! class_exists( 'ZipArchive' ) );
102
- $archive->extractTo( $extract_to );
103
- $archive->close();
104
-
105
- // Verify whether this arhive is valid
106
- if ( $this->is_valid( $extract_to ) ) {
107
- // Enable maintenance mode
108
- $this->maintenance_mode( true );
109
-
110
- // Media base directory
111
- $upload_dir = wp_upload_dir();
112
- $upload_basedir = $upload_dir['basedir'] . DIRECTORY_SEPARATOR;
113
- if ( ! is_dir( $upload_basedir ) ) {
114
- mkdir( $upload_basedir );
115
- }
116
-
117
- // Themes base directory
118
- $themes_dir = get_theme_root();
119
- $themes_basedir = $themes_dir . DIRECTORY_SEPARATOR;
120
- if ( ! is_dir( $themes_basedir ) ) {
121
- mkdir( $themes_basedir );
122
- }
123
-
124
- if ( file_exists( $extract_to . Ai1wm_Export::EXPORT_DATABASE_NAME ) ) {
125
- // Backup database
126
- $model = new Ai1wm_Export;
127
- $database_file = tmpfile();
128
- $options = array( 'add-drop-table' => true, 'export-single-transaction' => true );
129
- $model->prepare_database( $database_file, $options );
130
-
131
- // Truncate database
132
- $this->connection->truncateDatabase();
133
-
134
- // Import database
135
- $this->connection->setOldTablePrefix( AI1WM_TABLE_PREFIX )
136
- ->setNewTablePrefix( $wpdb->prefix )
137
- ->import( $extract_to . Ai1wm_Export::EXPORT_DATABASE_NAME );
138
- }
139
-
140
- // Check if media files are present
141
- if ( file_exists( $extract_to . Ai1wm_Export::EXPORT_MEDIA_NAME ) ) {
142
- // Backup media files
143
- $backup_media_to = sys_get_temp_dir() . DIRECTORY_SEPARATOR
144
- . uniqid()
145
- . DIRECTORY_SEPARATOR;
146
- if ( ! is_dir( $backup_media_to ) ) {
147
- mkdir( $backup_media_to );
148
- }
149
-
150
- $this->copy_dir( $upload_basedir, $backup_media_to );
151
-
152
- // Truncate media files
153
- $this->truncate_dir( $upload_basedir );
154
-
155
- // Import media files
156
- $this->copy_dir( $extract_to . Ai1wm_Export::EXPORT_MEDIA_NAME, $upload_basedir );
157
- }
158
-
159
- if ( file_exists( $extract_to . Ai1wm_Export::EXPORT_THEMES_NAME ) ) {
160
- // Backup themes files
161
- $backup_themes_to = sys_get_temp_dir() . DIRECTORY_SEPARATOR
162
- . uniqid()
163
- . DIRECTORY_SEPARATOR;
164
- if ( ! is_dir( $backup_themes_to ) ) {
165
- mkdir( $backup_themes_to );
166
  }
167
 
168
- $this->copy_dir( $themes_basedir, $backup_themes_to );
169
-
170
- // Truncate themes files
171
- $this->truncate_dir( $themes_basedir );
172
-
173
- // Import themes files
174
- $this->copy_dir( $extract_to . Ai1wm_Export::EXPORT_THEMES_NAME, $themes_basedir );
175
- }
176
-
177
- if ( file_exists( $extract_to . Ai1wm_Export::EXPORT_PLUGINS_NAME ) ) {
178
- // Backup plugin files
179
- $backup_plugins_to = sys_get_temp_dir() . DIRECTORY_SEPARATOR
180
- . uniqid()
181
- . DIRECTORY_SEPARATOR;
182
- if ( ! is_dir( $backup_plugins_to ) ) {
183
- mkdir( $backup_plugins_to );
184
  }
185
 
186
- $this->copy_dir( WP_PLUGIN_DIR, $backup_plugins_to );
187
-
188
- // Truncate plugin files
189
- $this->truncate_dir( WP_PLUGIN_DIR );
190
-
191
- // Import plugin files
192
- $this->copy_dir( $extract_to . Ai1wm_Export::EXPORT_PLUGINS_NAME, WP_PLUGIN_DIR );
193
- }
194
-
195
- // Test website
196
- if ( ! $this->test_website( get_option( 'siteurl' ) ) ) {
197
  if ( file_exists( $extract_to . Ai1wm_Export::EXPORT_DATABASE_NAME ) ) {
 
 
 
 
198
  // Truncate database
199
  $this->connection->truncateDatabase();
200
 
201
- // Import "OLD" database
202
  $this->connection->setOldTablePrefix( AI1WM_TABLE_PREFIX )
203
- ->setNewTablePrefix( $wpdb->prefix )
204
- ->import( $database_file );
205
  }
206
 
207
- if ( file_exists( $extract_to . Ai1wm_Export::EXPORT_MEDIA_NAME ) ) {
 
 
 
 
 
 
208
  // Truncate media files
209
  $this->truncate_dir( $upload_basedir );
210
 
211
- // Import "OLD" media files
212
- $this->copy_dir( $backup_media_to, $upload_basedir );
213
  }
214
 
215
- if ( file_exists( $extract_to . Ai1wm_Export::EXPORT_THEMES_NAME ) ) {
 
 
 
 
 
 
216
  // Truncate themes files
217
  $this->truncate_dir( $themes_basedir );
218
 
219
- // Import "OLD" themes files
220
- $this->copy_dir( $backup_themes_to, $themes_basedir );
221
  }
222
 
223
- if ( file_exists( $extract_to . Ai1wm_Export::EXPORT_PLUGINS_NAME ) ) {
 
 
 
 
 
 
224
  // Truncate plugin files
225
- $this->truncate_dir( WP_PLUGIN_DIR );
226
 
227
- // Import "OLD" plugin files
228
- $this->copy_dir( $backup_plugins_to, WP_PLUGIN_DIR );
229
  }
230
- }
231
 
232
- // Disable maintenance mode
233
- $this->maintenance_mode( false );
234
- } else {
235
- $errors[] = _( 'File is not compatible with "All In One WP Migration" plugin! Please verify your archive file.' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  }
 
 
 
237
  }
238
  } else {
239
  $errors[] = $this->code_to_message( $input_file['error'] );
@@ -256,22 +270,47 @@ class Ai1wm_Import
256
  /**
257
  * Copy files from directory to directory
258
  *
259
- * @param string $from Copy files and directories FROM
260
- * @param string $to Copy files and directories TO
 
261
  * @return void
262
  */
263
- public function copy_dir( $from, $to ) {
264
  $from = trailingslashit( $from );
265
  $to = trailingslashit( $to );
266
 
267
  $iterator = new RecursiveIteratorIterator(
268
- $rdi = new RecursiveDirectoryIterator( $from ),
269
  RecursiveIteratorIterator::SELF_FIRST
270
  );
271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
  foreach ( $iterator as $item ) {
273
  // Skip dots
274
- if ( $iterator->isDot() ) continue;
 
 
 
 
 
 
 
 
 
275
 
276
  if ( $item->isDir() ) {
277
  mkdir( $to . $iterator->getSubPathName() );
@@ -284,19 +323,44 @@ class Ai1wm_Import
284
  /**
285
  * Truncate all files from specific directory
286
  *
287
- * @param string $dir Path to directory
 
288
  * @return void
289
  */
290
- public function truncate_dir( $dir ) {
291
  $dir = trailingslashit( $dir );
292
  $iterator = new RecursiveIteratorIterator(
293
- $rdi = new RecursiveDirectoryIterator( $dir ),
294
  RecursiveIteratorIterator::CHILD_FIRST
295
  );
296
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
  foreach ( $iterator as $item ) {
298
  // Skip dots
299
- if ( $iterator->isDot() ) continue;
 
 
 
 
 
 
 
 
 
300
 
301
  if ( $item->isDir() ) {
302
  rmdir( $dir . $iterator->getSubPathName() );
56
  $errors = array();
57
 
58
  if ( empty( $input_file['error'] ) ) {
59
+ try {
60
+ $storage = new StorageArea;
61
+
62
+ // Partial file path
63
+ $upload_file = $storage->makeFile( $options['name'] )->getAs( 'string' );
64
+
65
+ // Open partial file
66
+ $out = fopen( $upload_file, $options['chunk'] == 0 ? 'wb' : 'ab' );
67
+ if ( $out ) {
68
+ // Read binary input stream and append it to temp file
69
+ $in = fopen( $input_file['tmp_name'], 'rb' );
70
+ if ( $in ) {
71
+ while ( $buff = fread( $in, 4096 ) ) {
72
+ fwrite( $out, $buff );
73
+ }
74
  }
 
75
 
76
+ fclose( $in );
77
+ fclose( $out );
78
 
79
+ // Remove temporary uploaded file
80
+ unlink( $input_file['tmp_name'] );
81
+ } else {
82
+ $errors[] = sprintf(
83
+ _(
84
+ 'Site could not be imported!<br />
85
+ Please make sure that storage directory <strong>%s</strong> has read and write permissions.'
86
+ ),
87
+ AI1WM_STORAGE_PATH
88
+ );
89
+
90
+ // Clear storage
91
+ $storage->flush();
92
+ }
93
+ } catch ( Exception $e ) {
94
  $errors[] = sprintf(
95
  _(
96
+ 'Site could not be imported!<br />
97
+ Please make sure that storage directory <strong>%s</strong> has read and write permissions.'
 
98
  ),
99
+ AI1WM_STORAGE_PATH
100
  );
101
+
102
+ // Clear storage
103
+ $storage->flush();
104
  }
105
 
106
  // Check if file has been uploaded
107
  if ( empty( $errors ) && ( ! $options['chunks'] || $options['chunk'] == $options['chunks'] - 1 ) ) {
108
  // Create temporary directory
109
+ $extract_to = $storage->makeDirectory()->getAs( 'string' );
110
+
111
+ try {
112
+ // Extract archive to a temporary directory
113
+ $archive = ZipFactory::makeZipArchiver( $upload_file, ! class_exists( 'ZipArchive' ) );
114
+ $archive->extractTo( $extract_to );
115
+ $archive->close();
116
+ } catch ( Exception $e ) {
117
+ $errors[] = _(
118
+ 'Archive file is broken or is not compatible with
119
+ "All In One WP Migration" plugin! Please verify your archive file.'
120
+ );
121
  }
122
 
123
+ if ( empty( $errors ) ) {
124
+ // Verify whether this archive is valid
125
+ if ( $this->is_valid( $extract_to ) ) {
126
+ // Enable maintenance mode
127
+ $this->maintenance_mode( true );
128
+
129
+ // Media base directory
130
+ $upload_dir = wp_upload_dir();
131
+ $upload_basedir = $upload_dir['basedir'] . DIRECTORY_SEPARATOR;
132
+ if ( ! is_dir( $upload_basedir ) ) {
133
+ mkdir( $upload_basedir );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  }
135
 
136
+ // Themes base directory
137
+ $themes_dir = get_theme_root();
138
+ $themes_basedir = $themes_dir . DIRECTORY_SEPARATOR;
139
+ if ( ! is_dir( $themes_basedir ) ) {
140
+ mkdir( $themes_basedir );
 
 
 
 
 
 
 
 
 
 
 
141
  }
142
 
143
+ // Database import
 
 
 
 
 
 
 
 
 
 
144
  if ( file_exists( $extract_to . Ai1wm_Export::EXPORT_DATABASE_NAME ) ) {
145
+ // Backup database
146
+ $model = new Ai1wm_Export;
147
+ $database_file = $model->prepare_database( $storage );
148
+
149
  // Truncate database
150
  $this->connection->truncateDatabase();
151
 
152
+ // Import database
153
  $this->connection->setOldTablePrefix( AI1WM_TABLE_PREFIX )
154
+ ->setNewTablePrefix( $wpdb->prefix )
155
+ ->import( $extract_to . Ai1wm_Export::EXPORT_DATABASE_NAME );
156
  }
157
 
158
+ // Media import
159
+ if ( is_dir( $extract_to . Ai1wm_Export::EXPORT_MEDIA_NAME ) ) {
160
+ // Backup media files
161
+ $backup_media_to = $storage->makeDirectory()->getAs( 'string' );
162
+
163
+ $this->copy_dir( $upload_basedir, $backup_media_to );
164
+
165
  // Truncate media files
166
  $this->truncate_dir( $upload_basedir );
167
 
168
+ // Import media files
169
+ $this->copy_dir( $extract_to . Ai1wm_Export::EXPORT_MEDIA_NAME, $upload_basedir );
170
  }
171
 
172
+ // Themes import
173
+ if ( is_dir( $extract_to . Ai1wm_Export::EXPORT_THEMES_NAME ) ) {
174
+ // Backup themes files
175
+ $backup_themes_to = $storage->makeDirectory()->getAs( 'string' );
176
+
177
+ $this->copy_dir( $themes_basedir, $backup_themes_to );
178
+
179
  // Truncate themes files
180
  $this->truncate_dir( $themes_basedir );
181
 
182
+ // Import themes files
183
+ $this->copy_dir( $extract_to . Ai1wm_Export::EXPORT_THEMES_NAME, $themes_basedir );
184
  }
185
 
186
+ // Plugins import
187
+ if ( is_dir( $extract_to . Ai1wm_Export::EXPORT_PLUGINS_NAME ) ) {
188
+ // Backup plugin files
189
+ $backup_plugins_to = $storage->makeDirectory()->getAs( 'string' );
190
+
191
+ $this->copy_dir( WP_PLUGIN_DIR, $backup_plugins_to, array( AI1WM_PLUGIN_NAME ) );
192
+
193
  // Truncate plugin files
194
+ $this->truncate_dir( WP_PLUGIN_DIR, array( AI1WM_PLUGIN_NAME ) );
195
 
196
+ // Import plugin files
197
+ $this->copy_dir( $extract_to . Ai1wm_Export::EXPORT_PLUGINS_NAME, WP_PLUGIN_DIR );
198
  }
 
199
 
200
+ // Test website
201
+ if ( ! $this->test_website( get_option( 'siteurl' ) ) ) {
202
+
203
+ // Database import
204
+ if ( file_exists( $extract_to . Ai1wm_Export::EXPORT_DATABASE_NAME ) ) {
205
+ // Truncate database
206
+ $this->connection->truncateDatabase();
207
+
208
+ // Import "OLD" database
209
+ $this->connection->setOldTablePrefix( AI1WM_TABLE_PREFIX )
210
+ ->setNewTablePrefix( $wpdb->prefix )
211
+ ->import( $database_file->getAs( 'string' ) );
212
+ }
213
+
214
+ // Media import
215
+ if ( is_dir( $extract_to . Ai1wm_Export::EXPORT_MEDIA_NAME ) ) {
216
+ // Truncate media files
217
+ $this->truncate_dir( $upload_basedir );
218
+
219
+ // Import "OLD" media files
220
+ $this->copy_dir( $backup_media_to, $upload_basedir );
221
+ }
222
+
223
+ // Themes import
224
+ if ( is_dir( $extract_to . Ai1wm_Export::EXPORT_THEMES_NAME ) ) {
225
+ // Truncate themes files
226
+ $this->truncate_dir( $themes_basedir );
227
+
228
+ // Import "OLD" themes files
229
+ $this->copy_dir( $backup_themes_to, $themes_basedir );
230
+ }
231
+
232
+ // Plugins import
233
+ if ( is_dir( $extract_to . Ai1wm_Export::EXPORT_PLUGINS_NAME ) ) {
234
+ // Truncate plugin files
235
+ $this->truncate_dir( WP_PLUGIN_DIR, array( AI1WM_PLUGIN_NAME ) );
236
+
237
+ // Import "OLD" plugin files
238
+ $this->copy_dir( $backup_plugins_to, WP_PLUGIN_DIR, array( AI1WM_PLUGIN_NAME ) );
239
+ }
240
+ }
241
+
242
+ // Disable maintenance mode
243
+ $this->maintenance_mode( false );
244
+ } else {
245
+ $errors[] = _( 'File is not compatible with "All In One WP Migration" plugin! Please verify your archive file.' );
246
+ }
247
  }
248
+
249
+ // Clear storage
250
+ $storage->flush();
251
  }
252
  } else {
253
  $errors[] = $this->code_to_message( $input_file['error'] );
270
  /**
271
  * Copy files from directory to directory
272
  *
273
+ * @param string $from Copy files and directories FROM
274
+ * @param string $to Copy files and directories TO
275
+ * @param array $exclude List of directories to exclude
276
  * @return void
277
  */
278
+ public function copy_dir( $from, $to, $exclude = array() ) {
279
  $from = trailingslashit( $from );
280
  $to = trailingslashit( $to );
281
 
282
  $iterator = new RecursiveIteratorIterator(
283
+ new RecursiveDirectoryIterator( $from ),
284
  RecursiveIteratorIterator::SELF_FIRST
285
  );
286
 
287
+ // Prepare filter pattern
288
+ $filter_pattern = null;
289
+ if ( is_array( $exclude ) ) {
290
+ $filters = array();
291
+ foreach ( $exclude as $filter ) {
292
+ $filters[] = sprintf(
293
+ '(%s(%s.*)?)',
294
+ preg_quote( $filter, '/' ),
295
+ preg_quote( DIRECTORY_SEPARATOR, '/' )
296
+ );
297
+ }
298
+
299
+ $filter_pattern = implode( '|', $filters );
300
+ }
301
+
302
  foreach ( $iterator as $item ) {
303
  // Skip dots
304
+ if ( $iterator->isDot() ) {
305
+ continue;
306
+ }
307
+
308
+ // Validate filter pattern
309
+ if ( $filter_pattern ) {
310
+ if ( preg_match( '/^' . $filter_pattern . '$/', $iterator->getSubPathName() ) ) {
311
+ continue;
312
+ }
313
+ }
314
 
315
  if ( $item->isDir() ) {
316
  mkdir( $to . $iterator->getSubPathName() );
323
  /**
324
  * Truncate all files from specific directory
325
  *
326
+ * @param string $dir Path to directory
327
+ * @param array $exclude List of directories to exclude
328
  * @return void
329
  */
330
+ public function truncate_dir( $dir, $exclude = array() ) {
331
  $dir = trailingslashit( $dir );
332
  $iterator = new RecursiveIteratorIterator(
333
+ new RecursiveDirectoryIterator( $dir ),
334
  RecursiveIteratorIterator::CHILD_FIRST
335
  );
336
 
337
+ // Prepare filter pattern
338
+ $filter_pattern = null;
339
+ if ( is_array( $exclude ) ) {
340
+ $filters = array();
341
+ foreach ( $exclude as $filter ) {
342
+ $filters[] = sprintf(
343
+ '(%s(%s.*)?)',
344
+ preg_quote( $filter, '/' ),
345
+ preg_quote( DIRECTORY_SEPARATOR, '/' )
346
+ );
347
+ }
348
+
349
+ $filter_pattern = implode( '|', $filters );
350
+ }
351
+
352
  foreach ( $iterator as $item ) {
353
  // Skip dots
354
+ if ( $iterator->isDot() ) {
355
+ continue;
356
+ }
357
+
358
+ // Validate filter pattern
359
+ if ( $filter_pattern ) {
360
+ if ( preg_match( '/^' . $filter_pattern . '$/', $iterator->getSubPathName() ) ) {
361
+ continue;
362
+ }
363
+ }
364
 
365
  if ( $item->isDir() ) {
366
  rmdir( $dir . $iterator->getSubPathName() );
lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpPDO.php CHANGED
@@ -543,11 +543,14 @@ class MysqlDumpPDO implements MysqlDumpInterface
543
  $query = "SELECT * FROM `$tableName` ";
544
 
545
  // Apply additional query clauses
546
- if ($this->getNoTableData()) {
547
- $clauses = $this->getQueryClauses();
548
- if (isset($clauses[$tableName]) && ($queryClause = $clauses[$tableName])) {
549
- $query .= $queryClause;
550
- }
 
 
 
551
  }
552
 
553
  // Replace table prefix
543
  $query = "SELECT * FROM `$tableName` ";
544
 
545
  // Apply additional query clauses
546
+ $clauses = $this->getQueryClauses();
547
+ if (isset($clauses[$tableName]) && ($queryClause = $clauses[$tableName])) {
548
+ $query .= $queryClause;
549
+ }
550
+
551
+ // No table data
552
+ if ($this->getNoTableData() && !isset($clauses[$tableName])) {
553
+ return;
554
  }
555
 
556
  // Replace table prefix
lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpSQL.php CHANGED
@@ -536,11 +536,14 @@ class MysqlDumpSQL implements MysqlDumpInterface
536
  $query = "SELECT * FROM `$tableName` ";
537
 
538
  // Apply additional query clauses
539
- if ($this->getNoTableData()) {
540
- $clauses = $this->getQueryClauses();
541
- if (isset($clauses[$tableName]) && ($queryClause = $clauses[$tableName])) {
542
- $query .= $queryClause;
543
- }
 
 
 
544
  }
545
 
546
  // Replace table prefix
536
  $query = "SELECT * FROM `$tableName` ";
537
 
538
  // Apply additional query clauses
539
+ $clauses = $this->getQueryClauses();
540
+ if (isset($clauses[$tableName]) && ($queryClause = $clauses[$tableName])) {
541
+ $query .= $queryClause;
542
+ }
543
+
544
+ // No table data
545
+ if ($this->getNoTableData() && !isset($clauses[$tableName])) {
546
+ return;
547
  }
548
 
549
  // Replace table prefix
lib/vendor/storage-factory/storage-factory/.editorconfig ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # top-most EditorConfig file
2
+ root = true
3
+
4
+ # Unix-style newlines with a newline ending every file
5
+ [*]
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+ indent_style = space
11
+
12
+ # PHP
13
+ [*.php]
14
+ indent_style = space
15
+ indent_size = 4
16
+ max_line_length = 120
17
+
18
+ # YAML
19
+ [*.yml]
20
+ indent_style = space
21
+ indent_size = 4
22
+
23
+ # XML
24
+ [*.xml]
25
+ indent_style = space
26
+ indent_size = 4
lib/vendor/storage-factory/storage-factory/.travil.yml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ language: php
2
+
3
+ php:
4
+ - 5.5
5
+ - 5.4
6
+ - 5.3
7
+ - 5.2
8
+
9
+ script: phpunit
10
+
lib/vendor/storage-factory/storage-factory/LICENSE ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Yani Iliev, Bobby Angelov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
lib/vendor/storage-factory/storage-factory/README.md ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Storage Factory
2
+
3
+ [![Build Status](https://travis-ci.org/borislav-angelov/storage-factory.png)](https://travis-ci.org/borislav-angelov/storage-factory)
4
+ [![Latest Stable Version](https://poser.pugx.org/storage-factory/storage-factory/v/stable.png)](https://packagist.org/packages/storage-factory/storage-factory)
5
+ [![Total Downloads](https://poser.pugx.org/storage-factory/storage-factory/downloads.png)](https://packagist.org/packages/storage-factory/storage-factory)
6
+
7
+ Factory class that creates either File Storage or Directory Storage
8
+
9
+ ### Requirements
10
+ PHP v5.2 and up. Tested on PHP v5.2.17, v5.3, v5.4, v5.5
11
+
12
+ ### Usage
13
+ ```php
14
+ ```
15
+
16
+ ### Tests
17
+ Coverage reports are stored inside the coverage folder.
18
+ ```bash
19
+ phpunit
20
+ ```
21
+
22
+ ### Contributing
23
+ For code guidelines refer to `.editorconfig`. This project is following PEAR code standard - http://pear.php.net/manual/en/standards.php
24
+ The project is following Vincent Driessen's branching model aka git flow - http://nvie.com/git-model/
25
+ Make sure to submit your pull requests against the **develop** branch
26
+
27
+ ### License
28
+ MIT
29
+
30
+ ### Authors
31
+ * Bobby Angelov
32
+ * Yani Iliev
lib/vendor/storage-factory/storage-factory/bump-version.sh ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ if [ -z "$1" ]; then
4
+ echo -e "\033[0;31mUsage:\033[0m $0 (major|minor|patch)\033[0m"
5
+ echo -e "\033[4;32mCurrent version\033[0m:\033[0m \033[33m`git describe master`\033[0m"
6
+ exit -1
7
+ fi
8
+
9
+ # increment version depending on passed parameter
10
+ case "$1" in
11
+ major)
12
+ currentVersion=`git describe master`
13
+ bumpedVersion=`echo $currentVersion | ( IFS=".$IFS" ; read a b c && echo $((a + 1)).0.0 )`
14
+ ;;
15
+ minor)
16
+ currentVersion=`git describe master`
17
+ bumpedVersion=`echo $currentVersion | ( IFS=".$IFS" ; read a b c && echo $a.$((b + 1)).0 )`
18
+ ;;
19
+ patch)
20
+ currentVersion=`git describe master`
21
+ bumpedVersion=`echo $currentVersion | ( IFS=".$IFS" ; read a b c && echo $a.$b.$((c + 1)) )`
22
+ ;;
23
+ *)
24
+ echo -e "\033[0;31mUsage:\033[0m $0 (major|minor|patch)\033[0m"
25
+ echo -e "\033[4;32mCurrent version\033[0m:\033[0m \033[33m`git describe master`\033[0m"
26
+ exit -1
27
+ esac
28
+
29
+ # let's start a new release
30
+ git flow release start $bumpedVersion
31
+
32
+ # bump version in all files
33
+ for file in `find . -path ./coverage -prune -o -path ./.git -prune -o -type f`
34
+ do
35
+ filename=$(basename "$file")
36
+ ext="${filename##*.}"
37
+ if [ $ext != "png" -a $ext != "jpg" -a $ext != "jpeg" -a $ext != "gif" ]; then
38
+ if [ $ext != "DS_Store" -a $ext != "ttf" -a $ext != "node_modules" -a $ext != "git" ]; then
39
+ sed -i '' "s/GIT: ..11.0.0$currentVersion/GIT: ..11.0.0$bumpedVersion/g" $file
40
+ fi
41
+ fi
42
+ done
43
+
44
+ # bump version in package.json
45
+ sed -i '' "s/\"version\": \"$currentVersion\"/\"version\": \"$bumpedVersion\"/g" package.json
46
+
47
+ # add changed files to git
48
+ git add . && git commit -m "Bumped version from $currentVersion to $bumpedVersion"
49
+
50
+ # finish the release
51
+ git flow release finish -F -m "$bumpedVersion" $bumpedVersion
52
+
53
+ # publish develop branch
54
+ git checkout develop && git push origin develop
55
+
56
+ # publish master
57
+ git checkout master && git push origin master
58
+
59
+ # publish tags
60
+ git push origin --tags
61
+
62
+ # Announce the result
63
+ echo -e "\033[4;32mSuccessfully released\033[0m:\033[0m \033[33m$bumpedVersion\033[0m"
lib/vendor/storage-factory/storage-factory/composer.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "storage-factory/storage-factory",
3
+ "type": "library",
4
+ "description": "Factory class that creates either File Storage or Directory Storage PHP 5.2.17 and up",
5
+ "keywords": ["file storage", "directory storage"],
6
+ "homepage": "http://github.com/borislav-angelov/storage-factory",
7
+ "license": "MIT",
8
+ "authors": [
9
+ {
10
+ "name": "Bobby Angelov",
11
+ "email": "borislav.angelov@gmail.com",
12
+ "homepage": "https://servmask.com",
13
+ "role": "developer"
14
+ },
15
+ {
16
+ "name": "Yani Iliev",
17
+ "email": "yani@iliev.me",
18
+ "homepage": "https://yani.iliev.me",
19
+ "role": "developer"
20
+ }
21
+ ],
22
+ "require": {
23
+ "php": ">=5.2.0"
24
+ }
25
+ }
lib/vendor/storage-factory/storage-factory/lib/StorageAbstract.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
+
4
+ /**
5
+ * StorageAbstract 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 FileSystem
27
+ * @package StorageFactory
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/borislav-angelov/storage-factory/master/LICENSE The MIT License (MIT)
32
+ * @version GIT: 1.0.0
33
+ * @link https://github.com/borislav-angelov/storage-factory/
34
+ */
35
+
36
+ /**
37
+ * StorageAbstract class
38
+ *
39
+ * @category FileSystem
40
+ * @package StorageFactory
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/borislav-angelov/storage-factory/master/LICENSE The MIT License (MIT)
45
+ * @version GIT: 1.0.0
46
+ * @link https://github.com/borislav-angelov/storage-factory/
47
+ */
48
+ abstract class StorageAbstract
49
+ {
50
+ /**
51
+ * Get a file or directory as resource
52
+ *
53
+ * @param string Get a file or directory as resource or absolute path
54
+ * @return mixed
55
+ */
56
+ abstract public function getAs($type = 'string');
57
+
58
+ /**
59
+ * Delete a file or directory
60
+ *
61
+ * @return string
62
+ */
63
+ abstract public function delete();
64
+
65
+ /**
66
+ * Get storage absolute path
67
+ *
68
+ * @return mixed
69
+ */
70
+ public function getRootPath() {
71
+ if (defined('AI1WM_STORAGE_PATH') && self::isAccessible(AI1WM_STORAGE_PATH)) {
72
+ return AI1WM_STORAGE_PATH;
73
+ } else if (self::isAccessible(sys_get_temp_dir())) {
74
+ return sys_get_temp_dir();
75
+ } else {
76
+ throw new Exception('Storage directory is not accessible (read/write).');
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Is path accessible (read/write)
82
+ *
83
+ * @param string Absolute path
84
+ * @return boolean Path is accessible or not
85
+ */
86
+ public static function isAccessible($path) {
87
+ return is_readable($path) && is_writable($path);
88
+ }
89
+ }
lib/vendor/storage-factory/storage-factory/lib/StorageArea.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
+
4
+ /**
5
+ * StorageArea class main file
6
+ *
7
+ * PHP version 5
8
+ *
9
+ * LICENSE: Permission is hereby granted, free of charge, to any person obtaining
10
+ * a copy of this software and associated documentation files (the "Software"), to
11
+ * deal in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
13
+ * of the Software, and to permit persons to whom the Software is furnished to do so,
14
+ * subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
21
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
22
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
23
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+ *
26
+ * @category FileSystem
27
+ * @package StorageFactory
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/borislav-angelov/storage-factory/master/LICENSE The MIT License (MIT)
32
+ * @version GIT: 1.0.0
33
+ * @link https://github.com/borislav-angelov/storage-factory/
34
+ */
35
+
36
+ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'StorageFile.php';
37
+ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'StorageDirectory.php';
38
+
39
+ /**
40
+ * StorageArea Main class
41
+ *
42
+ * @category FileSystem
43
+ * @package StorageFactory
44
+ * @author Yani Iliev <yani@iliev.me>
45
+ * @author Bobby Angelov <bobby@servmask.com>
46
+ * @copyright 2014 Yani Iliev, Bobby Angelov
47
+ * @license https://raw.github.com/borislav-angelov/storage-factory/master/LICENSE The MIT License (MIT)
48
+ * @version GIT: 1.0.0
49
+ * @link https://github.com/borislav-angelov/storage-factory/
50
+ */
51
+ class StorageArea
52
+ {
53
+ protected $nodes = array();
54
+
55
+ /**
56
+ * Create a file with unique name
57
+ *
58
+ * @param string $name Custom file name
59
+ * @return StorageFile StorageFile instance
60
+ */
61
+ public function makeFile($name = null) {
62
+ $this->nodes[] = $node = new StorageFile($name);
63
+
64
+ return $node;
65
+ }
66
+
67
+ /**
68
+ * Create a directory with unique name
69
+ *
70
+ * @param string $name Custom directory name
71
+ * @return StorageDirectory StorageDirectory instance
72
+ */
73
+ public function makeDirectory($name = null) {
74
+ $this->nodes[] = $node = new StorageDirectory($name);
75
+
76
+ return $node;
77
+ }
78
+
79
+ /**
80
+ * Remove all files and directories in the current storage
81
+ *
82
+ * @return void
83
+ */
84
+ public function flush() {
85
+ foreach ($this->nodes as $node) {
86
+ $node->delete();
87
+ }
88
+ }
89
+ }
lib/vendor/storage-factory/storage-factory/lib/StorageDirectory.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
+
4
+ /**
5
+ * StorageDirectory 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 FileSystem
27
+ * @package StorageFactory
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/borislav-angelov/storage-factory/master/LICENSE The MIT License (MIT)
32
+ * @version GIT: 1.0.0
33
+ * @link https://github.com/borislav-angelov/storage-factory/
34
+ */
35
+
36
+ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'StorageAbstract.php';
37
+
38
+ /**
39
+ * StorageDirectory class
40
+ *
41
+ * @category FileSystem
42
+ * @package StorageFactory
43
+ * @author Yani Iliev <yani@iliev.me>
44
+ * @author Bobby Angelov <bobby@servmask.com>
45
+ * @copyright 2014 Yani Iliev, Bobby Angelov
46
+ * @license https://raw.github.com/borislav-angelov/storage-factory/master/LICENSE The MIT License (MIT)
47
+ * @version GIT: 1.0.0
48
+ * @link https://github.com/borislav-angelov/storage-factory/
49
+ */
50
+ class StorageDirectory extends StorageAbstract
51
+ {
52
+ protected $directory = null;
53
+
54
+ /**
55
+ * CTOR
56
+ */
57
+ public function __construct($name = null) {
58
+ if (empty($name)) {
59
+ $this->directory = $this->getRootPath() . DIRECTORY_SEPARATOR . uniqid() . DIRECTORY_SEPARATOR;
60
+ } else {
61
+ $this->directory = $this->getRootPath() . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR;
62
+ }
63
+
64
+ // Create directory
65
+ if (!is_dir($this->directory)) {
66
+ mkdir($this->directory);
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Get a file or directory as resource
72
+ *
73
+ * @param string Get a file or directory as resource or absolute path
74
+ * @return mixed
75
+ */
76
+ public function getAs($type = 'string') {
77
+ if ($type === 'string') {
78
+ return $this->directory;
79
+ } else {
80
+ throw new Exception('Unable to retrieve directory as ' . $type . '. Make sure the method is implemented');
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Delete a file or directory
86
+ *
87
+ * @return void
88
+ */
89
+ public function delete() {
90
+ $iterator = new RecursiveIteratorIterator(
91
+ new RecursiveDirectoryIterator( $this->directory ),
92
+ RecursiveIteratorIterator::CHILD_FIRST
93
+ );
94
+
95
+ foreach ( $iterator as $item ) {
96
+ // Skip dots
97
+ if ( $iterator->isDot() ) continue;
98
+
99
+ if ( $item->isDir() ) {
100
+ rmdir( $this->directory . $iterator->getSubPathName() );
101
+ } else {
102
+ unlink( $this->directory . $iterator->getSubPathName() );
103
+ }
104
+ }
105
+
106
+ rmdir( $this->directory );
107
+ }
108
+
109
+ }
lib/vendor/storage-factory/storage-factory/lib/StorageFile.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
+
4
+ /**
5
+ * StorageFile 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 FileSystem
27
+ * @package StorageFactory
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/borislav-angelov/storage-factory/master/LICENSE The MIT License (MIT)
32
+ * @version GIT: 1.0.0
33
+ * @link https://github.com/borislav-angelov/storage-factory/
34
+ */
35
+
36
+ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'StorageAbstract.php';
37
+
38
+ /**
39
+ * StorageFile class
40
+ *
41
+ * @category FileSystem
42
+ * @package StorageFactory
43
+ * @author Yani Iliev <yani@iliev.me>
44
+ * @author Bobby Angelov <bobby@servmask.com>
45
+ * @copyright 2014 Yani Iliev, Bobby Angelov
46
+ * @license https://raw.github.com/borislav-angelov/storage-factory/master/LICENSE The MIT License (MIT)
47
+ * @version GIT: 1.0.0
48
+ * @link https://github.com/borislav-angelov/storage-factory/
49
+ */
50
+ class StorageFile extends StorageAbstract
51
+ {
52
+ protected $file = null;
53
+
54
+ /**
55
+ * CTOR
56
+ */
57
+ public function __construct($name = null) {
58
+ if (empty($name)) {
59
+ $this->file = tempnam(
60
+ $this->getRootPath(),
61
+ (defined('AI1WM_STORAGE_PREFIX') ? AI1WM_STORAGE_PREFIX : 'sm_')
62
+ );
63
+ } else {
64
+ $this->file = $this->getRootPath() . DIRECTORY_SEPARATOR . $name;
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Get absolute file path or file resource
70
+ *
71
+ * @return mixed
72
+ */
73
+ public function getAs($type = 'string') {
74
+ return ($type === 'string' ? $this->file : fopen($this->file, 'a+'));
75
+ }
76
+
77
+ /**
78
+ * Delete file
79
+ *
80
+ * @return boolean
81
+ */
82
+ public function delete() {
83
+ return unlink($this->file);
84
+ }
85
+ }
lib/vendor/storage-factory/storage-factory/phpunit.xml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <phpunit
2
+ bootstrap="test/bootstrap.php"
3
+ backupGlobals="false"
4
+ colors="true"
5
+ convertErrorsToExceptions="true"
6
+ convertNoticesToExceptions="true"
7
+ convertWarningsToExceptions="true"
8
+ >
9
+ <testsuites>
10
+ <testsuite>
11
+ <directory prefix="test-" suffix=".php">./test/</directory>
12
+ </testsuite>
13
+ </testsuites>
14
+ <filter>
15
+ <whitelist processUncoveredFilesFromWhitelist="true">
16
+ <directory suffix=".php">lib/</directory>
17
+ </whitelist>
18
+ </filter>
19
+ <logging>
20
+ <log
21
+ type="coverage-html"
22
+ target="coverage"
23
+ charset="UTF-8"
24
+ highlight="false"
25
+ lowUpperBound="35"
26
+ highLowerBound="70"
27
+ />
28
+ </logging>
29
+ </phpunit>
lib/vendor/storage-factory/storage-factory/test/bootstrap.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
+
4
+ /**
5
+ * Bootstrap file for unit tests used in Storage Factory
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 FileSystem
27
+ * @package StorageFactory
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/borislav-angelov/storage-factory/master/LICENSE The MIT License (MIT)
32
+ * @version GIT: 1.0.0
33
+ * @link https://github.com/borislav-angelov/storage-factory/
34
+ */
35
+
36
+ require_once
37
+ dirname(__FILE__) .
38
+ DIRECTORY_SEPARATOR . '..' .
39
+ DIRECTORY_SEPARATOR . 'lib' .
40
+ DIRECTORY_SEPARATOR . 'StorageFactory.php';
lib/vendor/storage-factory/storage-factory/test/test-storage-factory.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
+
4
+ /**
5
+ * Bootstrap file for unit tests used in Storage Factory
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 FileSystem
27
+ * @package StorageFactory
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/borislav-angelov/storage-factory/master/LICENSE The MIT License (MIT)
32
+ * @version GIT: 1.0.0
33
+ * @link https://github.com/borislav-angelov/storage-factory/
34
+ */
35
+
36
+ /**
37
+ * Unit test class
38
+ *
39
+ * @category Tests
40
+ * @package ZipFactory
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/borislav-angelov/storage-factory/master/LICENSE The MIT License (MIT)
45
+ * @version GIT: 1.0.0
46
+ * @link https://github.com/borislav-angelov/storage-factory/
47
+ */
48
+ class StorageFactoryTest extends PHPUnit_Framework_TestCase
49
+ {
50
+ /**
51
+ * @return [type] [description]
52
+ */
53
+ public function testMakeFileStorage()
54
+ {
55
+ $fileStorage = StorageFactory::make();
56
+ $this->assertTrue($fileStorage instanceof StorageFile);
57
+ }
58
+
59
+ /**
60
+ * @return [type] [description]
61
+ */
62
+ public function testMakeDirectoryStorage()
63
+ {
64
+ $fileStorage = StorageFactory::make(true);
65
+ $this->assertTrue($fileStorage instanceof StorageDirectory);
66
+ }
67
+ }
lib/vendor/zip-factory/zip-factory/lib/ArchiverPclZip.php CHANGED
@@ -28,7 +28,7 @@
28
  * @author Yani Iliev <yani@iliev.me>
29
  * @copyright 2014 Yani Iliev
30
  * @license https://raw.github.com/yani-/zip-factory/master/LICENSE The MIT License (MIT)
31
- * @version GIT: 1.1.0
32
  * @link https://github.com/yani-/zip-factory/
33
  */
34
 
@@ -121,23 +121,45 @@ if (function_exists('gzopen')) {
121
  }
122
 
123
  /**
124
- * [addDir description]
125
  *
126
- * @param [type] $path [description]
127
- * @param [type] $name [description]
128
- * @param array $include [description]
129
  *
130
- * @return null
131
  */
132
- public function addDir($path, $name = null, $include = array())
133
  {
134
- $this->pclzip->add(
135
- $path,
136
- PCLZIP_OPT_REMOVE_PATH,
137
- $path,
138
- PCLZIP_OPT_ADD_PATH,
139
- $name
140
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  }
142
 
143
  /**
28
  * @author Yani Iliev <yani@iliev.me>
29
  * @copyright 2014 Yani Iliev
30
  * @license https://raw.github.com/yani-/zip-factory/master/LICENSE The MIT License (MIT)
31
+ * @version GIT: 1.2.0
32
  * @link https://github.com/yani-/zip-factory/
33
  */
34
 
121
  }
122
 
123
  /**
124
+ * Add directory to archive
125
  *
126
+ * @param string $path Path to directory
127
+ * @param string $parent_dir Parent path name
128
+ * @param array $include Include specific directories
129
  *
130
+ * @return void
131
  */
132
+ public function addDir($path, $parent_dir = null, $include = array())
133
  {
134
+ // Prepare filter pattern
135
+ $filter_pattern = null;
136
+ if (is_array($include)) {
137
+ $filters = array();
138
+ foreach ($include as $filter) {
139
+ $filters[] = $path . DIRECTORY_SEPARATOR . $filter;
140
+ }
141
+
142
+ $filter_pattern = implode(',', $filters);
143
+ }
144
+
145
+ // Validate filter pattern
146
+ if ($filter_pattern) {
147
+ $this->pclzip->add(
148
+ $filter_pattern,
149
+ PCLZIP_OPT_REMOVE_PATH,
150
+ $path,
151
+ PCLZIP_OPT_ADD_PATH,
152
+ $parent_dir
153
+ );
154
+ } else {
155
+ $this->pclzip->add(
156
+ $path,
157
+ PCLZIP_OPT_REMOVE_PATH,
158
+ $path,
159
+ PCLZIP_OPT_ADD_PATH,
160
+ $parent_dir
161
+ );
162
+ }
163
  }
164
 
165
  /**
lib/vendor/zip-factory/zip-factory/lib/ArchiverZipArchive.php CHANGED
@@ -28,7 +28,7 @@
28
  * @author Yani Iliev <yani@iliev.me>
29
  * @copyright 2014 Yani Iliev
30
  * @license https://raw.github.com/yani-/zip-factory/master/LICENSE The MIT License (MIT)
31
- * @version GIT: 1.1.0
32
  * @link https://github.com/yani-/zip-factory/
33
  */
34
 
@@ -112,13 +112,13 @@ if (class_exists('ZipArchive')) {
112
  }
113
 
114
  /**
115
- * [addDir description]
116
  *
117
- * @param [type] $path [description]
118
- * @param [type] $parent_dir [description]
119
- * @param array $include [description]
120
  *
121
- * @return null [description]
122
  */
123
  public function addDir($path, $parent_dir = null, $include = array())
124
  {
@@ -128,18 +128,19 @@ if (class_exists('ZipArchive')) {
128
  RecursiveIteratorIterator::SELF_FIRST
129
  );
130
 
131
- // Prepare File Filter Pattern
132
- $file_pattern = null;
133
  if (is_array($include)) {
134
  $filters = array();
135
- foreach ($include as $file) {
136
- $filters[] = str_replace(
137
- '\.\*', '.*',
138
- preg_quote($file, '/')
 
139
  );
140
  }
141
 
142
- $file_pattern = implode('|', $filters);
143
  }
144
 
145
  foreach ($iterator as $item) {
@@ -148,12 +149,9 @@ if (class_exists('ZipArchive')) {
148
  continue;
149
  }
150
 
151
- // Validate file pattern
152
- if ($file_pattern) {
153
- if (!preg_match(
154
- '/^(' . $file_pattern . ')$/',
155
- $iterator->getSubPathName()
156
- )) {
157
  continue;
158
  }
159
  }
28
  * @author Yani Iliev <yani@iliev.me>
29
  * @copyright 2014 Yani Iliev
30
  * @license https://raw.github.com/yani-/zip-factory/master/LICENSE The MIT License (MIT)
31
+ * @version GIT: 1.2.0
32
  * @link https://github.com/yani-/zip-factory/
33
  */
34
 
112
  }
113
 
114
  /**
115
+ * Add directory to archive
116
  *
117
+ * @param string $path Path to directory
118
+ * @param string $parent_dir Parent path name
119
+ * @param array $include Include specific directories
120
  *
121
+ * @return void
122
  */
123
  public function addDir($path, $parent_dir = null, $include = array())
124
  {
128
  RecursiveIteratorIterator::SELF_FIRST
129
  );
130
 
131
+ // Prepare filter pattern
132
+ $filter_pattern = null;
133
  if (is_array($include)) {
134
  $filters = array();
135
+ foreach ($include as $filter) {
136
+ $filters[] = sprintf(
137
+ '(%s(%s.*)?)',
138
+ preg_quote( $filter, '/' ),
139
+ preg_quote( DIRECTORY_SEPARATOR, '/' )
140
  );
141
  }
142
 
143
+ $filter_pattern = implode( '|', $filters );
144
  }
145
 
146
  foreach ($iterator as $item) {
149
  continue;
150
  }
151
 
152
+ // Validate filter pattern
153
+ if ($filter_pattern) {
154
+ if (!preg_match('/^' . $filter_pattern . '$/', $iterator->getSubPathName())) {
 
 
 
155
  continue;
156
  }
157
  }
lib/vendor/zip-factory/zip-factory/lib/ZipFactory.php CHANGED
@@ -28,7 +28,7 @@
28
  * @author Yani Iliev <yani@iliev.me>
29
  * @copyright 2014 Yani Iliev
30
  * @license https://raw.github.com/yani-/zip-factory/master/LICENSE The MIT License (MIT)
31
- * @version GIT: 1.1.0
32
  * @link https://github.com/yani-/zip-factory/
33
  */
34
 
28
  * @author Yani Iliev <yani@iliev.me>
29
  * @copyright 2014 Yani Iliev
30
  * @license https://raw.github.com/yani-/zip-factory/master/LICENSE The MIT License (MIT)
31
+ * @version GIT: 1.2.0
32
  * @link https://github.com/yani-/zip-factory/
33
  */
34
 
lib/view/export/index.php CHANGED
@@ -149,7 +149,7 @@
149
  </div>
150
 
151
  <div class="ai1wm-field">
152
- <?php if ( $temp_dir ): ?>
153
  <div class="ai1wm-buttons">
154
  <button type="submit" name="options[action]" value="export" class="ai1wm-button-green">
155
  <i class="ai1wm-icon-arrow-down"></i>
@@ -162,10 +162,9 @@
162
  printf(
163
  _(
164
  'Site could not be exported!<br />
165
- Please make sure that PHP temporary directory <strong>%s</strong> has read and write permissions.
166
- <a href="https://servmask.com/blog/setting-permissions-for-temp-folder-on-windows" target="_blank">See how to do it?</a>'
167
  ),
168
- sys_get_temp_dir()
169
  );
170
  ?>
171
  </div>
149
  </div>
150
 
151
  <div class="ai1wm-field">
152
+ <?php if ( $is_accessible ): ?>
153
  <div class="ai1wm-buttons">
154
  <button type="submit" name="options[action]" value="export" class="ai1wm-button-green">
155
  <i class="ai1wm-icon-arrow-down"></i>
162
  printf(
163
  _(
164
  'Site could not be exported!<br />
165
+ Please make sure that storage directory <strong>%s</strong> has read and write permissions.'
 
166
  ),
167
+ AI1WM_STORAGE_PATH
168
  );
169
  ?>
170
  </div>
lib/view/import/index.php CHANGED
@@ -59,7 +59,7 @@
59
  <?php _e( 'When the file is uploaded successfully it will be automatically restored on the current WordPress instance.' ); ?>
60
  </p>
61
 
62
- <?php if ( $temp_dir ): ?>
63
  <div class="ai1wm-upload-file-message ai1wm-message"></div>
64
 
65
  <form action="" method="post" enctype="multipart/form-data">
@@ -89,10 +89,9 @@
89
  printf(
90
  _(
91
  'Site could not be imported!<br />
92
- Please make sure that PHP temporary directory <strong>%s</strong> has read and write permissions.
93
- <a href="https://servmask.com/blog/setting-permissions-for-temp-folder-on-windows" target="_blank">See how to do it?</a>'
94
  ),
95
- sys_get_temp_dir()
96
  );
97
  ?>
98
  </div>
59
  <?php _e( 'When the file is uploaded successfully it will be automatically restored on the current WordPress instance.' ); ?>
60
  </p>
61
 
62
+ <?php if ( $is_accessible ): ?>
63
  <div class="ai1wm-upload-file-message ai1wm-message"></div>
64
 
65
  <form action="" method="post" enctype="multipart/form-data">
89
  printf(
90
  _(
91
  'Site could not be imported!<br />
92
+ Please make sure that storage directory <strong>%s</strong> has read and write permissions.'
 
93
  ),
94
+ AI1WM_STORAGE_PATH
95
  );
96
  ?>
97
  </div>
loader.php CHANGED
@@ -54,6 +54,16 @@ require_once AI1WM_VENDOR_PATH .
54
  DIRECTORY_SEPARATOR .
55
  'ZipFactory.php';
56
 
 
 
 
 
 
 
 
 
 
 
57
  require_once AI1WM_CONTROLLER_PATH .
58
  DIRECTORY_SEPARATOR .
59
  'class-ai1wm-main-controller.php';
@@ -101,3 +111,4 @@ require_once AI1WM_MODEL_PATH .
101
  require_once AI1WM_MODEL_PATH .
102
  DIRECTORY_SEPARATOR .
103
  'class-ai1wm-report.php';
 
54
  DIRECTORY_SEPARATOR .
55
  'ZipFactory.php';
56
 
57
+ require_once AI1WM_VENDOR_PATH .
58
+ DIRECTORY_SEPARATOR .
59
+ 'storage-factory' .
60
+ DIRECTORY_SEPARATOR .
61
+ 'storage-factory' .
62
+ DIRECTORY_SEPARATOR .
63
+ 'lib' .
64
+ DIRECTORY_SEPARATOR .
65
+ 'StorageArea.php';
66
+
67
  require_once AI1WM_CONTROLLER_PATH .
68
  DIRECTORY_SEPARATOR .
69
  'class-ai1wm-main-controller.php';
111
  require_once AI1WM_MODEL_PATH .
112
  DIRECTORY_SEPARATOR .
113
  'class-ai1wm-report.php';
114
+
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: yani.iliev, bangelov, mirkov
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: 3.8
6
- Stable tag: 1.6.0
7
  License: GPLv2 or later
8
 
9
  All-in-One WP Migration is the only tools that you will ever needs when you need to perform site migration of your WordPress blog.
@@ -40,7 +40,7 @@ All in One WP Plugin is the first plugin to offer true mobile experience on Word
40
  * Your export files are archived using the fast ZipArchive pecl extension. If your server doesn't have it, we fall back to PclZIP which is included in WordPress
41
 
42
  = True WordPress v3.3 Support =
43
- * We tested every single WordPress version from `3.3` up to `3.8`
44
 
45
  = Coming soon in a commercial version =
46
  * A new, slicker design
@@ -70,6 +70,12 @@ All in One WP Plugin is the first plugin to offer true mobile experience on Word
70
  3. Plugin Menu
71
 
72
  == Changelog ==
 
 
 
 
 
 
73
  = 1.6.0 =
74
  * Added additional check for directory's permissions
75
  * Added additional check for output buffering when exporting a file
2
  Contributors: yani.iliev, bangelov, mirkov
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: 3.9
6
+ Stable tag: 1.7.0
7
  License: GPLv2 or later
8
 
9
  All-in-One WP Migration is the only tools that you will ever needs when you need to perform site migration of your WordPress blog.
40
  * Your export files are archived using the fast ZipArchive pecl extension. If your server doesn't have it, we fall back to PclZIP which is included in WordPress
41
 
42
  = True WordPress v3.3 Support =
43
+ * We tested every single WordPress version from `3.3` up to `3.9`
44
 
45
  = Coming soon in a commercial version =
46
  * A new, slicker design
70
  3. Plugin Menu
71
 
72
  == Changelog ==
73
+ = 1.7.0 =
74
+ * Added storage layer to avoid permission issues with OS's directory used for temporary storage
75
+ * Added additional checks to verify the consistency of the imported archive
76
+ * Fixed a bug that caused the database to be exported without data
77
+ * Removed unused variables from package.json file
78
+
79
  = 1.6.0 =
80
  * Added additional check for directory's permissions
81
  * Added additional check for output buffering when exporting a file