@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | try { |
254 | 254 | unlink($_FILES['blob']['tmp_name']); |
255 | 255 | }catch (Exception $e) { |
256 | - //silent message |
|
256 | + //silent message |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | }elseif (isset($_POST['blob'])) { |
@@ -424,18 +424,18 @@ discard block |
||
424 | 424 | |
425 | 425 | } |
426 | 426 | |
427 | - $return['start'] = ftell($fp); |
|
427 | + $return['start'] = ftell($fp); |
|
428 | 428 | |
429 | - $this->logger->info(sprintf("Executed %s queries of size %s bytes", $line_count, ($return['start'] - $start))); |
|
429 | + $this->logger->info(sprintf("Executed %s queries of size %s bytes", $line_count, ($return['start'] - $start))); |
|
430 | 430 | |
431 | - if (!feof($fp)) |
|
432 | - { |
|
433 | - $return['finished'] = 0; |
|
434 | - } else { |
|
435 | - $this->logger->info(sprintf("Mysql Import Done.")); |
|
436 | - } |
|
431 | + if (!feof($fp)) |
|
432 | + { |
|
433 | + $return['finished'] = 0; |
|
434 | + } else { |
|
435 | + $this->logger->info(sprintf("Mysql Import Done.")); |
|
436 | + } |
|
437 | 437 | |
438 | - fclose($fp); |
|
438 | + fclose($fp); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | $this->send_response(200, $return); |
@@ -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); |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | $hook = 'xcloner_scheduler_'.$schedule->id; |
105 | 105 | |
106 | 106 | if($timestamp = wp_next_scheduled($hook, array($schedule->id))) { |
107 | - wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
108 | - } |
|
107 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
108 | + } |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
@@ -128,8 +128,8 @@ discard block |
||
128 | 128 | |
129 | 129 | } elseif (!$schedule->status) { |
130 | 130 | if($timestamp = wp_next_scheduled($hook, array($schedule->id))) { |
131 | - wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
132 | - } |
|
131 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
132 | + } |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | $hook = 'xcloner_scheduler_'.$schedule->id; |
141 | 141 | |
142 | 142 | if( $timestamp = wp_next_scheduled($hook, array($schedule->id))) { |
143 | - wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
144 | - } |
|
143 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
144 | + } |
|
145 | 145 | |
146 | 146 | if ($schedule->status) { |
147 | 147 | |
@@ -155,12 +155,12 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | public function disable_single_cron($schedule_id) { |
158 | - $schedule = array(); |
|
158 | + $schedule = array(); |
|
159 | 159 | $hook = 'xcloner_scheduler_'.$schedule_id; |
160 | 160 | |
161 | 161 | if($timestamp = wp_next_scheduled($hook, array($schedule_id))) { |
162 | - wp_unschedule_event($timestamp, $hook, array($schedule_id)); |
|
163 | - } |
|
162 | + wp_unschedule_event($timestamp, $hook, array($schedule_id)); |
|
163 | + } |
|
164 | 164 | |
165 | 165 | $schedule['status'] = 0; |
166 | 166 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | } |
197 | 197 | |
198 | 198 | public function update_last_backup($schedule_id, $last_backup) { |
199 | - $schedule = array(); |
|
199 | + $schedule = array(); |
|
200 | 200 | |
201 | 201 | $this->logger->info(sprintf('Updating last backup %s for schedule id #%s', $last_backup, $schedule_id)); |
202 | 202 | |
@@ -222,9 +222,9 @@ discard block |
||
222 | 222 | $xcloner = new XCloner(); |
223 | 223 | $xcloner->init(); |
224 | 224 | $this->set_xcloner_container( $xcloner ); |
225 | - $return_encrypted = array(); |
|
226 | - $return = array(); |
|
227 | - $additional = array(); |
|
225 | + $return_encrypted = array(); |
|
226 | + $return = array(); |
|
227 | + $additional = array(); |
|
228 | 228 | |
229 | 229 | #$hash = $this->xcloner_settings->get_hash(); |
230 | 230 | #$this->get_xcloner_container()->get_xcloner_settings()->set_hash($hash); |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | foreach ($list as $schedule) { |
104 | 104 | $hook = 'xcloner_scheduler_'.$schedule->id; |
105 | 105 | |
106 | - if($timestamp = wp_next_scheduled($hook, array($schedule->id))) { |
|
106 | + if ($timestamp = wp_next_scheduled($hook, array($schedule->id))) { |
|
107 | 107 | wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
108 | 108 | } |
109 | 109 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | } |
128 | 128 | |
129 | 129 | } elseif (!$schedule->status) { |
130 | - if($timestamp = wp_next_scheduled($hook, array($schedule->id))) { |
|
130 | + if ($timestamp = wp_next_scheduled($hook, array($schedule->id))) { |
|
131 | 131 | wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
132 | 132 | } |
133 | 133 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $schedule = $this->get_schedule_by_id_object($id); |
140 | 140 | $hook = 'xcloner_scheduler_'.$schedule->id; |
141 | 141 | |
142 | - if( $timestamp = wp_next_scheduled($hook, array($schedule->id))) { |
|
142 | + if ($timestamp = wp_next_scheduled($hook, array($schedule->id))) { |
|
143 | 143 | wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
144 | 144 | } |
145 | 145 | |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | |
157 | 157 | public function disable_single_cron($schedule_id) { |
158 | 158 | $schedule = array(); |
159 | - $hook = 'xcloner_scheduler_'.$schedule_id; |
|
159 | + $hook = 'xcloner_scheduler_'.$schedule_id; |
|
160 | 160 | |
161 | - if($timestamp = wp_next_scheduled($hook, array($schedule_id))) { |
|
161 | + if ($timestamp = wp_next_scheduled($hook, array($schedule_id))) { |
|
162 | 162 | wp_unschedule_event($timestamp, $hook, array($schedule_id)); |
163 | 163 | } |
164 | 164 | |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | return $update; |
178 | 178 | } |
179 | 179 | |
180 | - public function update_hash( $schedule_id, $hash ) { |
|
180 | + public function update_hash($schedule_id, $hash) { |
|
181 | 181 | $schedule = array(); |
182 | 182 | |
183 | 183 | $schedule['hash'] = $hash; |
@@ -215,13 +215,13 @@ discard block |
||
215 | 215 | return $update; |
216 | 216 | } |
217 | 217 | |
218 | - private function _xcloner_scheduler_callback( $id, $schedule ) { |
|
219 | - set_time_limit( 0 ); |
|
218 | + private function _xcloner_scheduler_callback($id, $schedule) { |
|
219 | + set_time_limit(0); |
|
220 | 220 | |
221 | 221 | |
222 | 222 | $xcloner = new XCloner(); |
223 | 223 | $xcloner->init(); |
224 | - $this->set_xcloner_container( $xcloner ); |
|
224 | + $this->set_xcloner_container($xcloner); |
|
225 | 225 | $return_encrypted = array(); |
226 | 226 | $return = array(); |
227 | 227 | $additional = array(); |
@@ -231,79 +231,79 @@ discard block |
||
231 | 231 | |
232 | 232 | //$this->xcloner_settings = $this->get_xcloner_container()->get_xcloner_settings(); |
233 | 233 | $this->xcloner_file_system = $this->get_xcloner_container()->get_xcloner_filesystem(); |
234 | - $this->xcloner_encryption = $this->get_xcloner_container()->get_xcloner_encryption(); |
|
234 | + $this->xcloner_encryption = $this->get_xcloner_container()->get_xcloner_encryption(); |
|
235 | 235 | $this->xcloner_database = $this->get_xcloner_container()->get_xcloner_database(); |
236 | 236 | $this->archive_system = $this->get_xcloner_container()->get_archive_system(); |
237 | - $this->logger = $this->get_xcloner_container()->get_xcloner_logger()->withName( "xcloner_scheduler" ); |
|
237 | + $this->logger = $this->get_xcloner_container()->get_xcloner_logger()->withName("xcloner_scheduler"); |
|
238 | 238 | $this->xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
239 | 239 | |
240 | - $this->logger->info( sprintf( "New schedule hash is %s", $this->xcloner_settings->get_hash() ) ); |
|
240 | + $this->logger->info(sprintf("New schedule hash is %s", $this->xcloner_settings->get_hash())); |
|
241 | 241 | |
242 | - if ( isset( $schedule['backup_params']->diff_start_date ) && $schedule['backup_params']->diff_start_date ) { |
|
243 | - $this->xcloner_file_system->set_diff_timestamp_start( $schedule['backup_params']->diff_start_date ); |
|
242 | + if (isset($schedule['backup_params']->diff_start_date) && $schedule['backup_params']->diff_start_date) { |
|
243 | + $this->xcloner_file_system->set_diff_timestamp_start($schedule['backup_params']->diff_start_date); |
|
244 | 244 | } |
245 | 245 | |
246 | - if ( $schedule['recurrence'] == "single" ) { |
|
247 | - $this->disable_single_cron( $schedule['id'] ); |
|
246 | + if ($schedule['recurrence'] == "single") { |
|
247 | + $this->disable_single_cron($schedule['id']); |
|
248 | 248 | } |
249 | 249 | |
250 | - if ( ! $schedule ) { |
|
251 | - $this->logger->info( sprintf( "Could not load schedule with id'%s'", $id ), array( "CRON" ) ); |
|
250 | + if (!$schedule) { |
|
251 | + $this->logger->info(sprintf("Could not load schedule with id'%s'", $id), array("CRON")); |
|
252 | 252 | |
253 | 253 | return; |
254 | 254 | } |
255 | 255 | |
256 | 256 | //echo $this->get_xcloner_container()->get_xcloner_settings()->get_hash(); exit; |
257 | 257 | |
258 | - $this->update_hash( $schedule['id'], $this->xcloner_settings->get_hash() ); |
|
258 | + $this->update_hash($schedule['id'], $this->xcloner_settings->get_hash()); |
|
259 | 259 | |
260 | - $this->logger->info( sprintf( "Starting cron schedule '%s'", $schedule['name'] ), array( "CRON" ) ); |
|
260 | + $this->logger->info(sprintf("Starting cron schedule '%s'", $schedule['name']), array("CRON")); |
|
261 | 261 | |
262 | - $this->xcloner_file_system->set_excluded_files( json_decode( $schedule['excluded_files'] ) ); |
|
262 | + $this->xcloner_file_system->set_excluded_files(json_decode($schedule['excluded_files'])); |
|
263 | 263 | |
264 | 264 | $init = 1; |
265 | 265 | $continue = 1; |
266 | 266 | |
267 | - while ( $continue ) { |
|
268 | - $continue = $this->xcloner_file_system->start_file_recursion( $init ); |
|
267 | + while ($continue) { |
|
268 | + $continue = $this->xcloner_file_system->start_file_recursion($init); |
|
269 | 269 | |
270 | 270 | $init = 0; |
271 | 271 | } |
272 | 272 | |
273 | - $this->logger->info( sprintf( "File scan finished" ), array( "CRON" ) ); |
|
273 | + $this->logger->info(sprintf("File scan finished"), array("CRON")); |
|
274 | 274 | |
275 | - $this->logger->info( sprintf( "Starting the database backup" ), array( "CRON" ) ); |
|
275 | + $this->logger->info(sprintf("Starting the database backup"), array("CRON")); |
|
276 | 276 | |
277 | 277 | $init = 1; |
278 | 278 | $return['finished'] = 0; |
279 | 279 | |
280 | - while ( ! $return['finished'] ) { |
|
281 | - $return = $this->xcloner_database->start_database_recursion( (array) json_decode( $schedule['table_params'] ), $return, $init ); |
|
280 | + while (!$return['finished']) { |
|
281 | + $return = $this->xcloner_database->start_database_recursion((array)json_decode($schedule['table_params']), $return, $init); |
|
282 | 282 | $init = 0; |
283 | 283 | } |
284 | 284 | |
285 | - $this->logger->info( sprintf( "Database backup done" ), array( "CRON" ) ); |
|
285 | + $this->logger->info(sprintf("Database backup done"), array("CRON")); |
|
286 | 286 | |
287 | - $this->logger->info( sprintf( "Starting file archive process" ), array( "CRON" ) ); |
|
287 | + $this->logger->info(sprintf("Starting file archive process"), array("CRON")); |
|
288 | 288 | |
289 | 289 | $init = 0; |
290 | 290 | $return['finished'] = 0; |
291 | 291 | $return['extra'] = array(); |
292 | 292 | |
293 | - while ( ! $return['finished'] ) { |
|
294 | - $return = $this->archive_system->start_incremental_backup( (array) $schedule['backup_params'], $return['extra'], $init ); |
|
293 | + while (!$return['finished']) { |
|
294 | + $return = $this->archive_system->start_incremental_backup((array)$schedule['backup_params'], $return['extra'], $init); |
|
295 | 295 | $init = 0; |
296 | 296 | } |
297 | - $this->logger->info( sprintf( "File archive process FINISHED." ), array( "CRON" ) ); |
|
297 | + $this->logger->info(sprintf("File archive process FINISHED."), array("CRON")); |
|
298 | 298 | |
299 | 299 | //getting the last backup archive file |
300 | 300 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); |
301 | - if ( $this->xcloner_file_system->is_part( $this->archive_system->get_archive_name_with_extension() ) ) { |
|
301 | + if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) { |
|
302 | 302 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
303 | 303 | } |
304 | 304 | |
305 | 305 | //Updating schedule last backup archive |
306 | - $this->update_last_backup( $schedule['id'], $return['extra']['backup_parent'] ); |
|
306 | + $this->update_last_backup($schedule['id'], $return['extra']['backup_parent']); |
|
307 | 307 | |
308 | 308 | //Encrypting the backup archive |
309 | 309 | $return_encrypted['finished'] = 0; |
@@ -313,8 +313,8 @@ discard block |
||
313 | 313 | $part = 0; |
314 | 314 | $backup_parts = array(); |
315 | 315 | |
316 | - if( $schedule['backup_params']->backup_encrypt){ |
|
317 | - $this->logger->info( sprintf( "Encrypting backup archive %s.", $return['extra']['backup_parent'] ), array( "CRON" ) ); |
|
316 | + if ($schedule['backup_params']->backup_encrypt) { |
|
317 | + $this->logger->info(sprintf("Encrypting backup archive %s.", $return['extra']['backup_parent']), array("CRON")); |
|
318 | 318 | |
319 | 319 | $backup_file = $return['extra']['backup_parent']; |
320 | 320 | |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | $backup_file = $backup_parts[$part]; |
324 | 324 | } |
325 | 325 | |
326 | - while ( ! $return_encrypted['finished'] ) { |
|
326 | + while (!$return_encrypted['finished']) { |
|
327 | 327 | $return_encrypted = $this->xcloner_encryption->encrypt_file( |
328 | 328 | $backup_file, |
329 | 329 | "", |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | true |
335 | 335 | ); |
336 | 336 | |
337 | - if($return_encrypted['finished']) { |
|
337 | + if ($return_encrypted['finished']) { |
|
338 | 338 | ++$part; |
339 | 339 | |
340 | 340 | if ($part < sizeof($backup_parts)) { |
@@ -346,37 +346,37 @@ discard block |
||
346 | 346 | } |
347 | 347 | |
348 | 348 | //Sending backup to remote storage |
349 | - if ( isset( $schedule['remote_storage'] ) && $schedule['remote_storage'] && array_key_exists( $schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages() ) ) { |
|
349 | + if (isset($schedule['remote_storage']) && $schedule['remote_storage'] && array_key_exists($schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages())) { |
|
350 | 350 | $backup_file = $return['extra']['backup_parent']; |
351 | 351 | |
352 | - $this->logger->info( sprintf( "Transferring backup to remote storage %s", strtoupper( $schedule['remote_storage'] ) ), array( "CRON" ) ); |
|
352 | + $this->logger->info(sprintf("Transferring backup to remote storage %s", strtoupper($schedule['remote_storage'])), array("CRON")); |
|
353 | 353 | |
354 | - if ( method_exists( $this->xcloner_remote_storage, "upload_backup_to_storage" ) ) { |
|
355 | - call_user_func_array( array( |
|
354 | + if (method_exists($this->xcloner_remote_storage, "upload_backup_to_storage")) { |
|
355 | + call_user_func_array(array( |
|
356 | 356 | $this->xcloner_remote_storage, |
357 | 357 | "upload_backup_to_storage" |
358 | - ), array( $backup_file, $schedule['remote_storage'] ) ); |
|
358 | + ), array($backup_file, $schedule['remote_storage'])); |
|
359 | 359 | } |
360 | 360 | } |
361 | 361 | |
362 | 362 | //Sending email notification |
363 | - if ( isset( $schedule['backup_params']->email_notification ) and $to = $schedule['backup_params']->email_notification ) { |
|
363 | + if (isset($schedule['backup_params']->email_notification) and $to = $schedule['backup_params']->email_notification) { |
|
364 | 364 | try { |
365 | 365 | $from = ""; |
366 | 366 | $additional['lines_total'] = $return['extra']['lines_total']; |
367 | - $subject = sprintf( __( "%s - new backup generated %s" ), $schedule['name'], $return['extra']['backup_parent'] ); |
|
367 | + $subject = sprintf(__("%s - new backup generated %s"), $schedule['name'], $return['extra']['backup_parent']); |
|
368 | 368 | |
369 | - $this->archive_system->send_notification( $to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional ); |
|
369 | + $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional); |
|
370 | 370 | |
371 | - } catch ( Exception $e ) { |
|
372 | - $this->logger->error( $e->getMessage() ); |
|
371 | + }catch (Exception $e) { |
|
372 | + $this->logger->error($e->getMessage()); |
|
373 | 373 | } |
374 | 374 | } |
375 | 375 | |
376 | 376 | //CHECK IF WE SHOULD DELETE BACKUP AFTER REMOTE TRANSFER IS DONE |
377 | - if ( $schedule['remote_storage'] && $this->xcloner_settings->get_xcloner_option( 'xcloner_cleanup_delete_after_remote_transfer' ) ) { |
|
378 | - $this->logger->info( sprintf( "Deleting %s from local storage matching rule xcloner_cleanup_delete_after_remote_transfer", $return['extra']['backup_parent'] ) ); |
|
379 | - $this->xcloner_file_system->delete_backup_by_name( $return['extra']['backup_parent'] ); |
|
377 | + if ($schedule['remote_storage'] && $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_delete_after_remote_transfer')) { |
|
378 | + $this->logger->info(sprintf("Deleting %s from local storage matching rule xcloner_cleanup_delete_after_remote_transfer", $return['extra']['backup_parent'])); |
|
379 | + $this->xcloner_file_system->delete_backup_by_name($return['extra']['backup_parent']); |
|
380 | 380 | |
381 | 381 | } |
382 | 382 | |
@@ -390,28 +390,28 @@ discard block |
||
390 | 390 | $this->xcloner_file_system->cleanup_tmp_directories(); |
391 | 391 | } |
392 | 392 | |
393 | - public function xcloner_scheduler_callback( $id, $schedule = "" ) { |
|
394 | - if ( $id ) { |
|
395 | - $schedule = $this->get_schedule_by_id( $id ); |
|
393 | + public function xcloner_scheduler_callback($id, $schedule = "") { |
|
394 | + if ($id) { |
|
395 | + $schedule = $this->get_schedule_by_id($id); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | try { |
399 | - if( get_option('xcloner_disable_email_notification') ) { |
|
399 | + if (get_option('xcloner_disable_email_notification')) { |
|
400 | 400 | //we disable email notifications |
401 | 401 | $schedule['backup_params']->email_notification = ""; |
402 | 402 | } |
403 | - $this->_xcloner_scheduler_callback( $id, $schedule ); |
|
403 | + $this->_xcloner_scheduler_callback($id, $schedule); |
|
404 | 404 | |
405 | - } catch ( Exception $e ) { |
|
405 | + }catch (Exception $e) { |
|
406 | 406 | |
407 | 407 | //send email to site admin if email notification is not set in the scheduler |
408 | - if ( ! isset( $schedule['backup_params']->email_notification ) || ! $schedule['backup_params']->email_notification ) { |
|
409 | - $schedule['backup_params']->email_notification = get_option( 'admin_email' ); |
|
408 | + if (!isset($schedule['backup_params']->email_notification) || !$schedule['backup_params']->email_notification) { |
|
409 | + $schedule['backup_params']->email_notification = get_option('admin_email'); |
|
410 | 410 | } |
411 | 411 | |
412 | - if ( isset( $schedule['backup_params']->email_notification ) && $to = $schedule['backup_params']->email_notification ) { |
|
412 | + if (isset($schedule['backup_params']->email_notification) && $to = $schedule['backup_params']->email_notification) { |
|
413 | 413 | $from = ""; |
414 | - $this->archive_system->send_notification( $to, $from, $schedule['name'] . " - backup error", "", "", $e->getMessage() ); |
|
414 | + $this->archive_system->send_notification($to, $from, $schedule['name']." - backup error", "", "", $e->getMessage()); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | } |