GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Branch dev (bf1ac2)
by Liuta
03:48
created
includes/class-xcloner-scheduler.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
 			$hook = 'xcloner_scheduler_'.$schedule->id;
105 105
 
106 106
 			if($timestamp = wp_next_scheduled($hook, array($schedule->id))) {
107
-                wp_unschedule_event($timestamp, $hook, array($schedule->id));
108
-            }
107
+				wp_unschedule_event($timestamp, $hook, array($schedule->id));
108
+			}
109 109
 		}
110 110
 	}
111 111
 
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
 
129 129
 			} elseif (!$schedule->status) {
130 130
 				if($timestamp = wp_next_scheduled($hook, array($schedule->id))) {
131
-                    wp_unschedule_event($timestamp, $hook, array($schedule->id));
132
-                }
131
+					wp_unschedule_event($timestamp, $hook, array($schedule->id));
132
+				}
133 133
 			}
134 134
 		}
135 135
 
@@ -140,8 +140,8 @@  discard block
 block discarded – undo
140 140
 		$hook     = 'xcloner_scheduler_'.$schedule->id;
141 141
 
142 142
 		if( $timestamp = wp_next_scheduled($hook, array($schedule->id))) {
143
-            wp_unschedule_event($timestamp, $hook, array($schedule->id));
144
-        }
143
+			wp_unschedule_event($timestamp, $hook, array($schedule->id));
144
+		}
145 145
 
146 146
 		if ($schedule->status) {
147 147
 
@@ -155,12 +155,12 @@  discard block
 block discarded – undo
155 155
 	}
156 156
 
157 157
 	public function disable_single_cron($schedule_id) {
158
-        $schedule = array();
158
+		$schedule = array();
159 159
 		$hook      = 'xcloner_scheduler_'.$schedule_id;
160 160
 
161 161
 		if($timestamp = wp_next_scheduled($hook, array($schedule_id))) {
162
-            wp_unschedule_event($timestamp, $hook, array($schedule_id));
163
-        }
162
+			wp_unschedule_event($timestamp, $hook, array($schedule_id));
163
+		}
164 164
 
165 165
 		$schedule['status'] = 0;
166 166
 
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	}
197 197
 
