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
Branch dev (76c677)
by Liuta
01:52
created
restore/xcloner_restore.php 1 patch
Braces   +117 added lines, -93 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
 
@@ -208,7 +207,7 @@  discard block
 block discarded – undo
208 207
 				$this->logger->debug(sprintf('Starting action %s', $method));
209 208
 				return call_user_func(array($this, $method));
210 209
 				
211
-			}else{
210
+			} else{
212 211
 				throw new Exception($method ." does not exists");
213 212
 				}
214 213
 		}
@@ -228,13 +227,15 @@  discard block
 block discarded – undo
228 227
 		{
229 228
 			$target_file = filter_input(INPUT_POST, 'file', FILTER_SANITIZE_STRING);
230 229
 			
231
-			if(!$_POST['start'])
232
-				$fp = fopen($target_file, "wb+");
233
-			else
234
-				$fp = fopen($target_file, "ab+");	
230
+			if(!$_POST['start']) {
231
+							$fp = fopen($target_file, "wb+");
232
+			} else {
233
+							$fp = fopen($target_file, "ab+");
234
+			}
235 235
 			
236
-			if(!$fp)
237
-				throw new Exception("Unable to open $target_file file for writing");
236
+			if(!$fp) {
237
+							throw new Exception("Unable to open $target_file file for writing");
238
+			}
238 239
 			
239 240
 			fseek($fp, $_POST['start']);
240 241
 			
@@ -244,23 +245,25 @@  discard block
 block discarded – undo
244 245
 				
245 246
 				$blob = file_get_contents($_FILES['blob']['tmp_name']);
246 247
 				
247
-				if(!$bytes_written = fwrite($fp, $blob))
248
-					throw new Exception("Unable to write data to file $target_file");
248
+				if(!$bytes_written = fwrite($fp, $blob)) {
249
+									throw new Exception("Unable to write data to file $target_file");
250
+				}
249 251
 
250 252
 				try {
251 253
                     unlink($_FILES['blob']['tmp_name']);
252
-                }catch(Exception $e){
254
+                } catch(Exception $e){
253 255
 
254 256
                 }
255 257
 
256
-			}elseif(isset($_POST['blob'])){
258
+			} elseif(isset($_POST['blob'])){
257 259
 				$this->logger->debug(sprintf('Writing %s bytes to file %s starting position %s using POST blob', strlen($_POST['blob']), $target_file, $_POST['start']));
258 260
 				
259 261
 				$blob = $_POST['blob'];
260 262
 
261
-				if(!$bytes_written = fwrite($fp, $blob))
262
-					throw new Exception("Unable to write data to file $target_file");
263
-			}else{
263
+				if(!$bytes_written = fwrite($fp, $blob)) {
264
+									throw new Exception("Unable to write data to file $target_file");
265
+				}
266
+			} else{
264 267
 				throw new Exception("Upload failed, did not receive any binary data");
265 268
 			}
266 269
 			
@@ -294,10 +297,11 @@  discard block
 block discarded – undo
294 297
 		
295 298
 		$mysqli->query("SET sql_mode='';");
296 299
 		$mysqli->query("SET foreign_key_checks = 0;");
297
-		if(isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file'])
298
-			$mysqli->query("SET NAMES ".$_REQUEST['charset_of_file']."");
299
-		else
300
-			$mysqli->query("SET NAMES utf8;");
300
+		if(isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file']) {
301
+					$mysqli->query("SET NAMES ".$_REQUEST['charset_of_file']."");
302
+		} else {
303
+					$mysqli->query("SET NAMES utf8;");
304
+		}
301 305
 			
302 306
 		return $mysqli;	
303 307
 	}
@@ -327,8 +331,9 @@  discard block
 block discarded – undo
327 331
 		
328 332
 		$mysql_backup_file = $remote_path.DS.$mysqldump_file;
329 333
 		
330
-		if(!file_exists($mysql_backup_file))
331
-			throw new Exception(sprintf("Mysql backup file %s does not exists",$mysql_backup_file));
334
+		if(!file_exists($mysql_backup_file)) {
335
+					throw new Exception(sprintf("Mysql backup file %s does not exists",$mysql_backup_file));
336
+		}
332 337
 		
333 338
 		
