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 ( 02764c...e4dc90 )
by Liuta
02:47
created
includes/class-xcloner-file-system.php 1 patch
Braces   +159 added lines, -117 removed lines patch added patch discarded remove patch
@@ -59,13 +59,14 @@  discard block
 block discarded – undo
59 59
 			$this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([
60 60
 					'disable_asserts' => true,
61 61
 				]));
62
-		}catch(Exception $e){
62
+		} catch(Exception $e){
63 63
 			return false;
64 64
 		}
65 65
 		
66 66
 		
67
-		if($value = get_option('xcloner_directories_to_scan_per_request'))
68
-			$this->folders_to_process_per_session = $value;
67
+		if($value = get_option('xcloner_directories_to_scan_per_request')) {
68
+					$this->folders_to_process_per_session = $value;
69
+		}
69 70
 
70 71
 	}
71 72
 	
@@ -128,8 +129,9 @@  discard block
 block discarded – undo
128 129
 	public function get_included_files_handler($metadata  = 0)
129 130
 	{
130 131
 		$path = $this->included_files_handler;
131
-		if(!$metadata)
132
-			return $path;
132
+		if(!$metadata) {
133
+					return $path;
134
+		}
133 135
 		
134 136
 		$spl_info = $this->getMetadataFull('tmp_adapter', $path);
135 137
 		return $spl_info;
@@ -145,31 +147,36 @@  discard block
 block discarded – undo
145 147
 	{
146 148
 		$files = $this->get_backup_archives_list();
147 149
 		
148
-		if(is_array($files))
149
-			$this->sort_by($files, "timestamp","desc");
150
+		if(is_array($files)) {
151
+					$this->sort_by($files, "timestamp","desc");
152
+		}
150 153
 		
151 154
 		$new_list = array();
152 155
 		
153
-		foreach($files as $key=>$file)
154
-			if(!isset($file['parent']))
156
+		foreach($files as $key=>$file) {
157
+					if(!isset($file['parent']))
155 158
 				$new_list[] = ($files[$key]);
159
+		}
156 160
 
157
-		if(isset($new_list[0]))
158
-			return $new_list[0];
161
+		if(isset($new_list[0])) {
162
+					return $new_list[0];
163
+		}
159 164
 	}
160 165
 	
161 166
 	public function get_latest_backups()
162 167
 	{
163 168
 		$files = $this->get_backup_archives_list();
164 169
 
165
-		if(is_array($files))
166
-			$this->sort_by($files, "timestamp","desc");
170
+		if(is_array($files)) {
171
+					$this->sort_by($files, "timestamp","desc");
172
+		}
167 173
 		
168 174
 		$new_list = array();
169 175
 		
170
-		foreach($files as $key=>$file)
171
-			if(!isset($file['parent']))
176
+		foreach($files as $key=>$file) {
177
+					if(!isset($file['parent']))
172 178
 				$new_list[] = ($files[$key]);
179
+		}
173 180
 
174 181
 		return $new_list;
175 182
 	}
@@ -179,25 +186,28 @@  discard block
 block discarded – undo
179 186
 		$files = $this->get_backup_archives_list();
180 187
 		$total = 0;
181 188
 		
182
-		if(is_array($files))
183
-			foreach($files as $file)
189
+		if(is_array($files)) {
190
+					foreach($files as $file)
184 191
 				$total += $file['size'];
192
+		}
185 193
 				
186 194
 		return $total;		
187 195
 	}
188 196
 	
189 197
 	public function is_part($backup_name)
190 198
 	{
191
-		if(stristr($backup_name, "-part"))
192
-			return true;
199
+		if(stristr($backup_name, "-part")) {
200
+					return true;
201
+		}
193 202
 		
194 203
 		return false;	
195 204
 	}
196 205
 	
197 206
 	public function is_multipart($backup_name)
198 207
 	{
199
-		if(stristr($backup_name, "-multipart"))
200
-			return true;
208
+		if(stristr($backup_name, "-multipart")) {
209
+					return true;
210
+		}
201 211
 		
202 212
 		return false;	
203 213
 	}
@@ -208,8 +218,9 @@  discard block
 block discarded – undo