198 198
 	public function update_last_backup($schedule_id, $last_backup) {
199
-        $schedule = array();
199
+		$schedule = array();
200 200
 
201 201
 		$this->logger->info(sprintf('Updating last backup %s for schedule id #%s', $last_backup, $schedule_id));
202 202
 
@@ -222,9 +222,9 @@  discard block
 block discarded – undo
222 222
 		$xcloner = new XCloner();
223 223
 		$xcloner->init();
224 224
 		$this->set_xcloner_container( $xcloner );
225
-        $return_encrypted = array();
226
-        $return = array();
227
-        $additional = array();
225
+		$return_encrypted = array();
226
+		$return = array();
227
+		$additional = array();
228 228
 
229 229
 		#$hash = $this->xcloner_settings->get_hash();
230 230
 		#$this->get_xcloner_container()->get_xcloner_settings()->set_hash($hash);
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 		foreach ($list as $schedule) {
104 104
 			$hook = 'xcloner_scheduler_'.$schedule->id;
105 105
 
106
-			if($timestamp = wp_next_scheduled($hook, array($schedule->id))) {
106
+			if ($timestamp = wp_next_scheduled($hook, array($schedule->id))) {
107 107
                 wp_unschedule_event($timestamp, $hook, array($schedule->id));
108 108
             }
109 109
 		}
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 				}
128 128
 
129 129
 			} elseif (!$schedule->status) {
130
-				if($timestamp = wp_next_scheduled($hook, array($schedule->id))) {
130
+				if ($timestamp = wp_next_scheduled($hook, array($schedule->id))) {
131 131
                     wp_unschedule_event($timestamp, $hook, array($schedule->id));
132 132
                 }
133 133
 			}
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 		$schedule = $this->get_schedule_by_id_object($id);
140 140
 		$hook     = 'xcloner_scheduler_'.$schedule->id;
141 141
 
142
-		if( $timestamp = wp_next_scheduled($hook, array($schedule->id))) {
142
+		if ($timestamp = wp_next_scheduled($hook, array($schedule->id))) {
143 143
             wp_unschedule_event($timestamp, $hook, array($schedule->id));
144 144
         }
145 145
 
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
 
157 157
 	public function disable_single_cron($schedule_id) {
158 158
         $schedule = array();
159
-		$hook      = 'xcloner_scheduler_'.$schedule_id;
159
+		$hook = 'xcloner_scheduler_'.$schedule_id;
160 160
 
161
-		if($timestamp = wp_next_scheduled($hook, array($schedule_id))) {
161
+		if ($timestamp = wp_next_scheduled($hook, array($schedule_id))) {
162 162
             wp_unschedule_event($timestamp, $hook, array($schedule_id));
163 163
         }
164 164
 
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 		return $update;
178 178
 	}
179 179
 
180
-	public function update_hash( $schedule_id, $hash ) {
180
+	public function update_hash($schedule_id, $hash) {
181 181
 		$schedule = array();
182 182
 
183 183
 		$schedule['hash'] = $hash;
@@ -215,13 +215,13 @@  discard block
 block discarded – undo
215 215
 		return $update;
216 216
 	}
217 217
 
218
-	private function _xcloner_scheduler_callback( $id, $schedule ) {
219
-		set_time_limit( 0 );
218
+	private function _xcloner_scheduler_callback($id, $schedule) {
219
+		set_time_limit(0);
220 220
 
221 221
 
222 222
 		$xcloner = new XCloner();
223 223
 		$xcloner->init();
224
-		$this->set_xcloner_container( $xcloner );
224
+		$this->set_xcloner_container($xcloner);
225 225
         $return_encrypted = array();
226 226
         $return = array();
227 227
         $additional = array();
@@ -231,79 +231,79 @@  discard block
 block discarded – undo
231 231
 
232 232
 		//$this->xcloner_settings 		= $this->get_xcloner_container()->get_xcloner_settings();		
233 233
 		$this->xcloner_file_system    = $this->get_xcloner_container()->get_xcloner_filesystem();
234
-		$this->xcloner_encryption    = $this->get_xcloner_container()->get_xcloner_encryption();
234
+		$this->xcloner_encryption = $this->get_xcloner_container()->get_xcloner_encryption();
235 235
 		$this->xcloner_database       = $this->get_xcloner_container()->get_xcloner_database();
236 236
 		$this->archive_system         = $this->get_xcloner_container()->get_archive_system();
237
-		$this->logger                 = $this->get_xcloner_container()->get_xcloner_logger()->withName( "xcloner_scheduler" );
237
+		$this->logger                 = $this->get_xcloner_container()->get_xcloner_logger()->withName("xcloner_scheduler");
238 238
 		$this->xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
239 239
 
240
-		$this->logger->info( sprintf( "New schedule hash is %s", $this->xcloner_settings->get_hash() ) );
240
+		$this->logger->info(sprintf("New schedule hash is %s", $this->xcloner_settings->get_hash()));
241 241
 
242
-		if ( isset( $schedule['backup_params']->diff_start_date ) && $schedule['backup_params']->diff_start_date ) {
243
-			$this->xcloner_file_system->set_diff_timestamp_start( $schedule['backup_params']->diff_start_date );
242
+		if (isset($schedule['backup_params']->diff_start_date) && $schedule['backup_params']->diff_start_date) {
243
+			$this->xcloner_file_system->set_diff_timestamp_start($schedule['backup_params']->diff_start_date);
244 244
 		}
245 245
 
246
-		if ( $schedule['recurrence'] == "single" ) {
247
-			$this->disable_single_cron( $schedule['id'] );
246
+		if ($schedule['recurrence'] == "single") {
247
+			$this->disable_single_cron($schedule['id']);
248 248
 		}
249 249
 
250
-		if ( ! $schedule ) {
251
-			$this->logger->info( sprintf( "Could not load schedule with id'%s'", $id ), array( "CRON" ) );
250
+		if (!$schedule) {
251
+			$this->logger->info(sprintf("Could not load schedule with id'%s'", $id), array("CRON"));
252 252
 
253 253
 			return;
254 254
 		}
255 255
 
256 256
 		//echo $this->get_xcloner_container()->get_xcloner_settings()->get_hash(); exit;
257 257
 
258
-		$this->update_hash( $schedule['id'], $this->xcloner_settings->get_hash() );
258
+		$this->update_hash($schedule['id'], $this->xcloner_settings->get_hash());
259 259
 
260
-		$this->logger->info( sprintf( "Starting cron schedule '%s'", $schedule['name'] ), array( "CRON" ) );
260
+		$this->logger->info(sprintf("Starting cron schedule '%s'", $schedule['name']), array("CRON"));
261 261
 
262
-		$this->xcloner_file_system->set_excluded_files( json_decode( $schedule['excluded_files'] ) );
262
+		$this->xcloner_file_system->set_excluded_files(json_decode($schedule['excluded_files']));
263 263
 
264 264
 		$init     = 1;
265 265
 		$continue = 1;
266 266
 
267
-		while ( $continue ) {
268
-			$continue = $this->xcloner_file_system->start_file_recursion( $init );
267
+		while ($continue) {
268
+			$continue = $this->xcloner_file_system->start_file_recursion($init);
269 269
 
270 270
 			$init = 0;
271 271
 		}
272 272
 
273
-		$this->logger->info( sprintf( "File scan finished" ), array( "CRON" ) );
273
+		$this->logger->info(sprintf("File scan finished"), array("CRON"));
274 274
 
275
-		$this->logger->info( sprintf( "Starting the database backup" ), array( "CRON" ) );
275
+		$this->logger->info(sprintf("Starting the database backup"), array("CRON"));
276 276
 
277 277
 		$init               = 1;
278 278
 		$return['finished'] = 0;
279 279
 
280
-		while ( ! $return['finished'] ) {
281
-			$return = $this->xcloner_database->start_database_recursion( (array) json_decode( $schedule['table_params'] ), $return, $init );
280
+		while (!$return['finished']) {
281
+			$return = $this->xcloner_database->start_database_recursion((array)json_decode($schedule['table_params']), $return, $init);
282 282
 			$init   = 0;
283 283
 		}
284 284
 
285
-		$this->logger->info( sprintf( "Database backup done" ), array( "CRON" ) );
285
+		$this->logger->info(sprintf("Database backup done"), array("CRON"));
286 286
 
287
-		$this->logger->info( sprintf( "Starting file archive process" ), array( "CRON" ) );
287
+		$this->logger->info(sprintf("Starting file archive process"), array("CRON"));
288 288
 
289 289
 		$init               = 0;
290 290
 		$return['finished'] = 0;
291 291
 		$return['extra']    = array();
292 292
 
293
-		while ( ! $return['finished'] ) {
294
-			$return = $this->archive_system->start_incremental_backup( (array) $schedule['backup_params'], $return['extra'], $init );
293
+		while (!$return['finished']) {
294
+			$return = $this->archive_system->start_incremental_backup((array)$schedule['backup_params'], $return['extra'], $init);
295 295
 			$init   = 0;
296 296
 		}
297
-		$this->logger->info( sprintf( "File archive process FINISHED." ), array( "CRON" ) );
297
+		$this->logger->info(sprintf("File archive process FINISHED."), array("CRON"));
298 298
 
299 299
 		//getting the last backup archive file
300 300
 		$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension();
301
-		if ( $this->xcloner_file_system->is_part( $this->archive_system->get_archive_name_with_extension() ) ) {
301
+		if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) {
302 302
 			$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
303 303
 		}
304 304
 
305 305
 		//Updating schedule last backup archive
306
-		$this->update_last_backup( $schedule['id'], $return['extra']['backup_parent'] );
306
+		$this->update_last_backup($schedule['id'], $return['extra']['backup_parent']);
307 307
 
308 308
 		//Encrypting the backup archive
309 309
 		$return_encrypted['finished'] = 0;
@@ -313,8 +313,8 @@  discard block
 block discarded – undo
313 313
 		$part = 0;
314 314
 		$backup_parts = array();
315 315
 
316
-		if( $schedule['backup_params']->backup_encrypt){
317
-			$this->logger->info( sprintf( "Encrypting backup archive %s.", $return['extra']['backup_parent'] ), array( "CRON" ) );
316
+		if ($schedule['backup_params']->backup_encrypt) {
317
+			$this->logger->info(sprintf("Encrypting backup archive %s.", $return['extra']['backup_parent']), array("CRON"));
318 318
 
319 319
 			$backup_file = $return['extra']['backup_parent'];
320 320
 
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 				$backup_file = $backup_parts[$part];
324 324
 			}
325 325
 
326
-			while ( ! $return_encrypted['finished'] ) {
326
+			while (!$return_encrypted['finished']) {
327 327
 				$return_encrypted = $this->xcloner_encryption->encrypt_file(
328 328
 											$backup_file,
329 329
 											"",
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
 											true
335 335
 				);
336 336
 
337
-				if($return_encrypted['finished']) {
337
+				if ($return_encrypted['finished']) {
338 338
 					++$part;
339 339
 
340 340
 					if ($part < sizeof($backup_parts)) {
@@ -346,37 +346,37 @@  discard block
 block discarded – undo
346 346
 		}
347 347
 
348 348
 		//Sending backup to remote storage
349
-		if ( isset( $schedule['remote_storage'] ) && $schedule['remote_storage'] && array_key_exists( $schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages() ) ) {
349
+		if (isset($schedule['remote_storage']) && $schedule['remote_storage'] && array_key_exists($schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages())) {
350 350
 			$backup_file = $return['extra']['backup_parent'];
351 351
 
352
-			$this->logger->info( sprintf( "Transferring backup to remote storage %s", strtoupper( $schedule['remote_storage'] ) ), array( "CRON" ) );
352
+			$this->logger->info(sprintf("Transferring backup to remote storage %s", strtoupper($schedule['remote_storage'])), array("CRON"));
353 353
 
354
-			if ( method_exists( $this->xcloner_remote_storage, "upload_backup_to_storage" ) ) {
355
-				call_user_func_array( array(
354
+			if (method_exists($this->xcloner_remote_storage, "upload_backup_to_storage")) {
355
+				call_user_func_array(array(
356 356
 					$this->xcloner_remote_storage,
357 357
 					"upload_backup_to_storage"
358
-				), array( $backup_file, $schedule['remote_storage'] ) );
358
+				), array($backup_file, $schedule['remote_storage']));
359 359
 			}
360 360
 		}
361 361
 
362 362
 		//Sending email notification
363
-		if ( isset( $schedule['backup_params']->email_notification ) and $to = $schedule['backup_params']->email_notification ) {
363
+		if (isset($schedule['backup_params']->email_notification) and $to = $schedule['backup_params']->email_notification) {
364 364
 			try {
365 365
 				$from                      = "";
366 366
 				$additional['lines_total'] = $return['extra']['lines_total'];
367
-				$subject                   = sprintf( __( "%s - new backup generated %s" ), $schedule['name'], $return['extra']['backup_parent'] );
367
+				$subject                   = sprintf(__("%s - new backup generated %s"), $schedule['name'], $return['extra']['backup_parent']);
368 368
 
369
-				$this->archive_system->send_notification( $to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional );
369
+				$this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional);
370 370
 
371
-			} catch ( Exception $e ) {
372
-				$this->logger->error( $e->getMessage() );
371
+			}catch (Exception $e) {
372
+				$this->logger->error($e->getMessage());
373 373
 			}
374 374
 		}
375 375
 
376 376
 		//CHECK IF WE SHOULD DELETE BACKUP AFTER REMOTE TRANSFER IS DONE
377
-		if ( $schedule['remote_storage'] && $this->xcloner_settings->get_xcloner_option( 'xcloner_cleanup_delete_after_remote_transfer' ) ) {
378
-			$this->logger->info( sprintf( "Deleting %s from local storage matching rule xcloner_cleanup_delete_after_remote_transfer", $return['extra']['backup_parent'] ) );
379
-			$this->xcloner_file_system->delete_backup_by_name( $return['extra']['backup_parent'] );
377
+		if ($schedule['remote_storage'] && $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_delete_after_remote_transfer')) {
378
+			$this->logger->info(sprintf("Deleting %s from local storage matching rule xcloner_cleanup_delete_after_remote_transfer", $return['extra']['backup_parent']));
379
+			$this->xcloner_file_system->delete_backup_by_name($return['extra']['backup_parent']);
380 380
 
381 381
 		}
382 382
 
@@ -390,28 +390,28 @@  discard block
 block discarded – undo
390 390
 		$this->xcloner_file_system->cleanup_tmp_directories();
391 391
 	}
392 392
 
393
-	public function xcloner_scheduler_callback( $id, $schedule = "" ) {
394
-		if ( $id ) {
395
-			$schedule = $this->get_schedule_by_id( $id );
393
+	public function xcloner_scheduler_callback($id, $schedule = "") {
394
+		if ($id) {
395
+			$schedule = $this->get_schedule_by_id($id);
396 396
 		}
397 397
 
398 398
 		try {
399
-			if( get_option('xcloner_disable_email_notification') ) {
399
+			if (get_option('xcloner_disable_email_notification')) {
400 400
 				//we disable email notifications
401 401
 				$schedule['backup_params']->email_notification = "";
402 402
 			}
403
-			$this->_xcloner_scheduler_callback( $id, $schedule );
403
+			$this->_xcloner_scheduler_callback($id, $schedule);
404 404
 
405
-		} catch ( Exception $e ) {
405
+		}catch (Exception $e) {
406 406
 
407 407
 			//send email to site admin if email notification is not set in the scheduler
408
-			if ( ! isset( $schedule['backup_params']->email_notification ) || ! $schedule['backup_params']->email_notification ) {
409
-				$schedule['backup_params']->email_notification = get_option( 'admin_email' );
408
+			if (!isset($schedule['backup_params']->email_notification) || !$schedule['backup_params']->email_notification) {
409
+				$schedule['backup_params']->email_notification = get_option('admin_email');
410 410
 			}
411 411
 
412
-			if ( isset( $schedule['backup_params']->email_notification ) && $to = $schedule['backup_params']->email_notification ) {
412
+			if (isset($schedule['backup_params']->email_notification) && $to = $schedule['backup_params']->email_notification) {
413 413
 				$from = "";
414
-				$this->archive_system->send_notification( $to, $from, $schedule['name'] . " - backup error", "", "", $e->getMessage() );
414
+				$this->archive_system->send_notification($to, $from, $schedule['name']." - backup error", "", "", $e->getMessage());
415 415
 			}
416 416
 
417 417
 		}
Please login to merge, or discard this patch.
includes/class-xcloner-file-system.php 3 patches
Indentation   +979 added lines, -979 removed lines patch added patch discarded remove patch
@@ -37,861 +37,861 @@  discard block
 block discarded – undo
37 37
 class Xcloner_File_System
38 38
 {
39 39
 
40
-    private $excluded_files = "";
41
-    private $additional_regex_patterns = array();
42
-    private $excluded_files_by_default = array("administrator/backups", "wp-content/backups");
43
-    private $included_files_handler = "backup_files.csv";
44
-    private $temp_dir_handler = ".dir";
45
-    public $filesystem;
46
-    public $tmp_filesystem;
47
-    public $storage_filesystem;
48
-    private $xcloner_container;
49
-    private $diff_timestamp_start = "";
50
-
51
-    private $logger;
52
-    private $start_adapter;
53
-    private $tmp_adapter;
54
-    private $storage_adapter;
55
-    private $xcloner_settings;
56
-    private $start_filesystem;
57
-    private $tmp_filesystem_append;
58
-    private $storage_filesystem_append;
59
-
60
-    private $files_counter;
61
-    private $files_size;
62
-    private $last_logged_file;
63
-    private $folders_to_process_per_session = 25;
64
-    private $backup_archive_extensions = array("tar", "tgz", "tar.gz", "gz", "csv", "encrypted", "decrypted");
65
-    private $backup_name_tags = array('[time]', '[hostname]', '[domain]');
66
-
67
-    /**
68
-     * Xcloner_File_System constructor.
69
-     * @param Xcloner $xcloner_container
70
-     * @param string $hash
71
-     */
72
-    public function __construct(Xcloner $xcloner_container, $hash = "")
73
-    {
74
-        $this->xcloner_container = $xcloner_container;
75
-
76
-        $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_file_system");
77
-        $this->xcloner_settings = $xcloner_container->get_xcloner_settings();
78
-
79
-        try {
80
-
81
-            $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS');
82
-            $this->start_filesystem = new Filesystem($this->start_adapter, new Config([
83
-                'disable_asserts' => true,
84
-            ]));
85
-
86
-            $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS');
87
-            $this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([
88
-                'disable_asserts' => true,
89
-            ]));
90
-            $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
91
-            $this->tmp_filesystem_append = new Filesystem($adapter, new Config([
92
-                'disable_asserts' => true,
93
-            ]));
94
-
95
-            $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS');
96
-            $this->storage_filesystem = new Filesystem($adapter, new Config([
97
-                'disable_asserts' => true,
98
-            ]));
99
-
100
-            $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND,
101
-                'SKIP_LINKS');
102
-            $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([
103
-                'disable_asserts' => true,
104
-            ]));
105
-        }catch (Exception $e) {
106
-            $this->logger->error("Filesystem Initialization Error: ".$e->getMessage());
107
-        }
108
-
109
-
110
-        if ($value = get_option('xcloner_directories_to_scan_per_request')) {
111
-            $this->folders_to_process_per_session = $value;
112
-        }
113
-
114
-    }
115
-
116
-    /**
117
-     * Set differential timestamp date
118
-     * @param string $timestamp
119
-     */
120
-    public function set_diff_timestamp_start($timestamp = "")
121
-    {
122
-        if ($timestamp) {
123
-            $this->logger->info(sprintf("Setting Differential Timestamp To %s", date("Y-m-d", $timestamp)), array(
124
-                "FILESYSTEM",
125
-                "DIFF"
126
-            ));
127
-            $this->diff_timestamp_start = $timestamp;
128
-        }
129
-    }
130
-
131
-    /**
132
-     * Gets the differential timestamp date
133
-     * @return string
134
-     */
135
-    public function get_diff_timestamp_start()
136
-    {
137
-        return $this->diff_timestamp_start;
138
-    }
139
-
140
-    private function get_xcloner_container()
141
-    {
142
-        return $this->xcloner_container;
143
-    }
144
-
145
-    public function set_hash($hash)
146
-    {
147
-        $this->xcloner_settings->set_hash($hash);
148
-    }
149
-
150
-    public function get_hash($hash)
151
-    {
152
-        $this->xcloner_settings->get_hash();
153
-    }
154
-
155
-    public function get_tmp_filesystem()
156
-    {
157
-        return $this->tmp_filesystem;
158
-    }
159
-
160
-    public function get_storage_filesystem($remote_storage_selection = "")
161
-    {
162
-        if ($remote_storage_selection != "") {
163
-            $remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
164
-            $method = "get_".$remote_storage_selection."_filesystem";
165
-
166
-            if (!method_exists($remote_storage, $method)) {
167
-                return false;
168
-            }
169
-
170
-            list($adapter, $filesystem) = $remote_storage->$method();
171
-
172
-            return $filesystem;
173
-        }
174
-
175
-        return $this->storage_filesystem;
176
-    }
177
-
178
-    public function get_tmp_filesystem_adapter()
179
-    {
180
-        return $this->tmp_adapter;
181
-    }
182
-
183
-    public function get_tmp_filesystem_append()
184
-    {
185
-        return $this->tmp_filesystem_append;
186
-    }
187
-
188
-    public function get_start_adapter()
189
-    {
190
-        return $this->start_adapter;
191
-    }
192
-
193
-    public function get_start_filesystem()
194
-    {
195
-        return $this->start_filesystem;
196
-    }
197
-
198
-    public function get_logger()
199
-    {
200
-        return $this->logger;
201
-    }
202
-
203
-    public function get_start_path_file_info($file)
204
-    {
205
-        $info = $this->getMetadataFull('start_adapter', $file);
206
-
207
-        return $this->start_filesystem->normalizeFileInfo($info);
208
-    }
209
-
210
-    /**
211
-     * @param string $file
212
-     */
213
-    public function get_storage_path_file_info($file)
214
-    {
215
-        return $this->getMetadataFull('storage_adapter', $file);
216
-    }
217
-
218
-    public function get_included_files_handler($metadata = 0)
219
-    {
220
-        $path = $this->included_files_handler;
221
-        if (!$metadata) {
222
-            return $path;
223
-        }
224
-
225
-        $spl_info = $this->getMetadataFull('tmp_adapter', $path);
226
-
227
-        return $spl_info;
228
-
229
-    }
230
-
231
-    public function get_temp_dir_handler()
232
-    {
233
-        return $this->temp_dir_handler;
234
-    }
235
-
236
-    public function get_latest_backup()
237
-    {
238
-        $files = $this->get_backup_archives_list();
239
-
240
-        if (is_array($files)) {
241
-            $this->sort_by($files, "timestamp", "desc");
242
-        }
243
-
244
-        $new_list = array();
245
-
246
-        foreach ($files as $key => $file) {
247
-            if (!isset($file['parent'])) {
248
-                $new_list[] = ($files[$key]);
249
-            }
250
-        }
251
-
252
-        if (isset($new_list[0])) {
253
-            return $new_list[0];
254
-        }
255
-    }
256
-
257
-    public function get_latest_backups()
258
-    {
259
-        $files = $this->get_backup_archives_list();
260
-
261
-        if (is_array($files)) {
262
-            $this->sort_by($files, "timestamp", "desc");
263
-        }
264
-
265
-        $new_list = array();
266
-
267
-        foreach ($files as $key => $file) {
268
-            if (!isset($file['parent'])) {
269
-                $new_list[] = ($files[$key]);
270
-            }
271
-        }
272
-
273
-        return $new_list;
274
-    }
275
-
276
-    public function get_storage_usage()
277
-    {
278
-        $files = $this->get_backup_archives_list();
279
-        $total = 0;
280
-
281
-        if (is_array($files)) {
282
-            foreach ($files as $file) {
283
-                $total += $file['size'];
284
-            }
285
-        }
286
-
287
-        return $total;
288
-    }
289
-
290
-    public function is_part($backup_name)
291
-    {
292
-        if (stristr($backup_name, "-part")) {
293
-            return true;
294
-        }
295
-
296
-        return false;
297
-    }
298
-
299
-    public function is_multipart($backup_name)
300
-    {
301
-        if (stristr($backup_name, "-multipart")) {
302
-            return true;
303
-        }
304
-
305
-        return false;
306
-    }
307
-
308
-    public function get_backup_size($backup_name)
309
-    {
310
-        $backup_size = $this->get_storage_filesystem()->getSize($backup_name);
311
-        if ($this->is_multipart($backup_name)) {
312
-            $backup_parts = $this->get_multipart_files($backup_name);
313
-            foreach ($backup_parts as $part_file) {
314
-                $backup_size += $this->get_storage_filesystem()->getSize($part_file);
315
-            }
316
-        }
317
-
318
-        return $backup_size;
319
-    }
320
-
321
-    public function get_multipart_files($backup_name, $storage_selection = "")
322
-    {
323
-        $files = array();
324
-
325
-        if ($this->is_multipart($backup_name)) {
326
-            $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
327
-            foreach ($lines as $line) {
328
-                if ($line) {
329
-                    $data = str_getcsv($line);
330
-                    $files[] = $data[0];
331
-                }
332
-            }
333
-        }
334
-
335
-        return $files;
336
-    }
337
-
338
-    public function delete_backup_by_name($backup_name, $storage_selection = "")
339
-    {
340
-        if ($this->is_multipart($backup_name)) {
341
-            $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
342
-            foreach ($lines as $line) {
343
-                if ($line) {
344
-                    $data = str_getcsv($line);
345
-                    $this->get_storage_filesystem($storage_selection)->delete($data[0]);
346
-                }
347
-            }
348
-        }
349
-
350
-        if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) {
351
-            $return = true;
352
-        } else {
353
-            $return = false;
354
-        }
355
-
356
-        return $return;
357
-    }
358
-
359
-    public function getMetadataFull($adapter = "storage_adapter", $path)
360
-    {
361
-        $location = $this->$adapter->applyPathPrefix($path);
362
-        $spl_info = new SplFileInfo($location);
363
-
364
-        return ($spl_info);
365
-    }
366
-
367
-
368
-    public function get_backup_archives_list($storage_selection = "")
369
-    {
370
-        $list = array();
371
-
372
-
373
-        if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) {
374
-            $list = $this->get_storage_filesystem($storage_selection)->listContents();
375
-        }
376
-
377
-        $backup_files = array();
378
-        $parents = array();
379
-
380
-        foreach ($list as $file_info) {
381
-            if (isset($file_info['extension']) and $file_info['extension'] == "csv") {
382
-                $data = array();
383
-
384
-                $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path']));
385
-                foreach ($lines as $line) {
386
-                    if ($line) {
387
-                        $data = str_getcsv($line);
388
-                        if (is_array($data)) {
389
-                            $parents[$data[0]] = $file_info['basename'];
390
-                            $file_info['childs'][] = $data;
391
-                            $file_info['size'] += $data[2];
392
-                        }
393
-                    }
394
-                }
395
-
396
-            }
397
-
398
-            if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'],
399
-                    $this->backup_archive_extensions)) {
400
-                $backup_files[$file_info['path']] = $file_info;
401
-            }
402
-        }
403
-
404
-        foreach ($backup_files as $key => $file_info) {
405
-            if (!isset($backup_files[$key]['timestamp'])) {
406
-                //$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']);
407
-            }
408
-
409
-            if (isset($parents[$file_info['basename']])) {
410
-                $backup_files[$key]['parent'] = $parents[$file_info['basename']];
411
-            }
412
-        }
413
-
414
-        return $backup_files;
415
-    }
416
-
417
-    public function start_file_recursion($init = 0)
418
-    {
419
-        if ($init) {
420
-            $this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"),
421
-                $this->xcloner_settings->get_xcloner_start_path()));
422
-            $this->do_system_init();
423
-        }
424
-
425
-        if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
426
-            //.dir exists, we presume we have files to iterate
427
-            $content = $this->tmp_filesystem->read($this->get_temp_dir_handler());
428
-            $files = array_filter(explode("\n", $content));
429
-            $this->tmp_filesystem->delete($this->get_temp_dir_handler());
430
-
431
-            $counter = 0;
432
-            foreach ($files as $file) {
433
-                if ($counter < $this->folders_to_process_per_session) {
434
-                    $this->build_files_list($file);
435
-                    $counter++;
436
-                } else {
437
-                    $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n");
438
-                }
439
-            }
440
-        } else {
441
-            $this->build_files_list();
442
-        }
443
-
444
-        if ($this->scan_finished()) {
445
-            $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html");
446
-            $this->store_file($metadata_dumpfile, 'tmp_filesystem');
447
-            $this->files_counter++;
448
-
449
-            //adding included dump file to the included files list
450
-            if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) {
451
-                $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler());
452
-                $this->store_file($metadata_dumpfile, 'tmp_filesystem');
453
-                $this->files_counter++;
454
-            }
455
-
456
-            //adding a default index.html to the temp xcloner folder
457
-            if (!$this->get_tmp_filesystem()->has("index.html")) {
458
-                $this->get_tmp_filesystem()->write("index.html", "");
459
-            }
460
-
461
-            //adding the default log file
462
-            if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) {
463
-                $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1));
464
-                $this->store_file($metadata_dumpfile, 'tmp_filesystem');
465
-                $this->files_counter++;
466
-            }
467
-
468
-            return false;
469
-        }
470
-
471
-        return true;
472
-    }
473
-
474
-    public function get_backup_attachments()
475
-    {
476
-        $return = array();
477
-
478
-        $files_list_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler();
479
-        if (file_exists($files_list_file)) {
480
-            $return[] = $files_list_file;
481
-        }
482
-
483
-        if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
484
-            $log_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
485
-            if (!file_exists($log_file)) {
486
-                $log_file = $this->xcloner_settings->get_xcloner_store_path().DS.$this->xcloner_settings->get_logger_filename();
487
-            }
488
-
489
-            if (file_exists($log_file)) {
490
-                $return[] = $log_file;
491
-            }
492
-        }
493
-
494
-        return $return;
495
-    }
496
-
497
-    public function remove_tmp_filesystem()
498
-    {
499
-        //delete the temporary folder
500
-        $this->logger->debug(sprintf("Deleting the temporary storage folder %s",
501
-            $this->xcloner_settings->get_xcloner_tmp_path()));
502
-
503
-        $contents = $this->get_tmp_filesystem()->listContents();
504
-
505
-        if (is_array($contents)) {
506
-            foreach ($contents as $file_info) {
507
-                $this->get_tmp_filesystem()->delete($file_info['path']);
508
-            }
509
-        }
510
-
511
-        try{
512
-            rmdir($this->xcloner_settings->get_xcloner_tmp_path());
513
-        }catch(Exception $e){
514
-            //silent continue
515
-        }
516
-
517
-        return;
518
-    }
519
-
520
-    public function cleanup_tmp_directories()
521
-    {
522
-        $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
523
-        $tmp_filesystem = new Filesystem($adapter, new Config([
524
-            'disable_asserts' => true,
525
-        ]));
526
-
527
-        $contents = $tmp_filesystem->listContents();
528
-
529
-        foreach ($contents as $file) {
530
-
531
-            if (preg_match("/.xcloner-(.*)/", $file['path'])) {
532
-                if ($file['timestamp'] < strtotime("-1days")) {
533
-                    $tmp_filesystem->deleteDir($file['path']);
534
-                    $this->logger->debug(sprintf("Delete temporary directory %s", $file['path']));
535
-                }
536
-            }
537
-        }
538
-
539
-        return true;
540
-    }
541
-
542
-    private function do_system_init()
543
-    {
544
-        $this->files_counter = 0;
545
-
546
-        if (!$this->storage_filesystem->has("index.html")) {
547
-            $this->storage_filesystem->write("index.html", "");
548
-        }
549
-
550
-        if (!$this->tmp_filesystem->has("index.html")) {
551
-            $this->tmp_filesystem->write("index.html", "");
552
-        }
553
-
554
-        if ($this->tmp_filesystem->has($this->get_included_files_handler())) {
555
-            $this->tmp_filesystem->delete($this->get_included_files_handler());
556
-        }
557
-
558
-        if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
559
-            $this->tmp_filesystem->delete($this->get_temp_dir_handler());
560
-        }
561
-    }
562
-
563
-    public function get_scanned_files_num()
564
-    {
565
-        return $this->files_counter;
566
-    }
567
-
568
-    public function get_scanned_files_total_size()
569
-    {
570
-        return $this->files_size;
571
-    }
572
-
573
-    public function last_logged_file()
574
-    {
575
-        return $this->last_logged_file;
576
-    }
577
-
578
-    public static function is_regex($regex)
579
-    {
580
-        return preg_match("/^\^(.*)\$$/i", $regex);
581
-    }
40
+	private $excluded_files = "";
41
+	private $additional_regex_patterns = array();
42
+	private $excluded_files_by_default = array("administrator/backups", "wp-content/backups");
43
+	private $included_files_handler = "backup_files.csv";
44
+	private $temp_dir_handler = ".dir";
45
+	public $filesystem;
46
+	public $tmp_filesystem;
47
+	public $storage_filesystem;
48
+	private $xcloner_container;
49
+	private $diff_timestamp_start = "";
50
+
51
+	private $logger;
52
+	private $start_adapter;
53
+	private $tmp_adapter;
54
+	private $storage_adapter;
55
+	private $xcloner_settings;
56
+	private $start_filesystem;
57
+	private $tmp_filesystem_append;
58
+	private $storage_filesystem_append;
59
+
60
+	private $files_counter;
61
+	private $files_size;
62
+	private $last_logged_file;
63
+	private $folders_to_process_per_session = 25;
64
+	private $backup_archive_extensions = array("tar", "tgz", "tar.gz", "gz", "csv", "encrypted", "decrypted");
65
+	private $backup_name_tags = array('[time]', '[hostname]', '[domain]');
66
+
67
+	/**
68
+	 * Xcloner_File_System constructor.
69
+	 * @param Xcloner $xcloner_container
70
+	 * @param string $hash
71
+	 */
72
+	public function __construct(Xcloner $xcloner_container, $hash = "")
73
+	{
74
+		$this->xcloner_container = $xcloner_container;
75
+
76
+		$this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_file_system");
77
+		$this->xcloner_settings = $xcloner_container->get_xcloner_settings();
78
+
79
+		try {
80
+
81
+			$this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS');
82
+			$this->start_filesystem = new Filesystem($this->start_adapter, new Config([
83
+				'disable_asserts' => true,
84
+			]));
85
+
86
+			$this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS');
87
+			$this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([
88
+				'disable_asserts' => true,
89
+			]));
90
+			$adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
91
+			$this->tmp_filesystem_append = new Filesystem($adapter, new Config([
92
+				'disable_asserts' => true,
93
+			]));
94
+
95
+			$adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS');
96
+			$this->storage_filesystem = new Filesystem($adapter, new Config([
97
+				'disable_asserts' => true,
98
+			]));
99
+
100
+			$this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND,
101
+				'SKIP_LINKS');
102
+			$this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([
103
+				'disable_asserts' => true,
104
+			]));
105
+		}catch (Exception $e) {
106
+			$this->logger->error("Filesystem Initialization Error: ".$e->getMessage());
107
+		}
108
+
109
+
110
+		if ($value = get_option('xcloner_directories_to_scan_per_request')) {
111
+			$this->folders_to_process_per_session = $value;
112
+		}
113
+
114
+	}
115
+
116
+	/**
117
+	 * Set differential timestamp date
118
+	 * @param string $timestamp
119
+	 */
120
+	public function set_diff_timestamp_start($timestamp = "")
121
+	{
122
+		if ($timestamp) {
123
+			$this->logger->info(sprintf("Setting Differential Timestamp To %s", date("Y-m-d", $timestamp)), array(
124
+				"FILESYSTEM",
125
+				"DIFF"
126
+			));
127
+			$this->diff_timestamp_start = $timestamp;
128
+		}
129
+	}
130
+
131
+	/**
132
+	 * Gets the differential timestamp date
133
+	 * @return string
134
+	 */
135
+	public function get_diff_timestamp_start()
136
+	{
137
+		return $this->diff_timestamp_start;
138
+	}
139
+
140
+	private function get_xcloner_container()
141
+	{
142
+		return $this->xcloner_container;
143
+	}
144
+
145
+	public function set_hash($hash)
146
+	{
147
+		$this->xcloner_settings->set_hash($hash);
148
+	}
149
+
150
+	public function get_hash($hash)
151
+	{
152
+		$this->xcloner_settings->get_hash();
153
+	}
154
+
155
+	public function get_tmp_filesystem()
156
+	{
157
+		return $this->tmp_filesystem;
158
+	}
159
+
160
+	public function get_storage_filesystem($remote_storage_selection = "")
161
+	{
162
+		if ($remote_storage_selection != "") {
163
+			$remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
164
+			$method = "get_".$remote_storage_selection."_filesystem";
165
+
166
+			if (!method_exists($remote_storage, $method)) {
167
+				return false;
168
+			}
169
+
170
+			list($adapter, $filesystem) = $remote_storage->$method();
171
+
172
+			return $filesystem;
173
+		}
174
+
175
+		return $this->storage_filesystem;
176
+	}
177
+
178
+	public function get_tmp_filesystem_adapter()
179
+	{
180
+		return $this->tmp_adapter;
181
+	}
182
+
183
+	public function get_tmp_filesystem_append()
184
+	{
185
+		return $this->tmp_filesystem_append;
186
+	}
187
+
188
+	public function get_start_adapter()
189
+	{
190
+		return $this->start_adapter;
191
+	}
192
+
193
+	public function get_start_filesystem()
194
+	{
195
+		return $this->start_filesystem;
196
+	}
197
+
198
+	public function get_logger()
199
+	{
200
+		return $this->logger;
201
+	}
202
+
203
+	public function get_start_path_file_info($file)
204
+	{
205
+		$info = $this->getMetadataFull('start_adapter', $file);
206
+
207
+		return $this->start_filesystem->normalizeFileInfo($info);
208
+	}
209
+
210
+	/**
211
+	 * @param string $file
212
+	 */
213
+	public function get_storage_path_file_info($file)
214
+	{
215
+		return $this->getMetadataFull('storage_adapter', $file);
216
+	}
217
+
218
+	public function get_included_files_handler($metadata = 0)
219
+	{
220
+		$path = $this->included_files_handler;
221
+		if (!$metadata) {
222
+			return $path;
223
+		}
224
+
225
+		$spl_info = $this->getMetadataFull('tmp_adapter', $path);
226
+
227
+		return $spl_info;
228
+
229
+	}
230
+
231
+	public function get_temp_dir_handler()
232
+	{
233
+		return $this->temp_dir_handler;
234
+	}
235
+
236
+	public function get_latest_backup()
237
+	{
238
+		$files = $this->get_backup_archives_list();
239
+
240
+		if (is_array($files)) {
241
+			$this->sort_by($files, "timestamp", "desc");
242
+		}
243
+
244
+		$new_list = array();
245
+
246
+		foreach ($files as $key => $file) {
247
+			if (!isset($file['parent'])) {
248
+				$new_list[] = ($files[$key]);
249
+			}
250
+		}
251
+
252
+		if (isset($new_list[0])) {
253
+			return $new_list[0];
254
+		}
255
+	}
256
+
257
+	public function get_latest_backups()
258
+	{
259
+		$files = $this->get_backup_archives_list();
260
+
261
+		if (is_array($files)) {
262
+			$this->sort_by($files, "timestamp", "desc");
263
+		}
264
+
265
+		$new_list = array();
266
+
267
+		foreach ($files as $key => $file) {
268
+			if (!isset($file['parent'])) {
269
+				$new_list[] = ($files[$key]);
270
+			}
271
+		}
272
+
273
+		return $new_list;
274
+	}
275
+
276
+	public function get_storage_usage()
277
+	{
278
+		$files = $this->get_backup_archives_list();
279
+		$total = 0;
280
+
281
+		if (is_array($files)) {
282
+			foreach ($files as $file) {
283
+				$total += $file['size'];
284
+			}
285
+		}
286
+
287
+		return $total;
288
+	}
289
+
290
+	public function is_part($backup_name)
291
+	{
292
+		if (stristr($backup_name, "-part")) {
293
+			return true;
294
+		}
295
+
296
+		return false;
297
+	}
298
+
299
+	public function is_multipart($backup_name)
300
+	{
301
+		if (stristr($backup_name, "-multipart")) {
302
+			return true;
303
+		}
304
+
305
+		return false;
306
+	}
307
+
308
+	public function get_backup_size($backup_name)
309
+	{
310
+		$backup_size = $this->get_storage_filesystem()->getSize($backup_name);
311
+		if ($this->is_multipart($backup_name)) {
312
+			$backup_parts = $this->get_multipart_files($backup_name);
313
+			foreach ($backup_parts as $part_file) {
314
+				$backup_size += $this->get_storage_filesystem()->getSize($part_file);
315
+			}
316
+		}
317
+
318
+		return $backup_size;
319
+	}
320
+
321
+	public function get_multipart_files($backup_name, $storage_selection = "")
322
+	{
323
+		$files = array();
324
+
325
+		if ($this->is_multipart($backup_name)) {
326
+			$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
327
+			foreach ($lines as $line) {
328
+				if ($line) {
329
+					$data = str_getcsv($line);
330
+					$files[] = $data[0];
331
+				}
332
+			}
333
+		}
334
+
335
+		return $files;
336
+	}
337
+
338
+	public function delete_backup_by_name($backup_name, $storage_selection = "")
339
+	{
340
+		if ($this->is_multipart($backup_name)) {
341
+			$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
342
+			foreach ($lines as $line) {
343
+				if ($line) {
344
+					$data = str_getcsv($line);
345
+					$this->get_storage_filesystem($storage_selection)->delete($data[0]);
346
+				}
347
+			}
348
+		}
349
+
350
+		if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) {
351
+			$return = true;
352
+		} else {
353
+			$return = false;
354
+		}
355
+
356
+		return $return;
357
+	}
358
+
359
+	public function getMetadataFull($adapter = "storage_adapter", $path)
360
+	{
361
+		$location = $this->$adapter->applyPathPrefix($path);
362
+		$spl_info = new SplFileInfo($location);
363
+
364
+		return ($spl_info);
365
+	}
366
+
367
+
368
+	public function get_backup_archives_list($storage_selection = "")
369
+	{
370
+		$list = array();
371
+
372
+
373
+		if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) {
374
+			$list = $this->get_storage_filesystem($storage_selection)->listContents();
375
+		}
376
+
377
+		$backup_files = array();
378
+		$parents = array();
379
+
380
+		foreach ($list as $file_info) {
381
+			if (isset($file_info['extension']) and $file_info['extension'] == "csv") {
382
+				$data = array();
383
+
384
+				$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path']));
385
+				foreach ($lines as $line) {
386
+					if ($line) {
387
+						$data = str_getcsv($line);
388
+						if (is_array($data)) {
389
+							$parents[$data[0]] = $file_info['basename'];
390
+							$file_info['childs'][] = $data;
391
+							$file_info['size'] += $data[2];
392
+						}
393
+					}
394
+				}
395
+
396
+			}
397
+
398
+			if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'],
399
+					$this->backup_archive_extensions)) {
400
+				$backup_files[$file_info['path']] = $file_info;
401
+			}
402
+		}
403
+
404
+		foreach ($backup_files as $key => $file_info) {
405
+			if (!isset($backup_files[$key]['timestamp'])) {
406
+				//$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']);
407
+			}
408
+
409
+			if (isset($parents[$file_info['basename']])) {
410
+				$backup_files[$key]['parent'] = $parents[$file_info['basename']];
411
+			}
412
+		}
413
+
414
+		return $backup_files;
415
+	}
416
+
417
+	public function start_file_recursion($init = 0)
418
+	{
419
+		if ($init) {
420
+			$this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"),
421
+				$this->xcloner_settings->get_xcloner_start_path()));
422
+			$this->do_system_init();
423
+		}
424
+
425
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
426
+			//.dir exists, we presume we have files to iterate
427
+			$content = $this->tmp_filesystem->read($this->get_temp_dir_handler());
428
+			$files = array_filter(explode("\n", $content));
429
+			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
430
+
431
+			$counter = 0;
432
+			foreach ($files as $file) {
433
+				if ($counter < $this->folders_to_process_per_session) {
434
+					$this->build_files_list($file);
435
+					$counter++;
436
+				} else {
437
+					$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n");
438
+				}
439
+			}
440
+		} else {
441
+			$this->build_files_list();
442
+		}
443
+
444
+		if ($this->scan_finished()) {
445
+			$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html");
446
+			$this->store_file($metadata_dumpfile, 'tmp_filesystem');
447
+			$this->files_counter++;
448
+
449
+			//adding included dump file to the included files list
450
+			if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) {
451
+				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler());
452
+				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
453
+				$this->files_counter++;
454
+			}
455
+
456
+			//adding a default index.html to the temp xcloner folder
457
+			if (!$this->get_tmp_filesystem()->has("index.html")) {
458
+				$this->get_tmp_filesystem()->write("index.html", "");
459
+			}
460
+
461
+			//adding the default log file
462
+			if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) {
463
+				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1));
464
+				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
465
+				$this->files_counter++;
466
+			}
467
+
468
+			return false;
469
+		}
470
+
471
+		return true;
472
+	}
473
+
474
+	public function get_backup_attachments()
475
+	{
476
+		$return = array();
477
+
478
+		$files_list_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler();
479
+		if (file_exists($files_list_file)) {
480
+			$return[] = $files_list_file;
481
+		}
482
+
483
+		if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
484
+			$log_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
485
+			if (!file_exists($log_file)) {
486
+				$log_file = $this->xcloner_settings->get_xcloner_store_path().DS.$this->xcloner_settings->get_logger_filename();
487
+			}
488
+
489
+			if (file_exists($log_file)) {
490
+				$return[] = $log_file;
491
+			}
492
+		}
493
+
494
+		return $return;
495
+	}
496
+
497
+	public function remove_tmp_filesystem()
498
+	{
499
+		//delete the temporary folder
500
+		$this->logger->debug(sprintf("Deleting the temporary storage folder %s",
501
+			$this->xcloner_settings->get_xcloner_tmp_path()));
502
+
503
+		$contents = $this->get_tmp_filesystem()->listContents();
504
+
505
+		if (is_array($contents)) {
506
+			foreach ($contents as $file_info) {
507
+				$this->get_tmp_filesystem()->delete($file_info['path']);
508
+			}
509
+		}
510
+
511
+		try{
512
+			rmdir($this->xcloner_settings->get_xcloner_tmp_path());
513
+		}catch(Exception $e){
514
+			//silent continue
515
+		}
516
+
517
+		return;
518
+	}
519
+
520
+	public function cleanup_tmp_directories()
521
+	{
522
+		$adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
523
+		$tmp_filesystem = new Filesystem($adapter, new Config([
524
+			'disable_asserts' => true,
525
+		]));
526
+
527
+		$contents = $tmp_filesystem->listContents();
528
+
529
+		foreach ($contents as $file) {
530
+
531
+			if (preg_match("/.xcloner-(.*)/", $file['path'])) {
532
+				if ($file['timestamp'] < strtotime("-1days")) {
533
+					$tmp_filesystem->deleteDir($file['path']);
534
+					$this->logger->debug(sprintf("Delete temporary directory %s", $file['path']));
535
+				}
536
+			}
537
+		}
538
+
539
+		return true;
540
+	}
541
+
542
+	private function do_system_init()
543
+	{
544
+		$this->files_counter = 0;
545
+
546
+		if (!$this->storage_filesystem->has("index.html")) {
547
+			$this->storage_filesystem->write("index.html", "");
548
+		}
549
+
550
+		if (!$this->tmp_filesystem->has("index.html")) {
551
+			$this->tmp_filesystem->write("index.html", "");
552
+		}
553
+
554
+		if ($this->tmp_filesystem->has($this->get_included_files_handler())) {
555
+			$this->tmp_filesystem->delete($this->get_included_files_handler());
556
+		}
557
+
558
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
559
+			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
560
+		}
561
+	}
562
+
563
+	public function get_scanned_files_num()
564
+	{
565
+		return $this->files_counter;
566
+	}
567
+
568
+	public function get_scanned_files_total_size()
569
+	{
570
+		return $this->files_size;
571
+	}
572
+
573
+	public function last_logged_file()
574
+	{
575
+		return $this->last_logged_file;
576
+	}
577
+
578
+	public static function is_regex($regex)
579
+	{
580
+		return preg_match("/^\^(.*)\$$/i", $regex);
581
+	}
582 582
 
