@@ -45,8 +45,7 @@ discard block |
||
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 | 51 | } else { |
@@ -87,7 +86,7 @@ discard block |
||
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 | |
@@ -231,13 +230,15 @@ discard block |
||
231 | 230 | { |
232 | 231 | $target_file = filter_input(INPUT_POST, 'file', FILTER_SANITIZE_STRING); |
233 | 232 | |
234 | - if (!$_POST['start']) |
|
235 | - $fp = fopen($target_file, "wb+"); |
|
236 | - else |
|
237 | - $fp = fopen($target_file, "ab+"); |
|
233 | + if (!$_POST['start']) { |
|
234 | + $fp = fopen($target_file, "wb+"); |
|
235 | + } else { |
|
236 | + $fp = fopen($target_file, "ab+"); |
|
237 | + } |
|
238 | 238 | |
239 | - if (!$fp) |
|
240 | - throw new Exception("Unable to open $target_file file for writing"); |
|
239 | + if (!$fp) { |
|
240 | + throw new Exception("Unable to open $target_file file for writing"); |
|
241 | + } |
|
241 | 242 | |
242 | 243 | fseek($fp, $_POST['start']); |
243 | 244 | |
@@ -247,22 +248,24 @@ discard block |
||
247 | 248 | |
248 | 249 | $blob = file_get_contents($_FILES['blob']['tmp_name']); |
249 | 250 | |
250 | - if (!$bytes_written = fwrite($fp, $blob)) |
|
251 | - throw new Exception("Unable to write data to file $target_file"); |
|
251 | + if (!$bytes_written = fwrite($fp, $blob)) { |
|
252 | + throw new Exception("Unable to write data to file $target_file"); |
|
253 | + } |
|
252 | 254 | |
253 | 255 | try { |
254 | 256 | unlink($_FILES['blob']['tmp_name']); |
255 | - }catch (Exception $e) { |
|
257 | + } catch (Exception $e) { |
|
256 | 258 | //silent message |
257 | 259 | } |
258 | 260 | |
259 | - }elseif (isset($_POST['blob'])) { |
|
261 | + } elseif (isset($_POST['blob'])) { |
|
260 | 262 | $this->logger->debug(sprintf('Writing %s bytes to file %s starting position %s using POST blob', strlen($_POST['blob']), $target_file, $_POST['start'])); |
261 | 263 | |
262 | 264 | $blob = $_POST['blob']; |
263 | 265 | |
264 | - if (!$bytes_written = fwrite($fp, $blob)) |
|
265 | - throw new Exception("Unable to write data to file $target_file"); |
|
266 | + if (!$bytes_written = fwrite($fp, $blob)) { |
|
267 | + throw new Exception("Unable to write data to file $target_file"); |
|
268 | + } |
|
266 | 269 | } else { |
267 | 270 | throw new Exception("Upload failed, did not receive any binary data"); |
268 | 271 | } |
@@ -297,10 +300,11 @@ discard block |
||
297 | 300 | |
298 | 301 | $mysqli->query("SET sql_mode='';"); |
299 | 302 | $mysqli->query("SET foreign_key_checks = 0;"); |
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;"); |
|
303 | + if (isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file']) { |
|
304 | + $mysqli->query("SET NAMES ".$_REQUEST['charset_of_file'].""); |
|
305 | + } else { |
|
306 | + $mysqli->query("SET NAMES utf8;"); |
|
307 | + } |
|
304 | 308 | |
305 | 309 | return $mysqli; |
306 | 310 | } |
@@ -330,8 +334,9 @@ discard block |
||
330 | 334 | |
331 | 335 | $mysql_backup_file = $remote_path.DS.$mysqldump_file; |
332 | 336 | |
333 | - if (!file_exists($mysql_backup_file)) |
|
334 | - throw new Exception(sprintf("Mysql backup file %s does not exists", $mysql_backup_file)); |
|
337 | + if (!file_exists($mysql_backup_file)) { |
|
338 | + throw new Exception(sprintf("Mysql backup file %s does not exists", $mysql_backup_file)); |
|
339 | + } |
|
335 | 340 | |
336 | 341 | |
337 | 342 | /*if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
@@ -364,16 +369,18 @@ discard block |
||
364 | 369 | // process the line read. |
365 | 370 | |
366 | 371 | //check if line is comment |
367 | - if (substr($line, 0, 1) == "#") |
|
368 | - continue; |
|
372 | + if (substr($line, 0, 1) == "#") { |
|
373 | + continue; |
|
374 | + } |
|
369 | 375 | |
370 | 376 | //check if line is empty |
371 | - if ($line == "\n" or trim($line) == "") |
|
372 | - continue; |
|
377 | + if ($line == "\n" or trim($line) == "") { |
|
378 | + continue; |
|
379 | + } |
|
373 | 380 | |
374 | - if (substr($line, strlen($line) - 2, strlen($line)) == ";\n") |
|
375 | - $query .= $line; |
|
376 | - else { |
|
381 | + if (substr($line, strlen($line) - 2, strlen($line)) == ";\n") { |
|
382 | + $query .= $line; |
|
383 | + } else { |
|
377 | 384 | $query .= $line; |
378 | 385 | continue; |
379 | 386 | } |
@@ -497,7 +504,7 @@ discard block |
||
497 | 504 | $tar->open($this->backup_storage_dir.DS.$backup_file, $start); |
498 | 505 | |
499 | 506 | $data = $tar->contents($this->process_files_limit_list); |
500 | - }catch (Exception $e) |
|
507 | + } catch (Exception $e) |
|
501 | 508 | { |
502 | 509 | $return['error'] = true; |
503 | 510 | $return['message'] = $e->getMessage(); |
@@ -532,8 +539,9 @@ discard block |
||
532 | 539 | |
533 | 540 | ++$return['part']; |
534 | 541 | |
535 | - if ($return['part'] < sizeof($backup_parts)) |
|
536 | - $return['finished'] = 0; |
|
542 | + if ($return['part'] < sizeof($backup_parts)) { |
|
543 | + $return['finished'] = 0; |
|
544 | + } |
|
537 | 545 | |
538 | 546 | } |
539 | 547 | } |
@@ -674,19 +682,22 @@ discard block |
||
674 | 682 | { |
675 | 683 | $config = file_get_contents($wp_config); |
676 | 684 | preg_match("/.*table_prefix.*=.*'(.*)'/i", $config, $matches); |
677 | - if (isset($matches[1])) |
|
678 | - $table_prefix = $matches[1]; |
|
679 | - else |
|
680 | - throw new Exception("Could not load wordpress table prefix from wp-config.php file."); |
|
685 | + if (isset($matches[1])) { |
|
686 | + $table_prefix = $matches[1]; |
|
687 | + } else { |
|
688 | + throw new Exception("Could not load wordpress table prefix from wp-config.php file."); |
|
689 | + } |
|
690 | + } else { |
|
691 | + throw new Exception("Could not update the SITEURL and HOME, wp-config.php file not found"); |
|
681 | 692 | } |
682 | - else |
|
683 | - throw new Exception("Could not update the SITEURL and HOME, wp-config.php file not found"); |
|
684 | 693 | |
685 | - if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'")) |
|
686 | - throw new Exception(sprintf("Could not update the HOME option, error: %s\n", $mysqli->error)); |
|
694 | + if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'")) { |
|
695 | + throw new Exception(sprintf("Could not update the HOME option, error: %s\n", $mysqli->error)); |
|
696 | + } |
|
687 | 697 | |
688 | - if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'")) |
|
689 | - throw new Exception(sprintf("Could not update the SITEURL option, error: %s\n", $mysqli->error)); |
|
698 | + if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'")) { |
|
699 | + throw new Exception(sprintf("Could not update the SITEURL option, error: %s\n", $mysqli->error)); |
|
700 | + } |
|
690 | 701 | |
691 | 702 | return true; |
692 | 703 | } |
@@ -724,8 +735,9 @@ discard block |
||
724 | 735 | |
725 | 736 | $this->logger->info(sprintf('Updating wp-config.php file with the new mysql details')); |
726 | 737 | |
727 | - if (!file_put_contents($wp_config, $content)) |
|
728 | - throw new Exception("Could not write updated config data to ".$wp_config); |
|
738 | + if (!file_put_contents($wp_config, $content)) { |
|
739 | + throw new Exception("Could not write updated config data to ".$wp_config); |
|
740 | + } |
|
729 | 741 | |
730 | 742 | chmod($wp_config, $file_perms); |
731 | 743 | |
@@ -770,10 +782,11 @@ discard block |
||
770 | 782 | $mysqldump_list[$file['path']]['size'] = $file['size']; |
771 | 783 | $mysqldump_list[$file['path']]['timestamp'] = date("d M,Y H:i", $file['timestamp']); |
772 | 784 | |
773 | - if ($hash and $hash == $matches[1]) |
|
774 | - $mysqldump_list[$file['path']]['selected'] = "selected"; |
|
775 | - else |
|
776 | - $mysqldump_list[$file['path']]['selected'] = ""; |
|
785 | + if ($hash and $hash == $matches[1]) { |
|
786 | + $mysqldump_list[$file['path']]['selected'] = "selected"; |
|
787 | + } else { |
|
788 | + $mysqldump_list[$file['path']]['selected'] = ""; |
|
789 | + } |
|
777 | 790 | } |
778 | 791 | } |
779 | 792 | } |
@@ -794,13 +807,15 @@ discard block |
||
794 | 807 | */ |
795 | 808 | private function get_hash_from_backup($backup_file) |
796 | 809 | { |
797 | - if (!$backup_file) |
|
798 | - return false; |
|
810 | + if (!$backup_file) { |
|
811 | + return false; |
|
812 | + } |
|
799 | 813 | |
800 | 814 | $result = preg_match("/-(\w*)./", substr($backup_file, strlen($backup_file) - 10, strlen($backup_file)), $matches); |
801 | 815 | |
802 | - if ($result and isset($matches[1])) |
|
803 | - return ($matches[1]); |
|
816 | + if ($result and isset($matches[1])) { |
|
817 | + return ($matches[1]); |
|
818 | + } |
|
804 | 819 | |
805 | 820 | return false; |
806 | 821 | } |
@@ -825,10 +840,11 @@ discard block |
||
825 | 840 | if (isset($file_info['extension']) and $file_info['extension'] == "csv") |
826 | 841 | { |
827 | 842 | $lines = explode(PHP_EOL, $this->filesystem->read($file_info['path'])); |
828 | - foreach ($lines as $line) |
|
829 | - if ($line) |
|
843 | + foreach ($lines as $line) { |
|
844 | + if ($line) |
|
830 | 845 | { |
831 | 846 | $data = str_getcsv($line); |
847 | + } |
|
832 | 848 | if (is_array($data)) { |
833 | 849 | $parents[$data[0]] = $file_info['path']; |
834 | 850 | $file_info['childs'][] = $data; |
@@ -838,20 +854,22 @@ discard block |
||
838 | 854 | |
839 | 855 | } |
840 | 856 | |
841 | - if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
842 | - $backup_files[$file_info['path']] = $file_info; |
|
857 | + if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) { |
|
858 | + $backup_files[$file_info['path']] = $file_info; |
|
859 | + } |
|
843 | 860 | } |
844 | 861 | |
845 | 862 | $new_list = array(); |
846 | 863 | |
847 | 864 | foreach ($backup_files as $key=>$file_info) |
848 | 865 | { |
849 | - if (isset($parents[$file_info['path']])) |
|
850 | - $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
851 | - else { |
|
866 | + if (isset($parents[$file_info['path']])) { |
|
867 | + $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
868 | + } else { |
|
852 | 869 | |
853 | - if ($local_backup_file and ($file_info['basename'] == $local_backup_file)) |
|
854 | - $file_info['selected'] = 'selected'; |
|
870 | + if ($local_backup_file and ($file_info['basename'] == $local_backup_file)) { |
|
871 | + $file_info['selected'] = 'selected'; |
|
872 | + } |
|
855 | 873 | |
856 | 874 | $this->logger->info(sprintf('Found %s backup file', $file_info['path'])); |
857 | 875 | |
@@ -898,8 +916,9 @@ discard block |
||
898 | 916 | $backup_archive = new Tar(); |
899 | 917 | if ($this->is_multipart($backup_file)) |
900 | 918 | { |
901 | - if (!$return['part']) |
|
902 | - $return['processed'] += $this->filesystem->getSize($backup_file); |
|
919 | + if (!$return['part']) { |
|
920 | + $return['processed'] += $this->filesystem->getSize($backup_file); |
|
921 | + } |
|
903 | 922 | |
904 | 923 | $backup_parts = $this->get_multipart_files($backup_file); |
905 | 924 | $backup_file = $backup_parts[$return['part']]; |
@@ -919,10 +938,11 @@ discard block |
||
919 | 938 | } |
920 | 939 | } |
921 | 940 | |
922 | - if (isset($data['start'])) |
|
923 | - //if(isset($data['start']) and $data['start'] <= $this->filesystem->getSize($backup_file)) |
|
941 | + if (isset($data['start'])) { |
|
942 | + //if(isset($data['start']) and $data['start'] <= $this->filesystem->getSize($backup_file)) |
|
924 | 943 | { |
925 | 944 | $return['finished'] = 0; |
945 | + } |
|
926 | 946 | $return['start'] = $data['start']; |
927 | 947 | } else { |
928 | 948 | |
@@ -934,14 +954,16 @@ discard block |
||
934 | 954 | |
935 | 955 | ++$return['part']; |
936 | 956 | |
937 | - if ($return['part'] < sizeof($backup_parts)) |
|
938 | - $return['finished'] = 0; |
|
957 | + if ($return['part'] < sizeof($backup_parts)) { |
|
958 | + $return['finished'] = 0; |
|
959 | + } |
|
939 | 960 | |
940 | 961 | } |
941 | 962 | } |
942 | 963 | |
943 | - if ($return['finished']) |
|
944 | - $this->logger->info(sprintf('Done extracting %s', $source_backup_file)); |
|
964 | + if ($return['finished']) { |
|
965 | + $this->logger->info(sprintf('Done extracting %s', $source_backup_file)); |
|
966 | + } |
|
945 | 967 | |
946 | 968 | $return['backup_file'] = $backup_file; |
947 | 969 | |
@@ -973,8 +995,7 @@ discard block |
||
973 | 995 | $return['remote_mysql_user'] = $wpdb->dbuser; |
974 | 996 | $return['remote_mysql_pass'] = $wpdb->dbpassword; |
975 | 997 | $return['remote_mysql_db'] = $wpdb->dbname; |
976 | - } |
|
977 | - else { |
|
998 | + } else { |
|
978 | 999 | $return['dir'] = ($pathinfo['dirname']).DS.$suffix; |
979 | 1000 | $return['restore_script_url'] = str_replace($pathinfo['basename'], "", $restore_script_url).$suffix; |
980 | 1001 | } |
@@ -993,11 +1014,13 @@ discard block |
||
993 | 1014 | { |
994 | 1015 | //check if i can write |
995 | 1016 | $tmp_file = md5(time()); |
996 | - if (!file_put_contents($tmp_file, "++")) |
|
997 | - throw new Exception("Could not write to new host"); |
|
1017 | + if (!file_put_contents($tmp_file, "++")) { |
|
1018 | + throw new Exception("Could not write to new host"); |
|
1019 | + } |
|
998 | 1020 | |
999 | - if (!unlink($tmp_file)) |
|
1000 | - throw new Exception("Could not delete temporary file from new host"); |
|
1021 | + if (!unlink($tmp_file)) { |
|
1022 | + throw new Exception("Could not delete temporary file from new host"); |
|
1023 | + } |
|
1001 | 1024 | |
1002 | 1025 | $max_upload = $this->return_bytes((ini_get('upload_max_filesize'))); |
1003 | 1026 | $max_post = $this->return_bytes((ini_get('post_max_size'))); |
@@ -1041,8 +1064,9 @@ discard block |
||
1041 | 1064 | */ |
1042 | 1065 | public function is_multipart($backup_name) |
1043 | 1066 | { |
1044 | - if (stristr($backup_name, "-multipart")) |
|
1045 | - return true; |
|
1067 | + if (stristr($backup_name, "-multipart")) { |
|
1068 | + return true; |
|
1069 | + } |
|
1046 | 1070 | |
1047 | 1071 | return false; |
1048 | 1072 | } |
@@ -1060,8 +1084,9 @@ discard block |
||
1060 | 1084 | if ($this->is_multipart($backup_name)) |
1061 | 1085 | { |
1062 | 1086 | $backup_parts = $this->get_multipart_files($backup_name); |
1063 | - foreach ($backup_parts as $part_file) |
|
1064 | - $backup_size += $this->filesystem->getSize($part_file); |
|
1087 | + foreach ($backup_parts as $part_file) { |
|
1088 | + $backup_size += $this->filesystem->getSize($part_file); |
|
1089 | + } |
|
1065 | 1090 | } |
1066 | 1091 | |
1067 | 1092 | return $backup_size; |
@@ -1123,15 +1148,13 @@ discard block |
||
1123 | 1148 | if ($direction == 'desc') { |
1124 | 1149 | if ($a > $b) { |
1125 | 1150 | return -1; |
1126 | - } |
|
1127 | - else { |
|
1151 | + } else { |
|
1128 | 1152 | return 1; |
1129 | 1153 | } |
1130 | 1154 | } else { |
1131 | 1155 | if ($a < $b) { |
1132 | 1156 | return -1; |
1133 | - } |
|
1134 | - else { |
|
1157 | + } else { |
|
1135 | 1158 | return 1; |
1136 | 1159 | } |
1137 | 1160 | } |
@@ -1161,7 +1184,7 @@ discard block |
||
1161 | 1184 | { |
1162 | 1185 | $return['statusText'] = $response['message']; |
1163 | 1186 | $return['error'] = true; |
1164 | - }elseif ($status != 200 and $status != 418) |
|
1187 | + } elseif ($status != 200 and $status != 418) |
|
1165 | 1188 | { |
1166 | 1189 | $return['error'] = true; |
1167 | 1190 | $return['message'] = $response; |
@@ -1185,8 +1208,9 @@ discard block |
||
1185 | 1208 | return preg_replace_callback('!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!', function($m) { |
1186 | 1209 | $data = ""; |
1187 | 1210 | |
1188 | - if (!isset($m[3])) |
|
1189 | - $m[3] = ""; |
|
1211 | + if (!isset($m[3])) { |
|
1212 | + $m[3] = ""; |
|
1213 | + } |
|
1190 | 1214 | |
1191 | 1215 | $data = 's:'.strlen(($m[3])).':\"'.($m[3]).'\";'; |
1192 | 1216 | //return $this->unescape_quotes($data); |