208 218
 		if($this->is_multipart($backup_name))
209 219
 		{
210 220
 			$backup_parts = $this->get_multipart_files($backup_name);
211
-			foreach($backup_parts as $part_file)
212
-				$backup_size += $this->get_storage_filesystem()->getSize($part_file);
221
+			foreach($backup_parts as $part_file) {
222
+							$backup_size += $this->get_storage_filesystem()->getSize($part_file);
223
+			}
213 224
 		}
214 225
 		
215 226
 		return $backup_size;
@@ -250,10 +261,11 @@  discard block
 block discarded – undo
250 261
 			}
251 262
 		}
252 263
 		
253
-		if($this->get_storage_filesystem()->delete($backup_name))
254
-			$return = true;
255
-		else
256
-			$return = false;
264
+		if($this->get_storage_filesystem()->delete($backup_name)) {
265
+					$return = true;
266
+		} else {
267
+					$return = false;
268
+		}
257 269
 			
258 270
 		return $return;	
259 271
 	}
@@ -271,8 +283,9 @@  discard block
 block discarded – undo
271 283
 	{
272 284
 		$list = array();
273 285
 		
274
-		if(method_exists($this->get_storage_filesystem(), "listContents"))
275
-			$list = $this->get_storage_filesystem()->listContents();
286
+		if(method_exists($this->get_storage_filesystem(), "listContents")) {
287
+					$list = $this->get_storage_filesystem()->listContents();
288
+		}
276 289
 
277 290
 		
278 291
 		$backup_files = array();
@@ -285,10 +298,11 @@  discard block
 block discarded – undo
285 298
 			if(isset($file_info['extension']) and $file_info['extension'] == "csv")
286 299
 			{
287 300
 				$lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($file_info['path']));
288
-				foreach($lines as $line)
289
-					if($line)
301
+				foreach($lines as $line) {
302
+									if($line)
290 303
 					{
291 304
 						$data = str_getcsv($line);
305
+				}
292 306
 						if(is_array($data)){
293 307
 							$parents[$data[0]] = $file_info['path'];
294 308
 							$file_info['childs'][] = $data;
@@ -298,14 +312,16 @@  discard block
 block discarded – undo
298 312
 						
299 313
 			}
300 314
 			
301
-			if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions))
302
-				$backup_files[$file_info['path']] = $file_info;
315
+			if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) {
316
+							$backup_files[$file_info['path']] = $file_info;
317
+			}
303 318
 		}
304 319
 		
305 320
 		foreach($backup_files as $key=>$file_info)
306 321
 		{
307
-			if(isset($parents[$file_info['path']]))
308
-				$backup_files[$key]['parent'] = $parents[$file_info['path']];
322
+			if(isset($parents[$file_info['path']])) {
323
+							$backup_files[$key]['parent'] = $parents[$file_info['path']];
324
+			}
309 325
 		}
310 326
 		
311 327
 		return $backup_files;
@@ -331,11 +347,11 @@  discard block
 block discarded – undo
331 347
 				if($counter < $this->folders_to_process_per_session){
332 348
 					$this->build_files_list($file);
333 349
 					$counter++;
334
-				}else{
350
+				} else{
335 351
 					$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n");
336 352
 				}
337 353
 			}
338
-		}else{
354
+		} else{
339 355
 			$this->build_files_list();
340 356
 		}
341 357
 		
@@ -377,8 +393,9 @@  discard block
 block discarded – undo
377 393
 	{
378 394
 		$return = array();
379 395
 		$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler();
380
-		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log'))
381
-			$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
396
+		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
397
+					$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
398
+		}
382 399
 		
383 400
 		return $return;
384 401
 	}
@@ -390,9 +407,10 @@  discard block
 block discarded – undo
390 407
 		
391 408
 		$contents = $this->get_tmp_filesystem()->listContents();
392 409
 	
393
-		if(is_array($contents))
394
-		foreach($contents as $file_info)
410
+		if(is_array($contents)) {
411
+				foreach($contents as $file_info)
395 412
 			$this->get_tmp_filesystem()->delete($file_info['path']);
413
+		}
396 414
 			