583
-    public function set_excluded_files($excluded_files = array())
584
-    {
585
-        if (!is_array($excluded_files)) {
586
-            $excluded_files = array();
587
-        }
583
+	public function set_excluded_files($excluded_files = array())
584
+	{
585
+		if (!is_array($excluded_files)) {
586
+			$excluded_files = array();
587
+		}
588 588
 
589
-        foreach ($excluded_files as $excl) {
589
+		foreach ($excluded_files as $excl) {
590 590
 
591
-            if ($this->is_regex($excl)) {
592
-                $this->additional_regex_patterns[] = $excl;
593
-            }
594
-        }
591
+			if ($this->is_regex($excl)) {
592
+				$this->additional_regex_patterns[] = $excl;
593
+			}
594
+		}
595 595
 
596
-        $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
596
+		$this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
597 597
 
598
-        return $this->excluded_files;
599
-    }
598
+		return $this->excluded_files;
599
+	}
600 600
 
601
-    public function get_excluded_files()
602
-    {
603
-        return $this->excluded_files_by_default;
604
-    }
601
+	public function get_excluded_files()
602
+	{
603
+		return $this->excluded_files_by_default;
604
+	}
605 605
 
606
-    public function list_directory($path)
607
-    {
608
-        return $this->start_filesystem->listContents($path);
609
-    }
606
+	public function list_directory($path)
607
+	{
608
+		return $this->start_filesystem->listContents($path);
609
+	}
610 610
 