334 339
 		/*if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS)
@@ -360,16 +365,18 @@  discard block
 block discarded – undo
360 365
 			// process the line read.
361 366
 									
362 367
 				//check if line is comment
363
-				if(substr($line, 0, 1) == "#")
364
-					continue;
368
+				if(substr($line, 0, 1) == "#") {
369
+									continue;
370
+				}
365 371
 				
366 372
 				//check if line is empty	
367
-				if($line == "\n" or trim($line) == "")
368
-					continue;
373
+				if($line == "\n" or trim($line) == "") {
374
+									continue;
375
+				}
369 376
 					
370
-				if(substr($line, strlen($line)-2, strlen($line)) == ";\n")
371
-					$query .= $line;
372
-				else{
377
+				if(substr($line, strlen($line)-2, strlen($line)) == ";\n") {
378
+									$query .= $line;
379
+				} else{
373 380
 					$query .= $line;
374 381
 					continue;
375 382
 				}
@@ -428,7 +435,7 @@  discard block
 block discarded – undo
428 435
 		if(!feof($fp))
429 436
 		{
430 437
 			$return['finished'] = 0;
431
-		}else{
438
+		} else{
432 439
 			$this->logger->info(sprintf("Mysql Import Done."));
433 440
 		}
434 441
 		
@@ -493,7 +500,7 @@  discard block
 block discarded – undo
493 500
 			$tar->open($this->backup_storage_dir.DS.$backup_file, $start);
494 501
 		
495 502
 			$data = $tar->contents($this->process_files_limit_list);
496
-		}catch(Exception $e)
503
+		} catch(Exception $e)
497 504
 		{
498 505
 			$return['error'] = true;
499 506
 			$return['message'] = $e->getMessage();
@@ -521,15 +528,16 @@  discard block
 block discarded – undo
521 528
 		{
522 529
 			$return['start'] = $data['start'];
523 530
 			$return['finished'] = 0;	
524
-		}else{
531
+		} else{
525 532
 			if($this->is_multipart($source_backup_file))
526 533
 			{
527 534
 				$return['start'] = 0;
528 535
 				
529 536
 				++$return['part'];
530 537
 			
531
-				if($return['part'] < sizeof($backup_parts))	
532
-					$return['finished'] = 0;
538
+				if($return['part'] < sizeof($backup_parts)) {
539
+									$return['finished'] = 0;
540
+				}
533 541
 				
534 542
 			}
535 543
 		}	
@@ -670,19 +678,22 @@  discard block
 block discarded – undo
670 678
 		{
671 679
 			$config = file_get_contents($wp_config);
672 680
 			preg_match("/.*table_prefix.*=.*'(.*)'/i", $config, $matches);
673
-			if(isset($matches[1]))
674
-				$table_prefix = $matches[1];
675
-			else
676
-				throw new Exception("Could not load wordpress table prefix from wp-config.php file.");
681
+			if(isset($matches[1])) {
682
+							$table_prefix = $matches[1];
683
+			} else {
684
+							throw new Exception("Could not load wordpress table prefix from wp-config.php file.");
685
+			}
686
+		} else {
687
+					throw new Exception("Could not update the SITEURL and HOME, wp-config.php file not found");
677 688
 		}
678
-		else
679
-			throw new Exception("Could not update the SITEURL and HOME, wp-config.php file not found");
680 689
 			
681
-		if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'"))
682
-			throw new Exception(sprintf("Could not update the HOME option, error: %s\n", $mysqli->error));
690
+		if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'")) {
691
+					throw new Exception(sprintf("Could not update the HOME option, error: %s\n", $mysqli->error));
692
+		}
683 693
 		
684
-		if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'"))
685
-			throw new Exception(sprintf("Could not update the SITEURL option, error: %s\n", $mysqli->error));
694
+		if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'")) {
695
+					throw new Exception(sprintf("Could not update the SITEURL option, error: %s\n", $mysqli->error));
696
+		}
686 697
 		
687 698
 		return true;
688 699
 	}
@@ -720,8 +731,9 @@  discard block
 block discarded – undo
720 731
 		
721 732
 		$this->logger->info(sprintf('Updating wp-config.php file with the new mysql details'));
722 733
 		
723
-		if(!file_put_contents($wp_config, $content))
724
-			throw new Exception("Could not write updated config data to ".$wp_config);
734
+		if(!file_put_contents($wp_config, $content)) {
735
+					throw new Exception("Could not write updated config data to ".$wp_config);
736
+		}
725 737
 		
726 738
 		chmod($wp_config, $file_perms);
727 739
 		
@@ -766,10 +778,11 @@  discard block
 block discarded – undo
766 778
 							$mysqldump_list[$file['path']]['size'] = $file['size'];
767 779
 							$mysqldump_list[$file['path']]['timestamp'] = date("d M,Y H:i",$file['timestamp']);
768 780
 							
769
-							if($hash and $hash == $matches[1])
770
-								$mysqldump_list[$file['path']]['selected'] = "selected";
771
-							else
772
-								$mysqldump_list[$file['path']]['selected'] = "";	
781
+							if($hash and $hash == $matches[1]) {
782
+															$mysqldump_list[$file['path']]['selected'] = "selected";
783
+							} else {
784
+															$mysqldump_list[$file['path']]['selected'] = "";
785
+							}
773 786
 						}
774 787
 					}
775 788
 				}
@@ -790,13 +803,15 @@  discard block
 block discarded – undo
790 803
      */