397 415
 		@rmdir($this->xcloner_settings->get_xcloner_tmp_path());
398 416
 		
@@ -403,17 +421,21 @@  discard block
 block discarded – undo
403 421
 	{
404 422
 		$this->files_counter = 0;
405 423
 		
406
-		if(!$this->storage_filesystem->has("index.html"))	
407
-			$this->storage_filesystem->write("index.html","");
424
+		if(!$this->storage_filesystem->has("index.html")) {
425
+					$this->storage_filesystem->write("index.html","");
426
+		}
408 427
 		
409
-		if(!$this->tmp_filesystem->has("index.html"))	
410
-			$this->tmp_filesystem->write("index.html","");
428
+		if(!$this->tmp_filesystem->has("index.html")) {
429
+					$this->tmp_filesystem->write("index.html","");
430
+		}
411 431
 			
412
-		if($this->tmp_filesystem->has($this->get_included_files_handler()))
413
-			$this->tmp_filesystem->delete($this->get_included_files_handler());
432
+		if($this->tmp_filesystem->has($this->get_included_files_handler())) {
433
+					$this->tmp_filesystem->delete($this->get_included_files_handler());
434
+		}
414 435
 		
415
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler()))	
416
-			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
436
+		if($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
437
+					$this->tmp_filesystem->delete($this->get_temp_dir_handler());
438
+		}
417 439
 	}
418 440
 	
419 441
 	public function get_scanned_files_num()
@@ -433,8 +455,9 @@  discard block
 block discarded – undo
433 455
 	
434 456
 	public function set_excluded_files($excluded_files = array())
435 457
 	{
436
-		if(!is_array($excluded_files))
437
-			$excluded_files = array();
458
+		if(!is_array($excluded_files)) {
459
+					$excluded_files = array();
460
+		}
438 461
 			
439 462
 		$this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
440 463
 		
@@ -468,21 +491,21 @@  discard block
 block discarded – undo
468 491
 				if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path']))
469 492
 				{
470 493
 					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE"));
471
-				}
472
-				elseif(!$matching_pattern = $this->is_excluded($file) ){
494
+				} elseif(!$matching_pattern = $this->is_excluded($file) ){
473 495
 					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE"));
474 496
 					$file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
475 497
 					$this->store_file($file);
476 498
 					$this->files_counter++;
477
-					if(isset($file['size']))
478
-						$this->files_size += $file['size'];
499
+					if(isset($file['size'])) {
500
+											$this->files_size += $file['size'];
501
+					}
479 502
 					
480
-				}else{
503
+				} else{
481 504
 					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE"));
482 505
 					}
483 506
 			}
484 507
 			
485
-		}catch(Exception $e){
508
+		} catch(Exception $e){
486 509
 			
487 510
 			$this->logger->error($e->getMessage());
488 511
 		
@@ -509,7 +532,7 @@  discard block
 block discarded – undo
509 532
 		
510 533
 			$this->tmp_filesystem->delete($tmp_file);
511 534
 		
512
-		}catch(Exception $e){
535
+		} catch(Exception $e){
513 536
 			
514 537
 			$this->logger->error($e->getMessage());
515 538
 			
@@ -530,12 +553,14 @@  discard block
 block discarded – undo
530 553
 		
531 554
 		$files = $this->storage_filesystem->listContents();
532 555
 		
533
-		if(is_array($files))
534
-			foreach($files as $file)
556
+		if(is_array($files)) {
557
+					foreach($files as $file)
535 558
 			{
536 559
 				if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions))
537 560
 				{
538
-					$_storage_size += $file['size']; //bytes
561
+					$_storage_size += $file['size'];
562
+		}
563
+		//bytes
539 564
 					$_backup_files_list[] = $file;
540 565
 				}
541 566
 			}
@@ -549,9 +574,11 @@  discard block
 block discarded – undo
549 574
 		{
550 575
 			//processing rule folder capacity
551 576
 			if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
552
-			$_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))	//bytes	
577
+			$_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) {
578
+				//bytes	
553 579
 			{
554 580
 				$this->storage_filesystem->delete($file['path']);
581
+			}
555 582
 				$_storage_size -= $file['size'];
556 583
 				$this->logger->info("Deleting backup ".$file['path']." matching rule", array("STORAGE SIZE LIMIT", $_storage_size." >= ".$set_storage_limit));
557 584
 			}