611
-    public function build_files_list($folder = "")
612
-    {
613
-        $this->logger->debug(sprintf(("Building the files system list")));
611
+	public function build_files_list($folder = "")
612
+	{
613
+		$this->logger->debug(sprintf(("Building the files system list")));
614 614
 
615
-        //if we start with the root folder(empty value), we initializa the file system
616
-        if (!$folder) {
615
+		//if we start with the root folder(empty value), we initializa the file system
616
+		if (!$folder) {
617 617
 
618
-        }
618
+		}
619 619
 
620
-        try {
620
+		try {
621 621
 
622
-            $files = $this->start_filesystem->listContents($folder);
623
-            foreach ($files as $file) {
624
-                if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) {
625
-                    $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"),
626
-                        $file['path']), array(
627
-                        "FILESYSTEM SCAN",
628
-                        "NOT READABLE"
629
-                    ));
630
-                } elseif (!$matching_pattern = $this->is_excluded($file)) {
631
-                    $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array(
632
-                        "FILESYSTEM SCAN",
633
-                        "INCLUDE"
634
-                    ));
635
-                    $file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
636
-                    if ($this->store_file($file)) {
637
-                        $this->files_counter++;
638
-                    }
639
-                    if (isset($file['size'])) {
640
-                        $this->files_size += $file['size'];
641
-                    }
642
-
643
-                } else {
644
-                    $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"),
645
-                        $file['path'], $matching_pattern), array(
646
-                        "FILESYSTEM SCAN",
647
-                        "EXCLUDE"
648
-                    ));
649
-                }
650
-            }
622
+			$files = $this->start_filesystem->listContents($folder);
623
+			foreach ($files as $file) {
624
+				if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) {
625
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"),
626
+						$file['path']), array(
627
+						"FILESYSTEM SCAN",
628
+						"NOT READABLE"
629
+					));
630
+				} elseif (!$matching_pattern = $this->is_excluded($file)) {
631
+					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array(
632
+						"FILESYSTEM SCAN",
633
+						"INCLUDE"
634
+					));
635
+					$file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
636
+					if ($this->store_file($file)) {
637
+						$this->files_counter++;
638
+					}
639
+					if (isset($file['size'])) {
640
+						$this->files_size += $file['size'];
641
+					}
642
+
643
+				} else {
644
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"),
645
+						$file['path'], $matching_pattern), array(
646
+						"FILESYSTEM SCAN",
647
+						"EXCLUDE"
648
+					));
649
+				}
650
+			}
651 651
 
652
-        }catch (Exception $e) {
652
+		}catch (Exception $e) {
653 653
 
654
-            $this->logger->error($e->getMessage());
655
-
656
-        }
654
+			$this->logger->error($e->getMessage());
655
+
656
+		}
657 657
 
658
-    }
658
+	}
659 659
 
660
-    public function estimate_read_write_time()
661
-    {
662
-        $tmp_file = ".xcloner".substr(md5(time()), 0, 5);
660
+	public function estimate_read_write_time()
661
+	{
662
+		$tmp_file = ".xcloner".substr(md5(time()), 0, 5);
663 663
 
664
-        $start_time = microtime(true);
664
+		$start_time = microtime(true);
665 665
 
666
-        $data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data
666
+		$data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data
667 667
 
668
-        try {
669
-            $this->tmp_filesystem->write($tmp_file, $data);
668
+		try {
669
+			$this->tmp_filesystem->write($tmp_file, $data);
670 670
 
671
-            $end_time = microtime(true) - $start_time;
671
+			$end_time = microtime(true) - $start_time;
672 672
 
673
-            $return['writing_time'] = $end_time;
673
+			$return['writing_time'] = $end_time;
674 674
 
675
-            $return['reading_time'] = $this->estimate_reading_time($tmp_file);
675
+			$return['reading_time'] = $this->estimate_reading_time($tmp_file);
676 676
 
677
-            $this->tmp_filesystem->delete($tmp_file);
677
+			$this->tmp_filesystem->delete($tmp_file);
678 678
 
679
-        }catch (Exception $e) {
679
+		}catch (Exception $e) {
680 680
 
681
-            $this->logger->error($e->getMessage());
681
+			$this->logger->error($e->getMessage());
682 682
 
683
-        }
683
+		}
684 684
 
685
-        return $return;
686
-    }
685
+		return $return;
686
+	}
687 687
 
688
-    public function backup_storage_cleanup()
689
-    {
690
-        $this->logger->info(sprintf(("Cleaning the backup storage on matching rules")));
688
+	public function backup_storage_cleanup()
689
+	{
690
+		$this->logger->info(sprintf(("Cleaning the backup storage on matching rules")));
691 691
 
692
-        $_storage_size = 0;
693
-        $_backup_files_list = array();
692
+		$_storage_size = 0;
693
+		$_backup_files_list = array();
694 694
 
695
-        //rule date limit
696
-        $current_timestamp = strtotime("-".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')." days");
697
-
698
-        $files = $this->storage_filesystem->listContents();
699
-
700
-        if (is_array($files)) {
701
-            foreach ($files as $file) {
702
-                if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) {
703
-                    $_storage_size += $file['size']; //bytes
704
-                    $_backup_files_list[] = $file;
705
-                }
706
-            }
707
-        }
695
+		//rule date limit
696
+		$current_timestamp = strtotime("-".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')." days");
697
+
698
+		$files = $this->storage_filesystem->listContents();
699
+
700
+		if (is_array($files)) {
701
+			foreach ($files as $file) {
702
+				if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) {
703
+					$_storage_size += $file['size']; //bytes
704
+					$_backup_files_list[] = $file;
705
+				}
706
+			}
707
+		}
708 708
 
709 709
 
710
-        $this->sort_by($_backup_files_list, "timestamp", "asc");
711
-
712
-        $_backups_counter = sizeof($_backup_files_list);
713
-
714
-        foreach ($_backup_files_list as $file) {
715
-            //processing rule folder capacity
716
-            if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
717
-                $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))    //bytes
718
-            {
719
-                $this->storage_filesystem->delete($file['path']);
720
-                $_storage_size -= $file['size'];
721
-                $this->logger->info("Deleting backup ".$file['path']." matching rule", array(
722
-                    "STORAGE SIZE LIMIT",
723
-                    $_storage_size." >= ".$set_storage_limit
724
-                ));
725
-            }
726
-
727
-            //processing rule days limit
728
-            if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) {
729
-                $this->storage_filesystem->delete($file['path']);
730
-                $this->logger->info("Deleting backup ".$file['path']." matching rule", array(
731
-                    "RETENTION LIMIT TIMESTAMP",
732
-                    $file['timestamp']." =< ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')
733
-                ));
734
-            }
735
-
736
-            //processing backup countert limit
737
-            if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') && $_backups_counter >= $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')) {
738
-                $this->storage_filesystem->delete($file['path']);
739
-                $_backups_counter--;
740
-                $this->logger->info("Deleting backup ".$file['path']." matching rule", array(
741
-                    "BACKUP QUANTITY LIMIT",
742
-                    $_backups_counter." >= ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')
743
-                ));
744
-            }
745
-
746
-
747
-        }
710
+		$this->sort_by($_backup_files_list, "timestamp", "asc");
711
+
712
+		$_backups_counter = sizeof($_backup_files_list);
713
+
714
+		foreach ($_backup_files_list as $file) {
715
+			//processing rule folder capacity
716
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
717
+				$_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))    //bytes
718
+			{
719
+				$this->storage_filesystem->delete($file['path']);
720
+				$_storage_size -= $file['size'];
721
+				$this->logger->info("Deleting backup ".$file['path']." matching rule", array(
722
+					"STORAGE SIZE LIMIT",
723
+					$_storage_size." >= ".$set_storage_limit
724
+				));
725
+			}
726
+
727
+			//processing rule days limit
728
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) {
729
+				$this->storage_filesystem->delete($file['path']);
730
+				$this->logger->info("Deleting backup ".$file['path']." matching rule", array(
731
+					"RETENTION LIMIT TIMESTAMP",
732
+					$file['timestamp']." =< ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')
733
+				));
734
+			}
735
+
736
+			//processing backup countert limit
737
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') && $_backups_counter >= $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')) {
738
+				$this->storage_filesystem->delete($file['path']);
739
+				$_backups_counter--;
740
+				$this->logger->info("Deleting backup ".$file['path']." matching rule", array(
741
+					"BACKUP QUANTITY LIMIT",
742
+					$_backups_counter." >= ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')
743
+				));
744
+			}
745
+
746
+
747
+		}
748 748
 
749
-    }
749
+	}
750 750
 
