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.
Completed
Push — master ( 67f878...5fe6bb )
by Liuta
07:51
created
includes/class-xcloner-database.php 4 patches
Doc Comments   +5 added lines patch added patch discarded remove patch
@@ -469,6 +469,11 @@
 block discarded – undo
469 469
 	 * 		handler $fd - file handler where to write the records
470 470
 	 * @return
471 471
 	 */
472
+
473
+	/**
474
+	 * @param integer $start
475
+	 * @param integer $limit
476
+	 */
472 477
 	public function export_table($databaseName, $tableName, $start, $limit, $dumpfile)
473 478
 	{
474 479
 		$this->logger->debug(sprintf(("Exporting table  %s.%s data"), $databaseName, $tableName));
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 					$this->log(sprintf(__("Excluding table %s.%s from backup"), $table, $database));
285 285
 				}
286 286
 			$inc++;
287
-        }
287
+		}
288 288
 
289 289
 		return $tablesList;
290 290
 
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
 					$buffer = "";
508 508
 					$this->countRecords++;
509 509
 
510
-	                foreach ($arr as $key => $value) {
510
+					foreach ($arr as $key => $value) {
511 511
 						$value = $this->_real_escape($value);
512 512
 						
513 513
 						if(method_exists($this, 'remove_placeholder_escape')){
@@ -538,8 +538,8 @@  discard block
 block discarded – undo
538 538
 		$line = ("\n#\n# Table structure for table `$tableName`\n#\n\n");
539 539
 		$this->fs->get_tmp_filesystem_append()->write($dumpfile, $line);
540 540
 
541
-        if ($this->dbDropSyntax)
542
-        {
541
+		if ($this->dbDropSyntax)
542
+		{
543 543
 			$line = ("\nDROP table IF EXISTS `$tableName`;\n");
544 544
 			$this->fs->get_tmp_filesystem_append()->write($dumpfile, $line);
545 545
 		}
Please login to merge, or discard this patch.
Spacing   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -21,12 +21,12 @@  discard block
 block discarded – undo
21 21
  */
22 22
 
23 23
 
24
-class Xcloner_Database extends wpdb{
24
+class Xcloner_Database extends wpdb {
25 25
 
26 26
 
27
-	public  $debug 						= 0;
28
-	public  $recordsPerSession			= 10000;
29
-	public  $dbCompatibility			= "";
27
+	public  $debug = 0;
28
+	public  $recordsPerSession = 10000;
29
+	public  $dbCompatibility = "";
30 30
 	public  $dbDropSyntax				= 1;
31 31
 	public  $countRecords				= 0;
32 32
 
@@ -38,24 +38,24 @@  discard block
 block discarded – undo
38 38
 	private   $TEMP_DBPROCESS_FILE = ".database";
39 39
 	private   $TEMP_DUMP_FILE = "database-backup.sql";
40 40
 	
41
-	public function __construct(Xcloner $xcloner_container, $wp_user="", $wp_pass="", $wp_db="", $wp_host="")
41
+	public function __construct(Xcloner $xcloner_container, $wp_user = "", $wp_pass = "", $wp_db = "", $wp_host = "")
42 42
 	{
43
-		$this->logger 					= $xcloner_container->get_xcloner_logger()->withName("xcloner_database");
44
-		$this->xcloner_settings 		= $xcloner_container->get_xcloner_settings();
45
-		$this->fs 						= $xcloner_container->get_xcloner_filesystem();
43
+		$this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_database");
44
+		$this->xcloner_settings = $xcloner_container->get_xcloner_settings();
45
+		$this->fs = $xcloner_container->get_xcloner_filesystem();
46 46
 		
47
-		if($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'))
48
-			$this->recordsPerSession		= $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
47
+		if ($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'))
48
+			$this->recordsPerSession = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
49 49
 		
50
-		if(!$this->recordsPerSession)
50
+		if (!$this->recordsPerSession)
51 51
 			$this->recordsPerSession = 100;
52 52
 		
53
-		if(!$wp_user && !$wp_pass && !$wp_host && !$wp_db )
53
+		if (!$wp_user && !$wp_pass && !$wp_host && !$wp_db)
54 54
 		{
55 55
 			$wp_host 	= $this->xcloner_settings->get_db_hostname();
56 56
 			$wp_user 	= $this->xcloner_settings->get_db_username();
57 57
 			$wp_pass 	= $this->xcloner_settings->get_db_password();
58
-			$wp_db 		= $this->xcloner_settings->get_db_database();
58
+			$wp_db = $this->xcloner_settings->get_db_database();
59 59
 		}
60 60
 		
61 61
 		parent::__construct($wp_user, $wp_pass, $wp_db, $wp_host);
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 */
72 72
 	public function init($data, $start = 0)
73 73
 	{
74
-		if($start and $this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)){
74
+		if ($start and $this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) {
75 75
 				$this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE);
76 76
 		}
77 77
 		
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 				"database_count"=>0,
91 91
 		);
92 92
 		
93
-		if(!$this->xcloner_settings->get_enable_mysql_backup())
93
+		if (!$this->xcloner_settings->get_enable_mysql_backup())
94 94
 		{
95 95
 			$return['finished'] = 1;
96 96
 			return $return;
@@ -100,44 +100,44 @@  discard block
 block discarded – undo
100 100
 		
101 101
 		$this->init($params, $init);
102 102
 		
103
-		if($init)
103
+		if ($init)
104 104
 		{
105 105
 			$db_count = 0;
106 106
 			
107
-			if(isset($params['#']))
107
+			if (isset($params['#']))
108 108
 			{
109
-				foreach($params['#'] as $database)
109
+				foreach ($params['#'] as $database)
110 110
 				{
111
-					if(!isset($params[$database]) or !is_array($params[$database]))
111
+					if (!isset($params[$database]) or !is_array($params[$database]))
112 112
 						$params[$database] = array();
113 113
 				}
114 114
 				$db_count = -1;
115 115
 			}
116 116
 			
117
-			if(isset($params) and is_array($params))
118
-				foreach($params as $database=>$tables)
117
+			if (isset($params) and is_array($params))
118
+				foreach ($params as $database=>$tables)
119 119
 				{	
120
-					if($database != "#")
120
+					if ($database != "#")
121 121
 					{
122 122
 						$stats = $this->write_backup_process_list($database, $tables);	
123
-						$return['stats']['tables_count'] 	+= $stats['tables_count'];
124
-						$return['stats']['total_records'] 	+= $stats['total_records'];
123
+						$return['stats']['tables_count'] += $stats['tables_count'];
124
+						$return['stats']['total_records'] += $stats['total_records'];
125 125
 					}
126 126
 				}
127 127
 
128
-			if(sizeof($params))
129
-				$return['stats']['database_count'] = sizeof($params)+$db_count;
128
+			if (sizeof($params))
129
+				$return['stats']['database_count'] = sizeof($params) + $db_count;
130 130
 			else	
131 131
 				$return['stats']['database_count'] = 0;
132 132
 				
133 133
 			return $return;
134 134
 		}
135 135
 		
136
-		if(!isset($extra_params['startAtLine']))
136
+		if (!isset($extra_params['startAtLine']))
137 137
 			$extra_params['startAtLine'] = 0;
138
-		if(!isset($extra_params['startAtRecord']))
138
+		if (!isset($extra_params['startAtRecord']))
139 139
 			$extra_params['startAtRecord'] = 0;
140
-		if(!isset($extra_params['dumpfile']))
140
+		if (!isset($extra_params['dumpfile']))
141 141
 			$extra_params['dumpfile'] = "";
142 142
 		
143 143
 		$return = $this->process_incremental($extra_params['startAtLine'], $extra_params['startAtRecord'], $extra_params['dumpfile']);
@@ -148,13 +148,13 @@  discard block
 block discarded – undo
148 148
 	public function log($message = "")
149 149
 	{
150 150
 		
151
-		if($message){
152
-			$this->logger->info( $message, array(""));
153
-		}else{	
154
-			if($this->last_query)
155
-				$this->logger->debug( $this->last_query, array(""));
156
-			if($this->last_error)
157
-				$this->logger->error( $this->last_error, array(""));
151
+		if ($message) {
152
+			$this->logger->info($message, array(""));
153
+		} else {	
154
+			if ($this->last_query)
155
+				$this->logger->debug($this->last_query, array(""));
156
+			if ($this->last_error)
157
+				$this->logger->error($this->last_error, array(""));
158 158
 		}
159 159
 		
160 160
 		return;
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 	*/
170 170
 	public function error($message)
171 171
 	{
172
-		$this->logger->error( $message, array(""));
172
+		$this->logger->error($message, array(""));
173 173
 		
174 174
 		return;
175 175
 	}
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 		
203 203
 		$query = "show tables in `".$database."`";
204 204
 		
205
-		$res =  $this->get_results($query);
205
+		$res = $this->get_results($query);
206 206
 		$this->log();
207 207
 			
208 208
 		return count($res);
@@ -225,9 +225,9 @@  discard block
 block discarded – undo
225 225
 		$databases_list[$i]['num_tables'] = $this->get_database_num_tables($this->dbname);
226 226
 		$i++;
227 227
 		
228
-		if(is_array($databases))
229
-		foreach( $databases as $db){
230
-			if($db->Database != $this->dbname)
228
+		if (is_array($databases))
229
+		foreach ($databases as $db) {
230
+			if ($db->Database != $this->dbname)
231 231
 			{
232 232
 				$databases_list[$i]['name'] = $db->Database;
233 233
 				$databases_list[$i]['num_tables'] = $this->get_database_num_tables($db->Database);
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 		$tablesList[0] = array( );
253 253
 		$inc = 0;
254 254
 
255
-		if(!$database)
255
+		if (!$database)
256 256
 			$database = $this->dbname;
257 257
 		
258 258
 		$this->logger->debug(sprintf(("Listing tables in %s database"), $database));
@@ -260,14 +260,14 @@  discard block
 block discarded – undo
260 260
 		$tables = $this->get_results("SHOW TABLES in `".$database."`");
261 261
 		$this->log();
262 262
 
263
-		foreach ($tables as $table){
263
+		foreach ($tables as $table) {
264 264
 			
265 265
 			$table = array_values((array)$table)[0];
266 266
 			
267 267
 			$tablesList[$inc]['name'] = $table;
268 268
 			$tablesList[$inc]['database'] = $database;
269 269
 
270
-			if($get_num_records)
270
+			if ($get_num_records)
271 271
 			{
272 272
 				$records_num_result = $this->get_var("SELECT count(*) FROM `".$database."`.`".$table."`");
273 273
 				$this->log();
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
 			
278 278
 			$tablesList[$inc]['excluded'] = 0;
279 279
 						
280
-			if(sizeof($included) and is_array($included))
281
-				if(!in_array($table, $included) )
280
+			if (sizeof($included) and is_array($included))
281
+				if (!in_array($table, $included))
282 282
 				{
283 283
 					$tablesList[$inc]['excluded'] = 1;
284 284
 					$this->log(sprintf(__("Excluding table %s.%s from backup"), $table, $database));
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 		
300 300
 		$tables = $this->list_tables($dbname, $incl_tables, 1);
301 301
 		
302
-		if($this->dbname != $dbname)
302
+		if ($this->dbname != $dbname)
303 303
 			$dumpfile = $dbname."-backup.sql";
304 304
 		else
305 305
 			$dumpfile = $this->TEMP_DUMP_FILE;
@@ -308,8 +308,8 @@  discard block
 block discarded – undo
308 308
 		$this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line);
309 309
 			
310 310
 		// write this to the class and write to $TEMP_DBPROCESS_FILE file as database.table records
311
-		foreach($tables as $key=>$table) 
312
-		if($table!= "" and !$tables[$key]['excluded']){
311
+		foreach ($tables as $key=>$table) 
312
+		if ($table != "" and !$tables[$key]['excluded']) {
313 313
 
314 314
 			$line = sprintf("`%s`.`%s`\t%s\t%s\n", $dbname, $tables[$key]['name'], $tables[$key]['records'], $tables[$key]['excluded']);
315 315
 			$this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line);
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 
338 338
 			$result = $this->get_var("SELECT count(*) FROM $table;");
339 339
 
340
-			return intval($result) ;// not max limit on 32 bit systems 2147483647; on 64 bit 999999999999
340
+			return intval($result); // not max limit on 32 bit systems 2147483647; on 64 bit 999999999999
341 341
 
342 342
 	}
343 343
 
@@ -353,25 +353,25 @@  discard block
 block discarded – undo
353 353
 	 * 		int $dbDropSyntax	- check if the DROP TABLE syntax should be added
354 354
 	 * @return array $return
355 355
 	 */
356
-	public function process_incremental($startAtLine= 0, $startAtRecord = 0, $dumpfile = "", $dbCompatibility= ""){
356
+	public function process_incremental($startAtLine = 0, $startAtRecord = 0, $dumpfile = "", $dbCompatibility = "") {
357 357
 
358 358
 		$count = 0;
359 359
 		$return['finished'] = 0;
360 360
 		$lines = array();
361 361
 		
362
-		if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE))
363
-			$lines = array_filter(explode("\n",$this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE)));
362
+		if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE))
363
+			$lines = array_filter(explode("\n", $this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE)));
364 364
 	
365
-		foreach ($lines as $buffer){
365
+		foreach ($lines as $buffer) {
366 366
 			
367
-			if($count == $startAtLine)
367
+			if ($count == $startAtLine)
368 368
 			{
369 369
 	
370
-				$tableInfo =explode("\t", $buffer);
370
+				$tableInfo = explode("\t", $buffer);
371 371
 				
372
-				if($tableInfo[0] == "###newdump###"){
372
+				if ($tableInfo[0] == "###newdump###") {
373 373
 						// we create a new mysql dump file
374
-						if($dumpfile != ""){
374
+						if ($dumpfile != "") {
375 375
 								// we finished a previous one and write the footers
376 376
 								$return['dumpsize'] = $this->data_footers($dumpfile);
377 377
 						}
@@ -385,13 +385,13 @@  discard block
 block discarded – undo
385 385
 						$startAtLine++;
386 386
 						$return['new_dump'] = 1;
387 387
 						//break;
388
-				}else{
388
+				} else {
389 389
 						//we export the table
390
-						if($tableInfo[0] == "###enddump###")
390
+						if ($tableInfo[0] == "###enddump###")
391 391
 							$return['endDump'] = 1;
392 392
 	
393 393
 						//table is excluded
394
-						if($tableInfo[2])
394
+						if ($tableInfo[2])
395 395
 							continue;
396 396
 							
397 397
 						$next = $startAtRecord + $this->recordsPerSession;
@@ -403,28 +403,28 @@  discard block
 block discarded – undo
403 403
 
404 404
 						//return something to the browser
405 405
 						$return['databaseName'] 	= $databaseName;
406
-						$return['tableName'] 		= $tableName;
406
+						$return['tableName'] = $tableName;
407 407
 						$return['totalRecords'] 	= $tableInfo[1];
408 408
 
409 409
 						$processed_records = 0;
410 410
 						
411
-						if(trim($tableName) !=""  and !$tableInfo[2])
411
+						if (trim($tableName) != "" and !$tableInfo[2])
412 412
 							$processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile);
413 413
 						
414
-						$return['processedRecords'] = $startAtRecord+$processed_records;
414
+						$return['processedRecords'] = $startAtRecord + $processed_records;
415 415
 						
416
-						if($next >= $tableInfo[1]) //we finished loading the records for next sessions, will go to the new record
416
+						if ($next >= $tableInfo[1]) //we finished loading the records for next sessions, will go to the new record
417 417
 						{
418
-								$startAtLine ++;
418
+								$startAtLine++;
419 419
 								$startAtRecord = 0;
420
-						}else{
420
+						} else {
421 421
 								$startAtRecord = $startAtRecord + $this->recordsPerSession;
422 422
 							}
423 423
 
424 424
 						//$return['dbCompatibility'] 	= self::$dbCompatibility;
425 425
 						
426
-						$return['startAtLine']		= $startAtLine;
427
-						$return['startAtRecord']	= $startAtRecord;
426
+						$return['startAtLine'] = $startAtLine;
427
+						$return['startAtRecord'] = $startAtRecord;
428 428
 						$return['dumpfile']			= $dumpfile;
429 429
 						$return['dumpsize']			= $this->fs->get_tmp_filesystem_append()->getSize($dumpfile);
430 430
 
@@ -442,15 +442,15 @@  discard block
 block discarded – undo
442 442
 		}
443 443
 	
444 444
 		//while is finished, lets go home...
445
-		if($dumpfile != ""){
445
+		if ($dumpfile != "") {
446 446
 			// we finished a previous one and write the footers
447 447
 			$return['dumpsize'] = $this->data_footers($dumpfile);
448 448
 			$return['dumpfile'] = ($dumpfile);
449 449
 		}
450 450
 		$return['finished'] = 1;
451
-		$return['startAtLine']	= $startAtLine;
451
+		$return['startAtLine'] = $startAtLine;
452 452
 		
453
-		if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE))
453
+		if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE))
454 454
 			$this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE);
455 455
 		
456 456
 		$this->logger->debug(sprintf(("Database backup finished!")));
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
 		
480 480
 		$records = 0;
481 481
 		
482
-		if($start == 0)
482
+		if ($start == 0)
483 483
 			$this->dump_structure($databaseName, $tableName, $dumpfile);
484 484
 
485 485
 		$start = intval($start);
@@ -487,20 +487,20 @@  discard block
 block discarded – undo
487 487
 		//exporting the table content now
488 488
 
489 489
 		$query = "SELECT * from `$databaseName`.`$tableName` Limit $start, $limit ;";
490
-		if($this->use_mysqli)
490
+		if ($this->use_mysqli)
491 491
 		{
492 492
 			$result = mysqli_query($this->dbh, $query);
493 493
 			$mysql_fetch_function = "mysqli_fetch_array";
494 494
 		
495
-		}else{
495
+		} else {
496 496
 			$result = mysql_query($query, $this->dbh);
497 497
 			$mysql_fetch_function = "mysqli_fetch_array";
498 498
 		}
499 499
 		//$result = $this->get_results($query, ARRAY_N);
500 500
 		//print_r($result); exit;
501 501
 		
502
-		if($result){
503
-			while($row = $mysql_fetch_function($result, MYSQLI_ASSOC)){
502
+		if ($result) {
503
+			while ($row = $mysql_fetch_function($result, MYSQLI_ASSOC)) {
504 504
 					
505 505
 					$this->fs->get_tmp_filesystem_append()->write($dumpfile, "INSERT INTO `$tableName` VALUES (");
506 506
 					$arr = $row;
@@ -510,13 +510,13 @@  discard block
 block discarded – undo
510 510
 	                foreach ($arr as $key => $value) {
511 511
 						$value = $this->_real_escape($value);
512 512
 						
513
-						if(method_exists($this, 'remove_placeholder_escape')){
513
+						if (method_exists($this, 'remove_placeholder_escape')) {
514 514
 							$value = $this->remove_placeholder_escape($value);
515 515
 						}
516 516
 						
517 517
 						$buffer .= "'".$value."', ";
518 518
 					}
519
-					$buffer = rtrim($buffer, ', ') . ");\n";
519
+					$buffer = rtrim($buffer, ', ').");\n";
520 520
 					$this->fs->get_tmp_filesystem_append()->write($dumpfile, $buffer);
521 521
 					unset($buffer);
522 522
 					
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 
532 532
 	}
533 533
 
534
-	public function dump_structure($databaseName, $tableName ,$dumpfile)
534
+	public function dump_structure($databaseName, $tableName, $dumpfile)
535 535
 	{
536 536
 		$this->log(sprintf(__("Dumping the structure for %s.%s table"), $databaseName, $tableName));
537 537
 		
@@ -546,14 +546,14 @@  discard block
 block discarded – undo
546 546
 
547 547
 		//$result = mysqli_query($this->dbh,"SHOW CREATE table `$databaseName`.`$tableName`;");
548 548
 		$result = $this->get_row("SHOW CREATE table `$databaseName`.`$tableName`;", ARRAY_N);
549
-		if($result){
549
+		if ($result) {
550 550
 			//$row = mysqli_fetch_row( $result);
551 551
 			$line = ($result[1].";\n");
552 552
 			$this->fs->get_tmp_filesystem_append()->write($dumpfile, $line);
553 553
 		}
554 554
 
555
-		$line = ( "\n#\n# End Structure for table `$tableName`\n#\n\n");
556
-		$line .=("#\n# Dumping data for table `$tableName`\n#\n\n");
555
+		$line = ("\n#\n# End Structure for table `$tableName`\n#\n\n");
556
+		$line .= ("#\n# Dumping data for table `$tableName`\n#\n\n");
557 557
 		$this->fs->get_tmp_filesystem_append()->write($dumpfile, $line);
558 558
 		
559 559
 		return;
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
 
577 577
 	}
578 578
 
579
-	public function resetcountRecords(){
579
+	public function resetcountRecords() {
580 580
 		
581 581
 		$this->countRecords = 0;
582 582
 
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
 	
585 585
 	}
586 586
 
587
-	public function getcountRecords(){
587
+	public function getcountRecords() {
588 588
 		
589 589
 		return $this->countRecords;
590 590
 		
@@ -601,14 +601,14 @@  discard block
 block discarded – undo
601 601
 		$return .= "# Powered by XCloner Site Backup\n";
602 602
 		$return .= "# http://www.xcloner.com\n";
603 603
 		$return .= "#\n";
604
-		$return .= "# Host: " . get_site_url() . "\n";
605
-		$return .= "# Generation Time: " . date("M j, Y \a\\t H:i") . "\n";
606
-		$return .= "# PHP Version: " . phpversion() . "\n";
607
-		$return .= "# Database Charset: ". $this->charset . "\n";
604
+		$return .= "# Host: ".get_site_url()."\n";
605
+		$return .= "# Generation Time: ".date("M j, Y \a\\t H:i")."\n";
606
+		$return .= "# PHP Version: ".phpversion()."\n";
607
+		$return .= "# Database Charset: ".$this->charset."\n";
608 608
 		
609 609
 		$results = $this->get_results("SHOW VARIABLES LIKE \"%version%\";", ARRAY_N);
610
-		if(isset($results)){
611
-			foreach($results as $result){
610
+		if (isset($results)) {
611
+			foreach ($results as $result) {
612 612
 
613 613
 					$return .= "# MYSQL ".$result[0].": ".$result[1]."\n";
614 614
 
@@ -618,13 +618,13 @@  discard block
 block discarded – undo
618 618
 		$results = $this->get_results("SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME
619 619
 					FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '".$database."';");
620 620
 		
621
-		if(isset($results[0])){
621
+		if (isset($results[0])) {
622 622
 
623 623
 			$return .= "# MYSQL DEFAULT_CHARACTER_SET_NAME: ".$results[0]->DEFAULT_CHARACTER_SET_NAME."\n";
624 624
 			$return .= "# MYSQL SCHEMA_NAME: ".$results[0]->DEFAULT_COLLATION_NAME."\n";
625 625
 		}
626 626
 
627
-		$return .= "#\n# Database : `" . $database . "`\n# --------------------------------------------------------\n\n";
627
+		$return .= "#\n# Database : `".$database."`\n# --------------------------------------------------------\n\n";
628 628
 		
629 629
 		$this->log(sprintf(__("Writing %s database dump headers"), $database));
630 630
 		
Please login to merge, or discard this patch.
Braces   +75 added lines, -52 removed lines patch added patch discarded remove patch
@@ -44,11 +44,13 @@  discard block
 block discarded – undo
44 44
 		$this->xcloner_settings 		= $xcloner_container->get_xcloner_settings();
45 45
 		$this->fs 						= $xcloner_container->get_xcloner_filesystem();
46 46
 		
47
-		if($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'))
48
-			$this->recordsPerSession		= $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
47
+		if($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request')) {
48
+					$this->recordsPerSession		= $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
49
+		}
49 50
 		
50
-		if(!$this->recordsPerSession)
51
-			$this->recordsPerSession = 100;
51
+		if(!$this->recordsPerSession) {
52
+					$this->recordsPerSession = 100;
53
+		}
52 54
 		
53 55
 		if(!$wp_user && !$wp_pass && !$wp_host && !$wp_db )
54 56
 		{
@@ -108,37 +110,43 @@  discard block
 block discarded – undo
108 110
 			{
109 111
 				foreach($params['#'] as $database)
110 112
 				{
111
-					if(!isset($params[$database]) or !is_array($params[$database]))
112
-						$params[$database] = array();
113
+					if(!isset($params[$database]) or !is_array($params[$database])) {
114
+											$params[$database] = array();
115
+					}
113 116
 				}
114 117
 				$db_count = -1;
115 118
 			}
116 119
 			
117
-			if(isset($params) and is_array($params))
118
-				foreach($params as $database=>$tables)
120
+			if(isset($params) and is_array($params)) {
121
+							foreach($params as $database=>$tables)
119 122
 				{	
120 123
 					if($database != "#")
121 124
 					{
122
-						$stats = $this->write_backup_process_list($database, $tables);	
125
+						$stats = $this->write_backup_process_list($database, $tables);
126
+			}
123 127
 						$return['stats']['tables_count'] 	+= $stats['tables_count'];
124 128
 						$return['stats']['total_records'] 	+= $stats['total_records'];
125 129
 					}
126 130
 				}
127 131
 
128
-			if(sizeof($params))
129
-				$return['stats']['database_count'] = sizeof($params)+$db_count;
130
-			else	
131
-				$return['stats']['database_count'] = 0;
132
+			if(sizeof($params)) {
133
+							$return['stats']['database_count'] = sizeof($params)+$db_count;
134
+			} else {
135
+							$return['stats']['database_count'] = 0;
136
+			}
132 137
 				
133 138
 			return $return;
134 139
 		}
135 140
 		
136
-		if(!isset($extra_params['startAtLine']))
137
-			$extra_params['startAtLine'] = 0;
138
-		if(!isset($extra_params['startAtRecord']))
139
-			$extra_params['startAtRecord'] = 0;
140
-		if(!isset($extra_params['dumpfile']))
141
-			$extra_params['dumpfile'] = "";
141
+		if(!isset($extra_params['startAtLine'])) {
142
+					$extra_params['startAtLine'] = 0;
143
+		}
144
+		if(!isset($extra_params['startAtRecord'])) {
145
+					$extra_params['startAtRecord'] = 0;
146
+		}
147
+		if(!isset($extra_params['dumpfile'])) {
148
+					$extra_params['dumpfile'] = "";
149
+		}
142 150
 		
143 151
 		$return = $this->process_incremental($extra_params['startAtLine'], $extra_params['startAtRecord'], $extra_params['dumpfile']);
144 152
 		
@@ -150,11 +158,13 @@  discard block
 block discarded – undo
150 158
 		
151 159
 		if($message){
152 160
 			$this->logger->info( $message, array(""));
153
-		}else{	
154
-			if($this->last_query)
155
-				$this->logger->debug( $this->last_query, array(""));
156
-			if($this->last_error)
157
-				$this->logger->error( $this->last_error, array(""));
161
+		} else{	
162
+			if($this->last_query) {
163
+							$this->logger->debug( $this->last_query, array(""));
164
+			}
165
+			if($this->last_error) {
166
+							$this->logger->error( $this->last_error, array(""));
167
+			}
158 168
 		}
159 169
 		
160 170
 		return;
@@ -225,11 +235,12 @@  discard block
 block discarded – undo
225 235
 		$databases_list[$i]['num_tables'] = $this->get_database_num_tables($this->dbname);
226 236
 		$i++;
227 237
 		
228
-		if(is_array($databases))
229
-		foreach( $databases as $db){
238
+		if(is_array($databases)) {
239
+				foreach( $databases as $db){
230 240
 			if($db->Database != $this->dbname)
231 241
 			{
232 242
 				$databases_list[$i]['name'] = $db->Database;
243
+		}
233 244
 				$databases_list[$i]['num_tables'] = $this->get_database_num_tables($db->Database);
234 245
 				$i++;
235 246
 			}
@@ -252,8 +263,9 @@  discard block
 block discarded – undo
252 263
 		$tablesList[0] = array( );
253 264
 		$inc = 0;
254 265
 
255
-		if(!$database)
256
-			$database = $this->dbname;
266
+		if(!$database) {
267
+					$database = $this->dbname;
268
+		}
257 269
 		
258 270
 		$this->logger->debug(sprintf(("Listing tables in %s database"), $database));
259 271
 		
@@ -277,10 +289,11 @@  discard block
 block discarded – undo
277 289
 			
278 290
 			$tablesList[$inc]['excluded'] = 0;
279 291
 						
280
-			if(sizeof($included) and is_array($included))
281
-				if(!in_array($table, $included) )
292
+			if(sizeof($included) and is_array($included)) {
293
+							if(!in_array($table, $included) )
282 294
 				{
283 295
 					$tablesList[$inc]['excluded'] = 1;
296
+			}
284 297
 					$this->log(sprintf(__("Excluding table %s.%s from backup"), $table, $database));
285 298
 				}
286 299
 			$inc++;
@@ -299,19 +312,21 @@  discard block
 block discarded – undo
299 312
 		
300 313
 		$tables = $this->list_tables($dbname, $incl_tables, 1);
301 314
 		
302
-		if($this->dbname != $dbname)
303
-			$dumpfile = $dbname."-backup.sql";
304
-		else
305
-			$dumpfile = $this->TEMP_DUMP_FILE;
315
+		if($this->dbname != $dbname) {
316
+					$dumpfile = $dbname."-backup.sql";
317
+		} else {
318
+					$dumpfile = $this->TEMP_DUMP_FILE;
319
+		}
306 320
 		
307 321
 		$line = sprintf("###newdump###\t%s\t%s\n", $dbname, $dumpfile);
308 322
 		$this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line);
309 323
 			
310 324
 		// write this to the class and write to $TEMP_DBPROCESS_FILE file as database.table records
311
-		foreach($tables as $key=>$table) 
312
-		if($table!= "" and !$tables[$key]['excluded']){
325
+		foreach($tables as $key=>$table) {
326
+				if($table!= "" and !$tables[$key]['excluded']){
313 327
 
314 328
 			$line = sprintf("`%s`.`%s`\t%s\t%s\n", $dbname, $tables[$key]['name'], $tables[$key]['records'], $tables[$key]['excluded']);
329
+		}
315 330
 			$this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line);
316 331
 			$return['tables_count']++;
317 332
 			$return['total_records'] += $tables[$key]['records'];
@@ -359,8 +374,9 @@  discard block
 block discarded – undo
359 374
 		$return['finished'] = 0;
360 375
 		$lines = array();
361 376
 		
362
-		if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE))
363
-			$lines = array_filter(explode("\n",$this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE)));
377
+		if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) {
378
+					$lines = array_filter(explode("\n",$this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE)));
379
+		}
364 380
 	
365 381
 		foreach ($lines as $buffer){
366 382
 			
@@ -385,14 +401,16 @@  discard block
 block discarded – undo
385 401
 						$startAtLine++;
386 402
 						$return['new_dump'] = 1;
387 403
 						//break;
388
-				}else{
404
+				} else{
389 405
 						//we export the table
390
-						if($tableInfo[0] == "###enddump###")
391
-							$return['endDump'] = 1;
406
+						if($tableInfo[0] == "###enddump###") {
407
+													$return['endDump'] = 1;
408
+						}
392 409
 	
393 410
 						//table is excluded
394
-						if($tableInfo[2])
395
-							continue;
411
+						if($tableInfo[2]) {
412
+													continue;
413
+						}
396 414
 							
397 415
 						$next = $startAtRecord + $this->recordsPerSession;
398 416
 						
@@ -408,16 +426,19 @@  discard block
 block discarded – undo
408 426
 
409 427
 						$processed_records = 0;
410 428
 						
411
-						if(trim($tableName) !=""  and !$tableInfo[2])
412
-							$processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile);
429
+						if(trim($tableName) !=""  and !$tableInfo[2]) {
430
+													$processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile);
431
+						}
413 432
 						
414 433
 						$return['processedRecords'] = $startAtRecord+$processed_records;
415 434
 						
416
-						if($next >= $tableInfo[1]) //we finished loading the records for next sessions, will go to the new record
435
+						if($next >= $tableInfo[1]) {
436
+							//we finished loading the records for next sessions, will go to the new record
417 437
 						{
418 438
 								$startAtLine ++;
439
+						}
419 440
 								$startAtRecord = 0;
420
-						}else{
441
+						} else{
421 442
 								$startAtRecord = $startAtRecord + $this->recordsPerSession;
422 443
 							}
423 444
 
@@ -450,8 +471,9 @@  discard block
 block discarded – undo
450 471
 		$return['finished'] = 1;
451 472
 		$return['startAtLine']	= $startAtLine;
452 473
 		
453
-		if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE))
454
-			$this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE);
474
+		if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) {
475
+					$this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE);
476
+		}
455 477
 		
456 478
 		$this->logger->debug(sprintf(("Database backup finished!")));
457 479
 		
@@ -479,8 +501,9 @@  discard block
 block discarded – undo
479 501
 		
480 502
 		$records = 0;
481 503
 		
482
-		if($start == 0)
483
-			$this->dump_structure($databaseName, $tableName, $dumpfile);
504
+		if($start == 0) {
505
+					$this->dump_structure($databaseName, $tableName, $dumpfile);
506
+		}
484 507
 
485 508
 		$start = intval($start);
486 509
 		$limit = intval($limit);
@@ -492,7 +515,7 @@  discard block
 block discarded – undo
492 515
 			$result = mysqli_query($this->dbh, $query);
493 516
 			$mysql_fetch_function = "mysqli_fetch_array";
494 517
 		
495
-		}else{
518
+		} else{
496 519
 			$result = mysql_query($query, $this->dbh);
497 520
 			$mysql_fetch_function = "mysqli_fetch_array";
498 521
 		}
Please login to merge, or discard this patch.
uninstall.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,6 +26,6 @@
 block discarded – undo
26 26
  */
27 27
 
28 28
 // If uninstall not called from WordPress, then exit.
29
-if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
29
+if (!defined('WP_UNINSTALL_PLUGIN')) {
30 30
 	exit;
31 31
 }
Please login to merge, or discard this patch.
restore/xcloner_restore.php 5 patches
Unused Use Statements   -5 removed lines patch added patch discarded remove patch
@@ -65,13 +65,8 @@
 block discarded – undo
65 65
 
66 66
 use League\Flysystem\Config;
67 67
 use League\Flysystem\Filesystem;
68
-use League\Flysystem\Util;
69 68
 use League\Flysystem\Adapter\Local;
70
-
71 69
 use splitbrain\PHPArchive\Tar;
72
-use splitbrain\PHPArchive\Archive;
73
-use splitbrain\PHPArchive\FileInfo;
74
-
75 70
 use Monolog\Logger;
76 71
 use Monolog\Handler\StreamHandler;
77 72
 
Please login to merge, or discard this patch.
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -158,15 +158,15 @@  discard block
 block discarded – undo
158 158
 	}
159 159
 	
160 160
 	private function friendly_error_type($type) {
161
-	    static $levels=null;
162
-	    if ($levels===null) {
163
-	        $levels=[];
164
-	        foreach (get_defined_constants() as $key=>$value) {
165
-	            if (strpos($key,'E_')!==0) {continue;}
161
+		static $levels=null;
162
+		if ($levels===null) {
163
+			$levels=[];
164
+			foreach (get_defined_constants() as $key=>$value) {
165
+				if (strpos($key,'E_')!==0) {continue;}
166 166
 					$levels[$value]= $key; //substr($key,2);
167
-	        }
168
-	    }
169
-	    return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}");
167
+			}
168
+		}
169
+		return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}");
170 170
 	}
171 171
 	
172 172
 	public function get_logger_filename()
@@ -887,19 +887,19 @@  discard block
 block discarded – undo
887 887
 	}
888 888
 	
889 889
 	private function return_bytes($val) {
890
-	    $val = trim($val);
891
-	    $last = strtolower($val[strlen($val)-1]);
892
-	    switch($last) {
893
-	        // The 'G' modifier is available since PHP 5.1.0
894
-	        case 'g':
895
-	            $val *= 1024;
896
-	        case 'm':
897
-	            $val *= 1024;
898
-	        case 'k':
899
-	            $val *= 1024;
900
-	    }
890
+		$val = trim($val);
891
+		$last = strtolower($val[strlen($val)-1]);
892
+		switch($last) {
893
+			// The 'G' modifier is available since PHP 5.1.0
894
+			case 'g':
895
+				$val *= 1024;
896
+			case 'm':
897
+				$val *= 1024;
898
+			case 'k':
899
+				$val *= 1024;
900
+		}
901 901
 	
902
-	    return $val;
902
+		return $val;
903 903
 	}
904 904
 	
905 905
 	public function is_multipart($backup_name)
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
 	{
948 948
 		$direction = strtolower($direction);
949 949
 		
950
-	    usort($array, create_function('$a, $b', '
950
+		usort($array, create_function('$a, $b', '
951 951
 	        $a = $a["' . $field . '"];
952 952
 	        $b = $b["' . $field . '"];
953 953
 	
@@ -959,7 +959,7 @@  discard block
 block discarded – undo
959 959
 	        return ($a ' . ($direction == 'desc' ? '>' : '<') .' $b) ? -1 : 1;
960 960
 	    '));
961 961
 	
962
-	    return true;
962
+		return true;
963 963
 	}
964 964
 		
965 965
 	public static function send_response($status = 200, $response)
@@ -999,10 +999,10 @@  discard block
 block discarded – undo
999 999
 					$m[3] = "";
1000 1000
 					
1001 1001
 					$data = 's:'.strlen(($m[3])).':\"'.($m[3]).'\";';
1002
-	              //return $this->unescape_quotes($data);
1002
+				  //return $this->unescape_quotes($data);
1003 1003
 	              
1004
-	              return $data;
1005
-	            }, $query);
1004
+				  return $data;
1005
+				}, $query);
1006 1006
 	}
1007 1007
 	
1008 1008
 	private function unescape_quotes($value) {
@@ -1019,14 +1019,14 @@  discard block
 block discarded – undo
1019 1019
 	private function has_serialized($s)
1020 1020
 	{
1021 1021
 		if(
1022
-		    stristr($s, '{' ) != false &&
1023
-		    stristr($s, '}' ) != false &&
1024
-		    stristr($s, ';' ) != false &&
1025
-		    stristr($s, ':' ) != false
1026
-		    ){
1027
-		    return true;
1022
+			stristr($s, '{' ) != false &&
1023
+			stristr($s, '}' ) != false &&
1024
+			stristr($s, ';' ) != false &&
1025
+			stristr($s, ':' ) != false
1026
+			){
1027
+			return true;
1028 1028
 		}else{
1029
-		    return false;
1029
+			return false;
1030 1030
 		}
1031 1031
 
1032 1032
 	}
Please login to merge, or discard this patch.
Braces   +113 added lines, -87 removed lines patch added patch discarded remove patch
@@ -45,11 +45,10 @@  discard block
 block discarded – undo
45 45
 {
46 46
 	
47 47
 	require_once($file);
48
-}
49
-elseif(file_exists("vendor.phar") and extension_loaded('phar'))
48
+} elseif(file_exists("vendor.phar") and extension_loaded('phar'))
50 49
 {
51 50
 	require_once(__DIR__.DS."vendor.phar");
52
-}else{	
51
+} else{	
53 52
 	
54 53
 	$file = dirname( __FILE__ )  . DS.'vendor'.DS.'autoload.php';
55 54
 	
@@ -87,7 +86,7 @@  discard block
 block discarded – undo
87 86
 try{
88 87
 	$return = $xcloner_restore->init();
89 88
 	$xcloner_restore->send_response(200, $return);
90
-}catch(Exception $e){
89
+} catch(Exception $e){
91 90
 	$xcloner_restore->send_response(417, $e->getMessage());
92 91
 }
93 92
 
@@ -191,7 +190,7 @@  discard block
 block discarded – undo
191 190
 				$this->logger->debug(sprintf('Starting action %s', $method));
192 191
 				return call_user_func(array($this, $method));
193 192
 				
194
-			}else{
193
+			} else{
195 194
 				throw new Exception($method ." does not exists");
196 195
 				}
197 196
 		}
@@ -205,13 +204,15 @@  discard block
 block discarded – undo
205 204
 		{
206 205
 			$target_file = filter_input(INPUT_POST, 'file', FILTER_SANITIZE_STRING);
207 206
 			
208
-			if(!$_POST['start'])
209
-				$fp = fopen($target_file, "wb+");
210
-			else
211
-				$fp = fopen($target_file, "ab+");	
207
+			if(!$_POST['start']) {
208
+							$fp = fopen($target_file, "wb+");
209
+			} else {
210
+							$fp = fopen($target_file, "ab+");
211
+			}
212 212
 			
213
-			if(!$fp)
214
-				throw new Exception("Unable to open $target_file file for writing");
213
+			if(!$fp) {
214
+							throw new Exception("Unable to open $target_file file for writing");
215
+			}
215 216
 			
216 217
 			fseek($fp, $_POST['start']);
217 218
 			
@@ -221,18 +222,20 @@  discard block
 block discarded – undo
221 222
 				
222 223
 				$blob = file_get_contents($_FILES['blob']['tmp_name']);
223 224
 				
224
-				if(!$bytes_written = fwrite($fp, $blob))
225
-					throw new Exception("Unable to write data to file $target_file");
225
+				if(!$bytes_written = fwrite($fp, $blob)) {
226
+									throw new Exception("Unable to write data to file $target_file");
227
+				}
226 228
 				
227 229
 				@unlink($_FILES['blob']['tmp_name']);
228
-			}elseif(isset($_POST['blob'])){
230
+			} elseif(isset($_POST['blob'])){
229 231
 				$this->logger->debug(sprintf('Writing %s bytes to file %s starting position %s using POST blob', strlen($_POST['blob']), $target_file, $_POST['start']));
230 232
 				
231 233
 				$blob = $_POST['blob'];
232 234
 
233
-				if(!$bytes_written = fwrite($fp, $blob))
234
-					throw new Exception("Unable to write data to file $target_file");
235
-			}else{
235
+				if(!$bytes_written = fwrite($fp, $blob)) {
236
+									throw new Exception("Unable to write data to file $target_file");
237
+				}
238
+			} else{
236 239
 				throw new Exception("Upload failed, did not receive any binary data");
237 240
 			}
238 241
 			
@@ -256,10 +259,11 @@  discard block
 block discarded – undo
256 259
 		
257 260
 		$mysqli->query("SET sql_mode='';");
258 261
 		$mysqli->query("SET foreign_key_checks = 0;");
259
-		if(isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file'])
260
-			$mysqli->query("SET NAMES ".$_REQUEST['charset_of_file']."");
261
-		else
262
-			$mysqli->query("SET NAMES utf8;");
262
+		if(isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file']) {
263
+					$mysqli->query("SET NAMES ".$_REQUEST['charset_of_file']."");
264
+		} else {
265
+					$mysqli->query("SET NAMES utf8;");
266
+		}
263 267
 			
264 268
 		return $mysqli;	
265 269
 	}
@@ -284,8 +288,9 @@  discard block
 block discarded – undo
284 288
 		
285 289
 		$mysql_backup_file = $remote_path.DS.$mysqldump_file;
286 290
 		
287
-		if(!file_exists($mysql_backup_file))
288
-			throw new Exception(sprintf("Mysql backup file %s does not exists",$mysql_backup_file));
291
+		if(!file_exists($mysql_backup_file)) {
292
+					throw new Exception(sprintf("Mysql backup file %s does not exists",$mysql_backup_file));
293
+		}
289 294
 		
290 295
 		
291 296
 		/*if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS)
@@ -317,16 +322,18 @@  discard block
 block discarded – undo
317 322
 			// process the line read.
318 323
 									
319 324
 				//check if line is comment
320
-				if(substr($line, 0, 1) == "#")
321
-					continue;
325
+				if(substr($line, 0, 1) == "#") {
326
+									continue;
327
+				}
322 328
 				
323 329
 				//check if line is empty	
324
-				if($line == "\n" or trim($line) == "")
325
-					continue;
330
+				if($line == "\n" or trim($line) == "") {
331
+									continue;
332
+				}
326 333
 					
327
-				if(substr($line, strlen($line)-2, strlen($line)) == ";\n")
328
-					$query .= $line;
329
-				else{
334
+				if(substr($line, strlen($line)-2, strlen($line)) == ";\n") {
335
+									$query .= $line;
336
+				} else{
330 337
 					$query .= $line;
331 338
 					continue;
332 339
 				}
@@ -385,7 +392,7 @@  discard block
 block discarded – undo
385 392
 		if(!feof($fp))
386 393
 		{
387 394
 			$return['finished'] = 0;
388
-		}else{
395
+		} else{
389 396
 			$this->logger->info(sprintf("Mysql Import Done."));
390 397
 		}
391 398
 		
@@ -437,7 +444,7 @@  discard block
 block discarded – undo
437 444
 			$tar->open($this->backup_storage_dir.DS.$backup_file, $start);
438 445
 		
439 446
 			$data = $tar->contents($this->process_files_limit_list);
440
-		}catch(Exception $e)
447
+		} catch(Exception $e)
441 448
 		{
442 449
 			$return['error'] = true;
443 450
 			$return['message'] = $e->getMessage();
@@ -465,15 +472,16 @@  discard block
 block discarded – undo
465 472
 		{
466 473
 			$return['start'] = $data['start'];
467 474
 			$return['finished'] = 0;	
468
-		}else{
475
+		} else{
469 476
 			if($this->is_multipart($source_backup_file))
470 477
 			{
471 478
 				$return['start'] = 0;
472 479
 				
473 480
 				++$return['part'];
474 481
 			
475
-				if($return['part'] < sizeof($backup_parts))	
476
-					$return['finished'] = 0;
482
+				if($return['part'] < sizeof($backup_parts)) {
483
+									$return['finished'] = 0;
484
+				}
477 485
 				
478 486
 			}
479 487
 		}	
@@ -590,19 +598,22 @@  discard block
 block discarded – undo
590 598
 		{
591 599
 			$config = file_get_contents($wp_config);
592 600
 			preg_match("/.*table_prefix.*=.*'(.*)'/i", $config, $matches);
593
-			if(isset($matches[1]))
594
-				$table_prefix = $matches[1];
595
-			else
596
-				throw new Exception("Could not load wordpress table prefix from wp-config.php file.");
601
+			if(isset($matches[1])) {
602
+							$table_prefix = $matches[1];
603
+			} else {
604
+							throw new Exception("Could not load wordpress table prefix from wp-config.php file.");
605
+			}
606
+		} else {
607
+					throw new Exception("Could not update the SITEURL and HOME, wp-config.php file not found");
597 608
 		}
598
-		else
599
-			throw new Exception("Could not update the SITEURL and HOME, wp-config.php file not found");
600 609
 			
601
-		if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'"))
602
-			throw new Exception(sprintf("Could not update the HOME option, error: %s\n", $mysqli->error));
610
+		if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'")) {
611
+					throw new Exception(sprintf("Could not update the HOME option, error: %s\n", $mysqli->error));
612
+		}
603 613
 		
604
-		if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'"))
605
-			throw new Exception(sprintf("Could not update the SITEURL option, error: %s\n", $mysqli->error));
614
+		if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'")) {
615
+					throw new Exception(sprintf("Could not update the SITEURL option, error: %s\n", $mysqli->error));
616
+		}
606 617
 		
607 618
 		return true;
608 619
 	}
@@ -629,8 +640,9 @@  discard block
 block discarded – undo
629 640
 		
630 641
 		$this->logger->info(sprintf('Updating wp-config.php file with the new mysql details'));
631 642
 		
632
-		if(!file_put_contents($wp_config, $content))
633
-			throw new Exception("Could not write updated config data to ".$wp_config);
643
+		if(!file_put_contents($wp_config, $content)) {
644
+					throw new Exception("Could not write updated config data to ".$wp_config);
645
+		}
634 646
 		
635 647
 		chmod($wp_config, $file_perms);
636 648
 		
@@ -671,10 +683,11 @@  discard block
 block discarded – undo
671 683
 							$mysqldump_list[$file['path']]['size'] = $file['size'];
672 684
 							$mysqldump_list[$file['path']]['timestamp'] = date("d M,Y H:i",$file['timestamp']);
673 685
 							
674
-							if($hash and $hash == $matches[1])
675
-								$mysqldump_list[$file['path']]['selected'] = "selected";
676
-							else
677
-								$mysqldump_list[$file['path']]['selected'] = "";	
686
+							if($hash and $hash == $matches[1]) {
687
+															$mysqldump_list[$file['path']]['selected'] = "selected";
688
+							} else {
689
+															$mysqldump_list[$file['path']]['selected'] = "";
690
+							}
678 691
 						}
679 692
 					}
680 693
 				}
@@ -689,13 +702,15 @@  discard block
 block discarded – undo
689 702
 	
690 703
 	private function get_hash_from_backup($backup_file)
691 704
 	{
692
-		if(!$backup_file)
693
-			return false;
705
+		if(!$backup_file) {
706
+					return false;
707
+		}
694 708
 			
695 709
 		$result = preg_match("/-(\w*)./", substr($backup_file, strlen($backup_file)-10, strlen($backup_file)), $matches)	;
696 710
 		
697
-		if($result and isset($matches[1]))
698
-			return ($matches[1]);
711
+		if($result and isset($matches[1])) {
712
+					return ($matches[1]);
713
+		}
699 714
 		
700 715
 		return false;
701 716
 	}
@@ -715,10 +730,11 @@  discard block
 block discarded – undo
715 730
 			if(isset($file_info['extension']) and $file_info['extension'] == "csv")
716 731
 			{
717 732
 				$lines = explode(PHP_EOL, $this->filesystem->read($file_info['path']));
718
-				foreach($lines as $line)
719
-					if($line)
733
+				foreach($lines as $line) {
734
+									if($line)
720 735
 					{
721 736
 						$data = str_getcsv($line);
737
+				}
722 738
 						if(is_array($data)){
723 739
 							$parents[$data[0]] = $file_info['path'];
724 740
 							$file_info['childs'][] = $data;
@@ -728,20 +744,22 @@  discard block
 block discarded – undo
728 744
 						
729 745
 			}
730 746
 			
731
-			if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions))
732
-				$backup_files[$file_info['path']] = $file_info;
747
+			if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) {
748
+							$backup_files[$file_info['path']] = $file_info;
749
+			}
733 750
 		}
734 751
 		
735 752
 		$new_list = array();
736 753
 		
737 754
 		foreach($backup_files as $key=>$file_info)
738 755
 		{
739
-			if(isset($parents[$file_info['path']]))
740
-				$backup_files[$key]['parent'] = $parents[$file_info['path']];
741
-			else{
756
+			if(isset($parents[$file_info['path']])) {
757
+							$backup_files[$key]['parent'] = $parents[$file_info['path']];
758
+			} else{
742 759
 				
743
-				if($local_backup_file and ($file_info['basename'] == $local_backup_file))
744
-					$file_info['selected'] = 'selected';
760
+				if($local_backup_file and ($file_info['basename'] == $local_backup_file)) {
761
+									$file_info['selected'] = 'selected';
762
+				}
745 763
 				
746 764
 				$this->logger->info(sprintf('Found %s backup file', $file_info['path']));
747 765
 					
@@ -782,8 +800,9 @@  discard block
 block discarded – undo
782 800
 		$backup_archive = new Tar();
783 801
 		if($this->is_multipart($backup_file))
784 802
 		{
785
-			if(!$return['part'])
786
-				$return['processed'] += $this->filesystem->getSize($backup_file);
803
+			if(!$return['part']) {
804
+							$return['processed'] += $this->filesystem->getSize($backup_file);
805
+			}
787 806
 				
788 807
 			$backup_parts = $this->get_multipart_files($backup_file);
789 808
 			$backup_file = $backup_parts[$return['part']];	
@@ -803,12 +822,13 @@  discard block
 block discarded – undo
803 822
 			}
804 823
 		}
805 824
 		
806
-		if(isset($data['start']))
807
-		//if(isset($data['start']) and $data['start'] <= $this->filesystem->getSize($backup_file))
825
+		if(isset($data['start'])) {
826
+				//if(isset($data['start']) and $data['start'] <= $this->filesystem->getSize($backup_file))
808 827
 		{
809 828
 			$return['finished'] = 0;
829
+		}
810 830
 			$return['start'] = $data['start'];
811
-		}else{
831
+		} else{
812 832
 			
813 833
 			$return['processed'] += $start;
814 834
 			
@@ -818,14 +838,16 @@  discard block
 block discarded – undo
818 838
 				
819 839
 				++$return['part'];
820 840
 			
821
-				if($return['part'] < sizeof($backup_parts))	
822
-					$return['finished'] = 0;
841
+				if($return['part'] < sizeof($backup_parts)) {
842
+									$return['finished'] = 0;
843
+				}
823 844
 				
824 845
 			}
825 846
 		}
826 847
 		
827
-		if($return['finished'])
828
-			$this->logger->info(sprintf('Done extracting %s', $source_backup_file));
848
+		if($return['finished']) {
849
+					$this->logger->info(sprintf('Done extracting %s', $source_backup_file));
850
+		}
829 851
 		
830 852
 		$return['backup_file'] = $backup_file;
831 853
 		
@@ -854,8 +876,7 @@  discard block
 block discarded – undo
854 876
 			$return['remote_mysql_user'] 	= $wpdb->dbuser;
855 877
 			$return['remote_mysql_pass'] 	= $wpdb->dbpassword;
856 878
 			$return['remote_mysql_db'] 		= $wpdb->dbname;
857
-		}
858
-		else{
879
+		} else{
859 880
 			$return['dir'] = ($pathinfo['dirname']).DS.$suffix;
860 881
 			$return['restore_script_url'] = str_replace($pathinfo['basename'], "", $restore_script_url).$suffix;
861 882
 		}	
@@ -869,11 +890,13 @@  discard block
 block discarded – undo
869 890
 	{
870 891
 		//check if i can write
871 892
 		$tmp_file = md5(time());
872
-		if(!file_put_contents($tmp_file, "++"))
873
-			throw new Exception("Could not write to new host");
893
+		if(!file_put_contents($tmp_file, "++")) {
894
+					throw new Exception("Could not write to new host");
895
+		}
874 896
 		
875
-		if(!unlink($tmp_file))
876
-			throw new Exception("Could not delete temporary file from new host");
897
+		if(!unlink($tmp_file)) {
898
+					throw new Exception("Could not delete temporary file from new host");
899
+		}
877 900
 		
878 901
 		$max_upload      = $this->return_bytes((ini_get('upload_max_filesize')));
879 902
 		$max_post        = $this->return_bytes((ini_get('post_max_size')));
@@ -904,8 +927,9 @@  discard block
 block discarded – undo
904 927
 	
905 928
 	public function is_multipart($backup_name)
906 929
 	{
907
-		if(stristr($backup_name, "-multipart"))
908
-			return true;
930
+		if(stristr($backup_name, "-multipart")) {
931
+					return true;
932
+		}
909 933
 		
910 934
 		return false;	
911 935
 	}
@@ -916,8 +940,9 @@  discard block
 block discarded – undo
916 940
 		if($this->is_multipart($backup_name))
917 941
 		{
918 942
 			$backup_parts = $this->get_multipart_files($backup_name);
919
-			foreach($backup_parts as $part_file)
920
-				$backup_size += $this->filesystem->getSize($part_file);
943
+			foreach($backup_parts as $part_file) {
944
+							$backup_size += $this->filesystem->getSize($part_file);
945
+			}
921 946
 		}
922 947
 		
923 948
 		return $backup_size;
@@ -974,7 +999,7 @@  discard block
 block discarded – undo
974 999
 		{
975 1000
 			$return['statusText'] = $response['message'];
976 1001
 			$return['error'] = true;
977
-		}elseif($status != 200 and $status != 418)
1002
+		} elseif($status != 200 and $status != 418)
978 1003
 		{
979 1004
 			$return['error'] = true;
980 1005
 			$return['message'] = $response;
@@ -995,8 +1020,9 @@  discard block
 block discarded – undo
995 1020
 		return preg_replace_callback('!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!', function ($m) {
996 1021
 				  $data = "";
997 1022
 				  	
998
-				  if(!isset($m[3]))
999
-					$m[3] = "";
1023
+				  if(!isset($m[3])) {
1024
+				  					$m[3] = "";
1025
+				  }
1000 1026
 					
1001 1027
 					$data = 's:'.strlen(($m[3])).':\"'.($m[3]).'\";';
1002 1028
 	              //return $this->unescape_quotes($data);
@@ -1025,7 +1051,7 @@  discard block
 block discarded – undo
1025 1051
 		    stristr($s, ':' ) != false
1026 1052
 		    ){
1027 1053
 		    return true;
1028
-		}else{
1054
+		} else{
1029 1055
 		    return false;
1030 1056
 		}
1031 1057
 
Please login to merge, or discard this patch.
Doc Comments   +12 added lines patch added patch discarded remove patch
@@ -580,6 +580,9 @@  discard block
 block discarded – undo
580 580
 		
581 581
 	}
582 582
 	
583
+	/**
584
+	 * @param mysqli $mysqli
585
+	 */
583 586
 	private function update_wp_url($wp_path, $url, $mysqli)
584 587
 	{
585 588
 		$wp_config = $wp_path.DS."wp-config.php";
@@ -886,6 +889,9 @@  discard block
 block discarded – undo
886 889
 		$this->send_response(200, $return);
887 890
 	}
888 891
 	
892
+	/**
893
+	 * @param string $val
894
+	 */
889 895
 	private function return_bytes($val) {
890 896
 	    $val = trim($val);
891 897
 	    $last = strtolower($val[strlen($val)-1]);
@@ -943,6 +949,9 @@  discard block
 block discarded – undo
943 949
 		return $files;
944 950
 	}
945 951
 	
952
+	/**
953
+	 * @param string $field
954
+	 */
946 955
 	private function sort_by( &$array, $field, $direction = 'asc')
947 956
 	{
948 957
 		$direction = strtolower($direction);
@@ -988,6 +997,9 @@  discard block
 block discarded – undo
988 997
 	 * Serialize fix methods below for mysql query lines
989 998
 	 */ 
990 999
 	 
1000
+	/**
1001
+	 * @return string
1002
+	 */
991 1003
 	function do_serialized_fix($query)
992 1004
 	{
993 1005
 		$query = str_replace(array("\\n","\\r","\\'"), array("","","\""), ($query));
Please login to merge, or discard this patch.
Spacing   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -1,30 +1,30 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if(!defined('AUTH_KEY'))
3
+if (!defined('AUTH_KEY'))
4 4
 {
5 5
 	define('AUTH_KEY', '');
6 6
 }
7 7
 
8
-if(!defined("DS"))
8
+if (!defined("DS"))
9 9
 {
10 10
 	define("DS", DIRECTORY_SEPARATOR);
11 11
 }
12 12
 
13
-if(!defined('XCLONER_PLUGIN_ACCESS') || XCLONER_PLUGIN_ACCESS != 1)
13
+if (!defined('XCLONER_PLUGIN_ACCESS') || XCLONER_PLUGIN_ACCESS != 1)
14 14
 {	
15
-	if(!AUTH_KEY)
15
+	if (!AUTH_KEY)
16 16
 	{
17 17
 			Xcloner_Restore::send_response("404", "Could not run restore script, AUTH_KEY not set!");
18 18
 			exit;
19 19
 	}
20 20
 	
21
-	if(!isset($_REQUEST['hash']))
21
+	if (!isset($_REQUEST['hash']))
22 22
 	{
23 23
 			Xcloner_Restore::send_response("404", "Could not run restore script, sent HASH is empty!");
24 24
 			exit;
25 25
 	}
26 26
 	
27
-	if($_REQUEST['hash'] != AUTH_KEY)
27
+	if ($_REQUEST['hash'] != AUTH_KEY)
28 28
 	{
29 29
 			Xcloner_Restore::send_response("404", "Could not run restore script, AUTH_KEY doesn't match the sent HASH!");
30 30
 			exit;
@@ -32,28 +32,28 @@  discard block
 block discarded – undo
32 32
 }
33 33
 
34 34
 //check minimum PHP version
35
-if(version_compare(phpversion(), Xcloner_Restore::xcloner_minimum_version, '<'))
35
+if (version_compare(phpversion(), Xcloner_Restore::xcloner_minimum_version, '<'))
36 36
 {
37
-	Xcloner_Restore::send_response(500, sprintf(("XCloner requires minimum PHP version %s in order to run correctly. We have detected your version as %s"),Xcloner_Restore::xcloner_minimum_version, phpversion()) );
37
+	Xcloner_Restore::send_response(500, sprintf(("XCloner requires minimum PHP version %s in order to run correctly. We have detected your version as %s"), Xcloner_Restore::xcloner_minimum_version, phpversion()));
38 38
 	exit;
39 39
 
40 40
 }
41 41
 
42
-$file = dirname( __DIR__ )  . DS.'vendor'.DS.'autoload.php';
42
+$file = dirname(__DIR__).DS.'vendor'.DS.'autoload.php';
43 43
 
44
-if(file_exists($file))
44
+if (file_exists($file))
45 45
 {
46 46
 	
47 47
 	require_once($file);
48 48
 }
49
-elseif(file_exists("vendor.phar") and extension_loaded('phar'))
49
+elseif (file_exists("vendor.phar") and extension_loaded('phar'))
50 50
 {
51 51
 	require_once(__DIR__.DS."vendor.phar");
52
-}else{	
52
+} else {	
53 53
 	
54
-	$file = dirname( __FILE__ )  . DS.'vendor'.DS.'autoload.php';
54
+	$file = dirname(__FILE__).DS.'vendor'.DS.'autoload.php';
55 55
 	
56
-	if(!file_exists($file))
56
+	if (!file_exists($file))
57 57
 	{
58 58
 		Xcloner_Restore::send_response("404", "File $file does not exists, please extract the vendor.tgz archive on the server or enable PHP Phar module!");
59 59
 		exit;
@@ -78,16 +78,16 @@  discard block
 block discarded – undo
78 78
 
79 79
 //do not modify below
80 80
 $that = "";
81
-if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS)
81
+if (defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS)
82 82
 {
83 83
 	$that = $this;
84 84
 }
85 85
 $xcloner_restore = new Xcloner_Restore($that);
86 86
 
87
-try{
87
+try {
88 88
 	$return = $xcloner_restore->init();
89 89
 	$xcloner_restore->send_response(200, $return);
90
-}catch(Exception $e){
90
+}catch (Exception $e) {
91 91
 	$xcloner_restore->send_response(417, $e->getMessage());
92 92
 }
93 93
 
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
 	
97 97
 	const 	xcloner_minimum_version = "5.4.0";
98 98
 	
99
-	private $backup_archive_extensions 		= array("zip", "tar", "tgz", "tar.gz", "gz", "csv");
100
-	private $process_files_limit 			= 150;
101
-	private $process_files_limit_list 		= 350;
102
-	private $process_mysql_records_limit 	= 250;
99
+	private $backup_archive_extensions = array("zip", "tar", "tgz", "tar.gz", "gz", "csv");
100
+	private $process_files_limit = 150;
101
+	private $process_files_limit_list = 350;
102
+	private $process_mysql_records_limit = 250;
103 103
 	private $adapter;
104 104
 	private $filesystem;
105 105
 	private $logger;
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
 	{
112 112
 		register_shutdown_function(array($this, 'exception_handler'));
113 113
 
114
-		if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS)
114
+		if (defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS)
115 115
 		{
116 116
 			$dir = $parent_api->get_xcloner_container()->get_xcloner_settings()->get_xcloner_store_path();
117 117
 		}
118 118
 		
119
-		if(!isset($dir) || !$dir){
119
+		if (!isset($dir) || !$dir) {
120 120
 			$dir = dirname(__FILE__);
121 121
 		}
122 122
 		
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 		
125 125
 		$this->backup_storage_dir = $dir;
126 126
 		
127
-		$this->adapter = new Local($dir ,LOCK_EX, 'SKIP_LINKS');
127
+		$this->adapter = new Local($dir, LOCK_EX, 'SKIP_LINKS');
128 128
 		$this->filesystem = new Filesystem($this->adapter, new Config([
129 129
 				'disable_asserts' => true,
130 130
 			]));
@@ -133,15 +133,15 @@  discard block
 block discarded – undo
133 133
 		
134 134
 		$logger_path = $this->get_logger_filename();
135 135
 		
136
-		if(!is_writeable($logger_path) and !touch($logger_path))
136
+		if (!is_writeable($logger_path) and !touch($logger_path))
137 137
 		{
138 138
 			$logger_path = "php://stderr";
139 139
 		}
140 140
 		
141 141
 		$this->logger->pushHandler(new StreamHandler($logger_path, Logger::DEBUG));
142 142
 		
143
-		if(isset($_POST['API_ID'])){
144
-			$this->logger->info("Processing ajax request ID ".substr(filter_input(INPUT_POST, 'API_ID', FILTER_SANITIZE_STRING), 0 , 15));
143
+		if (isset($_POST['API_ID'])) {
144
+			$this->logger->info("Processing ajax request ID ".substr(filter_input(INPUT_POST, 'API_ID', FILTER_SANITIZE_STRING), 0, 15));
145 145
 		}
146 146
 
147 147
 	}
@@ -150,20 +150,20 @@  discard block
 block discarded – undo
150 150
 		
151 151
 		$error = error_get_last();
152 152
 		
153
-		if($error['type'] and $this->logger)
153
+		if ($error['type'] and $this->logger)
154 154
 		{
155
-			$this->logger->info($this->friendly_error_type ($error['type']).": ".var_export($error, true));
155
+			$this->logger->info($this->friendly_error_type($error['type']).": ".var_export($error, true));
156 156
 		}
157 157
 	
158 158
 	}
159 159
 	
160 160
 	private function friendly_error_type($type) {
161
-	    static $levels=null;
162
-	    if ($levels===null) {
163
-	        $levels=[];
161
+	    static $levels = null;
162
+	    if ($levels === null) {
163
+	        $levels = [];
164 164
 	        foreach (get_defined_constants() as $key=>$value) {
165
-	            if (strpos($key,'E_')!==0) {continue;}
166
-					$levels[$value]= $key; //substr($key,2);
165
+	            if (strpos($key, 'E_') !== 0) {continue; }
166
+					$levels[$value] = $key; //substr($key,2);
167 167
 	        }
168 168
 	    }
169 169
 	    return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}");
@@ -171,14 +171,14 @@  discard block
 block discarded – undo
171 171
 	
172 172
 	public function get_logger_filename()
173 173
 	{
174
-		$filename = $this->backup_storage_dir .DS. "xcloner_restore.log";
174
+		$filename = $this->backup_storage_dir.DS."xcloner_restore.log";
175 175
 		
176 176
 		return $filename;
177 177
 	}
178 178
 	
179 179
 	public function init()
180 180
 	{
181
-		if(isset($_POST['xcloner_action']) and $_POST['xcloner_action'])
181
+		if (isset($_POST['xcloner_action']) and $_POST['xcloner_action'])
182 182
 		{
183 183
 			$method = filter_input(INPUT_POST, 'xcloner_action', FILTER_SANITIZE_STRING);
184 184
 			
@@ -186,13 +186,13 @@  discard block
 block discarded – undo
186 186
 			
187 187
 			$method .= "_action";
188 188
 			
189
-			if(method_exists($this, $method))
189
+			if (method_exists($this, $method))
190 190
 			{
191 191
 				$this->logger->debug(sprintf('Starting action %s', $method));
192 192
 				return call_user_func(array($this, $method));
193 193
 				
194
-			}else{
195
-				throw new Exception($method ." does not exists");
194
+			} else {
195
+				throw new Exception($method." does not exists");
196 196
 				}
197 197
 		}
198 198
 		
@@ -201,38 +201,38 @@  discard block
 block discarded – undo
201 201
 	
202 202
 	public function write_file_action()
203 203
 	{
204
-		if(isset($_POST['file']))
204
+		if (isset($_POST['file']))
205 205
 		{
206 206
 			$target_file = filter_input(INPUT_POST, 'file', FILTER_SANITIZE_STRING);
207 207
 			
208
-			if(!$_POST['start'])
208
+			if (!$_POST['start'])
209 209
 				$fp = fopen($target_file, "wb+");
210 210
 			else
211 211
 				$fp = fopen($target_file, "ab+");	
212 212
 			
213
-			if(!$fp)
213
+			if (!$fp)
214 214
 				throw new Exception("Unable to open $target_file file for writing");
215 215
 			
216 216
 			fseek($fp, $_POST['start']);
217 217
 			
218
-			if(isset($_FILES['blob']))
218
+			if (isset($_FILES['blob']))
219 219
 			{
220 220
 				$this->logger->debug(sprintf('Writing %s bytes to file %s starting position %s using FILES blob', filesize($_FILES['blob']['tmp_name']), $target_file, $_POST['start']));
221 221
 				
222 222
 				$blob = file_get_contents($_FILES['blob']['tmp_name']);
223 223
 				
224
-				if(!$bytes_written = fwrite($fp, $blob))
224
+				if (!$bytes_written = fwrite($fp, $blob))
225 225
 					throw new Exception("Unable to write data to file $target_file");
226 226
 				
227 227
 				@unlink($_FILES['blob']['tmp_name']);
228
-			}elseif(isset($_POST['blob'])){
228
+			}elseif (isset($_POST['blob'])) {
229 229
 				$this->logger->debug(sprintf('Writing %s bytes to file %s starting position %s using POST blob', strlen($_POST['blob']), $target_file, $_POST['start']));
230 230
 				
231 231
 				$blob = $_POST['blob'];
232 232
 
233
-				if(!$bytes_written = fwrite($fp, $blob))
233
+				if (!$bytes_written = fwrite($fp, $blob))
234 234
 					throw new Exception("Unable to write data to file $target_file");
235
-			}else{
235
+			} else {
236 236
 				throw new Exception("Upload failed, did not receive any binary data");
237 237
 			}
238 238
 			
@@ -243,20 +243,20 @@  discard block
 block discarded – undo
243 243
 		
244 244
 	}
245 245
 	
246
-	public function mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db )
246
+	public function mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db)
247 247
 	{
248 248
 		$this->logger->info(sprintf('Connecting to mysql database %s with %s@%s', $remote_mysql_db, $remote_mysql_user, $remote_mysql_host));
249 249
 
250 250
 		$mysqli = new mysqli($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db);
251 251
 
252 252
 		if ($mysqli->connect_error) {
253
-			throw new Exception('Connect Error (' . $mysqli->connect_errno . ') '
253
+			throw new Exception('Connect Error ('.$mysqli->connect_errno.') '
254 254
 				. $mysqli->connect_error);
255 255
 		}
256 256
 		
257 257
 		$mysqli->query("SET sql_mode='';");
258 258
 		$mysqli->query("SET foreign_key_checks = 0;");
259
-		if(isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file'])
259
+		if (isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file'])
260 260
 			$mysqli->query("SET NAMES ".$_REQUEST['charset_of_file']."");
261 261
 		else
262 262
 			$mysqli->query("SET NAMES utf8;");
@@ -266,15 +266,15 @@  discard block
 block discarded – undo
266 266
 	
267 267
 	public function restore_mysql_backup_action()
268 268
 	{
269
-		$mysqldump_file 	= filter_input(INPUT_POST, 'mysqldump_file', FILTER_SANITIZE_STRING);
270
-		$remote_path 		= filter_input(INPUT_POST, 'remote_path', FILTER_SANITIZE_STRING);
269
+		$mysqldump_file = filter_input(INPUT_POST, 'mysqldump_file', FILTER_SANITIZE_STRING);
270
+		$remote_path = filter_input(INPUT_POST, 'remote_path', FILTER_SANITIZE_STRING);
271 271
 		$remote_mysql_user 	= filter_input(INPUT_POST, 'remote_mysql_user', FILTER_SANITIZE_STRING);
272 272
 		$remote_mysql_pass 	= filter_input(INPUT_POST, 'remote_mysql_pass', FILTER_SANITIZE_STRING);
273
-		$remote_mysql_db 	= filter_input(INPUT_POST, 'remote_mysql_db', FILTER_SANITIZE_STRING);
273
+		$remote_mysql_db = filter_input(INPUT_POST, 'remote_mysql_db', FILTER_SANITIZE_STRING);
274 274
 		$remote_mysql_host 	= filter_input(INPUT_POST, 'remote_mysql_host', FILTER_SANITIZE_STRING);
275
-		$execute_query 		= trim(stripslashes($_POST['query']));
276
-		$error_line			= filter_input(INPUT_POST, 'error_line', FILTER_SANITIZE_NUMBER_INT);
277
-		$start			 	= filter_input(INPUT_POST, 'start', FILTER_SANITIZE_NUMBER_INT);
275
+		$execute_query = trim(stripslashes($_POST['query']));
276
+		$error_line = filter_input(INPUT_POST, 'error_line', FILTER_SANITIZE_NUMBER_INT);
277
+		$start = filter_input(INPUT_POST, 'start', FILTER_SANITIZE_NUMBER_INT);
278 278
 		
279 279
 		$wp_home_url 		= filter_input(INPUT_POST, 'wp_home_url', FILTER_SANITIZE_STRING);
280 280
 		$remote_restore_url = filter_input(INPUT_POST, 'remote_restore_url', FILTER_SANITIZE_STRING);
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 		
285 285
 		$mysql_backup_file = $remote_path.DS.$mysqldump_file;
286 286
 		
287
-		if(!file_exists($mysql_backup_file))
288
-			throw new Exception(sprintf("Mysql backup file %s does not exists",$mysql_backup_file));
287
+		if (!file_exists($mysql_backup_file))
288
+			throw new Exception(sprintf("Mysql backup file %s does not exists", $mysql_backup_file));
289 289
 		
290 290
 		
291 291
 		/*if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS)
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 		}*/
300 300
 		
301 301
 		{
302
-			$mysqli = $this->mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db );
302
+			$mysqli = $this->mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db);
303 303
 		}
304 304
 		
305 305
 		$line_count = 0;
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 		$return['backup_size']	= filesize($mysql_backup_file);
310 310
 		
311 311
 		$fp = fopen($mysql_backup_file, "r");
312
-		if($fp)
312
+		if ($fp)
313 313
 		{
314 314
 			$this->logger->info(sprintf("Opening mysql dump file %s at position %s.", $mysql_backup_file, $start));
315 315
 			fseek($fp, $start);
@@ -317,49 +317,49 @@  discard block
 block discarded – undo
317 317
 			// process the line read.
318 318
 									
319 319
 				//check if line is comment
320
-				if(substr($line, 0, 1) == "#")
320
+				if (substr($line, 0, 1) == "#")
321 321
 					continue;
322 322
 				
323 323
 				//check if line is empty	
324
-				if($line == "\n" or trim($line) == "")
324
+				if ($line == "\n" or trim($line) == "")
325 325
 					continue;
326 326
 					
327
-				if(substr($line, strlen($line)-2, strlen($line)) == ";\n")
327
+				if (substr($line, strlen($line) - 2, strlen($line)) == ";\n")
328 328
 					$query .= $line;
329
-				else{
329
+				else {
330 330
 					$query .= $line;
331 331
 					continue;
332 332
 				}
333 333
 				
334
-				if($execute_query)
334
+				if ($execute_query)
335 335
 				{
336
-					$query  = (($execute_query));
336
+					$query = (($execute_query));
337 337
 					$execute_query = "";
338 338
 				}	
339 339
 				
340 340
 				//Doing serialized url replace here
341 341
 				
342
-				if($wp_site_url and $wp_home_url and strlen($wp_home_url) < strlen($wp_site_url))
342
+				if ($wp_site_url and $wp_home_url and strlen($wp_home_url) < strlen($wp_site_url))
343 343
 				{
344
-					list($wp_home_url,$wp_site_url) 			= array($wp_site_url,$wp_home_url);
345
-					list($remote_restore_url,$restore_site_url) = array($restore_site_url,$remote_restore_url);
344
+					list($wp_home_url, $wp_site_url) = array($wp_site_url, $wp_home_url);
345
+					list($remote_restore_url, $restore_site_url) = array($restore_site_url, $remote_restore_url);
346 346
 					
347 347
 				}
348 348
 				
349
-				if($wp_home_url and $remote_restore_url and strpos($query, $wp_home_url) !== false)
349
+				if ($wp_home_url and $remote_restore_url and strpos($query, $wp_home_url) !== false)
350 350
 				{
351 351
 					$query = $this->url_replace($wp_home_url, $remote_restore_url, $query);
352 352
 				}
353 353
 				
354
-				if($wp_site_url and $restore_site_url and strpos($query, $wp_site_url) !== false)
354
+				if ($wp_site_url and $restore_site_url and strpos($query, $wp_site_url) !== false)
355 355
 				{
356 356
 					$query = $this->url_replace($wp_site_url, $restore_site_url, $query);
357 357
 				}
358 358
 				
359
-				if(!$mysqli->query($query) && !stristr($mysqli->error,"Duplicate entry"))
359
+				if (!$mysqli->query($query) && !stristr($mysqli->error, "Duplicate entry"))
360 360
 				{
361 361
 					//$return['error_line'] = $line_count;
362
-					$return['start'] = ftell($fp)-strlen($line);
362
+					$return['start'] = ftell($fp) - strlen($line);
363 363
 					$return['query_error'] = true;
364 364
 					$return['query'] = $query;
365 365
 					$return['message'] = sprintf("Mysql Error: %s\n", $mysqli->error);
@@ -380,12 +380,12 @@  discard block
 block discarded – undo
380 380
 		
381 381
 		$return['start'] = ftell($fp);
382 382
 		
383
-		$this->logger->info(sprintf("Executed %s queries of size %s bytes", $line_count, ($return['start']-$start)));
383
+		$this->logger->info(sprintf("Executed %s queries of size %s bytes", $line_count, ($return['start'] - $start)));
384 384
 		
385
-		if(!feof($fp))
385
+		if (!feof($fp))
386 386
 		{
387 387
 			$return['finished'] = 0;
388
-		}else{
388
+		} else {
389 389
 			$this->logger->info(sprintf("Mysql Import Done."));
390 390
 		}
391 391
 		
@@ -400,12 +400,12 @@  discard block
 block discarded – undo
400 400
 		$query = str_replace($search, $replace, $query);
401 401
 		$original_query = $query;
402 402
 		
403
-		if($this->has_serialized($query))
403
+		if ($this->has_serialized($query))
404 404
 		{
405 405
 			$this->logger->info(sprintf("Query contains serialized data, doing serialized size fix"), array("QUERY_REPLACE"));
406 406
 			$query = $this->do_serialized_fix($query);
407 407
 			
408
-			if(!$query)
408
+			if (!$query)
409 409
 			{
410 410
 				$this->logger->info(sprintf("Serialization probably failed here..."), array("QUERY_REPLACE"));
411 411
 				$query = $original_query;
@@ -421,37 +421,37 @@  discard block
 block discarded – undo
421 421
 		$backup_parts = array();
422 422
 		
423 423
 		$source_backup_file = filter_input(INPUT_POST, 'file', FILTER_SANITIZE_STRING);
424
-		$start 				= (int)filter_input(INPUT_POST, 'start', FILTER_SANITIZE_STRING);
425
-		$return['part'] 	= (int)filter_input(INPUT_POST, 'part', FILTER_SANITIZE_STRING);
424
+		$start = (int)filter_input(INPUT_POST, 'start', FILTER_SANITIZE_STRING);
425
+		$return['part'] = (int)filter_input(INPUT_POST, 'part', FILTER_SANITIZE_STRING);
426 426
 		
427 427
 		$backup_file = $source_backup_file;
428 428
 		
429
-		if($this->is_multipart($backup_file))
429
+		if ($this->is_multipart($backup_file))
430 430
 		{
431 431
 			$backup_parts = $this->get_multipart_files($backup_file);
432 432
 			$backup_file = $backup_parts[$return['part']];
433 433
 		}
434 434
 		
435
-		try{
435
+		try {
436 436
 			$tar = new Tar();
437 437
 			$tar->open($this->backup_storage_dir.DS.$backup_file, $start);
438 438
 		
439 439
 			$data = $tar->contents($this->process_files_limit_list);
440
-		}catch(Exception $e)
440
+		}catch (Exception $e)
441 441
 		{
442 442
 			$return['error'] = true;
443 443
 			$return['message'] = $e->getMessage();
444 444
 			$this->send_response(200, $return);
445 445
 		}
446 446
 		
447
-		$return['files'] 		= array();
448
-		$return['finished'] 	= 1;
449
-		$return['total_size'] 	= filesize($this->backup_storage_dir.DS.$backup_file);
447
+		$return['files'] = array();
448
+		$return['finished'] = 1;
449
+		$return['total_size'] = filesize($this->backup_storage_dir.DS.$backup_file);
450 450
 		$i = 0;
451 451
 		
452
-		if(isset($data['extracted_files']) and is_array($data['extracted_files']))
452
+		if (isset($data['extracted_files']) and is_array($data['extracted_files']))
453 453
 		{
454
-			foreach($data['extracted_files'] as $file)
454
+			foreach ($data['extracted_files'] as $file)
455 455
 			{
456 456
 				$return['files'][$i]['path'] = $file->getPath();
457 457
 				$return['files'][$i]['size'] = $file->getSize();
@@ -461,18 +461,18 @@  discard block
 block discarded – undo
461 461
 			}
462 462
 		}
463 463
 		
464
-		if(isset($data['start']))
464
+		if (isset($data['start']))
465 465
 		{
466 466
 			$return['start'] = $data['start'];
467 467
 			$return['finished'] = 0;	
468
-		}else{
469
-			if($this->is_multipart($source_backup_file))
468
+		} else {
469
+			if ($this->is_multipart($source_backup_file))
470 470
 			{
471 471
 				$return['start'] = 0;
472 472
 				
473 473
 				++$return['part'];
474 474
 			
475
-				if($return['part'] < sizeof($backup_parts))	
475
+				if ($return['part'] < sizeof($backup_parts))	
476 476
 					$return['finished'] = 0;
477 477
 				
478 478
 			}
@@ -490,28 +490,28 @@  discard block
 block discarded – undo
490 490
 		
491 491
 		$remote_mysql_user 	= filter_input(INPUT_POST, 'remote_mysql_user', FILTER_SANITIZE_STRING);
492 492
 		$remote_mysql_pass 	= filter_input(INPUT_POST, 'remote_mysql_pass', FILTER_SANITIZE_STRING);
493
-		$remote_mysql_db 	= filter_input(INPUT_POST, 'remote_mysql_db', FILTER_SANITIZE_STRING);
493
+		$remote_mysql_db = filter_input(INPUT_POST, 'remote_mysql_db', FILTER_SANITIZE_STRING);
494 494
 		$remote_mysql_host 	= filter_input(INPUT_POST, 'remote_mysql_host', FILTER_SANITIZE_STRING);
495 495
 		
496
-		$update_remote_site_url			 	= filter_input(INPUT_POST, 'update_remote_site_url', FILTER_SANITIZE_NUMBER_INT);
497
-		$delete_restore_script			 	= filter_input(INPUT_POST, 'delete_restore_script', FILTER_SANITIZE_NUMBER_INT);
498
-		$delete_backup_temporary_folder		= filter_input(INPUT_POST, 'delete_backup_temporary_folder', FILTER_SANITIZE_NUMBER_INT);
496
+		$update_remote_site_url = filter_input(INPUT_POST, 'update_remote_site_url', FILTER_SANITIZE_NUMBER_INT);
497
+		$delete_restore_script = filter_input(INPUT_POST, 'delete_restore_script', FILTER_SANITIZE_NUMBER_INT);
498
+		$delete_backup_temporary_folder = filter_input(INPUT_POST, 'delete_backup_temporary_folder', FILTER_SANITIZE_NUMBER_INT);
499 499
 				
500
-		if($update_remote_site_url)
500
+		if ($update_remote_site_url)
501 501
 		{
502
-			$mysqli = $this->mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db );
502
+			$mysqli = $this->mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db);
503 503
 			$this->update_wp_config($remote_path, $remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db);
504 504
 			$this->update_wp_url($remote_path, $remote_restore_url, $mysqli);
505 505
 		}
506 506
 		
507
-		if($delete_backup_temporary_folder)
507
+		if ($delete_backup_temporary_folder)
508 508
 		{
509 509
 			$this->delete_backup_temporary_folder($remote_path);
510 510
 		}
511 511
 		
512
-		if(!defined('XCLONER_PLUGIN_ACCESS') || XCLONER_PLUGIN_ACCESS != 1)
512
+		if (!defined('XCLONER_PLUGIN_ACCESS') || XCLONER_PLUGIN_ACCESS != 1)
513 513
 		{
514
-			if($delete_restore_script)
514
+			if ($delete_restore_script)
515 515
 			{
516 516
 				$this->delete_self();
517 517
 			}
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
 	
524 524
 	private function delete_backup_temporary_folder($remote_path)
525 525
 	{
526
-		$this->target_adapter = new Local($remote_path ,LOCK_EX, 'SKIP_LINKS');
526
+		$this->target_adapter = new Local($remote_path, LOCK_EX, 'SKIP_LINKS');
527 527
 		$this->target_filesystem = new Filesystem($this->target_adapter, new Config([
528 528
 				'disable_asserts' => true,
529 529
 			]));
@@ -531,13 +531,13 @@  discard block
 block discarded – undo
531 531
 		$mysqldump_list = array();
532 532
 		$list = $this->target_filesystem->listContents();
533 533
 		
534
-		foreach($list as $file)
534
+		foreach ($list as $file)
535 535
 		{
536 536
 			$matches = array();
537 537
 			
538
-			if($file['type'] == "dir")
538
+			if ($file['type'] == "dir")
539 539
 			{
540
-				if(preg_match("/xcloner-(\w*)/", $file['basename'], $matches)){
540
+				if (preg_match("/xcloner-(\w*)/", $file['basename'], $matches)) {
541 541
 					$this->logger->info(sprintf('Deleting temporary folder %s', $file['path']));
542 542
 					$this->target_filesystem->deleteDir($file['path']);
543 543
 				}
@@ -550,29 +550,29 @@  discard block
 block discarded – undo
550 550
 	
551 551
 	private function delete_self()
552 552
 	{
553
-		if($this->filesystem->has("vendor.phar"))
553
+		if ($this->filesystem->has("vendor.phar"))
554 554
 		{
555 555
 			$this->logger->info(sprintf('Deleting vendor.phar'));
556 556
 			$this->filesystem->delete("vendor.phar");
557 557
 		}
558
-		if($this->filesystem->has("vendor"))
558
+		if ($this->filesystem->has("vendor"))
559 559
 		{
560 560
 			$this->logger->info(sprintf('Deleting vendor folder'));
561 561
 			$this->filesystem->deleteDir("vendor");
562 562
 		}
563
-		if($this->filesystem->has("xcloner_restore.php"))
563
+		if ($this->filesystem->has("xcloner_restore.php"))
564 564
 		{
565 565
 			$this->logger->info(sprintf('Deleting xcloner_restore.php'));
566 566
 			$this->filesystem->delete("xcloner_restore.php");
567 567
 		}
568 568
 		
569
-		if($this->filesystem->has("xcloner_restore.log"))
569
+		if ($this->filesystem->has("xcloner_restore.log"))
570 570
 		{
571 571
 			$this->logger->info(sprintf('Deleting xcloner_restore.log'));
572 572
 			$this->filesystem->delete("xcloner_restore.log");
573 573
 		}
574 574
 		
575
-		if($this->filesystem->has($this->get_logger_filename()))
575
+		if ($this->filesystem->has($this->get_logger_filename()))
576 576
 		{
577 577
 			$this->logger->info(sprintf('Deleting logger file %s', $this->get_logger_filename()));
578 578
 			$this->filesystem->delete($this->get_logger_filename());
@@ -586,11 +586,11 @@  discard block
 block discarded – undo
586 586
 		
587 587
 		$this->logger->info(sprintf('Updating site url to %s', $url));
588 588
 		
589
-		if(file_exists($wp_config))
589
+		if (file_exists($wp_config))
590 590
 		{
591 591
 			$config = file_get_contents($wp_config);
592 592
 			preg_match("/.*table_prefix.*=.*'(.*)'/i", $config, $matches);
593
-			if(isset($matches[1]))
593
+			if (isset($matches[1]))
594 594
 				$table_prefix = $matches[1];
595 595
 			else
596 596
 				throw new Exception("Could not load wordpress table prefix from wp-config.php file.");
@@ -598,10 +598,10 @@  discard block
 block discarded – undo
598 598
 		else
599 599
 			throw new Exception("Could not update the SITEURL and HOME, wp-config.php file not found");
600 600
 			
601
-		if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'"))
601
+		if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'"))
602 602
 			throw new Exception(sprintf("Could not update the HOME option, error: %s\n", $mysqli->error));
603 603
 		
604
-		if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'"))
604
+		if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'"))
605 605
 			throw new Exception(sprintf("Could not update the SITEURL option, error: %s\n", $mysqli->error));
606 606
 		
607 607
 		return true;
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
 	{
612 612
 		$wp_config = $remote_path.DS."wp-config.php";
613 613
 		
614
-		if(!file_exists($wp_config))
614
+		if (!file_exists($wp_config))
615 615
 		{
616 616
 			throw new Exception("Could not find the wp-config.php in ".$remote_path);
617 617
 		}
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
 		
630 630
 		$this->logger->info(sprintf('Updating wp-config.php file with the new mysql details'));
631 631
 		
632
-		if(!file_put_contents($wp_config, $content))
632
+		if (!file_put_contents($wp_config, $content))
633 633
 			throw new Exception("Could not write updated config data to ".$wp_config);
634 634
 		
635 635
 		chmod($wp_config, $file_perms);
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
 	
646 646
 		$hash = $this->get_hash_from_backup($source_backup_file);	
647 647
 		
648
-		$this->target_adapter = new Local($remote_path ,LOCK_EX, 'SKIP_LINKS');
648
+		$this->target_adapter = new Local($remote_path, LOCK_EX, 'SKIP_LINKS');
649 649
 		$this->target_filesystem = new Filesystem($this->target_adapter, new Config([
650 650
 				'disable_asserts' => true,
651 651
 			]));
@@ -653,25 +653,25 @@  discard block
 block discarded – undo
653 653
 		$mysqldump_list = array();
654 654
 		$list = $this->target_filesystem->listContents();
655 655
 		
656
-		foreach($list as $file)
656
+		foreach ($list as $file)
657 657
 		{
658 658
 			$matches = array();
659 659
 			
660
-			if($file['type'] == "dir")
660
+			if ($file['type'] == "dir")
661 661
 			{
662
-				if(preg_match("/xcloner-(\w*)/", $file['basename'], $matches))
662
+				if (preg_match("/xcloner-(\w*)/", $file['basename'], $matches))
663 663
 				{
664 664
 					$files = $this->target_filesystem->listContents($file['basename']);
665
-					foreach($files as $file)
665
+					foreach ($files as $file)
666 666
 					{
667
-						if($file['extension'] == "sql")
667
+						if ($file['extension'] == "sql")
668 668
 						{
669 669
 							$this->logger->info(sprintf('Found %s mysql backup file', $file['path']));
670 670
 							$mysqldump_list[$file['path']]['path'] = $file['path'];
671 671
 							$mysqldump_list[$file['path']]['size'] = $file['size'];
672
-							$mysqldump_list[$file['path']]['timestamp'] = date("d M,Y H:i",$file['timestamp']);
672
+							$mysqldump_list[$file['path']]['timestamp'] = date("d M,Y H:i", $file['timestamp']);
673 673
 							
674
-							if($hash and $hash == $matches[1])
674
+							if ($hash and $hash == $matches[1])
675 675
 								$mysqldump_list[$file['path']]['selected'] = "selected";
676 676
 							else
677 677
 								$mysqldump_list[$file['path']]['selected'] = "";	
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
 			}	
682 682
 		}
683 683
 		
684
-		$this->sort_by($mysqldump_list, 'timestamp','desc');
684
+		$this->sort_by($mysqldump_list, 'timestamp', 'desc');
685 685
 		$return['files'] = $mysqldump_list;
686 686
 		
687 687
 		$this->send_response(200, $return);
@@ -689,12 +689,12 @@  discard block
 block discarded – undo
689 689
 	
690 690
 	private function get_hash_from_backup($backup_file)
691 691
 	{
692
-		if(!$backup_file)
692
+		if (!$backup_file)
693 693
 			return false;
694 694
 			
695
-		$result = preg_match("/-(\w*)./", substr($backup_file, strlen($backup_file)-10, strlen($backup_file)), $matches)	;
695
+		$result = preg_match("/-(\w*)./", substr($backup_file, strlen($backup_file) - 10, strlen($backup_file)), $matches);
696 696
 		
697
-		if($result and isset($matches[1]))
697
+		if ($result and isset($matches[1]))
698 698
 			return ($matches[1]);
699 699
 		
700 700
 		return false;
@@ -708,18 +708,18 @@  discard block
 block discarded – undo
708 708
 		$backup_files = array();
709 709
 		$parents = array();
710 710
 		
711
-		foreach($list as $file_info)
711
+		foreach ($list as $file_info)
712 712
 		{
713 713
 			$data = array();
714 714
 			
715
-			if(isset($file_info['extension']) and $file_info['extension'] == "csv")
715
+			if (isset($file_info['extension']) and $file_info['extension'] == "csv")
716 716
 			{
717 717
 				$lines = explode(PHP_EOL, $this->filesystem->read($file_info['path']));
718
-				foreach($lines as $line)
719
-					if($line)
718
+				foreach ($lines as $line)
719
+					if ($line)
720 720
 					{
721 721
 						$data = str_getcsv($line);
722
-						if(is_array($data)){
722
+						if (is_array($data)) {
723 723
 							$parents[$data[0]] = $file_info['path'];
724 724
 							$file_info['childs'][] = $data;
725 725
 							$file_info['size'] += $data[2];
@@ -728,19 +728,19 @@  discard block
 block discarded – undo
728 728
 						
729 729
 			}
730 730
 			
731
-			if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions))
731
+			if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions))
732 732
 				$backup_files[$file_info['path']] = $file_info;
733 733
 		}
734 734
 		
735 735
 		$new_list = array();
736 736
 		
737
-		foreach($backup_files as $key=>$file_info)
737
+		foreach ($backup_files as $key=>$file_info)
738 738
 		{
739
-			if(isset($parents[$file_info['path']]))
739
+			if (isset($parents[$file_info['path']]))
740 740
 				$backup_files[$key]['parent'] = $parents[$file_info['path']];
741
-			else{
741
+			else {
742 742
 				
743
-				if($local_backup_file and ($file_info['basename'] == $local_backup_file))
743
+				if ($local_backup_file and ($file_info['basename'] == $local_backup_file))
744 744
 					$file_info['selected'] = 'selected';
745 745
 				
746 746
 				$this->logger->info(sprintf('Found %s backup file', $file_info['path']));
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
 				
751 751
 		}
752 752
 		
753
-		$this->sort_by($new_list, "timestamp","desc");
753
+		$this->sort_by($new_list, "timestamp", "desc");
754 754
 		
755 755
 		$return['files'] = $new_list;
756 756
 		
@@ -760,15 +760,15 @@  discard block
 block discarded – undo
760 760
 	
761 761
 	public function restore_backup_to_path_action()
762 762
 	{
763
-		$source_backup_file 	= filter_input(INPUT_POST, 'backup_file', FILTER_SANITIZE_STRING);
764
-		$remote_path 			= filter_input(INPUT_POST, 'remote_path', FILTER_SANITIZE_STRING);
763
+		$source_backup_file = filter_input(INPUT_POST, 'backup_file', FILTER_SANITIZE_STRING);
764
+		$remote_path = filter_input(INPUT_POST, 'remote_path', FILTER_SANITIZE_STRING);
765 765
 		$include_filter_files 	= filter_input(INPUT_POST, 'filter_files', FILTER_SANITIZE_STRING);
766 766
 		$exclude_filter_files 	= "";
767
-		$start 					= filter_input(INPUT_POST, 'start', FILTER_SANITIZE_NUMBER_INT);
768
-		$return['part'] 		= (int)filter_input(INPUT_POST, 'part', FILTER_SANITIZE_NUMBER_INT);
767
+		$start = filter_input(INPUT_POST, 'start', FILTER_SANITIZE_NUMBER_INT);
768
+		$return['part'] = (int)filter_input(INPUT_POST, 'part', FILTER_SANITIZE_NUMBER_INT);
769 769
 		$return['processed'] 	= (int)filter_input(INPUT_POST, 'processed', FILTER_SANITIZE_NUMBER_INT);
770 770
 				
771
-		$this->target_adapter = new Local($remote_path ,LOCK_EX, 'SKIP_LINKS');
771
+		$this->target_adapter = new Local($remote_path, LOCK_EX, 'SKIP_LINKS');
772 772
 		$this->target_filesystem = new Filesystem($this->target_adapter, new Config([
773 773
 				'disable_asserts' => true,
774 774
 			]));
@@ -780,9 +780,9 @@  discard block
 block discarded – undo
780 780
 		$return['total_size'] = $this->get_backup_size($backup_file);
781 781
 		
782 782
 		$backup_archive = new Tar();
783
-		if($this->is_multipart($backup_file))
783
+		if ($this->is_multipart($backup_file))
784 784
 		{
785
-			if(!$return['part'])
785
+			if (!$return['part'])
786 786
 				$return['processed'] += $this->filesystem->getSize($backup_file);
787 787
 				
788 788
 			$backup_parts = $this->get_multipart_files($backup_file);
@@ -790,41 +790,41 @@  discard block
 block discarded – undo
790 790
 		}	
791 791
 		
792 792
 		$this->logger->info(sprintf('Opening backup archive %s at position %s', $backup_file, $start));
793
-		$backup_archive->open($this->backup_storage_dir .DS. $backup_file, $start);
793
+		$backup_archive->open($this->backup_storage_dir.DS.$backup_file, $start);
794 794
 
795
-		$data = $backup_archive->extract($remote_path, '',$exclude_filter_files,$include_filter_files, $this->process_files_limit);
795
+		$data = $backup_archive->extract($remote_path, '', $exclude_filter_files, $include_filter_files, $this->process_files_limit);
796 796
 		
797
-		if(isset($data['extracted_files']))
797
+		if (isset($data['extracted_files']))
798 798
 		{
799
-			foreach($data['extracted_files'] as $spl_fileinfo)
799
+			foreach ($data['extracted_files'] as $spl_fileinfo)
800 800
 			{
801 801
 				$this->logger->info(sprintf('Extracted %s file', $spl_fileinfo->getPath()));
802 802
 				$return['extracted_files'][] = $spl_fileinfo->getPath()." (".$spl_fileinfo->getSize()." bytes)";
803 803
 			}
804 804
 		}
805 805
 		
806
-		if(isset($data['start']))
806
+		if (isset($data['start']))
807 807
 		//if(isset($data['start']) and $data['start'] <= $this->filesystem->getSize($backup_file))
808 808
 		{
809 809
 			$return['finished'] = 0;
810 810
 			$return['start'] = $data['start'];
811
-		}else{
811
+		} else {
812 812
 			
813 813
 			$return['processed'] += $start;
814 814
 			
815
-			if($this->is_multipart($source_backup_file))
815
+			if ($this->is_multipart($source_backup_file))
816 816
 			{
817 817
 				$return['start'] = 0;
818 818
 				
819 819
 				++$return['part'];
820 820
 			
821
-				if($return['part'] < sizeof($backup_parts))	
821
+				if ($return['part'] < sizeof($backup_parts))	
822 822
 					$return['finished'] = 0;
823 823
 				
824 824
 			}
825 825
 		}
826 826
 		
827
-		if($return['finished'])
827
+		if ($return['finished'])
828 828
 			$this->logger->info(sprintf('Done extracting %s', $source_backup_file));
829 829
 		
830 830
 		$return['backup_file'] = $backup_file;
@@ -838,24 +838,24 @@  discard block
 block discarded – undo
838 838
 		
839 839
 		$restore_script_url = filter_input(INPUT_POST, 'restore_script_url', FILTER_SANITIZE_STRING);
840 840
 		
841
-		$pathinfo = pathinfo( __FILE__);
841
+		$pathinfo = pathinfo(__FILE__);
842 842
 		
843 843
 		$suffix = "";
844 844
 		$return['remote_mysql_host'] 	= "localhost";
845 845
 		$return['remote_mysql_user'] 	= "";
846 846
 		$return['remote_mysql_pass'] 	= "";
847
-		$return['remote_mysql_db'] 		= "";
847
+		$return['remote_mysql_db'] = "";
848 848
 		
849
-		if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS)
849
+		if (defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS)
850 850
 		{
851 851
 			$return['dir'] = realpath(get_home_path().DS.$suffix);
852
-			$return['restore_script_url']  	= get_site_url();
852
+			$return['restore_script_url'] = get_site_url();
853 853
 			$return['remote_mysql_host'] 	= $wpdb->dbhost;
854 854
 			$return['remote_mysql_user'] 	= $wpdb->dbuser;
855 855
 			$return['remote_mysql_pass'] 	= $wpdb->dbpassword;
856
-			$return['remote_mysql_db'] 		= $wpdb->dbname;
856
+			$return['remote_mysql_db'] = $wpdb->dbname;
857 857
 		}
858
-		else{
858
+		else {
859 859
 			$return['dir'] = ($pathinfo['dirname']).DS.$suffix;
860 860
 			$return['restore_script_url'] = str_replace($pathinfo['basename'], "", $restore_script_url).$suffix;
861 861
 		}	
@@ -869,17 +869,17 @@  discard block
 block discarded – undo
869 869
 	{
870 870
 		//check if i can write
871 871
 		$tmp_file = md5(time());
872
-		if(!file_put_contents($tmp_file, "++"))
872
+		if (!file_put_contents($tmp_file, "++"))
873 873
 			throw new Exception("Could not write to new host");
874 874
 		
875
-		if(!unlink($tmp_file))
875
+		if (!unlink($tmp_file))
876 876
 			throw new Exception("Could not delete temporary file from new host");
877 877
 		
878 878
 		$max_upload      = $this->return_bytes((ini_get('upload_max_filesize')));
879 879
 		$max_post        = $this->return_bytes((ini_get('post_max_size')));
880 880
 
881 881
 		$return['max_upload_size'] = min($max_upload, $max_post); // bytes
882
-		$return['status']		= true;
882
+		$return['status'] = true;
883 883
 		
884 884
 		$this->logger->info(sprintf('Current filesystem max upload size is %s bytes', $return['max_upload_size']));
885 885
 		
@@ -888,8 +888,8 @@  discard block
 block discarded – undo
888 888
 	
889 889
 	private function return_bytes($val) {
890 890
 	    $val = trim($val);
891
-	    $last = strtolower($val[strlen($val)-1]);
892
-	    switch($last) {
891
+	    $last = strtolower($val[strlen($val) - 1]);
892
+	    switch ($last) {
893 893
 	        // The 'G' modifier is available since PHP 5.1.0
894 894
 	        case 'g':
895 895
 	            $val *= 1024;
@@ -904,7 +904,7 @@  discard block
 block discarded – undo
904 904
 	
905 905
 	public function is_multipart($backup_name)
906 906
 	{
907
-		if(stristr($backup_name, "-multipart"))
907
+		if (stristr($backup_name, "-multipart"))
908 908
 			return true;
909 909
 		
910 910
 		return false;	
@@ -913,10 +913,10 @@  discard block
 block discarded – undo
913 913
 	public function get_backup_size($backup_name)
914 914
 	{
915 915
 		$backup_size = $this->filesystem->getSize($backup_name);
916
-		if($this->is_multipart($backup_name))
916
+		if ($this->is_multipart($backup_name))
917 917
 		{
918 918
 			$backup_parts = $this->get_multipart_files($backup_name);
919
-			foreach($backup_parts as $part_file)
919
+			foreach ($backup_parts as $part_file)
920 920
 				$backup_size += $this->filesystem->getSize($part_file);
921 921
 		}
922 922
 		
@@ -927,12 +927,12 @@  discard block
 block discarded – undo
927 927
 	{
928 928
 		$files = array();
929 929
 		
930
-		if($this->is_multipart($backup_name))
930
+		if ($this->is_multipart($backup_name))
931 931
 		{
932 932
 			$lines = explode(PHP_EOL, $this->filesystem->read($backup_name));
933
-			foreach($lines as $line)
933
+			foreach ($lines as $line)
934 934
 			{
935
-				if($line)
935
+				if ($line)
936 936
 				{
937 937
 					$data = str_getcsv($line);
938 938
 					$files[] = $data[0];
@@ -943,20 +943,20 @@  discard block
 block discarded – undo
943 943
 		return $files;
944 944
 	}
945 945
 	
946
-	private function sort_by( &$array, $field, $direction = 'asc')
946
+	private function sort_by(&$array, $field, $direction = 'asc')
947 947
 	{
948 948
 		$direction = strtolower($direction);
949 949
 		
950 950
 	    usort($array, create_function('$a, $b', '
951
-	        $a = $a["' . $field . '"];
952
-	        $b = $b["' . $field . '"];
951
+	        $a = $a["' . $field.'"];
952
+	        $b = $b["' . $field.'"];
953 953
 	
954 954
 	        if ($a == $b)
955 955
 	        {
956 956
 	            return 0;
957 957
 	        }
958 958
 	
959
-	        return ($a ' . ($direction == 'desc' ? '>' : '<') .' $b) ? -1 : 1;
959
+	        return ($a ' . ($direction == 'desc' ? '>' : '<').' $b) ? -1 : 1;
960 960
 	    '));
961 961
 	
962 962
 	    return true;
@@ -970,11 +970,11 @@  discard block
 block discarded – undo
970 970
 		$return['status'] = $status;
971 971
 		$return['statusText'] = $response;
972 972
 		
973
-		if(isset($response['error']) && $response['error'])
973
+		if (isset($response['error']) && $response['error'])
974 974
 		{
975 975
 			$return['statusText'] = $response['message'];
976 976
 			$return['error'] = true;
977
-		}elseif($status != 200 and $status != 418)
977
+		}elseif ($status != 200 and $status != 418)
978 978
 		{
979 979
 			$return['error'] = true;
980 980
 			$return['message'] = $response;
@@ -990,12 +990,12 @@  discard block
 block discarded – undo
990 990
 	 
991 991
 	function do_serialized_fix($query)
992 992
 	{
993
-		$query = str_replace(array("\\n","\\r","\\'"), array("","","\""), ($query));
993
+		$query = str_replace(array("\\n", "\\r", "\\'"), array("", "", "\""), ($query));
994 994
 		
995
-		return preg_replace_callback('!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!', function ($m) {
995
+		return preg_replace_callback('!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!', function($m) {
996 996
 				  $data = "";
997 997
 				  	
998
-				  if(!isset($m[3]))
998
+				  if (!isset($m[3]))
999 999
 					$m[3] = "";
1000 1000
 					
1001 1001
 					$data = 's:'.strlen(($m[3])).':\"'.($m[3]).'\";';
@@ -1010,22 +1010,22 @@  discard block
 block discarded – undo
1010 1010
 	}
1011 1011
 	
1012 1012
 	private function unescape_mysql($value) {
1013
-		return str_replace(array("\\\\", "\\0", "\\n", "\\r", "\Z",  "\'", '\"'),
1014
-						   array("\\",   "\0",  "\n",  "\r",  "\x1a", "'", '"'), 
1013
+		return str_replace(array("\\\\", "\\0", "\\n", "\\r", "\Z", "\'", '\"'),
1014
+						   array("\\", "\0", "\n", "\r", "\x1a", "'", '"'), 
1015 1015
 						   $value);
1016 1016
 	}	
1017 1017
 	
1018 1018
 	
1019 1019
 	private function has_serialized($s)
1020 1020
 	{
1021
-		if(
1022
-		    stristr($s, '{' ) != false &&
1023
-		    stristr($s, '}' ) != false &&
1024
-		    stristr($s, ';' ) != false &&
1025
-		    stristr($s, ':' ) != false
1026
-		    ){
1021
+		if (
1022
+		    stristr($s, '{') != false &&
1023
+		    stristr($s, '}') != false &&
1024
+		    stristr($s, ';') != false &&
1025
+		    stristr($s, ':') != false
1026
+		    ) {
1027 1027
 		    return true;
1028
-		}else{
1028
+		} else {
1029 1029
 		    return false;
1030 1030
 		}
1031 1031
 
Please login to merge, or discard this patch.
includes/class-xcloner.php 3 patches
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 			
351 351
 			if(defined('DOING_CRON') || $_POST['hash'] == "generate_hash"){
352 352
 				$this->xcloner_settings->generate_new_hash();
353
-			}else{
353
+			} else{
354 354
 				$this->xcloner_settings->set_hash($_POST['hash']);
355 355
 			}
356 356
 		}
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 		
453 453
 		try{
454 454
 			$this->xcloner_scheduler->xcloner_scheduler_callback(0, $schedule);
455
-		}catch(Exception $e){
455
+		} catch(Exception $e){
456 456
 			$this->get_xcloner_logger()->error($e->getMessage());
457 457
 		}
458 458
 	
Please login to merge, or discard this patch.
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 		$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
322 322
 
323 323
 		//wp_localize_script( 'ajax-script', 'my_ajax_object',
324
-        //   array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
324
+		//   array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
325 325
 
326 326
 	}
327 327
 
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
 
358 358
 	private function define_plugin_settings(){
359 359
 		/**
360
-		* register wporg_settings_init to the admin_init action hook
361
-		*/
360
+		 * register wporg_settings_init to the admin_init action hook
361
+		 */
362 362
 
363 363
 		$this->xcloner_settings = new XCloner_Settings($this);
364 364
 
@@ -513,15 +513,15 @@  discard block
 block discarded – undo
513 513
 	}
514 514
 
515 515
 	function friendly_error_type($type) {
516
-	    static $levels=null;
517
-	    if ($levels===null) {
518
-	        $levels=[];
519
-	        foreach (get_defined_constants() as $key=>$value) {
520
-	            if (strpos($key,'E_')!==0) {continue;}
516
+		static $levels=null;
517
+		if ($levels===null) {
518
+			$levels=[];
519
+			foreach (get_defined_constants() as $key=>$value) {
520
+				if (strpos($key,'E_')!==0) {continue;}
521 521
 					$levels[$value]= $key; //substr($key,2);
522
-	        }
523
-	    }
524
-	    return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}");
522
+			}
523
+		}
524
+		return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}");
525 525
 	}
526 526
 
527 527
 	private function define_ajax_hooks()
@@ -563,24 +563,24 @@  discard block
 block discarded – undo
563 563
 			add_action( 'wp_ajax_restore_backup', 				array($xcloner_api,'restore_backup')  );
564 564
 			add_action( 'admin_notices', 						array($this, 'xcloner_error_admin_notices' ));
565 565
 
566
-        }
566
+		}
567 567
 
568
-        //Do a pre-update backup of targeted files
569
-        if($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup'))
570
-        {
568
+		//Do a pre-update backup of targeted files
569
+		if($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup'))
570
+		{
571 571
 			add_action("pre_auto_update", array($this, "pre_auto_update"), 1, 3);
572 572
 		}
573 573
 	}
574 574
 
575 575
 	function add_plugin_action_links($links, $file) {
576
-        if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php'))
576
+		if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php'))
577 577
 		{
578 578
 			$links[] = '<a href="admin.php?page=xcloner_settings_page">'.__('Settings', 'xcloner-backup-and-restore').'</a>';
579 579
 			$links[] = '<a href="admin.php?page=xcloner_generate_backups_page">'.__('Generate Backup', 'xcloner-backup-and-restore').'</a>';
580 580
 		}
581 581
 
582
-        return $links;
583
-    }
582
+		return $links;
583
+	}
584 584
 
585 585
 	public function xcloner_error_admin_notices() {
586 586
 			settings_errors( 'xcloner_error_message' );
@@ -664,9 +664,9 @@  discard block
 block discarded – undo
664 664
 	function xcloner_display()
665 665
 	{
666 666
 		// check user capabilities
667
-	    if (!current_user_can('manage_options')) {
668
-	        return;
669
-	    }
667
+		if (!current_user_can('manage_options')) {
668
+			return;
669
+		}
670 670
 
671 671
 		$page = sanitize_key($_GET['page']);
672 672
 
Please login to merge, or discard this patch.
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -162,15 +162,15 @@  discard block
 block discarded – undo
162 162
 		return $this->xcloner_file_transfer;
163 163
 	}
164 164
 
165
-	public function check_dependencies(){
165
+	public function check_dependencies() {
166 166
 
167 167
 		$backup_storage_path = realpath(__DIR__.DS."..".DS."..".DS."..").DS."backups".DS;
168 168
 
169 169
 		define("XCLONER_STORAGE_PATH", realpath($backup_storage_path));
170 170
 
171
-		if(!is_dir($backup_storage_path))
171
+		if (!is_dir($backup_storage_path))
172 172
 		{
173
-			if(!@mkdir($backup_storage_path))
173
+			if (!@mkdir($backup_storage_path))
174 174
 			{
175 175
 				$status = "error";
176 176
 				$message = sprintf(__("Unable to create the Backup Storage Location Folder %s . Please fix this before starting the backup process."), $backup_storage_path);
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 				return;
179 179
 			}
180 180
 		}
181
-		if(!is_writable($backup_storage_path))
181
+		if (!is_writable($backup_storage_path))
182 182
 		{
183 183
 			$status = "error";
184 184
 			$message = sprintf(__("Unable to write to the Backup Storage Location Folder %s . Please fix this before starting the backup process."), $backup_storage_path);
@@ -192,15 +192,15 @@  discard block
 block discarded – undo
192 192
 	public function trigger_message($message, $status = "error", $message_param1 = "", $message_param2 = "", $message_param3 = "")
193 193
 	{
194 194
 			$message = sprintf(__($message), $message_param1, $message_param2, $message_param3);
195
-			add_action( 'xcloner_admin_notices', array($this,"trigger_message_notice"), 10, 2);
196
-			do_action( 'xcloner_admin_notices', $message, $status);
195
+			add_action('xcloner_admin_notices', array($this, "trigger_message_notice"), 10, 2);
196
+			do_action('xcloner_admin_notices', $message, $status);
197 197
 	}
198 198
 
199 199
 	public function trigger_message_notice($message, $status = "success")
200 200
 	{
201 201
 		?>
202 202
 		<div class="notice notice-<?php echo $status?> is-dismissible">
203
-	        <p><?php _e( $message, 'xcloner-backup-and-restore' ); ?></p>
203
+	        <p><?php _e($message, 'xcloner-backup-and-restore'); ?></p>
204 204
 	    </div>
205 205
 		<?php
206 206
 	}
@@ -227,79 +227,79 @@  discard block
 block discarded – undo
227 227
 		 * The class responsible for orchestrating the actions and filters of the
228 228
 		 * core plugin.
229 229
 		 */
230
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-loader.php';
230
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-loader.php';
231 231
 
232 232
 		/**
233 233
 		 * The class responsible for defining internationalization functionality
234 234
 		 * of the plugin.
235 235
 		 */
236
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-i18n.php';
236
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-i18n.php';
237 237
 
238 238
 		/**
239 239
 		 * The class responsible for defining all actions that occur in the admin area.
240 240
 		 */
241
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-xcloner-admin.php';
241
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-xcloner-admin.php';
242 242
 
243 243
 		/**
244 244
 		 * The class responsible for debugging XCloner.
245 245
 		 */
246
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-logger.php';
246
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-logger.php';
247 247
 
248 248
 		/**
249 249
 		 * The class responsible for defining the admin settings area.
250 250
 		 */
251
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-settings.php';
251
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-settings.php';
252 252
 
253 253
 		/**
254 254
 		 * The class responsible for defining the Remote Storage settings area.
255 255
 		 */
256
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-remote-storage.php';
256
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-remote-storage.php';
257 257
 
258 258
 		/**
259 259
 		 * The class responsible for implementing the database backup methods.
260 260
 		 */
261
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-database.php';
261
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-database.php';
262 262
 
263 263
 		/**
264 264
 		 * The class responsible for sanitization of users input.
265 265
 		 */
266
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-sanitization.php';
266
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-sanitization.php';
267 267
 
268 268
 		/**
269 269
 		 * The class responsible for XCloner system requirements validation.
270 270
 		 */
271
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-requirements.php';
271
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-requirements.php';
272 272
 
273 273
 		/**
274 274
 		 * The class responsible for XCloner backup archive creation.
275 275
 		 */
276
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-archive.php';
276
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-archive.php';
277 277
 
278 278
 		/**
279 279
 		 * The class responsible for XCloner API requests.
280 280
 		 */
281
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-api.php';
281
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-api.php';
282 282
 
283 283
 		/**
284 284
 		 * The class responsible for the XCloner File System methods.
285 285
 		 */
286
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-file-system.php';
286
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-file-system.php';
287 287
 
288 288
 		/**
289 289
 		 * The class responsible for the XCloner File Transfer methods.
290 290
 		 */
291
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-file-transfer.php';
291
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-file-transfer.php';
292 292
 
293 293
 		/**
294 294
 		 * The class responsible for the XCloner Scheduler methods.
295 295
 		 */
296
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-scheduler.php';
296
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-scheduler.php';
297 297
 
298 298
 		/**
299 299
 		 * The class responsible for defining all actions that occur in the public-facing
300 300
 		 * side of the site.
301 301
 		 */
302
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-xcloner-public.php';
302
+		require_once plugin_dir_path(dirname(__FILE__)).'public/class-xcloner-public.php';
303 303
 
304 304
 		$this->loader = new Xcloner_Loader($this);
305 305
 
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 
319 319
 		$plugin_i18n = new Xcloner_i18n();
320 320
 
321
-		$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
321
+		$this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
322 322
 
323 323
 		//wp_localize_script( 'ajax-script', 'my_ajax_object',
324 324
         //   array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
@@ -334,13 +334,13 @@  discard block
 block discarded – undo
334 334
 	 */
335 335
 	private function define_admin_hooks() {
336 336
 
337
-		$plugin_admin = new Xcloner_Admin( $this );
337
+		$plugin_admin = new Xcloner_Admin($this);
338 338
 		$this->plugin_admin = $plugin_admin;
339 339
 
340
-		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
341
-		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
340
+		$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
341
+		$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
342 342
 
343
-		add_action( 'backup_archive_finished', array($this, 'do_action_after_backup_finished'), 10, 2);
343
+		add_action('backup_archive_finished', array($this, 'do_action_after_backup_finished'), 10, 2);
344 344
 	}
345 345
 
346 346
 	/**
@@ -349,31 +349,31 @@  discard block
 block discarded – undo
349 349
 	 * @access    private
350 350
 	 *
351 351
 	 */
352
-	private function define_admin_menu(){
352
+	private function define_admin_menu() {
353 353
 
354 354
 		add_action('admin_menu', array($this->loader, 'xcloner_backup_add_admin_menu'));
355 355
 
356 356
 	}
357 357
 
358
-	private function define_plugin_settings(){
358
+	private function define_plugin_settings() {
359 359
 		/**
360 360
 		* register wporg_settings_init to the admin_init action hook
361 361
 		*/
362 362
 
363 363
 		$this->xcloner_settings = new XCloner_Settings($this);
364 364
 
365
-		if(defined('DOING_CRON') || isset($_POST['hash'])){
365
+		if (defined('DOING_CRON') || isset($_POST['hash'])) {
366 366
 
367
-			if(defined('DOING_CRON') || $_POST['hash'] == "generate_hash"){
367
+			if (defined('DOING_CRON') || $_POST['hash'] == "generate_hash") {
368 368
 				$this->xcloner_settings->generate_new_hash();
369
-			}else{
369
+			} else {
370 370
 				$this->xcloner_settings->set_hash($_POST['hash']);
371 371
 			}
372 372
 		}
373 373
 
374
-		if(defined('DOING_CRON') || !isset($_POST['hash']))
374
+		if (defined('DOING_CRON') || !isset($_POST['hash']))
375 375
 		{
376
-			add_action( 'shutdown', function(){
376
+			add_action('shutdown', function() {
377 377
 				$this->xcloner_file_system = new Xcloner_File_System($this);
378 378
 				$this->xcloner_file_system->remove_tmp_filesystem();
379 379
 			});
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 	 */
397 397
 	public function pre_auto_update($type, $item, $context)
398 398
 	{
399
-		if(!$type)
399
+		if (!$type)
400 400
 		{
401 401
 			return false;
402 402
 		}
@@ -405,10 +405,10 @@  discard block
 block discarded – undo
405 405
 
406 406
 		$content_dir = str_replace(ABSPATH, "", WP_CONTENT_DIR);
407 407
 		$plugins_dir 	= str_replace(ABSPATH, "", WP_PLUGIN_DIR);
408
-		$langs_dir 		= $content_dir . DS . "languages";
409
-		$themes_dir 		= $content_dir . DS . "themes";
408
+		$langs_dir 		= $content_dir.DS."languages";
409
+		$themes_dir 		= $content_dir.DS."themes";
410 410
 
411
-		switch ( $type ) {
411
+		switch ($type) {
412 412
 			case 'core':
413 413
 				$exclude_files = array(
414 414
 									"^(?!(wp-admin|wp-includes|(?!.*\/.*.php)))(.*)$",
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 
419 419
 				$dir_array = explode(DS, $plugins_dir);
420 420
 
421
-				foreach($dir_array as $dir)
421
+				foreach ($dir_array as $dir)
422 422
 				{
423 423
 					$data .= "\/".$dir;
424 424
 					$regex .= $data."$|";
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 
435 435
 				$dir_array = explode(DS, $themes_dir);
436 436
 
437
-				foreach($dir_array as $dir)
437
+				foreach ($dir_array as $dir)
438 438
 				{
439 439
 					$data .= "\/".$dir;
440 440
 					$regex .= $data."$|";
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
 
451 451
 				$dir_array = explode(DS, $langs_dir);
452 452
 
453
-				foreach($dir_array as $dir)
453
+				foreach ($dir_array as $dir)
454 454
 				{
455 455
 					$data .= "\/".$dir;
456 456
 					$regex .= $data."$|";
@@ -476,9 +476,9 @@  discard block
 block discarded – undo
476 476
 		$schedule['backup_params']->email_notification = get_option('admin_email');
477 477
 		$schedule['backup_params']->backup_name = "backup_pre_auto_update_".$type."_[domain]-[time]-sql";
478 478
 
479
-		try{
479
+		try {
480 480
 			$this->xcloner_scheduler->xcloner_scheduler_callback(0, $schedule);
481
-		}catch(Exception $e){
481
+		}catch (Exception $e) {
482 482
 			$this->get_xcloner_logger()->error($e->getMessage());
483 483
 		}
484 484
 
@@ -493,10 +493,10 @@  discard block
 block discarded – undo
493 493
 	 */
494 494
 	private function define_public_hooks() {
495 495
 
496
-		$plugin_public = new Xcloner_Public( $this );
496
+		$plugin_public = new Xcloner_Public($this);
497 497
 
498
-		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
499
-		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
498
+		$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles');
499
+		$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts');
500 500
 
501 501
 	}
502 502
 
@@ -505,20 +505,20 @@  discard block
 block discarded – undo
505 505
 		$logger = new XCloner_Logger($this, "php_system");
506 506
 		$error = error_get_last();
507 507
 
508
-		if($error['type'] and $logger)
508
+		if ($error['type'] and $logger)
509 509
 		{
510
-			$logger->info($this->friendly_error_type ($error['type']).": ".var_export($error, true));
510
+			$logger->info($this->friendly_error_type($error['type']).": ".var_export($error, true));
511 511
 		}
512 512
 
513 513
 	}
514 514
 
515 515
 	function friendly_error_type($type) {
516
-	    static $levels=null;
517
-	    if ($levels===null) {
518
-	        $levels=[];
516
+	    static $levels = null;
517
+	    if ($levels === null) {
518
+	        $levels = [];
519 519
 	        foreach (get_defined_constants() as $key=>$value) {
520
-	            if (strpos($key,'E_')!==0) {continue;}
521
-					$levels[$value]= $key; //substr($key,2);
520
+	            if (strpos($key, 'E_') !== 0) {continue; }
521
+					$levels[$value] = $key; //substr($key,2);
522 522
 	        }
523 523
 	    }
524 524
 	    return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}");
@@ -528,52 +528,52 @@  discard block
 block discarded – undo
528 528
 	{
529 529
 		//adding the pre-update hook
530 530
 
531
-		if(is_admin() || defined('DOING_CRON'))
531
+		if (is_admin() || defined('DOING_CRON'))
532 532
 		{
533
-			$this->xcloner_logger 			= new XCloner_Logger($this, "xcloner_api");
534
-			$this->xcloner_filesystem 		= new Xcloner_File_System($this);
533
+			$this->xcloner_logger = new XCloner_Logger($this, "xcloner_api");
534
+			$this->xcloner_filesystem = new Xcloner_File_System($this);
535 535
 
536 536
 			//$this->xcloner_filesystem->set_diff_timestamp_start (strtotime("-15 days"));
537 537
 
538
-			$this->archive_system 			= new Xcloner_Archive($this);
539
-			$this->xcloner_database 		= new Xcloner_Database($this);
540
-			$this->xcloner_scheduler 		= new Xcloner_Scheduler($this);
541
-			$this->xcloner_remote_storage 	= new Xcloner_Remote_Storage($this);
542
-			$this->xcloner_file_transfer 	= new Xcloner_File_Transfer($this);
543
-
544
-			$xcloner_api 					= new Xcloner_Api($this);
545
-
546
-			add_action( 'wp_ajax_get_database_tables_action', 	array($xcloner_api,'get_database_tables_action')  );
547
-			add_action( 'wp_ajax_get_file_system_action', 		array($xcloner_api,'get_file_system_action')  );
548
-			add_action( 'wp_ajax_scan_filesystem', 				array($xcloner_api,'scan_filesystem')  );
549
-			add_action( 'wp_ajax_backup_database', 				array($xcloner_api,'backup_database')  );
550
-			add_action( 'wp_ajax_backup_files'	, 				array($xcloner_api,'backup_files')  );
551
-			add_action( 'wp_ajax_save_schedule'	, 				array($xcloner_api,'save_schedule')  );
552
-			add_action( 'wp_ajax_get_schedule_by_id',	 		array($xcloner_api,'get_schedule_by_id')  );
553
-			add_action( 'wp_ajax_get_scheduler_list',	 		array($xcloner_api,'get_scheduler_list')  );
554
-			add_action( 'wp_ajax_delete_schedule_by_id'	, 		array($xcloner_api,'delete_schedule_by_id')  );
555
-			add_action( 'wp_ajax_delete_backup_by_name'	, 		array($xcloner_api,'delete_backup_by_name')  );
556
-			add_action( 'wp_ajax_download_backup_by_name', 		array($xcloner_api,'download_backup_by_name')  );
557
-			add_action( 'wp_ajax_remote_storage_save_status', 	array($xcloner_api,'remote_storage_save_status')  );
558
-			add_action( 'wp_ajax_upload_backup_to_remote', 		array($xcloner_api,'upload_backup_to_remote')  );
559
-			add_action( 'wp_ajax_list_backup_files'	,			array($xcloner_api,'list_backup_files')  );
560
-			add_action( 'wp_ajax_restore_upload_backup'	, 		array($xcloner_api,'restore_upload_backup')  );
561
-			add_action( 'wp_ajax_download_restore_script', 		array($xcloner_api,'download_restore_script')  );
562
-			add_action( 'wp_ajax_copy_backup_remote_to_local', 	array($xcloner_api,'copy_backup_remote_to_local')  );
563
-			add_action( 'wp_ajax_restore_backup', 				array($xcloner_api,'restore_backup')  );
564
-			add_action( 'admin_notices', 						array($this, 'xcloner_error_admin_notices' ));
538
+			$this->archive_system = new Xcloner_Archive($this);
539
+			$this->xcloner_database = new Xcloner_Database($this);
540
+			$this->xcloner_scheduler = new Xcloner_Scheduler($this);
541
+			$this->xcloner_remote_storage = new Xcloner_Remote_Storage($this);
542
+			$this->xcloner_file_transfer = new Xcloner_File_Transfer($this);
543
+
544
+			$xcloner_api = new Xcloner_Api($this);
545
+
546
+			add_action('wp_ajax_get_database_tables_action', array($xcloner_api, 'get_database_tables_action'));
547
+			add_action('wp_ajax_get_file_system_action', array($xcloner_api, 'get_file_system_action'));
548
+			add_action('wp_ajax_scan_filesystem', array($xcloner_api, 'scan_filesystem'));
549
+			add_action('wp_ajax_backup_database', array($xcloner_api, 'backup_database'));
550
+			add_action('wp_ajax_backup_files', array($xcloner_api, 'backup_files'));
551
+			add_action('wp_ajax_save_schedule', array($xcloner_api, 'save_schedule'));
552
+			add_action('wp_ajax_get_schedule_by_id', array($xcloner_api, 'get_schedule_by_id'));
553
+			add_action('wp_ajax_get_scheduler_list', array($xcloner_api, 'get_scheduler_list'));
554
+			add_action('wp_ajax_delete_schedule_by_id', array($xcloner_api, 'delete_schedule_by_id'));
555
+			add_action('wp_ajax_delete_backup_by_name', array($xcloner_api, 'delete_backup_by_name'));
556
+			add_action('wp_ajax_download_backup_by_name', array($xcloner_api, 'download_backup_by_name'));
557
+			add_action('wp_ajax_remote_storage_save_status', array($xcloner_api, 'remote_storage_save_status'));
558
+			add_action('wp_ajax_upload_backup_to_remote', array($xcloner_api, 'upload_backup_to_remote'));
559
+			add_action('wp_ajax_list_backup_files', array($xcloner_api, 'list_backup_files'));
560
+			add_action('wp_ajax_restore_upload_backup', array($xcloner_api, 'restore_upload_backup'));
561
+			add_action('wp_ajax_download_restore_script', array($xcloner_api, 'download_restore_script'));
562
+			add_action('wp_ajax_copy_backup_remote_to_local', array($xcloner_api, 'copy_backup_remote_to_local'));
563
+			add_action('wp_ajax_restore_backup', array($xcloner_api, 'restore_backup'));
564
+			add_action('admin_notices', array($this, 'xcloner_error_admin_notices'));
565 565
 
566 566
         }
567 567
 
568 568
         //Do a pre-update backup of targeted files
569
-        if($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup'))
569
+        if ($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup'))
570 570
         {
571 571
 			add_action("pre_auto_update", array($this, "pre_auto_update"), 1, 3);
572 572
 		}
573 573
 	}
574 574
 
575 575
 	function add_plugin_action_links($links, $file) {
576
-        if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php'))
576
+        if ($file == plugin_basename(dirname(dirname(__FILE__)).'/xcloner.php'))
577 577
 		{
578 578
 			$links[] = '<a href="admin.php?page=xcloner_settings_page">'.__('Settings', 'xcloner-backup-and-restore').'</a>';
579 579
 			$links[] = '<a href="admin.php?page=xcloner_generate_backups_page">'.__('Generate Backup', 'xcloner-backup-and-restore').'</a>';
@@ -583,13 +583,13 @@  discard block
 block discarded – undo
583 583
     }
584 584
 
585 585
 	public function xcloner_error_admin_notices() {
586
-			settings_errors( 'xcloner_error_message' );
586
+			settings_errors('xcloner_error_message');
587 587
 		}
588 588
 
589 589
 	public function define_cron_hooks()
590 590
 	{
591 591
 		//registering new schedule intervals
592
-		add_filter( 'cron_schedules', array($this, 'add_new_intervals'));
592
+		add_filter('cron_schedules', array($this, 'add_new_intervals'));
593 593
 
594 594
 
595 595
 		$xcloner_scheduler = $this->get_xcloner_scheduler();
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
 
671 671
 		$page = sanitize_key($_GET['page']);
672 672
 
673
-		if($page)
673
+		if ($page)
674 674
 		{
675 675
 			$this->display($page);
676 676
 		}
Please login to merge, or discard this patch.
admin/class-xcloner-admin.php 2 patches
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -47,8 +47,6 @@
 block discarded – undo
47 47
 	 *
48 48
 	 * @since    1.0.0
49 49
 	 *
50
-	 * @param      string $plugin_name The name of this plugin.
51
-	 * @param      string $version The version of this plugin.
52 50
 	 */
53 51
 	public function __construct( Xcloner $xcloner_container ) {
54 52
 
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 * @param      string $plugin_name The name of this plugin.
51 51
 	 * @param      string $version The version of this plugin.
52 52
 	 */
53
-	public function __construct( Xcloner $xcloner_container ) {
53
+	public function __construct(Xcloner $xcloner_container) {
54 54
 
55 55
 		$this->plugin_name       = $xcloner_container->get_plugin_name();
56 56
 		$this->version           = $xcloner_container->get_version();
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
 	 *
67 67
 	 * @since    1.0.0
68 68
 	 */
69
-	public function enqueue_styles( $hook ) {
69
+	public function enqueue_styles($hook) {
70 70
 
71
-		if ( ! stristr( $hook, "page_" . $this->plugin_name ) || ( isset( $_GET['option'] ) and $_GET['option'] == "com_cloner" ) ) {
71
+		if (!stristr($hook, "page_".$this->plugin_name) || (isset($_GET['option']) and $_GET['option'] == "com_cloner")) {
72 72
 			return;
73 73
 		}
74 74
 
@@ -84,13 +84,13 @@  discard block
 block discarded – undo
84 84
 		 * class.
85 85
 		 */
86 86
 
87
-		wp_enqueue_style( $this->plugin_name . "_materialize", plugin_dir_url( __FILE__ ) . 'css/materialize.min.css', array(), $this->version, 'all' );
88
-		wp_enqueue_style( $this->plugin_name . "_materialize.clockpicker", plugin_dir_url( __FILE__ ) . 'css/materialize.clockpicker.css', array(), $this->version, 'all' );
89
-		wp_enqueue_style( $this->plugin_name . "_materialize.icons", '//fonts.googleapis.com/icon?family=Material+Icons', array(), $this->version, 'all' );
90
-		wp_enqueue_style( $this->plugin_name . "_jquery.datatables", plugin_dir_url( __FILE__ ) . 'css/jquery.dataTables.min.css', array(), $this->version, 'all' );
91
-		wp_enqueue_style( $this->plugin_name . "_jquery.datatables.responsive", plugin_dir_url( __FILE__ ) . 'css/responsive.dataTables.css', array(), $this->version, 'all' );
92
-		wp_enqueue_style( $this->plugin_name . "_jstree", dirname( plugin_dir_url( __FILE__ ) ) . '/vendor/vakata/jstree/dist/themes/default/style.min.css', array(), '3.3', 'all' );
93
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/xcloner-admin.css', array(), $this->version, 'all' );
87
+		wp_enqueue_style($this->plugin_name."_materialize", plugin_dir_url(__FILE__).'css/materialize.min.css', array(), $this->version, 'all');
88
+		wp_enqueue_style($this->plugin_name."_materialize.clockpicker", plugin_dir_url(__FILE__).'css/materialize.clockpicker.css', array(), $this->version, 'all');
89
+		wp_enqueue_style($this->plugin_name."_materialize.icons", '//fonts.googleapis.com/icon?family=Material+Icons', array(), $this->version, 'all');
90
+		wp_enqueue_style($this->plugin_name."_jquery.datatables", plugin_dir_url(__FILE__).'css/jquery.dataTables.min.css', array(), $this->version, 'all');
91
+		wp_enqueue_style($this->plugin_name."_jquery.datatables.responsive", plugin_dir_url(__FILE__).'css/responsive.dataTables.css', array(), $this->version, 'all');
92
+		wp_enqueue_style($this->plugin_name."_jstree", dirname(plugin_dir_url(__FILE__)).'/vendor/vakata/jstree/dist/themes/default/style.min.css', array(), '3.3', 'all');
93
+		wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/xcloner-admin.css', array(), $this->version, 'all');
94 94
 
95 95
 	}
96 96
 
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
 	 *
100 100
 	 * @since    1.0.0
101 101
 	 */
102
-	public function enqueue_scripts( $hook ) {
102
+	public function enqueue_scripts($hook) {
103 103
 
104
-		if ( ! stristr( $hook, "page_" . $this->plugin_name ) ) {
104
+		if (!stristr($hook, "page_".$this->plugin_name)) {
105 105
 			return;
106 106
 		}
107 107
 
@@ -118,25 +118,25 @@  discard block
 block discarded – undo
118 118
 		 */
119 119
 
120 120
 		add_thickbox();
121
-		wp_enqueue_script( 'plugin-install' );
122
-		wp_enqueue_script( 'updates' );
123
-		wp_enqueue_script( $this->plugin_name . "_materialize", plugin_dir_url( __FILE__ ) . 'js/materialize.min.js', array( 'jquery' ), $this->version, false );
124
-		wp_enqueue_script( $this->plugin_name . "_materialize.clockpicker", plugin_dir_url( __FILE__ ) . 'js/materialize.clockpicker.js', array( 'jquery' ), $this->version, false );
125
-		wp_enqueue_script( $this->plugin_name . "_jquery.datatables", plugin_dir_url( __FILE__ ) . 'js/jquery.dataTables.min.js', array( 'jquery' ), $this->version, false );
126
-		wp_enqueue_script( $this->plugin_name . "_jquery.datatables.respnsive", plugin_dir_url( __FILE__ ) . 'js/dataTables.responsive.js', array( 'jquery' ), $this->version, false );
127
-		wp_enqueue_script( $this->plugin_name . "_vakata", dirname( plugin_dir_url( __FILE__ ) ) . '/vendor/vakata/jstree/dist/jstree.min.js', array( 'jquery' ), '3.3', false );
128
-		wp_enqueue_script( $this->plugin_name . "_xcloner-backup-class", plugin_dir_url( __FILE__ ) . 'js/xcloner-backup-class.js', array( 'jquery' ), $this->version, false );
129
-		wp_enqueue_script( $this->plugin_name . "_xcloner-scheduler-class", plugin_dir_url( __FILE__ ) . 'js/xcloner-scheduler-class.js', array( 'jquery' ), $this->version, false );
130
-		wp_enqueue_script( $this->plugin_name . "_xcloner-restore-class", plugin_dir_url( __FILE__ ) . 'js/xcloner-restore-class.js', array( 'jquery' ), $this->version, false );
131
-		wp_enqueue_script( $this->plugin_name . "_xcloner-manage-backups-class", plugin_dir_url( __FILE__ ) . 'js/xcloner-manage-backups-class.js', array( 'jquery' ), $this->version, false );
132
-		wp_enqueue_script( $this->plugin_name . "_xcloner-remote-storage-class", plugin_dir_url( __FILE__ ) . 'js/xcloner-remote-storage-class.js', array( 'jquery' ), $this->version, false );
133
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/xcloner-admin.js', array( 'jquery' ), $this->version, false );
121
+		wp_enqueue_script('plugin-install');
122
+		wp_enqueue_script('updates');
123
+		wp_enqueue_script($this->plugin_name."_materialize", plugin_dir_url(__FILE__).'js/materialize.min.js', array('jquery'), $this->version, false);
124
+		wp_enqueue_script($this->plugin_name."_materialize.clockpicker", plugin_dir_url(__FILE__).'js/materialize.clockpicker.js', array('jquery'), $this->version, false);
125
+		wp_enqueue_script($this->plugin_name."_jquery.datatables", plugin_dir_url(__FILE__).'js/jquery.dataTables.min.js', array('jquery'), $this->version, false);
126
+		wp_enqueue_script($this->plugin_name."_jquery.datatables.respnsive", plugin_dir_url(__FILE__).'js/dataTables.responsive.js', array('jquery'), $this->version, false);
127
+		wp_enqueue_script($this->plugin_name."_vakata", dirname(plugin_dir_url(__FILE__)).'/vendor/vakata/jstree/dist/jstree.min.js', array('jquery'), '3.3', false);
128
+		wp_enqueue_script($this->plugin_name."_xcloner-backup-class", plugin_dir_url(__FILE__).'js/xcloner-backup-class.js', array('jquery'), $this->version, false);
129
+		wp_enqueue_script($this->plugin_name."_xcloner-scheduler-class", plugin_dir_url(__FILE__).'js/xcloner-scheduler-class.js', array('jquery'), $this->version, false);
130
+		wp_enqueue_script($this->plugin_name."_xcloner-restore-class", plugin_dir_url(__FILE__).'js/xcloner-restore-class.js', array('jquery'), $this->version, false);
131
+		wp_enqueue_script($this->plugin_name."_xcloner-manage-backups-class", plugin_dir_url(__FILE__).'js/xcloner-manage-backups-class.js', array('jquery'), $this->version, false);
132
+		wp_enqueue_script($this->plugin_name."_xcloner-remote-storage-class", plugin_dir_url(__FILE__).'js/xcloner-remote-storage-class.js', array('jquery'), $this->version, false);
133
+		wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__).'js/xcloner-admin.js', array('jquery'), $this->version, false);
134 134
 
135 135
 
136 136
 	}
137 137
 
138 138
 	public function xcloner_init_page() {
139
-		require_once( "partials/xcloner_init_page.php" );
139
+		require_once("partials/xcloner_init_page.php");
140 140
 
141 141
 	}
142 142
 
@@ -145,70 +145,70 @@  discard block
 block discarded – undo
145 145
 		$remote_storage       = $this->get_xcloner_container()->get_xcloner_remote_storage();
146 146
 
147 147
 
148
-		if ( isset( $_POST['action'] ) ) {
149
-			$_POST['action'] = $xcloner_sanitization->sanitize_input_as_string( $_POST['action'] );
150
-			$remote_storage->save( $_POST['action'] );
148
+		if (isset($_POST['action'])) {
149
+			$_POST['action'] = $xcloner_sanitization->sanitize_input_as_string($_POST['action']);
150
+			$remote_storage->save($_POST['action']);
151 151
 		}
152 152
 
153
-		if ( isset( $_POST['authentification_code'] ) && $_POST['authentification_code'] != "" ) {
154
-			$_POST['authentification_code'] = $xcloner_sanitization->sanitize_input_as_string( $_POST['authentification_code'] );
153
+		if (isset($_POST['authentification_code']) && $_POST['authentification_code'] != "") {
154
+			$_POST['authentification_code'] = $xcloner_sanitization->sanitize_input_as_string($_POST['authentification_code']);
155 155
 
156
-			$remote_storage->set_access_token( $_POST['authentification_code'] );
156
+			$remote_storage->set_access_token($_POST['authentification_code']);
157 157
 		}
158 158
 
159
-		if ( isset( $_POST['connection_check'] ) && $_POST['connection_check'] ) {
160
-			$remote_storage->check( $_POST['action'] );
159
+		if (isset($_POST['connection_check']) && $_POST['connection_check']) {
160
+			$remote_storage->check($_POST['action']);
161 161
 		}
162 162
 
163
-		require_once( "partials/xcloner_remote_storage_page.php" );
163
+		require_once("partials/xcloner_remote_storage_page.php");
164 164
 
165 165
 	}
166 166
 
167 167
 	public function xcloner_scheduled_backups_page() {
168 168
 		$requirements = $this->xcloner_container->get_xcloner_requirements();
169 169
 
170
-		if ( ! $requirements->check_backup_ready_status() ) {
171
-			require_once( "partials/xcloner_init_page.php" );
170
+		if (!$requirements->check_backup_ready_status()) {
171
+			require_once("partials/xcloner_init_page.php");
172 172
 
173 173
 			return false;
174 174
 		}
175 175
 
176
-		require_once( "partials/xcloner_scheduled_backups_page.php" );
176
+		require_once("partials/xcloner_scheduled_backups_page.php");
177 177
 
178 178
 	}
179 179
 
180 180
 	public function xcloner_manage_backups_page() {
181
-		require_once( "partials/xcloner_manage_backups_page.php" );
181
+		require_once("partials/xcloner_manage_backups_page.php");
182 182
 
183 183
 	}
184 184
 
185 185
 	public function xcloner_debugger_page() {
186
-		require_once( "partials/xcloner_console_page.php" );
186
+		require_once("partials/xcloner_console_page.php");
187 187
 
188 188
 	}
189 189
 
190 190
 	public function xcloner_restore_page() {
191
-		require_once( "partials/xcloner_restore_page.php" );
191
+		require_once("partials/xcloner_restore_page.php");
192 192
 
193 193
 	}
194 194
 
195 195
 	public function xcloner_generate_backups_page() {
196 196
 		$requirements = $this->xcloner_container->get_xcloner_requirements();
197 197
 
198
-		if ( ! $requirements->check_backup_ready_status() ) {
199
-			require_once( "partials/xcloner_init_page.php" );
198
+		if (!$requirements->check_backup_ready_status()) {
199
+			require_once("partials/xcloner_init_page.php");
200 200
 
201 201
 			return false;
202 202
 		}
203 203
 
204
-		require_once( "partials/xcloner_generate_backups_page.php" );
204
+		require_once("partials/xcloner_generate_backups_page.php");
205 205
 
206 206
 		return;
207 207
 	}
208 208
 
209 209
 	public function xcloner_settings_page() {
210 210
 		// check user capabilities
211
-		if ( ! current_user_can( 'manage_options' ) ) {
211
+		if (!current_user_can('manage_options')) {
212 212
 			return;
213 213
 		}
214 214
 
@@ -216,40 +216,40 @@  discard block
 block discarded – undo
216 216
 
217 217
 		// check if the user have submitted the settings
218 218
 		// wordpress will add the "settings-updated" $_GET parameter to the url
219
-		if ( isset( $_GET['settings-updated'] ) ) {
219
+		if (isset($_GET['settings-updated'])) {
220 220
 			// add settings saved message with the class of "updated"
221
-			add_settings_error( 'wporg_messages', 'wporg_message', __( 'Settings Saved', 'wporg' ), 'updated' );
221
+			add_settings_error('wporg_messages', 'wporg_message', __('Settings Saved', 'wporg'), 'updated');
222 222
 		}
223 223
 
224 224
 		// show error/update messages
225
-		settings_errors( 'wporg_messages' );
225
+		settings_errors('wporg_messages');
226 226
 		?>
227 227
 
228 228
 		<?php
229 229
 		$xcloner_sanitization = $this->get_xcloner_container()->get_xcloner_sanitization();
230 230
 
231
-		if ( isset( $_GET['tab'] ) ) {
232
-			$active_tab = $xcloner_sanitization->sanitize_input_as_string( $_GET['tab'] );
231
+		if (isset($_GET['tab'])) {
232
+			$active_tab = $xcloner_sanitization->sanitize_input_as_string($_GET['tab']);
233 233
 		} // end if
234 234
 		else {
235 235
 			$active_tab = "general_options";
236 236
 		}
237 237
 
238 238
 		?>
239
-        <h1><?= esc_html( get_admin_page_title() ); ?></h1>
239
+        <h1><?= esc_html(get_admin_page_title()); ?></h1>
240 240
 
241 241
         <ul class="nav-tab-wrapper row">
242 242
             <li><a href="?page=xcloner_settings_page&tab=general_options"
243
-                   class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'general_options' ? 'nav-tab-active' : ''; ?>"><?php echo __( 'General Options', 'xcloner-backup-and-restore' ) ?></a>
243
+                   class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'general_options' ? 'nav-tab-active' : ''; ?>"><?php echo __('General Options', 'xcloner-backup-and-restore') ?></a>
244 244
             </li>
245 245
             <li><a href="?page=xcloner_settings_page&tab=mysql_options"
246
-                   class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'mysql_options' ? 'nav-tab-active' : ''; ?>"><?php echo __( 'Mysql Options', 'xcloner-backup-and-restore' ) ?></a>
246
+                   class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'mysql_options' ? 'nav-tab-active' : ''; ?>"><?php echo __('Mysql Options', 'xcloner-backup-and-restore') ?></a>
247 247
             </li>
248 248
             <li><a href="?page=xcloner_settings_page&tab=system_options"
249
-                   class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'system_options' ? 'nav-tab-active' : ''; ?>"><?php echo __( 'System Options', 'xcloner-backup-and-restore' ) ?></a>
249
+                   class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'system_options' ? 'nav-tab-active' : ''; ?>"><?php echo __('System Options', 'xcloner-backup-and-restore') ?></a>
250 250
             </li>
251 251
             <li><a href="?page=xcloner_settings_page&tab=cleanup_options"
252
-                   class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'cleanup_options' ? 'nav-tab-active' : ''; ?>"><?php echo __( 'Cleanup Options', 'xcloner-backup-and-restore' ) ?></a>
252
+                   class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'cleanup_options' ? 'nav-tab-active' : ''; ?>"><?php echo __('Cleanup Options', 'xcloner-backup-and-restore') ?></a>
253 253
             </li>
254 254
         </ul>
255 255
 
@@ -258,27 +258,27 @@  discard block
 block discarded – undo
258 258
             <form action="options.php" method="post">
259 259
 				<?php
260 260
 
261
-				if ( $active_tab == 'general_options' ) {
261
+				if ($active_tab == 'general_options') {
262 262
 
263
-					settings_fields( 'xcloner_general_settings_group' );
264
-					do_settings_sections( 'xcloner_settings_page' );
263
+					settings_fields('xcloner_general_settings_group');
264
+					do_settings_sections('xcloner_settings_page');
265 265
 
266
-				} elseif ( $active_tab == 'mysql_options' ) {
266
+				} elseif ($active_tab == 'mysql_options') {
267 267
 
268
-					settings_fields( 'xcloner_mysql_settings_group' );
269
-					do_settings_sections( 'xcloner_mysql_settings_page' );
270
-				} elseif ( $active_tab == 'system_options' ) {
268
+					settings_fields('xcloner_mysql_settings_group');
269
+					do_settings_sections('xcloner_mysql_settings_page');
270
+				} elseif ($active_tab == 'system_options') {
271 271
 
272
-					settings_fields( 'xcloner_system_settings_group' );
273
-					do_settings_sections( 'xcloner_system_settings_page' );
274
-				} elseif ( $active_tab == 'cleanup_options' ) {
272
+					settings_fields('xcloner_system_settings_group');
273
+					do_settings_sections('xcloner_system_settings_page');
274
+				} elseif ($active_tab == 'cleanup_options') {
275 275
 
276
-					settings_fields( 'xcloner_cleanup_settings_group' );
277
-					do_settings_sections( 'xcloner_cleanup_settings_page' );
276
+					settings_fields('xcloner_cleanup_settings_group');
277
+					do_settings_sections('xcloner_cleanup_settings_page');
278 278
 				}
279 279
 
280 280
 				// output save settings button
281
-				submit_button( 'Save Settings' );
281
+				submit_button('Save Settings');
282 282
 				?>
283 283
             </form>
284 284
 
Please login to merge, or discard this patch.
includes/class-xcloner-api.php 3 patches
Unused Use Statements   -5 removed lines patch added patch discarded remove patch
@@ -28,13 +28,8 @@
 block discarded – undo
28 28
 
29 29
 use League\Flysystem\Config;
30 30
 use League\Flysystem\Filesystem;
31
-use League\Flysystem\Util;
32 31
 use League\Flysystem\Adapter\Local;
33
-
34 32
 use splitbrain\PHPArchive\Tar;
35
-use splitbrain\PHPArchive\Zip;
36
-use splitbrain\PHPArchive\Archive;
37
-use splitbrain\PHPArchive\FileInfo;
38 33
 
39 34
 
40 35
 /**
Please login to merge, or discard this patch.
Indentation   +889 added lines, -889 removed lines patch added patch discarded remove patch
@@ -43,905 +43,905 @@  discard block
 block discarded – undo
43 43
 class Xcloner_Api
44 44
 {
45 45
 
46
-    private $xcloner_database;
47
-    private $xcloner_settings;
48
-    private $xcloner_file_system;
49
-    private $xcloner_requirements;
50
-    private $xcloner_sanitization;
51
-    private $archive_system;
52
-    private $form_params;
53
-    private $logger;
54
-    private $xcloner_container;
55
-
56
-    /**
57
-     * XCloner_Api construct class
58
-     *
59
-     * @param Xcloner $xcloner_container [description]
60
-     */
61
-    public function __construct(Xcloner $xcloner_container)
62
-    {
63
-        global $wpdb;
64
-
65
-        if (WP_DEBUG) {
66
-            error_reporting(0);
67
-        }
68
-
69
-        if (ob_get_length()) {
70
-            ob_end_clean();
71
-        }
72
-        ob_start();
73
-
74
-        $wpdb->show_errors = false;
75
-
76
-        $this->xcloner_container = $xcloner_container;
77
-
78
-        $this->xcloner_settings = $xcloner_container->get_xcloner_settings();
79
-        $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_api");
80
-        $this->xcloner_file_system = $xcloner_container->get_xcloner_filesystem();
81
-        $this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization();
82
-        $this->xcloner_requirements = $xcloner_container->get_xcloner_requirements();
83
-        $this->archive_system = $xcloner_container->get_archive_system();
84
-        $this->xcloner_database = $xcloner_container->get_xcloner_database();
85
-        $this->xcloner_scheduler = $xcloner_container->get_xcloner_scheduler();
86
-
87
-        if (isset($_POST['API_ID'])) {
88
-            $this->logger->info("Processing ajax request ID " . substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']),
89
-                    0, 15));
90
-        }
91
-
92
-    }
93
-
94
-    /**
95
-     * Get XCloner Container
96
-     * @return XCloner return the XCloner container
97
-     */
98
-    public function get_xcloner_container()
99
-    {
100
-        return $this->xcloner_container;
101
-    }
102
-
103
-    /**
104
-     * Check if user has access to this class
105
-     * @return die() returns die() if user is not allowed
106
-     * @link http://www.wordpress.org
107
-     */
108
-    private function check_access()
109
-    {
110
-        if (function_exists('current_user_can') && !current_user_can('manage_options')) {
111
-            die("Not allowed access here!");
112
-        }
113
-    }
114
-
115
-    /**
116
-     * Initialize the database connection
117
-     */
118
-    public function init_db()
119
-    {
120
-        return;
121
-
122
-
123
-        $data['dbHostname'] = $this->xcloner_settings->get_db_hostname();
124
-        $data['dbUsername'] = $this->xcloner_settings->get_db_username();
125
-        $data['dbPassword'] = $this->xcloner_settings->get_db_password();
126
-        $data['dbDatabase'] = $this->xcloner_settings->get_db_database();
127
-
128
-
129
-        $data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
130
-        $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . ".database";
131
-        $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "database-sql.sql";
132
-
133
-        try {
134
-            $this->xcloner_database->init($data);
135
-
136
-        } catch (Exception $e) {
137
-
138
-            $this->send_response($e->getMessage());
139
-            $this->logger->error($e->getMessage());
140
-
141
-        }
142
-
143
-        return $this->xcloner_database;
144
-
145
-
146
-    }
147
-
148
-    /*
46
+	private $xcloner_database;
47
+	private $xcloner_settings;
48
+	private $xcloner_file_system;
49
+	private $xcloner_requirements;
50
+	private $xcloner_sanitization;
51
+	private $archive_system;
52
+	private $form_params;
53
+	private $logger;
54
+	private $xcloner_container;
55
+
56
+	/**
57
+	 * XCloner_Api construct class
58
+	 *
59
+	 * @param Xcloner $xcloner_container [description]
60
+	 */
61
+	public function __construct(Xcloner $xcloner_container)
62
+	{
63
+		global $wpdb;
64
+
65
+		if (WP_DEBUG) {
66
+			error_reporting(0);
67
+		}
68
+
69
+		if (ob_get_length()) {
70
+			ob_end_clean();
71
+		}
72
+		ob_start();
73
+
74
+		$wpdb->show_errors = false;
75
+
76
+		$this->xcloner_container = $xcloner_container;
77
+
78
+		$this->xcloner_settings = $xcloner_container->get_xcloner_settings();
79
+		$this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_api");
80
+		$this->xcloner_file_system = $xcloner_container->get_xcloner_filesystem();
81
+		$this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization();
82
+		$this->xcloner_requirements = $xcloner_container->get_xcloner_requirements();
83
+		$this->archive_system = $xcloner_container->get_archive_system();
84
+		$this->xcloner_database = $xcloner_container->get_xcloner_database();
85
+		$this->xcloner_scheduler = $xcloner_container->get_xcloner_scheduler();
86
+
87
+		if (isset($_POST['API_ID'])) {
88
+			$this->logger->info("Processing ajax request ID " . substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']),
89
+					0, 15));
90
+		}
91
+
92
+	}
93
+
94
+	/**
95
+	 * Get XCloner Container
96
+	 * @return XCloner return the XCloner container
97
+	 */
98
+	public function get_xcloner_container()
99
+	{
100
+		return $this->xcloner_container;
101
+	}
102
+
103
+	/**
104
+	 * Check if user has access to this class
105
+	 * @return die() returns die() if user is not allowed
106
+	 * @link http://www.wordpress.org
107
+	 */
108
+	private function check_access()
109
+	{
110
+		if (function_exists('current_user_can') && !current_user_can('manage_options')) {
111
+			die("Not allowed access here!");
112
+		}
113
+	}
114
+
115
+	/**
116
+	 * Initialize the database connection
117
+	 */
118
+	public function init_db()
119
+	{
120
+		return;
121
+
122
+
123
+		$data['dbHostname'] = $this->xcloner_settings->get_db_hostname();
124
+		$data['dbUsername'] = $this->xcloner_settings->get_db_username();
125
+		$data['dbPassword'] = $this->xcloner_settings->get_db_password();
126
+		$data['dbDatabase'] = $this->xcloner_settings->get_db_database();
127
+
128
+
129
+		$data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
130
+		$data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . ".database";
131
+		$data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "database-sql.sql";
132
+
133
+		try {
134
+			$this->xcloner_database->init($data);
135
+
136
+		} catch (Exception $e) {
137
+
138
+			$this->send_response($e->getMessage());
139
+			$this->logger->error($e->getMessage());
140
+
141
+		}
142
+
143
+		return $this->xcloner_database;
144
+
145
+
146
+	}
147
+
148
+	/*
149 149
      * Save Schedule API
150 150
      */
151
-    public function save_schedule()
152
-    {
153
-        global $wpdb;
154
-
155
-        $this->check_access();
156
-
157
-        $scheduler = $this->xcloner_scheduler;
158
-        $params = array();
159
-        $schedule = array();
160
-        $response = array();
161
-
162
-        if (isset($_POST['data'])) {
163
-            $params = json_decode(stripslashes($_POST['data']));
164
-        }
165
-
166
-        $this->process_params($params);
167
-
168
-        if (isset($_POST['id'])) {
169
-
170
-            $this->form_params['backup_params']['backup_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_name']);
171
-            $this->form_params['backup_params']['email_notification'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['email_notification']);
172
-            if ($_POST['diff_start_date']) {
173
-                $this->form_params['backup_params']['diff_start_date'] = strtotime($this->xcloner_sanitization->sanitize_input_as_string($_POST['diff_start_date']));
174
-            } else {
175
-                $this->form_params['backup_params']['diff_start_date'] = "";
176
-            }
177
-            $this->form_params['backup_params']['schedule_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_name']);
178
-            $this->form_params['backup_params']['start_at'] = strtotime($_POST['schedule_start_date']);
179
-            $this->form_params['backup_params']['schedule_frequency'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_frequency']);
180
-            $this->form_params['backup_params']['schedule_storage'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_storage']);
181
-            $this->form_params['database'] = (stripslashes($this->xcloner_sanitization->sanitize_input_as_raw($_POST['table_params'])));
182
-            $this->form_params['excluded_files'] = (stripslashes($this->xcloner_sanitization->sanitize_input_as_raw($_POST['excluded_files'])));
183
-
184
-            //$this->form_params['backup_params']['backup_type'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_type']);
185
-
186
-            $tables = explode(PHP_EOL, $this->form_params['database']);
187
-            $return = array();
188
-
189
-            foreach ($tables as $table) {
190
-                $table = str_replace("\r", "", $table);
191
-                $data = explode(".", $table);
192
-                if (isset($data[1])) {
193
-                    $return[$data[0]][] = $data[1];
194
-                }
195
-            }
196
-
197
-            $this->form_params['database'] = ($return);
198
-
199
-            $excluded_files = explode(PHP_EOL, $this->form_params['excluded_files']);
200
-            $return = array();
201
-
202
-            foreach ($excluded_files as $file) {
203
-                $file = str_replace("\r", "", $file);
204
-                if ($file) {
205
-                    $return[] = $file;
206
-                }
207
-            }
208
-
209
-            $this->form_params['excluded_files'] = ($return);
210
-
211
-            $schedule['start_at'] = $this->form_params['backup_params']['start_at'];
212
-
213
-            if (!isset($_POST['status'])) {
214
-                $schedule['status'] = 0;
215
-            } else {
216
-                $schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']);
217
-            }
218
-        } else {
219
-
220
-            $schedule['status'] = 1;
221
-            $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] .
222
-                " " . $this->form_params['backup_params']['schedule_start_time']);
223
-
224
-            if ($schedule['start_at'] <= time()) {
225
-                $schedule['start_at'] = "";
226
-            }
227
-        }
228
-
229
-        if (!$schedule['start_at']) {
230
-            $schedule['start_at'] = date('Y-m-d H:i:s', time());
231
-        } else {
232
-            $schedule['start_at'] = date('Y-m-d H:i:s',
233
-                $schedule['start_at'] - (get_option('gmt_offset') * HOUR_IN_SECONDS));
234
-        }
235
-
236
-        $schedule['name'] = $this->form_params['backup_params']['schedule_name'];
237
-        $schedule['recurrence'] = $this->form_params['backup_params']['schedule_frequency'];
238
-        if (!isset($this->form_params['backup_params']['schedule_storage'])) {
239
-            $this->form_params['backup_params']['schedule_storage'] = "";
240
-        }
241
-        $schedule['remote_storage'] = $this->form_params['backup_params']['schedule_storage'];
242
-        //$schedule['backup_type'] = $this->form_params['backup_params']['backup_type'];
243
-        $schedule['params'] = json_encode($this->form_params);
244
-
245
-        if (!isset($_POST['id'])) {
246
-            $wpdb->insert(
247
-                $wpdb->prefix . 'xcloner_scheduler',
248
-                $schedule,
249
-                array(
250
-                    '%s',
251
-                    '%s'
252
-                )
253
-            );
254
-        } else {
255
-            $wpdb->update(
256
-                $wpdb->prefix . 'xcloner_scheduler',
257
-                $schedule,
258
-                array('id' => $_POST['id']),
259
-                array(
260
-                    '%s',
261
-                    '%s'
262
-                )
263
-            );
264
-        }
265
-        if (isset($_POST['id'])) {
266
-            $scheduler->update_cron_hook($_POST['id']);
267
-        }
268
-
269
-        if ($wpdb->last_error) {
270
-            $response['error'] = 1;
271
-            $response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/
272
-            ;
273
-
274
-        }
275
-
276
-        $scheduler->update_wp_cron_hooks();
277
-        $response['finished'] = 1;
278
-
279
-        $this->send_response($response);
280
-    }
281
-
282
-    /*
151
+	public function save_schedule()
152
+	{
153
+		global $wpdb;
154
+
155
+		$this->check_access();
156
+
157
+		$scheduler = $this->xcloner_scheduler;
158
+		$params = array();
159
+		$schedule = array();
160
+		$response = array();
161
+
162
+		if (isset($_POST['data'])) {
163
+			$params = json_decode(stripslashes($_POST['data']));
164
+		}
165
+
166
+		$this->process_params($params);
167
+
168
+		if (isset($_POST['id'])) {
169
+
170
+			$this->form_params['backup_params']['backup_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_name']);
171
+			$this->form_params['backup_params']['email_notification'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['email_notification']);
172
+			if ($_POST['diff_start_date']) {
173
+				$this->form_params['backup_params']['diff_start_date'] = strtotime($this->xcloner_sanitization->sanitize_input_as_string($_POST['diff_start_date']));
174
+			} else {
175
+				$this->form_params['backup_params']['diff_start_date'] = "";
176
+			}
177
+			$this->form_params['backup_params']['schedule_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_name']);
178
+			$this->form_params['backup_params']['start_at'] = strtotime($_POST['schedule_start_date']);
179
+			$this->form_params['backup_params']['schedule_frequency'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_frequency']);
180
+			$this->form_params['backup_params']['schedule_storage'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_storage']);
181
+			$this->form_params['database'] = (stripslashes($this->xcloner_sanitization->sanitize_input_as_raw($_POST['table_params'])));
182
+			$this->form_params['excluded_files'] = (stripslashes($this->xcloner_sanitization->sanitize_input_as_raw($_POST['excluded_files'])));
183
+
184
+			//$this->form_params['backup_params']['backup_type'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_type']);
185
+
186
+			$tables = explode(PHP_EOL, $this->form_params['database']);
187
+			$return = array();
188
+
189
+			foreach ($tables as $table) {
190
+				$table = str_replace("\r", "", $table);
191
+				$data = explode(".", $table);
192
+				if (isset($data[1])) {
193
+					$return[$data[0]][] = $data[1];
194
+				}
195
+			}
196
+
197
+			$this->form_params['database'] = ($return);
198
+
199
+			$excluded_files = explode(PHP_EOL, $this->form_params['excluded_files']);
200
+			$return = array();
201
+
202
+			foreach ($excluded_files as $file) {
203
+				$file = str_replace("\r", "", $file);
204
+				if ($file) {
205
+					$return[] = $file;
206
+				}
207
+			}
208
+
209
+			$this->form_params['excluded_files'] = ($return);
210
+
211
+			$schedule['start_at'] = $this->form_params['backup_params']['start_at'];
212
+
213
+			if (!isset($_POST['status'])) {
214
+				$schedule['status'] = 0;
215
+			} else {
216
+				$schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']);
217
+			}
218
+		} else {
219
+
220
+			$schedule['status'] = 1;
221
+			$schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] .
222
+				" " . $this->form_params['backup_params']['schedule_start_time']);
223
+
224
+			if ($schedule['start_at'] <= time()) {
225
+				$schedule['start_at'] = "";
226
+			}
227
+		}
228
+
229
+		if (!$schedule['start_at']) {
230
+			$schedule['start_at'] = date('Y-m-d H:i:s', time());
231
+		} else {
232
+			$schedule['start_at'] = date('Y-m-d H:i:s',
233
+				$schedule['start_at'] - (get_option('gmt_offset') * HOUR_IN_SECONDS));
234
+		}
235
+
236
+		$schedule['name'] = $this->form_params['backup_params']['schedule_name'];
237
+		$schedule['recurrence'] = $this->form_params['backup_params']['schedule_frequency'];
238
+		if (!isset($this->form_params['backup_params']['schedule_storage'])) {
239
+			$this->form_params['backup_params']['schedule_storage'] = "";
240
+		}
241
+		$schedule['remote_storage'] = $this->form_params['backup_params']['schedule_storage'];
242
+		//$schedule['backup_type'] = $this->form_params['backup_params']['backup_type'];
243
+		$schedule['params'] = json_encode($this->form_params);
244
+
245
+		if (!isset($_POST['id'])) {
246
+			$wpdb->insert(
247
+				$wpdb->prefix . 'xcloner_scheduler',
248
+				$schedule,
249
+				array(
250
+					'%s',
251
+					'%s'
252
+				)
253
+			);
254
+		} else {
255
+			$wpdb->update(
256
+				$wpdb->prefix . 'xcloner_scheduler',
257
+				$schedule,
258
+				array('id' => $_POST['id']),
259
+				array(
260
+					'%s',
261
+					'%s'
262
+				)
263
+			);
264
+		}
265
+		if (isset($_POST['id'])) {
266
+			$scheduler->update_cron_hook($_POST['id']);
267
+		}
268
+
269
+		if ($wpdb->last_error) {
270
+			$response['error'] = 1;
271
+			$response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/
272
+			;
273
+
274
+		}
275
+
276
+		$scheduler->update_wp_cron_hooks();
277
+		$response['finished'] = 1;
278
+
279
+		$this->send_response($response);
280
+	}
281
+
282
+	/*
283 283
      *
284 284
      * Backup Files API
285 285
      *
286 286
      */
287
-    public function backup_files()
288
-    {
289
-        $this->check_access();
290
-
291
-        $params = json_decode(stripslashes($_POST['data']));
292
-
293
-        $init = (int)$_POST['init'];
294
-
295
-        if ($params === null) {
296
-            die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
297
-        }
298
-
299
-        $this->process_params($params);
300
-
301
-        $return['finished'] = 1;
302
-
303
-        //$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init);
304
-        try {
305
-            $return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'],
306
-                $this->form_params['extra'], $init);
307
-        } catch (Exception $e) {
308
-            $return = array();
309
-            $return['error'] = true;
310
-            $return['status'] = 500;
311
-            $return['error_message'] = $e->getMessage();
312
-
313
-            return $this->send_response($return, $hash = 1);
314
-        }
315
-
316
-        if ($return['finished']) {
317
-            $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension();
318
-            if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) {
319
-                $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
320
-            }
321
-        }
322
-
323
-        $data = $return;
324
-
325
-        //check if backup is finished
326
-        if ($return['finished']) {
327
-            if (isset($this->form_params['backup_params']['email_notification']) and $to = $this->form_params['backup_params']['email_notification']) {
328
-                try {
329
-                    $from = "";
330
-                    $subject = "";
331
-                    $additional['lines_total'] = $return['extra']['lines_total'];
332
-                    $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'],
333
-                        $this->form_params, "", $additional);
334
-                } catch (Exception $e) {
335
-                    $this->logger->error($e->getMessage());
336
-                }
337
-            }
338
-            $this->xcloner_file_system->remove_tmp_filesystem();
339
-        }
340
-
341
-        return $this->send_response($data, $hash = 1);
342
-    }
343
-
344
-    /*
287
+	public function backup_files()
288
+	{
289
+		$this->check_access();
290
+
291
+		$params = json_decode(stripslashes($_POST['data']));
292
+
293
+		$init = (int)$_POST['init'];
294
+
295
+		if ($params === null) {
296
+			die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
297
+		}
298
+
299
+		$this->process_params($params);
300
+
301
+		$return['finished'] = 1;
302
+
303
+		//$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init);
304
+		try {
305
+			$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'],
306
+				$this->form_params['extra'], $init);
307
+		} catch (Exception $e) {
308
+			$return = array();
309
+			$return['error'] = true;
310
+			$return['status'] = 500;
311
+			$return['error_message'] = $e->getMessage();
312
+
313
+			return $this->send_response($return, $hash = 1);
314
+		}
315
+
316
+		if ($return['finished']) {
317
+			$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension();
318
+			if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) {
319
+				$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
320
+			}
321
+		}
322
+
323
+		$data = $return;
324
+
325
+		//check if backup is finished
326
+		if ($return['finished']) {
327
+			if (isset($this->form_params['backup_params']['email_notification']) and $to = $this->form_params['backup_params']['email_notification']) {
328
+				try {
329
+					$from = "";
330
+					$subject = "";
331
+					$additional['lines_total'] = $return['extra']['lines_total'];
332
+					$this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'],
333
+						$this->form_params, "", $additional);
334
+				} catch (Exception $e) {
335
+					$this->logger->error($e->getMessage());
336
+				}
337
+			}
338
+			$this->xcloner_file_system->remove_tmp_filesystem();
339
+		}
340
+
341
+		return $this->send_response($data, $hash = 1);
342
+	}
343
+
344
+	/*
345 345
      *
346 346
      * Backup Database API
347 347
      *
348 348
      */
349
-    public function backup_database()
350
-    {
351
-        $this->check_access();
349
+	public function backup_database()
350
+	{
351
+		$this->check_access();
352 352
 
353
-        $params = json_decode(stripslashes($_POST['data']));
353
+		$params = json_decode(stripslashes($_POST['data']));
354 354
 
355
-        $init = (int)$_POST['init'];
355
+		$init = (int)$_POST['init'];
356 356
 
357
-        if ($params === null) {
358
-            die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
359
-        }
357
+		if ($params === null) {
358
+			die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
359
+		}
360 360
 
361
-        $this->process_params($params);
361
+		$this->process_params($params);
362 362
 
363
-        //$xcloner_database = $this->init_db();
364
-        $return = $this->xcloner_database->start_database_recursion($this->form_params['database'],
365
-            $this->form_params['extra'], $init);
363
+		//$xcloner_database = $this->init_db();
364
+		$return = $this->xcloner_database->start_database_recursion($this->form_params['database'],
365
+			$this->form_params['extra'], $init);
366 366
 
367
-        if (isset($return['error']) and $return['error']) {
368
-            $data['finished'] = 1;
369
-        } else {
370
-            $data['finished'] = $return['finished'];
371
-        }
367
+		if (isset($return['error']) and $return['error']) {
368
+			$data['finished'] = 1;
369
+		} else {
370
+			$data['finished'] = $return['finished'];
371
+		}
372 372
 
373
-        $data['extra'] = $return;
373
+		$data['extra'] = $return;
374 374
 
375
-        return $this->send_response($data, $hash = 1);
376
-    }
375
+		return $this->send_response($data, $hash = 1);
376
+	}
377 377
 
378
-    /*
378
+	/*
379 379
      *
380 380
      * Scan Filesystem API
381 381
      *
382 382
      */
383
-    public function scan_filesystem()
384
-    {
385
-        $this->check_access();
383
+	public function scan_filesystem()
384
+	{
385
+		$this->check_access();
386 386
 
387
-        $params = json_decode(stripslashes($_POST['data']));
388
-        $init = (int)$_POST['init'];
387
+		$params = json_decode(stripslashes($_POST['data']));
388
+		$init = (int)$_POST['init'];
389 389
 
390
-        if ($params === null) {
391
-            die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
392
-        }
390
+		if ($params === null) {
391
+			die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
392
+		}
393 393
 
394
-        $hash = $this->process_params($params);
394
+		$hash = $this->process_params($params);
395 395
 
396
-        $this->xcloner_file_system->set_excluded_files($this->form_params['excluded_files']);
396
+		$this->xcloner_file_system->set_excluded_files($this->form_params['excluded_files']);
397 397
 
398
-        $return = $this->xcloner_file_system->start_file_recursion($init);
398
+		$return = $this->xcloner_file_system->start_file_recursion($init);
399 399
 
400
-        $data["finished"] = !$return;
401
-        $data["total_files_num"] = $this->xcloner_file_system->get_scanned_files_num();
402
-        $data["last_logged_file"] = $this->xcloner_file_system->last_logged_file();
403
-        $data["total_files_size"] = sprintf("%.2f",
404
-            $this->xcloner_file_system->get_scanned_files_total_size() / (1024 * 1024));
400
+		$data["finished"] = !$return;
401
+		$data["total_files_num"] = $this->xcloner_file_system->get_scanned_files_num();
402
+		$data["last_logged_file"] = $this->xcloner_file_system->last_logged_file();
403
+		$data["total_files_size"] = sprintf("%.2f",
404
+			$this->xcloner_file_system->get_scanned_files_total_size() / (1024 * 1024));
405 405
 
406
-        return $this->send_response($data, $hash = 1);
407
-    }
406
+		return $this->send_response($data, $hash = 1);
407
+	}
408 408
 
409
-    /*
409
+	/*
410 410
      *
411 411
      * Process params sent by the user
412 412
      *
413 413
      */
414
-    private function process_params($params)
415
-    {
416
-        if (isset($params->hash)) {
417
-            $this->xcloner_settings->set_hash($params->hash);
418
-        }
419
-
420
-        $this->form_params['extra'] = array();
421
-        $this->form_params['backup_params'] = array();
422
-
423
-        $this->form_params['database'] = array();
424
-
425
-        if (isset($params->backup_params)) {
426
-            foreach ($params->backup_params as $param) {
427
-                $this->form_params['backup_params'][$param->name] = $this->xcloner_sanitization->sanitize_input_as_string($param->value);
428
-                $this->logger->debug("Adding form parameter " . $param->name . "." . $param->value . "\n", array(
429
-                    'POST',
430
-                    'fields filter'
431
-                ));
432
-            }
433
-        }
434
-
435
-        $this->form_params['database'] = array();
436
-
437
-        if (isset($params->table_params)) {
438
-            foreach ($params->table_params as $param) {
439
-                $this->form_params['database'][$param->parent][] = $this->xcloner_sanitization->sanitize_input_as_raw($param->id);
440
-                $this->logger->debug("Adding database filter " . $param->parent . "." . $param->id . "\n", array(
441
-                    'POST',
442
-                    'database filter'
443
-                ));
444
-            }
445
-        }
446
-
447
-        $this->form_params['excluded_files'] = array();
448
-        if (isset($params->files_params)) {
449
-            foreach ($params->files_params as $param) {
450
-                $this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
451
-            }
452
-
453
-            $unique_exclude_files = array();
454
-
455
-            foreach ($params->files_params as $key => $param) {
456
-                if (!in_array($param->parent, $this->form_params['excluded_files'])) {
457
-                    //$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
458
-                    $unique_exclude_files[] = $param->id;
459
-                    $this->logger->debug("Adding file filter " . $param->id . "\n", array(
460
-                        'POST',
461
-                        'exclude files filter'
462
-                    ));
463
-                }
464
-            }
465
-            $this->form_params['excluded_files'] = (array)$unique_exclude_files;
466
-
467
-        }
468
-
469
-        //$this->form_params['excluded_files'] =  array_merge($this->form_params['excluded_files'], $this->exclude_files_by_default);
470
-
471
-        if (isset($params->extra)) {
472
-            foreach ($params->extra as $key => $value) {
473
-                $this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value);
474
-            }
475
-        }
476
-
477
-        if (isset($this->form_params['backup_params']['diff_start_date']) and $this->form_params['backup_params']['diff_start_date']) {
478
-            $this->form_params['backup_params']['diff_start_date'] = strtotime($this->form_params['backup_params']['diff_start_date']);
479
-            $this->xcloner_file_system->set_diff_timestamp_start($this->form_params['backup_params']['diff_start_date']);
480
-        }
481
-
482
-        return $this->xcloner_settings->get_hash();
483
-    }
484
-
485
-    /*
414
+	private function process_params($params)
415
+	{
416
+		if (isset($params->hash)) {
417
+			$this->xcloner_settings->set_hash($params->hash);
418
+		}
419
+
420
+		$this->form_params['extra'] = array();
421
+		$this->form_params['backup_params'] = array();
422
+
423
+		$this->form_params['database'] = array();
424
+
425
+		if (isset($params->backup_params)) {
426
+			foreach ($params->backup_params as $param) {
427
+				$this->form_params['backup_params'][$param->name] = $this->xcloner_sanitization->sanitize_input_as_string($param->value);
428
+				$this->logger->debug("Adding form parameter " . $param->name . "." . $param->value . "\n", array(
429
+					'POST',
430
+					'fields filter'
431
+				));
432
+			}
433
+		}
434
+
435
+		$this->form_params['database'] = array();
436
+
437
+		if (isset($params->table_params)) {
438
+			foreach ($params->table_params as $param) {
439
+				$this->form_params['database'][$param->parent][] = $this->xcloner_sanitization->sanitize_input_as_raw($param->id);
440
+				$this->logger->debug("Adding database filter " . $param->parent . "." . $param->id . "\n", array(
441
+					'POST',
442
+					'database filter'
443
+				));
444
+			}
445
+		}
446
+
447
+		$this->form_params['excluded_files'] = array();
448
+		if (isset($params->files_params)) {
449
+			foreach ($params->files_params as $param) {
450
+				$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
451
+			}
452
+
453
+			$unique_exclude_files = array();
454
+
455
+			foreach ($params->files_params as $key => $param) {
456
+				if (!in_array($param->parent, $this->form_params['excluded_files'])) {
457
+					//$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
458
+					$unique_exclude_files[] = $param->id;
459
+					$this->logger->debug("Adding file filter " . $param->id . "\n", array(
460
+						'POST',
461
+						'exclude files filter'
462
+					));
463
+				}
464
+			}
465
+			$this->form_params['excluded_files'] = (array)$unique_exclude_files;
466
+
467
+		}
468
+
469
+		//$this->form_params['excluded_files'] =  array_merge($this->form_params['excluded_files'], $this->exclude_files_by_default);
470
+
471
+		if (isset($params->extra)) {
472
+			foreach ($params->extra as $key => $value) {
473
+				$this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value);
474
+			}
475
+		}
476
+
477
+		if (isset($this->form_params['backup_params']['diff_start_date']) and $this->form_params['backup_params']['diff_start_date']) {
478
+			$this->form_params['backup_params']['diff_start_date'] = strtotime($this->form_params['backup_params']['diff_start_date']);
479
+			$this->xcloner_file_system->set_diff_timestamp_start($this->form_params['backup_params']['diff_start_date']);
480
+		}
481
+
482
+		return $this->xcloner_settings->get_hash();
483
+	}
484
+
485
+	/*
486 486
      *
487 487
      * Get file list for tree view API
488 488
      *
489 489
      */
490
-    public function get_file_system_action()
491
-    {
492
-        $this->check_access();
493
-
494
-        $folder = $this->xcloner_sanitization->sanitize_input_as_relative_path($_POST['id']);
495
-
496
-        $data = array();
497
-
498
-        if ($folder == "#") {
499
-
500
-            $folder = "/";
501
-            $data[] = array(
502
-                'id' => $folder,
503
-                'parent' => '#',
504
-                'text' => $this->xcloner_settings->get_xcloner_start_path(),
505
-                //'children' => true,
506
-                'state' => array('selected' => false, 'opened' => true),
507
-                'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-root.png"
508
-            );
509
-        }
510
-
511
-        try {
512
-            $files = $this->xcloner_file_system->list_directory($folder);
513
-        } catch (Exception $e) {
514
-
515
-            print $e->getMessage();
516
-            $this->logger->error($e->getMessage());
517
-
518
-            return;
519
-        }
520
-
521
-        $type = array();
522
-        foreach ($files as $key => $row) {
523
-            $type[$key] = $row['type'];
524
-        }
525
-        array_multisort($type, SORT_ASC, $files);
526
-
527
-        foreach ($files as $file) {
528
-            $children = false;
529
-            $text = $file['basename'];
530
-
531
-            if ($file['type'] == "dir") {
532
-                $children = true;
533
-            } else {
534
-                $text .= " (" . $this->xcloner_requirements->file_format_size($file['size']) . ")";
535
-            }
536
-
537
-            if ($this->xcloner_file_system->is_excluded($file)) {
538
-                $selected = true;
539
-            } else {
540
-                $selected = false;
541
-            }
542
-
543
-            $data[] = array(
544
-                'id' => $file['path'],
545
-                'parent' => $folder,
546
-                'text' => $text,
547
-                //'title' => "test",
548
-                'children' => $children,
549
-                'state' => array('selected' => $selected, 'opened' => false, "checkbox_disabled" => $selected),
550
-                'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-" . strtolower(substr($file['type'],
551
-                        0, 1)) . ".png"
552
-            );
553
-        }
554
-
555
-
556
-        return $this->send_response($data, 0);
557
-    }
558
-
559
-    /*
490
+	public function get_file_system_action()
491
+	{
492
+		$this->check_access();
493
+
494
+		$folder = $this->xcloner_sanitization->sanitize_input_as_relative_path($_POST['id']);
495
+
496
+		$data = array();
497
+
498
+		if ($folder == "#") {
499
+
500
+			$folder = "/";
501
+			$data[] = array(
502
+				'id' => $folder,
503
+				'parent' => '#',
504
+				'text' => $this->xcloner_settings->get_xcloner_start_path(),
505
+				//'children' => true,
506
+				'state' => array('selected' => false, 'opened' => true),
507
+				'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-root.png"
508
+			);
509
+		}
510
+
511
+		try {
512
+			$files = $this->xcloner_file_system->list_directory($folder);
513
+		} catch (Exception $e) {
514
+
515
+			print $e->getMessage();
516
+			$this->logger->error($e->getMessage());
517
+
518
+			return;
519
+		}
520
+
521
+		$type = array();
522
+		foreach ($files as $key => $row) {
523
+			$type[$key] = $row['type'];
524
+		}
525
+		array_multisort($type, SORT_ASC, $files);
526
+
527
+		foreach ($files as $file) {
528
+			$children = false;
529
+			$text = $file['basename'];
530
+
531
+			if ($file['type'] == "dir") {
532
+				$children = true;
533
+			} else {
534
+				$text .= " (" . $this->xcloner_requirements->file_format_size($file['size']) . ")";
535
+			}
536
+
537
+			if ($this->xcloner_file_system->is_excluded($file)) {
538
+				$selected = true;
539
+			} else {
540
+				$selected = false;
541
+			}
542
+
543
+			$data[] = array(
544
+				'id' => $file['path'],
545
+				'parent' => $folder,
546
+				'text' => $text,
547
+				//'title' => "test",
548
+				'children' => $children,
549
+				'state' => array('selected' => $selected, 'opened' => false, "checkbox_disabled" => $selected),
550
+				'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-" . strtolower(substr($file['type'],
551
+						0, 1)) . ".png"
552
+			);
553
+		}
554
+
555
+
556
+		return $this->send_response($data, 0);
557
+	}
558
+
559
+	/*
560 560
      *
561 561
      * Get databases/tables list for frontend tree display API
562 562
      *
563 563
      */
564
-    public function get_database_tables_action()
565
-    {
566
-        $this->check_access();
567
-
568
-        $database = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['id']);
569
-
570
-        $data = array();
571
-
572
-        $xcloner_backup_only_wp_tables = $this->xcloner_settings->get_xcloner_option('xcloner_backup_only_wp_tables');
573
-
574
-        if ($database == "#") {
575
-            try {
576
-                $return = $this->xcloner_database->get_all_databases();
577
-            } catch (Exception $e) {
578
-                $this->logger->error($e->getMessage());
579
-            }
580
-
581
-            foreach ($return as $database) {
582
-                if ($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) {
583
-                    continue;
584
-                }
585
-
586
-                $state = array();
587
-
588
-                if ($database['name'] == $this->xcloner_settings->get_db_database()) {
589
-                    $state['selected'] = true;
590
-                    if ($database['num_tables'] < 25) {
591
-                        $state['opened'] = false;
592
-                    }
593
-                }
594
-
595
-                $data[] = array(
596
-                    'id' => $database['name'],
597
-                    'parent' => '#',
598
-                    'text' => $database['name'] . " (" . (int)$database['num_tables'] . ")",
599
-                    'children' => true,
600
-                    'state' => $state,
601
-                    'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/database-icon.png"
602
-                );
603
-            }
604
-
605
-        } else {
606
-
607
-            try {
608
-                $return = $this->xcloner_database->list_tables($database, "", 1);
609
-            } catch (Exception $e) {
610
-                $this->logger->error($e->getMessage());
611
-            }
612
-
613
-            foreach ($return as $table) {
614
-                $state = array();
615
-
616
-                if ($xcloner_backup_only_wp_tables and !stristr($table['name'],
617
-                        $this->xcloner_settings->get_table_prefix())) {
618
-                    continue;
619
-                }
620
-
621
-                if (isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) {
622
-                    $state = array('selected' => true);
623
-                }
624
-
625
-                $data[] = array(
626
-                    'id' => $database . "." . $table['name'],
627
-                    'parent' => $database,
628
-                    'text' => $table['name'] . " (" . (int)$table['records'] . ")",
629
-                    'children' => false,
630
-                    'state' => $state,
631
-                    'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/table-icon.png"
632
-                );
633
-            }
634
-        }
635
-
636
-        return $this->send_response($data, 0);
637
-    }
638
-
639
-    /*
564
+	public function get_database_tables_action()
565
+	{
566
+		$this->check_access();
567
+
568
+		$database = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['id']);
569
+
570
+		$data = array();
571
+
572
+		$xcloner_backup_only_wp_tables = $this->xcloner_settings->get_xcloner_option('xcloner_backup_only_wp_tables');
573
+
574
+		if ($database == "#") {
575
+			try {
576
+				$return = $this->xcloner_database->get_all_databases();
577
+			} catch (Exception $e) {
578
+				$this->logger->error($e->getMessage());
579
+			}
580
+
581
+			foreach ($return as $database) {
582
+				if ($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) {
583
+					continue;
584
+				}
585
+
586
+				$state = array();
587
+
588
+				if ($database['name'] == $this->xcloner_settings->get_db_database()) {
589
+					$state['selected'] = true;
590
+					if ($database['num_tables'] < 25) {
591
+						$state['opened'] = false;
592
+					}
593
+				}
594
+
595
+				$data[] = array(
596
+					'id' => $database['name'],
597
+					'parent' => '#',
598
+					'text' => $database['name'] . " (" . (int)$database['num_tables'] . ")",
599
+					'children' => true,
600
+					'state' => $state,
601
+					'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/database-icon.png"
602
+				);
603
+			}
604
+
605
+		} else {
606
+
607
+			try {
608
+				$return = $this->xcloner_database->list_tables($database, "", 1);
609
+			} catch (Exception $e) {
610
+				$this->logger->error($e->getMessage());
611
+			}
612
+
613
+			foreach ($return as $table) {
614
+				$state = array();
615
+
616
+				if ($xcloner_backup_only_wp_tables and !stristr($table['name'],
617
+						$this->xcloner_settings->get_table_prefix())) {
618
+					continue;
619
+				}
620
+
621
+				if (isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) {
622
+					$state = array('selected' => true);
623
+				}
624
+
625
+				$data[] = array(
626
+					'id' => $database . "." . $table['name'],
627
+					'parent' => $database,
628
+					'text' => $table['name'] . " (" . (int)$table['records'] . ")",
629
+					'children' => false,
630
+					'state' => $state,
631
+					'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/table-icon.png"
632
+				);
633
+			}
634
+		}
635
+
636
+		return $this->send_response($data, 0);
637
+	}
638
+
639
+	/*
640 640
      *
641 641
      * Get schedule by id API
642 642
      *
643 643
      */
644
-    public function get_schedule_by_id()
645
-    {
646
-        $this->check_access();
644
+	public function get_schedule_by_id()
645
+	{
646
+		$this->check_access();
647 647
 
648
-        $schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']);
649
-        $scheduler = $this->xcloner_scheduler;
650
-        $data = $scheduler->get_schedule_by_id($schedule_id);
648
+		$schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']);
649
+		$scheduler = $this->xcloner_scheduler;
650
+		$data = $scheduler->get_schedule_by_id($schedule_id);
651 651
 
652
-        $data['start_at'] = date("Y-m-d H:i",
653
-            strtotime($data['start_at']) + (get_option('gmt_offset') * HOUR_IN_SECONDS));
654
-        if (isset($data['backup_params']->diff_start_date) && $data['backup_params']->diff_start_date != "") {
655
-            $data['backup_params']->diff_start_date = date("Y-m-d", ($data['backup_params']->diff_start_date));
656
-        }
652
+		$data['start_at'] = date("Y-m-d H:i",
653
+			strtotime($data['start_at']) + (get_option('gmt_offset') * HOUR_IN_SECONDS));
654
+		if (isset($data['backup_params']->diff_start_date) && $data['backup_params']->diff_start_date != "") {
655
+			$data['backup_params']->diff_start_date = date("Y-m-d", ($data['backup_params']->diff_start_date));
656
+		}
657 657
 
658
-        return $this->send_response($data);
659
-    }
658
+		return $this->send_response($data);
659
+	}
660 660
 
661
-    /*
661
+	/*
662 662
      *
663 663
      * Get Schedule list API
664 664
      *
665 665
      */
666
-    public function get_scheduler_list()
667
-    {
668
-        $this->check_access();
666
+	public function get_scheduler_list()
667
+	{
668
+		$this->check_access();
669 669
 
670
-        $scheduler = $this->xcloner_scheduler;
671
-        $data = $scheduler->get_scheduler_list();
672
-        $return['data'] = array();
670
+		$scheduler = $this->xcloner_scheduler;
671
+		$data = $scheduler->get_scheduler_list();
672
+		$return['data'] = array();
673 673
 
674
-        foreach ($data as $res) {
675
-            $action = "<a href=\"#" . $res->id . "\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a>
674
+		foreach ($data as $res) {
675
+			$action = "<a href=\"#" . $res->id . "\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a>
676 676
 					<a href=\"#" . $res->id . "\" class=\"delete\" title='Delete'><i class=\"material-icons  \">delete</i></a>";
677
-            if ($res->status) {
678
-                $status = '<i class="material-icons active status">timer</i>';
679
-            } else {
680
-                $status = '<i class="material-icons status inactive">timer_off</i>';
681
-            }
682
-
683
-            $next_run_time = wp_next_scheduled('xcloner_scheduler_' . $res->id, array($res->id));
684
-
685
-            $next_run = date(get_option('date_format') . " " . get_option('time_format'), $next_run_time);
686
-
687
-            $remote_storage = $res->remote_storage;
688
-
689
-            if (!$next_run_time >= time()) {
690
-                $next_run = " ";
691
-            }
692
-
693
-            if (trim($next_run)) {
694
-                $date_text = date(get_option('date_format') . " " . get_option('time_format'),
695
-                    $next_run_time + (get_option('gmt_offset') * HOUR_IN_SECONDS));
696
-
697
-                if ($next_run_time >= time()) {
698
-                    $next_run = "in " . human_time_diff($next_run_time, time());
699
-                } else {
700
-                    $next_run = __("executed", 'xcloner-backup-and-restore');
701
-                }
702
-
703
-                $next_run = "<a href='#' title='" . $date_text . "'>" . $next_run . "</a>";
704
-                //$next_run .=" ($date_text)";
705
-            }
706
-
707
-            $backup_text = "";
708
-            $backup_size = "";
709
-            $backup_time = "";
710
-
711
-            if ($res->last_backup) {
712
-                if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) {
713
-                    $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup);
714
-                    $backup_size = size_format($this->xcloner_file_system->get_backup_size($res->last_backup));
715
-                    $backup_time = date(get_option('date_format') . " " . get_option('time_format'),
716
-                        $metadata['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS));
717
-                }
718
-
719
-                $backup_text = "<span title='" . $backup_time . "' class='shorten_string'>" . $res->last_backup . " (" . $backup_size . ")</span>";
720
-            }
721
-
722
-            $schedules = wp_get_schedules();
723
-
724
-            if (isset($schedules[$res->recurrence])) {
725
-                $res->recurrence = $schedules[$res->recurrence]['display'];
726
-            }
727
-
728
-            $return['data'][] = array(
729
-                $res->id,
730
-                $res->name,
731
-                $res->recurrence,/*$res->start_at,*/
732
-                $next_run,
733
-                $remote_storage,
734
-                $backup_text,
735
-                $status,
736
-                $action
737
-            );
738
-        }
739
-
740
-        return $this->send_response($return, 0);
741
-    }
742
-
743
-    /*
677
+			if ($res->status) {
678
+				$status = '<i class="material-icons active status">timer</i>';
679
+			} else {
680
+				$status = '<i class="material-icons status inactive">timer_off</i>';
681
+			}
682
+
683
+			$next_run_time = wp_next_scheduled('xcloner_scheduler_' . $res->id, array($res->id));
684
+
685
+			$next_run = date(get_option('date_format') . " " . get_option('time_format'), $next_run_time);
686
+
687
+			$remote_storage = $res->remote_storage;
688
+
689
+			if (!$next_run_time >= time()) {
690
+				$next_run = " ";
691
+			}
692
+
693
+			if (trim($next_run)) {
694
+				$date_text = date(get_option('date_format') . " " . get_option('time_format'),
695
+					$next_run_time + (get_option('gmt_offset') * HOUR_IN_SECONDS));
696
+
697
+				if ($next_run_time >= time()) {
698
+					$next_run = "in " . human_time_diff($next_run_time, time());
699
+				} else {
700
+					$next_run = __("executed", 'xcloner-backup-and-restore');
701
+				}
702
+
703
+				$next_run = "<a href='#' title='" . $date_text . "'>" . $next_run . "</a>";
704
+				//$next_run .=" ($date_text)";
705
+			}
706
+
707
+			$backup_text = "";
708
+			$backup_size = "";
709
+			$backup_time = "";
710
+
711
+			if ($res->last_backup) {
712
+				if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) {
713
+					$metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup);
714
+					$backup_size = size_format($this->xcloner_file_system->get_backup_size($res->last_backup));
715
+					$backup_time = date(get_option('date_format') . " " . get_option('time_format'),
716
+						$metadata['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS));
717
+				}
718
+
719
+				$backup_text = "<span title='" . $backup_time . "' class='shorten_string'>" . $res->last_backup . " (" . $backup_size . ")</span>";
720
+			}
721
+
722
+			$schedules = wp_get_schedules();
723
+
724
+			if (isset($schedules[$res->recurrence])) {
725
+				$res->recurrence = $schedules[$res->recurrence]['display'];
726
+			}
727
+
728
+			$return['data'][] = array(
729
+				$res->id,
730
+				$res->name,
731
+				$res->recurrence,/*$res->start_at,*/
732
+				$next_run,
733
+				$remote_storage,
734
+				$backup_text,
735
+				$status,
736
+				$action
737
+			);
738
+		}
739
+
740
+		return $this->send_response($return, 0);
741
+	}
742
+
743
+	/*
744 744
      *
745 745
      * Delete Schedule by ID API
746 746
      *
747 747
      */
748
-    public function delete_schedule_by_id()
749
-    {
750
-        $this->check_access();
748
+	public function delete_schedule_by_id()
749
+	{
750
+		$this->check_access();
751 751
 
752
-        $schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']);
753
-        $scheduler = $this->xcloner_scheduler;
754
-        $data['finished'] = $scheduler->delete_schedule_by_id($schedule_id);
752
+		$schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']);
753
+		$scheduler = $this->xcloner_scheduler;
754
+		$data['finished'] = $scheduler->delete_schedule_by_id($schedule_id);
755 755
 
756
-        return $this->send_response($data);
757
-    }
756
+		return $this->send_response($data);
757
+	}
758 758
 
759
-    /*
759
+	/*
760 760
      *
761 761
      * Delete backup by name from the storage path
762 762
      *
763 763
      */
764
-    public function delete_backup_by_name()
765
-    {
766
-        $this->check_access();
764
+	public function delete_backup_by_name()
765
+	{
766
+		$this->check_access();
767 767
 
768
-        $backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_POST['name']);
769
-        $storage_selection = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_selection']);
768
+		$backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_POST['name']);
769
+		$storage_selection = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_selection']);
770 770
 
771
-        $data['finished'] = $this->xcloner_file_system->delete_backup_by_name($backup_name, $storage_selection);
771
+		$data['finished'] = $this->xcloner_file_system->delete_backup_by_name($backup_name, $storage_selection);
772 772
 
773
-        return $this->send_response($data);
774
-    }
773
+		return $this->send_response($data);
774
+	}
775 775
 
776
-    public function list_backup_files()
777
-    {
778
-        $this->check_access();
776
+	public function list_backup_files()
777
+	{
778
+		$this->check_access();
779 779
 
780
-        $backup_parts = array();
780
+		$backup_parts = array();
781 781
 
782
-        $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
783
-        $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']);
784
-        $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
782
+		$source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
783
+		$start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']);
784
+		$return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
785 785
 
786
-        $backup_file = $source_backup_file;
786
+		$backup_file = $source_backup_file;
787 787
 
788
-        if ($this->xcloner_file_system->is_multipart($backup_file)) {
789
-            $backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file);
790
-            $backup_file = $backup_parts[$return['part']];
791
-        }
788
+		if ($this->xcloner_file_system->is_multipart($backup_file)) {
789
+			$backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file);
790
+			$backup_file = $backup_parts[$return['part']];
791
+		}
792 792
 
793
-        try {
794
-            $tar = new Tar();
795
-            $tar->open($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file, $start);
793
+		try {
794
+			$tar = new Tar();
795
+			$tar->open($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file, $start);
796 796
 
797
-            $data = $tar->contents(get_option('xcloner_files_to_process_per_request'));
798
-        } catch (Exception $e) {
799
-            $return['error'] = true;
800
-            $return['message'] = $e->getMessage();
801
-            $this->send_response($return, 0);
802
-        }
797
+			$data = $tar->contents(get_option('xcloner_files_to_process_per_request'));
798
+		} catch (Exception $e) {
799
+			$return['error'] = true;
800
+			$return['message'] = $e->getMessage();
801
+			$this->send_response($return, 0);
802
+		}
803 803
 
804
-        $return['files'] = array();
805
-        $return['finished'] = 1;
806
-        $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file);
807
-        $i = 0;
804
+		$return['files'] = array();
805
+		$return['finished'] = 1;
806
+		$return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file);
807
+		$i = 0;
808 808
 
809
-        if (isset($data['extracted_files']) and is_array($data['extracted_files'])) {
810
-            foreach ($data['extracted_files'] as $file) {
811
-                $return['files'][$i]['path'] = $file->getPath();
812
-                $return['files'][$i]['size'] = $file->getSize();
813
-                $return['files'][$i]['mtime'] = date(get_option('date_format') . " " . get_option('time_format'),
814
-                    $file->getMtime());
809
+		if (isset($data['extracted_files']) and is_array($data['extracted_files'])) {
810
+			foreach ($data['extracted_files'] as $file) {
811
+				$return['files'][$i]['path'] = $file->getPath();
812
+				$return['files'][$i]['size'] = $file->getSize();
813
+				$return['files'][$i]['mtime'] = date(get_option('date_format') . " " . get_option('time_format'),
814
+					$file->getMtime());
815 815
 
816
-                $i++;
817
-            }
818
-        }
816
+				$i++;
817
+			}
818
+		}
819 819
 
820
-        if (isset($data['start'])) {
821
-            $return['start'] = $data['start'];
822
-            $return['finished'] = 0;
823
-        } else {
824
-            if ($this->xcloner_file_system->is_multipart($source_backup_file)) {
825
-                $return['start'] = 0;
820
+		if (isset($data['start'])) {
821
+			$return['start'] = $data['start'];
822
+			$return['finished'] = 0;
823
+		} else {
824
+			if ($this->xcloner_file_system->is_multipart($source_backup_file)) {
825
+				$return['start'] = 0;
826 826
 
827
-                ++$return['part'];
827
+				++$return['part'];
828 828
 
829
-                if ($return['part'] < sizeof($backup_parts)) {
830
-                    $return['finished'] = 0;
831
-                }
829
+				if ($return['part'] < sizeof($backup_parts)) {
830
+					$return['finished'] = 0;
831
+				}
832 832
 
833
-            }
834
-        }
833
+			}
834
+		}
835 835
 
836
-        $this->send_response($return, 0);
837
-    }
836
+		$this->send_response($return, 0);
837
+	}
838 838
 
839
-    /*
839
+	/*
840 840
      * Copy remote backup to local storage
841 841
      */
842
-    public function copy_backup_remote_to_local()
843
-    {
842
+	public function copy_backup_remote_to_local()
843
+	{
844 844
 
845
-        $this->check_access();
845
+		$this->check_access();
846 846
 
847
-        $backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
848
-        $storage_type = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_type']);
847
+		$backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
848
+		$storage_type = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_type']);
849 849
 
850
-        $xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
850
+		$xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
851 851
 
852
-        $return = array();
852
+		$return = array();
853 853
 
854
-        try {
855
-            if (method_exists($xcloner_remote_storage, "copy_backup_remote_to_local")) {
856
-                $return = call_user_func_array(array(
857
-                    $xcloner_remote_storage,
858
-                    "copy_backup_remote_to_local"
859
-                ), array($backup_file, $storage_type));
860
-            }
861
-        } catch (Exception $e) {
854
+		try {
855
+			if (method_exists($xcloner_remote_storage, "copy_backup_remote_to_local")) {
856
+				$return = call_user_func_array(array(
857
+					$xcloner_remote_storage,
858
+					"copy_backup_remote_to_local"
859
+				), array($backup_file, $storage_type));
860
+			}
861
+		} catch (Exception $e) {
862 862
 
863
-            $return['error'] = 1;
864
-            $return['message'] = $e->getMessage();
865
-        }
863
+			$return['error'] = 1;
864
+			$return['message'] = $e->getMessage();
865
+		}
866 866
 
867
-        if (!$return) {
868
-            $return['error'] = 1;
869
-            $return['message'] = "Upload failed, please check the error log for more information!";
870
-        }
867
+		if (!$return) {
868
+			$return['error'] = 1;
869
+			$return['message'] = "Upload failed, please check the error log for more information!";
870
+		}
871 871
 
872 872
 
873
-        $this->send_response($return, 0);
873
+		$this->send_response($return, 0);
874 874
 
875
-    }
875
+	}
876 876
 
877
-    /*
877
+	/*
878 878
      *
879 879
      * Upload backup to remote API
880 880
      *
881 881
      */
882
-    public function upload_backup_to_remote()
883
-    {
884
-        $this->check_access();
882
+	public function upload_backup_to_remote()
883
+	{
884
+		$this->check_access();
885 885
 
886
-        $backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
887
-        $storage_type = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_type']);
886
+		$backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
887
+		$storage_type = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_type']);
888 888
 
889
-        $xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
889
+		$xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
890 890
 
891
-        $return = array();
891
+		$return = array();
892 892
 
893
-        try {
894
-            if (method_exists($xcloner_remote_storage, "upload_backup_to_storage")) {
895
-                $return = call_user_func_array(array(
896
-                    $xcloner_remote_storage,
897
-                    "upload_backup_to_storage"
898
-                ), array($backup_file, $storage_type));
899
-            }
900
-        } catch (Exception $e) {
893
+		try {
894
+			if (method_exists($xcloner_remote_storage, "upload_backup_to_storage")) {
895
+				$return = call_user_func_array(array(
896
+					$xcloner_remote_storage,
897
+					"upload_backup_to_storage"
898
+				), array($backup_file, $storage_type));
899
+			}
900
+		} catch (Exception $e) {
901 901
 
902
-            $return['error'] = 1;
903
-            $return['message'] = $e->getMessage();
904
-        }
902
+			$return['error'] = 1;
903
+			$return['message'] = $e->getMessage();
904
+		}
905 905
 
906
-        if (!$return) {
907
-            $return['error'] = 1;
908
-            $return['message'] = "Upload failed, please check the error log for more information!";
909
-        }
906
+		if (!$return) {
907
+			$return['error'] = 1;
908
+			$return['message'] = "Upload failed, please check the error log for more information!";
909
+		}
910 910
 
911 911
 
912
-        $this->send_response($return, 0);
912
+		$this->send_response($return, 0);
913 913
 
914
-    }
914
+	}
915 915
 
916
-    /*
916
+	/*
917 917
      *
918 918
      * Remote Storage Status Save
919 919
      *
920 920
      */
921
-    public function remote_storage_save_status()
922
-    {
923
-        $this->check_access();
921
+	public function remote_storage_save_status()
922
+	{
923
+		$this->check_access();
924 924
 
925
-        $xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
925
+		$xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
926 926
 
927
-        $return['finished'] = $xcloner_remote_storage->change_storage_status($_POST['id'], $_POST['value']);
927
+		$return['finished'] = $xcloner_remote_storage->change_storage_status($_POST['id'], $_POST['value']);
928 928
 
929
-        $this->send_response($return, 0);
930
-    }
929
+		$this->send_response($return, 0);
930
+	}
931 931
 
932 932
 
933
-    public function download_restore_script()
934
-    {
935
-        $this->check_access();
933
+	public function download_restore_script()
934
+	{
935
+		$this->check_access();
936 936
 
937
-        @ob_end_clean();
937
+		@ob_end_clean();
938 938
 
939
-        $adapter = new Local(dirname(__DIR__), LOCK_EX, 'SKIP_LINKS');
940
-        $xcloner_plugin_filesystem = new Filesystem($adapter, new Config([
941
-            'disable_asserts' => true,
942
-        ]));
939
+		$adapter = new Local(dirname(__DIR__), LOCK_EX, 'SKIP_LINKS');
940
+		$xcloner_plugin_filesystem = new Filesystem($adapter, new Config([
941
+			'disable_asserts' => true,
942
+		]));
943 943
 
944
-        /* Generate PHAR FILE
944
+		/* Generate PHAR FILE
945 945
         $file = 'restore/vendor.built';
946 946
 
947 947
         if(file_exists($file))
@@ -957,178 +957,178 @@  discard block
 block discarded – undo
957 957
         $phar2->setStub($phar2->createDefaultStub('vendor/autoload.php', 'vendor/autoload.php'));
958 958
          * */
959 959
 
960
-        $tmp_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "xcloner-restore.tgz";
960
+		$tmp_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "xcloner-restore.tgz";
961 961
 
962
-        $tar = new Tar();
963
-        $tar->create($tmp_file);
962
+		$tar = new Tar();
963
+		$tar->create($tmp_file);
964 964
 
965
-        $tar->addFile(dirname(__DIR__) . "/restore/vendor.build.txt", "vendor.phar");
966
-        //$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz");
965
+		$tar->addFile(dirname(__DIR__) . "/restore/vendor.build.txt", "vendor.phar");
966
+		//$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz");
967 967
 
968
-        $files = $xcloner_plugin_filesystem->listContents("vendor/", true);
969
-        foreach ($files as $file) {
970
-            $tar->addFile(dirname(__DIR__) . DS . $file['path'], $file['path']);
971
-        }
968
+		$files = $xcloner_plugin_filesystem->listContents("vendor/", true);
969
+		foreach ($files as $file) {
970
+			$tar->addFile(dirname(__DIR__) . DS . $file['path'], $file['path']);
971
+		}
972 972
 
973
-        $content = file_get_contents(dirname(__DIR__) . "/restore/xcloner_restore.php");
974
-        $content = str_replace("define('AUTH_KEY', '');", "define('AUTH_KEY', '" . md5(AUTH_KEY) . "');", $content);
973
+		$content = file_get_contents(dirname(__DIR__) . "/restore/xcloner_restore.php");
974
+		$content = str_replace("define('AUTH_KEY', '');", "define('AUTH_KEY', '" . md5(AUTH_KEY) . "');", $content);
975 975
 
976
-        $tar->addData("xcloner_restore.php", $content);
976
+		$tar->addData("xcloner_restore.php", $content);
977 977
 
978
-        $tar->close();
978
+		$tar->close();
979 979
 
980
-        if (file_exists($tmp_file)) {
981
-            header('Content-Description: File Transfer');
982
-            header('Content-Type: application/octet-stream');
983
-            header('Content-Disposition: attachment; filename="' . basename($tmp_file) . '"');
984
-            header('Expires: 0');
985
-            header('Cache-Control: must-revalidate');
986
-            header('Pragma: public');
987
-            header('Content-Length: ' . filesize($tmp_file));
988
-            readfile($tmp_file);
980
+		if (file_exists($tmp_file)) {
981
+			header('Content-Description: File Transfer');
982
+			header('Content-Type: application/octet-stream');
983
+			header('Content-Disposition: attachment; filename="' . basename($tmp_file) . '"');
984
+			header('Expires: 0');
985
+			header('Cache-Control: must-revalidate');
986
+			header('Pragma: public');
987
+			header('Content-Length: ' . filesize($tmp_file));
988
+			readfile($tmp_file);
989 989
 
990
-        }
990
+		}
991 991
 
992
-        @unlink($tmp_file);
993
-        exit;
994
-    }
992
+		@unlink($tmp_file);
993
+		exit;
994
+	}
995 995
 
996
-    /*
996
+	/*
997 997
      *
998 998
      * Download backup by Name from the Storage Path
999 999
      *
1000 1000
      */
1001
-    public function download_backup_by_name()
1002
-    {
1003
-        $this->check_access();
1001
+	public function download_backup_by_name()
1002
+	{
1003
+		$this->check_access();
1004 1004
 
1005
-        @ob_end_clean();
1005
+		@ob_end_clean();
1006 1006
 
1007
-        $backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_GET['name']);
1007
+		$backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_GET['name']);
1008 1008
 
1009 1009
 
1010
-        $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name);
1011
-        $read_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name);
1010
+		$metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name);
1011
+		$read_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name);
1012 1012
 
1013 1013
 
1014
-        header('Pragma: public');
1015
-        header('Expires: 0');
1016
-        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1017
-        header('Cache-Control: private', false);
1018
-        header('Content-Transfer-Encoding: binary');
1019
-        header('Content-Disposition: attachment; filename="' . $metadata['path'] . '";');
1020
-        header('Content-Type: application/octet-stream');
1021
-        header('Content-Length: ' . $metadata['size']);
1014
+		header('Pragma: public');
1015
+		header('Expires: 0');
1016
+		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1017
+		header('Cache-Control: private', false);
1018
+		header('Content-Transfer-Encoding: binary');
1019
+		header('Content-Disposition: attachment; filename="' . $metadata['path'] . '";');
1020
+		header('Content-Type: application/octet-stream');
1021
+		header('Content-Length: ' . $metadata['size']);
1022 1022
 
1023
-        @ob_end_clean();
1023
+		@ob_end_clean();
1024 1024
 
1025
-        $chunkSize = 1024 * 1024;
1026
-        while (!feof($read_stream)) {
1027
-            $buffer = fread($read_stream, $chunkSize);
1028
-            echo $buffer;
1029
-        }
1030
-        fclose($read_stream);
1031
-        exit;
1025
+		$chunkSize = 1024 * 1024;
1026
+		while (!feof($read_stream)) {
1027
+			$buffer = fread($read_stream, $chunkSize);
1028
+			echo $buffer;
1029
+		}
1030
+		fclose($read_stream);
1031
+		exit;
1032 1032
 
1033
-    }
1033
+	}
1034 1034
 
1035
-    /*
1035
+	/*
1036 1036
      * Restore upload backup
1037 1037
      */
1038
-    public function restore_upload_backup()
1039
-    {
1040
-        $this->check_access();
1038
+	public function restore_upload_backup()
1039
+	{
1040
+		$this->check_access();
1041 1041
 
1042
-        $return['part'] = 0;
1043
-        $return['total_parts'] = 0;
1044
-        $return['uploaded_size'] = 0;
1045
-        $is_multipart = 0;
1042
+		$return['part'] = 0;
1043
+		$return['total_parts'] = 0;
1044
+		$return['uploaded_size'] = 0;
1045
+		$is_multipart = 0;
1046 1046
 
1047
-        $file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
1048
-        $hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']);
1047
+		$file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
1048
+		$hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']);
1049 1049
 
1050
-        if (isset($_POST['part'])) {
1051
-            $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
1052
-        }
1050
+		if (isset($_POST['part'])) {
1051
+			$return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
1052
+		}
1053 1053
 
1054
-        if (isset($_POST['uploaded_size'])) {
1055
-            $return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']);
1056
-        }
1054
+		if (isset($_POST['uploaded_size'])) {
1055
+			$return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']);
1056
+		}
1057 1057
 
1058
-        $start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']);
1059
-        $target_url = $this->xcloner_sanitization->sanitize_input_as_string($_POST['target_url']);
1058
+		$start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']);
1059
+		$target_url = $this->xcloner_sanitization->sanitize_input_as_string($_POST['target_url']);
1060 1060
 
1061
-        $return['total_size'] = $this->xcloner_file_system->get_backup_size($file);
1061
+		$return['total_size'] = $this->xcloner_file_system->get_backup_size($file);
1062 1062
 
1063
-        if ($this->xcloner_file_system->is_multipart($file)) {
1064
-            $backup_parts = $this->xcloner_file_system->get_multipart_files($file);
1063
+		if ($this->xcloner_file_system->is_multipart($file)) {
1064
+			$backup_parts = $this->xcloner_file_system->get_multipart_files($file);
1065 1065
 
1066
-            $return['total_parts'] = sizeof($backup_parts) + 1;
1066
+			$return['total_parts'] = sizeof($backup_parts) + 1;
1067 1067
 
1068
-            if ($return['part'] and isset($backup_parts[$return['part'] - 1])) {
1069
-                $file = $backup_parts[$return['part'] - 1];
1070
-            }
1068
+			if ($return['part'] and isset($backup_parts[$return['part'] - 1])) {
1069
+				$file = $backup_parts[$return['part'] - 1];
1070
+			}
1071 1071
 
1072
-            $is_multipart = 1;
1073
-        }
1072
+			$is_multipart = 1;
1073
+		}
1074 1074
 
1075
-        try {
1075
+		try {
1076 1076
 
1077
-            $xcloner_file_transfer = $this->get_xcloner_container()->get_xcloner_file_transfer();
1078
-            $xcloner_file_transfer->set_target($target_url);
1079
-            $return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash);
1077
+			$xcloner_file_transfer = $this->get_xcloner_container()->get_xcloner_file_transfer();
1078
+			$xcloner_file_transfer->set_target($target_url);
1079
+			$return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash);
1080 1080
 
1081
-        } catch (Exception $e) {
1081
+		} catch (Exception $e) {
1082 1082
 
1083
-            $return = array();
1084
-            $return['error'] = true;
1085
-            $return['status'] = 500;
1086
-            $return['message'] = "CURL communication error with the restore host. " . $e->getMessage();
1087
-            $this->send_response($return, 0);
1083
+			$return = array();
1084
+			$return['error'] = true;
1085
+			$return['status'] = 500;
1086
+			$return['message'] = "CURL communication error with the restore host. " . $e->getMessage();
1087
+			$this->send_response($return, 0);
1088 1088
 
1089
-        }
1089
+		}
1090 1090
 
1091
-        $return['status'] = 200;
1091
+		$return['status'] = 200;
1092 1092
 
1093
-        //we have finished the upload
1094
-        if (!$return['start'] and $is_multipart) {
1095
-            $return['part']++;
1096
-            $return['uploaded_size'] += $this->xcloner_file_system->get_storage_filesystem()->getSize($file);
1097
-        }
1093
+		//we have finished the upload
1094
+		if (!$return['start'] and $is_multipart) {
1095
+			$return['part']++;
1096
+			$return['uploaded_size'] += $this->xcloner_file_system->get_storage_filesystem()->getSize($file);
1097
+		}
1098 1098
 
1099
-        $this->send_response($return, 0);
1100
-    }
1099
+		$this->send_response($return, 0);
1100
+	}
1101 1101
 
1102
-    /*
1102
+	/*
1103 1103
      * Restore backup
1104 1104
      */
1105
-    public function restore_backup()
1106
-    {
1107
-        $this->check_access();
1105
+	public function restore_backup()
1106
+	{
1107
+		$this->check_access();
1108 1108
 
1109
-        define("XCLONER_PLUGIN_ACCESS", 1);
1110
-        include_once(dirname(__DIR__) . DS . "restore" . DS . "xcloner_restore.php");
1109
+		define("XCLONER_PLUGIN_ACCESS", 1);
1110
+		include_once(dirname(__DIR__) . DS . "restore" . DS . "xcloner_restore.php");
1111 1111
 
1112
-        return;
1113
-    }
1112
+		return;
1113
+	}
1114 1114
 
1115
-    /*
1115
+	/*
1116 1116
      *
1117 1117
      * Send the json response back
1118 1118
      *
1119 1119
      */
1120
-    private function send_response($data, $attach_hash = 1)
1121
-    {
1120
+	private function send_response($data, $attach_hash = 1)
1121
+	{
1122 1122
 
1123
-        if ($attach_hash and null !== $this->xcloner_settings->get_hash()) {
1124
-            $data['hash'] = $this->xcloner_settings->get_hash();
1125
-        }
1123
+		if ($attach_hash and null !== $this->xcloner_settings->get_hash()) {
1124
+			$data['hash'] = $this->xcloner_settings->get_hash();
1125
+		}
1126 1126
 
1127
-        if (ob_get_length()) {
1128
-            ob_clean();
1129
-        }
1130
-        wp_send_json($data);
1127
+		if (ob_get_length()) {
1128
+			ob_clean();
1129
+		}
1130
+		wp_send_json($data);
1131 1131
 
1132
-        die();
1133
-    }
1132
+		die();
1133
+	}
1134 1134
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
         $this->xcloner_scheduler = $xcloner_container->get_xcloner_scheduler();
86 86
 
87 87
         if (isset($_POST['API_ID'])) {
88
-            $this->logger->info("Processing ajax request ID " . substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']),
88
+            $this->logger->info("Processing ajax request ID ".substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']),
89 89
                     0, 15));
90 90
         }
91 91
 
@@ -127,13 +127,13 @@  discard block
 block discarded – undo
127 127
 
128 128
 
129 129
         $data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
130
-        $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . ".database";
131
-        $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "database-sql.sql";
130
+        $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS.".database";
131
+        $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS."database-sql.sql";
132 132
 
133 133
         try {
134 134
             $this->xcloner_database->init($data);
135 135
 
136
-        } catch (Exception $e) {
136
+        }catch (Exception $e) {
137 137
 
138 138
             $this->send_response($e->getMessage());
139 139
             $this->logger->error($e->getMessage());
@@ -218,8 +218,8 @@  discard block
 block discarded – undo
218 218
         } else {
219 219
 
220 220
             $schedule['status'] = 1;
221
-            $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] .
222
-                " " . $this->form_params['backup_params']['schedule_start_time']);
221
+            $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'].
222
+                " ".$this->form_params['backup_params']['schedule_start_time']);
223 223
 
224 224
             if ($schedule['start_at'] <= time()) {
225 225
                 $schedule['start_at'] = "";
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 
245 245
         if (!isset($_POST['id'])) {
246 246
             $wpdb->insert(
247
-                $wpdb->prefix . 'xcloner_scheduler',
247
+                $wpdb->prefix.'xcloner_scheduler',
248 248
                 $schedule,
249 249
                 array(
250 250
                     '%s',
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
             );
254 254
         } else {
255 255
             $wpdb->update(
256
-                $wpdb->prefix . 'xcloner_scheduler',
256
+                $wpdb->prefix.'xcloner_scheduler',
257 257
                 $schedule,
258 258
                 array('id' => $_POST['id']),
259 259
                 array(
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
         try {
305 305
             $return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'],
306 306
                 $this->form_params['extra'], $init);
307
-        } catch (Exception $e) {
307
+        }catch (Exception $e) {
308 308
             $return = array();
309 309
             $return['error'] = true;
310 310
             $return['status'] = 500;
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
                     $additional['lines_total'] = $return['extra']['lines_total'];
332 332
                     $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'],
333 333
                         $this->form_params, "", $additional);
334
-                } catch (Exception $e) {
334
+                }catch (Exception $e) {
335 335
                     $this->logger->error($e->getMessage());
336 336
                 }
337 337
             }
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
         if (isset($params->backup_params)) {
426 426
             foreach ($params->backup_params as $param) {
427 427
                 $this->form_params['backup_params'][$param->name] = $this->xcloner_sanitization->sanitize_input_as_string($param->value);
428
-                $this->logger->debug("Adding form parameter " . $param->name . "." . $param->value . "\n", array(
428
+                $this->logger->debug("Adding form parameter ".$param->name.".".$param->value."\n", array(
429 429
                     'POST',
430 430
                     'fields filter'
431 431
                 ));
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
         if (isset($params->table_params)) {
438 438
             foreach ($params->table_params as $param) {
439 439
                 $this->form_params['database'][$param->parent][] = $this->xcloner_sanitization->sanitize_input_as_raw($param->id);
440
-                $this->logger->debug("Adding database filter " . $param->parent . "." . $param->id . "\n", array(
440
+                $this->logger->debug("Adding database filter ".$param->parent.".".$param->id."\n", array(
441 441
                     'POST',
442 442
                     'database filter'
443 443
                 ));
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
                 if (!in_array($param->parent, $this->form_params['excluded_files'])) {
457 457
                     //$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
458 458
                     $unique_exclude_files[] = $param->id;
459
-                    $this->logger->debug("Adding file filter " . $param->id . "\n", array(
459
+                    $this->logger->debug("Adding file filter ".$param->id."\n", array(
460 460
                         'POST',
461 461
                         'exclude files filter'
462 462
                     ));
@@ -504,13 +504,13 @@  discard block
 block discarded – undo
504 504
                 'text' => $this->xcloner_settings->get_xcloner_start_path(),
505 505
                 //'children' => true,
506 506
                 'state' => array('selected' => false, 'opened' => true),
507
-                'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-root.png"
507
+                'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/file-icon-root.png"
508 508
             );
509 509
         }
510 510
 
511 511
         try {
512 512
             $files = $this->xcloner_file_system->list_directory($folder);
513
-        } catch (Exception $e) {
513
+        }catch (Exception $e) {
514 514
 
515 515
             print $e->getMessage();
516 516
             $this->logger->error($e->getMessage());
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
             if ($file['type'] == "dir") {
532 532
                 $children = true;
533 533
             } else {
534
-                $text .= " (" . $this->xcloner_requirements->file_format_size($file['size']) . ")";
534
+                $text .= " (".$this->xcloner_requirements->file_format_size($file['size']).")";
535 535
             }
536 536
 
537 537
             if ($this->xcloner_file_system->is_excluded($file)) {
@@ -547,8 +547,8 @@  discard block
 block discarded – undo
547 547
                 //'title' => "test",
548 548
                 'children' => $children,
549 549
                 'state' => array('selected' => $selected, 'opened' => false, "checkbox_disabled" => $selected),
550
-                'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-" . strtolower(substr($file['type'],
551
-                        0, 1)) . ".png"
550
+                'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/file-icon-".strtolower(substr($file['type'],
551
+                        0, 1)).".png"
552 552
             );
553 553
         }
554 554
 
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
         if ($database == "#") {
575 575
             try {
576 576
                 $return = $this->xcloner_database->get_all_databases();
577
-            } catch (Exception $e) {
577
+            }catch (Exception $e) {
578 578
                 $this->logger->error($e->getMessage());
579 579
             }
580 580
 
@@ -595,10 +595,10 @@  discard block
 block discarded – undo
595 595
                 $data[] = array(
596 596
                     'id' => $database['name'],
597 597
                     'parent' => '#',
598
-                    'text' => $database['name'] . " (" . (int)$database['num_tables'] . ")",
598
+                    'text' => $database['name']." (".(int)$database['num_tables'].")",
599 599
                     'children' => true,
600 600
                     'state' => $state,
601
-                    'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/database-icon.png"
601
+                    'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/database-icon.png"
602 602
                 );
603 603
             }
604 604
 
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 
607 607
             try {
608 608
                 $return = $this->xcloner_database->list_tables($database, "", 1);
609
-            } catch (Exception $e) {
609
+            }catch (Exception $e) {
610 610
                 $this->logger->error($e->getMessage());
611 611
             }
612 612
 
@@ -623,12 +623,12 @@  discard block
 block discarded – undo
623 623
                 }
624 624
 
625 625
                 $data[] = array(
626
-                    'id' => $database . "." . $table['name'],
626
+                    'id' => $database.".".$table['name'],
627 627
                     'parent' => $database,
628
-                    'text' => $table['name'] . " (" . (int)$table['records'] . ")",
628
+                    'text' => $table['name']." (".(int)$table['records'].")",
629 629
                     'children' => false,
630 630
                     'state' => $state,
631
-                    'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/table-icon.png"
631
+                    'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/table-icon.png"
632 632
                 );
633 633
             }
634 634
         }
@@ -672,17 +672,17 @@  discard block
 block discarded – undo
672 672
         $return['data'] = array();
673 673
 
674 674
         foreach ($data as $res) {
675
-            $action = "<a href=\"#" . $res->id . "\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a>
676
-					<a href=\"#" . $res->id . "\" class=\"delete\" title='Delete'><i class=\"material-icons  \">delete</i></a>";
675
+            $action = "<a href=\"#".$res->id."\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a>
676
+					<a href=\"#" . $res->id."\" class=\"delete\" title='Delete'><i class=\"material-icons  \">delete</i></a>";
677 677
             if ($res->status) {
678 678
                 $status = '<i class="material-icons active status">timer</i>';
679 679
             } else {
680 680
                 $status = '<i class="material-icons status inactive">timer_off</i>';
681 681
             }
682 682
 
683
-            $next_run_time = wp_next_scheduled('xcloner_scheduler_' . $res->id, array($res->id));
683
+            $next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id));
684 684
 
685
-            $next_run = date(get_option('date_format') . " " . get_option('time_format'), $next_run_time);
685
+            $next_run = date(get_option('date_format')." ".get_option('time_format'), $next_run_time);
686 686
 
687 687
             $remote_storage = $res->remote_storage;
688 688
 
@@ -691,16 +691,16 @@  discard block
 block discarded – undo
691 691
             }
692 692
 
693 693
             if (trim($next_run)) {
694
-                $date_text = date(get_option('date_format') . " " . get_option('time_format'),
694
+                $date_text = date(get_option('date_format')." ".get_option('time_format'),
695 695
                     $next_run_time + (get_option('gmt_offset') * HOUR_IN_SECONDS));
696 696
 
697 697
                 if ($next_run_time >= time()) {
698
-                    $next_run = "in " . human_time_diff($next_run_time, time());
698
+                    $next_run = "in ".human_time_diff($next_run_time, time());
699 699
                 } else {
700 700
                     $next_run = __("executed", 'xcloner-backup-and-restore');
701 701
                 }
702 702
 
703
-                $next_run = "<a href='#' title='" . $date_text . "'>" . $next_run . "</a>";
703
+                $next_run = "<a href='#' title='".$date_text."'>".$next_run."</a>";
704 704
                 //$next_run .=" ($date_text)";
705 705
             }
706 706
 
@@ -712,11 +712,11 @@  discard block
 block discarded – undo
712 712
                 if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) {
713 713
                     $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup);
714 714
                     $backup_size = size_format($this->xcloner_file_system->get_backup_size($res->last_backup));
715
-                    $backup_time = date(get_option('date_format') . " " . get_option('time_format'),
715
+                    $backup_time = date(get_option('date_format')." ".get_option('time_format'),
716 716
                         $metadata['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS));
717 717
                 }
718 718
 
719
-                $backup_text = "<span title='" . $backup_time . "' class='shorten_string'>" . $res->last_backup . " (" . $backup_size . ")</span>";
719
+                $backup_text = "<span title='".$backup_time."' class='shorten_string'>".$res->last_backup." (".$backup_size.")</span>";
720 720
             }
721 721
 
722 722
             $schedules = wp_get_schedules();
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
             $return['data'][] = array(
729 729
                 $res->id,
730 730
                 $res->name,
731
-                $res->recurrence,/*$res->start_at,*/
731
+                $res->recurrence, /*$res->start_at,*/
732 732
                 $next_run,
733 733
                 $remote_storage,
734 734
                 $backup_text,
@@ -792,10 +792,10 @@  discard block
 block discarded – undo
792 792
 
793 793
         try {
794 794
             $tar = new Tar();
795
-            $tar->open($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file, $start);
795
+            $tar->open($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file, $start);
796 796
 
797 797
             $data = $tar->contents(get_option('xcloner_files_to_process_per_request'));
798
-        } catch (Exception $e) {
798
+        }catch (Exception $e) {
799 799
             $return['error'] = true;
800 800
             $return['message'] = $e->getMessage();
801 801
             $this->send_response($return, 0);
@@ -803,14 +803,14 @@  discard block
 block discarded – undo
803 803
 
804 804
         $return['files'] = array();
805 805
         $return['finished'] = 1;
806
-        $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file);
806
+        $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file);
807 807
         $i = 0;
808 808
 
809 809
         if (isset($data['extracted_files']) and is_array($data['extracted_files'])) {
810 810
             foreach ($data['extracted_files'] as $file) {
811 811
                 $return['files'][$i]['path'] = $file->getPath();
812 812
                 $return['files'][$i]['size'] = $file->getSize();
813
-                $return['files'][$i]['mtime'] = date(get_option('date_format') . " " . get_option('time_format'),
813
+                $return['files'][$i]['mtime'] = date(get_option('date_format')." ".get_option('time_format'),
814 814
                     $file->getMtime());
815 815
 
816 816
                 $i++;
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
                     "copy_backup_remote_to_local"
859 859
                 ), array($backup_file, $storage_type));
860 860
             }
861
-        } catch (Exception $e) {
861
+        }catch (Exception $e) {
862 862
 
863 863
             $return['error'] = 1;
864 864
             $return['message'] = $e->getMessage();
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
                     "upload_backup_to_storage"
898 898
                 ), array($backup_file, $storage_type));
899 899
             }
900
-        } catch (Exception $e) {
900
+        }catch (Exception $e) {
901 901
 
902 902
             $return['error'] = 1;
903 903
             $return['message'] = $e->getMessage();
@@ -957,21 +957,21 @@  discard block
 block discarded – undo
957 957
         $phar2->setStub($phar2->createDefaultStub('vendor/autoload.php', 'vendor/autoload.php'));
958 958
          * */
959 959
 
960
-        $tmp_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "xcloner-restore.tgz";
960
+        $tmp_file = $this->xcloner_settings->get_xcloner_tmp_path().DS."xcloner-restore.tgz";
961 961
 
962 962
         $tar = new Tar();
963 963
         $tar->create($tmp_file);
964 964
 
965
-        $tar->addFile(dirname(__DIR__) . "/restore/vendor.build.txt", "vendor.phar");
965
+        $tar->addFile(dirname(__DIR__)."/restore/vendor.build.txt", "vendor.phar");
966 966
         //$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz");
967 967
 
968 968
         $files = $xcloner_plugin_filesystem->listContents("vendor/", true);
969 969
         foreach ($files as $file) {
970
-            $tar->addFile(dirname(__DIR__) . DS . $file['path'], $file['path']);
970
+            $tar->addFile(dirname(__DIR__).DS.$file['path'], $file['path']);
971 971
         }
972 972
 
973
-        $content = file_get_contents(dirname(__DIR__) . "/restore/xcloner_restore.php");
974
-        $content = str_replace("define('AUTH_KEY', '');", "define('AUTH_KEY', '" . md5(AUTH_KEY) . "');", $content);
973
+        $content = file_get_contents(dirname(__DIR__)."/restore/xcloner_restore.php");
974
+        $content = str_replace("define('AUTH_KEY', '');", "define('AUTH_KEY', '".md5(AUTH_KEY)."');", $content);
975 975
 
976 976
         $tar->addData("xcloner_restore.php", $content);
977 977
 
@@ -980,11 +980,11 @@  discard block
 block discarded – undo
980 980
         if (file_exists($tmp_file)) {
981 981
             header('Content-Description: File Transfer');
982 982
             header('Content-Type: application/octet-stream');
983
-            header('Content-Disposition: attachment; filename="' . basename($tmp_file) . '"');
983
+            header('Content-Disposition: attachment; filename="'.basename($tmp_file).'"');
984 984
             header('Expires: 0');
985 985
             header('Cache-Control: must-revalidate');
986 986
             header('Pragma: public');
987
-            header('Content-Length: ' . filesize($tmp_file));
987
+            header('Content-Length: '.filesize($tmp_file));
988 988
             readfile($tmp_file);
989 989
 
990 990
         }
@@ -1016,9 +1016,9 @@  discard block
 block discarded – undo
1016 1016
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1017 1017
         header('Cache-Control: private', false);
1018 1018
         header('Content-Transfer-Encoding: binary');
1019
-        header('Content-Disposition: attachment; filename="' . $metadata['path'] . '";');
1019
+        header('Content-Disposition: attachment; filename="'.$metadata['path'].'";');
1020 1020
         header('Content-Type: application/octet-stream');
1021
-        header('Content-Length: ' . $metadata['size']);
1021
+        header('Content-Length: '.$metadata['size']);
1022 1022
 
1023 1023
         @ob_end_clean();
1024 1024
 
@@ -1078,12 +1078,12 @@  discard block
 block discarded – undo
1078 1078
             $xcloner_file_transfer->set_target($target_url);
1079 1079
             $return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash);
1080 1080
 
1081
-        } catch (Exception $e) {
1081
+        }catch (Exception $e) {
1082 1082
 
1083 1083
             $return = array();
1084 1084
             $return['error'] = true;
1085 1085
             $return['status'] = 500;
1086
-            $return['message'] = "CURL communication error with the restore host. " . $e->getMessage();
1086
+            $return['message'] = "CURL communication error with the restore host. ".$e->getMessage();
1087 1087
             $this->send_response($return, 0);
1088 1088
 
1089 1089
         }
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
         $this->check_access();
1108 1108
 
1109 1109
         define("XCLONER_PLUGIN_ACCESS", 1);
1110
-        include_once(dirname(__DIR__) . DS . "restore" . DS . "xcloner_restore.php");
1110
+        include_once(dirname(__DIR__).DS."restore".DS."xcloner_restore.php");
1111 1111
 
1112 1112
         return;
1113 1113
     }
Please login to merge, or discard this patch.
includes/class-xcloner-archive.php 3 patches
Doc Comments   +21 added lines patch added patch discarded remove patch
@@ -213,6 +213,10 @@  discard block
 block discarded – undo
213 213
      *
214 214
      * @return bool
215 215
      */
216
+
217
+    /**
218
+     * @param string $error_message
219
+     */
216 220
     public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message)
217 221
     {
218 222
 
@@ -251,6 +255,11 @@  discard block
 block discarded – undo
251 255
      *
252 256
      * @return bool
253 257
      */
258
+
259
+    /**
260
+     * @param string $from
261
+     * @param string $subject
262
+     */
254 263
     public function send_notification(
255 264
         $to,
256 265
         $from,
@@ -339,6 +348,10 @@  discard block
 block discarded – undo
339 348
      * Incremental Backup method
340 349
      *
341 350
      */
351
+
352
+    /**
353
+     * @param integer $init
354
+     */
342 355
     public function start_incremental_backup($backup_params, $extra_params, $init)
343 356
     {
344 357
         $return = array();
@@ -576,6 +589,10 @@  discard block
 block discarded – undo
576 589
      * Write multipart file components
577 590
      *
578 591
      */
592
+
593
+    /**
594
+     * @param string $path
595
+     */
579 596
     private function write_multipart_file($path)
580 597
     {
581 598
         $path = $this->get_archive_name_with_extension();
@@ -636,6 +653,10 @@  discard block
 block discarded – undo
636 653
      * Add file to archive
637 654
      *
638 655
      */
656
+
657
+    /**
658
+     * @param integer $append
659
+     */
639 660
     public function add_file_to_archive($file_info, $start_at_byte, $byte_limit = 0, $append, $filesystem)
640 661
     {
641 662
 
Please login to merge, or discard this patch.
Indentation   +513 added lines, -513 removed lines patch added patch discarded remove patch
@@ -36,171 +36,171 @@  discard block
 block discarded – undo
36 36
  */
37 37
 class Xcloner_Archive extends Tar
38 38
 {
39
-    /**
40
-     * Process file size per API request
41
-     * @var float|int
42
-     */
43
-    private $file_size_per_request_limit = 52428800; //50MB = 52428800; 1MB = 1048576
44
-    /**
45
-     * Files count to process per API request
46
-     * @var int
47
-     */
48
-    private $files_to_process_per_request = 250; //block of 512 bytes
49
-    /**
50
-     * Compression level, 0-uncompressed, 9-maximum compression
51
-     * @var int
52
-     */
53
-    private $compression_level = 0; //0-9 , 0 uncompressed
54
-    /**
55
-     * Split backup size limit
56
-     * Create a new backup archive file once the set size is reached
57
-     * @var float|int
58
-     */
59
-    private $xcloner_split_backup_limit = 2048; //2048MB
60
-    /**
61
-     * Number of processed bytes
62
-     * @var int
63
-     */
64
-    private $processed_size_bytes = 0;
65
-
66
-    /**
67
-     * Archive name
68
-     * @var string
69
-     */
70
-    private $archive_name;
71
-    /**
72
-     * @var Tar
73
-     */
74
-    private $backup_archive;
75
-    /**
76
-     * @var Xcloner_File_System
77
-     */
78
-    private $filesystem;
79
-    /**
80
-     * @var Xcloner_Logger
81
-     */
82
-    private $logger;
83
-    /**
84
-     * @var Xcloner_Settings
85
-     */
86
-    private $xcloner_settings;
87
-
88
-    /**
89
-     * [__construct description]
90
-     * @param Xcloner $xcloner_container XCloner Container
91
-     * @param string $archive_name Achive Name
92
-     */
93
-    public function __construct(Xcloner $xcloner_container, $archive_name = "")
94
-    {
95
-        $this->filesystem = $xcloner_container->get_xcloner_filesystem();
96
-        $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_archive");
97
-        $this->xcloner_settings = $xcloner_container->get_xcloner_settings();
98
-
99
-        if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) {
100
-            $this->file_size_per_request_limit = $value * 1024 * 1024;
101
-        } //MB
102
-
103
-        if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) {
104
-            $this->files_to_process_per_request = $value;
105
-        }
39
+	/**
40
+	 * Process file size per API request
41
+	 * @var float|int
42
+	 */
43
+	private $file_size_per_request_limit = 52428800; //50MB = 52428800; 1MB = 1048576
44
+	/**
45
+	 * Files count to process per API request
46
+	 * @var int
47
+	 */
48
+	private $files_to_process_per_request = 250; //block of 512 bytes
49
+	/**
50
+	 * Compression level, 0-uncompressed, 9-maximum compression
51
+	 * @var int
52
+	 */
53
+	private $compression_level = 0; //0-9 , 0 uncompressed
54
+	/**
55
+	 * Split backup size limit
56
+	 * Create a new backup archive file once the set size is reached
57
+	 * @var float|int
58
+	 */
59
+	private $xcloner_split_backup_limit = 2048; //2048MB
60
+	/**
61
+	 * Number of processed bytes
62
+	 * @var int
63
+	 */
64
+	private $processed_size_bytes = 0;
65
+
66
+	/**
67
+	 * Archive name
68
+	 * @var string
69
+	 */
70
+	private $archive_name;
71
+	/**
72
+	 * @var Tar
73
+	 */
74
+	private $backup_archive;
75
+	/**
76
+	 * @var Xcloner_File_System
77
+	 */
78
+	private $filesystem;
79
+	/**
80
+	 * @var Xcloner_Logger
81
+	 */
82
+	private $logger;
83
+	/**
84
+	 * @var Xcloner_Settings
85
+	 */
86
+	private $xcloner_settings;
87
+
88
+	/**
89
+	 * [__construct description]
90
+	 * @param Xcloner $xcloner_container XCloner Container
91
+	 * @param string $archive_name Achive Name
92
+	 */
93
+	public function __construct(Xcloner $xcloner_container, $archive_name = "")
94
+	{
95
+		$this->filesystem = $xcloner_container->get_xcloner_filesystem();
96
+		$this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_archive");
97
+		$this->xcloner_settings = $xcloner_container->get_xcloner_settings();
98
+
99
+		if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) {
100
+			$this->file_size_per_request_limit = $value * 1024 * 1024;
101
+		} //MB
102
+
103
+		if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) {
104
+			$this->files_to_process_per_request = $value;
105
+		}
106 106
 
107
-        if ($value = get_option('xcloner_backup_compression_level')) {
108
-            $this->compression_level = $value;
109
-        }
107
+		if ($value = get_option('xcloner_backup_compression_level')) {
108
+			$this->compression_level = $value;
109
+		}
110 110
 
111
-        if ($value = get_option('xcloner_split_backup_limit')) {
112
-            $this->xcloner_split_backup_limit = $value;
113
-        }
111
+		if ($value = get_option('xcloner_split_backup_limit')) {
112
+			$this->xcloner_split_backup_limit = $value;
113
+		}
114 114
 
115
-        $this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024 * 1024; //transform to bytes
115
+		$this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024 * 1024; //transform to bytes
116 116
 
117
-        if (isset($archive_name) && $archive_name) {
118
-            $this->set_archive_name($archive_name);
119
-        }
120
-    }
117
+		if (isset($archive_name) && $archive_name) {
118
+			$this->set_archive_name($archive_name);
119
+		}
120
+	}
121 121
 
122
-    /*
122
+	/*
123 123
      * Rename backup archive
124 124
      *
125 125
      * @param string $old_name
126 126
      * @param string $new_name
127 127
      *
128 128
      */
129
-    public function rename_archive($old_name, $new_name)
130
-    {
131
-        $this->logger->info(sprintf("Renaming backup archive %s to %s", $old_name, $new_name));
132
-        $storage_filesystem = $this->filesystem->get_storage_filesystem();
133
-        $storage_filesystem->rename($old_name, $new_name);
134
-    }
135
-
136
-    /*
129
+	public function rename_archive($old_name, $new_name)
130
+	{
131
+		$this->logger->info(sprintf("Renaming backup archive %s to %s", $old_name, $new_name));
132
+		$storage_filesystem = $this->filesystem->get_storage_filesystem();
133
+		$storage_filesystem->rename($old_name, $new_name);
134
+	}
135
+
136
+	/*
137 137
      *
138 138
      * Set the backup archive name
139 139
      *
140 140
      */
141
-    public function set_archive_name($name = "", $part = 0)
142
-    {
141
+	public function set_archive_name($name = "", $part = 0)
142
+	{
143 143
 
144
-        $this->archive_name = $this->filesystem->process_backup_name($name);
144
+		$this->archive_name = $this->filesystem->process_backup_name($name);
145 145
 
146
-        if ($diff_timestamp_start = $this->filesystem->get_diff_timestamp_start()) {
147
-            //$this->archive_name = $this->archive_name."-diff-".date("Y-m-d_H-i",$diff_timestamp_start);
148
-            $new_name = $this->archive_name;
146
+		if ($diff_timestamp_start = $this->filesystem->get_diff_timestamp_start()) {
147
+			//$this->archive_name = $this->archive_name."-diff-".date("Y-m-d_H-i",$diff_timestamp_start);
148
+			$new_name = $this->archive_name;
149 149
 
150
-            if (!stristr($new_name, "-diff")) {
151
-                $new_name = $this->archive_name . "-diff" . date("Y-m-d_H-i", $diff_timestamp_start);
152
-            }
150
+			if (!stristr($new_name, "-diff")) {
151
+				$new_name = $this->archive_name . "-diff" . date("Y-m-d_H-i", $diff_timestamp_start);
152
+			}
153 153
 
154
-            $this->archive_name = $new_name;
154
+			$this->archive_name = $new_name;
155 155
 
156
-        }
156
+		}
157 157
 
158
-        if (isset($part) and $part) {
159
-            $new_name = preg_replace('/-part(\d*)/', "-part" . $part, $this->archive_name);
160
-            if (!stristr($new_name, "-part")) {
161
-                $new_name = $this->archive_name . "-part" . $part;
162
-            }
158
+		if (isset($part) and $part) {
159
+			$new_name = preg_replace('/-part(\d*)/', "-part" . $part, $this->archive_name);
160
+			if (!stristr($new_name, "-part")) {
161
+				$new_name = $this->archive_name . "-part" . $part;
162
+			}
163 163
 
164
-            $this->archive_name = $new_name;
165
-        }
164
+			$this->archive_name = $new_name;
165
+		}
166 166
 
167
-        return $this;
168
-    }
167
+		return $this;
168
+	}
169 169
 
170
-    /*
170
+	/*
171 171
      *
172 172
      * Returns the backup archive name
173 173
      *
174 174
      * @return string archive name
175 175
      */
176
-    public function get_archive_name()
177
-    {
178
-        return $this->archive_name;
179
-    }
176
+	public function get_archive_name()
177
+	{
178
+		return $this->archive_name;
179
+	}
180 180
 
181
-    /*
181
+	/*
182 182
      *
183 183
      * Returns the multipart naming for the backup archive
184 184
      *
185 185
      * @return string multi-part backup name
186 186
      */
187
-    public function get_archive_name_multipart()
188
-    {
189
-        $new_name = preg_replace('/-part(\d*)/', "", $this->archive_name);
190
-        return $new_name . "-multipart" . $this->xcloner_settings->get_backup_extension_name(".csv");
191
-    }
187
+	public function get_archive_name_multipart()
188
+	{
189
+		$new_name = preg_replace('/-part(\d*)/', "", $this->archive_name);
190
+		return $new_name . "-multipart" . $this->xcloner_settings->get_backup_extension_name(".csv");
191
+	}
192 192
 
193
-    /*
193
+	/*
194 194
      *
195 195
      * Returns the full backup name including extension
196 196
      *
197 197
      */
198
-    public function get_archive_name_with_extension()
199
-    {
200
-        return $this->archive_name . $this->xcloner_settings->get_backup_extension_name();
201
-    }
198
+	public function get_archive_name_with_extension()
199
+	{
200
+		return $this->archive_name . $this->xcloner_settings->get_backup_extension_name();
201
+	}
202 202
 
203
-    /*
203
+	/*
204 204
      *
205 205
      * Send notification error by E-Mail
206 206
      *
@@ -213,31 +213,31 @@  discard block
 block discarded – undo
213 213
      *
214 214
      * @return bool
215 215
      */
216
-    public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message)
217
-    {
216
+	public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message)
217
+	{
218 218
 
219
-        $body = "";
220
-        $body .= sprintf(__("Backup Site Url: %s"), get_site_url());
221
-        $body .= "<br /><>";
219
+		$body = "";
220
+		$body .= sprintf(__("Backup Site Url: %s"), get_site_url());
221
+		$body .= "<br /><>";
222 222
 
223
-        $body .= sprintf(__("Error Message: %s"), $error_message);
223
+		$body .= sprintf(__("Error Message: %s"), $error_message);
224 224
 
225
-        $this->logger->info(sprintf("Sending backup error notification to %s", $to));
225
+		$this->logger->info(sprintf("Sending backup error notification to %s", $to));
226 226
 
227
-        $admin_email = get_option("admin_email");
227
+		$admin_email = get_option("admin_email");
228 228
 
229
-        $headers = array('Content-Type: text/html; charset=UTF-8');
229
+		$headers = array('Content-Type: text/html; charset=UTF-8');
230 230
 
231
-        if ($admin_email and $from) {
232
-            $headers[] = 'From: ' . $from . ' <' . $admin_email . '>';
233
-        }
231
+		if ($admin_email and $from) {
232
+			$headers[] = 'From: ' . $from . ' <' . $admin_email . '>';
233
+		}
234 234
 
235
-        $return = wp_mail($to, $subject, $body, $headers);
235
+		$return = wp_mail($to, $subject, $body, $headers);
236 236
 
237
-        return $return;
238
-    }
237
+		return $return;
238
+	}
239 239
 
240
-    /*
240
+	/*
241 241
      *
242 242
      * Send backup archive notfication by E-Mail
243 243
      *
@@ -251,480 +251,480 @@  discard block
 block discarded – undo
251 251
      *
252 252
      * @return bool
253 253
      */
254
-    public function send_notification(
255
-        $to,
256
-        $from,
257
-        $subject,
258
-        $backup_name,
259
-        $params,
260
-        $error_message = "",
261
-        $additional = array()
262
-    ) {
263
-        if (!$from) {
264
-            $from = "XCloner Backup";
265
-        }
254
+	public function send_notification(
255
+		$to,
256
+		$from,
257
+		$subject,
258
+		$backup_name,
259
+		$params,
260
+		$error_message = "",
261
+		$additional = array()
262
+	) {
263
+		if (!$from) {
264
+			$from = "XCloner Backup";
265
+		}
266 266
 
267
-        if (($error_message)) {
268
-            return $this->send_notification_error($to, $from, $subject, $backup_name, $params, $error_message);
269
-        }
267
+		if (($error_message)) {
268
+			return $this->send_notification_error($to, $from, $subject, $backup_name, $params, $error_message);
269
+		}
270 270
 
271
-        $params = (array)$params;
271
+		$params = (array)$params;
272 272
 
273
-        if (!$subject) {
274
-            $subject = sprintf(__("New backup generated %s"), $backup_name);
275
-        }
273
+		if (!$subject) {
274
+			$subject = sprintf(__("New backup generated %s"), $backup_name);
275
+		}
276 276
 
277
-        $body = sprintf(__("Generated Backup Size: %s"), size_format($this->filesystem->get_backup_size($backup_name)));
278
-        $body .= "<br /><br />";
277
+		$body = sprintf(__("Generated Backup Size: %s"), size_format($this->filesystem->get_backup_size($backup_name)));
278
+		$body .= "<br /><br />";
279 279
 
280
-        if (isset($additional['lines_total'])) {
281
-            $body .= sprintf(__("Total files added: %s"), $additional['lines_total']);
282
-            $body .= "<br /><br />";
283
-        }
280
+		if (isset($additional['lines_total'])) {
281
+			$body .= sprintf(__("Total files added: %s"), $additional['lines_total']);
282
+			$body .= "<br /><br />";
283
+		}
284 284
 
285
-        $backup_parts = $this->filesystem->get_multipart_files($backup_name);
285
+		$backup_parts = $this->filesystem->get_multipart_files($backup_name);
286 286
 
287
-        if (!$backups_counter = sizeof($backup_parts)) {
288
-            $backups_counter = 1;
289
-        }
287
+		if (!$backups_counter = sizeof($backup_parts)) {
288
+			$backups_counter = 1;
289
+		}
290 290
 
291
-        $body .= sprintf(__("Backup Parts: %s"), $backups_counter);
292
-        $body .= "<br />";
291
+		$body .= sprintf(__("Backup Parts: %s"), $backups_counter);
292
+		$body .= "<br />";
293 293
 
294
-        if (sizeof($backup_parts)) {
295
-            $body .= implode("<br />", $backup_parts);
296
-            $body .= "<br />";
297
-        }
294
+		if (sizeof($backup_parts)) {
295
+			$body .= implode("<br />", $backup_parts);
296
+			$body .= "<br />";
297
+		}
298 298
 
299
-        $body .= "<br />";
299
+		$body .= "<br />";
300 300
 
301
-        $body .= sprintf(__("Backup Site Url: %s"), get_site_url());
302
-        $body .= "<br />";
301
+		$body .= sprintf(__("Backup Site Url: %s"), get_site_url());
302
+		$body .= "<br />";
303 303
 
304
-        if (isset($params['backup_params']->backup_comments)) {
305
-            $body .= __("Backup Comments: ") . $params['backup_params']->backup_comments;
306
-            $body .= "<br /><br />";
307
-        }
304
+		if (isset($params['backup_params']->backup_comments)) {
305
+			$body .= __("Backup Comments: ") . $params['backup_params']->backup_comments;
306
+			$body .= "<br /><br />";
307
+		}
308 308
 
309
-        if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
310
-            $body .= __("Latest 50 Log Lines: ") . "<br />" . implode("<br />\n",
311
-                                                                        $this->logger->getLastDebugLines(50));
312
-        }
309
+		if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
310
+			$body .= __("Latest 50 Log Lines: ") . "<br />" . implode("<br />\n",
311
+																		$this->logger->getLastDebugLines(50));
312
+		}
313 313
 
314
-        $attachments = $this->filesystem->get_backup_attachments();
314
+		$attachments = $this->filesystem->get_backup_attachments();
315 315
 
316
-        $attachments_archive = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "info.tgz";
316
+		$attachments_archive = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "info.tgz";
317 317
 
318
-        $tar = new Tar();
319
-        $tar->create($attachments_archive);
318
+		$tar = new Tar();
319
+		$tar->create($attachments_archive);
320 320
 
321
-        foreach ($attachments as $key => $file) {
322
-            $tar->addFile($file, basename($file));
323
-        }
324
-        $tar->close();
321
+		foreach ($attachments as $key => $file) {
322
+			$tar->addFile($file, basename($file));
323
+		}
324
+		$tar->close();
325 325
 
326
-        $this->logger->info(sprintf("Sending backup notification to %s", $to));
326
+		$this->logger->info(sprintf("Sending backup notification to %s", $to));
327 327
 
328
-        $admin_email = get_option("admin_email");
328
+		$admin_email = get_option("admin_email");
329 329
 
330
-        $headers = array('Content-Type: text/html; charset=UTF-8', 'From: ' . $from . ' <' . $admin_email . '>');
330
+		$headers = array('Content-Type: text/html; charset=UTF-8', 'From: ' . $from . ' <' . $admin_email . '>');
331 331
 
332
-        $return = wp_mail($to, $subject, $body, $headers, array($attachments_archive));
332
+		$return = wp_mail($to, $subject, $body, $headers, array($attachments_archive));
333 333
 
334
-        return $return;
335
-    }
334
+		return $return;
335
+	}
336 336
 
337
-    /*
337
+	/*
338 338
      *
339 339
      * Incremental Backup method
340 340
      *
341 341
      */
342
-    public function start_incremental_backup($backup_params, $extra_params, $init)
343
-    {
344
-        $return = array();
342
+	public function start_incremental_backup($backup_params, $extra_params, $init)
343
+	{
344
+		$return = array();
345 345
 
346
-        if (!isset($extra_params['backup_part'])) {
347
-            $extra_params['backup_part'] = 0;
348
-        }
346
+		if (!isset($extra_params['backup_part'])) {
347
+			$extra_params['backup_part'] = 0;
348
+		}
349 349
 
350
-        $return['extra']['backup_part'] = $extra_params['backup_part'];
350
+		$return['extra']['backup_part'] = $extra_params['backup_part'];
351 351
 
352
-        if (isset($extra_params['backup_archive_name'])) {
353
-            $this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']);
354
-        } else {
355
-            $this->set_archive_name($backup_params['backup_name']);
356
-        }
352
+		if (isset($extra_params['backup_archive_name'])) {
353
+			$this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']);
354
+		} else {
355
+			$this->set_archive_name($backup_params['backup_name']);
356
+		}
357 357
 
358
-        if (!$this->get_archive_name()) {
359
-            $this->set_archive_name();
360
-        }
358
+		if (!$this->get_archive_name()) {
359
+			$this->set_archive_name();
360
+		}
361 361
 
362
-        $this->backup_archive = new Tar();
363
-        $this->backup_archive->setCompression($this->compression_level);
362
+		$this->backup_archive = new Tar();
363
+		$this->backup_archive->setCompression($this->compression_level);
364 364
 
365
-        $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension());
365
+		$archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension());
366 366
 
367
-        if ($init) {
368
-            $this->logger->info(sprintf(__("Initializing the backup archive %s"), $this->get_archive_name()));
367
+		if ($init) {
368
+			$this->logger->info(sprintf(__("Initializing the backup archive %s"), $this->get_archive_name()));
369 369
 
370
-            $this->backup_archive->create($archive_info->getPath() . DS . $archive_info->getFilename());
370
+			$this->backup_archive->create($archive_info->getPath() . DS . $archive_info->getFilename());
371 371
 
372
-            $return['extra']['backup_init'] = 1;
372
+			$return['extra']['backup_init'] = 1;
373 373
 
374
-        } else {
375
-            $this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name()));
374
+		} else {
375
+			$this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name()));
376 376
 
377
-            $this->backup_archive->openForAppend($archive_info->getPath() . DS . $archive_info->getFilename());
377
+			$this->backup_archive->openForAppend($archive_info->getPath() . DS . $archive_info->getFilename());
378 378
 
379
-            $return['extra']['backup_init'] = 0;
379
+			$return['extra']['backup_init'] = 0;
380 380
 
381
-        }
381
+		}
382 382
 
383
-        $return['extra']['backup_archive_name'] = $this->get_archive_name();
384
-        $return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension();
383
+		$return['extra']['backup_archive_name'] = $this->get_archive_name();
384
+		$return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension();
385 385
 
386
-        if (!isset($extra_params['start_at_line'])) {
387
-            $extra_params['start_at_line'] = 0;
388
-        }
386
+		if (!isset($extra_params['start_at_line'])) {
387
+			$extra_params['start_at_line'] = 0;
388
+		}
389 389
 
390
-        if (!isset($extra_params['start_at_byte'])) {
391
-            $extra_params['start_at_byte'] = 0;
392
-        }
390
+		if (!isset($extra_params['start_at_byte'])) {
391
+			$extra_params['start_at_byte'] = 0;
392
+		}
393 393
 
394
-        if (!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) {
395
-            $this->logger->error(sprintf("Missing the includes file handler %s, aborting...",
396
-                $this->filesystem->get_included_files_handler()));
394
+		if (!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) {
395
+			$this->logger->error(sprintf("Missing the includes file handler %s, aborting...",
396
+				$this->filesystem->get_included_files_handler()));
397 397
 
398
-            $return['finished'] = 1;
399
-            return $return;
400
-        }
398
+			$return['finished'] = 1;
399
+			return $return;
400
+		}
401 401
 
402
-        $included_files_handler = $this->filesystem->get_included_files_handler(1);
402
+		$included_files_handler = $this->filesystem->get_included_files_handler(1);
403 403
 
404
-        $file = new SplFileObject($included_files_handler);
404
+		$file = new SplFileObject($included_files_handler);
405 405
 
406
-        $file->seek(PHP_INT_MAX);
406
+		$file->seek(PHP_INT_MAX);
407 407
 
408
-        $return['extra']['lines_total'] = ($file->key() - 1);
408
+		$return['extra']['lines_total'] = ($file->key() - 1);
409 409
 
410
-        //we skip the first CSV line with headers
411
-        if (!$extra_params['start_at_line']) {
412
-            $file->seek(1);
413
-        } else {
414
-            $file->seek($extra_params['start_at_line'] + 1);
415
-        }
410
+		//we skip the first CSV line with headers
411
+		if (!$extra_params['start_at_line']) {
412
+			$file->seek(1);
413
+		} else {
414
+			$file->seek($extra_params['start_at_line'] + 1);
415
+		}
416 416
 
417
-        $this->processed_size_bytes = 0;
417
+		$this->processed_size_bytes = 0;
418 418
 
419
-        $counter = 0;
419
+		$counter = 0;
420 420
 
421
-        $start_byte = $extra_params['start_at_byte'];
421
+		$start_byte = $extra_params['start_at_byte'];
422 422
 
423
-        $byte_limit = 0;
423
+		$byte_limit = 0;
424 424
 
425
-        while (!$file->eof() and $counter <= $this->files_to_process_per_request) {
426
-            $current_line_str = $file->current();
425
+		while (!$file->eof() and $counter <= $this->files_to_process_per_request) {
426
+			$current_line_str = $file->current();
427 427
 
428
-            $line = str_getcsv($current_line_str);
428
+			$line = str_getcsv($current_line_str);
429 429
 
430
-            $relative_path = stripslashes($line[0]);
430
+			$relative_path = stripslashes($line[0]);
431 431
 
432
-            $start_filesystem = "start_filesystem";
432
+			$start_filesystem = "start_filesystem";
433 433
 
434
-            if (isset($line[4])) {
435
-                $start_filesystem = $line[4];
436
-            }
434
+			if (isset($line[4])) {
435
+				$start_filesystem = $line[4];
436
+			}
437 437
 
438
-            //$adapter = $this->filesystem->get_adapter($start_filesystem);
438
+			//$adapter = $this->filesystem->get_adapter($start_filesystem);
439 439
 
440
-            if (!$relative_path || !$this->filesystem->get_filesystem($start_filesystem)->has($relative_path)) {
441
-                if ($relative_path != "") {
442
-                    $this->logger->error(sprintf("Could not add file %b to backup archive, file not found",
443
-                        $relative_path));
444
-                }
440
+			if (!$relative_path || !$this->filesystem->get_filesystem($start_filesystem)->has($relative_path)) {
441
+				if ($relative_path != "") {
442
+					$this->logger->error(sprintf("Could not add file %b to backup archive, file not found",
443
+						$relative_path));
444
+				}
445 445
 
446
-                $extra_params['start_at_line']++;
447
-                $file->next();
448
-                continue;
449
-            }
446
+				$extra_params['start_at_line']++;
447
+				$file->next();
448
+				continue;
449
+			}
450 450
 
451
-            $file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path);
451
+			$file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path);
452 452
 
453
-            if (!isset($file_info['size'])) {
454
-                $file_info['size'] = 0;
455
-            }
453
+			if (!isset($file_info['size'])) {
454
+				$file_info['size'] = 0;
455
+			}
456 456
 
457
-            if ($start_filesystem == "tmp_filesystem") {
458
-                $file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix();
459
-            }
457
+			if ($start_filesystem == "tmp_filesystem") {
458
+				$file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix();
459
+			}
460 460
 
461
-            $byte_limit = (int)$this->file_size_per_request_limit / 512;
461
+			$byte_limit = (int)$this->file_size_per_request_limit / 512;
462 462
 
463
-            $append = 0;
463
+			$append = 0;
464 464
 
465
-            if ($file_info['size'] > $byte_limit * 512 or $start_byte) {
466
-                $append = 1;
467
-            }
465
+			if ($file_info['size'] > $byte_limit * 512 or $start_byte) {
466
+				$append = 1;
467
+			}
468 468
 
469
-            if (!isset($return['extra']['backup_size'])) {
470
-                $return['extra']['backup_size'] = 0;
471
-            }
469
+			if (!isset($return['extra']['backup_size'])) {
470
+				$return['extra']['backup_size'] = 0;
471
+			}
472 472
 
473
-            $return['extra']['backup_size'] = $archive_info->getSize();
473
+			$return['extra']['backup_size'] = $archive_info->getSize();
474 474
 
475
-            $estimated_new_size = $return['extra']['backup_size'] + $file_info['size'];
475
+			$estimated_new_size = $return['extra']['backup_size'] + $file_info['size'];
476 476
 
477
-            //we create a new backup part if we reach the Split Achive Limit
478
-            if ($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte)) {
479
-                $this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ",
480
-                    $this->xcloner_split_backup_limit, $estimated_new_size));
481
-                list($archive_info, $return['extra']['backup_part']) = $this->create_new_backup_part($return['extra']['backup_part']);
477
+			//we create a new backup part if we reach the Split Achive Limit
478
+			if ($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte)) {
479
+				$this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ",
480
+					$this->xcloner_split_backup_limit, $estimated_new_size));
481
+				list($archive_info, $return['extra']['backup_part']) = $this->create_new_backup_part($return['extra']['backup_part']);
482 482
 
483
-                if ($file_info['size'] > $this->xcloner_split_backup_limit) {
484
-                    $this->logger->info(sprintf("Excluding %s file as it's size(%s) is bigger than the backup split limit of %s and it won't fit a single backup file",
485
-                        $file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit));
486
-                    $extra_params['start_at_line']++;
487
-                }
483
+				if ($file_info['size'] > $this->xcloner_split_backup_limit) {
484
+					$this->logger->info(sprintf("Excluding %s file as it's size(%s) is bigger than the backup split limit of %s and it won't fit a single backup file",
485
+						$file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit));
486
+					$extra_params['start_at_line']++;
487
+				}
488 488
 
489
-                $return['extra']['start_at_line'] = $extra_params['start_at_line'];
490
-                $return['extra']['start_at_byte'] = 0;
489
+				$return['extra']['start_at_line'] = $extra_params['start_at_line'];
490
+				$return['extra']['start_at_byte'] = 0;
491 491
 
492
-                $return['finished'] = 0;
492
+				$return['finished'] = 0;
493 493
 
494
-                return $return;
495
-            }
494
+				return $return;
495
+			}
496 496
 
497
-            list($bytes_wrote, $last_position) = $this->add_file_to_archive($file_info, $start_byte, $byte_limit,
498
-                $append, $start_filesystem);
499
-            $this->processed_size_bytes += $bytes_wrote;
497
+			list($bytes_wrote, $last_position) = $this->add_file_to_archive($file_info, $start_byte, $byte_limit,
498
+				$append, $start_filesystem);
499
+			$this->processed_size_bytes += $bytes_wrote;
500 500
 
501
-            //echo" - processed ".$this->processed_size_bytes." bytes ".$this->file_size_per_request_limit." last_position:".$last_position." \n";
502
-            $return['extra']['processed_file'] = $file_info['path'];
503
-            $return['extra']['processed_file_size'] = $file_info['size'];
504
-            $return['extra']['backup_size'] = $archive_info->getSize();
501
+			//echo" - processed ".$this->processed_size_bytes." bytes ".$this->file_size_per_request_limit." last_position:".$last_position." \n";
502
+			$return['extra']['processed_file'] = $file_info['path'];
503
+			$return['extra']['processed_file_size'] = $file_info['size'];
504
+			$return['extra']['backup_size'] = $archive_info->getSize();
505 505
 
506
-            if ($last_position > 0) {
507
-                $start_byte = $last_position;
508
-            } else {
509
-                $extra_params['start_at_line']++;
510
-                $file->next();
511
-                $start_byte = 0;
512
-                $counter++;
513
-            }
506
+			if ($last_position > 0) {
507
+				$start_byte = $last_position;
508
+			} else {
509
+				$extra_params['start_at_line']++;
510
+				$file->next();
511
+				$start_byte = 0;
512
+				$counter++;
513
+			}
514 514
 
515
-            if ($this->processed_size_bytes >= $this->file_size_per_request_limit) {
516
-                clearstatcache();
517
-                $return['extra']['backup_size'] = $archive_info->getSize();
515
+			if ($this->processed_size_bytes >= $this->file_size_per_request_limit) {
516
+				clearstatcache();
517
+				$return['extra']['backup_size'] = $archive_info->getSize();
518 518
 
519
-                $return['finished'] = 0;
520
-                $return['extra']['start_at_line'] = $extra_params['start_at_line'];
521
-                $return['extra']['start_at_byte'] = $last_position;
522
-                $this->logger->info(sprintf("Reached the maximum %s request data limit, returning response",
523
-                    $this->file_size_per_request_limit));
524
-                return $return;
525
-            }
526
-        }
519
+				$return['finished'] = 0;
520
+				$return['extra']['start_at_line'] = $extra_params['start_at_line'];
521
+				$return['extra']['start_at_byte'] = $last_position;
522
+				$this->logger->info(sprintf("Reached the maximum %s request data limit, returning response",
523
+					$this->file_size_per_request_limit));
524
+				return $return;
525
+			}
526
+		}
527 527
 
528
-        if (!$file->eof()) {
529
-            clearstatcache();
530
-            $return['extra']['backup_size'] = $archive_info->getSize();
528
+		if (!$file->eof()) {
529
+			clearstatcache();
530
+			$return['extra']['backup_size'] = $archive_info->getSize();
531 531
 
532
-            $return['finished'] = 0;
533
-            $return['extra']['start_at_line'] = $extra_params['start_at_line'];
534
-            $return['extra']['start_at_byte'] = $last_position;
535
-            $this->logger->info(sprintf("We have reached the maximum files to process per request limit of %s, returning response",
536
-                $this->files_to_process_per_request));
532
+			$return['finished'] = 0;
533
+			$return['extra']['start_at_line'] = $extra_params['start_at_line'];
534
+			$return['extra']['start_at_byte'] = $last_position;
535
+			$this->logger->info(sprintf("We have reached the maximum files to process per request limit of %s, returning response",
536
+				$this->files_to_process_per_request));
537 537
 
538
-            return $return;
539
-        }
538
+			return $return;
539
+		}
540 540
 
541
-        //close the backup archive by adding 2*512 blocks of zero bytes
542
-        $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.",
543
-            $this->get_archive_name_with_extension()));
544
-        $this->backup_archive->close();
541
+		//close the backup archive by adding 2*512 blocks of zero bytes
542
+		$this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.",
543
+			$this->get_archive_name_with_extension()));
544
+		$this->backup_archive->close();
545 545
 
546
-        /**
547
-         * XCloner HOOK backup_archive_finished.
548
-         *
549
-         * This will get triggered when a backup archive is finished writing.
550
-         */
551
-        //do_action('backup_archive_finished', $this->backup_archive, $this);
546
+		/**
547
+		 * XCloner HOOK backup_archive_finished.
548
+		 *
549
+		 * This will get triggered when a backup archive is finished writing.
550
+		 */
551
+		//do_action('backup_archive_finished', $this->backup_archive, $this);
552 552
 
553
-        //updating archive_info
554
-        $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension());
553
+		//updating archive_info
554
+		$archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension());
555 555
 
556
-        if ($return['extra']['backup_part']) {
557
-            $this->write_multipart_file($this->get_archive_name_with_extension());
558
-        }
556
+		if ($return['extra']['backup_part']) {
557
+			$this->write_multipart_file($this->get_archive_name_with_extension());
558
+		}
559 559
 
560
-        $return['extra']['start_at_line'] = $extra_params['start_at_line'] - 1;
560
+		$return['extra']['start_at_line'] = $extra_params['start_at_line'] - 1;
561 561
 
562
-        if (isset($file_info)) {
563
-            $return['extra']['processed_file'] = $file_info['path'];
564
-            $return['extra']['processed_file_size'] = $file_info['size'];
565
-        }
562
+		if (isset($file_info)) {
563
+			$return['extra']['processed_file'] = $file_info['path'];
564
+			$return['extra']['processed_file_size'] = $file_info['size'];
565
+		}
566 566
 
567
-        clearstatcache();
568
-        $return['extra']['backup_size'] = $archive_info->getSize();
567
+		clearstatcache();
568
+		$return['extra']['backup_size'] = $archive_info->getSize();
569 569
 
570
-        $return['finished'] = 1;
571
-        return $return;
572
-    }
570
+		$return['finished'] = 1;
571
+		return $return;
572
+	}
573 573
 
574
-    /*
574
+	/*
575 575
      *
576 576
      * Write multipart file components
577 577
      *
578 578
      */
579
-    private function write_multipart_file($path)
580
-    {
581
-        $path = $this->get_archive_name_with_extension();
579
+	private function write_multipart_file($path)
580
+	{
581
+		$path = $this->get_archive_name_with_extension();
582 582
 
583
-        $file = $this->filesystem->get_filesystem("storage_filesystem_append")->getMetadata($path);
584
-        //print_r($file_info);
585
-        $line = '"' . $file['path'] . '","' . $file['timestamp'] . '","' . $file['size'] . '"' . PHP_EOL;
583
+		$file = $this->filesystem->get_filesystem("storage_filesystem_append")->getMetadata($path);
584
+		//print_r($file_info);
585
+		$line = '"' . $file['path'] . '","' . $file['timestamp'] . '","' . $file['size'] . '"' . PHP_EOL;
586 586
 
587 587
 
588
-        $this->filesystem->get_filesystem("storage_filesystem_append")
589
-            ->write($this->get_archive_name_multipart(), $line);
590
-    }
588
+		$this->filesystem->get_filesystem("storage_filesystem_append")
589
+			->write($this->get_archive_name_multipart(), $line);
590
+	}
591 591
 
592
-    /*
592
+	/*
593 593
      *
594 594
      * Create a new backup part
595 595
      *
596 596
      */
597
-    private function create_new_backup_part($part = 0)
598
-    {
599
-        //close the backup archive by adding 2*512 blocks of zero bytes
600
-        $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.",
601
-            $this->get_archive_name_with_extension()));
602
-        $this->backup_archive->close();
603
-
604
-        if (!$part) {
605
-            $old_name = $this->get_archive_name_with_extension();
606
-            $this->set_archive_name($this->get_archive_name(), ++$part);
607
-            $this->rename_archive($old_name, $this->get_archive_name_with_extension());
608
-
609
-            if ($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) {
610
-                $this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart());
611
-            }
612
-
613
-            $this->write_multipart_file($this->get_archive_name_with_extension());
614
-
615
-        } else {
616
-            $this->logger->info(sprintf("Creating new multipart info file %s",
617
-                $this->get_archive_name_with_extension()));
618
-            $this->write_multipart_file($this->get_archive_name_with_extension());
619
-        }
597
+	private function create_new_backup_part($part = 0)
598
+	{
599
+		//close the backup archive by adding 2*512 blocks of zero bytes
600
+		$this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.",
601
+			$this->get_archive_name_with_extension()));
602
+		$this->backup_archive->close();
603
+
604
+		if (!$part) {
605
+			$old_name = $this->get_archive_name_with_extension();
606
+			$this->set_archive_name($this->get_archive_name(), ++$part);
607
+			$this->rename_archive($old_name, $this->get_archive_name_with_extension());
608
+
609
+			if ($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) {
610
+				$this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart());
611
+			}
612
+
613
+			$this->write_multipart_file($this->get_archive_name_with_extension());
614
+
615
+		} else {
616
+			$this->logger->info(sprintf("Creating new multipart info file %s",
617
+				$this->get_archive_name_with_extension()));
618
+			$this->write_multipart_file($this->get_archive_name_with_extension());
619
+		}
620 620
 
621
-        $this->set_archive_name($this->get_archive_name(), ++$part);
621
+		$this->set_archive_name($this->get_archive_name(), ++$part);
622 622
 
623
-        $this->logger->info(sprintf("Creating new backup archive part %s", $this->get_archive_name_with_extension()));
623
+		$this->logger->info(sprintf("Creating new backup archive part %s", $this->get_archive_name_with_extension()));
624 624
 
625
-        $this->backup_archive = new Tar();
626
-        $this->backup_archive->setCompression($this->compression_level);
627
-        $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension());
628
-        $this->backup_archive->create($archive_info->getPath() . DS . $archive_info->getFilename());
625
+		$this->backup_archive = new Tar();
626
+		$this->backup_archive->setCompression($this->compression_level);
627
+		$archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension());
628
+		$this->backup_archive->create($archive_info->getPath() . DS . $archive_info->getFilename());
629 629
 
630
-        return array($archive_info, $part);
630
+		return array($archive_info, $part);
631 631
 
632
-    }
632
+	}
633 633
 
634
-    /*
634
+	/*
635 635
      *
636 636
      * Add file to archive
637 637
      *
638 638
      */
639
-    public function add_file_to_archive($file_info, $start_at_byte, $byte_limit = 0, $append, $filesystem)
640
-    {
641
-
642
-        $start_adapter = $this->filesystem->get_adapter($filesystem);
643
-        $start_filesystem = $this->filesystem->get_adapter($filesystem);
644
-
645
-        if (!$file_info['path']) {
646
-            return;
647
-        }
648
-
649
-        if (isset($file_info['archive_prefix_path'])) {
650
-            $file_info['target_path'] = $file_info['archive_prefix_path'] . "/" . $file_info['path'];
651
-        } else {
652
-            $file_info['target_path'] = $file_info['path'];
653
-        }
654
-
655
-        $last_position = $start_at_byte;
656
-
657
-        //$start_adapter = $this->filesystem->get_start_adapter();
658
-
659
-        if (!$append) {
660
-            $bytes_wrote = $file_info['size'];
661
-            $this->logger->info(sprintf("Adding %s bytes of file %s to archive %s ", $bytes_wrote,
662
-                $file_info['target_path'], $this->get_archive_name_with_extension()));
663
-            $this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']),
664
-                $file_info['target_path']);
665
-        } else {
666
-            $tmp_file = md5($file_info['path']);
667
-
668
-            //we isolate file to tmp if we are at byte 0, the starting point of file reading
669
-            if (!$start_at_byte) {
670
-                $this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes",
671
-                    $file_info['path'], $tmp_file));
672
-                $file_stream = $start_filesystem->readStream($file_info['path']);
673
-
674
-                if (is_resource($file_stream['stream'])) {
675
-                    $this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']);
676
-                }
677
-            }
678
-
679
-            if ($this->filesystem->get_tmp_filesystem()->has($tmp_file)) {
680
-                $is_tmp = 1;
681
-                $last_position = $this->backup_archive->appendFileData($this->filesystem->get_tmp_filesystem_adapter()
682
-                                                        ->applyPathPrefix($tmp_file),
683
-                    $file_info['target_path'], $start_at_byte, $byte_limit);
684
-            } else {
685
-                $is_tmp = 0;
686
-                $last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']),
687
-                    $file_info['target_path'], $start_at_byte, $byte_limit);
688
-            }
689
-
690
-
691
-            if ($last_position == -1) {
692
-                $bytes_wrote = $file_info['size'] - $start_at_byte;
693
-            } else {
694
-                $bytes_wrote = $last_position - $start_at_byte;
695
-            }
639
+	public function add_file_to_archive($file_info, $start_at_byte, $byte_limit = 0, $append, $filesystem)
640
+	{
696 641
 
642
+		$start_adapter = $this->filesystem->get_adapter($filesystem);
643
+		$start_filesystem = $this->filesystem->get_adapter($filesystem);
697 644
 
698
-            if ($is_tmp) {
699
-                $this->logger->info(sprintf("Appended %s bytes, starting position %s, of tmp file %s (%s) to archive %s ",
700
-                    $bytes_wrote, $start_at_byte, $tmp_file, $file_info['target_path'], $this->get_archive_name()));
701
-            } else {
702
-                $this->logger->info(sprintf("Appended %s bytes, starting position %s, of original file %s to archive %s ",
703
-                    $bytes_wrote, $start_at_byte, $file_info['target_path'], $tmp_file, $this->get_archive_name()));
704
-            }
645
+		if (!$file_info['path']) {
646
+			return;
647
+		}
705 648
 
706
-            //we delete here the isolated tmp file
707
-            if ($last_position == -1) {
708
-                if ($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file)) {
709
-                    $this->logger->info(sprintf("Deleting %s from the tmp filesystem", $tmp_file));
710
-                    $this->filesystem->get_tmp_filesystem_adapter()->delete($tmp_file);
711
-                }
712
-            }
649
+		if (isset($file_info['archive_prefix_path'])) {
650
+			$file_info['target_path'] = $file_info['archive_prefix_path'] . "/" . $file_info['path'];
651
+		} else {
652
+			$file_info['target_path'] = $file_info['path'];
653
+		}
713 654
 
714
-        }
655
+		$last_position = $start_at_byte;
656
+
657
+		//$start_adapter = $this->filesystem->get_start_adapter();
658
+
659
+		if (!$append) {
660
+			$bytes_wrote = $file_info['size'];
661
+			$this->logger->info(sprintf("Adding %s bytes of file %s to archive %s ", $bytes_wrote,
662
+				$file_info['target_path'], $this->get_archive_name_with_extension()));
663
+			$this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']),
664
+				$file_info['target_path']);
665
+		} else {
666
+			$tmp_file = md5($file_info['path']);
667
+
668
+			//we isolate file to tmp if we are at byte 0, the starting point of file reading
669
+			if (!$start_at_byte) {
670
+				$this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes",
671
+					$file_info['path'], $tmp_file));
672
+				$file_stream = $start_filesystem->readStream($file_info['path']);
673
+
674
+				if (is_resource($file_stream['stream'])) {
675
+					$this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']);
676
+				}
677
+			}
678
+
679
+			if ($this->filesystem->get_tmp_filesystem()->has($tmp_file)) {
680
+				$is_tmp = 1;
681
+				$last_position = $this->backup_archive->appendFileData($this->filesystem->get_tmp_filesystem_adapter()
682
+														->applyPathPrefix($tmp_file),
683
+					$file_info['target_path'], $start_at_byte, $byte_limit);
684
+			} else {
685
+				$is_tmp = 0;
686
+				$last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']),
687
+					$file_info['target_path'], $start_at_byte, $byte_limit);
688
+			}
689
+
690
+
691
+			if ($last_position == -1) {
692
+				$bytes_wrote = $file_info['size'] - $start_at_byte;
693
+			} else {
694
+				$bytes_wrote = $last_position - $start_at_byte;
695
+			}
696
+
697
+
698
+			if ($is_tmp) {
699
+				$this->logger->info(sprintf("Appended %s bytes, starting position %s, of tmp file %s (%s) to archive %s ",
700
+					$bytes_wrote, $start_at_byte, $tmp_file, $file_info['target_path'], $this->get_archive_name()));
701
+			} else {
702
+				$this->logger->info(sprintf("Appended %s bytes, starting position %s, of original file %s to archive %s ",
703
+					$bytes_wrote, $start_at_byte, $file_info['target_path'], $tmp_file, $this->get_archive_name()));
704
+			}
705
+
706
+			//we delete here the isolated tmp file
707
+			if ($last_position == -1) {
708
+				if ($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file)) {
709
+					$this->logger->info(sprintf("Deleting %s from the tmp filesystem", $tmp_file));
710
+					$this->filesystem->get_tmp_filesystem_adapter()->delete($tmp_file);
711
+				}
712
+			}
715 713
 
716
-        return array($bytes_wrote, $last_position);
717
-    }
714
+		}
718 715
 
719
-    /**
720
-     * Open a TAR archive and put the file cursor at the end for data appending
721
-     *
722
-     * If $file is empty, the tar file will be created in memory
723
-     *
724
-     * @param string $file
725
-     * @throws ArchiveIOException
726
-     */
727
-    /*
716
+		return array($bytes_wrote, $last_position);
717
+	}
718
+
719
+	/**
720
+	 * Open a TAR archive and put the file cursor at the end for data appending
721
+	 *
722
+	 * If $file is empty, the tar file will be created in memory
723
+	 *
724
+	 * @param string $file
725
+	 * @throws ArchiveIOException
726
+	 */
727
+	/*
728 728
     public function openForAppend($file = '')
729 729
     {
730 730
         $this->file   = $file;
@@ -754,17 +754,17 @@  discard block
 block discarded – undo
754 754
     }
755 755
     */
756 756
 
757
-    /**
758
-     * Append data to a file to the current TAR archive using an existing file in the filesystem
759
-     *
760
-     * @param string $file path to the original file
761
-     * @param int $start starting reading position in file
762
-     * @param int $end end position in reading multiple with 512
763
-     * @param string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with
764
-     * all meta data, empty to take from original
765
-     * @throws ArchiveIOException
766
-     */
767
-    /*
757
+	/**
758
+	 * Append data to a file to the current TAR archive using an existing file in the filesystem
759
+	 *
760
+	 * @param string $file path to the original file
761
+	 * @param int $start starting reading position in file
762
+	 * @param int $end end position in reading multiple with 512
763
+	 * @param string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with
764
+	 * all meta data, empty to take from original
765
+	 * @throws ArchiveIOException
766
+	 */
767
+	/*
768 768
      * public function appendFileData($file, $fileinfo = '', $start = 0, $limit = 0)
769 769
     {
770 770
 		$end = $start+($limit*512);
@@ -820,15 +820,15 @@  discard block
 block discarded – undo
820 820
         return $last_position;
821 821
     }*/
822 822
 
823
-    /**
824
-     * Adds a file to a TAR archive by appending it's data
825
-     *
826
-     * @param string $archive name of the archive file
827
-     * @param string $file name of the file to read data from
828
-     * @param string $start start position from where to start reading data
829
-     * @throws ArchiveIOException
830
-     */
831
-    /*public function addFileToArchive($archive, $file, $start = 0)
823
+	/**
824
+	 * Adds a file to a TAR archive by appending it's data
825
+	 *
826
+	 * @param string $archive name of the archive file
827
+	 * @param string $file name of the file to read data from
828
+	 * @param string $start start position from where to start reading data
829
+	 * @throws ArchiveIOException
830
+	 */
831
+	/*public function addFileToArchive($archive, $file, $start = 0)
832 832
     {
833 833
         $this->openForAppend($archive);
834 834
         return $start = $this->appendFileData($file, $start, $this->file_size_per_request_limit);
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
             $new_name = $this->archive_name;
149 149
 
150 150
             if (!stristr($new_name, "-diff")) {
151
-                $new_name = $this->archive_name . "-diff" . date("Y-m-d_H-i", $diff_timestamp_start);
151
+                $new_name = $this->archive_name."-diff".date("Y-m-d_H-i", $diff_timestamp_start);
152 152
             }
153 153
 
154 154
             $this->archive_name = $new_name;
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
         }
157 157
 
158 158
         if (isset($part) and $part) {
159
-            $new_name = preg_replace('/-part(\d*)/', "-part" . $part, $this->archive_name);
159
+            $new_name = preg_replace('/-part(\d*)/', "-part".$part, $this->archive_name);
160 160
             if (!stristr($new_name, "-part")) {
161
-                $new_name = $this->archive_name . "-part" . $part;
161
+                $new_name = $this->archive_name."-part".$part;
162 162
             }
163 163
 
164 164
             $this->archive_name = $new_name;
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
     public function get_archive_name_multipart()
188 188
     {
189 189
         $new_name = preg_replace('/-part(\d*)/', "", $this->archive_name);
190
-        return $new_name . "-multipart" . $this->xcloner_settings->get_backup_extension_name(".csv");
190
+        return $new_name."-multipart".$this->xcloner_settings->get_backup_extension_name(".csv");
191 191
     }
192 192
 
193 193
     /*
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
      */
198 198
     public function get_archive_name_with_extension()
199 199
     {
200
-        return $this->archive_name . $this->xcloner_settings->get_backup_extension_name();
200
+        return $this->archive_name.$this->xcloner_settings->get_backup_extension_name();
201 201
     }
202 202
 
203 203
     /*
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
         $headers = array('Content-Type: text/html; charset=UTF-8');
230 230
 
231 231
         if ($admin_email and $from) {
232
-            $headers[] = 'From: ' . $from . ' <' . $admin_email . '>';
232
+            $headers[] = 'From: '.$from.' <'.$admin_email.'>';
233 233
         }
234 234
 
235 235
         $return = wp_mail($to, $subject, $body, $headers);
@@ -302,18 +302,18 @@  discard block
 block discarded – undo
302 302
         $body .= "<br />";
303 303
 
304 304
         if (isset($params['backup_params']->backup_comments)) {
305
-            $body .= __("Backup Comments: ") . $params['backup_params']->backup_comments;
305
+            $body .= __("Backup Comments: ").$params['backup_params']->backup_comments;
306 306
             $body .= "<br /><br />";
307 307
         }
308 308
 
309 309
         if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
310
-            $body .= __("Latest 50 Log Lines: ") . "<br />" . implode("<br />\n",
310
+            $body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n",
311 311
                                                                         $this->logger->getLastDebugLines(50));
312 312
         }
313 313
 
314 314
         $attachments = $this->filesystem->get_backup_attachments();
315 315
 
316
-        $attachments_archive = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "info.tgz";
316
+        $attachments_archive = $this->xcloner_settings->get_xcloner_tmp_path().DS."info.tgz";
317 317
 
318 318
         $tar = new Tar();
319 319
         $tar->create($attachments_archive);
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 
328 328
         $admin_email = get_option("admin_email");
329 329
 
330
-        $headers = array('Content-Type: text/html; charset=UTF-8', 'From: ' . $from . ' <' . $admin_email . '>');
330
+        $headers = array('Content-Type: text/html; charset=UTF-8', 'From: '.$from.' <'.$admin_email.'>');
331 331
 
332 332
         $return = wp_mail($to, $subject, $body, $headers, array($attachments_archive));
333 333
 
@@ -367,14 +367,14 @@  discard block
 block discarded – undo
367 367
         if ($init) {
368 368
             $this->logger->info(sprintf(__("Initializing the backup archive %s"), $this->get_archive_name()));
369 369
 
370
-            $this->backup_archive->create($archive_info->getPath() . DS . $archive_info->getFilename());
370
+            $this->backup_archive->create($archive_info->getPath().DS.$archive_info->getFilename());
371 371
 
372 372
             $return['extra']['backup_init'] = 1;
373 373
 
374 374
         } else {
375 375
             $this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name()));
376 376
 
377
-            $this->backup_archive->openForAppend($archive_info->getPath() . DS . $archive_info->getFilename());
377
+            $this->backup_archive->openForAppend($archive_info->getPath().DS.$archive_info->getFilename());
378 378
 
379 379
             $return['extra']['backup_init'] = 0;
380 380
 
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 
583 583
         $file = $this->filesystem->get_filesystem("storage_filesystem_append")->getMetadata($path);
584 584
         //print_r($file_info);
585
-        $line = '"' . $file['path'] . '","' . $file['timestamp'] . '","' . $file['size'] . '"' . PHP_EOL;
585
+        $line = '"'.$file['path'].'","'.$file['timestamp'].'","'.$file['size'].'"'.PHP_EOL;
586 586
 
587 587
 
588 588
         $this->filesystem->get_filesystem("storage_filesystem_append")
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
         $this->backup_archive = new Tar();
626 626
         $this->backup_archive->setCompression($this->compression_level);
627 627
         $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension());
628
-        $this->backup_archive->create($archive_info->getPath() . DS . $archive_info->getFilename());
628
+        $this->backup_archive->create($archive_info->getPath().DS.$archive_info->getFilename());
629 629
 
630 630
         return array($archive_info, $part);
631 631
 
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
         }
648 648
 
649 649
         if (isset($file_info['archive_prefix_path'])) {
650
-            $file_info['target_path'] = $file_info['archive_prefix_path'] . "/" . $file_info['path'];
650
+            $file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path'];
651 651
         } else {
652 652
             $file_info['target_path'] = $file_info['path'];
653 653
         }
Please login to merge, or discard this patch.
includes/class-xcloner-file-system.php 5 patches
Doc Comments   +12 added lines patch added patch discarded remove patch
@@ -207,6 +207,9 @@  discard block
 block discarded – undo
207 207
         return $this->start_filesystem->normalizeFileInfo($info);
208 208
     }
209 209
 
210
+    /**
211
+     * @param string $file
212
+     */
210 213
     public function get_storage_path_file_info($file)
211 214
     {
212 215
         return $this->getMetadataFull('storage_adapter', $file);
@@ -284,6 +287,9 @@  discard block
 block discarded – undo
284 287
         return $total;
285 288
     }
286 289
 
290
+    /**
291
+     * @param string $backup_name
292
+     */
287 293
     public function is_part($backup_name)
288 294
     {
289 295
         if (stristr($backup_name, "-part")) {
@@ -741,6 +747,9 @@  discard block
 block discarded – undo
741 747
 
742 748
     }
743 749
 
750
+    /**
751
+     * @param string $tmp_file
752
+     */
744 753
     public function estimate_reading_time($tmp_file)
745 754
     {
746 755
         $this->logger->debug(sprintf(("Estimating file system reading time")));
@@ -781,6 +790,9 @@  discard block
 block discarded – undo
781 790
         return $name;
782 791
     }
783 792
 
793
+    /**
794
+     * @param string $field
795
+     */
784 796
     public function sort_by(&$array, $field, $direction = 'asc')
785 797
     {
786 798
         if (strtolower($direction) == "desc" || $direction == SORT_DESC) {
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,6 @@
 block discarded – undo
28 28
 
29 29
 use League\Flysystem\Config;
30 30
 use League\Flysystem\Filesystem;
31
-use League\Flysystem\Util;
32 31
 use League\Flysystem\Adapter\Local;
33 32
 
34 33
 /**
Please login to merge, or discard this patch.
Indentation   +957 added lines, -957 removed lines patch added patch discarded remove patch
@@ -37,848 +37,848 @@  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");
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
-    public function get_storage_path_file_info($file)
211
-    {
212
-        return $this->getMetadataFull('storage_adapter', $file);
213
-    }
214
-
215
-    public function get_included_files_handler($metadata = 0)
216
-    {
217
-        $path = $this->included_files_handler;
218
-        if (!$metadata) {
219
-            return $path;
220
-        }
221
-
222
-        $spl_info = $this->getMetadataFull('tmp_adapter', $path);
223
-
224
-        return $spl_info;
225
-
226
-    }
227
-
228
-    public function get_temp_dir_handler()
229
-    {
230
-        return $this->temp_dir_handler;
231
-    }
232
-
233
-    public function get_latest_backup()
234
-    {
235
-        $files = $this->get_backup_archives_list();
236
-
237
-        if (is_array($files)) {
238
-            $this->sort_by($files, "timestamp", "desc");
239
-        }
240
-
241
-        $new_list = array();
242
-
243
-        foreach ($files as $key => $file) {
244
-            if (!isset($file['parent'])) {
245
-                $new_list[] = ($files[$key]);
246
-            }
247
-        }
248
-
249
-        if (isset($new_list[0])) {
250
-            return $new_list[0];
251
-        }
252
-    }
253
-
254
-    public function get_latest_backups()
255
-    {
256
-        $files = $this->get_backup_archives_list();
257
-
258
-        if (is_array($files)) {
259
-            $this->sort_by($files, "timestamp", "desc");
260
-        }
261
-
262
-        $new_list = array();
263
-
264
-        foreach ($files as $key => $file) {
265
-            if (!isset($file['parent'])) {
266
-                $new_list[] = ($files[$key]);
267
-            }
268
-        }
269
-
270
-        return $new_list;
271
-    }
272
-
273
-    public function get_storage_usage()
274
-    {
275
-        $files = $this->get_backup_archives_list();
276
-        $total = 0;
277
-
278
-        if (is_array($files)) {
279
-            foreach ($files as $file) {
280
-                $total += $file['size'];
281
-            }
282
-        }
283
-
284
-        return $total;
285
-    }
286
-
287
-    public function is_part($backup_name)
288
-    {
289
-        if (stristr($backup_name, "-part")) {
290
-            return true;
291
-        }
292
-
293
-        return false;
294
-    }
295
-
296
-    public function is_multipart($backup_name)
297
-    {
298
-        if (stristr($backup_name, "-multipart")) {
299
-            return true;
300
-        }
301
-
302
-        return false;
303
-    }
304
-
305
-    public function get_backup_size($backup_name)
306
-    {
307
-        $backup_size = $this->get_storage_filesystem()->getSize($backup_name);
308
-        if ($this->is_multipart($backup_name)) {
309
-            $backup_parts = $this->get_multipart_files($backup_name);
310
-            foreach ($backup_parts as $part_file) {
311
-                $backup_size += $this->get_storage_filesystem()->getSize($part_file);
312
-            }
313
-        }
314
-
315
-        return $backup_size;
316
-    }
317
-
318
-    public function get_multipart_files($backup_name, $storage_selection = "")
319
-    {
320
-        $files = array();
321
-
322
-        if ($this->is_multipart($backup_name)) {
323
-            $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
324
-            foreach ($lines as $line) {
325
-                if ($line) {
326
-                    $data = str_getcsv($line);
327
-                    $files[] = $data[0];
328
-                }
329
-            }
330
-        }
331
-
332
-        return $files;
333
-    }
334
-
335
-    public function delete_backup_by_name($backup_name, $storage_selection = "")
336
-    {
337
-        if ($this->is_multipart($backup_name)) {
338
-            $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
339
-            foreach ($lines as $line) {
340
-                if ($line) {
341
-                    $data = str_getcsv($line);
342
-                    $this->get_storage_filesystem($storage_selection)->delete($data[0]);
343
-                }
344
-            }
345
-        }
346
-
347
-        if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) {
348
-            $return = true;
349
-        } else {
350
-            $return = false;
351
-        }
352
-
353
-        return $return;
354
-    }
355
-
356
-    public function getMetadataFull($adapter = "storage_adapter", $path)
357
-    {
358
-        $location = $this->$adapter->applyPathPrefix($path);
359
-        $spl_info = new SplFileInfo($location);
360
-
361
-        return ($spl_info);
362
-    }
363
-
364
-
365
-    public function get_backup_archives_list($storage_selection = "")
366
-    {
367
-        $list = array();
368
-
369
-
370
-        if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) {
371
-            $list = $this->get_storage_filesystem($storage_selection)->listContents();
372
-        }
373
-
374
-        $backup_files = array();
375
-        $parents = array();
376
-
377
-        foreach ($list as $file_info) {
378
-            if (isset($file_info['extension']) and $file_info['extension'] == "csv") {
379
-                $data = array();
380
-
381
-                $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path']));
382
-                foreach ($lines as $line) {
383
-                    if ($line) {
384
-                        $data = str_getcsv($line);
385
-                        if (is_array($data)) {
386
-                            $parents[$data[0]] = $file_info['basename'];
387
-                            $file_info['childs'][] = $data;
388
-                            $file_info['size'] += $data[2];
389
-                        }
390
-                    }
391
-                }
392
-
393
-            }
394
-
395
-            if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'],
396
-                    $this->backup_archive_extensions)) {
397
-                $backup_files[$file_info['path']] = $file_info;
398
-            }
399
-        }
400
-
401
-        foreach ($backup_files as $key => $file_info) {
402
-            if (!isset($backup_files[$key]['timestamp'])) {
403
-                //$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']);
404
-            }
405
-
406
-            if (isset($parents[$file_info['basename']])) {
407
-                $backup_files[$key]['parent'] = $parents[$file_info['basename']];
408
-            }
409
-        }
410
-
411
-        return $backup_files;
412
-    }
413
-
414
-    public function start_file_recursion($init = 0)
415
-    {
416
-        if ($init) {
417
-            $this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"),
418
-                $this->xcloner_settings->get_xcloner_start_path()));
419
-            $this->do_system_init();
420
-        }
421
-
422
-        if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
423
-            //.dir exists, we presume we have files to iterate
424
-            $content = $this->tmp_filesystem->read($this->get_temp_dir_handler());
425
-            $files = array_filter(explode("\n", $content));
426
-            $this->tmp_filesystem->delete($this->get_temp_dir_handler());
427
-
428
-            $counter = 0;
429
-            foreach ($files as $file) {
430
-                if ($counter < $this->folders_to_process_per_session) {
431
-                    $this->build_files_list($file);
432
-                    $counter++;
433
-                } else {
434
-                    $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file . "\n");
435
-                }
436
-            }
437
-        } else {
438
-            $this->build_files_list();
439
-        }
440
-
441
-        if ($this->scan_finished()) {
442
-            $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html");
443
-            $this->store_file($metadata_dumpfile, 'tmp_filesystem');
444
-            $this->files_counter++;
445
-
446
-            //adding included dump file to the included files list
447
-            if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) {
448
-                $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler());
449
-                $this->store_file($metadata_dumpfile, 'tmp_filesystem');
450
-                $this->files_counter++;
451
-            }
452
-
453
-            //adding a default index.html to the temp xcloner folder
454
-            if (!$this->get_tmp_filesystem()->has("index.html")) {
455
-                $this->get_tmp_filesystem()->write("index.html", "");
456
-            }
457
-
458
-            //adding the default log file
459
-            if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) {
460
-                $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1));
461
-                $this->store_file($metadata_dumpfile, 'tmp_filesystem');
462
-                $this->files_counter++;
463
-            }
464
-
465
-            return false;
466
-        }
467
-
468
-        return true;
469
-    }
470
-
471
-    public function get_backup_attachments()
472
-    {
473
-        $return = array();
474
-
475
-        $files_list_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->get_included_files_handler();
476
-        if (file_exists($files_list_file)) {
477
-            $return[] = $files_list_file;
478
-        }
479
-
480
-        if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
481
-            $log_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->xcloner_settings->get_logger_filename(1);
482
-            if (!file_exists($log_file)) {
483
-                $log_file = $this->xcloner_settings->get_xcloner_store_path() . DS . $this->xcloner_settings->get_logger_filename();
484
-            }
485
-
486
-            if (file_exists($log_file)) {
487
-                $return[] = $log_file;
488
-            }
489
-        }
490
-
491
-        return $return;
492
-    }
493
-
494
-    public function remove_tmp_filesystem()
495
-    {
496
-        //delete the temporary folder
497
-        $this->logger->debug(sprintf("Deleting the temporary storage folder %s",
498
-            $this->xcloner_settings->get_xcloner_tmp_path()));
499
-
500
-        $contents = $this->get_tmp_filesystem()->listContents();
501
-
502
-        if (is_array($contents)) {
503
-            foreach ($contents as $file_info) {
504
-                $this->get_tmp_filesystem()->delete($file_info['path']);
505
-            }
506
-        }
507
-
508
-        @rmdir($this->xcloner_settings->get_xcloner_tmp_path());
509
-
510
-        return;
511
-    }
512
-
513
-    public function cleanup_tmp_directories()
514
-    {
515
-        $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
516
-        $tmp_filesystem = new Filesystem($adapter, new Config([
517
-            'disable_asserts' => true,
518
-        ]));
519
-
520
-        $contents = $tmp_filesystem->listContents();
521
-
522
-        foreach ($contents as $file) {
523
-
524
-            if (preg_match("/.xcloner-(.*)/", $file['path'])) {
525
-                if ($file['timestamp'] < strtotime("-1days")) {
526
-                    $tmp_filesystem->deleteDir($file['path']);
527
-                    $this->logger->debug(sprintf("Delete temporary directory %s", $file['path']));
528
-                }
529
-            }
530
-        }
531
-
532
-        return true;
533
-    }
534
-
535
-    private function do_system_init()
536
-    {
537
-        $this->files_counter = 0;
538
-
539
-        if (!$this->storage_filesystem->has("index.html")) {
540
-            $this->storage_filesystem->write("index.html", "");
541
-        }
542
-
543
-        if (!$this->tmp_filesystem->has("index.html")) {
544
-            $this->tmp_filesystem->write("index.html", "");
545
-        }
546
-
547
-        if ($this->tmp_filesystem->has($this->get_included_files_handler())) {
548
-            $this->tmp_filesystem->delete($this->get_included_files_handler());
549
-        }
550
-
551
-        if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
552
-            $this->tmp_filesystem->delete($this->get_temp_dir_handler());
553
-        }
554
-    }
555
-
556
-    public function get_scanned_files_num()
557
-    {
558
-        return $this->files_counter;
559
-    }
560
-
561
-    public function get_scanned_files_total_size()
562
-    {
563
-        return $this->files_size;
564
-    }
565
-
566
-    public function last_logged_file()
567
-    {
568
-        return $this->last_logged_file;
569
-    }
570
-
571
-    public static function is_regex($regex)
572
-    {
573
-        return preg_match("/^\^(.*)\$$/i", $regex);
574
-    }
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");
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
+	public function get_storage_path_file_info($file)
211
+	{
212
+		return $this->getMetadataFull('storage_adapter', $file);
213
+	}
214
+
215
+	public function get_included_files_handler($metadata = 0)
216
+	{
217
+		$path = $this->included_files_handler;
218
+		if (!$metadata) {
219
+			return $path;
220
+		}
221
+
222
+		$spl_info = $this->getMetadataFull('tmp_adapter', $path);
223
+
224
+		return $spl_info;
225
+
226
+	}
227
+
228
+	public function get_temp_dir_handler()
229
+	{
230
+		return $this->temp_dir_handler;
231
+	}
232
+
233
+	public function get_latest_backup()
234
+	{
235
+		$files = $this->get_backup_archives_list();
236
+
237
+		if (is_array($files)) {
238
+			$this->sort_by($files, "timestamp", "desc");
239
+		}
240
+
241
+		$new_list = array();
242
+
243
+		foreach ($files as $key => $file) {
244
+			if (!isset($file['parent'])) {
245
+				$new_list[] = ($files[$key]);
246
+			}
247
+		}
248
+
249
+		if (isset($new_list[0])) {
250
+			return $new_list[0];
251
+		}
252
+	}
253
+
254
+	public function get_latest_backups()
255
+	{
256
+		$files = $this->get_backup_archives_list();
257
+
258
+		if (is_array($files)) {
259
+			$this->sort_by($files, "timestamp", "desc");
260
+		}
261
+
262
+		$new_list = array();
263
+
264
+		foreach ($files as $key => $file) {
265
+			if (!isset($file['parent'])) {
266
+				$new_list[] = ($files[$key]);
267
+			}
268
+		}
269
+
270
+		return $new_list;
271
+	}
272
+
273
+	public function get_storage_usage()
274
+	{
275
+		$files = $this->get_backup_archives_list();
276
+		$total = 0;
277
+
278
+		if (is_array($files)) {
279
+			foreach ($files as $file) {
280
+				$total += $file['size'];
281
+			}
282
+		}
283
+
284
+		return $total;
285
+	}
286
+
287
+	public function is_part($backup_name)
288
+	{
289
+		if (stristr($backup_name, "-part")) {
290
+			return true;
291
+		}
292
+
293
+		return false;
294
+	}
295
+
296
+	public function is_multipart($backup_name)
297
+	{
298
+		if (stristr($backup_name, "-multipart")) {
299
+			return true;
300
+		}
301
+
302
+		return false;
303
+	}
304
+
305
+	public function get_backup_size($backup_name)
306
+	{
307
+		$backup_size = $this->get_storage_filesystem()->getSize($backup_name);
308
+		if ($this->is_multipart($backup_name)) {
309
+			$backup_parts = $this->get_multipart_files($backup_name);
310
+			foreach ($backup_parts as $part_file) {
311
+				$backup_size += $this->get_storage_filesystem()->getSize($part_file);
312
+			}
313
+		}
314
+
315
+		return $backup_size;
316
+	}
317
+
318
+	public function get_multipart_files($backup_name, $storage_selection = "")
319
+	{
320
+		$files = array();
321
+
322
+		if ($this->is_multipart($backup_name)) {
323
+			$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
324
+			foreach ($lines as $line) {
325
+				if ($line) {
326
+					$data = str_getcsv($line);
327
+					$files[] = $data[0];
328
+				}
329
+			}
330
+		}
331
+
332
+		return $files;
333
+	}
334
+
335
+	public function delete_backup_by_name($backup_name, $storage_selection = "")
336
+	{
337
+		if ($this->is_multipart($backup_name)) {
338
+			$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
339
+			foreach ($lines as $line) {
340
+				if ($line) {
341
+					$data = str_getcsv($line);
342
+					$this->get_storage_filesystem($storage_selection)->delete($data[0]);
343
+				}
344
+			}
345
+		}
346
+
347
+		if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) {
348
+			$return = true;
349
+		} else {
350
+			$return = false;
351
+		}
352
+
353
+		return $return;
354
+	}
355
+
356
+	public function getMetadataFull($adapter = "storage_adapter", $path)
357
+	{
358
+		$location = $this->$adapter->applyPathPrefix($path);
359
+		$spl_info = new SplFileInfo($location);
360
+
361
+		return ($spl_info);
362
+	}
363
+
364
+
365
+	public function get_backup_archives_list($storage_selection = "")
366
+	{
367
+		$list = array();
368
+
369
+
370
+		if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) {
371
+			$list = $this->get_storage_filesystem($storage_selection)->listContents();
372
+		}
373
+
374
+		$backup_files = array();
375
+		$parents = array();
376
+
377
+		foreach ($list as $file_info) {
378
+			if (isset($file_info['extension']) and $file_info['extension'] == "csv") {
379
+				$data = array();
380
+
381
+				$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path']));
382
+				foreach ($lines as $line) {
383
+					if ($line) {
384
+						$data = str_getcsv($line);
385
+						if (is_array($data)) {
386
+							$parents[$data[0]] = $file_info['basename'];
387
+							$file_info['childs'][] = $data;
388
+							$file_info['size'] += $data[2];
389
+						}
390
+					}
391
+				}
392
+
393
+			}
394
+
395
+			if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'],
396
+					$this->backup_archive_extensions)) {
397
+				$backup_files[$file_info['path']] = $file_info;
398
+			}
399
+		}
400
+
401
+		foreach ($backup_files as $key => $file_info) {
402
+			if (!isset($backup_files[$key]['timestamp'])) {
403
+				//$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']);
404
+			}
405
+
406
+			if (isset($parents[$file_info['basename']])) {
407
+				$backup_files[$key]['parent'] = $parents[$file_info['basename']];
408
+			}
409
+		}
410
+
411
+		return $backup_files;
412
+	}
413
+
414
+	public function start_file_recursion($init = 0)
415
+	{
416
+		if ($init) {
417
+			$this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"),
418
+				$this->xcloner_settings->get_xcloner_start_path()));
419
+			$this->do_system_init();
420
+		}
421
+
422
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
423
+			//.dir exists, we presume we have files to iterate
424
+			$content = $this->tmp_filesystem->read($this->get_temp_dir_handler());
425
+			$files = array_filter(explode("\n", $content));
426
+			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
427
+
428
+			$counter = 0;
429
+			foreach ($files as $file) {
430
+				if ($counter < $this->folders_to_process_per_session) {
431
+					$this->build_files_list($file);
432
+					$counter++;
433
+				} else {
434
+					$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file . "\n");
435
+				}
436
+			}
437
+		} else {
438
+			$this->build_files_list();
439
+		}
440
+
441
+		if ($this->scan_finished()) {
442
+			$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html");
443
+			$this->store_file($metadata_dumpfile, 'tmp_filesystem');
444
+			$this->files_counter++;
445
+
446
+			//adding included dump file to the included files list
447
+			if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) {
448
+				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler());
449
+				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
450
+				$this->files_counter++;
451
+			}
452
+
453
+			//adding a default index.html to the temp xcloner folder
454
+			if (!$this->get_tmp_filesystem()->has("index.html")) {
455
+				$this->get_tmp_filesystem()->write("index.html", "");
456
+			}
457
+
458
+			//adding the default log file
459
+			if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) {
460
+				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1));
461
+				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
462
+				$this->files_counter++;
463
+			}
464
+
465
+			return false;
466
+		}
467
+
468
+		return true;
469
+	}
470
+
471
+	public function get_backup_attachments()
472
+	{
473
+		$return = array();
474
+
475
+		$files_list_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->get_included_files_handler();
476
+		if (file_exists($files_list_file)) {
477
+			$return[] = $files_list_file;
478
+		}
479
+
480
+		if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
481
+			$log_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->xcloner_settings->get_logger_filename(1);
482
+			if (!file_exists($log_file)) {
483
+				$log_file = $this->xcloner_settings->get_xcloner_store_path() . DS . $this->xcloner_settings->get_logger_filename();
484
+			}
485
+
486
+			if (file_exists($log_file)) {
487
+				$return[] = $log_file;
488
+			}
489
+		}
490
+
491
+		return $return;
492
+	}
493
+
494
+	public function remove_tmp_filesystem()
495
+	{
496
+		//delete the temporary folder
497
+		$this->logger->debug(sprintf("Deleting the temporary storage folder %s",
498
+			$this->xcloner_settings->get_xcloner_tmp_path()));
499
+
500
+		$contents = $this->get_tmp_filesystem()->listContents();
501
+
502
+		if (is_array($contents)) {
503
+			foreach ($contents as $file_info) {
504
+				$this->get_tmp_filesystem()->delete($file_info['path']);
505
+			}
506
+		}
507
+
508
+		@rmdir($this->xcloner_settings->get_xcloner_tmp_path());
509
+
510
+		return;
511
+	}
512
+
513
+	public function cleanup_tmp_directories()
514
+	{
515
+		$adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
516
+		$tmp_filesystem = new Filesystem($adapter, new Config([
517
+			'disable_asserts' => true,
518
+		]));
519
+
520
+		$contents = $tmp_filesystem->listContents();
521
+
522
+		foreach ($contents as $file) {
523
+
524
+			if (preg_match("/.xcloner-(.*)/", $file['path'])) {
525
+				if ($file['timestamp'] < strtotime("-1days")) {
526
+					$tmp_filesystem->deleteDir($file['path']);
527
+					$this->logger->debug(sprintf("Delete temporary directory %s", $file['path']));
528
+				}
529
+			}
530
+		}
531
+
532
+		return true;
533
+	}
534
+
535
+	private function do_system_init()
536
+	{
537
+		$this->files_counter = 0;
538
+
539
+		if (!$this->storage_filesystem->has("index.html")) {
540
+			$this->storage_filesystem->write("index.html", "");
541
+		}
542
+
543
+		if (!$this->tmp_filesystem->has("index.html")) {
544
+			$this->tmp_filesystem->write("index.html", "");
545
+		}
546
+
547
+		if ($this->tmp_filesystem->has($this->get_included_files_handler())) {
548
+			$this->tmp_filesystem->delete($this->get_included_files_handler());
549
+		}
550
+
551
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
552
+			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
553
+		}
554
+	}
555
+
556
+	public function get_scanned_files_num()
557
+	{
558
+		return $this->files_counter;
559
+	}
560
+
561
+	public function get_scanned_files_total_size()
562
+	{
563
+		return $this->files_size;
564
+	}
565
+
566
+	public function last_logged_file()
567
+	{
568
+		return $this->last_logged_file;
569
+	}
570
+
571
+	public static function is_regex($regex)
572
+	{
573
+		return preg_match("/^\^(.*)\$$/i", $regex);
574
+	}
575 575
 
576
-    public function set_excluded_files($excluded_files = array())
577
-    {
578
-        if (!is_array($excluded_files)) {
579
-            $excluded_files = array();
580
-        }
576
+	public function set_excluded_files($excluded_files = array())
577
+	{
578
+		if (!is_array($excluded_files)) {
579
+			$excluded_files = array();
580
+		}
581 581
 
582
-        foreach ($excluded_files as $excl) {
582
+		foreach ($excluded_files as $excl) {
583 583
 
584
-            if ($this->is_regex($excl)) {
585
-                $this->additional_regex_patterns[] = $excl;
586
-            }
587
-        }
584
+			if ($this->is_regex($excl)) {
585
+				$this->additional_regex_patterns[] = $excl;
586
+			}
587
+		}
588 588
 
589
-        $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
589
+		$this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
590 590
 
591
-        return $this->excluded_files;
592
-    }
591
+		return $this->excluded_files;
592
+	}
593 593
 
594
-    public function get_excluded_files()
595
-    {
596
-        return $this->excluded_files_by_default;
597
-    }
594
+	public function get_excluded_files()
595
+	{
596
+		return $this->excluded_files_by_default;
597
+	}
598 598
 
599
-    public function list_directory($path)
600
-    {
601
-        return $this->start_filesystem->listContents($path);
602
-    }
599
+	public function list_directory($path)
600
+	{
601
+		return $this->start_filesystem->listContents($path);
602
+	}
603 603
 
604
-    public function build_files_list($folder = "")
605
-    {
606
-        $this->logger->debug(sprintf(("Building the files system list")));
604
+	public function build_files_list($folder = "")
605
+	{
606
+		$this->logger->debug(sprintf(("Building the files system list")));
607 607
 
608
-        //if we start with the root folder(empty value), we initializa the file system
609
-        if (!$folder) {
608
+		//if we start with the root folder(empty value), we initializa the file system
609
+		if (!$folder) {
610 610
 
611
-        }
611
+		}
612 612
 
613
-        try {
613
+		try {
614 614
 
615
-            $files = $this->start_filesystem->listContents($folder);
616
-            foreach ($files as $file) {
617
-                if (!is_readable($this->xcloner_settings->get_xcloner_start_path() . DS . $file['path'])) {
618
-                    $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"),
619
-                        $file['path']), array(
620
-                        "FILESYSTEM SCAN",
621
-                        "NOT READABLE"
622
-                    ));
623
-                } elseif (!$matching_pattern = $this->is_excluded($file)) {
624
-                    $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array(
625
-                        "FILESYSTEM SCAN",
626
-                        "INCLUDE"
627
-                    ));
628
-                    $file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
629
-                    if ($this->store_file($file)) {
630
-                        $this->files_counter++;
631
-                    }
632
-                    if (isset($file['size'])) {
633
-                        $this->files_size += $file['size'];
634
-                    }
635
-
636
-                } else {
637
-                    $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"),
638
-                        $file['path'], $matching_pattern), array(
639
-                        "FILESYSTEM SCAN",
640
-                        "EXCLUDE"
641
-                    ));
642
-                }
643
-            }
615
+			$files = $this->start_filesystem->listContents($folder);
616
+			foreach ($files as $file) {
617
+				if (!is_readable($this->xcloner_settings->get_xcloner_start_path() . DS . $file['path'])) {
618
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"),
619
+						$file['path']), array(
620
+						"FILESYSTEM SCAN",
621
+						"NOT READABLE"
622
+					));
623
+				} elseif (!$matching_pattern = $this->is_excluded($file)) {
624
+					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array(
625
+						"FILESYSTEM SCAN",
626
+						"INCLUDE"
627
+					));
628
+					$file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
629
+					if ($this->store_file($file)) {
630
+						$this->files_counter++;
631
+					}
632
+					if (isset($file['size'])) {
633
+						$this->files_size += $file['size'];
634
+					}
635
+
636
+				} else {
637
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"),
638
+						$file['path'], $matching_pattern), array(
639
+						"FILESYSTEM SCAN",
640
+						"EXCLUDE"
641
+					));
642
+				}
643
+			}
644 644
 
645
-        } catch (Exception $e) {
645
+		} catch (Exception $e) {
646 646
 
647
-            $this->logger->error($e->getMessage());
647
+			$this->logger->error($e->getMessage());
648 648
 
649
-        }
649
+		}
650 650
 
651
-    }
651
+	}
652 652
 
653
-    public function estimate_read_write_time()
654
-    {
655
-        $tmp_file = ".xcloner" . substr(md5(time()), 0, 5);
653
+	public function estimate_read_write_time()
654
+	{
655
+		$tmp_file = ".xcloner" . substr(md5(time()), 0, 5);
656 656
 
657
-        $start_time = microtime(true);
657
+		$start_time = microtime(true);
658 658
 
659
-        $data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data
659
+		$data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data
660 660
 
661
-        try {
662
-            $this->tmp_filesystem->write($tmp_file, $data);
661
+		try {
662
+			$this->tmp_filesystem->write($tmp_file, $data);
663 663
 
664
-            $end_time = microtime(true) - $start_time;
664
+			$end_time = microtime(true) - $start_time;
665 665
 
666
-            $return['writing_time'] = $end_time;
666
+			$return['writing_time'] = $end_time;
667 667
 
668
-            $return['reading_time'] = $this->estimate_reading_time($tmp_file);
668
+			$return['reading_time'] = $this->estimate_reading_time($tmp_file);
669 669
 
670
-            $this->tmp_filesystem->delete($tmp_file);
670
+			$this->tmp_filesystem->delete($tmp_file);
671 671
 
672
-        } catch (Exception $e) {
672
+		} catch (Exception $e) {
673 673
 
674
-            $this->logger->error($e->getMessage());
674
+			$this->logger->error($e->getMessage());
675 675
 
676
-        }
676
+		}
677 677
 
678
-        return $return;
679
-    }
678
+		return $return;
679
+	}
680 680
 
681
-    public function backup_storage_cleanup()
682
-    {
683
-        $this->logger->info(sprintf(("Cleaning the backup storage on matching rules")));
681
+	public function backup_storage_cleanup()
682
+	{
683
+		$this->logger->info(sprintf(("Cleaning the backup storage on matching rules")));
684 684
 
685
-        $_storage_size = 0;
686
-        $_backup_files_list = array();
685
+		$_storage_size = 0;
686
+		$_backup_files_list = array();
687 687
 
688
-        //rule date limit
689
-        $current_timestamp = strtotime("-" . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') . " days");
688
+		//rule date limit
689
+		$current_timestamp = strtotime("-" . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') . " days");
690 690
 
691
-        $files = $this->storage_filesystem->listContents();
691
+		$files = $this->storage_filesystem->listContents();
692 692
 
693
-        if (is_array($files)) {
694
-            foreach ($files as $file) {
695
-                if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) {
696
-                    $_storage_size += $file['size']; //bytes
697
-                    $_backup_files_list[] = $file;
698
-                }
699
-            }
700
-        }
693
+		if (is_array($files)) {
694
+			foreach ($files as $file) {
695
+				if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) {
696
+					$_storage_size += $file['size']; //bytes
697
+					$_backup_files_list[] = $file;
698
+				}
699
+			}
700
+		}
701 701
 
702 702
 
703
-        $this->sort_by($_backup_files_list, "timestamp", "asc");
703
+		$this->sort_by($_backup_files_list, "timestamp", "asc");
704 704
 
705
-        $_backups_counter = sizeof($_backup_files_list);
705
+		$_backups_counter = sizeof($_backup_files_list);
706 706
 
707
-        foreach ($_backup_files_list as $file) {
708
-            //processing rule folder capacity
709
-            if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
710
-                $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))    //bytes
711
-            {
712
-                $this->storage_filesystem->delete($file['path']);
713
-                $_storage_size -= $file['size'];
714
-                $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
715
-                    "STORAGE SIZE LIMIT",
716
-                    $_storage_size . " >= " . $set_storage_limit
717
-                ));
718
-            }
719
-
720
-            //processing rule days limit
721
-            if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) {
722
-                $this->storage_filesystem->delete($file['path']);
723
-                $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
724
-                    "RETENTION LIMIT TIMESTAMP",
725
-                    $file['timestamp'] . " =< " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')
726
-                ));
727
-            }
728
-
729
-            //processing backup countert limit
730
-            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')) {
731
-                $this->storage_filesystem->delete($file['path']);
732
-                $_backups_counter--;
733
-                $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
734
-                    "BACKUP QUANTITY LIMIT",
735
-                    $_backups_counter . " >= " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')
736
-                ));
737
-            }
707
+		foreach ($_backup_files_list as $file) {
708
+			//processing rule folder capacity
709
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
710
+				$_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))    //bytes
711
+			{
712
+				$this->storage_filesystem->delete($file['path']);
713
+				$_storage_size -= $file['size'];
714
+				$this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
715
+					"STORAGE SIZE LIMIT",
716
+					$_storage_size . " >= " . $set_storage_limit
717
+				));
718
+			}
719
+
720
+			//processing rule days limit
721
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) {
722
+				$this->storage_filesystem->delete($file['path']);
723
+				$this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
724
+					"RETENTION LIMIT TIMESTAMP",
725
+					$file['timestamp'] . " =< " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')
726
+				));
727
+			}
728
+
729
+			//processing backup countert limit
730
+			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')) {
731
+				$this->storage_filesystem->delete($file['path']);
732
+				$_backups_counter--;
733
+				$this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
734
+					"BACKUP QUANTITY LIMIT",
735
+					$_backups_counter . " >= " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')
736
+				));
737
+			}
738 738
 
739 739
 
740
-        }
740
+		}
741 741
 
742
-    }
742
+	}
743 743
 
744
-    public function estimate_reading_time($tmp_file)
745
-    {
746
-        $this->logger->debug(sprintf(("Estimating file system reading time")));
744
+	public function estimate_reading_time($tmp_file)
745
+	{
746
+		$this->logger->debug(sprintf(("Estimating file system reading time")));
747 747
 
748
-        $start_time = microtime(true);
748
+		$start_time = microtime(true);
749 749
 
750
-        if ($this->tmp_filesystem->has($tmp_file)) {
751
-            $this->tmp_filesystem->read($tmp_file);
752
-        }
753
-
754
-        $end_time = microtime(true) - $start_time;
755
-
756
-        return $end_time;
757
-
758
-    }
759
-
760
-    public function process_backup_name($name = "", $max_length = 100)
761
-    {
762
-        if (!$name) {
763
-            $name = $this->xcloner_settings->get_default_backup_name();
764
-        }
765
-
766
-        foreach ($this->backup_name_tags as $tag) {
767
-            if ($tag == '[time]') {
768
-                $name = str_replace($tag, date("Y-m-d_H-i"), $name);
769
-            } elseif ($tag == '[hostname]') {
770
-                $name = str_replace($tag, gethostname(), $name);
771
-            } elseif ($tag == '[domain]') {
772
-                $domain = parse_url(admin_url(), PHP_URL_HOST);
773
-                $name = str_replace($tag, $domain, $name);
774
-            }
775
-        }
776
-
777
-        if ($max_length) {
778
-            $name = substr($name, 0, $max_length);
779
-        }
780
-
781
-        return $name;
782
-    }
783
-
784
-    public function sort_by(&$array, $field, $direction = 'asc')
785
-    {
786
-        if (strtolower($direction) == "desc" || $direction == SORT_DESC) {
787
-            $direction = SORT_DESC;
788
-        } else {
789
-            $direction = SORT_ASC;
790
-        }
791
-
792
-        $array = $this->array_orderby($array, $field, $direction);
793
-
794
-        return true;
795
-    }
796
-
797
-    private function array_orderby()
798
-    {
799
-        $args = func_get_args();
800
-        $data = array_shift($args);
801
-
802
-        foreach ($args as $n => $field) {
803
-            if (is_string($field)) {
804
-                $tmp = array();
805
-                foreach ($data as $key => $row) {
806
-                    if (is_array($row)) {
807
-                        $tmp[$key] = $row[$field];
808
-                    } else {
809
-                        $tmp[$key] = $row->$field;
810
-                    }
811
-                }
812
-                $args[$n] = $tmp;
813
-            }
814
-        }
815
-        $args[] = &$data;
816
-
817
-        call_user_func_array('array_multisort', $args);
818
-
819
-        return array_pop($args);
820
-    }
821
-
822
-    private function check_file_diff_time($file)
823
-    {
824
-        if ($this->get_diff_timestamp_start() != "") {
825
-            $fileMeta = $this->getMetadataFull("start_adapter", $file['path']);
826
-            $timestamp = $fileMeta->getMTime();
827
-            if ($timestamp < $fileMeta->getCTime()) {
828
-                $timestamp = $fileMeta->getCTime();
829
-            }
830
-
831
-            if ($timestamp <= $this->get_diff_timestamp_start()) {
832
-                return " file DIFF timestamp " . $timestamp . " < " . $this->diff_timestamp_start;
833
-            }
834
-        }
835
-
836
-        return false;
837
-    }
838
-
839
-    public function is_excluded($file)
840
-    {
841
-        $this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
842
-
843
-        if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) {
844
-            if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) {
845
-                return "> " . $xcloner_exclude_files_larger_than_mb . "MB";
846
-            }
847
-        }
848
-
849
-        if (!is_array($this->excluded_files) || !sizeof($this->excluded_files)) {
850
-            $this->set_excluded_files();
851
-        }
852
-
853
-        if (is_array($this->excluded_files)) {
854
-            foreach ($this->excluded_files as $excluded_file_pattern) {
855
-                if ($excluded_file_pattern == "/") {
856
-                    $needle = "$";
857
-                } else {
858
-                    $needle = "$" . $excluded_file_pattern;
859
-                }
860
-
861
-                if (strstr("$" . $file['path'], $needle)) {
862
-                    return $excluded_file_pattern;
863
-                }
864
-            }
865
-        }
866
-
867
-        if ($regex = $this->is_excluded_regex($file)) {
868
-            return $regex;
869
-        }
870
-
871
-        if ($file['type'] == "file") {
872
-            $check_file_diff_timestamp = $this->check_file_diff_time($file);
873
-            if ($check_file_diff_timestamp) {
874
-                return $check_file_diff_timestamp;
875
-            }
876
-        }
877
-
878
-        return false;
879
-    }
880
-
881
-    /*REGEX examples
750
+		if ($this->tmp_filesystem->has($tmp_file)) {
751
+			$this->tmp_filesystem->read($tmp_file);
752
+		}
753
+
754
+		$end_time = microtime(true) - $start_time;
755
+
756
+		return $end_time;
757
+
758
+	}
759
+
760
+	public function process_backup_name($name = "", $max_length = 100)
761
+	{
762
+		if (!$name) {
763
+			$name = $this->xcloner_settings->get_default_backup_name();
764
+		}
765
+
766
+		foreach ($this->backup_name_tags as $tag) {
767
+			if ($tag == '[time]') {
768
+				$name = str_replace($tag, date("Y-m-d_H-i"), $name);
769
+			} elseif ($tag == '[hostname]') {
770
+				$name = str_replace($tag, gethostname(), $name);
771
+			} elseif ($tag == '[domain]') {
772
+				$domain = parse_url(admin_url(), PHP_URL_HOST);
773
+				$name = str_replace($tag, $domain, $name);
774
+			}
775
+		}
776
+
777
+		if ($max_length) {
778
+			$name = substr($name, 0, $max_length);
779
+		}
780
+
781
+		return $name;
782
+	}
783
+
784
+	public function sort_by(&$array, $field, $direction = 'asc')
785
+	{
786
+		if (strtolower($direction) == "desc" || $direction == SORT_DESC) {
787
+			$direction = SORT_DESC;
788
+		} else {
789
+			$direction = SORT_ASC;
790
+		}
791
+
792
+		$array = $this->array_orderby($array, $field, $direction);
793
+
794
+		return true;
795
+	}
796
+
797
+	private function array_orderby()
798
+	{
799
+		$args = func_get_args();
800
+		$data = array_shift($args);
801
+
802
+		foreach ($args as $n => $field) {
803
+			if (is_string($field)) {
804
+				$tmp = array();
805
+				foreach ($data as $key => $row) {
806
+					if (is_array($row)) {
807
+						$tmp[$key] = $row[$field];
808
+					} else {
809
+						$tmp[$key] = $row->$field;
810
+					}
811
+				}
812
+				$args[$n] = $tmp;
813
+			}
814
+		}
815
+		$args[] = &$data;
816
+
817
+		call_user_func_array('array_multisort', $args);
818
+
819
+		return array_pop($args);
820
+	}
821
+
822
+	private function check_file_diff_time($file)
823
+	{
824
+		if ($this->get_diff_timestamp_start() != "") {
825
+			$fileMeta = $this->getMetadataFull("start_adapter", $file['path']);
826
+			$timestamp = $fileMeta->getMTime();
827
+			if ($timestamp < $fileMeta->getCTime()) {
828
+				$timestamp = $fileMeta->getCTime();
829
+			}
830
+
831
+			if ($timestamp <= $this->get_diff_timestamp_start()) {
832
+				return " file DIFF timestamp " . $timestamp . " < " . $this->diff_timestamp_start;
833
+			}
834
+		}
835
+
836
+		return false;
837
+	}
838
+
839
+	public function is_excluded($file)
840
+	{
841
+		$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
842
+
843
+		if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) {
844
+			if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) {
845
+				return "> " . $xcloner_exclude_files_larger_than_mb . "MB";
846
+			}
847
+		}
848
+
849
+		if (!is_array($this->excluded_files) || !sizeof($this->excluded_files)) {
850
+			$this->set_excluded_files();
851
+		}
852
+
853
+		if (is_array($this->excluded_files)) {
854
+			foreach ($this->excluded_files as $excluded_file_pattern) {
855
+				if ($excluded_file_pattern == "/") {
856
+					$needle = "$";
857
+				} else {
858
+					$needle = "$" . $excluded_file_pattern;
859
+				}
860
+
861
+				if (strstr("$" . $file['path'], $needle)) {
862
+					return $excluded_file_pattern;
863
+				}
864
+			}
865
+		}
866
+
867
+		if ($regex = $this->is_excluded_regex($file)) {
868
+			return $regex;
869
+		}
870
+
871
+		if ($file['type'] == "file") {
872
+			$check_file_diff_timestamp = $this->check_file_diff_time($file);
873
+			if ($check_file_diff_timestamp) {
874
+				return $check_file_diff_timestamp;
875
+			}
876
+		}
877
+
878
+		return false;
879
+	}
880
+
881
+	/*REGEX examples
882 882
      *
883 883
     * exclude all except .php file
884 884
     * PATTERN: ^(.*)\.(.+)$(?<!(php))
@@ -910,163 +910,163 @@  discard block
 block discarded – undo
910 910
     * exclude the backup folders
911 911
     * PATTERN: (^|^\/)(wp-content\/backups|administrator\/backups)(.*)$";
912 912
     */
913
-    private function is_excluded_regex($file)
914
-    {
915
-        //$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
916
-
917
-        $regex_patterns = explode(PHP_EOL, $this->xcloner_settings->get_xcloner_option('xcloner_regex_exclude'));
918
-
919
-        if (is_array($this->additional_regex_patterns)) {
920
-            $regex_patterns = array_merge($regex_patterns, $this->additional_regex_patterns);
921
-        }
922
-
923
-        //print_r($regex_patterns);exit;
924
-
925
-        if (is_array($regex_patterns)) {
926
-            //$this->excluded_files = array();
927
-            //$this->excluded_files[] ="(.*)\.(git)(.*)$";
928
-            //$this->excluded_files[] ="wp-content\/backups(.*)$";
929
-
930
-            foreach ($regex_patterns as $excluded_file_pattern) {
931
-
932
-                if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1,
933
-                        strlen($excluded_file_pattern)) == "\r") {
934
-                    $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1);
935
-                }
936
-
937
-                if ($file['path'] == "/") {
938
-                    $needle = "/";
939
-                } else {
940
-                    $needle = "/" . $file['path'];
941
-                }
942
-                //echo $needle."---".$excluded_file_pattern."---\n";
943
-
944
-                if (@preg_match("/(^|^\/)" . $excluded_file_pattern . "/i", $needle)) {
945
-                    return $excluded_file_pattern;
946
-                }
947
-            }
948
-        }
949
-
950
-        return false;
951
-    }
952
-
953
-    public function store_file($file, $storage = 'start_filesystem')
954
-    {
955
-        $this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
956
-
957
-        if (!isset($file['size'])) {
958
-            $file['size'] = 0;
959
-        }
960
-        if (!isset($file['visibility'])) {
961
-            $file['visibility'] = "private";
962
-        }
963
-
964
-        $csv_filename = str_replace('"', '""', $file['path']);
965
-
966
-        $line = '"' . ($csv_filename) . '","' . $file['timestamp'] . '","' . $file['size'] . '","' . $file['visibility'] . '","' . $storage . '"' . PHP_EOL;
967
-
968
-        $this->last_logged_file = $file['path'];
969
-
970
-        if ($file['type'] == "dir") {
971
-            try {
972
-                $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path'] . "\n");
973
-            } catch (Exception $e) {
974
-                $this->logger->error($e->getMessage());
975
-            }
976
-        }
977
-
978
-        if ($this->get_diff_timestamp_start()) {
979
-            if ($file['type'] != "file" && $response = $this->check_file_diff_time($file)) {
980
-                $this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'],
981
-                    $response), array(
982
-                    "FILESYSTEM SCAN",
983
-                    "DIR DIFF"
984
-                ));
985
-
986
-                return false;
987
-            }
988
-        }
989
-
990
-        try {
991
-            if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) {
992
-                //adding fix for UTF-8 CSV preview
993
-                $start_line = "\xEF\xBB\xBF" . '"Filename","Timestamp","Size","Visibility","Storage"' . PHP_EOL;
994
-                $this->tmp_filesystem_append->write($this->get_included_files_handler(), $start_line);
995
-            }
996
-
997
-            $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
998
-
999
-        } catch (Exception $e) {
1000
-
1001
-            $this->logger->error($e->getMessage());
1002
-        }
1003
-
1004
-        return true;
1005
-    }
1006
-
1007
-    public function get_fileystem_handler()
1008
-    {
1009
-        return $this;
1010
-    }
1011
-
1012
-    public function get_filesystem($system = "")
1013
-    {
1014
-        if ($system == "storage_filesystem_append") {
1015
-            return $this->storage_filesystem_append;
1016
-        } elseif ($system == "tmp_filesystem_append") {
1017
-            return $this->tmp_filesystem_append;
1018
-        } elseif ($system == "tmp_filesystem") {
1019
-            return $this->tmp_filesystem;
1020
-        } elseif ($system == "storage_filesystem") {
1021
-            return $this->storage_filesystem;
1022
-        } else {
1023
-            return $this->start_filesystem;
1024
-        }
1025
-    }
1026
-
1027
-    public function get_adapter($system)
1028
-    {
1029
-        if ($system == "tmp_filesystem") {
1030
-            return $this->tmp_adapter;
1031
-        } elseif ($system == "storage_filesystem") {
1032
-            return $this->storage_adapter;
1033
-        } else {
1034
-            return $this->start_adapter;
1035
-        }
1036
-    }
1037
-
1038
-    /**
1039
-     * File scan finished
1040
-     * Method called when file scan is finished
1041
-     *
1042
-     * @return bool
1043
-     */
1044
-    private function scan_finished()
1045
-    {
1046
-        if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) &&
1047
-            $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) {
1048
-            return false;
1049
-        }
1050
-
1051
-        if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
1052
-            $this->tmp_filesystem->delete($this->get_temp_dir_handler());
1053
-        }
1054
-
1055
-        $this->logger->debug(sprintf(("File scan finished")));
1056
-
1057
-        return true;
1058
-    }
1059
-
1060
-    /**
1061
-     * Calculate bytes from MB value
1062
-     *
1063
-     * @param int $mb_size
1064
-     *
1065
-     * @return float|int
1066
-     */
1067
-    private function calc_to_bytes($mb_size)
1068
-    {
1069
-        return $mb_size * (1024 * 1024);
1070
-    }
913
+	private function is_excluded_regex($file)
914
+	{
915
+		//$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
916
+
917
+		$regex_patterns = explode(PHP_EOL, $this->xcloner_settings->get_xcloner_option('xcloner_regex_exclude'));
918
+
919
+		if (is_array($this->additional_regex_patterns)) {
920
+			$regex_patterns = array_merge($regex_patterns, $this->additional_regex_patterns);
921
+		}
922
+
923
+		//print_r($regex_patterns);exit;
924
+
925
+		if (is_array($regex_patterns)) {
926
+			//$this->excluded_files = array();
927
+			//$this->excluded_files[] ="(.*)\.(git)(.*)$";
928
+			//$this->excluded_files[] ="wp-content\/backups(.*)$";
929
+
930
+			foreach ($regex_patterns as $excluded_file_pattern) {
931
+
932
+				if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1,
933
+						strlen($excluded_file_pattern)) == "\r") {
934
+					$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1);
935
+				}
936
+
937
+				if ($file['path'] == "/") {
938
+					$needle = "/";
939
+				} else {
940
+					$needle = "/" . $file['path'];
941
+				}
942
+				//echo $needle."---".$excluded_file_pattern."---\n";
943
+
944
+				if (@preg_match("/(^|^\/)" . $excluded_file_pattern . "/i", $needle)) {
945
+					return $excluded_file_pattern;
946
+				}
947
+			}
948
+		}
949
+
950
+		return false;
951
+	}
952
+
953
+	public function store_file($file, $storage = 'start_filesystem')
954
+	{
955
+		$this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
956
+
957
+		if (!isset($file['size'])) {
958
+			$file['size'] = 0;
959
+		}
960
+		if (!isset($file['visibility'])) {
961
+			$file['visibility'] = "private";
962
+		}
963
+
964
+		$csv_filename = str_replace('"', '""', $file['path']);
965
+
966
+		$line = '"' . ($csv_filename) . '","' . $file['timestamp'] . '","' . $file['size'] . '","' . $file['visibility'] . '","' . $storage . '"' . PHP_EOL;
967
+
968
+		$this->last_logged_file = $file['path'];
969
+
970
+		if ($file['type'] == "dir") {
971
+			try {
972
+				$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path'] . "\n");
973
+			} catch (Exception $e) {
974
+				$this->logger->error($e->getMessage());
975
+			}
976
+		}
977
+
978
+		if ($this->get_diff_timestamp_start()) {
979
+			if ($file['type'] != "file" && $response = $this->check_file_diff_time($file)) {
980
+				$this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'],
981
+					$response), array(
982
+					"FILESYSTEM SCAN",
983
+					"DIR DIFF"
984
+				));
985
+
986
+				return false;
987
+			}
988
+		}
989
+
990
+		try {
991
+			if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) {
992
+				//adding fix for UTF-8 CSV preview
993
+				$start_line = "\xEF\xBB\xBF" . '"Filename","Timestamp","Size","Visibility","Storage"' . PHP_EOL;
994
+				$this->tmp_filesystem_append->write($this->get_included_files_handler(), $start_line);
995
+			}
996
+
997
+			$this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
998
+
999
+		} catch (Exception $e) {
1000
+
1001
+			$this->logger->error($e->getMessage());
1002
+		}
1003
+
1004
+		return true;
1005
+	}
1006
+
1007
+	public function get_fileystem_handler()
1008
+	{
1009
+		return $this;
1010
+	}
1011
+
1012
+	public function get_filesystem($system = "")
1013
+	{
1014
+		if ($system == "storage_filesystem_append") {
1015
+			return $this->storage_filesystem_append;
1016
+		} elseif ($system == "tmp_filesystem_append") {
1017
+			return $this->tmp_filesystem_append;
1018
+		} elseif ($system == "tmp_filesystem") {
1019
+			return $this->tmp_filesystem;
1020
+		} elseif ($system == "storage_filesystem") {
1021
+			return $this->storage_filesystem;
1022
+		} else {
1023
+			return $this->start_filesystem;
1024
+		}
1025
+	}
1026
+
1027
+	public function get_adapter($system)
1028
+	{
1029
+		if ($system == "tmp_filesystem") {
1030
+			return $this->tmp_adapter;
1031
+		} elseif ($system == "storage_filesystem") {
1032
+			return $this->storage_adapter;
1033
+		} else {
1034
+			return $this->start_adapter;
1035
+		}
1036
+	}
1037
+
1038
+	/**
1039
+	 * File scan finished
1040
+	 * Method called when file scan is finished
1041
+	 *
1042
+	 * @return bool
1043
+	 */
1044
+	private function scan_finished()
1045
+	{
1046
+		if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) &&
1047
+			$this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) {
1048
+			return false;
1049
+		}
1050
+
1051
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
1052
+			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
1053
+		}
1054
+
1055
+		$this->logger->debug(sprintf(("File scan finished")));
1056
+
1057
+		return true;
1058
+	}
1059
+
1060
+	/**
1061
+	 * Calculate bytes from MB value
1062
+	 *
1063
+	 * @param int $mb_size
1064
+	 *
1065
+	 * @return float|int
1066
+	 */
1067
+	private function calc_to_bytes($mb_size)
1068
+	{
1069
+		return $mb_size * (1024 * 1024);
1070
+	}
1071 1071
 
1072 1072
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -102,8 +102,8 @@  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) {
106
-            $this->logger->error("Filesystem Initialization Error: " . $e->getMessage());
105
+        }catch (Exception $e) {
106
+            $this->logger->error("Filesystem Initialization Error: ".$e->getMessage());
107 107
         }
108 108
 
109 109
 
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
     {
162 162
         if ($remote_storage_selection != "") {
163 163
             $remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
164
-            $method = "get_" . $remote_storage_selection . "_filesystem";
164
+            $method = "get_".$remote_storage_selection."_filesystem";
165 165
 
166 166
             if (!method_exists($remote_storage, $method)) {
167 167
                 return false;
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
                     $this->build_files_list($file);
432 432
                     $counter++;
433 433
                 } else {
434
-                    $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file . "\n");
434
+                    $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n");
435 435
                 }
436 436
             }
437 437
         } else {
@@ -472,15 +472,15 @@  discard block
 block discarded – undo
472 472
     {
473 473
         $return = array();
474 474
 
475
-        $files_list_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->get_included_files_handler();
475
+        $files_list_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler();
476 476
         if (file_exists($files_list_file)) {
477 477
             $return[] = $files_list_file;
478 478
         }
479 479
 
480 480
         if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
481
-            $log_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->xcloner_settings->get_logger_filename(1);
481
+            $log_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
482 482
             if (!file_exists($log_file)) {
483
-                $log_file = $this->xcloner_settings->get_xcloner_store_path() . DS . $this->xcloner_settings->get_logger_filename();
483
+                $log_file = $this->xcloner_settings->get_xcloner_store_path().DS.$this->xcloner_settings->get_logger_filename();
484 484
             }
485 485
 
486 486
             if (file_exists($log_file)) {
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
 
615 615
             $files = $this->start_filesystem->listContents($folder);
616 616
             foreach ($files as $file) {
617
-                if (!is_readable($this->xcloner_settings->get_xcloner_start_path() . DS . $file['path'])) {
617
+                if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) {
618 618
                     $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"),
619 619
                         $file['path']), array(
620 620
                         "FILESYSTEM SCAN",
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
                 }
643 643
             }
644 644
 
645
-        } catch (Exception $e) {
645
+        }catch (Exception $e) {
646 646
 
647 647
             $this->logger->error($e->getMessage());
648 648
 
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
 
653 653
     public function estimate_read_write_time()
654 654
     {
655
-        $tmp_file = ".xcloner" . substr(md5(time()), 0, 5);
655
+        $tmp_file = ".xcloner".substr(md5(time()), 0, 5);
656 656
 
657 657
         $start_time = microtime(true);
658 658
 
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
 
670 670
             $this->tmp_filesystem->delete($tmp_file);
671 671
 
672
-        } catch (Exception $e) {
672
+        }catch (Exception $e) {
673 673
 
674 674
             $this->logger->error($e->getMessage());
675 675
 
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
         $_backup_files_list = array();
687 687
 
688 688
         //rule date limit
689
-        $current_timestamp = strtotime("-" . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') . " days");
689
+        $current_timestamp = strtotime("-".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')." days");
690 690
 
691 691
         $files = $this->storage_filesystem->listContents();
692 692
 
@@ -711,18 +711,18 @@  discard block
 block discarded – undo
711 711
             {
712 712
                 $this->storage_filesystem->delete($file['path']);
713 713
                 $_storage_size -= $file['size'];
714
-                $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
714
+                $this->logger->info("Deleting backup ".$file['path']." matching rule", array(
715 715
                     "STORAGE SIZE LIMIT",
716
-                    $_storage_size . " >= " . $set_storage_limit
716
+                    $_storage_size." >= ".$set_storage_limit
717 717
                 ));
718 718
             }
719 719
 
720 720
             //processing rule days limit
721 721
             if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) {
722 722
                 $this->storage_filesystem->delete($file['path']);
723
-                $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
723
+                $this->logger->info("Deleting backup ".$file['path']." matching rule", array(
724 724
                     "RETENTION LIMIT TIMESTAMP",
725
-                    $file['timestamp'] . " =< " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')
725
+                    $file['timestamp']." =< ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')
726 726
                 ));
727 727
             }
728 728
 
@@ -730,9 +730,9 @@  discard block
 block discarded – undo
730 730
             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')) {
731 731
                 $this->storage_filesystem->delete($file['path']);
732 732
                 $_backups_counter--;
733
-                $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
733
+                $this->logger->info("Deleting backup ".$file['path']." matching rule", array(
734 734
                     "BACKUP QUANTITY LIMIT",
735
-                    $_backups_counter . " >= " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')
735
+                    $_backups_counter." >= ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')
736 736
                 ));
737 737
             }
738 738
 
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
             }
830 830
 
831 831
             if ($timestamp <= $this->get_diff_timestamp_start()) {
832
-                return " file DIFF timestamp " . $timestamp . " < " . $this->diff_timestamp_start;
832
+                return " file DIFF timestamp ".$timestamp." < ".$this->diff_timestamp_start;
833 833
             }
834 834
         }
835 835
 
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
 
843 843
         if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) {
844 844
             if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) {
845
-                return "> " . $xcloner_exclude_files_larger_than_mb . "MB";
845
+                return "> ".$xcloner_exclude_files_larger_than_mb."MB";
846 846
             }
847 847
         }
848 848
 
@@ -855,10 +855,10 @@  discard block
 block discarded – undo
855 855
                 if ($excluded_file_pattern == "/") {
856 856
                     $needle = "$";
857 857
                 } else {
858
-                    $needle = "$" . $excluded_file_pattern;
858
+                    $needle = "$".$excluded_file_pattern;
859 859
                 }
860 860
 
861
-                if (strstr("$" . $file['path'], $needle)) {
861
+                if (strstr("$".$file['path'], $needle)) {
862 862
                     return $excluded_file_pattern;
863 863
                 }
864 864
             }
@@ -937,11 +937,11 @@  discard block
 block discarded – undo
937 937
                 if ($file['path'] == "/") {
938 938
                     $needle = "/";
939 939
                 } else {
940
-                    $needle = "/" . $file['path'];
940
+                    $needle = "/".$file['path'];
941 941
                 }
942 942
                 //echo $needle."---".$excluded_file_pattern."---\n";
943 943
 
944
-                if (@preg_match("/(^|^\/)" . $excluded_file_pattern . "/i", $needle)) {
944
+                if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) {
945 945
                     return $excluded_file_pattern;
946 946
                 }
947 947
             }
@@ -963,14 +963,14 @@  discard block
 block discarded – undo
963 963
 
964 964
         $csv_filename = str_replace('"', '""', $file['path']);
965 965
 
966
-        $line = '"' . ($csv_filename) . '","' . $file['timestamp'] . '","' . $file['size'] . '","' . $file['visibility'] . '","' . $storage . '"' . PHP_EOL;
966
+        $line = '"'.($csv_filename).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL;
967 967
 
968 968
         $this->last_logged_file = $file['path'];
969 969
 
970 970
         if ($file['type'] == "dir") {
971 971
             try {
972
-                $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path'] . "\n");
973
-            } catch (Exception $e) {
972
+                $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n");
973
+            }catch (Exception $e) {
974 974
                 $this->logger->error($e->getMessage());
975 975
             }
976 976
         }
@@ -990,13 +990,13 @@  discard block
 block discarded – undo
990 990
         try {
991 991
             if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) {
992 992
                 //adding fix for UTF-8 CSV preview
993
-                $start_line = "\xEF\xBB\xBF" . '"Filename","Timestamp","Size","Visibility","Storage"' . PHP_EOL;
993
+                $start_line = "\xEF\xBB\xBF".'"Filename","Timestamp","Size","Visibility","Storage"'.PHP_EOL;
994 994
                 $this->tmp_filesystem_append->write($this->get_included_files_handler(), $start_line);
995 995
             }
996 996
 
997 997
             $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
998 998
 
999
-        } catch (Exception $e) {
999
+        }catch (Exception $e) {
1000 1000
 
1001 1001
             $this->logger->error($e->getMessage());
1002 1002
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -707,9 +707,11 @@
 block discarded – undo
707 707
         foreach ($_backup_files_list as $file) {
708 708
             //processing rule folder capacity
709 709
             if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
710
-                $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))    //bytes
710
+                $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) {
711
+            	//bytes
711 712
             {
712 713
                 $this->storage_filesystem->delete($file['path']);
714
+            }
713 715
                 $_storage_size -= $file['size'];
714 716
                 $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
715 717
                     "STORAGE SIZE LIMIT",
Please login to merge, or discard this patch.
includes/class-xcloner-file-transfer.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     }
53 53
 
54 54
     /**
55
-     * @return mixed
55
+     * @return string
56 56
      */
57 57
     public function get_target()
58 58
     {
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
     }
142 142
 
143 143
     /**
144
-     * @param $filename
144
+     * @param string $filename
145 145
      * @param string $mimetype
146 146
      * @param string $postname
147 147
      *
Please login to merge, or discard this patch.
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -29,136 +29,136 @@
 block discarded – undo
29 29
 class Xcloner_File_Transfer extends Xcloner_File_System
30 30
 {
31 31
 
32
-    /**
33
-     * Target url web address of the restore script
34
-     * @var string
35
-     */
36
-    private $target_url;
37
-    /**
38
-     * Transfer data limit in bytes
39
-     * @var int
40
-     */
41
-    private $transfer_limit = 1048576; //bytes 1MB= 1048576 300KB = 358400
32
+	/**
33
+	 * Target url web address of the restore script
34
+	 * @var string
35
+	 */
36
+	private $target_url;
37
+	/**
38
+	 * Transfer data limit in bytes
39
+	 * @var int
40
+	 */
41
+	private $transfer_limit = 1048576; //bytes 1MB= 1048576 300KB = 358400
42 42
 
43 43
 
44
-    /**
45
-     * @param $target_url
46
-     *
47
-     * @return mixed
48
-     */
49
-    public function set_target($target_url)
50
-    {
51
-        return $this->target_url = $target_url;
52
-    }
44
+	/**
45
+	 * @param $target_url
46
+	 *
47
+	 * @return mixed
48
+	 */
49
+	public function set_target($target_url)
50
+	{
51
+		return $this->target_url = $target_url;
52
+	}
53 53
 
54
-    /**
55
-     * @return mixed
56
-     */
57
-    public function get_target()
58
-    {
59
-        return $this->target_url;
60
-    }
54
+	/**
55
+	 * @return mixed
56
+	 */
57
+	public function get_target()
58
+	{
59
+		return $this->target_url;
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * @param $file
65
-     * @param int $start
66
-     * @param string $hash
67
-     *
68
-     * @return bool|int
69
-     * @throws Exception
70
-     */
71
-    public function transfer_file($file, $start = 0, $hash = "")
72
-    {
73
-        if (!$this->target_url) {
74
-            throw new Exception("Please setup a target url for upload");
75
-        }
63
+	/**
64
+	 * @param $file
65
+	 * @param int $start
66
+	 * @param string $hash
67
+	 *
68
+	 * @return bool|int
69
+	 * @throws Exception
70
+	 */
71
+	public function transfer_file($file, $start = 0, $hash = "")
72
+	{
73
+		if (!$this->target_url) {
74
+			throw new Exception("Please setup a target url for upload");
75
+		}
76 76
 
77 77
 
78
-        $fp = $this->get_storage_filesystem()->readStream($file);
78
+		$fp = $this->get_storage_filesystem()->readStream($file);
79 79
 
80
-        fseek($fp, $start, SEEK_SET);
80
+		fseek($fp, $start, SEEK_SET);
81 81
 
82
-        $binary_data = fread($fp, $this->transfer_limit);
82
+		$binary_data = fread($fp, $this->transfer_limit);
83 83
 
84
-        $tmp_filename = "xcloner_upload_" . substr(md5(time()), 0, 5);
84
+		$tmp_filename = "xcloner_upload_" . substr(md5(time()), 0, 5);
85 85
 
86
-        $this->get_tmp_filesystem()->write($tmp_filename, $binary_data);
86
+		$this->get_tmp_filesystem()->write($tmp_filename, $binary_data);
87 87
 
88
-        $tmp_file_path = $this->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_filename);
88
+		$tmp_file_path = $this->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_filename);
89 89
 
90
-        $send_array = array();
90
+		$send_array = array();
91 91
 
92
-        $send_array['file'] = $file;
93
-        $send_array['start'] = $start;
94
-        $send_array['xcloner_action'] = "write_file";
95
-        $send_array['hash'] = $hash;
96
-        #$send_array['blob'] 	= $binary_data;
97
-        $send_array['blob'] = $this->curl_file_create($tmp_file_path, 'application/x-binary', $tmp_filename);
92
+		$send_array['file'] = $file;
93
+		$send_array['start'] = $start;
94
+		$send_array['xcloner_action'] = "write_file";
95
+		$send_array['hash'] = $hash;
96
+		#$send_array['blob'] 	= $binary_data;
97
+		$send_array['blob'] = $this->curl_file_create($tmp_file_path, 'application/x-binary', $tmp_filename);
98 98
 
99
-        //$data = http_build_query($send_array);
99
+		//$data = http_build_query($send_array);
100 100
 
101
-        $this->get_logger()->info(sprintf("Sending curl request to %s with %s data of file %s starting position %s using temporary file %s",
102
-            $this->target_url, $this->transfer_limit, $file, $start, $tmp_filename));
101
+		$this->get_logger()->info(sprintf("Sending curl request to %s with %s data of file %s starting position %s using temporary file %s",
102
+			$this->target_url, $this->transfer_limit, $file, $start, $tmp_filename));
103 103
 
104 104
 
105
-        $ch = curl_init();
106
-        curl_setopt($ch, CURLOPT_URL, $this->target_url);
105
+		$ch = curl_init();
106
+		curl_setopt($ch, CURLOPT_URL, $this->target_url);
107 107
 
108
-        curl_setopt($ch, CURLOPT_POST, 1);
109
-        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
110
-        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
111
-        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
112
-        curl_setopt($ch, CURLOPT_TIMEOUT, 1200);
113
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
108
+		curl_setopt($ch, CURLOPT_POST, 1);
109
+		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
110
+		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
111
+		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
112
+		curl_setopt($ch, CURLOPT_TIMEOUT, 1200);
113
+		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
114 114
 
115
-        curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array);
116
-        curl_setopt($ch, CURLOPT_VERBOSE, true);
115
+		curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array);
116
+		curl_setopt($ch, CURLOPT_VERBOSE, true);
117 117
 
118
-        $original_result = curl_exec($ch);
118
+		$original_result = curl_exec($ch);
119 119
 
120
-        $this->get_tmp_filesystem()->delete($tmp_filename);
120
+		$this->get_tmp_filesystem()->delete($tmp_filename);
121 121
 
122
-        $result = json_decode($original_result);
122
+		$result = json_decode($original_result);
123 123
 
124
-        if (!$result) {
125
-            throw new Exception("We have received no valid response from the remote host, original message: " . $original_result);
126
-        }
124
+		if (!$result) {
125
+			throw new Exception("We have received no valid response from the remote host, original message: " . $original_result);
126
+		}
127 127
 
128
-        if ($result->status != 200) {
129
-            throw new Exception($result->response);
130
-        }
128
+		if ($result->status != 200) {
129
+			throw new Exception($result->response);
130
+		}
131 131
 
132
-        if (ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) {
133
-            $this->get_logger()->info(sprintf("Upload done for file %s to target url %s, transferred a total of %s bytes",
134
-                $file, $this->target_url, ftell($fp)));
135
-            $this->remove_tmp_filesystem();
132
+		if (ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) {
133
+			$this->get_logger()->info(sprintf("Upload done for file %s to target url %s, transferred a total of %s bytes",
134
+				$file, $this->target_url, ftell($fp)));
135
+			$this->remove_tmp_filesystem();
136 136
 
137
-            return false;
138
-        }
137
+			return false;
138
+		}
139 139
 
140
-        return ftell($fp);
141
-    }
140
+		return ftell($fp);
141
+	}
142 142
 
143
-    /**
144
-     * @param $filename
145
-     * @param string $mimetype
146
-     * @param string $postname
147
-     *
148
-     * @return CURLFile|string
149
-     */
150
-    private function curl_file_create($filename, $mimetype = '', $postname = '')
151
-    {
152
-        if (!function_exists('curl_file_create')) {
143
+	/**
144
+	 * @param $filename
145
+	 * @param string $mimetype
146
+	 * @param string $postname
147
+	 *
148
+	 * @return CURLFile|string
149
+	 */
150
+	private function curl_file_create($filename, $mimetype = '', $postname = '')
151
+	{
152
+		if (!function_exists('curl_file_create')) {
153 153
 
154
-            return "@$filename;filename="
155
-                . ($postname ?: basename($filename))
156
-                . ($mimetype ? ";type=$mimetype" : '');
154
+			return "@$filename;filename="
155
+				. ($postname ?: basename($filename))
156
+				. ($mimetype ? ";type=$mimetype" : '');
157 157
 
158
-        } else {
158
+		} else {
159 159
 
160
-            return curl_file_create($filename, $mimetype, $postname);
160
+			return curl_file_create($filename, $mimetype, $postname);
161 161
 
162
-        }
163
-    }
162
+		}
163
+	}
164 164
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 
82 82
         $binary_data = fread($fp, $this->transfer_limit);
83 83
 
84
-        $tmp_filename = "xcloner_upload_" . substr(md5(time()), 0, 5);
84
+        $tmp_filename = "xcloner_upload_".substr(md5(time()), 0, 5);
85 85
 
86 86
         $this->get_tmp_filesystem()->write($tmp_filename, $binary_data);
87 87
 
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
         $result = json_decode($original_result);
123 123
 
124 124
         if (!$result) {
125
-            throw new Exception("We have received no valid response from the remote host, original message: " . $original_result);
125
+            throw new Exception("We have received no valid response from the remote host, original message: ".$original_result);
126 126
         }
127 127
 
128 128
         if ($result->status != 200) {
Please login to merge, or discard this patch.