@@ -592,24 +619,26 @@  discard block
 block discarded – undo
592 619
 	
593 620
 	public function process_backup_name($name = "", $max_length=100)
594 621
 	{
595
-		if(!$name)
596
-			$name = $this->xcloner_settings->get_default_backup_name();
622
+		if(!$name) {
623
+					$name = $this->xcloner_settings->get_default_backup_name();
624
+		}
597 625
 		
598 626
 		foreach($this->backup_name_tags as $tag)
599 627
 		{
600
-			if($tag == '[time]')
601
-				$name = str_replace($tag, date("Y-m-d_H-i"),$name);
602
-			elseif($tag == '[hostname]')
603
-				$name = str_replace($tag, gethostname() ,$name);	
604
-			elseif($tag == '[domain]')
628
+			if($tag == '[time]') {
629
+							$name = str_replace($tag, date("Y-m-d_H-i"),$name);
630
+			} elseif($tag == '[hostname]') {
631
+							$name = str_replace($tag, gethostname() ,$name);
632
+			} elseif($tag == '[domain]')
605 633
 			{
606 634
 				$domain = parse_url(admin_url(), PHP_URL_HOST);
607 635
 				$name = str_replace($tag, $domain ,$name);	
608 636
 			}
609 637
 		}
610 638
 		
611
-		if($max_length)
612
-			$name = substr($name, 0, $max_length);
639
+		if($max_length) {
640
+					$name = substr($name, 0, $max_length);
641
+		}
613 642
 			
614 643
 		return $name;	
615 644
 	}
@@ -626,10 +655,11 @@  discard block
 block discarded – undo
626 655
             return 0;
627 656
         }
628 657
 		
629
-		if(strlower($direction) == 'desc' )
630
-			return ($a > $b) ? -1 : 1;
631
-		else	
632
-			return ($a < $b) ? -1 : 1;
658
+		if(strlower($direction) == 'desc' ) {
659
+					return ($a > $b) ? -1 : 1;
660
+		} else {
661
+					return ($a < $b) ? -1 : 1;
662
+		}
633 663
 			
634 664
         //return ($a ($direction == 'desc' ? '>' : '<')  $b) ? -1 : 1;
635 665
 	}
@@ -649,28 +679,32 @@  discard block
 block discarded – undo
649 679
 		
650 680
 		if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb'))
651 681
 		{
652
-			if(isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb))
653
-				return "> ".$xcloner_exclude_files_larger_than_mb."MB";
682
+			if(isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) {
683
+							return "> ".$xcloner_exclude_files_larger_than_mb."MB";
684
+			}
654 685
 		}
655 686
 		
656
-		if(!sizeof($this->excluded_files))
657
-			$this->set_excluded_files();
687
+		if(!sizeof($this->excluded_files)) {
688
+					$this->set_excluded_files();
689
+		}
658 690
 				
659
-		if(is_array($this->excluded_files))
660
-		foreach($this->excluded_files as $excluded_file_pattern)
691
+		if(is_array($this->excluded_files)) {
692
+				foreach($this->excluded_files as $excluded_file_pattern)
661 693
 		{
662 694
 			if($excluded_file_pattern == "/")
663 695
 				$needle = "$";
664
-			else
665
-				$needle = "$".$excluded_file_pattern;
696
+		} else {
697
+							$needle = "$".$excluded_file_pattern;
698
+			}
666 699
 				
667 700
 			if(strstr("$".$file['path'], $needle)){
668 701
 				return $excluded_file_pattern;
669 702
 			}
670 703
 		}
671 704
 		
672
-		if( $regex = $this->is_excluded_regex($file))
673
-			return $regex;
705
+		if( $regex = $this->is_excluded_regex($file)) {
706
+					return $regex;
707
+		}
674 708
 		
675 709
 		return false;
676 710
 	}
@@ -724,13 +758,15 @@  discard block
 block discarded – undo
724 758
 			foreach($regex_patterns as $excluded_file_pattern)
725 759
 			{
726 760
 				
727
-				if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r")
728
-					$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1);
761
+				if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") {
762
+									$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1);
763
+				}
729 764
 					
730
-				if($file['path'] == "/")
731
-					$needle = "/";
732
-				else
733
-					$needle = "/".$file['path'];
765
+				if($file['path'] == "/") {
766
+									$needle = "/";
767
+				} else {
768
+									$needle = "/".$file['path'];
769
+				}
734 770
 				//echo $needle."---".$excluded_file_pattern."---\n";
735 771
 				
736 772
 				if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){
@@ -746,10 +782,12 @@  discard block
 block discarded – undo
746 782
 	{
747 783
 		$this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
748 784
 		
749
-		if(!isset($file['size']))
750
-			$file['size'] = 0;
751
-		if(!isset($file['visibility']))	
752
-			$file['visibility'] = "private";
785
+		if(!isset($file['size'])) {
786
+					$file['size'] = 0;
787
+		}
788
+		if(!isset($file['visibility'])) {
789
+					$file['visibility'] = "private";
790
+		}
753 791
 		
754 792
 		$line = '"'.addslashes($file['path']).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL;
755 793
 		
@@ -758,7 +796,7 @@  discard block
 block discarded – undo
758 796
 		try{
759 797
 			$this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
760 798
 		
761
-		}catch(Exception $e){
799
+		} catch(Exception $e){
762 800
 		
763 801
 			$this->logger->error($e->getMessage());	
764 802
 		}
@@ -766,7 +804,7 @@  discard block
 block discarded – undo
766 804
 		if($file['type'] == "dir"){
767 805
 			try{
768 806
 				$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n");
769
-			}catch(Exception $e){
807
+			} catch(Exception $e){
770 808
 				$this->logger->error($e->getMessage());	
771 809
 			}
772 810
 		}
@@ -779,35 +817,39 @@  discard block
 block discarded – undo
779 817
 	
780 818
 	public function get_filesystem($system = "")
781 819
 	{
782
-		if($system == "storage_filesystem_append")
783
-			return $this->storage_filesystem_append;
784
-		elseif($system == "tmp_filesystem_append")
785
-			return $this->tmp_filesystem_append;
786
-		elseif($system == "tmp_filesystem")
787
-			return $this->tmp_filesystem;
788
-		elseif($system == "storage_filesystem")
789
-			return $this->storage_filesystem;
790
-		else
791
-			return $this->start_filesystem;	
820
+		if($system == "storage_filesystem_append") {
821
+					return $this->storage_filesystem_append;
822
+		} elseif($system == "tmp_filesystem_append") {
823
+					return $this->tmp_filesystem_append;
824
+		} elseif($system == "tmp_filesystem") {
825
+					return $this->tmp_filesystem;
826
+		} elseif($system == "storage_filesystem") {
827
+					return $this->storage_filesystem;
828
+		} else {
829
+					return $this->start_filesystem;
830
+		}
792 831
 	}
793 832
 	
794 833
 	public function get_adapter($system)
795 834
 	{
796
-		if($system == "tmp_filesystem")
797
-			return $this->tmp_adapter;
798
-		elseif($system == "storage_filesystem")
799
-			return $this->storage_adapter;
800
-		else
801
-			return $this->start_adapter;	
835
+		if($system == "tmp_filesystem") {
836
+					return $this->tmp_adapter;
837
+		} elseif($system == "storage_filesystem") {
838
+					return $this->storage_adapter;
839
+		} else {
840
+					return $this->start_adapter;
841
+		}
802 842
 	}
803 843
 	
804 844
 	private function scan_finished()
805 845
 	{
806
-		if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler()))
807
-			return false;
846
+		if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) {
847
+					return false;
848
+		}
808 849
 		
809
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler()))
810
-			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
850
+		if($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
851
+					$this->tmp_filesystem->delete($this->get_temp_dir_handler());
852
+		}
811 853
 		
812 854
 		$this->logger->debug(sprintf(("File scan finished")));
813 855
 			
Please login to merge, or discard this patch.