751
-    /**
752
-     * @param string $tmp_file
753
-     */
754
-    public function estimate_reading_time($tmp_file)
755
-    {
756
-        $this->logger->debug(sprintf(("Estimating file system reading time")));
757
-
758
-        $start_time = microtime(true);
759
-
760
-        if ($this->tmp_filesystem->has($tmp_file)) {
761
-            $this->tmp_filesystem->read($tmp_file);
762
-        }
763
-
764
-        $end_time = microtime(true) - $start_time;
765
-
766
-        return $end_time;
767
-
768
-    }
769
-
770
-    public function process_backup_name($name = "", $max_length = 100)
771
-    {
772
-        if (!$name) {
773
-            $name = $this->xcloner_settings->get_default_backup_name();
774
-        }
775
-
776
-        foreach ($this->backup_name_tags as $tag) {
777
-            if ($tag == '[time]') {
778
-                $name = str_replace($tag, date("Y-m-d_H-i"), $name);
779
-            } elseif ($tag == '[hostname]') {
780
-                $name = str_replace($tag, gethostname(), $name);
781
-            } elseif ($tag == '[domain]') {
782
-                $domain = parse_url(admin_url(), PHP_URL_HOST);
783
-                $name = str_replace($tag, $domain, $name);
784
-            }
785
-        }
786
-
787
-        if ($max_length) {
788
-            $name = substr($name, 0, $max_length);
789
-        }
790
-
791
-        return $name;
792
-    }
793
-
794
-    /**
795
-     * @param string $field
796
-     */
797
-    public function sort_by(&$array, $field, $direction = 'asc')
798
-    {
799
-        if (strtolower($direction) == "desc" || $direction == SORT_DESC) {
800
-            $direction = SORT_DESC;
801
-        } else {
802
-            $direction = SORT_ASC;
803
-        }
804
-
805
-        $array = $this->array_orderby($array, $field, $direction);
806
-
807
-        return true;
808
-    }
809
-
810
-    private function array_orderby()
811
-    {
812
-        $args = func_get_args();
813
-        $data = array_shift($args);
814
-
815
-        foreach ($args as $n => $field) {
816
-            if (is_string($field)) {
817
-                $tmp = array();
818
-                foreach ($data as $key => $row) {
819
-                    if (is_array($row)) {
820
-                        $tmp[$key] = $row[$field];
821
-                    } else {
822
-                        $tmp[$key] = $row->$field;
823
-                    }
824
-                }
825
-                $args[$n] = $tmp;
826
-            }
827
-        }
828
-        $args[] = &$data;
829
-
830
-        call_user_func_array('array_multisort', $args);
831
-
832
-        return array_pop($args);
833
-    }
834
-
835
-    private function check_file_diff_time($file)
836
-    {
837
-        if ($this->get_diff_timestamp_start() != "") {
838
-            $fileMeta = $this->getMetadataFull("start_adapter", $file['path']);
839
-            $timestamp = $fileMeta->getMTime();
840
-            if ($timestamp < $fileMeta->getCTime()) {
841
-                $timestamp = $fileMeta->getCTime();
842
-            }
843
-
844
-            if ($timestamp <= $this->get_diff_timestamp_start()) {
845
-                return " file DIFF timestamp ".$timestamp." < ".$this->diff_timestamp_start;
846
-            }
847
-        }
848
-
849
-        return false;
850
-    }
851
-
852
-    public function is_excluded($file)
853
-    {
854
-        $this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
855
-
856
-        if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) {
857
-            if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) {
858
-                return "> ".$xcloner_exclude_files_larger_than_mb."MB";
859
-            }
860
-        }
861
-
862
-        if (!is_array($this->excluded_files) || !sizeof($this->excluded_files)) {
863
-            $this->set_excluded_files();
864
-        }
865
-
866
-        if (is_array($this->excluded_files)) {
867
-            foreach ($this->excluded_files as $excluded_file_pattern) {
868
-                if ($excluded_file_pattern == "/") {
869
-                    $needle = "$";
870
-                } else {
871
-                    $needle = "$".$excluded_file_pattern;
872
-                }
873
-
874
-                if (strstr("$".$file['path'], $needle)) {
875
-                    return $excluded_file_pattern;
876
-                }
877
-            }
878
-        }
879
-
880
-        if ($regex = $this->is_excluded_regex($file)) {
881
-            return $regex;
882
-        }
883
-
884
-        if ($file['type'] == "file") {
885
-            $check_file_diff_timestamp = $this->check_file_diff_time($file);
886
-            if ($check_file_diff_timestamp) {
887
-                return $check_file_diff_timestamp;
888
-            }
889
-        }
890
-
891
-        return false;
892
-    }
893
-
894
-    /*REGEX examples
751
+	/**
752
+	 * @param string $tmp_file
753
+	 */
754
+	public function estimate_reading_time($tmp_file)
755
+	{
756
+		$this->logger->debug(sprintf(("Estimating file system reading time")));
757
+
758
+		$start_time = microtime(true);
759
+
760
+		if ($this->tmp_filesystem->has($tmp_file)) {
761
+			$this->tmp_filesystem->read($tmp_file);
762
+		}
763
+
764
+		$end_time = microtime(true) - $start_time;
765
+
766
+		return $end_time;
767
+
768
+	}
769
+
770
+	public function process_backup_name($name = "", $max_length = 100)
771
+	{
772
+		if (!$name) {
773
+			$name = $this->xcloner_settings->get_default_backup_name();
774
+		}
775
+
776
+		foreach ($this->backup_name_tags as $tag) {
777
+			if ($tag == '[time]') {
778
+				$name = str_replace($tag, date("Y-m-d_H-i"), $name);
779
+			} elseif ($tag == '[hostname]') {
780
+				$name = str_replace($tag, gethostname(), $name);
781
+			} elseif ($tag == '[domain]') {
782
+				$domain = parse_url(admin_url(), PHP_URL_HOST);
783
+				$name = str_replace($tag, $domain, $name);
784
+			}
785
+		}
786
+
787
+		if ($max_length) {
788
+			$name = substr($name, 0, $max_length);
789
+		}
790
+
791
+		return $name;
792
+	}
793
+
794
+	/**
795
+	 * @param string $field
796
+	 */
797
+	public function sort_by(&$array, $field, $direction = 'asc')
798
+	{
799
+		if (strtolower($direction) == "desc" || $direction == SORT_DESC) {
800
+			$direction = SORT_DESC;
801
+		} else {
802
+			$direction = SORT_ASC;
803
+		}
804
+
805
+		$array = $this->array_orderby($array, $field, $direction);
806
+
807
+		return true;
808
+	}
809
+
810
+	private function array_orderby()
811
+	{
812
+		$args = func_get_args();
813
+		$data = array_shift($args);
814
+
815
+		foreach ($args as $n => $field) {
816
+			if (is_string($field)) {
817
+				$tmp = array();
818
+				foreach ($data as $key => $row) {
819
+					if (is_array($row)) {
820
+						$tmp[$key] = $row[$field];
821
+					} else {
822
+						$tmp[$key] = $row->$field;
823
+					}
824
+				}
825
+				$args[$n] = $tmp;
826
+			}
827
+		}
828
+		$args[] = &$data;
829
+
830
+		call_user_func_array('array_multisort', $args);
831
+
832
+		return array_pop($args);
833
+	}
834
+
835
+	private function check_file_diff_time($file)
836
+	{
837
+		if ($this->get_diff_timestamp_start() != "") {
838
+			$fileMeta = $this->getMetadataFull("start_adapter", $file['path']);
839
+			$timestamp = $fileMeta->getMTime();
840
+			if ($timestamp < $fileMeta->getCTime()) {
841
+				$timestamp = $fileMeta->getCTime();
842
+			}
843
+
844
+			if ($timestamp <= $this->get_diff_timestamp_start()) {
845
+				return " file DIFF timestamp ".$timestamp." < ".$this->diff_timestamp_start;
846
+			}
847
+		}
848
+
849
+		return false;
850
+	}
851
+
852
+	public function is_excluded($file)
853
+	{
854
+		$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
855
+
856
+		if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) {
857
+			if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) {
858
+				return "> ".$xcloner_exclude_files_larger_than_mb."MB";
859
+			}
860
+		}
861
+
862
+		if (!is_array($this->excluded_files) || !sizeof($this->excluded_files)) {
863
+			$this->set_excluded_files();
864
+		}
865
+
866
+		if (is_array($this->excluded_files)) {
867
+			foreach ($this->excluded_files as $excluded_file_pattern) {
868
+				if ($excluded_file_pattern == "/") {
869
+					$needle = "$";
870
+				} else {
871
+					$needle = "$".$excluded_file_pattern;
872
+				}
873
+
874
+				if (strstr("$".$file['path'], $needle)) {
875
+					return $excluded_file_pattern;
876
+				}
877
+			}
878
+		}
879
+
880
+		if ($regex = $this->is_excluded_regex($file)) {
881
+			return $regex;
882
+		}
883
+
884
+		if ($file['type'] == "file") {
885
+			$check_file_diff_timestamp = $this->check_file_diff_time($file);
886
+			if ($check_file_diff_timestamp) {
887
+				return $check_file_diff_timestamp;
888
+			}
889
+		}
890
+
891
+		return false;
892
+	}
893
+
894
+	/*REGEX examples
895 895
      *
896 896
     * exclude all except .php file
897 897
     * PATTERN: ^(.*)\.(.+)$(?<!(php))
@@ -923,163 +923,163 @@  discard block
 block discarded – undo
923 923
     * exclude the backup folders
924 924
     * PATTERN: (^|^\/)(wp-content\/backups|administrator\/backups)(.*)$";
925 925
     */