791 804
 	private function get_hash_from_backup($backup_file)
792 805
 	{
793
-		if(!$backup_file)
794
-			return false;
806
+		if(!$backup_file) {
807
+					return false;
808
+		}
795 809
 			
796 810
 		$result = preg_match("/-(\w*)./", substr($backup_file, strlen($backup_file)-10, strlen($backup_file)), $matches)	;
797 811
 		
798
-		if($result and isset($matches[1]))
799
-			return ($matches[1]);
812
+		if($result and isset($matches[1])) {
813
+					return ($matches[1]);
814
+		}
800 815
 		
801 816
 		return false;
802 817
 	}
@@ -821,10 +836,11 @@  discard block
 block discarded – undo
821 836
 			if(isset($file_info['extension']) and $file_info['extension'] == "csv")
822 837
 			{
823 838
 				$lines = explode(PHP_EOL, $this->filesystem->read($file_info['path']));
824
-				foreach($lines as $line)
825
-					if($line)
839
+				foreach($lines as $line) {
840
+									if($line)
826 841
 					{
827 842
 						$data = str_getcsv($line);
843
+				}
828 844
 						if(is_array($data)){
829 845
 							$parents[$data[0]] = $file_info['path'];
830 846
 							$file_info['childs'][] = $data;
@@ -834,20 +850,22 @@  discard block
 block discarded – undo
834 850
 						
835 851
 			}
836 852
 			
837
-			if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions))
838
-				$backup_files[$file_info['path']] = $file_info;
853
+			if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) {
854
+							$backup_files[$file_info['path']] = $file_info;
855
+			}
839 856
 		}
840 857
 		
841 858
 		$new_list = array();
842 859
 		
843 860
 		foreach($backup_files as $key=>$file_info)
844 861
 		{
845
-			if(isset($parents[$file_info['path']]))
846
-				$backup_files[$key]['parent'] = $parents[$file_info['path']];
847
-			else{
862
+			if(isset($parents[$file_info['path']])) {
863
+							$backup_files[$key]['parent'] = $parents[$file_info['path']];
864
+			} else{
848 865
 				
849
-				if($local_backup_file and ($file_info['basename'] == $local_backup_file))
850
-					$file_info['selected'] = 'selected';
866
+				if($local_backup_file and ($file_info['basename'] == $local_backup_file)) {
867
+									$file_info['selected'] = 'selected';
868
+				}
851 869
 				
852 870
 				$this->logger->info(sprintf('Found %s backup file', $file_info['path']));
853 871
 					
@@ -894,8 +912,9 @@  discard block
 block discarded – undo
894 912
 		$backup_archive = new Tar();
895 913
 		if($this->is_multipart($backup_file))
896 914
 		{
897
-			if(!$return['part'])
898
-				$return['processed'] += $this->filesystem->getSize($backup_file);
915
+			if(!$return['part']) {
916
+							$return['processed'] += $this->filesystem->getSize($backup_file);
917
+			}
899 918
 				
900 919
 			$backup_parts = $this->get_multipart_files($backup_file);
901 920
 			$backup_file = $backup_parts[$return['part']];	
@@ -915,12 +934,13 @@  discard block
 block discarded – undo
915 934
 			}
916 935
 		}
917 936
 		
918
-		if(isset($data['start']))
919
-		//if(isset($data['start']) and $data['start'] <= $this->filesystem->getSize($backup_file))
937
+		if(isset($data['start'])) {
938
+				//if(isset($data['start']) and $data['start'] <= $this->filesystem->getSize($backup_file))
920 939
 		{
921 940
 			$return['finished'] = 0;
941
+		}
922 942
 			$return['start'] = $data['start'];
923
-		}else{
943
+		} else{
924 944
 			
925 945
 			$return['processed'] += $start;
926 946
 			
@@ -930,14 +950,16 @@  discard block
 block discarded – undo
930 950
 				
931 951
 				++$return['part'];
932 952
 			
933
-				if($return['part'] < sizeof($backup_parts))	
934
-					$return['finished'] = 0;
953
+				if($return['part'] < sizeof($backup_parts)) {
954
+									$return['finished'] = 0;
955
+				}
935 956
 				
936 957
 			}
937 958
 		}
938 959
 		
939
-		if($return['finished'])
940
-			$this->logger->info(sprintf('Done extracting %s', $source_backup_file));
960
+		if($return['finished']) {
961
+					$this->logger->info(sprintf('Done extracting %s', $source_backup_file));
962
+		}
941 963
 		
942 964
 		$return['backup_file'] = $backup_file;
943 965
 		
@@ -969,8 +991,7 @@  discard block
 block discarded – undo
969 991
 			$return['remote_mysql_user'] 	= $wpdb->dbuser;
970 992
 			$return['remote_mysql_pass'] 	= $wpdb->dbpassword;
971 993
 			$return['remote_mysql_db'] 		= $wpdb->dbname;
972
-		}
973
-		else{
994
+		} else{
974 995
 			$return['dir'] = ($pathinfo['dirname']).DS.$suffix;
975 996
 			$return['restore_script_url'] = str_replace($pathinfo['basename'], "", $restore_script_url).$suffix;
976 997
 		}	
@@ -989,11 +1010,13 @@  discard block
 block discarded – undo
989 1010
 	{
990 1011
 		//check if i can write
991 1012
 		$tmp_file = md5(time());
992
-		if(!file_put_contents($tmp_file, "++"))
993
-			throw new Exception("Could not write to new host");
1013
+		if(!file_put_contents($tmp_file, "++")) {
1014
+					throw new Exception("Could not write to new host");
1015
+		}
994 1016
 		
995
-		if(!unlink($tmp_file))
996
-			throw new Exception("Could not delete temporary file from new host");
1017
+		if(!unlink($tmp_file)) {
1018
+					throw new Exception("Could not delete temporary file from new host");
1019
+		}
997 1020
 		
998 1021
 		$max_upload      = $this->return_bytes((ini_get('upload_max_filesize')));
999 1022
 		$max_post        = $this->return_bytes((ini_get('post_max_size')));
@@ -1037,8 +1060,9 @@  discard block
 block discarded – undo
1037 1060
      */
1038 1061
 	public function is_multipart($backup_name)
1039 1062
 	{
1040
-		if(stristr($backup_name, "-multipart"))
1041
-			return true;
1063
+		if(stristr($backup_name, "-multipart")) {
1064
+					return true;
1065
+		}
1042 1066
 		
1043 1067
 		return false;	
1044 1068
 	}
@@ -1056,8 +1080,9 @@  discard block
 block discarded – undo
1056 1080
 		if($this->is_multipart($backup_name))
1057 1081
 		{
1058 1082
 			$backup_parts = $this->get_multipart_files($backup_name);
1059
-			foreach($backup_parts as $part_file)
1060
-				$backup_size += $this->filesystem->getSize($part_file);
1083
+			foreach($backup_parts as $part_file) {
1084
+							$backup_size += $this->filesystem->getSize($part_file);
1085
+			}
1061 1086
 		}
1062 1087
 		
1063 1088
 		return $backup_size;
@@ -1115,15 +1140,13 @@  discard block
 block discarded – undo
1115 1140
                 if($direction == 'desc') {
1116 1141
                     if($a > $b) {
1117 1142
                         return -1;
1118
-                    }
1119
-                    else{
1143
+                    } else{
1120 1144
                         return 1;
1121 1145
                     }
1122
-                }else {
1146
+                } else {
1123 1147
                     if($a < $b) {
1124 1148
                         return -1;
1125
-                    }
1126
-                    else{
1149
+                    } else{
1127 1150
                         return 1;
1128 1151
                     }
1129 1152
                 }
@@ -1153,7 +1176,7 @@  discard block
 block discarded – undo
1153 1176
 		{
1154 1177
 			$return['statusText'] = $response['message'];
1155 1178
 			$return['error'] = true;
1156
-		}elseif($status != 200 and $status != 418)
1179
+		} elseif($status != 200 and $status != 418)
1157 1180
 		{
1158 1181
 			$return['error'] = true;
1159 1182
 			$return['message'] = $response;
@@ -1177,8 +1200,9 @@  discard block
 block discarded – undo
1177 1200
 		return preg_replace_callback('!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!', function ($m) {
1178 1201
 				  $data = "";
1179 1202
 				  	
1180
-				  if(!isset($m[3]))
1181
-					$m[3] = "";
1203
+				  if(!isset($m[3])) {
1204
+				  					$m[3] = "";
1205
+				  }
1182 1206
 					
1183 1207
 					$data = 's:'.strlen(($m[3])).':\"'.($m[3]).'\";';
1184 1208
 	              //return $this->unescape_quotes($data);
@@ -1224,7 +1248,7 @@  discard block
 block discarded – undo
1224 1248
 		    stristr($s, ':' ) !== false
1225 1249
 		    ){
1226 1250
 		    return true;
1227
-		}else{
1251
+		} else{
1228 1252
 		    return false;
1229 1253
 		}
1230 1254
 
Please login to merge, or discard this patch.