926
-    private function is_excluded_regex($file)
927
-    {
928
-        //$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
929
-
930
-        $regex_patterns = explode(PHP_EOL, $this->xcloner_settings->get_xcloner_option('xcloner_regex_exclude'));
931
-
932
-        if (is_array($this->additional_regex_patterns)) {
933
-            $regex_patterns = array_merge($regex_patterns, $this->additional_regex_patterns);
934
-        }
935
-
936
-        //print_r($regex_patterns);exit;
937
-
938
-        if (is_array($regex_patterns)) {
939
-            //$this->excluded_files = array();
940
-            //$this->excluded_files[] ="(.*)\.(git)(.*)$";
941
-            //$this->excluded_files[] ="wp-content\/backups(.*)$";
942
-
943
-            foreach ($regex_patterns as $excluded_file_pattern) {
944
-
945
-                if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1,
946
-                        strlen($excluded_file_pattern)) == "\r") {
947
-                    $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1);
948
-                }
949
-
950
-                if ($file['path'] == "/") {
951
-                    $needle = "/";
952
-                } else {
953
-                    $needle = "/".$file['path'];
954
-                }
955
-                //echo $needle."---".$excluded_file_pattern."---\n";
956
-
957
-                if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) {
958
-                    return $excluded_file_pattern;
959
-                }
960
-            }
961
-        }
962
-
963
-        return false;
964
-    }
965
-
966
-    public function store_file($file, $storage = 'start_filesystem')
967
-    {
968
-        $this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
969
-
970
-        if (!isset($file['size'])) {
971
-            $file['size'] = 0;
972
-        }
973
-        if (!isset($file['visibility'])) {
974
-            $file['visibility'] = "private";
975
-        }
976
-
977
-        $csv_filename = str_replace('"', '""', $file['path']);
978
-
979
-        $line = '"'.($csv_filename).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL;
980
-
981
-        $this->last_logged_file = $file['path'];
982
-
983
-        if ($file['type'] == "dir") {
984
-            try {
985
-                $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n");
986
-            }catch (Exception $e) {
987
-                $this->logger->error($e->getMessage());
988
-            }
989
-        }
990
-
991
-        if ($this->get_diff_timestamp_start()) {
992
-            if ($file['type'] != "file" && $response = $this->check_file_diff_time($file)) {
993
-                $this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'],
994
-                    $response), array(
995
-                    "FILESYSTEM SCAN",
996
-                    "DIR DIFF"
997
-                ));
998
-
999
-                return false;
1000
-            }
1001
-        }
1002
-
1003
-        try {
1004
-            if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) {
1005
-                //adding fix for UTF-8 CSV preview
1006
-                $start_line = "\xEF\xBB\xBF".'"Filename","Timestamp","Size","Visibility","Storage"'.PHP_EOL;
1007
-                $this->tmp_filesystem_append->write($this->get_included_files_handler(), $start_line);
1008
-            }
1009
-
1010
-            $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
1011
-
1012
-        }catch (Exception $e) {
1013
-
1014
-            $this->logger->error($e->getMessage());
1015
-        }
1016
-
1017
-        return true;
1018
-    }
1019
-
1020
-    public function get_fileystem_handler()
1021
-    {
1022
-        return $this;
1023
-    }
1024
-
1025
-    public function get_filesystem($system = "")
1026
-    {
1027
-        if ($system == "storage_filesystem_append") {
1028
-            return $this->storage_filesystem_append;
1029
-        } elseif ($system == "tmp_filesystem_append") {
1030
-            return $this->tmp_filesystem_append;
1031
-        } elseif ($system == "tmp_filesystem") {
1032
-            return $this->tmp_filesystem;
1033
-        } elseif ($system == "storage_filesystem") {
1034
-            return $this->storage_filesystem;
1035
-        } else {
1036
-            return $this->start_filesystem;
1037
-        }
1038
-    }
1039
-
1040
-    public function get_adapter($system)
1041
-    {
1042
-        if ($system == "tmp_filesystem") {
1043
-            return $this->tmp_adapter;
1044
-        } elseif ($system == "storage_filesystem") {
1045
-            return $this->storage_adapter;
1046
-        } else {
1047
-            return $this->start_adapter;
1048
-        }
1049
-    }
1050
-
1051
-    /**
1052
-     * File scan finished
1053
-     * Method called when file scan is finished
1054
-     *
1055
-     * @return bool
1056
-     */
1057
-    private function scan_finished()
1058
-    {
1059
-        if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) &&
1060
-            $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) {
1061
-            return false;
1062
-        }
1063
-
1064
-        if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
1065
-            $this->tmp_filesystem->delete($this->get_temp_dir_handler());
1066
-        }
1067
-
1068
-        $this->logger->debug(sprintf(("File scan finished")));
1069
-
1070
-        return true;
1071
-    }
1072
-
1073
-    /**
1074
-     * Calculate bytes from MB value
1075
-     *
1076
-     * @param int $mb_size
1077
-     *
1078
-     * @return float|int
1079
-     */
1080
-    private function calc_to_bytes($mb_size)
1081
-    {
1082
-        return $mb_size * (1024 * 1024);
1083
-    }
926
+	private function is_excluded_regex($file)
927
+	{
928
+		//$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
929
+
930
+		$regex_patterns = explode(PHP_EOL, $this->xcloner_settings->get_xcloner_option('xcloner_regex_exclude'));
931
+
932
+		if (is_array($this->additional_regex_patterns)) {
933
+			$regex_patterns = array_merge($regex_patterns, $this->additional_regex_patterns);
934
+		}
935
+
936
+		//print_r($regex_patterns);exit;
937
+
938
+		if (is_array($regex_patterns)) {
939
+			//$this->excluded_files = array();
940
+			//$this->excluded_files[] ="(.*)\.(git)(.*)$";
941
+			//$this->excluded_files[] ="wp-content\/backups(.*)$";
942
+
943
+			foreach ($regex_patterns as $excluded_file_pattern) {
944
+
945
+				if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1,
946
+						strlen($excluded_file_pattern)) == "\r") {
947
+					$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1);
948
+				}
949
+
950
+				if ($file['path'] == "/") {
951
+					$needle = "/";
952
+				} else {
953
+					$needle = "/".$file['path'];
954
+				}
955
+				//echo $needle."---".$excluded_file_pattern."---\n";
956
+
957
+				if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) {
958
+					return $excluded_file_pattern;
959
+				}
960
+			}
961
+		}
962
+
963
+		return false;
964
+	}
965
+
966
+	public function store_file($file, $storage = 'start_filesystem')
967
+	{
968
+		$this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
969
+
970
+		if (!isset($file['size'])) {
971
+			$file['size'] = 0;
972
+		}
973
+		if (!isset($file['visibility'])) {
974
+			$file['visibility'] = "private";
975
+		}
976
+
977
+		$csv_filename = str_replace('"', '""', $file['path']);
978
+
979
+		$line = '"'.($csv_filename).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL;
980
+
981
+		$this->last_logged_file = $file['path'];
982
+
983
+		if ($file['type'] == "dir") {
984
+			try {
985
+				$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n");
986
+			}catch (Exception $e) {
987
+				$this->logger->error($e->getMessage());
988
+			}
989
+		}
990
+
991
+		if ($this->get_diff_timestamp_start()) {
992
+			if ($file['type'] != "file" && $response = $this->check_file_diff_time($file)) {
993
+				$this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'],
994
+					$response), array(
995
+					"FILESYSTEM SCAN",
996
+					"DIR DIFF"
997
+				));
998
+
999
+				return false;
1000
+			}
1001
+		}
1002
+
1003
+		try {
1004
+			if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) {
1005
+				//adding fix for UTF-8 CSV preview
1006
+				$start_line = "\xEF\xBB\xBF".'"Filename","Timestamp","Size","Visibility","Storage"'.PHP_EOL;
1007
+				$this->tmp_filesystem_append->write($this->get_included_files_handler(), $start_line);
1008
+			}
1009
+
1010
+			$this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
1011
+
1012
+		}catch (Exception $e) {
1013
+
1014
+			$this->logger->error($e->getMessage());
1015
+		}
1016
+
1017
+		return true;
1018
+	}
1019
+
1020
+	public function get_fileystem_handler()
1021
+	{
1022
+		return $this;
1023
+	}
1024
+
1025
+	public function get_filesystem($system = "")
1026
+	{
1027
+		if ($system == "storage_filesystem_append") {
1028
+			return $this->storage_filesystem_append;
1029
+		} elseif ($system == "tmp_filesystem_append") {
1030
+			return $this->tmp_filesystem_append;
1031
+		} elseif ($system == "tmp_filesystem") {
1032
+			return $this->tmp_filesystem;
1033
+		} elseif ($system == "storage_filesystem") {
1034
+			return $this->storage_filesystem;
1035
+		} else {
1036
+			return $this->start_filesystem;
1037
+		}
1038
+	}
1039
+
1040
+	public function get_adapter($system)
1041
+	{
1042
+		if ($system == "tmp_filesystem") {
1043
+			return $this->tmp_adapter;
1044
+		} elseif ($system == "storage_filesystem") {
1045
+			return $this->storage_adapter;
1046
+		} else {
1047
+			return $this->start_adapter;
1048
+		}
1049
+	}
1050
+
1051
+	/**
1052
+	 * File scan finished
1053
+	 * Method called when file scan is finished
1054
+	 *
1055
+	 * @return bool
1056
+	 */
1057
+	private function scan_finished()
1058
+	{
1059
+		if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) &&
1060
+			$this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) {
1061
+			return false;
1062
+		}
1063
+
1064
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
1065
+			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
1066
+		}
1067
+
1068
+		$this->logger->debug(sprintf(("File scan finished")));
1069
+
1070
+		return true;
1071
+	}
1072
+
1073
+	/**
1074
+	 * Calculate bytes from MB value
1075
+	 *
1076
+	 * @param int $mb_size
1077
+	 *
1078
+	 * @return float|int
1079
+	 */
1080
+	private function calc_to_bytes($mb_size)
1081
+	{
1082
+		return $mb_size * (1024 * 1024);
1083
+	}
1084 1084
 
1085 1085
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -508,9 +508,9 @@
 block discarded – undo
508 508
             }
509 509
         }
510 510
 
511
-        try{
511
+        try {
512 512
             rmdir($this->xcloner_settings->get_xcloner_tmp_path());
513
-        }catch(Exception $e){
513
+        }catch (Exception $e) {
514 514
             //silent continue
515 515
         }
516 516
 
Please login to merge, or discard this patch.
Braces   +9 added lines, -7 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
             $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([
103 103
                 'disable_asserts' => true,
104 104
             ]));
105
-        }catch (Exception $e) {
105
+        } catch (Exception $e) {
106 106
             $this->logger->error("Filesystem Initialization Error: ".$e->getMessage());
107 107
         }
108 108
 
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 
511 511
         try{
512 512
             rmdir($this->xcloner_settings->get_xcloner_tmp_path());
513
-        }catch(Exception $e){
513
+        } catch(Exception $e){
514 514
             //silent continue
515 515
         }
516 516
 
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
                 }
650 650
             }
651 651
 
652
-        }catch (Exception $e) {
652
+        } catch (Exception $e) {
653 653
 
654 654
             $this->logger->error($e->getMessage());
655 655
 
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 
677 677
             $this->tmp_filesystem->delete($tmp_file);
678 678
 
679
-        }catch (Exception $e) {
679
+        } catch (Exception $e) {
680 680
 
681 681
             $this->logger->error($e->getMessage());
682 682
 
@@ -714,9 +714,11 @@  discard block
 block discarded – undo
714 714
         foreach ($_backup_files_list as $file) {
715 715
             //processing rule folder capacity
716 716
             if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
717
-                $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))    //bytes
717
+                $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) {
718
+            	//bytes
718 719
             {
719 720
                 $this->storage_filesystem->delete($file['path']);
721
+            }
720 722
                 $_storage_size -= $file['size'];
721 723
                 $this->logger->info("Deleting backup ".$file['path']." matching rule", array(
722 724
                     "STORAGE SIZE LIMIT",
@@ -983,7 +985,7 @@  discard block
 block discarded – undo
983 985
         if ($file['type'] == "dir") {
984 986
             try {
985 987
                 $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n");
986
-            }catch (Exception $e) {
988
+            } catch (Exception $e) {
987 989
                 $this->logger->error($e->getMessage());
988 990
             }
989 991
         }
@@ -1009,7 +1011,7 @@  discard block
 block discarded – undo
1009 1011
 
1010 1012
             $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
1011 1013
 
1012
-        }catch (Exception $e) {
1014
+        } catch (Exception $e) {
1013 1015
 
1014 1016
             $this->logger->error($e->getMessage());
1015 1017
         }
Please login to merge, or discard this patch.