@@ -10,61 +10,61 @@ discard block |
||
10 | 10 | private $max_logger_files = 7; |
11 | 11 | private $main_logger_url; |
12 | 12 | |
13 | - public function __construct( Xcloner $xcloner_container, $logger_name = "xcloner_logger" ) { |
|
14 | - if ( ! $xcloner_container->get_xcloner_settings() ) { |
|
15 | - $xcloner_settings = new Xcloner_Settings( $xcloner_container ); |
|
13 | + public function __construct(Xcloner $xcloner_container, $logger_name = "xcloner_logger") { |
|
14 | + if (!$xcloner_container->get_xcloner_settings()) { |
|
15 | + $xcloner_settings = new Xcloner_Settings($xcloner_container); |
|
16 | 16 | } else { |
17 | 17 | $xcloner_settings = $xcloner_container->get_xcloner_settings(); |
18 | 18 | } |
19 | 19 | |
20 | 20 | $hash = $xcloner_settings->get_hash(); |
21 | - if ( $hash == "-" . $xcloner_settings->get_server_unique_hash( 5 ) ) { |
|
21 | + if ($hash == "-".$xcloner_settings->get_server_unique_hash(5)) { |
|
22 | 22 | $hash = ""; |
23 | 23 | } |
24 | 24 | |
25 | - $logger_path = $xcloner_settings->get_xcloner_store_path() . DS . $xcloner_settings->get_logger_filename(); |
|
25 | + $logger_path = $xcloner_settings->get_xcloner_store_path().DS.$xcloner_settings->get_logger_filename(); |
|
26 | 26 | $logger_path_tmp = ""; |
27 | 27 | |
28 | - if ( $hash ) { |
|
29 | - $logger_path_tmp = $xcloner_settings->get_xcloner_tmp_path() . DS . $xcloner_settings->get_logger_filename( 1 ); |
|
28 | + if ($hash) { |
|
29 | + $logger_path_tmp = $xcloner_settings->get_xcloner_tmp_path().DS.$xcloner_settings->get_logger_filename(1); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | $this->logger_path = $logger_path; |
33 | 33 | |
34 | - if ( ! is_dir( $xcloner_settings->get_xcloner_store_path() ) or ! is_writable( $xcloner_settings->get_xcloner_store_path() ) ) { |
|
34 | + if (!is_dir($xcloner_settings->get_xcloner_store_path()) or !is_writable($xcloner_settings->get_xcloner_store_path())) { |
|
35 | 35 | $logger_path = 'php://stderr'; |
36 | 36 | $logger_path_tmp = ""; |
37 | 37 | } |
38 | 38 | |
39 | - if ( ! $xcloner_settings->get_xcloner_option( 'xcloner_enable_log' ) ) { |
|
39 | + if (!$xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
|
40 | 40 | $logger_path = 'php://stderr'; |
41 | 41 | $logger_path_tmp = ""; |
42 | 42 | } |
43 | 43 | |
44 | 44 | // create a log channel |
45 | - parent::__construct( $logger_name ); |
|
45 | + parent::__construct($logger_name); |
|
46 | 46 | |
47 | 47 | $debug_level = Logger::INFO; |
48 | 48 | |
49 | - if ( WP_DEBUG ) { |
|
49 | + if (WP_DEBUG) { |
|
50 | 50 | $debug_level = Logger::DEBUG; |
51 | 51 | } |
52 | 52 | |
53 | 53 | |
54 | - if ( $logger_path ) { |
|
55 | - if ( ! $xcloner_settings->get_xcloner_option( 'xcloner_enable_log' ) ) { |
|
56 | - $stream = new StreamHandler( $logger_path, $debug_level ); |
|
54 | + if ($logger_path) { |
|
55 | + if (!$xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
|
56 | + $stream = new StreamHandler($logger_path, $debug_level); |
|
57 | 57 | } else { |
58 | - $stream = new RotatingFileHandler( $logger_path, $this->max_logger_files, $debug_level ); |
|
58 | + $stream = new RotatingFileHandler($logger_path, $this->max_logger_files, $debug_level); |
|
59 | 59 | } |
60 | 60 | |
61 | - $this->pushHandler( $stream ); |
|
61 | + $this->pushHandler($stream); |
|
62 | 62 | |
63 | 63 | $this->main_logger_url = $stream->getUrl(); |
64 | 64 | } |
65 | 65 | |
66 | - if ( $hash and $logger_path_tmp ) { |
|
67 | - $this->pushHandler( new StreamHandler( $logger_path_tmp, $debug_level ) ); |
|
66 | + if ($hash and $logger_path_tmp) { |
|
67 | + $this->pushHandler(new StreamHandler($logger_path_tmp, $debug_level)); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | //return $this; |
@@ -74,35 +74,35 @@ discard block |
||
74 | 74 | return $this->main_logger_url; |
75 | 75 | } |
76 | 76 | |
77 | - function getLastDebugLines( $totalLines = 200 ) { |
|
77 | + function getLastDebugLines($totalLines = 200) { |
|
78 | 78 | $lines = array(); |
79 | 79 | |
80 | - if ( ! file_exists( $this->main_logger_url ) or ! is_readable( $this->main_logger_url ) ) { |
|
80 | + if (!file_exists($this->main_logger_url) or !is_readable($this->main_logger_url)) { |
|
81 | 81 | return false; |
82 | 82 | } |
83 | 83 | |
84 | - $fp = fopen( $this->main_logger_url, 'r' ); |
|
85 | - fseek( $fp, - 1, SEEK_END ); |
|
86 | - $pos = ftell( $fp ); |
|
84 | + $fp = fopen($this->main_logger_url, 'r'); |
|
85 | + fseek($fp, - 1, SEEK_END); |
|
86 | + $pos = ftell($fp); |
|
87 | 87 | $lastLine = ""; |
88 | 88 | |
89 | 89 | // Loop backword until we have our lines or we reach the start |
90 | - while ( $pos > 0 && count( $lines ) < $totalLines ) { |
|
90 | + while ($pos > 0 && count($lines) < $totalLines) { |
|
91 | 91 | |
92 | - $C = fgetc( $fp ); |
|
93 | - if ( $C == "\n" ) { |
|
92 | + $C = fgetc($fp); |
|
93 | + if ($C == "\n") { |
|
94 | 94 | // skip empty lines |
95 | - if ( trim( $lastLine ) != "" ) { |
|
95 | + if (trim($lastLine) != "") { |
|
96 | 96 | $lines[] = $lastLine; |
97 | 97 | } |
98 | 98 | $lastLine = ''; |
99 | 99 | } else { |
100 | - $lastLine = $C . $lastLine; |
|
100 | + $lastLine = $C.$lastLine; |
|
101 | 101 | } |
102 | - fseek( $fp, $pos -- ); |
|
102 | + fseek($fp, $pos--); |
|
103 | 103 | } |
104 | 104 | |
105 | - $lines = array_reverse( $lines ); |
|
105 | + $lines = array_reverse($lines); |
|
106 | 106 | |
107 | 107 | return $lines; |
108 | 108 | } |
@@ -51,11 +51,11 @@ |
||
51 | 51 | |
52 | 52 | global $xcloner_plugin; |
53 | 53 | |
54 | - if ( is_a( $xcloner_plugin, 'Xcloner' ) ) { |
|
54 | + if (is_a($xcloner_plugin, 'Xcloner')) { |
|
55 | 55 | try { |
56 | 56 | $xcloner_plugin->get_xcloner_filesystem()->cleanup_tmp_directories(); |
57 | - } catch ( Exception $e ) { |
|
58 | - $xcloner_plugin->trigger_message_notice( $e->getMessage() ); |
|
57 | + }catch (Exception $e) { |
|
58 | + $xcloner_plugin->trigger_message_notice($e->getMessage()); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | $xcloner_scheduler = $xcloner_plugin->get_xcloner_scheduler(); |
@@ -213,6 +213,10 @@ discard block |
||
213 | 213 | * |
214 | 214 | * @return bool |
215 | 215 | */ |
216 | + |
|
217 | + /** |
|
218 | + * @param string $error_message |
|
219 | + */ |
|
216 | 220 | public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message) |
217 | 221 | { |
218 | 222 | |
@@ -638,6 +642,10 @@ discard block |
||
638 | 642 | * Add file to archive |
639 | 643 | * |
640 | 644 | */ |
645 | + |
|
646 | + /** |
|
647 | + * @param integer $append |
|
648 | + */ |
|
641 | 649 | public function add_file_to_archive($file_info, $start_at_byte, $byte_limit = 0, $append, $filesystem) |
642 | 650 | { |
643 | 651 |
@@ -36,171 +36,171 @@ discard block |
||
36 | 36 | */ |
37 | 37 | class Xcloner_Archive extends Tar |
38 | 38 | { |
39 | - /** |
|
40 | - * Process file size per API request |
|
41 | - * @var float|int |
|
42 | - */ |
|
43 | - private $file_size_per_request_limit = 52428800; //50MB = 52428800; 1MB = 1048576 |
|
44 | - /** |
|
45 | - * Files count to process per API request |
|
46 | - * @var int |
|
47 | - */ |
|
48 | - private $files_to_process_per_request = 250; //block of 512 bytes |
|
49 | - /** |
|
50 | - * Compression level, 0-uncompressed, 9-maximum compression |
|
51 | - * @var int |
|
52 | - */ |
|
53 | - private $compression_level = 0; //0-9 , 0 uncompressed |
|
54 | - /** |
|
55 | - * Split backup size limit |
|
56 | - * Create a new backup archive file once the set size is reached |
|
57 | - * @var float|int |
|
58 | - */ |
|
59 | - private $xcloner_split_backup_limit = 2048; //2048MB |
|
60 | - /** |
|
61 | - * Number of processed bytes |
|
62 | - * @var int |
|
63 | - */ |
|
64 | - private $processed_size_bytes = 0; |
|
65 | - |
|
66 | - /** |
|
67 | - * Archive name |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - private $archive_name; |
|
71 | - /** |
|
72 | - * @var Tar |
|
73 | - */ |
|
74 | - private $backup_archive; |
|
75 | - /** |
|
76 | - * @var Xcloner_File_System |
|
77 | - */ |
|
78 | - private $filesystem; |
|
79 | - /** |
|
80 | - * @var Xcloner_Logger |
|
81 | - */ |
|
82 | - private $logger; |
|
83 | - /** |
|
84 | - * @var Xcloner_Settings |
|
85 | - */ |
|
86 | - private $xcloner_settings; |
|
87 | - |
|
88 | - /** |
|
89 | - * [__construct description] |
|
90 | - * @param Xcloner $xcloner_container XCloner Container |
|
91 | - * @param string $archive_name Achive Name |
|
92 | - */ |
|
93 | - public function __construct(Xcloner $xcloner_container, $archive_name = "") |
|
94 | - { |
|
95 | - $this->filesystem = $xcloner_container->get_xcloner_filesystem(); |
|
96 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_archive"); |
|
97 | - $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
|
98 | - |
|
99 | - if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) { |
|
100 | - $this->file_size_per_request_limit = $value * 1024 * 1024; |
|
101 | - } //MB |
|
102 | - |
|
103 | - if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) { |
|
104 | - $this->files_to_process_per_request = $value; |
|
105 | - } |
|
39 | + /** |
|
40 | + * Process file size per API request |
|
41 | + * @var float|int |
|
42 | + */ |
|
43 | + private $file_size_per_request_limit = 52428800; //50MB = 52428800; 1MB = 1048576 |
|
44 | + /** |
|
45 | + * Files count to process per API request |
|
46 | + * @var int |
|
47 | + */ |
|
48 | + private $files_to_process_per_request = 250; //block of 512 bytes |
|
49 | + /** |
|
50 | + * Compression level, 0-uncompressed, 9-maximum compression |
|
51 | + * @var int |
|
52 | + */ |
|
53 | + private $compression_level = 0; //0-9 , 0 uncompressed |
|
54 | + /** |
|
55 | + * Split backup size limit |
|
56 | + * Create a new backup archive file once the set size is reached |
|
57 | + * @var float|int |
|
58 | + */ |
|
59 | + private $xcloner_split_backup_limit = 2048; //2048MB |
|
60 | + /** |
|
61 | + * Number of processed bytes |
|
62 | + * @var int |
|
63 | + */ |
|
64 | + private $processed_size_bytes = 0; |
|
65 | + |
|
66 | + /** |
|
67 | + * Archive name |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + private $archive_name; |
|
71 | + /** |
|
72 | + * @var Tar |
|
73 | + */ |
|
74 | + private $backup_archive; |
|
75 | + /** |
|
76 | + * @var Xcloner_File_System |
|
77 | + */ |
|
78 | + private $filesystem; |
|
79 | + /** |
|
80 | + * @var Xcloner_Logger |
|
81 | + */ |
|
82 | + private $logger; |
|
83 | + /** |
|
84 | + * @var Xcloner_Settings |
|
85 | + */ |
|
86 | + private $xcloner_settings; |
|
87 | + |
|
88 | + /** |
|
89 | + * [__construct description] |
|
90 | + * @param Xcloner $xcloner_container XCloner Container |
|
91 | + * @param string $archive_name Achive Name |
|
92 | + */ |
|
93 | + public function __construct(Xcloner $xcloner_container, $archive_name = "") |
|
94 | + { |
|
95 | + $this->filesystem = $xcloner_container->get_xcloner_filesystem(); |
|
96 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_archive"); |
|
97 | + $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
|
98 | + |
|
99 | + if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) { |
|
100 | + $this->file_size_per_request_limit = $value * 1024 * 1024; |
|
101 | + } //MB |
|
102 | + |
|
103 | + if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) { |
|
104 | + $this->files_to_process_per_request = $value; |
|
105 | + } |
|
106 | 106 | |
107 | - if ($value = get_option('xcloner_backup_compression_level')) { |
|
108 | - $this->compression_level = $value; |
|
109 | - } |
|
107 | + if ($value = get_option('xcloner_backup_compression_level')) { |
|
108 | + $this->compression_level = $value; |
|
109 | + } |
|
110 | 110 | |
111 | - if ($value = get_option('xcloner_split_backup_limit')) { |
|
112 | - $this->xcloner_split_backup_limit = $value; |
|
113 | - } |
|
111 | + if ($value = get_option('xcloner_split_backup_limit')) { |
|
112 | + $this->xcloner_split_backup_limit = $value; |
|
113 | + } |
|
114 | 114 | |
115 | - $this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024 * 1024; //transform to bytes |
|
115 | + $this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024 * 1024; //transform to bytes |
|
116 | 116 | |
117 | - if (isset($archive_name) && $archive_name) { |
|
118 | - $this->set_archive_name($archive_name); |
|
119 | - } |
|
120 | - } |
|
117 | + if (isset($archive_name) && $archive_name) { |
|
118 | + $this->set_archive_name($archive_name); |
|
119 | + } |
|
120 | + } |
|
121 | 121 | |
122 | - /* |
|
122 | + /* |
|
123 | 123 | * Rename backup archive |
124 | 124 | * |
125 | 125 | * @param string $old_name |
126 | 126 | * @param string $new_name |
127 | 127 | * |
128 | 128 | */ |
129 | - public function rename_archive($old_name, $new_name) |
|
130 | - { |
|
131 | - $this->logger->info(sprintf("Renaming backup archive %s to %s", $old_name, $new_name)); |
|
132 | - $storage_filesystem = $this->filesystem->get_storage_filesystem(); |
|
133 | - $storage_filesystem->rename($old_name, $new_name); |
|
134 | - } |
|
135 | - |
|
136 | - /* |
|
129 | + public function rename_archive($old_name, $new_name) |
|
130 | + { |
|
131 | + $this->logger->info(sprintf("Renaming backup archive %s to %s", $old_name, $new_name)); |
|
132 | + $storage_filesystem = $this->filesystem->get_storage_filesystem(); |
|
133 | + $storage_filesystem->rename($old_name, $new_name); |
|
134 | + } |
|
135 | + |
|
136 | + /* |
|
137 | 137 | * |
138 | 138 | * Set the backup archive name |
139 | 139 | * |
140 | 140 | */ |
141 | - public function set_archive_name($name = "", $part = 0) |
|
142 | - { |
|
141 | + public function set_archive_name($name = "", $part = 0) |
|
142 | + { |
|
143 | 143 | |
144 | - $this->archive_name = $this->filesystem->process_backup_name($name); |
|
144 | + $this->archive_name = $this->filesystem->process_backup_name($name); |
|
145 | 145 | |
146 | - if ($diff_timestamp_start = $this->filesystem->get_diff_timestamp_start()) { |
|
147 | - //$this->archive_name = $this->archive_name."-diff-".date("Y-m-d_H-i",$diff_timestamp_start); |
|
148 | - $new_name = $this->archive_name; |
|
146 | + if ($diff_timestamp_start = $this->filesystem->get_diff_timestamp_start()) { |
|
147 | + //$this->archive_name = $this->archive_name."-diff-".date("Y-m-d_H-i",$diff_timestamp_start); |
|
148 | + $new_name = $this->archive_name; |
|
149 | 149 | |
150 | - if (!stristr($new_name, "-diff")) { |
|
151 | - $new_name = $this->archive_name . "-diff" . date("Y-m-d_H-i", $diff_timestamp_start); |
|
152 | - } |
|
150 | + if (!stristr($new_name, "-diff")) { |
|
151 | + $new_name = $this->archive_name . "-diff" . date("Y-m-d_H-i", $diff_timestamp_start); |
|
152 | + } |
|
153 | 153 | |
154 | - $this->archive_name = $new_name; |
|
154 | + $this->archive_name = $new_name; |
|
155 | 155 | |
156 | - } |
|
156 | + } |
|
157 | 157 | |
158 | - if (isset($part) and $part) { |
|
159 | - $new_name = preg_replace('/-part(\d*)/', "-part" . $part, $this->archive_name); |
|
160 | - if (!stristr($new_name, "-part")) { |
|
161 | - $new_name = $this->archive_name . "-part" . $part; |
|
162 | - } |
|
158 | + if (isset($part) and $part) { |
|
159 | + $new_name = preg_replace('/-part(\d*)/', "-part" . $part, $this->archive_name); |
|
160 | + if (!stristr($new_name, "-part")) { |
|
161 | + $new_name = $this->archive_name . "-part" . $part; |
|
162 | + } |
|
163 | 163 | |
164 | - $this->archive_name = $new_name; |
|
165 | - } |
|
164 | + $this->archive_name = $new_name; |
|
165 | + } |
|
166 | 166 | |
167 | - return $this; |
|
168 | - } |
|
167 | + return $this; |
|
168 | + } |
|
169 | 169 | |
170 | - /* |
|
170 | + /* |
|
171 | 171 | * |
172 | 172 | * Returns the backup archive name |
173 | 173 | * |
174 | 174 | * @return string archive name |
175 | 175 | */ |
176 | - public function get_archive_name() |
|
177 | - { |
|
178 | - return $this->archive_name; |
|
179 | - } |
|
176 | + public function get_archive_name() |
|
177 | + { |
|
178 | + return $this->archive_name; |
|
179 | + } |
|
180 | 180 | |
181 | - /* |
|
181 | + /* |
|
182 | 182 | * |
183 | 183 | * Returns the multipart naming for the backup archive |
184 | 184 | * |
185 | 185 | * @return string multi-part backup name |
186 | 186 | */ |
187 | - public function get_archive_name_multipart() |
|
188 | - { |
|
189 | - $new_name = preg_replace('/-part(\d*)/', "", $this->archive_name); |
|
190 | - return $new_name . "-multipart" . $this->xcloner_settings->get_backup_extension_name(".csv"); |
|
191 | - } |
|
187 | + public function get_archive_name_multipart() |
|
188 | + { |
|
189 | + $new_name = preg_replace('/-part(\d*)/', "", $this->archive_name); |
|
190 | + return $new_name . "-multipart" . $this->xcloner_settings->get_backup_extension_name(".csv"); |
|
191 | + } |
|
192 | 192 | |
193 | - /* |
|
193 | + /* |
|
194 | 194 | * |
195 | 195 | * Returns the full backup name including extension |
196 | 196 | * |
197 | 197 | */ |
198 | - public function get_archive_name_with_extension() |
|
199 | - { |
|
200 | - return $this->archive_name . $this->xcloner_settings->get_backup_extension_name(); |
|
201 | - } |
|
198 | + public function get_archive_name_with_extension() |
|
199 | + { |
|
200 | + return $this->archive_name . $this->xcloner_settings->get_backup_extension_name(); |
|
201 | + } |
|
202 | 202 | |
203 | - /* |
|
203 | + /* |
|
204 | 204 | * |
205 | 205 | * Send notification error by E-Mail |
206 | 206 | * |
@@ -213,31 +213,31 @@ discard block |
||
213 | 213 | * |
214 | 214 | * @return bool |
215 | 215 | */ |
216 | - public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message) |
|
217 | - { |
|
216 | + public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message) |
|
217 | + { |
|
218 | 218 | |
219 | - $body = ""; |
|
220 | - $body .= sprintf(__("Backup Site Url: %s"), get_site_url()); |
|
221 | - $body .= "<br /><>"; |
|
219 | + $body = ""; |
|
220 | + $body .= sprintf(__("Backup Site Url: %s"), get_site_url()); |
|
221 | + $body .= "<br /><>"; |
|
222 | 222 | |
223 | - $body .= sprintf(__("Error Message: %s"), $error_message); |
|
223 | + $body .= sprintf(__("Error Message: %s"), $error_message); |
|
224 | 224 | |
225 | - $this->logger->info(sprintf("Sending backup error notification to %s", $to)); |
|
225 | + $this->logger->info(sprintf("Sending backup error notification to %s", $to)); |
|
226 | 226 | |
227 | - $admin_email = get_option("admin_email"); |
|
227 | + $admin_email = get_option("admin_email"); |
|
228 | 228 | |
229 | - $headers = array('Content-Type: text/html; charset=UTF-8'); |
|
229 | + $headers = array('Content-Type: text/html; charset=UTF-8'); |
|
230 | 230 | |
231 | - if ($admin_email and $from) { |
|
232 | - $headers[] = 'From: ' . $from . ' <' . $admin_email . '>'; |
|
233 | - } |
|
231 | + if ($admin_email and $from) { |
|
232 | + $headers[] = 'From: ' . $from . ' <' . $admin_email . '>'; |
|
233 | + } |
|
234 | 234 | |
235 | - $return = wp_mail($to, $subject, $body, $headers); |
|
235 | + $return = wp_mail($to, $subject, $body, $headers); |
|
236 | 236 | |
237 | - return $return; |
|
238 | - } |
|
237 | + return $return; |
|
238 | + } |
|
239 | 239 | |
240 | - /* |
|
240 | + /* |
|
241 | 241 | * |
242 | 242 | * Send backup archive notfication by E-Mail |
243 | 243 | * |
@@ -251,482 +251,482 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @return bool |
253 | 253 | */ |
254 | - public function send_notification( |
|
255 | - $to, |
|
256 | - $from, |
|
257 | - $subject, |
|
258 | - $backup_name, |
|
259 | - $params, |
|
260 | - $error_message = "", |
|
261 | - $additional = array() |
|
262 | - ) { |
|
263 | - if (!$from) { |
|
264 | - $from = "XCloner Backup"; |
|
265 | - } |
|
254 | + public function send_notification( |
|
255 | + $to, |
|
256 | + $from, |
|
257 | + $subject, |
|
258 | + $backup_name, |
|
259 | + $params, |
|
260 | + $error_message = "", |
|
261 | + $additional = array() |
|
262 | + ) { |
|
263 | + if (!$from) { |
|
264 | + $from = "XCloner Backup"; |
|
265 | + } |
|
266 | 266 | |
267 | - if (($error_message)) { |
|
268 | - return $this->send_notification_error($to, $from, $subject, $backup_name, $params, $error_message); |
|
269 | - } |
|
267 | + if (($error_message)) { |
|
268 | + return $this->send_notification_error($to, $from, $subject, $backup_name, $params, $error_message); |
|
269 | + } |
|
270 | 270 | |
271 | - $params = (array)$params; |
|
271 | + $params = (array)$params; |
|
272 | 272 | |
273 | - if (!$subject) { |
|
274 | - $subject = sprintf(__("New backup generated %s"), $backup_name); |
|
275 | - } |
|
273 | + if (!$subject) { |
|
274 | + $subject = sprintf(__("New backup generated %s"), $backup_name); |
|
275 | + } |
|
276 | 276 | |
277 | - $body = sprintf(__("Generated Backup Size: %s"), size_format($this->filesystem->get_backup_size($backup_name))); |
|
278 | - $body .= "<br /><br />"; |
|
277 | + $body = sprintf(__("Generated Backup Size: %s"), size_format($this->filesystem->get_backup_size($backup_name))); |
|
278 | + $body .= "<br /><br />"; |
|
279 | 279 | |
280 | - if (isset($additional['lines_total'])) { |
|
281 | - $body .= sprintf(__("Total files added: %s"), $additional['lines_total']); |
|
282 | - $body .= "<br /><br />"; |
|
283 | - } |
|
280 | + if (isset($additional['lines_total'])) { |
|
281 | + $body .= sprintf(__("Total files added: %s"), $additional['lines_total']); |
|
282 | + $body .= "<br /><br />"; |
|
283 | + } |
|
284 | 284 | |
285 | - $backup_parts = $this->filesystem->get_multipart_files($backup_name); |
|
285 | + $backup_parts = $this->filesystem->get_multipart_files($backup_name); |
|
286 | 286 | |
287 | - if (!$backups_counter = sizeof($backup_parts)) { |
|
288 | - $backups_counter = 1; |
|
289 | - } |
|
287 | + if (!$backups_counter = sizeof($backup_parts)) { |
|
288 | + $backups_counter = 1; |
|
289 | + } |
|
290 | 290 | |
291 | - $body .= sprintf(__("Backup Parts: %s"), $backups_counter); |
|
292 | - $body .= "<br />"; |
|
291 | + $body .= sprintf(__("Backup Parts: %s"), $backups_counter); |
|
292 | + $body .= "<br />"; |
|
293 | 293 | |
294 | - if (sizeof($backup_parts)) { |
|
295 | - $body .= implode("<br />", $backup_parts); |
|
296 | - $body .= "<br />"; |
|
297 | - } |
|
294 | + if (sizeof($backup_parts)) { |
|
295 | + $body .= implode("<br />", $backup_parts); |
|
296 | + $body .= "<br />"; |
|
297 | + } |
|
298 | 298 | |
299 | - $body .= "<br />"; |
|
299 | + $body .= "<br />"; |
|
300 | 300 | |
301 | - $body .= sprintf(__("Backup Site Url: %s"), get_site_url()); |
|
302 | - $body .= "<br />"; |
|
301 | + $body .= sprintf(__("Backup Site Url: %s"), get_site_url()); |
|
302 | + $body .= "<br />"; |
|
303 | 303 | |
304 | - if (isset($params['backup_params']->backup_comments)) { |
|
305 | - $body .= __("Backup Comments: ") . $params['backup_params']->backup_comments; |
|
306 | - $body .= "<br /><br />"; |
|
307 | - } |
|
304 | + if (isset($params['backup_params']->backup_comments)) { |
|
305 | + $body .= __("Backup Comments: ") . $params['backup_params']->backup_comments; |
|
306 | + $body .= "<br /><br />"; |
|
307 | + } |
|
308 | 308 | |
309 | - if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
|
310 | - $body .= __("Latest 50 Log Lines: ") . "<br />" . implode("<br />\n", |
|
311 | - $this->logger->getLastDebugLines(50)); |
|
312 | - } |
|
309 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
|
310 | + $body .= __("Latest 50 Log Lines: ") . "<br />" . implode("<br />\n", |
|
311 | + $this->logger->getLastDebugLines(50)); |
|
312 | + } |
|
313 | 313 | |
314 | - $attachments = $this->filesystem->get_backup_attachments(); |
|
314 | + $attachments = $this->filesystem->get_backup_attachments(); |
|
315 | 315 | |
316 | - $attachments_archive = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "info.tgz"; |
|
316 | + $attachments_archive = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "info.tgz"; |
|
317 | 317 | |
318 | - $tar = new Tar(); |
|
319 | - $tar->create($attachments_archive); |
|
318 | + $tar = new Tar(); |
|
319 | + $tar->create($attachments_archive); |
|
320 | 320 | |
321 | - foreach ($attachments as $key => $file) { |
|
322 | - $tar->addFile($file, basename($file)); |
|
323 | - } |
|
324 | - $tar->close(); |
|
321 | + foreach ($attachments as $key => $file) { |
|
322 | + $tar->addFile($file, basename($file)); |
|
323 | + } |
|
324 | + $tar->close(); |
|
325 | 325 | |
326 | - $this->logger->info(sprintf("Sending backup notification to %s", $to)); |
|
326 | + $this->logger->info(sprintf("Sending backup notification to %s", $to)); |
|
327 | 327 | |
328 | - $admin_email = get_option("admin_email"); |
|
328 | + $admin_email = get_option("admin_email"); |
|
329 | 329 | |
330 | - $headers = array('Content-Type: text/html; charset=UTF-8', 'From: ' . $from . ' <' . $admin_email . '>'); |
|
330 | + $headers = array('Content-Type: text/html; charset=UTF-8', 'From: ' . $from . ' <' . $admin_email . '>'); |
|
331 | 331 | |
332 | - $return = wp_mail($to, $subject, $body, $headers, array($attachments_archive)); |
|
332 | + $return = wp_mail($to, $subject, $body, $headers, array($attachments_archive)); |
|
333 | 333 | |
334 | - return $return; |
|
335 | - } |
|
334 | + return $return; |
|
335 | + } |
|
336 | 336 | |
337 | - /* |
|
337 | + /* |
|
338 | 338 | * |
339 | 339 | * Incremental Backup method |
340 | 340 | * |
341 | 341 | */ |
342 | - public function start_incremental_backup($backup_params, $extra_params, $init) |
|
343 | - { |
|
344 | - $return = array(); |
|
342 | + public function start_incremental_backup($backup_params, $extra_params, $init) |
|
343 | + { |
|
344 | + $return = array(); |
|
345 | 345 | |
346 | - if (!isset($extra_params['backup_part'])) { |
|
347 | - $extra_params['backup_part'] = 0; |
|
348 | - } |
|
346 | + if (!isset($extra_params['backup_part'])) { |
|
347 | + $extra_params['backup_part'] = 0; |
|
348 | + } |
|
349 | 349 | |
350 | - $return['extra']['backup_part'] = $extra_params['backup_part']; |
|
350 | + $return['extra']['backup_part'] = $extra_params['backup_part']; |
|
351 | 351 | |
352 | - if (isset($extra_params['backup_archive_name'])) { |
|
353 | - $this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']); |
|
354 | - } else { |
|
355 | - $this->set_archive_name($backup_params['backup_name']); |
|
356 | - } |
|
352 | + if (isset($extra_params['backup_archive_name'])) { |
|
353 | + $this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']); |
|
354 | + } else { |
|
355 | + $this->set_archive_name($backup_params['backup_name']); |
|
356 | + } |
|
357 | 357 | |
358 | - if (!$this->get_archive_name()) { |
|
359 | - $this->set_archive_name(); |
|
360 | - } |
|
358 | + if (!$this->get_archive_name()) { |
|
359 | + $this->set_archive_name(); |
|
360 | + } |
|
361 | 361 | |
362 | - $this->backup_archive = new Tar(); |
|
363 | - $this->backup_archive->setCompression($this->compression_level); |
|
362 | + $this->backup_archive = new Tar(); |
|
363 | + $this->backup_archive->setCompression($this->compression_level); |
|
364 | 364 | |
365 | - $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension()); |
|
365 | + $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension()); |
|
366 | 366 | |
367 | - if ($init) { |
|
368 | - $this->logger->info(sprintf(__("Initializing the backup archive %s"), $this->get_archive_name())); |
|
367 | + if ($init) { |
|
368 | + $this->logger->info(sprintf(__("Initializing the backup archive %s"), $this->get_archive_name())); |
|
369 | 369 | |
370 | - $this->backup_archive->create($archive_info->getPath() . DS . $archive_info->getFilename()); |
|
370 | + $this->backup_archive->create($archive_info->getPath() . DS . $archive_info->getFilename()); |
|
371 | 371 | |
372 | - $return['extra']['backup_init'] = 1; |
|
372 | + $return['extra']['backup_init'] = 1; |
|
373 | 373 | |
374 | - } else { |
|
375 | - $this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name())); |
|
374 | + } else { |
|
375 | + $this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name())); |
|
376 | 376 | |
377 | - $this->backup_archive->openForAppend($archive_info->getPath() . DS . $archive_info->getFilename()); |
|
377 | + $this->backup_archive->openForAppend($archive_info->getPath() . DS . $archive_info->getFilename()); |
|
378 | 378 | |
379 | - $return['extra']['backup_init'] = 0; |
|
379 | + $return['extra']['backup_init'] = 0; |
|
380 | 380 | |
381 | - } |
|
381 | + } |
|
382 | 382 | |
383 | - $return['extra']['backup_archive_name'] = $this->get_archive_name(); |
|
384 | - $return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension(); |
|
383 | + $return['extra']['backup_archive_name'] = $this->get_archive_name(); |
|
384 | + $return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension(); |
|
385 | 385 | |
386 | - if (!isset($extra_params['start_at_line'])) { |
|
387 | - $extra_params['start_at_line'] = 0; |
|
388 | - } |
|
386 | + if (!isset($extra_params['start_at_line'])) { |
|
387 | + $extra_params['start_at_line'] = 0; |
|
388 | + } |
|
389 | 389 | |
390 | - if (!isset($extra_params['start_at_byte'])) { |
|
391 | - $extra_params['start_at_byte'] = 0; |
|
392 | - } |
|
390 | + if (!isset($extra_params['start_at_byte'])) { |
|
391 | + $extra_params['start_at_byte'] = 0; |
|
392 | + } |
|
393 | 393 | |
394 | - if (!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) { |
|
395 | - $this->logger->error(sprintf("Missing the includes file handler %s, aborting...", |
|
396 | - $this->filesystem->get_included_files_handler())); |
|
394 | + if (!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) { |
|
395 | + $this->logger->error(sprintf("Missing the includes file handler %s, aborting...", |
|
396 | + $this->filesystem->get_included_files_handler())); |
|
397 | 397 | |
398 | - $return['finished'] = 1; |
|
399 | - return $return; |
|
400 | - } |
|
398 | + $return['finished'] = 1; |
|
399 | + return $return; |
|
400 | + } |
|
401 | 401 | |
402 | - $included_files_handler = $this->filesystem->get_included_files_handler(1); |
|
402 | + $included_files_handler = $this->filesystem->get_included_files_handler(1); |
|
403 | 403 | |
404 | - $file = new SplFileObject($included_files_handler); |
|
404 | + $file = new SplFileObject($included_files_handler); |
|
405 | 405 | |
406 | - $file->seek(PHP_INT_MAX); |
|
406 | + $file->seek(PHP_INT_MAX); |
|
407 | 407 | |
408 | - $return['extra']['lines_total'] = ($file->key() - 1); |
|
408 | + $return['extra']['lines_total'] = ($file->key() - 1); |
|
409 | 409 | |
410 | - //we skip the first CSV line with headers |
|
411 | - if (!$extra_params['start_at_line']) { |
|
412 | - $file->seek(1); |
|
413 | - } else { |
|
414 | - $file->seek($extra_params['start_at_line'] + 1); |
|
415 | - } |
|
410 | + //we skip the first CSV line with headers |
|
411 | + if (!$extra_params['start_at_line']) { |
|
412 | + $file->seek(1); |
|
413 | + } else { |
|
414 | + $file->seek($extra_params['start_at_line'] + 1); |
|
415 | + } |
|
416 | 416 | |
417 | - $this->processed_size_bytes = 0; |
|
417 | + $this->processed_size_bytes = 0; |
|
418 | 418 | |
419 | - $counter = 0; |
|
419 | + $counter = 0; |
|
420 | 420 | |
421 | - $start_byte = $extra_params['start_at_byte']; |
|
421 | + $start_byte = $extra_params['start_at_byte']; |
|
422 | 422 | |
423 | - $byte_limit = 0; |
|
423 | + $byte_limit = 0; |
|
424 | 424 | |
425 | - while (!$file->eof() and $counter <= $this->files_to_process_per_request) { |
|
426 | - $current_line_str = $file->current(); |
|
425 | + while (!$file->eof() and $counter <= $this->files_to_process_per_request) { |
|
426 | + $current_line_str = $file->current(); |
|
427 | 427 | |
428 | - $line = str_getcsv($current_line_str); |
|
428 | + $line = str_getcsv($current_line_str); |
|
429 | 429 | |
430 | - $relative_path = stripslashes($line[0]); |
|
430 | + $relative_path = stripslashes($line[0]); |
|
431 | 431 | |
432 | - $start_filesystem = "start_filesystem"; |
|
432 | + $start_filesystem = "start_filesystem"; |
|
433 | 433 | |
434 | - if (isset($line[4])) { |
|
435 | - $start_filesystem = $line[4]; |
|
436 | - } |
|
434 | + if (isset($line[4])) { |
|
435 | + $start_filesystem = $line[4]; |
|
436 | + } |
|
437 | 437 | |
438 | - //$adapter = $this->filesystem->get_adapter($start_filesystem); |
|
438 | + //$adapter = $this->filesystem->get_adapter($start_filesystem); |
|
439 | 439 | |
440 | - if (!$relative_path || !$this->filesystem->get_filesystem($start_filesystem)->has($relative_path)) { |
|
441 | - if ($relative_path != "") { |
|
442 | - $this->logger->error(sprintf("Could not add file %b to backup archive, file not found", |
|
443 | - $relative_path)); |
|
444 | - } |
|
440 | + if (!$relative_path || !$this->filesystem->get_filesystem($start_filesystem)->has($relative_path)) { |
|
441 | + if ($relative_path != "") { |
|
442 | + $this->logger->error(sprintf("Could not add file %b to backup archive, file not found", |
|
443 | + $relative_path)); |
|
444 | + } |
|
445 | 445 | |
446 | - $extra_params['start_at_line']++; |
|
447 | - $file->next(); |
|
448 | - continue; |
|
449 | - } |
|
446 | + $extra_params['start_at_line']++; |
|
447 | + $file->next(); |
|
448 | + continue; |
|
449 | + } |
|
450 | 450 | |
451 | - $file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path); |
|
451 | + $file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path); |
|
452 | 452 | |
453 | - if (!isset($file_info['size'])) { |
|
454 | - $file_info['size'] = 0; |
|
455 | - } |
|
453 | + if (!isset($file_info['size'])) { |
|
454 | + $file_info['size'] = 0; |
|
455 | + } |
|
456 | 456 | |
457 | - if ($start_filesystem == "tmp_filesystem") { |
|
458 | - $file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix(); |
|
459 | - } |
|
457 | + if ($start_filesystem == "tmp_filesystem") { |
|
458 | + $file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix(); |
|
459 | + } |
|
460 | 460 | |
461 | - $byte_limit = (int)$this->file_size_per_request_limit / 512; |
|
461 | + $byte_limit = (int)$this->file_size_per_request_limit / 512; |
|
462 | 462 | |
463 | - $append = 0; |
|
463 | + $append = 0; |
|
464 | 464 | |
465 | - if ($file_info['size'] > $byte_limit * 512 or $start_byte) { |
|
466 | - $append = 1; |
|
467 | - } |
|
465 | + if ($file_info['size'] > $byte_limit * 512 or $start_byte) { |
|
466 | + $append = 1; |
|
467 | + } |
|
468 | 468 | |
469 | - if (!isset($return['extra']['backup_size'])) { |
|
470 | - $return['extra']['backup_size'] = 0; |
|
471 | - } |
|
469 | + if (!isset($return['extra']['backup_size'])) { |
|
470 | + $return['extra']['backup_size'] = 0; |
|
471 | + } |
|
472 | 472 | |
473 | - $return['extra']['backup_size'] = $archive_info->getSize(); |
|
473 | + $return['extra']['backup_size'] = $archive_info->getSize(); |
|
474 | 474 | |
475 | - $estimated_new_size = $return['extra']['backup_size'] + $file_info['size']; |
|
475 | + $estimated_new_size = $return['extra']['backup_size'] + $file_info['size']; |
|
476 | 476 | |
477 | - //we create a new backup part if we reach the Split Achive Limit |
|
478 | - if ($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte)) { |
|
479 | - $this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ", |
|
480 | - $this->xcloner_split_backup_limit, $estimated_new_size)); |
|
481 | - list($archive_info, $return['extra']['backup_part']) = $this->create_new_backup_part($return['extra']['backup_part']); |
|
477 | + //we create a new backup part if we reach the Split Achive Limit |
|
478 | + if ($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte)) { |
|
479 | + $this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ", |
|
480 | + $this->xcloner_split_backup_limit, $estimated_new_size)); |
|
481 | + list($archive_info, $return['extra']['backup_part']) = $this->create_new_backup_part($return['extra']['backup_part']); |
|
482 | 482 | |
483 | - if ($file_info['size'] > $this->xcloner_split_backup_limit) { |
|
484 | - $this->logger->info(sprintf("Excluding %s file as it's size(%s) is bigger than the backup split limit of %s and it won't fit a single backup file", |
|
485 | - $file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit)); |
|
486 | - $extra_params['start_at_line']++; |
|
487 | - } |
|
483 | + if ($file_info['size'] > $this->xcloner_split_backup_limit) { |
|
484 | + $this->logger->info(sprintf("Excluding %s file as it's size(%s) is bigger than the backup split limit of %s and it won't fit a single backup file", |
|
485 | + $file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit)); |
|
486 | + $extra_params['start_at_line']++; |
|
487 | + } |
|
488 | 488 | |
489 | - $return['extra']['start_at_line'] = $extra_params['start_at_line']; |
|
490 | - $return['extra']['start_at_byte'] = 0; |
|
489 | + $return['extra']['start_at_line'] = $extra_params['start_at_line']; |
|
490 | + $return['extra']['start_at_byte'] = 0; |
|
491 | 491 | |
492 | - $return['finished'] = 0; |
|
492 | + $return['finished'] = 0; |
|
493 | 493 | |
494 | - return $return; |
|
495 | - } |
|
494 | + return $return; |
|
495 | + } |
|
496 | 496 | |
497 | - list($bytes_wrote, $last_position) = $this->add_file_to_archive($file_info, $start_byte, $byte_limit, |
|
498 | - $append, $start_filesystem); |
|
499 | - $this->processed_size_bytes += $bytes_wrote; |
|
497 | + list($bytes_wrote, $last_position) = $this->add_file_to_archive($file_info, $start_byte, $byte_limit, |
|
498 | + $append, $start_filesystem); |
|
499 | + $this->processed_size_bytes += $bytes_wrote; |
|
500 | 500 | |
501 | - //echo" - processed ".$this->processed_size_bytes." bytes ".$this->file_size_per_request_limit." last_position:".$last_position." \n"; |
|
502 | - $return['extra']['processed_file'] = $file_info['path']; |
|
503 | - $return['extra']['processed_file_size'] = $file_info['size']; |
|
504 | - $return['extra']['backup_size'] = $archive_info->getSize(); |
|
501 | + //echo" - processed ".$this->processed_size_bytes." bytes ".$this->file_size_per_request_limit." last_position:".$last_position." \n"; |
|
502 | + $return['extra']['processed_file'] = $file_info['path']; |
|
503 | + $return['extra']['processed_file_size'] = $file_info['size']; |
|
504 | + $return['extra']['backup_size'] = $archive_info->getSize(); |
|
505 | 505 | |
506 | - if ($last_position > 0) { |
|
507 | - $start_byte = $last_position; |
|
508 | - } else { |
|
509 | - $extra_params['start_at_line']++; |
|
510 | - $file->next(); |
|
511 | - $start_byte = 0; |
|
512 | - $counter++; |
|
513 | - } |
|
506 | + if ($last_position > 0) { |
|
507 | + $start_byte = $last_position; |
|
508 | + } else { |
|
509 | + $extra_params['start_at_line']++; |
|
510 | + $file->next(); |
|
511 | + $start_byte = 0; |
|
512 | + $counter++; |
|
513 | + } |
|
514 | 514 | |
515 | - if ($this->processed_size_bytes >= $this->file_size_per_request_limit) { |
|
516 | - clearstatcache(); |
|
517 | - $return['extra']['backup_size'] = $archive_info->getSize(); |
|
515 | + if ($this->processed_size_bytes >= $this->file_size_per_request_limit) { |
|
516 | + clearstatcache(); |
|
517 | + $return['extra']['backup_size'] = $archive_info->getSize(); |
|
518 | 518 | |
519 | - $return['finished'] = 0; |
|
520 | - $return['extra']['start_at_line'] = $extra_params['start_at_line']; |
|
521 | - $return['extra']['start_at_byte'] = $last_position; |
|
522 | - $this->logger->info(sprintf("Reached the maximum %s request data limit, returning response", |
|
523 | - $this->file_size_per_request_limit)); |
|
524 | - return $return; |
|
525 | - } |
|
526 | - } |
|
519 | + $return['finished'] = 0; |
|
520 | + $return['extra']['start_at_line'] = $extra_params['start_at_line']; |
|
521 | + $return['extra']['start_at_byte'] = $last_position; |
|
522 | + $this->logger->info(sprintf("Reached the maximum %s request data limit, returning response", |
|
523 | + $this->file_size_per_request_limit)); |
|
524 | + return $return; |
|
525 | + } |
|
526 | + } |
|
527 | 527 | |
528 | - if (!$file->eof()) { |
|
529 | - clearstatcache(); |
|
530 | - $return['extra']['backup_size'] = $archive_info->getSize(); |
|
528 | + if (!$file->eof()) { |
|
529 | + clearstatcache(); |
|
530 | + $return['extra']['backup_size'] = $archive_info->getSize(); |
|
531 | 531 | |
532 | - $return['finished'] = 0; |
|
533 | - $return['extra']['start_at_line'] = $extra_params['start_at_line']; |
|
534 | - $return['extra']['start_at_byte'] = $last_position; |
|
535 | - $this->logger->info(sprintf("We have reached the maximum files to process per request limit of %s, returning response", |
|
536 | - $this->files_to_process_per_request)); |
|
532 | + $return['finished'] = 0; |
|
533 | + $return['extra']['start_at_line'] = $extra_params['start_at_line']; |
|
534 | + $return['extra']['start_at_byte'] = $last_position; |
|
535 | + $this->logger->info(sprintf("We have reached the maximum files to process per request limit of %s, returning response", |
|
536 | + $this->files_to_process_per_request)); |
|
537 | 537 | |
538 | - return $return; |
|
539 | - } |
|
538 | + return $return; |
|
539 | + } |
|
540 | 540 | |
541 | - //close the backup archive by adding 2*512 blocks of zero bytes |
|
542 | - $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", |
|
543 | - $this->get_archive_name_with_extension())); |
|
544 | - $this->backup_archive->close(); |
|
541 | + //close the backup archive by adding 2*512 blocks of zero bytes |
|
542 | + $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", |
|
543 | + $this->get_archive_name_with_extension())); |
|
544 | + $this->backup_archive->close(); |
|
545 | 545 | |
546 | - /** |
|
547 | - * XCloner HOOK backup_archive_finished. |
|
548 | - * |
|
549 | - * This will get triggered when a backup archive is finished writing. |
|
550 | - */ |
|
551 | - //do_action('backup_archive_finished', $this->backup_archive, $this); |
|
546 | + /** |
|
547 | + * XCloner HOOK backup_archive_finished. |
|
548 | + * |
|
549 | + * This will get triggered when a backup archive is finished writing. |
|
550 | + */ |
|
551 | + //do_action('backup_archive_finished', $this->backup_archive, $this); |
|
552 | 552 | |
553 | - //updating archive_info |
|
554 | - $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension()); |
|
553 | + //updating archive_info |
|
554 | + $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension()); |
|
555 | 555 | |
556 | - if ($return['extra']['backup_part']) { |
|
557 | - $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
558 | - } |
|
556 | + if ($return['extra']['backup_part']) { |
|
557 | + $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
558 | + } |
|
559 | 559 | |
560 | - $return['extra']['start_at_line'] = $extra_params['start_at_line'] - 1; |
|
560 | + $return['extra']['start_at_line'] = $extra_params['start_at_line'] - 1; |
|
561 | 561 | |
562 | - if (isset($file_info)) { |
|
563 | - $return['extra']['processed_file'] = $file_info['path']; |
|
564 | - $return['extra']['processed_file_size'] = $file_info['size']; |
|
565 | - } |
|
562 | + if (isset($file_info)) { |
|
563 | + $return['extra']['processed_file'] = $file_info['path']; |
|
564 | + $return['extra']['processed_file_size'] = $file_info['size']; |
|
565 | + } |
|
566 | 566 | |
567 | - clearstatcache(); |
|
568 | - $return['extra']['backup_size'] = $archive_info->getSize(); |
|
567 | + clearstatcache(); |
|
568 | + $return['extra']['backup_size'] = $archive_info->getSize(); |
|
569 | 569 | |
570 | - $return['finished'] = 1; |
|
571 | - return $return; |
|
572 | - } |
|
570 | + $return['finished'] = 1; |
|
571 | + return $return; |
|
572 | + } |
|
573 | 573 | |
574 | - /* |
|
574 | + /* |
|
575 | 575 | * |
576 | 576 | * Write multipart file components |
577 | 577 | * |
578 | 578 | */ |
579 | - private function write_multipart_file($path = "") |
|
580 | - { |
|
581 | - if(!$path) { |
|
582 | - $path = $this->get_archive_name_with_extension(); |
|
583 | - } |
|
579 | + private function write_multipart_file($path = "") |
|
580 | + { |
|
581 | + if(!$path) { |
|
582 | + $path = $this->get_archive_name_with_extension(); |
|
583 | + } |
|
584 | 584 | |
585 | - $file = $this->filesystem->get_filesystem("storage_filesystem_append")->getMetadata($path); |
|
586 | - //print_r($file_info); |
|
587 | - $line = '"' . $file['path'] . '","' . $file['timestamp'] . '","' . $file['size'] . '"' . PHP_EOL; |
|
585 | + $file = $this->filesystem->get_filesystem("storage_filesystem_append")->getMetadata($path); |
|
586 | + //print_r($file_info); |
|
587 | + $line = '"' . $file['path'] . '","' . $file['timestamp'] . '","' . $file['size'] . '"' . PHP_EOL; |
|
588 | 588 | |
589 | 589 | |
590 | - $this->filesystem->get_filesystem("storage_filesystem_append") |
|
591 | - ->write($this->get_archive_name_multipart(), $line); |
|
592 | - } |
|
590 | + $this->filesystem->get_filesystem("storage_filesystem_append") |
|
591 | + ->write($this->get_archive_name_multipart(), $line); |
|
592 | + } |
|
593 | 593 | |
594 | - /* |
|
594 | + /* |
|
595 | 595 | * |
596 | 596 | * Create a new backup part |
597 | 597 | * |
598 | 598 | */ |
599 | - private function create_new_backup_part($part = 0) |
|
600 | - { |
|
601 | - //close the backup archive by adding 2*512 blocks of zero bytes |
|
602 | - $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", |
|
603 | - $this->get_archive_name_with_extension())); |
|
604 | - $this->backup_archive->close(); |
|
605 | - |
|
606 | - if (!$part) { |
|
607 | - $old_name = $this->get_archive_name_with_extension(); |
|
608 | - $this->set_archive_name($this->get_archive_name(), ++$part); |
|
609 | - $this->rename_archive($old_name, $this->get_archive_name_with_extension()); |
|
610 | - |
|
611 | - if ($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) { |
|
612 | - $this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart()); |
|
613 | - } |
|
614 | - |
|
615 | - $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
616 | - |
|
617 | - } else { |
|
618 | - $this->logger->info(sprintf("Creating new multipart info file %s", |
|
619 | - $this->get_archive_name_with_extension())); |
|
620 | - $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
621 | - } |
|
599 | + private function create_new_backup_part($part = 0) |
|
600 | + { |
|
601 | + //close the backup archive by adding 2*512 blocks of zero bytes |
|
602 | + $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", |
|
603 | + $this->get_archive_name_with_extension())); |
|
604 | + $this->backup_archive->close(); |
|
605 | + |
|
606 | + if (!$part) { |
|
607 | + $old_name = $this->get_archive_name_with_extension(); |
|
608 | + $this->set_archive_name($this->get_archive_name(), ++$part); |
|
609 | + $this->rename_archive($old_name, $this->get_archive_name_with_extension()); |
|
610 | + |
|
611 | + if ($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) { |
|
612 | + $this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart()); |
|
613 | + } |
|
614 | + |
|
615 | + $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
616 | + |
|
617 | + } else { |
|
618 | + $this->logger->info(sprintf("Creating new multipart info file %s", |
|
619 | + $this->get_archive_name_with_extension())); |
|
620 | + $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
621 | + } |
|
622 | 622 | |
623 | - $this->set_archive_name($this->get_archive_name(), ++$part); |
|
623 | + $this->set_archive_name($this->get_archive_name(), ++$part); |
|
624 | 624 | |
625 | - $this->logger->info(sprintf("Creating new backup archive part %s", $this->get_archive_name_with_extension())); |
|
625 | + $this->logger->info(sprintf("Creating new backup archive part %s", $this->get_archive_name_with_extension())); |
|
626 | 626 | |
627 | - $this->backup_archive = new Tar(); |
|
628 | - $this->backup_archive->setCompression($this->compression_level); |
|
629 | - $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension()); |
|
630 | - $this->backup_archive->create($archive_info->getPath() . DS . $archive_info->getFilename()); |
|
627 | + $this->backup_archive = new Tar(); |
|
628 | + $this->backup_archive->setCompression($this->compression_level); |
|
629 | + $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension()); |
|
630 | + $this->backup_archive->create($archive_info->getPath() . DS . $archive_info->getFilename()); |
|
631 | 631 | |
632 | - return array($archive_info, $part); |
|
632 | + return array($archive_info, $part); |
|
633 | 633 | |
634 | - } |
|
634 | + } |
|
635 | 635 | |
636 | - /* |
|
636 | + /* |
|
637 | 637 | * |
638 | 638 | * Add file to archive |
639 | 639 | * |
640 | 640 | */ |
641 | - public function add_file_to_archive($file_info, $start_at_byte, $byte_limit = 0, $append, $filesystem) |
|
642 | - { |
|
643 | - |
|
644 | - $start_adapter = $this->filesystem->get_adapter($filesystem); |
|
645 | - $start_filesystem = $this->filesystem->get_adapter($filesystem); |
|
646 | - |
|
647 | - if (!$file_info['path']) { |
|
648 | - return; |
|
649 | - } |
|
650 | - |
|
651 | - if (isset($file_info['archive_prefix_path'])) { |
|
652 | - $file_info['target_path'] = $file_info['archive_prefix_path'] . "/" . $file_info['path']; |
|
653 | - } else { |
|
654 | - $file_info['target_path'] = $file_info['path']; |
|
655 | - } |
|
656 | - |
|
657 | - $last_position = $start_at_byte; |
|
658 | - |
|
659 | - //$start_adapter = $this->filesystem->get_start_adapter(); |
|
660 | - |
|
661 | - if (!$append) { |
|
662 | - $bytes_wrote = $file_info['size']; |
|
663 | - $this->logger->info(sprintf("Adding %s bytes of file %s to archive %s ", $bytes_wrote, |
|
664 | - $file_info['target_path'], $this->get_archive_name_with_extension())); |
|
665 | - $this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']), |
|
666 | - $file_info['target_path']); |
|
667 | - } else { |
|
668 | - $tmp_file = md5($file_info['path']); |
|
669 | - |
|
670 | - //we isolate file to tmp if we are at byte 0, the starting point of file reading |
|
671 | - if (!$start_at_byte) { |
|
672 | - $this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes", |
|
673 | - $file_info['path'], $tmp_file)); |
|
674 | - $file_stream = $start_filesystem->readStream($file_info['path']); |
|
675 | - |
|
676 | - if (is_resource($file_stream['stream'])) { |
|
677 | - $this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']); |
|
678 | - } |
|
679 | - } |
|
680 | - |
|
681 | - if ($this->filesystem->get_tmp_filesystem()->has($tmp_file)) { |
|
682 | - $is_tmp = 1; |
|
683 | - $last_position = $this->backup_archive->appendFileData($this->filesystem->get_tmp_filesystem_adapter() |
|
684 | - ->applyPathPrefix($tmp_file), |
|
685 | - $file_info['target_path'], $start_at_byte, $byte_limit); |
|
686 | - } else { |
|
687 | - $is_tmp = 0; |
|
688 | - $last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']), |
|
689 | - $file_info['target_path'], $start_at_byte, $byte_limit); |
|
690 | - } |
|
691 | - |
|
692 | - |
|
693 | - if ($last_position == -1) { |
|
694 | - $bytes_wrote = $file_info['size'] - $start_at_byte; |
|
695 | - } else { |
|
696 | - $bytes_wrote = $last_position - $start_at_byte; |
|
697 | - } |
|
641 | + public function add_file_to_archive($file_info, $start_at_byte, $byte_limit = 0, $append, $filesystem) |
|
642 | + { |
|
698 | 643 | |
644 | + $start_adapter = $this->filesystem->get_adapter($filesystem); |
|
645 | + $start_filesystem = $this->filesystem->get_adapter($filesystem); |
|
699 | 646 | |
700 | - if ($is_tmp) { |
|
701 | - $this->logger->info(sprintf("Appended %s bytes, starting position %s, of tmp file %s (%s) to archive %s ", |
|
702 | - $bytes_wrote, $start_at_byte, $tmp_file, $file_info['target_path'], $this->get_archive_name())); |
|
703 | - } else { |
|
704 | - $this->logger->info(sprintf("Appended %s bytes, starting position %s, of original file %s to archive %s ", |
|
705 | - $bytes_wrote, $start_at_byte, $file_info['target_path'], $tmp_file, $this->get_archive_name())); |
|
706 | - } |
|
647 | + if (!$file_info['path']) { |
|
648 | + return; |
|
649 | + } |
|
707 | 650 | |
708 | - //we delete here the isolated tmp file |
|
709 | - if ($last_position == -1) { |
|
710 | - if ($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file)) { |
|
711 | - $this->logger->info(sprintf("Deleting %s from the tmp filesystem", $tmp_file)); |
|
712 | - $this->filesystem->get_tmp_filesystem_adapter()->delete($tmp_file); |
|
713 | - } |
|
714 | - } |
|
651 | + if (isset($file_info['archive_prefix_path'])) { |
|
652 | + $file_info['target_path'] = $file_info['archive_prefix_path'] . "/" . $file_info['path']; |
|
653 | + } else { |
|
654 | + $file_info['target_path'] = $file_info['path']; |
|
655 | + } |
|
715 | 656 | |
716 | - } |
|
657 | + $last_position = $start_at_byte; |
|
658 | + |
|
659 | + //$start_adapter = $this->filesystem->get_start_adapter(); |
|
660 | + |
|
661 | + if (!$append) { |
|
662 | + $bytes_wrote = $file_info['size']; |
|
663 | + $this->logger->info(sprintf("Adding %s bytes of file %s to archive %s ", $bytes_wrote, |
|
664 | + $file_info['target_path'], $this->get_archive_name_with_extension())); |
|
665 | + $this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']), |
|
666 | + $file_info['target_path']); |
|
667 | + } else { |
|
668 | + $tmp_file = md5($file_info['path']); |
|
669 | + |
|
670 | + //we isolate file to tmp if we are at byte 0, the starting point of file reading |
|
671 | + if (!$start_at_byte) { |
|
672 | + $this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes", |
|
673 | + $file_info['path'], $tmp_file)); |
|
674 | + $file_stream = $start_filesystem->readStream($file_info['path']); |
|
675 | + |
|
676 | + if (is_resource($file_stream['stream'])) { |
|
677 | + $this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']); |
|
678 | + } |
|
679 | + } |
|
680 | + |
|
681 | + if ($this->filesystem->get_tmp_filesystem()->has($tmp_file)) { |
|
682 | + $is_tmp = 1; |
|
683 | + $last_position = $this->backup_archive->appendFileData($this->filesystem->get_tmp_filesystem_adapter() |
|
684 | + ->applyPathPrefix($tmp_file), |
|
685 | + $file_info['target_path'], $start_at_byte, $byte_limit); |
|
686 | + } else { |
|
687 | + $is_tmp = 0; |
|
688 | + $last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']), |
|
689 | + $file_info['target_path'], $start_at_byte, $byte_limit); |
|
690 | + } |
|
691 | + |
|
692 | + |
|
693 | + if ($last_position == -1) { |
|
694 | + $bytes_wrote = $file_info['size'] - $start_at_byte; |
|
695 | + } else { |
|
696 | + $bytes_wrote = $last_position - $start_at_byte; |
|
697 | + } |
|
698 | + |
|
699 | + |
|
700 | + if ($is_tmp) { |
|
701 | + $this->logger->info(sprintf("Appended %s bytes, starting position %s, of tmp file %s (%s) to archive %s ", |
|
702 | + $bytes_wrote, $start_at_byte, $tmp_file, $file_info['target_path'], $this->get_archive_name())); |
|
703 | + } else { |
|
704 | + $this->logger->info(sprintf("Appended %s bytes, starting position %s, of original file %s to archive %s ", |
|
705 | + $bytes_wrote, $start_at_byte, $file_info['target_path'], $tmp_file, $this->get_archive_name())); |
|
706 | + } |
|
707 | + |
|
708 | + //we delete here the isolated tmp file |
|
709 | + if ($last_position == -1) { |
|
710 | + if ($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file)) { |
|
711 | + $this->logger->info(sprintf("Deleting %s from the tmp filesystem", $tmp_file)); |
|
712 | + $this->filesystem->get_tmp_filesystem_adapter()->delete($tmp_file); |
|
713 | + } |
|
714 | + } |
|
717 | 715 | |
718 | - return array($bytes_wrote, $last_position); |
|
719 | - } |
|
716 | + } |
|
720 | 717 | |
721 | - /** |
|
722 | - * Open a TAR archive and put the file cursor at the end for data appending |
|
723 | - * |
|
724 | - * If $file is empty, the tar file will be created in memory |
|
725 | - * |
|
726 | - * @param string $file |
|
727 | - * @throws ArchiveIOException |
|
728 | - */ |
|
729 | - /* |
|
718 | + return array($bytes_wrote, $last_position); |
|
719 | + } |
|
720 | + |
|
721 | + /** |
|
722 | + * Open a TAR archive and put the file cursor at the end for data appending |
|
723 | + * |
|
724 | + * If $file is empty, the tar file will be created in memory |
|
725 | + * |
|
726 | + * @param string $file |
|
727 | + * @throws ArchiveIOException |
|
728 | + */ |
|
729 | + /* |
|
730 | 730 | public function openForAppend($file = '') |
731 | 731 | { |
732 | 732 | $this->file = $file; |
@@ -756,17 +756,17 @@ discard block |
||
756 | 756 | } |
757 | 757 | */ |
758 | 758 | |
759 | - /** |
|
760 | - * Append data to a file to the current TAR archive using an existing file in the filesystem |
|
761 | - * |
|
762 | - * @param string $file path to the original file |
|
763 | - * @param int $start starting reading position in file |
|
764 | - * @param int $end end position in reading multiple with 512 |
|
765 | - * @param string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with |
|
766 | - * all meta data, empty to take from original |
|
767 | - * @throws ArchiveIOException |
|
768 | - */ |
|
769 | - /* |
|
759 | + /** |
|
760 | + * Append data to a file to the current TAR archive using an existing file in the filesystem |
|
761 | + * |
|
762 | + * @param string $file path to the original file |
|
763 | + * @param int $start starting reading position in file |
|
764 | + * @param int $end end position in reading multiple with 512 |
|
765 | + * @param string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with |
|
766 | + * all meta data, empty to take from original |
|
767 | + * @throws ArchiveIOException |
|
768 | + */ |
|
769 | + /* |
|
770 | 770 | * public function appendFileData($file, $fileinfo = '', $start = 0, $limit = 0) |
771 | 771 | { |
772 | 772 | $end = $start+($limit*512); |
@@ -822,15 +822,15 @@ discard block |
||
822 | 822 | return $last_position; |
823 | 823 | }*/ |
824 | 824 | |
825 | - /** |
|
826 | - * Adds a file to a TAR archive by appending it's data |
|
827 | - * |
|
828 | - * @param string $archive name of the archive file |
|
829 | - * @param string $file name of the file to read data from |
|
830 | - * @param string $start start position from where to start reading data |
|
831 | - * @throws ArchiveIOException |
|
832 | - */ |
|
833 | - /*public function addFileToArchive($archive, $file, $start = 0) |
|
825 | + /** |
|
826 | + * Adds a file to a TAR archive by appending it's data |
|
827 | + * |
|
828 | + * @param string $archive name of the archive file |
|
829 | + * @param string $file name of the file to read data from |
|
830 | + * @param string $start start position from where to start reading data |
|
831 | + * @throws ArchiveIOException |
|
832 | + */ |
|
833 | + /*public function addFileToArchive($archive, $file, $start = 0) |
|
834 | 834 | { |
835 | 835 | $this->openForAppend($archive); |
836 | 836 | return $start = $this->appendFileData($file, $start, $this->file_size_per_request_limit); |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | $new_name = $this->archive_name; |
149 | 149 | |
150 | 150 | if (!stristr($new_name, "-diff")) { |
151 | - $new_name = $this->archive_name . "-diff" . date("Y-m-d_H-i", $diff_timestamp_start); |
|
151 | + $new_name = $this->archive_name."-diff".date("Y-m-d_H-i", $diff_timestamp_start); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | $this->archive_name = $new_name; |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | } |
157 | 157 | |
158 | 158 | if (isset($part) and $part) { |
159 | - $new_name = preg_replace('/-part(\d*)/', "-part" . $part, $this->archive_name); |
|
159 | + $new_name = preg_replace('/-part(\d*)/', "-part".$part, $this->archive_name); |
|
160 | 160 | if (!stristr($new_name, "-part")) { |
161 | - $new_name = $this->archive_name . "-part" . $part; |
|
161 | + $new_name = $this->archive_name."-part".$part; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | $this->archive_name = $new_name; |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | public function get_archive_name_multipart() |
188 | 188 | { |
189 | 189 | $new_name = preg_replace('/-part(\d*)/', "", $this->archive_name); |
190 | - return $new_name . "-multipart" . $this->xcloner_settings->get_backup_extension_name(".csv"); |
|
190 | + return $new_name."-multipart".$this->xcloner_settings->get_backup_extension_name(".csv"); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | /* |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | */ |
198 | 198 | public function get_archive_name_with_extension() |
199 | 199 | { |
200 | - return $this->archive_name . $this->xcloner_settings->get_backup_extension_name(); |
|
200 | + return $this->archive_name.$this->xcloner_settings->get_backup_extension_name(); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /* |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | $headers = array('Content-Type: text/html; charset=UTF-8'); |
230 | 230 | |
231 | 231 | if ($admin_email and $from) { |
232 | - $headers[] = 'From: ' . $from . ' <' . $admin_email . '>'; |
|
232 | + $headers[] = 'From: '.$from.' <'.$admin_email.'>'; |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | $return = wp_mail($to, $subject, $body, $headers); |
@@ -302,18 +302,18 @@ discard block |
||
302 | 302 | $body .= "<br />"; |
303 | 303 | |
304 | 304 | if (isset($params['backup_params']->backup_comments)) { |
305 | - $body .= __("Backup Comments: ") . $params['backup_params']->backup_comments; |
|
305 | + $body .= __("Backup Comments: ").$params['backup_params']->backup_comments; |
|
306 | 306 | $body .= "<br /><br />"; |
307 | 307 | } |
308 | 308 | |
309 | 309 | if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
310 | - $body .= __("Latest 50 Log Lines: ") . "<br />" . implode("<br />\n", |
|
310 | + $body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n", |
|
311 | 311 | $this->logger->getLastDebugLines(50)); |
312 | 312 | } |
313 | 313 | |
314 | 314 | $attachments = $this->filesystem->get_backup_attachments(); |
315 | 315 | |
316 | - $attachments_archive = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "info.tgz"; |
|
316 | + $attachments_archive = $this->xcloner_settings->get_xcloner_tmp_path().DS."info.tgz"; |
|
317 | 317 | |
318 | 318 | $tar = new Tar(); |
319 | 319 | $tar->create($attachments_archive); |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | |
328 | 328 | $admin_email = get_option("admin_email"); |
329 | 329 | |
330 | - $headers = array('Content-Type: text/html; charset=UTF-8', 'From: ' . $from . ' <' . $admin_email . '>'); |
|
330 | + $headers = array('Content-Type: text/html; charset=UTF-8', 'From: '.$from.' <'.$admin_email.'>'); |
|
331 | 331 | |
332 | 332 | $return = wp_mail($to, $subject, $body, $headers, array($attachments_archive)); |
333 | 333 | |
@@ -367,14 +367,14 @@ discard block |
||
367 | 367 | if ($init) { |
368 | 368 | $this->logger->info(sprintf(__("Initializing the backup archive %s"), $this->get_archive_name())); |
369 | 369 | |
370 | - $this->backup_archive->create($archive_info->getPath() . DS . $archive_info->getFilename()); |
|
370 | + $this->backup_archive->create($archive_info->getPath().DS.$archive_info->getFilename()); |
|
371 | 371 | |
372 | 372 | $return['extra']['backup_init'] = 1; |
373 | 373 | |
374 | 374 | } else { |
375 | 375 | $this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name())); |
376 | 376 | |
377 | - $this->backup_archive->openForAppend($archive_info->getPath() . DS . $archive_info->getFilename()); |
|
377 | + $this->backup_archive->openForAppend($archive_info->getPath().DS.$archive_info->getFilename()); |
|
378 | 378 | |
379 | 379 | $return['extra']['backup_init'] = 0; |
380 | 380 | |
@@ -578,13 +578,13 @@ discard block |
||
578 | 578 | */ |
579 | 579 | private function write_multipart_file($path = "") |
580 | 580 | { |
581 | - if(!$path) { |
|
581 | + if (!$path) { |
|
582 | 582 | $path = $this->get_archive_name_with_extension(); |
583 | 583 | } |
584 | 584 | |
585 | 585 | $file = $this->filesystem->get_filesystem("storage_filesystem_append")->getMetadata($path); |
586 | 586 | //print_r($file_info); |
587 | - $line = '"' . $file['path'] . '","' . $file['timestamp'] . '","' . $file['size'] . '"' . PHP_EOL; |
|
587 | + $line = '"'.$file['path'].'","'.$file['timestamp'].'","'.$file['size'].'"'.PHP_EOL; |
|
588 | 588 | |
589 | 589 | |
590 | 590 | $this->filesystem->get_filesystem("storage_filesystem_append") |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | $this->backup_archive = new Tar(); |
628 | 628 | $this->backup_archive->setCompression($this->compression_level); |
629 | 629 | $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension()); |
630 | - $this->backup_archive->create($archive_info->getPath() . DS . $archive_info->getFilename()); |
|
630 | + $this->backup_archive->create($archive_info->getPath().DS.$archive_info->getFilename()); |
|
631 | 631 | |
632 | 632 | return array($archive_info, $part); |
633 | 633 | |
@@ -649,7 +649,7 @@ discard block |
||
649 | 649 | } |
650 | 650 | |
651 | 651 | if (isset($file_info['archive_prefix_path'])) { |
652 | - $file_info['target_path'] = $file_info['archive_prefix_path'] . "/" . $file_info['path']; |
|
652 | + $file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path']; |
|
653 | 653 | } else { |
654 | 654 | $file_info['target_path'] = $file_info['path']; |
655 | 655 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | /** |
71 | 71 | * Returns the filename with encrypted suffix |
72 | 72 | * |
73 | - * @param $filename |
|
73 | + * @param string $filename |
|
74 | 74 | * @return string |
75 | 75 | */ |
76 | 76 | public function get_encrypted_target_backup_file_name( $filename ) { |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | /** |
82 | 82 | * Returns the filename without encrypted suffix |
83 | 83 | * |
84 | - * @param $filename |
|
84 | + * @param string $filename |
|
85 | 85 | * @return string |
86 | 86 | */ |
87 | 87 | public function get_decrypted_target_backup_file_name( $filename ) { |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | * @param string $dest File name where the encryped file should be written to. |
97 | 97 | * @param string $key The key used for the encryption |
98 | 98 | * @param int $start Start position for reading when doing incremental mode. |
99 | - * @param string $iv The IV key to use. |
|
100 | - * @param bool $verfication Weather we should we try to verify the decryption. |
|
99 | + * @param integer $iv The IV key to use. |
|
100 | + * @param bool $verification Weather we should we try to verify the decryption. |
|
101 | 101 | * @return string|false Returns the file name that has been created or FALSE if an error occured |
102 | 102 | */ |
103 | 103 | public function encrypt_file($source, $dest = "" , $key= "", $start = 0, $iv = 0, $verification = true, $recursive = false) |
@@ -206,6 +206,9 @@ discard block |
||
206 | 206 | return array("target_file" => $dest, "finished" => 1); |
207 | 207 | } |
208 | 208 | |
209 | + /** |
|
210 | + * @param string $file |
|
211 | + */ |
|
209 | 212 | public function verify_encrypted_file($file) { |
210 | 213 | if(is_object($this->logger)) { |
211 | 214 | $this->logger->info(sprintf('Verifying encrypted file %s', $file)); |
@@ -224,7 +227,7 @@ discard block |
||
224 | 227 | * @param string $dest File name where the decryped file should be written to. |
225 | 228 | * @param string $key The key used for the decryption (must be the same as for encryption) |
226 | 229 | * @param int $start Start position for reading when doing incremental mode. |
227 | - * @param string $iv The IV key to use. |
|
230 | + * @param integer $iv The IV key to use. |
|
228 | 231 | * @return string|false Returns the file name that has been created or FALSE if an error occured |
229 | 232 | */ |
230 | 233 | public function decrypt_file($source, $dest = "", $key = "", $start = 0, $iv = 0, $recursive = false) |
@@ -10,370 +10,370 @@ |
||
10 | 10 | |
11 | 11 | class Xcloner_Encryption |
12 | 12 | { |
13 | - const FILE_ENCRYPTION_BLOCKS = 1024*1024; |
|
14 | - const FILE_ENCRYPTION_SUFFIX = ".encrypted"; |
|
15 | - const FILE_DECRYPTION_SUFFIX = ".decrypted"; |
|
16 | - |
|
17 | - private $xcloner_settings; |
|
18 | - private $logger; |
|
19 | - private $verification = false; |
|
20 | - |
|
21 | - public function __construct(Xcloner $xcloner_container) |
|
22 | - { |
|
23 | - $this->xcloner_container = $xcloner_container; |
|
24 | - if(method_exists($xcloner_container, 'get_xcloner_settings')) { |
|
25 | - $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
|
26 | - }else{ |
|
27 | - $this->xcloner_settings = ""; |
|
28 | - } |
|
29 | - |
|
30 | - if(method_exists($xcloner_container, 'get_xcloner_logger')) { |
|
31 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_encryption"); |
|
32 | - }else{ |
|
33 | - $this->logger = ""; |
|
34 | - } |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * Returns the backup encryption key |
|
39 | - * |
|
40 | - * @return SECURE_AUTH_SALT|null |
|
41 | - */ |
|
42 | - public function get_backup_encryption_key() |
|
43 | - { |
|
44 | - if(is_object($this->xcloner_settings)) { |
|
45 | - return $this->xcloner_settings->get_xcloner_encryption_key(); |
|
46 | - } |
|
47 | - |
|
48 | - return false; |
|
49 | - |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Check if provided filename has encrypted suffix |
|
54 | - * |
|
55 | - * @param $filename |
|
56 | - * @return bool |
|
57 | - */ |
|
58 | - public function is_encrypted_file($filename) { |
|
59 | - $fp = fopen($this->get_xcloner_path() .$filename, 'r'); |
|
60 | - $encryption_length = fread($fp, 16); |
|
61 | - fclose($fp); |
|
62 | - if(is_numeric($encryption_length)) { |
|
63 | - return true; |
|
64 | - } |
|
65 | - |
|
66 | - return false; |
|
67 | - |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Returns the filename with encrypted suffix |
|
72 | - * |
|
73 | - * @param $filename |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function get_encrypted_target_backup_file_name( $filename ) { |
|
77 | - |
|
78 | - return str_replace(self::FILE_DECRYPTION_SUFFIX, "", $filename) . self::FILE_ENCRYPTION_SUFFIX; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Returns the filename without encrypted suffix |
|
83 | - * |
|
84 | - * @param $filename |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public function get_decrypted_target_backup_file_name( $filename ) { |
|
88 | - |
|
89 | - return str_replace(self::FILE_ENCRYPTION_SUFFIX, "", $filename) . self::FILE_DECRYPTION_SUFFIX; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Encrypt the passed file and saves the result in a new file with ".enc" as suffix. |
|
94 | - * |
|
95 | - * @param string $source Path to file that should be encrypted |
|
96 | - * @param string $dest File name where the encryped file should be written to. |
|
97 | - * @param string $key The key used for the encryption |
|
98 | - * @param int $start Start position for reading when doing incremental mode. |
|
99 | - * @param string $iv The IV key to use. |
|
100 | - * @param bool $verfication Weather we should we try to verify the decryption. |
|
101 | - * @return string|false Returns the file name that has been created or FALSE if an error occured |
|
102 | - */ |
|
103 | - public function encrypt_file($source, $dest = "" , $key= "", $start = 0, $iv = 0, $verification = true, $recursive = false) |
|
104 | - { |
|
105 | - if(is_object($this->logger)) { |
|
106 | - $this->logger->info(sprintf('Encrypting file %s at position %d IV %s', $source, $start, base64_encode($iv))); |
|
107 | - } |
|
108 | - |
|
109 | - //$key = substr(sha1($key, true), 0, 16); |
|
110 | - if(!$key){ |
|
111 | - $key = self::get_backup_encryption_key(); |
|
112 | - } |
|
113 | - $key_digest = openssl_digest ($key, "md5", true); |
|
114 | - |
|
115 | - $keep_local = 1; |
|
116 | - if(!$dest) { |
|
117 | - $dest = $this->get_encrypted_target_backup_file_name($source); |
|
118 | - $keep_local = 0; |
|
119 | - } |
|
120 | - |
|
121 | - if(!$iv || !$start) { |
|
122 | - //$iv = openssl_random_pseudo_bytes(16); |
|
123 | - $iv = str_pad(self::FILE_ENCRYPTION_BLOCKS, 16, "0000000000000000", STR_PAD_LEFT); |
|
124 | - } |
|
125 | - |
|
126 | - if( !$start ) { |
|
127 | - $fpOut = fopen($this->get_xcloner_path() .$dest, 'w'); |
|
128 | - }else{ |
|
129 | - $fpOut = fopen($this->get_xcloner_path() .$dest, 'a'); |
|
130 | - } |
|
131 | - |
|
132 | - if ( $fpOut ) { |
|
133 | - |
|
134 | - // Put the initialization vector to the beginning of the file |
|
135 | - if(!$start) { |
|
136 | - fwrite($fpOut, $iv); |
|
137 | - } |
|
138 | - |
|
139 | - if (file_exists($this->get_xcloner_path() .$source) && |
|
140 | - $fpIn = fopen($this->get_xcloner_path() .$source, 'rb')) { |
|
141 | - |
|
142 | - fseek($fpIn, (int)$start); |
|
143 | - |
|
144 | - if (!feof($fpIn)) { |
|
145 | - |
|
146 | - $plaintext = fread($fpIn, 16 * self::FILE_ENCRYPTION_BLOCKS); |
|
147 | - $ciphertext = openssl_encrypt($plaintext, 'AES-128-CBC', $key_digest, OPENSSL_RAW_DATA, $iv); |
|
148 | - |
|
149 | - // Use the first 16 bytes of the ciphertext as the next initialization vector |
|
150 | - $iv = substr($ciphertext, 0, 16); |
|
151 | - //$iv = openssl_random_pseudo_bytes(16); |
|
152 | - |
|
153 | - fwrite($fpOut, $ciphertext); |
|
154 | - |
|
155 | - $start = ftell($fpIn); |
|
156 | - |
|
157 | - fclose($fpOut ); |
|
158 | - |
|
159 | - if(!feof($fpIn)) { |
|
160 | - fclose($fpIn); |
|
161 | - //echo "\n NEW:".$key.md5($iv); |
|
162 | - //self::encryptFile($source, $dest, $key, $start, $iv); |
|
163 | - if($recursive ){ |
|
164 | - $this->encrypt_file($source, $dest, $key, $start, ($iv), $verification, $recursive); |
|
165 | - }else { |
|
166 | - |
|
167 | - if(($iv) != base64_decode(base64_encode($iv))) |
|
168 | - { |
|
169 | - throw new \Exception('Could not encode IV for transport'); |
|
170 | - } |
|
171 | - |
|
172 | - return array( |
|
173 | - "start" => $start, |
|
174 | - "iv" => base64_encode($iv), |
|
175 | - "target_file" => $dest, |
|
176 | - "finished" => 0 |
|
177 | - ); |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - } |
|
182 | - } else { |
|
183 | - if(is_object($this->logger)) { |
|
184 | - $this->logger->error('Unable to read source file for encryption.'); |
|
185 | - } |
|
186 | - throw new \Exception("Unable to read source file for encryption."); |
|
187 | - } |
|
188 | - } else { |
|
189 | - if(is_object($this->logger)) { |
|
190 | - $this->logger->error('Unable to write destination file for encryption.'); |
|
191 | - } |
|
192 | - throw new \Exception("Unable to write destination file for encryption."); |
|
193 | - } |
|
194 | - |
|
195 | - if($verification) { |
|
196 | - $this->verify_encrypted_file($dest); |
|
197 | - } |
|
198 | - |
|
199 | - //we replace the original backup with the encrypted one |
|
200 | - if( !$keep_local && copy($this->get_xcloner_path() .$dest, |
|
201 | - $this->get_xcloner_path() .$source) ) { |
|
202 | - unlink($this->get_xcloner_path() .$dest); |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - return array("target_file" => $dest, "finished" => 1); |
|
207 | - } |
|
208 | - |
|
209 | - public function verify_encrypted_file($file) { |
|
210 | - if(is_object($this->logger)) { |
|
211 | - $this->logger->info(sprintf('Verifying encrypted file %s', $file)); |
|
212 | - } |
|
213 | - |
|
214 | - $this->verification = true; |
|
215 | - $this->decrypt_file($file); |
|
216 | - $this->verification = false; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Dencrypt the passed file and saves the result in a new file, removing the |
|
221 | - * last 4 characters from file name. |
|
222 | - * |
|
223 | - * @param string $source Path to file that should be decrypted |
|
224 | - * @param string $dest File name where the decryped file should be written to. |
|
225 | - * @param string $key The key used for the decryption (must be the same as for encryption) |
|
226 | - * @param int $start Start position for reading when doing incremental mode. |
|
227 | - * @param string $iv The IV key to use. |
|
228 | - * @return string|false Returns the file name that has been created or FALSE if an error occured |
|
229 | - */ |
|
230 | - public function decrypt_file($source, $dest = "", $key = "", $start = 0, $iv = 0, $recursive = false) |
|
231 | - { |
|
232 | - if(is_object($this->logger)) { |
|
233 | - $this->logger->info(sprintf('Decrypting file %s at position %d with IV %s', $source, $start, base64_encode($iv))); |
|
234 | - } |
|
235 | - |
|
236 | - //$key = substr(sha1($key, true), 0, 16); |
|
237 | - if(!$key){ |
|
238 | - $key = self::get_backup_encryption_key(); |
|
239 | - } |
|
240 | - |
|
241 | - $key_digest = openssl_digest ($key, "md5", true); |
|
242 | - |
|
243 | - $keep_local = 1; |
|
244 | - if(!$dest) { |
|
245 | - $dest = $this->get_decrypted_target_backup_file_name($source); |
|
246 | - $keep_local = 0; |
|
247 | - } |
|
248 | - |
|
249 | - if( !$start ) { |
|
250 | - if($this->verification){ |
|
251 | - $fpOut = fopen("php://stdout", 'w'); |
|
252 | - }else { |
|
253 | - $fpOut = fopen($this->get_xcloner_path() . $dest, 'w'); |
|
254 | - } |
|
255 | - }else{ |
|
256 | - if($this->verification){ |
|
257 | - $fpOut = fopen("php://stdout", 'a'); |
|
258 | - }else { |
|
259 | - $fpOut = fopen($this->get_xcloner_path() . $dest, 'a'); |
|
260 | - } |
|
261 | - } |
|
262 | - |
|
263 | - if ( $fpOut ) { |
|
264 | - if ( file_exists($this->get_xcloner_path() .$source) && |
|
265 | - $fpIn = fopen($this->get_xcloner_path() .$source, 'rb')) { |
|
266 | - |
|
267 | - $encryption_length = (int)fread($fpIn, 16); |
|
268 | - if(!$encryption_length) { |
|
269 | - $encryption_length = self::FILE_ENCRYPTION_BLOCKS; |
|
270 | - } |
|
271 | - |
|
272 | - fseek($fpIn, (int)$start); |
|
273 | - |
|
274 | - // Get the initialzation vector from the beginning of the file |
|
275 | - if(!$iv) { |
|
276 | - $iv = fread($fpIn, 16); |
|
277 | - } |
|
278 | - |
|
279 | - if (!feof($fpIn)) { |
|
280 | - |
|
281 | - // we have to read one block more for decrypting than for encrypting |
|
282 | - $ciphertext = fread($fpIn, 16 * ($encryption_length + 1)); |
|
283 | - $plaintext = openssl_decrypt($ciphertext, 'AES-128-CBC', $key_digest, OPENSSL_RAW_DATA, $iv); |
|
284 | - |
|
285 | - if(!$plaintext){ |
|
286 | - unlink($this->get_xcloner_path() . $dest); |
|
287 | - if(is_object($this->logger)) { |
|
288 | - $this->logger->error('Backup decryption failed, please check your provided Encryption Key.'); |
|
289 | - } |
|
290 | - throw new \Exception("Backup decryption failed, please check your provided Encryption Key."); |
|
291 | - } |
|
292 | - |
|
293 | - // Use the first 16 bytes of the ciphertext as the next initialization vector |
|
294 | - $iv = substr($ciphertext, 0, 16); |
|
295 | - |
|
296 | - if( !$this->verification) { |
|
297 | - fwrite($fpOut, $plaintext); |
|
298 | - } |
|
299 | - |
|
300 | - $start = ftell($fpIn); |
|
301 | - |
|
302 | - fclose($fpOut ); |
|
303 | - |
|
304 | - if(!feof($fpIn)) { |
|
305 | - fclose($fpIn); |
|
306 | - if($this->verification || $recursive) { |
|
307 | - $ciphertext = ""; |
|
308 | - $plaintext = ""; |
|
309 | - $this->decrypt_file($source, $dest, $key, $start, $iv, $recursive); |
|
310 | - }else { |
|
311 | - if(($iv) != base64_decode(base64_encode($iv))) |
|
312 | - { |
|
313 | - throw new \Exception('Could not encode IV for transport'); |
|
314 | - } |
|
315 | - |
|
316 | - return array( |
|
317 | - "start" => $start, |
|
318 | - "encryption_length" => $encryption_length, |
|
319 | - "iv" => base64_encode($iv), |
|
320 | - "target_file" => $dest, |
|
321 | - "finished" => 0 |
|
322 | - ); |
|
323 | - } |
|
324 | - } |
|
325 | - |
|
326 | - } |
|
327 | - } else { |
|
328 | - if(is_object($this->logger)) { |
|
329 | - $this->logger->error('Unable to read source file for decryption'); |
|
330 | - } |
|
331 | - throw new \Exception("Unable to read source file for decryption"); |
|
332 | - } |
|
333 | - } else { |
|
334 | - if(is_object($this->logger)) { |
|
335 | - $this->logger->error('Unable to write destination file for decryption'); |
|
336 | - } |
|
337 | - throw new \Exception("Unable to write destination file for decryption"); |
|
338 | - } |
|
339 | - |
|
340 | - //we replace the original backup with the encrypted one |
|
341 | - if( !$keep_local && !$this->verification && copy($this->get_xcloner_path() .$dest, |
|
342 | - $this->get_xcloner_path() .$source) ) { |
|
343 | - unlink($this->get_xcloner_path() .$dest); |
|
344 | - } |
|
345 | - |
|
346 | - return array("target_file" => $dest, "finished" => 1); |
|
347 | - } |
|
348 | - |
|
349 | - public function get_xcloner_path(){ |
|
350 | - if(is_object($this->xcloner_settings)) { |
|
351 | - return $this->xcloner_settings->get_xcloner_store_path() . DS; |
|
352 | - } |
|
353 | - |
|
354 | - return null; |
|
355 | - } |
|
13 | + const FILE_ENCRYPTION_BLOCKS = 1024*1024; |
|
14 | + const FILE_ENCRYPTION_SUFFIX = ".encrypted"; |
|
15 | + const FILE_DECRYPTION_SUFFIX = ".decrypted"; |
|
16 | + |
|
17 | + private $xcloner_settings; |
|
18 | + private $logger; |
|
19 | + private $verification = false; |
|
20 | + |
|
21 | + public function __construct(Xcloner $xcloner_container) |
|
22 | + { |
|
23 | + $this->xcloner_container = $xcloner_container; |
|
24 | + if(method_exists($xcloner_container, 'get_xcloner_settings')) { |
|
25 | + $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
|
26 | + }else{ |
|
27 | + $this->xcloner_settings = ""; |
|
28 | + } |
|
29 | + |
|
30 | + if(method_exists($xcloner_container, 'get_xcloner_logger')) { |
|
31 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_encryption"); |
|
32 | + }else{ |
|
33 | + $this->logger = ""; |
|
34 | + } |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * Returns the backup encryption key |
|
39 | + * |
|
40 | + * @return SECURE_AUTH_SALT|null |
|
41 | + */ |
|
42 | + public function get_backup_encryption_key() |
|
43 | + { |
|
44 | + if(is_object($this->xcloner_settings)) { |
|
45 | + return $this->xcloner_settings->get_xcloner_encryption_key(); |
|
46 | + } |
|
47 | + |
|
48 | + return false; |
|
49 | + |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Check if provided filename has encrypted suffix |
|
54 | + * |
|
55 | + * @param $filename |
|
56 | + * @return bool |
|
57 | + */ |
|
58 | + public function is_encrypted_file($filename) { |
|
59 | + $fp = fopen($this->get_xcloner_path() .$filename, 'r'); |
|
60 | + $encryption_length = fread($fp, 16); |
|
61 | + fclose($fp); |
|
62 | + if(is_numeric($encryption_length)) { |
|
63 | + return true; |
|
64 | + } |
|
65 | + |
|
66 | + return false; |
|
67 | + |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Returns the filename with encrypted suffix |
|
72 | + * |
|
73 | + * @param $filename |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function get_encrypted_target_backup_file_name( $filename ) { |
|
77 | + |
|
78 | + return str_replace(self::FILE_DECRYPTION_SUFFIX, "", $filename) . self::FILE_ENCRYPTION_SUFFIX; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Returns the filename without encrypted suffix |
|
83 | + * |
|
84 | + * @param $filename |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public function get_decrypted_target_backup_file_name( $filename ) { |
|
88 | + |
|
89 | + return str_replace(self::FILE_ENCRYPTION_SUFFIX, "", $filename) . self::FILE_DECRYPTION_SUFFIX; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Encrypt the passed file and saves the result in a new file with ".enc" as suffix. |
|
94 | + * |
|
95 | + * @param string $source Path to file that should be encrypted |
|
96 | + * @param string $dest File name where the encryped file should be written to. |
|
97 | + * @param string $key The key used for the encryption |
|
98 | + * @param int $start Start position for reading when doing incremental mode. |
|
99 | + * @param string $iv The IV key to use. |
|
100 | + * @param bool $verfication Weather we should we try to verify the decryption. |
|
101 | + * @return string|false Returns the file name that has been created or FALSE if an error occured |
|
102 | + */ |
|
103 | + public function encrypt_file($source, $dest = "" , $key= "", $start = 0, $iv = 0, $verification = true, $recursive = false) |
|
104 | + { |
|
105 | + if(is_object($this->logger)) { |
|
106 | + $this->logger->info(sprintf('Encrypting file %s at position %d IV %s', $source, $start, base64_encode($iv))); |
|
107 | + } |
|
108 | + |
|
109 | + //$key = substr(sha1($key, true), 0, 16); |
|
110 | + if(!$key){ |
|
111 | + $key = self::get_backup_encryption_key(); |
|
112 | + } |
|
113 | + $key_digest = openssl_digest ($key, "md5", true); |
|
114 | + |
|
115 | + $keep_local = 1; |
|
116 | + if(!$dest) { |
|
117 | + $dest = $this->get_encrypted_target_backup_file_name($source); |
|
118 | + $keep_local = 0; |
|
119 | + } |
|
120 | + |
|
121 | + if(!$iv || !$start) { |
|
122 | + //$iv = openssl_random_pseudo_bytes(16); |
|
123 | + $iv = str_pad(self::FILE_ENCRYPTION_BLOCKS, 16, "0000000000000000", STR_PAD_LEFT); |
|
124 | + } |
|
125 | + |
|
126 | + if( !$start ) { |
|
127 | + $fpOut = fopen($this->get_xcloner_path() .$dest, 'w'); |
|
128 | + }else{ |
|
129 | + $fpOut = fopen($this->get_xcloner_path() .$dest, 'a'); |
|
130 | + } |
|
131 | + |
|
132 | + if ( $fpOut ) { |
|
133 | + |
|
134 | + // Put the initialization vector to the beginning of the file |
|
135 | + if(!$start) { |
|
136 | + fwrite($fpOut, $iv); |
|
137 | + } |
|
138 | + |
|
139 | + if (file_exists($this->get_xcloner_path() .$source) && |
|
140 | + $fpIn = fopen($this->get_xcloner_path() .$source, 'rb')) { |
|
141 | + |
|
142 | + fseek($fpIn, (int)$start); |
|
143 | + |
|
144 | + if (!feof($fpIn)) { |
|
145 | + |
|
146 | + $plaintext = fread($fpIn, 16 * self::FILE_ENCRYPTION_BLOCKS); |
|
147 | + $ciphertext = openssl_encrypt($plaintext, 'AES-128-CBC', $key_digest, OPENSSL_RAW_DATA, $iv); |
|
148 | + |
|
149 | + // Use the first 16 bytes of the ciphertext as the next initialization vector |
|
150 | + $iv = substr($ciphertext, 0, 16); |
|
151 | + //$iv = openssl_random_pseudo_bytes(16); |
|
152 | + |
|
153 | + fwrite($fpOut, $ciphertext); |
|
154 | + |
|
155 | + $start = ftell($fpIn); |
|
156 | + |
|
157 | + fclose($fpOut ); |
|
158 | + |
|
159 | + if(!feof($fpIn)) { |
|
160 | + fclose($fpIn); |
|
161 | + //echo "\n NEW:".$key.md5($iv); |
|
162 | + //self::encryptFile($source, $dest, $key, $start, $iv); |
|
163 | + if($recursive ){ |
|
164 | + $this->encrypt_file($source, $dest, $key, $start, ($iv), $verification, $recursive); |
|
165 | + }else { |
|
166 | + |
|
167 | + if(($iv) != base64_decode(base64_encode($iv))) |
|
168 | + { |
|
169 | + throw new \Exception('Could not encode IV for transport'); |
|
170 | + } |
|
171 | + |
|
172 | + return array( |
|
173 | + "start" => $start, |
|
174 | + "iv" => base64_encode($iv), |
|
175 | + "target_file" => $dest, |
|
176 | + "finished" => 0 |
|
177 | + ); |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + } |
|
182 | + } else { |
|
183 | + if(is_object($this->logger)) { |
|
184 | + $this->logger->error('Unable to read source file for encryption.'); |
|
185 | + } |
|
186 | + throw new \Exception("Unable to read source file for encryption."); |
|
187 | + } |
|
188 | + } else { |
|
189 | + if(is_object($this->logger)) { |
|
190 | + $this->logger->error('Unable to write destination file for encryption.'); |
|
191 | + } |
|
192 | + throw new \Exception("Unable to write destination file for encryption."); |
|
193 | + } |
|
194 | + |
|
195 | + if($verification) { |
|
196 | + $this->verify_encrypted_file($dest); |
|
197 | + } |
|
198 | + |
|
199 | + //we replace the original backup with the encrypted one |
|
200 | + if( !$keep_local && copy($this->get_xcloner_path() .$dest, |
|
201 | + $this->get_xcloner_path() .$source) ) { |
|
202 | + unlink($this->get_xcloner_path() .$dest); |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + return array("target_file" => $dest, "finished" => 1); |
|
207 | + } |
|
208 | + |
|
209 | + public function verify_encrypted_file($file) { |
|
210 | + if(is_object($this->logger)) { |
|
211 | + $this->logger->info(sprintf('Verifying encrypted file %s', $file)); |
|
212 | + } |
|
213 | + |
|
214 | + $this->verification = true; |
|
215 | + $this->decrypt_file($file); |
|
216 | + $this->verification = false; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Dencrypt the passed file and saves the result in a new file, removing the |
|
221 | + * last 4 characters from file name. |
|
222 | + * |
|
223 | + * @param string $source Path to file that should be decrypted |
|
224 | + * @param string $dest File name where the decryped file should be written to. |
|
225 | + * @param string $key The key used for the decryption (must be the same as for encryption) |
|
226 | + * @param int $start Start position for reading when doing incremental mode. |
|
227 | + * @param string $iv The IV key to use. |
|
228 | + * @return string|false Returns the file name that has been created or FALSE if an error occured |
|
229 | + */ |
|
230 | + public function decrypt_file($source, $dest = "", $key = "", $start = 0, $iv = 0, $recursive = false) |
|
231 | + { |
|
232 | + if(is_object($this->logger)) { |
|
233 | + $this->logger->info(sprintf('Decrypting file %s at position %d with IV %s', $source, $start, base64_encode($iv))); |
|
234 | + } |
|
235 | + |
|
236 | + //$key = substr(sha1($key, true), 0, 16); |
|
237 | + if(!$key){ |
|
238 | + $key = self::get_backup_encryption_key(); |
|
239 | + } |
|
240 | + |
|
241 | + $key_digest = openssl_digest ($key, "md5", true); |
|
242 | + |
|
243 | + $keep_local = 1; |
|
244 | + if(!$dest) { |
|
245 | + $dest = $this->get_decrypted_target_backup_file_name($source); |
|
246 | + $keep_local = 0; |
|
247 | + } |
|
248 | + |
|
249 | + if( !$start ) { |
|
250 | + if($this->verification){ |
|
251 | + $fpOut = fopen("php://stdout", 'w'); |
|
252 | + }else { |
|
253 | + $fpOut = fopen($this->get_xcloner_path() . $dest, 'w'); |
|
254 | + } |
|
255 | + }else{ |
|
256 | + if($this->verification){ |
|
257 | + $fpOut = fopen("php://stdout", 'a'); |
|
258 | + }else { |
|
259 | + $fpOut = fopen($this->get_xcloner_path() . $dest, 'a'); |
|
260 | + } |
|
261 | + } |
|
262 | + |
|
263 | + if ( $fpOut ) { |
|
264 | + if ( file_exists($this->get_xcloner_path() .$source) && |
|
265 | + $fpIn = fopen($this->get_xcloner_path() .$source, 'rb')) { |
|
266 | + |
|
267 | + $encryption_length = (int)fread($fpIn, 16); |
|
268 | + if(!$encryption_length) { |
|
269 | + $encryption_length = self::FILE_ENCRYPTION_BLOCKS; |
|
270 | + } |
|
271 | + |
|
272 | + fseek($fpIn, (int)$start); |
|
273 | + |
|
274 | + // Get the initialzation vector from the beginning of the file |
|
275 | + if(!$iv) { |
|
276 | + $iv = fread($fpIn, 16); |
|
277 | + } |
|
278 | + |
|
279 | + if (!feof($fpIn)) { |
|
280 | + |
|
281 | + // we have to read one block more for decrypting than for encrypting |
|
282 | + $ciphertext = fread($fpIn, 16 * ($encryption_length + 1)); |
|
283 | + $plaintext = openssl_decrypt($ciphertext, 'AES-128-CBC', $key_digest, OPENSSL_RAW_DATA, $iv); |
|
284 | + |
|
285 | + if(!$plaintext){ |
|
286 | + unlink($this->get_xcloner_path() . $dest); |
|
287 | + if(is_object($this->logger)) { |
|
288 | + $this->logger->error('Backup decryption failed, please check your provided Encryption Key.'); |
|
289 | + } |
|
290 | + throw new \Exception("Backup decryption failed, please check your provided Encryption Key."); |
|
291 | + } |
|
292 | + |
|
293 | + // Use the first 16 bytes of the ciphertext as the next initialization vector |
|
294 | + $iv = substr($ciphertext, 0, 16); |
|
295 | + |
|
296 | + if( !$this->verification) { |
|
297 | + fwrite($fpOut, $plaintext); |
|
298 | + } |
|
299 | + |
|
300 | + $start = ftell($fpIn); |
|
301 | + |
|
302 | + fclose($fpOut ); |
|
303 | + |
|
304 | + if(!feof($fpIn)) { |
|
305 | + fclose($fpIn); |
|
306 | + if($this->verification || $recursive) { |
|
307 | + $ciphertext = ""; |
|
308 | + $plaintext = ""; |
|
309 | + $this->decrypt_file($source, $dest, $key, $start, $iv, $recursive); |
|
310 | + }else { |
|
311 | + if(($iv) != base64_decode(base64_encode($iv))) |
|
312 | + { |
|
313 | + throw new \Exception('Could not encode IV for transport'); |
|
314 | + } |
|
315 | + |
|
316 | + return array( |
|
317 | + "start" => $start, |
|
318 | + "encryption_length" => $encryption_length, |
|
319 | + "iv" => base64_encode($iv), |
|
320 | + "target_file" => $dest, |
|
321 | + "finished" => 0 |
|
322 | + ); |
|
323 | + } |
|
324 | + } |
|
325 | + |
|
326 | + } |
|
327 | + } else { |
|
328 | + if(is_object($this->logger)) { |
|
329 | + $this->logger->error('Unable to read source file for decryption'); |
|
330 | + } |
|
331 | + throw new \Exception("Unable to read source file for decryption"); |
|
332 | + } |
|
333 | + } else { |
|
334 | + if(is_object($this->logger)) { |
|
335 | + $this->logger->error('Unable to write destination file for decryption'); |
|
336 | + } |
|
337 | + throw new \Exception("Unable to write destination file for decryption"); |
|
338 | + } |
|
339 | + |
|
340 | + //we replace the original backup with the encrypted one |
|
341 | + if( !$keep_local && !$this->verification && copy($this->get_xcloner_path() .$dest, |
|
342 | + $this->get_xcloner_path() .$source) ) { |
|
343 | + unlink($this->get_xcloner_path() .$dest); |
|
344 | + } |
|
345 | + |
|
346 | + return array("target_file" => $dest, "finished" => 1); |
|
347 | + } |
|
348 | + |
|
349 | + public function get_xcloner_path(){ |
|
350 | + if(is_object($this->xcloner_settings)) { |
|
351 | + return $this->xcloner_settings->get_xcloner_store_path() . DS; |
|
352 | + } |
|
353 | + |
|
354 | + return null; |
|
355 | + } |
|
356 | 356 | |
357 | 357 | } |
358 | 358 | |
359 | 359 | |
360 | 360 | try { |
361 | 361 | |
362 | - if(isset($argv[1])) { |
|
363 | - |
|
364 | - class Xcloner { |
|
365 | - public function __construct() |
|
366 | - { |
|
367 | - } |
|
368 | - } |
|
369 | - $xcloner_encryption = new Xcloner_Encryption( new Xcloner() ); |
|
370 | - |
|
371 | - if ($argv[1] == "-e") { |
|
372 | - $xcloner_encryption->encrypt_file($argv[2], $argv[2] . ".enc", $argv[4], '', '', '', true); |
|
373 | - } elseif ($argv[1] == "-d") { |
|
374 | - $xcloner_encryption->decrypt_file($argv[2], $argv[2] . ".dec", $argv[4], '', '', true); |
|
375 | - } |
|
376 | - } |
|
362 | + if(isset($argv[1])) { |
|
363 | + |
|
364 | + class Xcloner { |
|
365 | + public function __construct() |
|
366 | + { |
|
367 | + } |
|
368 | + } |
|
369 | + $xcloner_encryption = new Xcloner_Encryption( new Xcloner() ); |
|
370 | + |
|
371 | + if ($argv[1] == "-e") { |
|
372 | + $xcloner_encryption->encrypt_file($argv[2], $argv[2] . ".enc", $argv[4], '', '', '', true); |
|
373 | + } elseif ($argv[1] == "-d") { |
|
374 | + $xcloner_encryption->decrypt_file($argv[2], $argv[2] . ".dec", $argv[4], '', '', true); |
|
375 | + } |
|
376 | + } |
|
377 | 377 | }catch(\Exception $e) { |
378 | - echo "CAUGHT: " . $e->getMessage(); |
|
378 | + echo "CAUGHT: " . $e->getMessage(); |
|
379 | 379 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | |
11 | 11 | class Xcloner_Encryption |
12 | 12 | { |
13 | - const FILE_ENCRYPTION_BLOCKS = 1024*1024; |
|
13 | + const FILE_ENCRYPTION_BLOCKS = 1024 * 1024; |
|
14 | 14 | const FILE_ENCRYPTION_SUFFIX = ".encrypted"; |
15 | 15 | const FILE_DECRYPTION_SUFFIX = ".decrypted"; |
16 | 16 | |
@@ -21,15 +21,15 @@ discard block |
||
21 | 21 | public function __construct(Xcloner $xcloner_container) |
22 | 22 | { |
23 | 23 | $this->xcloner_container = $xcloner_container; |
24 | - if(method_exists($xcloner_container, 'get_xcloner_settings')) { |
|
24 | + if (method_exists($xcloner_container, 'get_xcloner_settings')) { |
|
25 | 25 | $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
26 | - }else{ |
|
26 | + } else { |
|
27 | 27 | $this->xcloner_settings = ""; |
28 | 28 | } |
29 | 29 | |
30 | - if(method_exists($xcloner_container, 'get_xcloner_logger')) { |
|
30 | + if (method_exists($xcloner_container, 'get_xcloner_logger')) { |
|
31 | 31 | $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_encryption"); |
32 | - }else{ |
|
32 | + } else { |
|
33 | 33 | $this->logger = ""; |
34 | 34 | } |
35 | 35 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function get_backup_encryption_key() |
43 | 43 | { |
44 | - if(is_object($this->xcloner_settings)) { |
|
44 | + if (is_object($this->xcloner_settings)) { |
|
45 | 45 | return $this->xcloner_settings->get_xcloner_encryption_key(); |
46 | 46 | } |
47 | 47 | |
@@ -56,10 +56,10 @@ discard block |
||
56 | 56 | * @return bool |
57 | 57 | */ |
58 | 58 | public function is_encrypted_file($filename) { |
59 | - $fp = fopen($this->get_xcloner_path() .$filename, 'r'); |
|
59 | + $fp = fopen($this->get_xcloner_path().$filename, 'r'); |
|
60 | 60 | $encryption_length = fread($fp, 16); |
61 | 61 | fclose($fp); |
62 | - if(is_numeric($encryption_length)) { |
|
62 | + if (is_numeric($encryption_length)) { |
|
63 | 63 | return true; |
64 | 64 | } |
65 | 65 | |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | * @param $filename |
74 | 74 | * @return string |
75 | 75 | */ |
76 | - public function get_encrypted_target_backup_file_name( $filename ) { |
|
76 | + public function get_encrypted_target_backup_file_name($filename) { |
|
77 | 77 | |
78 | - return str_replace(self::FILE_DECRYPTION_SUFFIX, "", $filename) . self::FILE_ENCRYPTION_SUFFIX; |
|
78 | + return str_replace(self::FILE_DECRYPTION_SUFFIX, "", $filename).self::FILE_ENCRYPTION_SUFFIX; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | * @param $filename |
85 | 85 | * @return string |
86 | 86 | */ |
87 | - public function get_decrypted_target_backup_file_name( $filename ) { |
|
87 | + public function get_decrypted_target_backup_file_name($filename) { |
|
88 | 88 | |
89 | - return str_replace(self::FILE_ENCRYPTION_SUFFIX, "", $filename) . self::FILE_DECRYPTION_SUFFIX; |
|
89 | + return str_replace(self::FILE_ENCRYPTION_SUFFIX, "", $filename).self::FILE_DECRYPTION_SUFFIX; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -100,44 +100,44 @@ discard block |
||
100 | 100 | * @param bool $verfication Weather we should we try to verify the decryption. |
101 | 101 | * @return string|false Returns the file name that has been created or FALSE if an error occured |
102 | 102 | */ |
103 | - public function encrypt_file($source, $dest = "" , $key= "", $start = 0, $iv = 0, $verification = true, $recursive = false) |
|
103 | + public function encrypt_file($source, $dest = "", $key = "", $start = 0, $iv = 0, $verification = true, $recursive = false) |
|
104 | 104 | { |
105 | - if(is_object($this->logger)) { |
|
105 | + if (is_object($this->logger)) { |
|
106 | 106 | $this->logger->info(sprintf('Encrypting file %s at position %d IV %s', $source, $start, base64_encode($iv))); |
107 | 107 | } |
108 | 108 | |
109 | 109 | //$key = substr(sha1($key, true), 0, 16); |
110 | - if(!$key){ |
|
110 | + if (!$key) { |
|
111 | 111 | $key = self::get_backup_encryption_key(); |
112 | 112 | } |
113 | - $key_digest = openssl_digest ($key, "md5", true); |
|
113 | + $key_digest = openssl_digest($key, "md5", true); |
|
114 | 114 | |
115 | 115 | $keep_local = 1; |
116 | - if(!$dest) { |
|
116 | + if (!$dest) { |
|
117 | 117 | $dest = $this->get_encrypted_target_backup_file_name($source); |
118 | 118 | $keep_local = 0; |
119 | 119 | } |
120 | 120 | |
121 | - if(!$iv || !$start) { |
|
121 | + if (!$iv || !$start) { |
|
122 | 122 | //$iv = openssl_random_pseudo_bytes(16); |
123 | 123 | $iv = str_pad(self::FILE_ENCRYPTION_BLOCKS, 16, "0000000000000000", STR_PAD_LEFT); |
124 | 124 | } |
125 | 125 | |
126 | - if( !$start ) { |
|
127 | - $fpOut = fopen($this->get_xcloner_path() .$dest, 'w'); |
|
128 | - }else{ |
|
129 | - $fpOut = fopen($this->get_xcloner_path() .$dest, 'a'); |
|
126 | + if (!$start) { |
|
127 | + $fpOut = fopen($this->get_xcloner_path().$dest, 'w'); |
|
128 | + } else { |
|
129 | + $fpOut = fopen($this->get_xcloner_path().$dest, 'a'); |
|
130 | 130 | } |
131 | 131 | |
132 | - if ( $fpOut ) { |
|
132 | + if ($fpOut) { |
|
133 | 133 | |
134 | 134 | // Put the initialization vector to the beginning of the file |
135 | - if(!$start) { |
|
135 | + if (!$start) { |
|
136 | 136 | fwrite($fpOut, $iv); |
137 | 137 | } |
138 | 138 | |
139 | - if (file_exists($this->get_xcloner_path() .$source) && |
|
140 | - $fpIn = fopen($this->get_xcloner_path() .$source, 'rb')) { |
|
139 | + if (file_exists($this->get_xcloner_path().$source) && |
|
140 | + $fpIn = fopen($this->get_xcloner_path().$source, 'rb')) { |
|
141 | 141 | |
142 | 142 | fseek($fpIn, (int)$start); |
143 | 143 | |
@@ -154,17 +154,17 @@ discard block |
||
154 | 154 | |
155 | 155 | $start = ftell($fpIn); |
156 | 156 | |
157 | - fclose($fpOut ); |
|
157 | + fclose($fpOut); |
|
158 | 158 | |
159 | - if(!feof($fpIn)) { |
|
159 | + if (!feof($fpIn)) { |
|
160 | 160 | fclose($fpIn); |
161 | 161 | //echo "\n NEW:".$key.md5($iv); |
162 | 162 | //self::encryptFile($source, $dest, $key, $start, $iv); |
163 | - if($recursive ){ |
|
163 | + if ($recursive) { |
|
164 | 164 | $this->encrypt_file($source, $dest, $key, $start, ($iv), $verification, $recursive); |
165 | - }else { |
|
165 | + } else { |
|
166 | 166 | |
167 | - if(($iv) != base64_decode(base64_encode($iv))) |
|
167 | + if (($iv) != base64_decode(base64_encode($iv))) |
|
168 | 168 | { |
169 | 169 | throw new \Exception('Could not encode IV for transport'); |
170 | 170 | } |
@@ -180,26 +180,26 @@ discard block |
||
180 | 180 | |
181 | 181 | } |
182 | 182 | } else { |
183 | - if(is_object($this->logger)) { |
|
183 | + if (is_object($this->logger)) { |
|
184 | 184 | $this->logger->error('Unable to read source file for encryption.'); |
185 | 185 | } |
186 | 186 | throw new \Exception("Unable to read source file for encryption."); |
187 | 187 | } |
188 | 188 | } else { |
189 | - if(is_object($this->logger)) { |
|
189 | + if (is_object($this->logger)) { |
|
190 | 190 | $this->logger->error('Unable to write destination file for encryption.'); |
191 | 191 | } |
192 | 192 | throw new \Exception("Unable to write destination file for encryption."); |
193 | 193 | } |
194 | 194 | |
195 | - if($verification) { |
|
195 | + if ($verification) { |
|
196 | 196 | $this->verify_encrypted_file($dest); |
197 | 197 | } |
198 | 198 | |
199 | 199 | //we replace the original backup with the encrypted one |
200 | - if( !$keep_local && copy($this->get_xcloner_path() .$dest, |
|
201 | - $this->get_xcloner_path() .$source) ) { |
|
202 | - unlink($this->get_xcloner_path() .$dest); |
|
200 | + if (!$keep_local && copy($this->get_xcloner_path().$dest, |
|
201 | + $this->get_xcloner_path().$source)) { |
|
202 | + unlink($this->get_xcloner_path().$dest); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | } |
208 | 208 | |
209 | 209 | public function verify_encrypted_file($file) { |
210 | - if(is_object($this->logger)) { |
|
210 | + if (is_object($this->logger)) { |
|
211 | 211 | $this->logger->info(sprintf('Verifying encrypted file %s', $file)); |
212 | 212 | } |
213 | 213 | |
@@ -229,50 +229,50 @@ discard block |
||
229 | 229 | */ |
230 | 230 | public function decrypt_file($source, $dest = "", $key = "", $start = 0, $iv = 0, $recursive = false) |
231 | 231 | { |
232 | - if(is_object($this->logger)) { |
|
232 | + if (is_object($this->logger)) { |
|
233 | 233 | $this->logger->info(sprintf('Decrypting file %s at position %d with IV %s', $source, $start, base64_encode($iv))); |
234 | 234 | } |
235 | 235 | |
236 | 236 | //$key = substr(sha1($key, true), 0, 16); |
237 | - if(!$key){ |
|
237 | + if (!$key) { |
|
238 | 238 | $key = self::get_backup_encryption_key(); |
239 | 239 | } |
240 | 240 | |
241 | - $key_digest = openssl_digest ($key, "md5", true); |
|
241 | + $key_digest = openssl_digest($key, "md5", true); |
|
242 | 242 | |
243 | 243 | $keep_local = 1; |
244 | - if(!$dest) { |
|
244 | + if (!$dest) { |
|
245 | 245 | $dest = $this->get_decrypted_target_backup_file_name($source); |
246 | 246 | $keep_local = 0; |
247 | 247 | } |
248 | 248 | |
249 | - if( !$start ) { |
|
250 | - if($this->verification){ |
|
249 | + if (!$start) { |
|
250 | + if ($this->verification) { |
|
251 | 251 | $fpOut = fopen("php://stdout", 'w'); |
252 | - }else { |
|
253 | - $fpOut = fopen($this->get_xcloner_path() . $dest, 'w'); |
|
252 | + } else { |
|
253 | + $fpOut = fopen($this->get_xcloner_path().$dest, 'w'); |
|
254 | 254 | } |
255 | - }else{ |
|
256 | - if($this->verification){ |
|
255 | + } else { |
|
256 | + if ($this->verification) { |
|
257 | 257 | $fpOut = fopen("php://stdout", 'a'); |
258 | - }else { |
|
259 | - $fpOut = fopen($this->get_xcloner_path() . $dest, 'a'); |
|
258 | + } else { |
|
259 | + $fpOut = fopen($this->get_xcloner_path().$dest, 'a'); |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
263 | - if ( $fpOut ) { |
|
264 | - if ( file_exists($this->get_xcloner_path() .$source) && |
|
265 | - $fpIn = fopen($this->get_xcloner_path() .$source, 'rb')) { |
|
263 | + if ($fpOut) { |
|
264 | + if (file_exists($this->get_xcloner_path().$source) && |
|
265 | + $fpIn = fopen($this->get_xcloner_path().$source, 'rb')) { |
|
266 | 266 | |
267 | 267 | $encryption_length = (int)fread($fpIn, 16); |
268 | - if(!$encryption_length) { |
|
268 | + if (!$encryption_length) { |
|
269 | 269 | $encryption_length = self::FILE_ENCRYPTION_BLOCKS; |
270 | 270 | } |
271 | 271 | |
272 | 272 | fseek($fpIn, (int)$start); |
273 | 273 | |
274 | 274 | // Get the initialzation vector from the beginning of the file |
275 | - if(!$iv) { |
|
275 | + if (!$iv) { |
|
276 | 276 | $iv = fread($fpIn, 16); |
277 | 277 | } |
278 | 278 | |
@@ -282,9 +282,9 @@ discard block |
||
282 | 282 | $ciphertext = fread($fpIn, 16 * ($encryption_length + 1)); |
283 | 283 | $plaintext = openssl_decrypt($ciphertext, 'AES-128-CBC', $key_digest, OPENSSL_RAW_DATA, $iv); |
284 | 284 | |
285 | - if(!$plaintext){ |
|
286 | - unlink($this->get_xcloner_path() . $dest); |
|
287 | - if(is_object($this->logger)) { |
|
285 | + if (!$plaintext) { |
|
286 | + unlink($this->get_xcloner_path().$dest); |
|
287 | + if (is_object($this->logger)) { |
|
288 | 288 | $this->logger->error('Backup decryption failed, please check your provided Encryption Key.'); |
289 | 289 | } |
290 | 290 | throw new \Exception("Backup decryption failed, please check your provided Encryption Key."); |
@@ -293,22 +293,22 @@ discard block |
||
293 | 293 | // Use the first 16 bytes of the ciphertext as the next initialization vector |
294 | 294 | $iv = substr($ciphertext, 0, 16); |
295 | 295 | |
296 | - if( !$this->verification) { |
|
296 | + if (!$this->verification) { |
|
297 | 297 | fwrite($fpOut, $plaintext); |
298 | 298 | } |
299 | 299 | |
300 | 300 | $start = ftell($fpIn); |
301 | 301 | |
302 | - fclose($fpOut ); |
|
302 | + fclose($fpOut); |
|
303 | 303 | |
304 | - if(!feof($fpIn)) { |
|
304 | + if (!feof($fpIn)) { |
|
305 | 305 | fclose($fpIn); |
306 | - if($this->verification || $recursive) { |
|
306 | + if ($this->verification || $recursive) { |
|
307 | 307 | $ciphertext = ""; |
308 | 308 | $plaintext = ""; |
309 | 309 | $this->decrypt_file($source, $dest, $key, $start, $iv, $recursive); |
310 | - }else { |
|
311 | - if(($iv) != base64_decode(base64_encode($iv))) |
|
310 | + } else { |
|
311 | + if (($iv) != base64_decode(base64_encode($iv))) |
|
312 | 312 | { |
313 | 313 | throw new \Exception('Could not encode IV for transport'); |
314 | 314 | } |
@@ -325,30 +325,30 @@ discard block |
||
325 | 325 | |
326 | 326 | } |
327 | 327 | } else { |
328 | - if(is_object($this->logger)) { |
|
328 | + if (is_object($this->logger)) { |
|
329 | 329 | $this->logger->error('Unable to read source file for decryption'); |
330 | 330 | } |
331 | 331 | throw new \Exception("Unable to read source file for decryption"); |
332 | 332 | } |
333 | 333 | } else { |
334 | - if(is_object($this->logger)) { |
|
334 | + if (is_object($this->logger)) { |
|
335 | 335 | $this->logger->error('Unable to write destination file for decryption'); |
336 | 336 | } |
337 | 337 | throw new \Exception("Unable to write destination file for decryption"); |
338 | 338 | } |
339 | 339 | |
340 | 340 | //we replace the original backup with the encrypted one |
341 | - if( !$keep_local && !$this->verification && copy($this->get_xcloner_path() .$dest, |
|
342 | - $this->get_xcloner_path() .$source) ) { |
|
343 | - unlink($this->get_xcloner_path() .$dest); |
|
341 | + if (!$keep_local && !$this->verification && copy($this->get_xcloner_path().$dest, |
|
342 | + $this->get_xcloner_path().$source)) { |
|
343 | + unlink($this->get_xcloner_path().$dest); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | return array("target_file" => $dest, "finished" => 1); |
347 | 347 | } |
348 | 348 | |
349 | - public function get_xcloner_path(){ |
|
350 | - if(is_object($this->xcloner_settings)) { |
|
351 | - return $this->xcloner_settings->get_xcloner_store_path() . DS; |
|
349 | + public function get_xcloner_path() { |
|
350 | + if (is_object($this->xcloner_settings)) { |
|
351 | + return $this->xcloner_settings->get_xcloner_store_path().DS; |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | return null; |
@@ -359,21 +359,21 @@ discard block |
||
359 | 359 | |
360 | 360 | try { |
361 | 361 | |
362 | - if(isset($argv[1])) { |
|
362 | + if (isset($argv[1])) { |
|
363 | 363 | |
364 | 364 | class Xcloner { |
365 | 365 | public function __construct() |
366 | 366 | { |
367 | 367 | } |
368 | 368 | } |
369 | - $xcloner_encryption = new Xcloner_Encryption( new Xcloner() ); |
|
369 | + $xcloner_encryption = new Xcloner_Encryption(new Xcloner()); |
|
370 | 370 | |
371 | 371 | if ($argv[1] == "-e") { |
372 | - $xcloner_encryption->encrypt_file($argv[2], $argv[2] . ".enc", $argv[4], '', '', '', true); |
|
372 | + $xcloner_encryption->encrypt_file($argv[2], $argv[2].".enc", $argv[4], '', '', '', true); |
|
373 | 373 | } elseif ($argv[1] == "-d") { |
374 | - $xcloner_encryption->decrypt_file($argv[2], $argv[2] . ".dec", $argv[4], '', '', true); |
|
374 | + $xcloner_encryption->decrypt_file($argv[2], $argv[2].".dec", $argv[4], '', '', true); |
|
375 | 375 | } |
376 | 376 | } |
377 | -}catch(\Exception $e) { |
|
378 | - echo "CAUGHT: " . $e->getMessage(); |
|
377 | +}catch (\Exception $e) { |
|
378 | + echo "CAUGHT: ".$e->getMessage(); |
|
379 | 379 | } |
@@ -23,13 +23,13 @@ discard block |
||
23 | 23 | $this->xcloner_container = $xcloner_container; |
24 | 24 | if(method_exists($xcloner_container, 'get_xcloner_settings')) { |
25 | 25 | $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
26 | - }else{ |
|
26 | + } else{ |
|
27 | 27 | $this->xcloner_settings = ""; |
28 | 28 | } |
29 | 29 | |
30 | 30 | if(method_exists($xcloner_container, 'get_xcloner_logger')) { |
31 | 31 | $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_encryption"); |
32 | - }else{ |
|
32 | + } else{ |
|
33 | 33 | $this->logger = ""; |
34 | 34 | } |
35 | 35 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | |
126 | 126 | if( !$start ) { |
127 | 127 | $fpOut = fopen($this->get_xcloner_path() .$dest, 'w'); |
128 | - }else{ |
|
128 | + } else{ |
|
129 | 129 | $fpOut = fopen($this->get_xcloner_path() .$dest, 'a'); |
130 | 130 | } |
131 | 131 | |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | //self::encryptFile($source, $dest, $key, $start, $iv); |
163 | 163 | if($recursive ){ |
164 | 164 | $this->encrypt_file($source, $dest, $key, $start, ($iv), $verification, $recursive); |
165 | - }else { |
|
165 | + } else { |
|
166 | 166 | |
167 | 167 | if(($iv) != base64_decode(base64_encode($iv))) |
168 | 168 | { |
@@ -249,13 +249,13 @@ discard block |
||
249 | 249 | if( !$start ) { |
250 | 250 | if($this->verification){ |
251 | 251 | $fpOut = fopen("php://stdout", 'w'); |
252 | - }else { |
|
252 | + } else { |
|
253 | 253 | $fpOut = fopen($this->get_xcloner_path() . $dest, 'w'); |
254 | 254 | } |
255 | - }else{ |
|
255 | + } else{ |
|
256 | 256 | if($this->verification){ |
257 | 257 | $fpOut = fopen("php://stdout", 'a'); |
258 | - }else { |
|
258 | + } else { |
|
259 | 259 | $fpOut = fopen($this->get_xcloner_path() . $dest, 'a'); |
260 | 260 | } |
261 | 261 | } |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | $ciphertext = ""; |
308 | 308 | $plaintext = ""; |
309 | 309 | $this->decrypt_file($source, $dest, $key, $start, $iv, $recursive); |
310 | - }else { |
|
310 | + } else { |
|
311 | 311 | if(($iv) != base64_decode(base64_encode($iv))) |
312 | 312 | { |
313 | 313 | throw new \Exception('Could not encode IV for transport'); |
@@ -374,6 +374,6 @@ discard block |
||
374 | 374 | $xcloner_encryption->decrypt_file($argv[2], $argv[2] . ".dec", $argv[4], '', '', true); |
375 | 375 | } |
376 | 376 | } |
377 | -}catch(\Exception $e) { |
|
377 | +} catch(\Exception $e) { |
|
378 | 378 | echo "CAUGHT: " . $e->getMessage(); |
379 | 379 | } |
@@ -4,10 +4,10 @@ discard block |
||
4 | 4 | $xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
5 | 5 | $available_storages = $xcloner_remote_storage->get_available_storages(); |
6 | 6 | ?> |
7 | -<?php if ( ! defined( "DISABLE_WP_CRON" ) || ! DISABLE_WP_CRON ): ?> |
|
7 | +<?php if (!defined("DISABLE_WP_CRON") || !DISABLE_WP_CRON): ?> |
|
8 | 8 | <div id="setting-error-" class="error settings-error notice is-dismissible"> |
9 | 9 | <p><strong> |
10 | - <?php echo sprintf( __( 'We have noticed that DISABLE_WP_CRON is disabled, we recommend enabling that and setting up wp-cron.php to run manually through your hosting account scheduler as explained <a href="%s" target="_blank">here</a>', 'xcloner-backup-and-restore' ), "http://www.inmotionhosting.com/support/website/wordpress/disabling-the-wp-cronphp-in-wordpress" ) ?> |
|
10 | + <?php echo sprintf(__('We have noticed that DISABLE_WP_CRON is disabled, we recommend enabling that and setting up wp-cron.php to run manually through your hosting account scheduler as explained <a href="%s" target="_blank">here</a>', 'xcloner-backup-and-restore'), "http://www.inmotionhosting.com/support/website/wordpress/disabling-the-wp-cronphp-in-wordpress") ?> |
|
11 | 11 | </strong> |
12 | 12 | </p> |
13 | 13 | <button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span> |
@@ -15,32 +15,32 @@ discard block |
||
15 | 15 | </div> |
16 | 16 | <?php endif ?> |
17 | 17 | |
18 | -<h1><?= esc_html( get_admin_page_title() ); ?></h1> |
|
18 | +<h1><?= esc_html(get_admin_page_title()); ?></h1> |
|
19 | 19 | |
20 | 20 | <div class="row"> |
21 | 21 | <table id="scheduled_backups" class="col s12" cellspacing="0" width="100%"> |
22 | 22 | <thead> |
23 | 23 | <tr class="grey lighten-2"> |
24 | - <th><?php echo __( 'ID', 'xcloner-backup-and-restore' ) ?></th> |
|
25 | - <th><?php echo __( 'Schedule Name', 'xcloner-backup-and-restore' ) ?></th> |
|
26 | - <th><?php echo __( 'Recurrence', 'xcloner-backup-and-restore' ) ?></th> |
|
27 | - <th class="hide-on-med-and-down"><?php echo __( 'Next Execution', 'xcloner-backup-and-restore' ) ?></th> |
|
28 | - <th><?php echo __( 'Remote Storage', 'xcloner-backup-and-restore' ) ?></th> |
|
29 | - <th class="hide-on-med-and-down"><?php echo __( 'Last Backup', 'xcloner-backup-and-restore' ) ?></th> |
|
30 | - <th><?php echo __( 'Status', 'xcloner-backup-and-restore' ) ?></th> |
|
31 | - <th class="no-sort"><?php echo __( 'Action', 'xcloner-backup-and-restore' ) ?></th> |
|
24 | + <th><?php echo __('ID', 'xcloner-backup-and-restore') ?></th> |
|
25 | + <th><?php echo __('Schedule Name', 'xcloner-backup-and-restore') ?></th> |
|
26 | + <th><?php echo __('Recurrence', 'xcloner-backup-and-restore') ?></th> |
|
27 | + <th class="hide-on-med-and-down"><?php echo __('Next Execution', 'xcloner-backup-and-restore') ?></th> |
|
28 | + <th><?php echo __('Remote Storage', 'xcloner-backup-and-restore') ?></th> |
|
29 | + <th class="hide-on-med-and-down"><?php echo __('Last Backup', 'xcloner-backup-and-restore') ?></th> |
|
30 | + <th><?php echo __('Status', 'xcloner-backup-and-restore') ?></th> |
|
31 | + <th class="no-sort"><?php echo __('Action', 'xcloner-backup-and-restore') ?></th> |
|
32 | 32 | </tr> |
33 | 33 | </thead> |
34 | 34 | <tfoot> |
35 | 35 | <tr> |
36 | - <th><?php echo __( 'ID', 'xcloner-backup-and-restore' ) ?></th> |
|
37 | - <th><?php echo __( 'Schedule Name', 'xcloner-backup-and-restore' ) ?></th> |
|
38 | - <th><?php echo __( 'Recurrence', 'xcloner-backup-and-restore' ) ?></th> |
|
39 | - <th class="hide-on-med-and-down"><?php echo __( 'Next Execution', 'xcloner-backup-and-restore' ) ?></th> |
|
40 | - <th><?php echo __( 'Remote Storage', 'xcloner-backup-and-restore' ) ?></th> |
|
41 | - <th class="hide-on-med-and-down"><?php echo __( 'Last Backup', 'xcloner-backup-and-restore' ) ?></th> |
|
42 | - <th><?php echo __( 'Status', 'xcloner-backup-and-restore' ) ?></th> |
|
43 | - <th><?php echo __( 'Action', 'xcloner-backup-and-restore' ) ?></th> |
|
36 | + <th><?php echo __('ID', 'xcloner-backup-and-restore') ?></th> |
|
37 | + <th><?php echo __('Schedule Name', 'xcloner-backup-and-restore') ?></th> |
|
38 | + <th><?php echo __('Recurrence', 'xcloner-backup-and-restore') ?></th> |
|
39 | + <th class="hide-on-med-and-down"><?php echo __('Next Execution', 'xcloner-backup-and-restore') ?></th> |
|
40 | + <th><?php echo __('Remote Storage', 'xcloner-backup-and-restore') ?></th> |
|
41 | + <th class="hide-on-med-and-down"><?php echo __('Last Backup', 'xcloner-backup-and-restore') ?></th> |
|
42 | + <th><?php echo __('Status', 'xcloner-backup-and-restore') ?></th> |
|
43 | + <th><?php echo __('Action', 'xcloner-backup-and-restore') ?></th> |
|
44 | 44 | </tr> |
45 | 45 | </tfoot> |
46 | 46 | <tbody> |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | |
51 | 51 | <div class="row"> |
52 | 52 | <div class="col s12 m6 offset-m6 teal lighten-1" id="server_time"> |
53 | - <h2><?php echo __( 'Current Server Time', 'xcloner-backup-and-restore' ) ?>: <span |
|
54 | - class="right"><?php echo current_time( 'mysql' ); ?></span></h2> |
|
53 | + <h2><?php echo __('Current Server Time', 'xcloner-backup-and-restore') ?>: <span |
|
54 | + class="right"><?php echo current_time('mysql'); ?></span></h2> |
|
55 | 55 | </div> |
56 | 56 | </div> |
57 | 57 | |
@@ -65,17 +65,17 @@ discard block |
||
65 | 65 | |
66 | 66 | <div class="row"> |
67 | 67 | <div class="col s12 m6"> |
68 | - <h4><?php echo __( 'Edit Schedule', 'xcloner-backup-and-restore' ) ?> #<span |
|
68 | + <h4><?php echo __('Edit Schedule', 'xcloner-backup-and-restore') ?> #<span |
|
69 | 69 | id="schedule_id"></span></h4> |
70 | 70 | </div> |
71 | 71 | |
72 | 72 | <div class="col s12 m6 right-align"> |
73 | 73 | <div class="switch"> |
74 | 74 | <label> |
75 | - <?php echo __( 'Off', 'xcloner-backup-and-restore' ) ?> |
|
75 | + <?php echo __('Off', 'xcloner-backup-and-restore') ?> |
|
76 | 76 | <input type="checkbox" id="status" name="status" value="1"> |
77 | 77 | <span class="lever"></span> |
78 | - <?php echo __( 'On', 'xcloner-backup-and-restore' ) ?> |
|
78 | + <?php echo __('On', 'xcloner-backup-and-restore') ?> |
|
79 | 79 | </label> |
80 | 80 | </div> |
81 | 81 | </div> |
@@ -85,10 +85,10 @@ discard block |
||
85 | 85 | |
86 | 86 | <ul class="nav-tab-wrapper content row"> |
87 | 87 | <li><a href="#scheduler_settings" |
88 | - class="nav-tab col s12 m6 nav-tab-active"><?php echo __( 'Scheduler Settings', 'xcloner-backup-and-restore' ) ?></a> |
|
88 | + class="nav-tab col s12 m6 nav-tab-active"><?php echo __('Scheduler Settings', 'xcloner-backup-and-restore') ?></a> |
|
89 | 89 | </li> |
90 | 90 | <li><a href="#advanced_scheduler_settings" |
91 | - class="nav-tab col s12 m6"><?php echo __( 'Advanced', 'xcloner-backup-and-restore' ) ?></a></li> |
|
91 | + class="nav-tab col s12 m6"><?php echo __('Advanced', 'xcloner-backup-and-restore') ?></a></li> |
|
92 | 92 | </ul> |
93 | 93 | |
94 | 94 | <div class="nav-tab-wrapper-content"> |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | <div class="row"> |
98 | 98 | <div class="input-field col s12 l6"> |
99 | 99 | <input placeholder="" name="schedule_name" id="schedule_name" type="text" required value=""> |
100 | - <label for="schedule_name"><?php echo __( 'Schedule Name', 'xcloner-backup-and-restore' ) ?></label> |
|
100 | + <label for="schedule_name"><?php echo __('Schedule Name', 'xcloner-backup-and-restore') ?></label> |
|
101 | 101 | </div> |
102 | 102 | <div class="input-field col s12 l6"> |
103 | 103 | <div class="switch"> |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | </div> |
113 | 113 | <!--<div class="input-field inline col s12 l6"> |
114 | 114 | <select id="backup_type" class="" name="backup_type" id="backup_type"> |
115 | - <option value=""><?php echo __( "Full Backup", "xcloner-backup-and-restore" ); ?></option> |
|
116 | - <option value="diff"><?php echo __( "Differential Backups", "xcloner-backup-and-restore" ); ?></option> |
|
117 | - <option value="full_diff"><?php echo __( "Full Backup + Differential Backups", "xcloner-backup-and-restore" ); ?></option> |
|
115 | + <option value=""><?php echo __("Full Backup", "xcloner-backup-and-restore"); ?></option> |
|
116 | + <option value="diff"><?php echo __("Differential Backups", "xcloner-backup-and-restore"); ?></option> |
|
117 | + <option value="full_diff"><?php echo __("Full Backup + Differential Backups", "xcloner-backup-and-restore"); ?></option> |
|
118 | 118 | </select> |
119 | - <label for="backup_type"><?php echo __( 'Scheduled Backup Type', 'xcloner-backup-and-restore' ) ?></label> |
|
119 | + <label for="backup_type"><?php echo __('Scheduled Backup Type', 'xcloner-backup-and-restore') ?></label> |
|
120 | 120 | </div>--> |
121 | 121 | </div> |
122 | 122 | |
@@ -125,18 +125,18 @@ discard block |
||
125 | 125 | <input placeholder="" name="schedule_start_date" id="schedule_start_date" type="datetime" |
126 | 126 | value=""> |
127 | 127 | <label for="schedule_start_date" |
128 | - class="active"><?php echo __( 'Schedule Start At', 'xcloner-backup-and-restore' ) ?> |
|
128 | + class="active"><?php echo __('Schedule Start At', 'xcloner-backup-and-restore') ?> |
|
129 | 129 | :</label> |
130 | 130 | </div> |
131 | 131 | |
132 | 132 | <div class="input-field col s12 l6"> |
133 | 133 | <select name="schedule_frequency" id="schedule_frequency" class="validate" required> |
134 | 134 | <option value="" disabled |
135 | - selected><?php echo __( 'Schedule Recurrence', 'xcloner-backup-and-restore' ) ?></option> |
|
135 | + selected><?php echo __('Schedule Recurrence', 'xcloner-backup-and-restore') ?></option> |
|
136 | 136 | <?php |
137 | 137 | $schedules = $xcloner_scheduler->get_available_intervals(); |
138 | 138 | |
139 | - foreach ( $schedules as $key => $schedule ) { |
|
139 | + foreach ($schedules as $key => $schedule) { |
|
140 | 140 | ?> |
141 | 141 | <option value="<?php echo $key ?>"><?php echo $schedule['display'] ?></option> |
142 | 142 | <?php |
@@ -146,17 +146,17 @@ discard block |
||
146 | 146 | </div> |
147 | 147 | </div> |
148 | 148 | |
149 | - <?php if ( sizeof( $available_storages ) ): ?> |
|
149 | + <?php if (sizeof($available_storages)): ?> |
|
150 | 150 | <div class="row"> |
151 | 151 | <div class="input-field col s12 l12"> |
152 | 152 | <select name="schedule_storage" id="schedule_storage" class="validate"> |
153 | 153 | <option value="" |
154 | - selected><?php echo __( 'none', 'xcloner-backup-and-restore' ) ?></option> |
|
155 | - <?php foreach ( $available_storages as $storage => $text ): ?> |
|
154 | + selected><?php echo __('none', 'xcloner-backup-and-restore') ?></option> |
|
155 | + <?php foreach ($available_storages as $storage => $text): ?> |
|
156 | 156 | <option value="<?php echo $storage ?>"><?php echo $text ?></option> |
157 | 157 | <?php endforeach ?> |
158 | 158 | </select> |
159 | - <label><?php echo __( 'Send To Remote Storage ', 'xcloner-backup-and-restore' ) ?></label> |
|
159 | + <label><?php echo __('Send To Remote Storage ', 'xcloner-backup-and-restore') ?></label> |
|
160 | 160 | </div> |
161 | 161 | </div> |
162 | 162 | <?php endif ?> |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | <div class="input-field col s12 l12"> |
166 | 166 | <input placeholder="" name="email_notification" id="email_notification" type="text" |
167 | 167 | value=""> |
168 | - <label for="email_notification"><?php echo __( 'Email Notification Address', 'xcloner-backup-and-restore' ) ?></label> |
|
168 | + <label for="email_notification"><?php echo __('Email Notification Address', 'xcloner-backup-and-restore') ?></label> |
|
169 | 169 | </div> |
170 | 170 | </div> |
171 | 171 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | <div class="input-field col s12 l12"> |
174 | 174 | <input placeholder="" name="diff_start_date" id="diff_start_date" type="text" |
175 | 175 | class="datepicker_max_today" value=""> |
176 | - <label for="diff_start_date"><?php echo __( 'Backup Only Files Modified/Created After', 'xcloner-backup-and-restore' ) ?></label> |
|
176 | + <label for="diff_start_date"><?php echo __('Backup Only Files Modified/Created After', 'xcloner-backup-and-restore') ?></label> |
|
177 | 177 | </div> |
178 | 178 | </div> |
179 | 179 | </div> |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | <div class="row"> |
183 | 183 | <div class="input-field col s12 l12"> |
184 | 184 | <input placeholder="" name="backup_name" id="backup_name" type="text" required value=""> |
185 | - <label for="backup_name"><?php echo __( 'Backup Name', 'xcloner-backup-and-restore' ) ?></label> |
|
185 | + <label for="backup_name"><?php echo __('Backup Name', 'xcloner-backup-and-restore') ?></label> |
|
186 | 186 | </div> |
187 | 187 | </div> |
188 | 188 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | <textarea id="table_params" name="table_params" class="materialize-textarea" |
192 | 192 | rows="15"></textarea> |
193 | 193 | <label for="table_params" |
194 | - class="active"><?php echo __( 'Included Database Data', 'xcloner-backup-and-restore' ) ?></label> |
|
194 | + class="active"><?php echo __('Included Database Data', 'xcloner-backup-and-restore') ?></label> |
|
195 | 195 | </div> |
196 | 196 | </div> |
197 | 197 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | <textarea id="excluded_files" name="excluded_files" class="materialize-textarea" |
201 | 201 | rows="15"></textarea> |
202 | 202 | <label for="excluded_files" |
203 | - class="active"><?php echo __( 'Excluded Files', 'xcloner-backup-and-restore' ) ?></label> |
|
203 | + class="active"><?php echo __('Excluded Files', 'xcloner-backup-and-restore') ?></label> |
|
204 | 204 | </div> |
205 | 205 | </div> |
206 | 206 | </div> |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | |
211 | 211 | <div class="input-field col s12 "> |
212 | 212 | <button class="right btn waves-effect waves-light" type="submit" |
213 | - name="action"><?php echo __( 'Save', 'xcloner-backup-and-restore' ) ?> |
|
213 | + name="action"><?php echo __('Save', 'xcloner-backup-and-restore') ?> |
|
214 | 214 | <i class="material-icons right">send</i> |
215 | 215 | </button> |
216 | 216 | </div> |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | $storage_selection = ""; |
8 | 8 | |
9 | 9 | if (isset($_GET['storage_selection']) and $_GET['storage_selection']) { |
10 | - $storage_selection = $xcloner_sanitization->sanitize_input_as_string($_GET['storage_selection']); |
|
10 | + $storage_selection = $xcloner_sanitization->sanitize_input_as_string($_GET['storage_selection']); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | //$backup_list = $xcloner_file_system->get_backup_archives_list($storage_selection); |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | <?php foreach ($available_storages as $storage => $text): ?> |
40 | 40 | <option value="<?php echo $storage ?>"<?php if ($storage == $storage_selection) |
41 | - echo "selected" ?>><?php echo $text ?></option> |
|
41 | + echo "selected" ?>><?php echo $text ?></option> |
|
42 | 42 | <?php endforeach ?> |
43 | 43 | </select> |
44 | 44 | <?php endif ?> |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | |
66 | 66 | |
67 | 67 | <?php |
68 | - /*$i = 0; |
|
68 | + /*$i = 0; |
|
69 | 69 | foreach ($backup_list as $file_info):?> |
70 | 70 | <?php |
71 | 71 | if ($storage_selection == "gdrive") { |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | <div class="row"> |
303 | 303 | <div class="col s12 label"> |
304 | 304 | <label><?php echo sprintf(__('Send %s to remote storage', 'xcloner-backup-and-restore'), |
305 | - "<span class='backup_name'></span>") ?></label> |
|
305 | + "<span class='backup_name'></span>") ?></label> |
|
306 | 306 | </div> |
307 | 307 | <div class="input-field col s8 m10"> |
308 | 308 | <select name="transfer_storage" id="transfer_storage" class="validate" required> |
@@ -261,7 +261,7 @@ |
||
261 | 261 | <input type="text" |
262 | 262 | name="decryption_key" |
263 | 263 | id="decryption_key" |
264 | - placeholder="<?=__('Decryption Key', 'xcloner-backup-and-restore' )?>" /> |
|
264 | + placeholder="<?=__('Decryption Key', 'xcloner-backup-and-restore')?>" /> |
|
265 | 265 | </p> |
266 | 266 | <p class="center-align"> |
267 | 267 | <a class="waves-effect waves-light btn"><?php echo __("START DECRYPTION", 'xcloner-backup-and-restore') ?></a> |
@@ -31,10 +31,13 @@ |
||
31 | 31 | <?php if ($storage_selection): ?> |
32 | 32 | <option value="" |
33 | 33 | selected><?php echo __('Change To Local Storage...', 'xcloner-backup-and-restore') ?></option> |
34 | - <?php else: ?> |
|
34 | + <?php else { |
|
35 | + : ?> |
|
35 | 36 | <option value="" |
36 | 37 | selected><?php echo __('Change To Remote Storage...', 'xcloner-backup-and-restore') ?></option> |
37 | - <?php endif; ?> |
|
38 | + <?php endif; |
|
39 | +} |
|
40 | +?> |
|
38 | 41 | |
39 | 42 | <?php foreach ($available_storages as $storage => $text): ?> |
40 | 43 | <option value="<?php echo $storage ?>"<?php if ($storage == $storage_selection) |
@@ -8,25 +8,25 @@ discard block |
||
8 | 8 | |
9 | 9 | <script>var xcloner_backup = new Xcloner_Backup();</script> |
10 | 10 | |
11 | -<h1><?= esc_html( get_admin_page_title() ); ?></h1> |
|
11 | +<h1><?= esc_html(get_admin_page_title()); ?></h1> |
|
12 | 12 | |
13 | 13 | <ul class="nav-tab-wrapper content row"> |
14 | 14 | <li><a href="#backup_options" |
15 | - class="nav-tab col s12 m3 l2 nav-tab-active"><?php echo $tab . ". " . __( 'Backup Options', 'xcloner-backup-and-restore' ) ?></a> |
|
15 | + class="nav-tab col s12 m3 l2 nav-tab-active"><?php echo $tab.". ".__('Backup Options', 'xcloner-backup-and-restore') ?></a> |
|
16 | 16 | </li> |
17 | - <?php if ( $xcloner_settings->get_enable_mysql_backup() ): ?> |
|
17 | + <?php if ($xcloner_settings->get_enable_mysql_backup()): ?> |
|
18 | 18 | <li><a href="#database_options" |
19 | - class="nav-tab col s12 m3 l2 "><?php echo ++ $tab . ". " . __( 'Database Options', 'xcloner-backup-and-restore' ) ?></a> |
|
19 | + class="nav-tab col s12 m3 l2 "><?php echo ++$tab.". ".__('Database Options', 'xcloner-backup-and-restore') ?></a> |
|
20 | 20 | </li> |
21 | 21 | <?php endif ?> |
22 | 22 | <li><a href="#files_options" |
23 | - class="nav-tab col s12 m3 l2 "><?php echo ++ $tab . ". " . __( 'Files Options', 'xcloner-backup-and-restore' ) ?></a> |
|
23 | + class="nav-tab col s12 m3 l2 "><?php echo ++$tab.". ".__('Files Options', 'xcloner-backup-and-restore') ?></a> |
|
24 | 24 | </li> |
25 | 25 | <li><a href="#generate_backup" |
26 | - class="nav-tab col s12 m3 l2 "><?php echo ++ $tab . ". " . __( 'Generate Backup', 'xcloner-backup-and-restore' ) ?></a> |
|
26 | + class="nav-tab col s12 m3 l2 "><?php echo ++$tab.". ".__('Generate Backup', 'xcloner-backup-and-restore') ?></a> |
|
27 | 27 | </li> |
28 | 28 | <li><a href="#schedule_backup" |
29 | - class="nav-tab col s12 m3 l2 "><?php echo ++ $tab . ". " . __( 'Schedule Backup', 'xcloner-backup-and-restore' ) ?></a> |
|
29 | + class="nav-tab col s12 m3 l2 "><?php echo ++$tab.". ".__('Schedule Backup', 'xcloner-backup-and-restore') ?></a> |
|
30 | 30 | </li> |
31 | 31 | </ul> |
32 | 32 | |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | <i class="material-icons prefix">input</i> |
40 | 40 | <input name="backup_name" id="backup_name" type="text" |
41 | 41 | value=<?php echo $xcloner_settings->get_default_backup_name() ?>> |
42 | - <label for="backup_name"><?php echo __( 'Backup Name', 'xcloner-backup-and-restore' ) ?></label> |
|
42 | + <label for="backup_name"><?php echo __('Backup Name', 'xcloner-backup-and-restore') ?></label> |
|
43 | 43 | </div> |
44 | 44 | <div class="hide-on-small-only m2"> |
45 | 45 | <a class="btn-floating tooltipped btn-small" data-position="right" data-delay="50" |
46 | - data-tooltip="<?php echo __( 'The default backup name, supported tags [time], [hostname], [domain]', 'xcloner-backup-and-restore' ) ?>" |
|
46 | + data-tooltip="<?php echo __('The default backup name, supported tags [time], [hostname], [domain]', 'xcloner-backup-and-restore') ?>" |
|
47 | 47 | data-tooltip-id=""><i class="material-icons">help_outline</i></a> |
48 | 48 | </div> |
49 | 49 | </div> |
@@ -52,12 +52,12 @@ discard block |
||
52 | 52 | <div class="input-field inline col s12 m10 l6"> |
53 | 53 | <i class="material-icons prefix">email</i> |
54 | 54 | <input name="email_notification" id="email_notification" type="text" |
55 | - value="<?php echo get_option( 'admin_email' ); ?>"> |
|
56 | - <label for="email_notification"><?php echo __( 'Send Email Notification To', 'xcloner-backup-and-restore' ) ?></label> |
|
55 | + value="<?php echo get_option('admin_email'); ?>"> |
|
56 | + <label for="email_notification"><?php echo __('Send Email Notification To', 'xcloner-backup-and-restore') ?></label> |
|
57 | 57 | </div> |
58 | 58 | <div class="hide-on-small-only m2"> |
59 | 59 | <a class="btn-floating tooltipped btn-small" data-position="right" data-delay="50" |
60 | - data-tooltip="<?php echo __( 'If left blank, no notification will be sent', 'xcloner-backup-and-restore' ) ?>" |
|
60 | + data-tooltip="<?php echo __('If left blank, no notification will be sent', 'xcloner-backup-and-restore') ?>" |
|
61 | 61 | data-tooltip-id=""><i class="material-icons">help_outline</i></a> |
62 | 62 | </div> |
63 | 63 | </div> |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | <i class="material-icons prefix">access_time</i> |
68 | 68 | <input type="datetime-local" id="diff_start_date" class="datepicker_max_today" |
69 | 69 | name="diff_start_date"> |
70 | - <label for="diff_start_date"><?php echo __( 'Backup Only Files Modified/Created After', 'xcloner-backup-and-restore' ) ?></label> |
|
70 | + <label for="diff_start_date"><?php echo __('Backup Only Files Modified/Created After', 'xcloner-backup-and-restore') ?></label> |
|
71 | 71 | </div> |
72 | 72 | <div class="hide-on-small-only m2"> |
73 | 73 | <a class="btn-floating tooltipped btn-small" data-html="true" data-position="center" data-delay="50" |
74 | - data-tooltip="<?php echo __( "This option allows you to create a differential backup that will include only <br> changed files since the set date, leave blank to include all files", "xcloner-backup-and-restore" ) ?>"><i |
|
74 | + data-tooltip="<?php echo __("This option allows you to create a differential backup that will include only <br> changed files since the set date, leave blank to include all files", "xcloner-backup-and-restore") ?>"><i |
|
75 | 75 | class="material-icons">help_outline</i></a> |
76 | 76 | </div> |
77 | 77 | </div> |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | <div class="row"> |
80 | 80 | <div class="input-field col s6 m5 l4"> |
81 | 81 | <i class="material-icons prefix">enhanced_encryption</i> |
82 | - <label for="backup_comments"><?php echo __( 'Encrypt Backup', 'xcloner-backup-and-restore' ) ?></label> |
|
82 | + <label for="backup_comments"><?php echo __('Encrypt Backup', 'xcloner-backup-and-restore') ?></label> |
|
83 | 83 | |
84 | 84 | </div> |
85 | 85 | <div class="input-field col s6 m5 l2"> |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | <div class="hide-on-small-only s12 m2"> |
97 | 97 | <a class="btn-floating tooltipped btn-small" data-position="right" data-delay="50" |
98 | - data-tooltip="<?php echo __( 'Enable this option if you want to encrypt the final backup', 'xcloner-backup-and-restore' ) ?>" |
|
98 | + data-tooltip="<?php echo __('Enable this option if you want to encrypt the final backup', 'xcloner-backup-and-restore') ?>" |
|
99 | 99 | data-tooltip-id=""><i class="material-icons">help_outline</i></a> |
100 | 100 | </div> |
101 | 101 | </div> |
@@ -104,11 +104,11 @@ discard block |
||
104 | 104 | <div class="input-field col s12 m10 l6"> |
105 | 105 | <i class="material-icons prefix">input</i> |
106 | 106 | <textarea name="backup_comments" id="backup_comments" class="materialize-textarea"></textarea> |
107 | - <label for="backup_comments"><?php echo __( 'Backup Comments', 'xcloner-backup-and-restore' ) ?></label> |
|
107 | + <label for="backup_comments"><?php echo __('Backup Comments', 'xcloner-backup-and-restore') ?></label> |
|
108 | 108 | </div> |
109 | 109 | <div class="hide-on-small-only m2"> |
110 | 110 | <a class="btn-floating tooltipped btn-small" data-position="right" data-delay="50" |
111 | - data-tooltip="<?php echo __( 'Some default backup comments that will be stored inside the backup archive', 'xcloner-backup-and-restore' ) ?>" |
|
111 | + data-tooltip="<?php echo __('Some default backup comments that will be stored inside the backup archive', 'xcloner-backup-and-restore') ?>" |
|
112 | 112 | data-tooltip-id=""><i class="material-icons">help_outline</i></a> |
113 | 113 | </div> |
114 | 114 | </div> |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | </div> |
122 | 122 | </div> |
123 | 123 | |
124 | - <?php if ( $xcloner_settings->get_enable_mysql_backup() ): ?> |
|
124 | + <?php if ($xcloner_settings->get_enable_mysql_backup()): ?> |
|
125 | 125 | <div id="database_options" class="tab-content"> |
126 | - <h2><?php echo __( 'Select database data to include in the backup', 'xcloner-backup-and-restore' ) ?>: |
|
126 | + <h2><?php echo __('Select database data to include in the backup', 'xcloner-backup-and-restore') ?>: |
|
127 | 127 | <a class="btn-floating tooltipped btn-small" data-position="right" data-delay="50" |
128 | - data-tooltip="<?php echo __( 'Enable the \'Backup only WP tables\' setting if you don\'t want to show all other databases and tables not related to this Wordpress install', 'xcloner-backup-and-restore' ); ?>" |
|
128 | + data-tooltip="<?php echo __('Enable the \'Backup only WP tables\' setting if you don\'t want to show all other databases and tables not related to this Wordpress install', 'xcloner-backup-and-restore'); ?>" |
|
129 | 129 | data-tooltip-id=""><i class="material-icons">help_outline</i></a> |
130 | 130 | </h2> |
131 | 131 | |
@@ -147,10 +147,10 @@ discard block |
||
147 | 147 | <?php endif ?> |
148 | 148 | |
149 | 149 | <div id="files_options" class="tab-content"> |
150 | - <h2><?php echo __( 'Select from below the files/folders you want to exclude from your Backup Archive', 'xcloner-backup-and-restore' ) ?> |
|
150 | + <h2><?php echo __('Select from below the files/folders you want to exclude from your Backup Archive', 'xcloner-backup-and-restore') ?> |
|
151 | 151 | : |
152 | 152 | <a class="btn-floating tooltipped btn-small" data-position="bottom" data-delay="50" data-html="true" |
153 | - data-tooltip="<?php echo __( 'You can navigate below through all your site structure(Backup Start Location) to exclude any file/folder you need by clicking the checkbox near it. <br />If the checkobx is disabled, then it matches a Regex Exclude File option and it can\'t be unchecked', 'xcloner-backup-and-restore' ); ?>" |
|
153 | + data-tooltip="<?php echo __('You can navigate below through all your site structure(Backup Start Location) to exclude any file/folder you need by clicking the checkbox near it. <br />If the checkobx is disabled, then it matches a Regex Exclude File option and it can\'t be unchecked', 'xcloner-backup-and-restore'); ?>" |
|
154 | 154 | data-tooltip-id=""><i class="material-icons">help_outline</i></a> |
155 | 155 | </h2> |
156 | 156 | |
@@ -185,9 +185,9 @@ discard block |
||
185 | 185 | <ul class="backup-status collapsible" data-collapsible="accordion"> |
186 | 186 | <li class="file-system"> |
187 | 187 | <div class="collapsible-header"> |
188 | - <i class="material-icons">folder</i><?php echo __( 'Scanning The File System...', 'xcloner-backup-and-restore' ) ?> |
|
188 | + <i class="material-icons">folder</i><?php echo __('Scanning The File System...', 'xcloner-backup-and-restore') ?> |
|
189 | 189 | |
190 | - <p class="right"><?php echo sprintf( __( 'Found %s files (%s)', 'xcloner-backup-and-restore' ), '<span class="file-counter">0</span>', '<span class="file-size-total">0</span>MB' ) ?></p> |
|
190 | + <p class="right"><?php echo sprintf(__('Found %s files (%s)', 'xcloner-backup-and-restore'), '<span class="file-counter">0</span>', '<span class="file-size-total">0</span>MB') ?></p> |
|
191 | 191 | |
192 | 192 | <div> |
193 | 193 | <p class="right"><span class="last-logged-file"></span></p> |
@@ -199,12 +199,12 @@ discard block |
||
199 | 199 | </div> |
200 | 200 | <div class="collapsible-body status-body"></div> |
201 | 201 | </li> |
202 | - <?php if ( $xcloner_settings->get_enable_mysql_backup() ): ?> |
|
202 | + <?php if ($xcloner_settings->get_enable_mysql_backup()): ?> |
|
203 | 203 | <li class="database-backup"> |
204 | 204 | <div class="collapsible-header"> |
205 | - <i class="material-icons">storage</i><?php echo __( 'Generating the Mysql Backup...', 'xcloner-backup-and-restore' ) ?> |
|
205 | + <i class="material-icons">storage</i><?php echo __('Generating the Mysql Backup...', 'xcloner-backup-and-restore') ?> |
|
206 | 206 | |
207 | - <p class="right"><?php echo sprintf( __( 'Found %s tables in %s databases (%s)', 'xcloner-backup-and-restore' ), '<span class="table-counter">0</span>', '<span class="database-counter">0</span>', '<span data-processed="0" class="total-records">0</span> records', 'xcloner-backup-and-restore' ) ?></p> |
|
207 | + <p class="right"><?php echo sprintf(__('Found %s tables in %s databases (%s)', 'xcloner-backup-and-restore'), '<span class="table-counter">0</span>', '<span class="database-counter">0</span>', '<span data-processed="0" class="total-records">0</span> records', 'xcloner-backup-and-restore') ?></p> |
|
208 | 208 | |
209 | 209 | <div> |
210 | 210 | <p class="right"><span class="last-logged-table"></span></p> |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | <?php endif ?> |
229 | 229 | <li class="files-backup"> |
230 | 230 | <div class="collapsible-header"> |
231 | - <i class="material-icons">archive</i><?php echo __( 'Adding Files to Archive...', 'xcloner-backup-and-restore' ) ?> |
|
231 | + <i class="material-icons">archive</i><?php echo __('Adding Files to Archive...', 'xcloner-backup-and-restore') ?> |
|
232 | 232 | |
233 | - <p class="right"><?php echo sprintf( __( 'Adding %s files (%s)', 'xcloner-backup-and-restore' ), '<span class="file-counter">0</span>', '<span data-processed="0" class="file-size-total">0</span>MB' ) ?></p> |
|
233 | + <p class="right"><?php echo sprintf(__('Adding %s files (%s)', 'xcloner-backup-and-restore'), '<span class="file-counter">0</span>', '<span data-processed="0" class="file-size-total">0</span>MB') ?></p> |
|
234 | 234 | |
235 | 235 | <div> |
236 | 236 | <p class="right"><span class="last-logged-file"></span></p> |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | <div class="collapsible-body status-body"> |
244 | 244 | <div class="row"> |
245 | 245 | <div class="col l3 s12"> |
246 | - <h2><?php echo __( "Backup Parts", 'xcloner-backup-and-restore' ) ?>: </h2> |
|
246 | + <h2><?php echo __("Backup Parts", 'xcloner-backup-and-restore') ?>: </h2> |
|
247 | 247 | </div> |
248 | 248 | <div class="col l9 s12"> |
249 | 249 | <ul class="backup-name"></ul> |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | </li> |
254 | 254 | <li class="backup-encryption"> |
255 | 255 | <div class="collapsible-header"> |
256 | - <i class="material-icons">enhanced_encryption</i><?php echo __( 'Encrypting Backup Data...', 'xcloner-backup-and-restore' ) ?> |
|
256 | + <i class="material-icons">enhanced_encryption</i><?php echo __('Encrypting Backup Data...', 'xcloner-backup-and-restore') ?> |
|
257 | 257 | |
258 | 258 | <p class="right"><span class="status"></span></p> |
259 | 259 | |
@@ -268,19 +268,19 @@ discard block |
||
268 | 268 | </li> |
269 | 269 | <li class="backup-done"> |
270 | 270 | <div class="collapsible-header"> |
271 | - <i class="material-icons">done</i><?php echo __( 'Backup Done', 'xcloner-backup-and-restore' ) ?> |
|
271 | + <i class="material-icons">done</i><?php echo __('Backup Done', 'xcloner-backup-and-restore') ?> |
|
272 | 272 | |
273 | 273 | <p class="right"> |
274 | - <?php if ( sizeof( $available_storages ) ): ?> |
|
274 | + <?php if (sizeof($available_storages)): ?> |
|
275 | 275 | <a href="#" class="cloud-upload" |
276 | - title="<?php echo __( "Send Backup To Remote Storage", 'xcloner-backup-and-restore' ) ?>"><i |
|
276 | + title="<?php echo __("Send Backup To Remote Storage", 'xcloner-backup-and-restore') ?>"><i |
|
277 | 277 | class="material-icons">cloud_upload</i></a> |
278 | 278 | <?php endif ?> |
279 | 279 | <a href="#" class="download" |
280 | - title="<?php echo __( "Download Backup", 'xcloner-backup-and-restore' ) ?>"><i |
|
280 | + title="<?php echo __("Download Backup", 'xcloner-backup-and-restore') ?>"><i |
|
281 | 281 | class="material-icons">file_download</i></a> |
282 | 282 | <a href="#" class="list-backup-content" |
283 | - title="<?php echo __( "List Backup Content", 'xcloner-backup-and-restore' ) ?>"><i |
|
283 | + title="<?php echo __("List Backup Content", 'xcloner-backup-and-restore') ?>"><i |
|
284 | 284 | class="material-icons">folder_open</i></a> |
285 | 285 | </p> |
286 | 286 | |
@@ -291,8 +291,8 @@ discard block |
||
291 | 291 | </div> |
292 | 292 | <div class="collapsible-body center-align"> |
293 | 293 | <div class="row"> |
294 | - <h5><?php echo __( "Thank you for using XCloner.", 'xcloner-backup-and-restore' ) ?></h5> |
|
295 | - <h6><?php echo sprintf( __( "We would love to hear about your experience in the %s.", 'xcloner-backup-and-restore' ), '<a href="https://wordpress.org/support/plugin/xcloner-backup-and-restore/reviews/" target="_blank">Wordpress XCloner Reviews Section</a>' ) ?></h6> |
|
294 | + <h5><?php echo __("Thank you for using XCloner.", 'xcloner-backup-and-restore') ?></h5> |
|
295 | + <h6><?php echo sprintf(__("We would love to hear about your experience in the %s.", 'xcloner-backup-and-restore'), '<a href="https://wordpress.org/support/plugin/xcloner-backup-and-restore/reviews/" target="_blank">Wordpress XCloner Reviews Section</a>') ?></h6> |
|
296 | 296 | <a class="twitter-follow-button" href="https://twitter.com/thinkovi" |
297 | 297 | data-show-count="false">Follow @thinkovi</a> |
298 | 298 | <script src="//platform.twitter.com/widgets.js" async="" charset="utf-8"></script> |
@@ -313,9 +313,9 @@ discard block |
||
313 | 313 | |
314 | 314 | <div class="row"> |
315 | 315 | <div id="schedule_backup_success" class="col s12 l6 updated settings-error notice is-dismissible"> |
316 | - <p><strong><?php echo __( 'Schedule Saved', 'xcloner-backup-and-restore' ) ?></strong></p> |
|
316 | + <p><strong><?php echo __('Schedule Saved', 'xcloner-backup-and-restore') ?></strong></p> |
|
317 | 317 | <button type="button" class="notice-dismiss"><span |
318 | - class="screen-reader-text"><?php echo __( '(Dismiss this notice.', 'xcloner-backup-and-restore' ) ?></span> |
|
318 | + class="screen-reader-text"><?php echo __('(Dismiss this notice.', 'xcloner-backup-and-restore') ?></span> |
|
319 | 319 | </button> |
320 | 320 | </div> |
321 | 321 | </div> |
@@ -323,18 +323,18 @@ discard block |
||
323 | 323 | <div class="row"> |
324 | 324 | <div class="input-field inline col s12 l7"> |
325 | 325 | <input type="text" id="schedule_name" class="" name="schedule_name" required> |
326 | - <label for="schedule_name"><?php echo __( 'Schedule Name', 'xcloner-backup-and-restore' ) ?></label> |
|
326 | + <label for="schedule_name"><?php echo __('Schedule Name', 'xcloner-backup-and-restore') ?></label> |
|
327 | 327 | </div> |
328 | 328 | </div> |
329 | 329 | |
330 | 330 | <div class="row"> |
331 | 331 | <div class="input-field inline col s12 m8 l4"> |
332 | 332 | <input type="datetime-local" id="datepicker" class="datepicker" name="schedule_start_date"> |
333 | - <label for="datepicker"><?php echo __( 'Schedule Backup To Start On:', 'xcloner-backup-and-restore' ) ?></label> |
|
333 | + <label for="datepicker"><?php echo __('Schedule Backup To Start On:', 'xcloner-backup-and-restore') ?></label> |
|
334 | 334 | </div> |
335 | 335 | <div class="input-field inline col s12 m4 l3"> |
336 | 336 | <input id="timepicker_ampm_dark" class="timepicker" type="time" name="schedule_start_time"> |
337 | - <label for="timepicker_ampm_dark"><?php echo __( 'At:', 'xcloner-backup-and-restore' ) ?></label> |
|
337 | + <label for="timepicker_ampm_dark"><?php echo __('At:', 'xcloner-backup-and-restore') ?></label> |
|
338 | 338 | </div> |
339 | 339 | </div> |
340 | 340 | |
@@ -342,17 +342,17 @@ discard block |
||
342 | 342 | <div class="row"> |
343 | 343 | <div class="input-field inline col s10 m11 l7"> |
344 | 344 | <select id="backup_type" class="" name="backup_type"> |
345 | - <option value=""><?php echo __( "Full Backup", "xcloner-backup-and-restore" ); ?></option> |
|
346 | - <option value="diff"><?php echo __( "Differential Backups", "xcloner-backup-and-restore" ); ?></option> |
|
347 | - <option value="full_diff"><?php echo __( "Full Backup + Differential Backups", "xcloner-backup-and-restore" ); ?></option> |
|
345 | + <option value=""><?php echo __("Full Backup", "xcloner-backup-and-restore"); ?></option> |
|
346 | + <option value="diff"><?php echo __("Differential Backups", "xcloner-backup-and-restore"); ?></option> |
|
347 | + <option value="full_diff"><?php echo __("Full Backup + Differential Backups", "xcloner-backup-and-restore"); ?></option> |
|
348 | 348 | </select> |
349 | - <label for="backup_type"><?php echo __( 'Scheduled Backup Type', 'xcloner-backup-and-restore' ) ?></label> |
|
349 | + <label for="backup_type"><?php echo __('Scheduled Backup Type', 'xcloner-backup-and-restore') ?></label> |
|
350 | 350 | </div> |
351 | 351 | <div class="col s2 m1"> |
352 | 352 | <a class="btn-floating tooltipped btn-small" data-html="true" data-position="center" data-delay="50" data-tooltip="<ul style='max-width:760px; text-align:left;'> |
353 | - <li><?php echo __( "Full Backup = it will generate a full backup of all included files each time schedule runs", "xcloner-backup-and-restore" ); ?></li> |
|
354 | - <li><?php echo __( "Differentials Backups = backups will include only changed files since the schedule started to run", "xcloner-backup-and-restore" ); ?></li> |
|
355 | - <li><?php echo __( "Full Backup + Differential Backups = the first time schedule runs, it will create a full backup and all next scheduled backups will include only files created/modified since that last full backup; a full backup is recreated when the number of changed files is bigger than the 'Differetial Backups Max Days' XCloner option.", "xcloner-backup-and-restore" ); ?></li> |
|
353 | + <li><?php echo __("Full Backup = it will generate a full backup of all included files each time schedule runs", "xcloner-backup-and-restore"); ?></li> |
|
354 | + <li><?php echo __("Differentials Backups = backups will include only changed files since the schedule started to run", "xcloner-backup-and-restore"); ?></li> |
|
355 | + <li><?php echo __("Full Backup + Differential Backups = the first time schedule runs, it will create a full backup and all next scheduled backups will include only files created/modified since that last full backup; a full backup is recreated when the number of changed files is bigger than the 'Differetial Backups Max Days' XCloner option.", "xcloner-backup-and-restore"); ?></li> |
|
356 | 356 | </ul>"><i class="material-icons">help_outline</i></a> |
357 | 357 | </div> |
358 | 358 | </div> |
@@ -361,38 +361,38 @@ discard block |
||
361 | 361 | <div class="input-field col s12 l7"> |
362 | 362 | <select name="schedule_frequency" id="schedule_frequency" class="validate" required> |
363 | 363 | <option value="" disabled |
364 | - selected><?php echo __( 'please select', 'xcloner-backup-and-restore' ) ?></option> |
|
364 | + selected><?php echo __('please select', 'xcloner-backup-and-restore') ?></option> |
|
365 | 365 | <?php |
366 | 366 | $schedules = $xcloner_scheduler->get_available_intervals(); |
367 | 367 | |
368 | - foreach ( $schedules as $key => $schedule ) { |
|
368 | + foreach ($schedules as $key => $schedule) { |
|
369 | 369 | ?> |
370 | 370 | <option value="<?php echo $key ?>"><?php echo $schedule['display'] ?></option> |
371 | 371 | <?php |
372 | 372 | } |
373 | 373 | ?> |
374 | 374 | </select> |
375 | - <label><?php echo __( 'Schedule Frequency', 'xcloner-backup-and-restore' ) ?></label> |
|
375 | + <label><?php echo __('Schedule Frequency', 'xcloner-backup-and-restore') ?></label> |
|
376 | 376 | </div> |
377 | 377 | </div> |
378 | 378 | |
379 | - <?php if ( sizeof( $available_storages ) ): ?> |
|
379 | + <?php if (sizeof($available_storages)): ?> |
|
380 | 380 | <div class="row"> |
381 | 381 | <div class="input-field col s12 m12 l7"> |
382 | 382 | <select name="schedule_storage" id="schedule_storage" class="validate"> |
383 | - <option value="" selected><?php echo __( 'none', 'xcloner-backup-and-restore' ) ?></option> |
|
384 | - <?php foreach ( $available_storages as $storage => $text ): ?> |
|
383 | + <option value="" selected><?php echo __('none', 'xcloner-backup-and-restore') ?></option> |
|
384 | + <?php foreach ($available_storages as $storage => $text): ?> |
|
385 | 385 | <option value="<?php echo $storage ?>"><?php echo $text ?></option> |
386 | 386 | <?php endforeach ?> |
387 | 387 | </select> |
388 | - <label><?php echo __( 'Send To Remote Storage', 'xcloner-backup-and-restore' ) ?></label> |
|
388 | + <label><?php echo __('Send To Remote Storage', 'xcloner-backup-and-restore') ?></label> |
|
389 | 389 | </div> |
390 | 390 | </div> |
391 | 391 | <?php endif ?> |
392 | 392 | <div class="row"> |
393 | 393 | <div class="col s12 l7"> |
394 | 394 | <button class="right btn waves-effect waves-light submit_schedule" type="submit" |
395 | - name="action"><?php echo __( "Submit", 'xcloner-backup-and-restore' ) ?> |
|
395 | + name="action"><?php echo __("Submit", 'xcloner-backup-and-restore') ?> |
|
396 | 396 | <i class="material-icons right">send</i> |
397 | 397 | </button> |
398 | 398 | </div> |
@@ -407,19 +407,19 @@ discard block |
||
407 | 407 | class="material-icons medium right">help</i></a> |
408 | 408 | <div class="modal-content"> |
409 | 409 | <h4 class="title_line"><span class="title"></span></h4> |
410 | - <!--<h5 class="title_line"><?php echo __( 'Message' ) ?>: <span class="msg.old"></span></h5>--> |
|
411 | - <h5><?php echo __( 'Response Code', 'xcloner-backup-and-restore' ) ?>: <span class="status"></span></h5> |
|
410 | + <!--<h5 class="title_line"><?php echo __('Message') ?>: <span class="msg.old"></span></h5>--> |
|
411 | + <h5><?php echo __('Response Code', 'xcloner-backup-and-restore') ?>: <span class="status"></span></h5> |
|
412 | 412 | <textarea class="body" rows="5"></textarea> |
413 | 413 | </div> |
414 | 414 | <div class="modal-footer"> |
415 | - <a class=" modal-action modal-close waves-effect waves-green btn-flat red darken-2"><?php echo __( 'Close', 'xcloner-backup-and-restore' ) ?></a> |
|
415 | + <a class=" modal-action modal-close waves-effect waves-green btn-flat red darken-2"><?php echo __('Close', 'xcloner-backup-and-restore') ?></a> |
|
416 | 416 | </div> |
417 | 417 | </div> |
418 | 418 | |
419 | 419 | <!-- List Backup Content Modal--> |
420 | 420 | <div id="backup_cotent_modal" class="modal"> |
421 | 421 | <div class="modal-content"> |
422 | - <h4><?php echo sprintf( __( "Listing Backup Content ", 'xcloner-backup-and-restore' ), "" ) ?></h4> |
|
422 | + <h4><?php echo sprintf(__("Listing Backup Content ", 'xcloner-backup-and-restore'), "") ?></h4> |
|
423 | 423 | <h5 class="backup-name"></h5> |
424 | 424 | |
425 | 425 | <div class="progress"> |
@@ -434,18 +434,18 @@ discard block |
||
434 | 434 | <form method="POST" class="remote-storage-form"> |
435 | 435 | <input type="hidden" name="file" class="backup_name"> |
436 | 436 | <div class="modal-content"> |
437 | - <h4><?php echo __( "Remote Storage Transfer", 'xcloner-backup-and-restore' ) ?></h4> |
|
437 | + <h4><?php echo __("Remote Storage Transfer", 'xcloner-backup-and-restore') ?></h4> |
|
438 | 438 | <p> |
439 | - <?php if ( sizeof( $available_storages ) ): ?> |
|
439 | + <?php if (sizeof($available_storages)): ?> |
|
440 | 440 | <div class="row"> |
441 | 441 | <div class="col s12 label"> |
442 | - <label><?php echo __( sprintf( 'Send %s to remote storage', "<span class='backup_name'></span>" ), 'xcloner-backup-and-restore' ) ?></label> |
|
442 | + <label><?php echo __(sprintf('Send %s to remote storage', "<span class='backup_name'></span>"), 'xcloner-backup-and-restore') ?></label> |
|
443 | 443 | </div> |
444 | 444 | <div class="input-field col s8 m10"> |
445 | 445 | <select name="transfer_storage" id="transfer_storage" class="validate" required> |
446 | 446 | <option value="" |
447 | - selected><?php echo __( 'please select...', 'xcloner-backup-and-restore' ) ?></option> |
|
448 | - <?php foreach ( $available_storages as $storage => $text ): ?> |
|
447 | + selected><?php echo __('please select...', 'xcloner-backup-and-restore') ?></option> |
|
448 | + <?php foreach ($available_storages as $storage => $text): ?> |
|
449 | 449 | <option value="<?php echo $storage ?>"><?php echo $text ?></option> |
450 | 450 | <?php endforeach ?> |
451 | 451 | </select> |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | </div> |
458 | 458 | </div> |
459 | 459 | <div class="row status"> |
460 | - <?php echo __( "Uploading backup to the selected remote storage...", 'xcloner-backup-and-restore' ) ?> |
|
460 | + <?php echo __("Uploading backup to the selected remote storage...", 'xcloner-backup-and-restore') ?> |
|
461 | 461 | <span class="status-text"></span> |
462 | 462 | <div class="progress"> |
463 | 463 | <div class="indeterminate"></div> |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | } |
542 | 542 | }); |
543 | 543 | |
544 | - <?php if($xcloner_settings->get_enable_mysql_backup()):?> |
|
544 | + <?php if ($xcloner_settings->get_enable_mysql_backup()):?> |
|
545 | 545 | jQuery('#jstree_database_container').jstree({ |
546 | 546 | 'core': { |
547 | 547 | 'check_callback': true, |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | if ( version_compare( phpversion(), Xcloner_Activator::xcloner_minimum_version, '<' ) ) { |
65 | 65 | wp_die( '<p>' . sprintf( __( "XCloner requires minimum PHP version %s in order to run correctly. We have detected your version as %s" ), Xcloner_Activator::xcloner_minimum_version, phpversion() ) . '</p>', __( "XCloner Activation Error" ), array( 'response' => 500, |
66 | - 'back_link' => true |
|
66 | + 'back_link' => true |
|
67 | 67 | ) ); |
68 | 68 | } |
69 | 69 | |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | update_option( 'xcloner_regex_exclude', "(wp-content\/updraft|wp-content\/uploads\/wp_all_backup)(.*)$" . PHP_EOL . "(.*)\.(svn|git)(.*)$" . PHP_EOL . "wp-content\/cache(.*)$" . PHP_EOL . "(.*)error_log$" ); |
153 | 153 | } |
154 | 154 | |
155 | - if ( ! get_option( 'xcloner_regex_exclude' ) ) { |
|
156 | - update_option( 'xcloner_regex_exclude', "(wp-content\/updraft|wp-content\/uploads\/wp_all_backup)(.*)$" . PHP_EOL . "(.*)\.(svn|git)(.*)$" . PHP_EOL . "wp-content\/cache(.*)$" . PHP_EOL . "(.*)error_log$" ); |
|
157 | - } |
|
155 | + if ( ! get_option( 'xcloner_regex_exclude' ) ) { |
|
156 | + update_option( 'xcloner_regex_exclude', "(wp-content\/updraft|wp-content\/uploads\/wp_all_backup)(.*)$" . PHP_EOL . "(.*)\.(svn|git)(.*)$" . PHP_EOL . "wp-content\/cache(.*)$" . PHP_EOL . "(.*)error_log$" ); |
|
157 | + } |
|
158 | 158 | |
159 | 159 | } |
160 | 160 |
@@ -61,22 +61,22 @@ discard block |
||
61 | 61 | |
62 | 62 | global $wpdb; |
63 | 63 | |
64 | - if ( version_compare( phpversion(), Xcloner_Activator::xcloner_minimum_version, '<' ) ) { |
|
65 | - wp_die( '<p>' . sprintf( __( "XCloner requires minimum PHP version %s in order to run correctly. We have detected your version as %s" ), Xcloner_Activator::xcloner_minimum_version, phpversion() ) . '</p>', __( "XCloner Activation Error" ), array( 'response' => 500, |
|
64 | + if (version_compare(phpversion(), Xcloner_Activator::xcloner_minimum_version, '<')) { |
|
65 | + wp_die('<p>'.sprintf(__("XCloner requires minimum PHP version %s in order to run correctly. We have detected your version as %s"), Xcloner_Activator::xcloner_minimum_version, phpversion()).'</p>', __("XCloner Activation Error"), array('response' => 500, |
|
66 | 66 | 'back_link' => true |
67 | - ) ); |
|
67 | + )); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | $charset_collate = $wpdb->get_charset_collate(); |
71 | 71 | |
72 | - $installed_ver = get_option( "xcloner_db_version" ); |
|
72 | + $installed_ver = get_option("xcloner_db_version"); |
|
73 | 73 | |
74 | 74 | $xcloner_db_version = Xcloner_Activator::xcloner_db_version; |
75 | 75 | |
76 | - $xcloner_scheduler_table = $wpdb->prefix . "xcloner_scheduler"; |
|
76 | + $xcloner_scheduler_table = $wpdb->prefix."xcloner_scheduler"; |
|
77 | 77 | |
78 | - if ( $installed_ver != $xcloner_db_version ) { |
|
79 | - $xcloner_schedule_sql = "CREATE TABLE `" . $xcloner_scheduler_table . "` ( |
|
78 | + if ($installed_ver != $xcloner_db_version) { |
|
79 | + $xcloner_schedule_sql = "CREATE TABLE `".$xcloner_scheduler_table."` ( |
|
80 | 80 | `id` int(11) NOT NULL AUTO_INCREMENT, |
81 | 81 | `name` varchar(255) NOT NULL, |
82 | 82 | `recurrence` varchar(25) NOT NULL, |
@@ -87,73 +87,73 @@ discard block |
||
87 | 87 | `status` int(1) NOT NULL, |
88 | 88 | `last_backup` varchar(100) DEFAULT NULL, |
89 | 89 | PRIMARY KEY (`id`) |
90 | - ) " . $charset_collate . "; |
|
90 | + ) " . $charset_collate."; |
|
91 | 91 | "; |
92 | 92 | |
93 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
94 | - dbDelta( $xcloner_schedule_sql ); |
|
93 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
94 | + dbDelta($xcloner_schedule_sql); |
|
95 | 95 | |
96 | - update_option( "xcloner_db_version", $xcloner_db_version ); |
|
96 | + update_option("xcloner_db_version", $xcloner_db_version); |
|
97 | 97 | } |
98 | 98 | |
99 | - if ( get_option( 'xcloner_backup_compression_level' ) === false ) { |
|
100 | - update_option( 'xcloner_backup_compression_level', 0 ); |
|
99 | + if (get_option('xcloner_backup_compression_level') === false) { |
|
100 | + update_option('xcloner_backup_compression_level', 0); |
|
101 | 101 | } |
102 | 102 | |
103 | - if ( get_option( 'xcloner_enable_log' ) === false ) { |
|
104 | - update_option( 'xcloner_enable_log', 1 ); |
|
103 | + if (get_option('xcloner_enable_log') === false) { |
|
104 | + update_option('xcloner_enable_log', 1); |
|
105 | 105 | } |
106 | 106 | |
107 | - if ( get_option( 'xcloner_enable_mysql_backup' ) === false ) { |
|
108 | - update_option( 'xcloner_enable_mysql_backup', 1 ); |
|
107 | + if (get_option('xcloner_enable_mysql_backup') === false) { |
|
108 | + update_option('xcloner_enable_mysql_backup', 1); |
|
109 | 109 | } |
110 | 110 | |
111 | - if ( get_option( 'xcloner_system_settings_page' ) === false ) { |
|
112 | - update_option( 'xcloner_system_settings_page', 100 ); |
|
111 | + if (get_option('xcloner_system_settings_page') === false) { |
|
112 | + update_option('xcloner_system_settings_page', 100); |
|
113 | 113 | } |
114 | 114 | |
115 | - if ( get_option( 'xcloner_files_to_process_per_request' ) === false ) { |
|
116 | - update_option( 'xcloner_files_to_process_per_request', 250 ); |
|
115 | + if (get_option('xcloner_files_to_process_per_request') === false) { |
|
116 | + update_option('xcloner_files_to_process_per_request', 250); |
|
117 | 117 | } |
118 | 118 | |
119 | - if ( get_option( 'xcloner_database_records_per_request' ) === false ) { |
|
120 | - update_option( 'xcloner_database_records_per_request', 10000 ); |
|
119 | + if (get_option('xcloner_database_records_per_request') === false) { |
|
120 | + update_option('xcloner_database_records_per_request', 10000); |
|
121 | 121 | } |
122 | 122 | |
123 | - if ( get_option( 'xcloner_exclude_files_larger_than_mb' ) === false ) { |
|
124 | - update_option( 'xcloner_exclude_files_larger_than_mb', 0 ); |
|
123 | + if (get_option('xcloner_exclude_files_larger_than_mb') === false) { |
|
124 | + update_option('xcloner_exclude_files_larger_than_mb', 0); |
|
125 | 125 | } |
126 | 126 | |
127 | - if ( get_option( 'xcloner_split_backup_limit' ) === false ) { |
|
128 | - update_option( 'xcloner_split_backup_limit', 2048 ); |
|
127 | + if (get_option('xcloner_split_backup_limit') === false) { |
|
128 | + update_option('xcloner_split_backup_limit', 2048); |
|
129 | 129 | } |
130 | 130 | |
131 | - if ( get_option( 'xcloner_size_limit_per_request' ) === false ) { |
|
132 | - update_option( 'xcloner_size_limit_per_request', 50 ); |
|
131 | + if (get_option('xcloner_size_limit_per_request') === false) { |
|
132 | + update_option('xcloner_size_limit_per_request', 50); |
|
133 | 133 | } |
134 | 134 | |
135 | - if ( get_option( 'xcloner_cleanup_retention_limit_days' ) === false ) { |
|
136 | - update_option( 'xcloner_cleanup_retention_limit_days', 60 ); |
|
135 | + if (get_option('xcloner_cleanup_retention_limit_days') === false) { |
|
136 | + update_option('xcloner_cleanup_retention_limit_days', 60); |
|
137 | 137 | } |
138 | 138 | |
139 | - if ( get_option( 'xcloner_cleanup_retention_limit_archives' ) === false ) { |
|
140 | - update_option( 'xcloner_cleanup_retention_limit_archives', 100 ); |
|
139 | + if (get_option('xcloner_cleanup_retention_limit_archives') === false) { |
|
140 | + update_option('xcloner_cleanup_retention_limit_archives', 100); |
|
141 | 141 | } |
142 | 142 | |
143 | - if ( get_option( 'xcloner_directories_to_scan_per_request' ) === false ) { |
|
144 | - update_option( 'xcloner_directories_to_scan_per_request', 25 ); |
|
143 | + if (get_option('xcloner_directories_to_scan_per_request') === false) { |
|
144 | + update_option('xcloner_directories_to_scan_per_request', 25); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /*if(!get_option('xcloner_diff_backup_recreate_period')) |
148 | 148 | update_option('xcloner_diff_backup_recreate_period', 10); |
149 | 149 | * */ |
150 | 150 | |
151 | - if ( ! get_option( 'xcloner_regex_exclude' ) ) { |
|
152 | - update_option( 'xcloner_regex_exclude', "(wp-content\/updraft|wp-content\/uploads\/wp_all_backup)(.*)$" . PHP_EOL . "(.*)\.(svn|git)(.*)$" . PHP_EOL . "wp-content\/cache(.*)$" . PHP_EOL . "(.*)error_log$" ); |
|
151 | + if (!get_option('xcloner_regex_exclude')) { |
|
152 | + update_option('xcloner_regex_exclude', "(wp-content\/updraft|wp-content\/uploads\/wp_all_backup)(.*)$".PHP_EOL."(.*)\.(svn|git)(.*)$".PHP_EOL."wp-content\/cache(.*)$".PHP_EOL."(.*)error_log$"); |
|
153 | 153 | } |
154 | 154 | |
155 | - if ( ! get_option( 'xcloner_regex_exclude' ) ) { |
|
156 | - update_option( 'xcloner_regex_exclude', "(wp-content\/updraft|wp-content\/uploads\/wp_all_backup)(.*)$" . PHP_EOL . "(.*)\.(svn|git)(.*)$" . PHP_EOL . "wp-content\/cache(.*)$" . PHP_EOL . "(.*)error_log$" ); |
|
155 | + if (!get_option('xcloner_regex_exclude')) { |
|
156 | + update_option('xcloner_regex_exclude', "(wp-content\/updraft|wp-content\/uploads\/wp_all_backup)(.*)$".PHP_EOL."(.*)\.(svn|git)(.*)$".PHP_EOL."wp-content\/cache(.*)$".PHP_EOL."(.*)error_log$"); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | } |
172 | 172 | |
173 | 173 | public function update_hash( $schedule_id, $hash ) { |
174 | - $schedule = array(); |
|
174 | + $schedule = array(); |
|
175 | 175 | |
176 | 176 | $schedule['hash'] = $hash; |
177 | 177 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | |
191 | 191 | public function update_last_backup( $schedule_id, $last_backup ) { |
192 | 192 | |
193 | - $this->logger->info(sprintf('Updating last backup %s for schedule id #%s', $last_backup, $schedule_id)); |
|
193 | + $this->logger->info(sprintf('Updating last backup %s for schedule id #%s', $last_backup, $schedule_id)); |
|
194 | 194 | |
195 | 195 | $schedule['last_backup'] = $last_backup; |
196 | 196 | |
@@ -284,56 +284,56 @@ discard block |
||
284 | 284 | } |
285 | 285 | $this->logger->info( sprintf( "File archive process FINISHED." ), array( "CRON" ) ); |
286 | 286 | |
287 | - //getting the last backup archive file |
|
288 | - $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); |
|
287 | + //getting the last backup archive file |
|
288 | + $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); |
|
289 | 289 | if ( $this->xcloner_file_system->is_part( $this->archive_system->get_archive_name_with_extension() ) ) { |
290 | 290 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
291 | 291 | } |
292 | 292 | |
293 | 293 | //Updating schedule last backup archive |
294 | - $this->update_last_backup( $schedule['id'], $return['extra']['backup_parent'] ); |
|
294 | + $this->update_last_backup( $schedule['id'], $return['extra']['backup_parent'] ); |
|
295 | 295 | |
296 | 296 | //Encrypting the backup archive |
297 | - $return_encrypted['finished'] = 0; |
|
298 | - $return_encrypted['start'] = 0; |
|
299 | - $return_encrypted['iv'] = ''; |
|
300 | - $return_encrypted['target_file'] = ''; |
|
301 | - $part = 0; |
|
302 | - $backup_parts = array(); |
|
303 | - |
|
304 | - if( $schedule['backup_params']->backup_encrypt){ |
|
305 | - $this->logger->info( sprintf( "Encrypting backup archive %s.", $return['extra']['backup_parent'] ), array( "CRON" ) ); |
|
306 | - |
|
307 | - $backup_file = $return['extra']['backup_parent']; |
|
308 | - |
|
309 | - if ($this->xcloner_file_system->is_multipart($return['extra']['backup_parent'])) { |
|
310 | - $backup_parts = $this->xcloner_file_system->get_multipart_files($return['extra']['backup_parent']); |
|
311 | - $backup_file = $backup_parts[$part]; |
|
312 | - } |
|
313 | - |
|
314 | - while ( ! $return_encrypted['finished'] ) { |
|
315 | - $return_encrypted = $this->xcloner_encryption->encrypt_file( |
|
316 | - $backup_file, |
|
317 | - "", |
|
318 | - "", |
|
319 | - "", |
|
320 | - "", |
|
321 | - true, |
|
322 | - true |
|
323 | - ); |
|
324 | - |
|
325 | - if($return_encrypted['finished']) { |
|
326 | - ++$part; |
|
327 | - |
|
328 | - if ($part < sizeof($backup_parts)) { |
|
329 | - $return_encrypted['finished'] = 0; |
|
330 | - $backup_file = $backup_parts[$part]; |
|
331 | - } |
|
332 | - } |
|
333 | - } |
|
334 | - } |
|
335 | - |
|
336 | - //Sending backup to remote storage |
|
297 | + $return_encrypted['finished'] = 0; |
|
298 | + $return_encrypted['start'] = 0; |
|
299 | + $return_encrypted['iv'] = ''; |
|
300 | + $return_encrypted['target_file'] = ''; |
|
301 | + $part = 0; |
|
302 | + $backup_parts = array(); |
|
303 | + |
|
304 | + if( $schedule['backup_params']->backup_encrypt){ |
|
305 | + $this->logger->info( sprintf( "Encrypting backup archive %s.", $return['extra']['backup_parent'] ), array( "CRON" ) ); |
|
306 | + |
|
307 | + $backup_file = $return['extra']['backup_parent']; |
|
308 | + |
|
309 | + if ($this->xcloner_file_system->is_multipart($return['extra']['backup_parent'])) { |
|
310 | + $backup_parts = $this->xcloner_file_system->get_multipart_files($return['extra']['backup_parent']); |
|
311 | + $backup_file = $backup_parts[$part]; |
|
312 | + } |
|
313 | + |
|
314 | + while ( ! $return_encrypted['finished'] ) { |
|
315 | + $return_encrypted = $this->xcloner_encryption->encrypt_file( |
|
316 | + $backup_file, |
|
317 | + "", |
|
318 | + "", |
|
319 | + "", |
|
320 | + "", |
|
321 | + true, |
|
322 | + true |
|
323 | + ); |
|
324 | + |
|
325 | + if($return_encrypted['finished']) { |
|
326 | + ++$part; |
|
327 | + |
|
328 | + if ($part < sizeof($backup_parts)) { |
|
329 | + $return_encrypted['finished'] = 0; |
|
330 | + $backup_file = $backup_parts[$part]; |
|
331 | + } |
|
332 | + } |
|
333 | + } |
|
334 | + } |
|
335 | + |
|
336 | + //Sending backup to remote storage |
|
337 | 337 | if ( isset( $schedule['remote_storage'] ) && $schedule['remote_storage'] && array_key_exists( $schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages() ) ) { |
338 | 338 | $backup_file = $return['extra']['backup_parent']; |
339 | 339 | |
@@ -384,10 +384,10 @@ discard block |
||
384 | 384 | } |
385 | 385 | |
386 | 386 | try { |
387 | - if( get_option('xcloner_disable_email_notification') ) { |
|
388 | - //we disable email notifications |
|
389 | - $schedule['backup_params']->email_notification = ""; |
|
390 | - } |
|
387 | + if( get_option('xcloner_disable_email_notification') ) { |
|
388 | + //we disable email notifications |
|
389 | + $schedule['backup_params']->email_notification = ""; |
|
390 | + } |
|
391 | 391 | $this->_xcloner_scheduler_callback( $id, $schedule ); |
392 | 392 | |
393 | 393 | } catch ( Exception $e ) { |
@@ -13,13 +13,13 @@ discard block |
||
13 | 13 | private $xcloner_file_system; |
14 | 14 | private $xcloner_encryption; |
15 | 15 | |
16 | - private $allowed_schedules = array( "hourly", "twicedaily", "daily", "weekly", "monthly" ); |
|
16 | + private $allowed_schedules = array("hourly", "twicedaily", "daily", "weekly", "monthly"); |
|
17 | 17 | |
18 | 18 | /*public function __call($method, $args) { |
19 | 19 | echo "$method is not defined"; |
20 | 20 | }*/ |
21 | 21 | |
22 | - public function __construct( Xcloner $xcloner_container ) { |
|
22 | + public function __construct(Xcloner $xcloner_container) { |
|
23 | 23 | global $wpdb; |
24 | 24 | |
25 | 25 | $this->db = $wpdb; |
@@ -28,26 +28,26 @@ discard block |
||
28 | 28 | $this->xcloner_container = $xcloner_container; |
29 | 29 | $this->xcloner_settings = $this->xcloner_container->get_xcloner_settings(); |
30 | 30 | |
31 | - $this->scheduler_table = $this->db->prefix . $this->scheduler_table; |
|
31 | + $this->scheduler_table = $this->db->prefix.$this->scheduler_table; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | private function get_xcloner_container() { |
35 | 35 | return $this->xcloner_container; |
36 | 36 | } |
37 | 37 | |
38 | - private function set_xcloner_container( Xcloner $container ) { |
|
38 | + private function set_xcloner_container(Xcloner $container) { |
|
39 | 39 | $this->xcloner_container = $container; |
40 | 40 | } |
41 | 41 | |
42 | - public function get_scheduler_list( $return_only_enabled = 0 ) { |
|
43 | - $list = $this->db->get_results( "SELECT * FROM " . $this->scheduler_table ); |
|
42 | + public function get_scheduler_list($return_only_enabled = 0) { |
|
43 | + $list = $this->db->get_results("SELECT * FROM ".$this->scheduler_table); |
|
44 | 44 | |
45 | - if ( $return_only_enabled ) { |
|
45 | + if ($return_only_enabled) { |
|
46 | 46 | $new_list = array(); |
47 | 47 | |
48 | - foreach ( $list as $res ) { |
|
49 | - if ( $res->status ) { |
|
50 | - $res->next_run_time = wp_next_scheduled( 'xcloner_scheduler_' . $res->id, array( $res->id ) ) + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
48 | + foreach ($list as $res) { |
|
49 | + if ($res->status) { |
|
50 | + $res->next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id)) + (get_option('gmt_offset') * HOUR_IN_SECONDS); |
|
51 | 51 | $new_list[] = $res; |
52 | 52 | } |
53 | 53 | } |
@@ -58,40 +58,40 @@ discard block |
||
58 | 58 | } |
59 | 59 | |
60 | 60 | public function get_next_run_schedule( ) { |
61 | - $list = $this->get_scheduler_list( $return_only_enabled = 1 ); |
|
61 | + $list = $this->get_scheduler_list($return_only_enabled = 1); |
|
62 | 62 | |
63 | 63 | return $list; |
64 | 64 | } |
65 | 65 | |
66 | - public function get_schedule_by_id_object( $id ) { |
|
67 | - $data = $this->db->get_row( "SELECT * FROM " . $this->scheduler_table . " WHERE id=" . $id ); |
|
66 | + public function get_schedule_by_id_object($id) { |
|
67 | + $data = $this->db->get_row("SELECT * FROM ".$this->scheduler_table." WHERE id=".$id); |
|
68 | 68 | |
69 | 69 | return $data; |
70 | 70 | } |
71 | 71 | |
72 | - public function get_schedule_by_id( $id ) { |
|
73 | - $data = $this->db->get_row( "SELECT * FROM " . $this->scheduler_table . " WHERE id=" . $id, ARRAY_A ); |
|
72 | + public function get_schedule_by_id($id) { |
|
73 | + $data = $this->db->get_row("SELECT * FROM ".$this->scheduler_table." WHERE id=".$id, ARRAY_A); |
|
74 | 74 | |
75 | - if ( ! $data ) { |
|
75 | + if (!$data) { |
|
76 | 76 | return false; |
77 | 77 | } |
78 | 78 | |
79 | - $params = json_decode( $data['params'] ); |
|
79 | + $params = json_decode($data['params']); |
|
80 | 80 | |
81 | 81 | //print_r($params); |
82 | 82 | $data['params'] = ""; |
83 | 83 | $data['backup_params'] = $params->backup_params; |
84 | - $data['table_params'] = json_encode( $params->database ); |
|
85 | - $data['excluded_files'] = json_encode( $params->excluded_files ); |
|
84 | + $data['table_params'] = json_encode($params->database); |
|
85 | + $data['excluded_files'] = json_encode($params->excluded_files); |
|
86 | 86 | |
87 | 87 | return $data; |
88 | 88 | } |
89 | 89 | |
90 | - public function delete_schedule_by_id( $id ) { |
|
91 | - $hook = 'xcloner_scheduler_' . $id; |
|
92 | - wp_clear_scheduled_hook( $hook, array( $id ) ); |
|
90 | + public function delete_schedule_by_id($id) { |
|
91 | + $hook = 'xcloner_scheduler_'.$id; |
|
92 | + wp_clear_scheduled_hook($hook, array($id)); |
|
93 | 93 | |
94 | - $data = $this->db->delete( $this->scheduler_table, array( 'id' => $id ) ); |
|
94 | + $data = $this->db->delete($this->scheduler_table, array('id' => $id)); |
|
95 | 95 | |
96 | 96 | return $data; |
97 | 97 | } |
@@ -99,68 +99,68 @@ discard block |
||
99 | 99 | public function deactivate_wp_cron_hooks() { |
100 | 100 | $list = $this->get_scheduler_list(); |
101 | 101 | |
102 | - foreach ( $list as $schedule ) { |
|
103 | - $hook = 'xcloner_scheduler_' . $schedule->id; |
|
102 | + foreach ($list as $schedule) { |
|
103 | + $hook = 'xcloner_scheduler_'.$schedule->id; |
|
104 | 104 | |
105 | - $timestamp = wp_next_scheduled( $hook, array( $schedule->id ) ); |
|
106 | - wp_unschedule_event( $timestamp, $hook, array( $schedule->id ) ); |
|
105 | + $timestamp = wp_next_scheduled($hook, array($schedule->id)); |
|
106 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
110 | 110 | public function update_wp_cron_hooks() { |
111 | 111 | $list = $this->get_scheduler_list(); |
112 | 112 | |
113 | - foreach ( $list as $schedule ) { |
|
114 | - $hook = 'xcloner_scheduler_' . $schedule->id; |
|
113 | + foreach ($list as $schedule) { |
|
114 | + $hook = 'xcloner_scheduler_'.$schedule->id; |
|
115 | 115 | |
116 | 116 | //adding the xcloner_scheduler hook with xcloner_scheduler_callback callback |
117 | - add_action( $hook, array( $this, 'xcloner_scheduler_callback' ), 10, 1 ); |
|
117 | + add_action($hook, array($this, 'xcloner_scheduler_callback'), 10, 1); |
|
118 | 118 | |
119 | - if ( ! wp_next_scheduled( $hook, array( $schedule->id ) ) and $schedule->status ) { |
|
119 | + if (!wp_next_scheduled($hook, array($schedule->id)) and $schedule->status) { |
|
120 | 120 | |
121 | - if ( $schedule->recurrence == "single" ) { |
|
122 | - wp_schedule_single_event( strtotime( $schedule->start_at ), $hook, array( $schedule->id ) ); |
|
121 | + if ($schedule->recurrence == "single") { |
|
122 | + wp_schedule_single_event(strtotime($schedule->start_at), $hook, array($schedule->id)); |
|
123 | 123 | } else { |
124 | - wp_schedule_event( strtotime( $schedule->start_at ), $schedule->recurrence, $hook, array( $schedule->id ) ); |
|
124 | + wp_schedule_event(strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id)); |
|
125 | 125 | } |
126 | 126 | |
127 | - } elseif ( ! $schedule->status ) { |
|
128 | - $timestamp = wp_next_scheduled( $hook, array( $schedule->id ) ); |
|
129 | - wp_unschedule_event( $timestamp, $hook, array( $schedule->id ) ); |
|
127 | + } elseif (!$schedule->status) { |
|
128 | + $timestamp = wp_next_scheduled($hook, array($schedule->id)); |
|
129 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | 133 | } |
134 | 134 | |
135 | - public function update_cron_hook( $id ) { |
|
136 | - $schedule = $this->get_schedule_by_id_object( $id ); |
|
137 | - $hook = 'xcloner_scheduler_' . $schedule->id; |
|
135 | + public function update_cron_hook($id) { |
|
136 | + $schedule = $this->get_schedule_by_id_object($id); |
|
137 | + $hook = 'xcloner_scheduler_'.$schedule->id; |
|
138 | 138 | |
139 | - $timestamp = wp_next_scheduled( $hook, array( $schedule->id ) ); |
|
140 | - wp_unschedule_event( $timestamp, $hook, array( $schedule->id ) ); |
|
139 | + $timestamp = wp_next_scheduled($hook, array($schedule->id)); |
|
140 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
141 | 141 | |
142 | - if ( $schedule->status ) { |
|
142 | + if ($schedule->status) { |
|
143 | 143 | |
144 | - if ( $schedule->recurrence == "single" ) { |
|
145 | - wp_schedule_single_event( strtotime( $schedule->start_at ), $hook, array( $schedule->id ) ); |
|
144 | + if ($schedule->recurrence == "single") { |
|
145 | + wp_schedule_single_event(strtotime($schedule->start_at), $hook, array($schedule->id)); |
|
146 | 146 | } else { |
147 | - wp_schedule_event( strtotime( $schedule->start_at ), $schedule->recurrence, $hook, array( $schedule->id ) ); |
|
147 | + wp_schedule_event(strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id)); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | } |
151 | 151 | } |
152 | 152 | |
153 | - public function disable_single_cron( $schedule_id ) { |
|
154 | - $hook = 'xcloner_scheduler_' . $schedule_id; |
|
155 | - $timestamp = wp_next_scheduled( $hook, array( $schedule_id ) ); |
|
156 | - wp_unschedule_event( $timestamp, $hook, array( $schedule_id ) ); |
|
153 | + public function disable_single_cron($schedule_id) { |
|
154 | + $hook = 'xcloner_scheduler_'.$schedule_id; |
|
155 | + $timestamp = wp_next_scheduled($hook, array($schedule_id)); |
|
156 | + wp_unschedule_event($timestamp, $hook, array($schedule_id)); |
|
157 | 157 | |
158 | 158 | $schedule['status'] = 0; |
159 | 159 | |
160 | 160 | $update = $this->db->update( |
161 | 161 | $this->scheduler_table, |
162 | 162 | $schedule, |
163 | - array( 'id' => $schedule_id ), |
|
163 | + array('id' => $schedule_id), |
|
164 | 164 | array( |
165 | 165 | '%s', |
166 | 166 | '%s' |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | return $update; |
171 | 171 | } |
172 | 172 | |
173 | - public function update_hash( $schedule_id, $hash ) { |
|
173 | + public function update_hash($schedule_id, $hash) { |
|
174 | 174 | $schedule = array(); |
175 | 175 | |
176 | 176 | $schedule['hash'] = $hash; |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | $update = $this->db->update( |
179 | 179 | $this->scheduler_table, |
180 | 180 | $schedule, |
181 | - array( 'id' => $schedule_id ), |
|
181 | + array('id' => $schedule_id), |
|
182 | 182 | array( |
183 | 183 | '%s', |
184 | 184 | '%s' |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | return $update; |
189 | 189 | } |
190 | 190 | |
191 | - public function update_last_backup( $schedule_id, $last_backup ) { |
|
191 | + public function update_last_backup($schedule_id, $last_backup) { |
|
192 | 192 | |
193 | 193 | $this->logger->info(sprintf('Updating last backup %s for schedule id #%s', $last_backup, $schedule_id)); |
194 | 194 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | $update = $this->db->update( |
198 | 198 | $this->scheduler_table, |
199 | 199 | $schedule, |
200 | - array( 'id' => $schedule_id ), |
|
200 | + array('id' => $schedule_id), |
|
201 | 201 | array( |
202 | 202 | '%s', |
203 | 203 | '%s' |
@@ -207,91 +207,91 @@ discard block |
||
207 | 207 | return $update; |
208 | 208 | } |
209 | 209 | |
210 | - private function _xcloner_scheduler_callback( $id, $schedule ) { |
|
211 | - set_time_limit( 0 ); |
|
210 | + private function _xcloner_scheduler_callback($id, $schedule) { |
|
211 | + set_time_limit(0); |
|
212 | 212 | |
213 | 213 | $xcloner = new XCloner(); |
214 | 214 | $xcloner->init(); |
215 | - $this->set_xcloner_container( $xcloner ); |
|
215 | + $this->set_xcloner_container($xcloner); |
|
216 | 216 | |
217 | 217 | #$hash = $this->xcloner_settings->get_hash(); |
218 | 218 | #$this->get_xcloner_container()->get_xcloner_settings()->set_hash($hash); |
219 | 219 | |
220 | 220 | //$this->xcloner_settings = $this->get_xcloner_container()->get_xcloner_settings(); |
221 | 221 | $this->xcloner_file_system = $this->get_xcloner_container()->get_xcloner_filesystem(); |
222 | - $this->xcloner_encryption = $this->get_xcloner_container()->get_xcloner_encryption(); |
|
222 | + $this->xcloner_encryption = $this->get_xcloner_container()->get_xcloner_encryption(); |
|
223 | 223 | $this->xcloner_database = $this->get_xcloner_container()->get_xcloner_database(); |
224 | 224 | $this->archive_system = $this->get_xcloner_container()->get_archive_system(); |
225 | - $this->logger = $this->get_xcloner_container()->get_xcloner_logger()->withName( "xcloner_scheduler" ); |
|
225 | + $this->logger = $this->get_xcloner_container()->get_xcloner_logger()->withName("xcloner_scheduler"); |
|
226 | 226 | $this->xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
227 | 227 | |
228 | - $this->logger->info( sprintf( "New schedule hash is %s", $this->xcloner_settings->get_hash() ) ); |
|
228 | + $this->logger->info(sprintf("New schedule hash is %s", $this->xcloner_settings->get_hash())); |
|
229 | 229 | |
230 | - if ( isset( $schedule['backup_params']->diff_start_date ) && $schedule['backup_params']->diff_start_date ) { |
|
231 | - $this->xcloner_file_system->set_diff_timestamp_start( $schedule['backup_params']->diff_start_date ); |
|
230 | + if (isset($schedule['backup_params']->diff_start_date) && $schedule['backup_params']->diff_start_date) { |
|
231 | + $this->xcloner_file_system->set_diff_timestamp_start($schedule['backup_params']->diff_start_date); |
|
232 | 232 | } |
233 | 233 | |
234 | - if ( $schedule['recurrence'] == "single" ) { |
|
235 | - $this->disable_single_cron( $schedule['id'] ); |
|
234 | + if ($schedule['recurrence'] == "single") { |
|
235 | + $this->disable_single_cron($schedule['id']); |
|
236 | 236 | } |
237 | 237 | |
238 | - if ( ! $schedule ) { |
|
239 | - $this->logger->info( sprintf( "Could not load schedule with id'%s'", $id ), array( "CRON" ) ); |
|
238 | + if (!$schedule) { |
|
239 | + $this->logger->info(sprintf("Could not load schedule with id'%s'", $id), array("CRON")); |
|
240 | 240 | |
241 | 241 | return; |
242 | 242 | } |
243 | 243 | |
244 | 244 | //echo $this->get_xcloner_container()->get_xcloner_settings()->get_hash(); exit; |
245 | 245 | |
246 | - $this->update_hash( $schedule['id'], $this->xcloner_settings->get_hash() ); |
|
246 | + $this->update_hash($schedule['id'], $this->xcloner_settings->get_hash()); |
|
247 | 247 | |
248 | - $this->logger->info( sprintf( "Starting cron schedule '%s'", $schedule['name'] ), array( "CRON" ) ); |
|
248 | + $this->logger->info(sprintf("Starting cron schedule '%s'", $schedule['name']), array("CRON")); |
|
249 | 249 | |
250 | - $this->xcloner_file_system->set_excluded_files( json_decode( $schedule['excluded_files'] ) ); |
|
250 | + $this->xcloner_file_system->set_excluded_files(json_decode($schedule['excluded_files'])); |
|
251 | 251 | |
252 | 252 | $init = 1; |
253 | 253 | $continue = 1; |
254 | 254 | |
255 | - while ( $continue ) { |
|
256 | - $continue = $this->xcloner_file_system->start_file_recursion( $init ); |
|
255 | + while ($continue) { |
|
256 | + $continue = $this->xcloner_file_system->start_file_recursion($init); |
|
257 | 257 | |
258 | 258 | $init = 0; |
259 | 259 | } |
260 | 260 | |
261 | - $this->logger->info( sprintf( "File scan finished" ), array( "CRON" ) ); |
|
261 | + $this->logger->info(sprintf("File scan finished"), array("CRON")); |
|
262 | 262 | |
263 | - $this->logger->info( sprintf( "Starting the database backup" ), array( "CRON" ) ); |
|
263 | + $this->logger->info(sprintf("Starting the database backup"), array("CRON")); |
|
264 | 264 | |
265 | 265 | $init = 1; |
266 | 266 | $return['finished'] = 0; |
267 | 267 | |
268 | - while ( ! $return['finished'] ) { |
|
269 | - $return = $this->xcloner_database->start_database_recursion( (array) json_decode( $schedule['table_params'] ), $return, $init ); |
|
268 | + while (!$return['finished']) { |
|
269 | + $return = $this->xcloner_database->start_database_recursion((array)json_decode($schedule['table_params']), $return, $init); |
|
270 | 270 | $init = 0; |
271 | 271 | } |
272 | 272 | |
273 | - $this->logger->info( sprintf( "Database backup done" ), array( "CRON" ) ); |
|
273 | + $this->logger->info(sprintf("Database backup done"), array("CRON")); |
|
274 | 274 | |
275 | - $this->logger->info( sprintf( "Starting file archive process" ), array( "CRON" ) ); |
|
275 | + $this->logger->info(sprintf("Starting file archive process"), array("CRON")); |
|
276 | 276 | |
277 | 277 | $init = 0; |
278 | 278 | $return['finished'] = 0; |
279 | 279 | $return['extra'] = array(); |
280 | 280 | |
281 | - while ( ! $return['finished'] ) { |
|
282 | - $return = $this->archive_system->start_incremental_backup( (array) $schedule['backup_params'], $return['extra'], $init ); |
|
281 | + while (!$return['finished']) { |
|
282 | + $return = $this->archive_system->start_incremental_backup((array)$schedule['backup_params'], $return['extra'], $init); |
|
283 | 283 | $init = 0; |
284 | 284 | } |
285 | - $this->logger->info( sprintf( "File archive process FINISHED." ), array( "CRON" ) ); |
|
285 | + $this->logger->info(sprintf("File archive process FINISHED."), array("CRON")); |
|
286 | 286 | |
287 | 287 | //getting the last backup archive file |
288 | 288 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); |
289 | - if ( $this->xcloner_file_system->is_part( $this->archive_system->get_archive_name_with_extension() ) ) { |
|
289 | + if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) { |
|
290 | 290 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
291 | 291 | } |
292 | 292 | |
293 | 293 | //Updating schedule last backup archive |
294 | - $this->update_last_backup( $schedule['id'], $return['extra']['backup_parent'] ); |
|
294 | + $this->update_last_backup($schedule['id'], $return['extra']['backup_parent']); |
|
295 | 295 | |
296 | 296 | //Encrypting the backup archive |
297 | 297 | $return_encrypted['finished'] = 0; |
@@ -301,8 +301,8 @@ discard block |
||
301 | 301 | $part = 0; |
302 | 302 | $backup_parts = array(); |
303 | 303 | |
304 | - if( $schedule['backup_params']->backup_encrypt){ |
|
305 | - $this->logger->info( sprintf( "Encrypting backup archive %s.", $return['extra']['backup_parent'] ), array( "CRON" ) ); |
|
304 | + if ($schedule['backup_params']->backup_encrypt) { |
|
305 | + $this->logger->info(sprintf("Encrypting backup archive %s.", $return['extra']['backup_parent']), array("CRON")); |
|
306 | 306 | |
307 | 307 | $backup_file = $return['extra']['backup_parent']; |
308 | 308 | |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | $backup_file = $backup_parts[$part]; |
312 | 312 | } |
313 | 313 | |
314 | - while ( ! $return_encrypted['finished'] ) { |
|
314 | + while (!$return_encrypted['finished']) { |
|
315 | 315 | $return_encrypted = $this->xcloner_encryption->encrypt_file( |
316 | 316 | $backup_file, |
317 | 317 | "", |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | true |
323 | 323 | ); |
324 | 324 | |
325 | - if($return_encrypted['finished']) { |
|
325 | + if ($return_encrypted['finished']) { |
|
326 | 326 | ++$part; |
327 | 327 | |
328 | 328 | if ($part < sizeof($backup_parts)) { |
@@ -334,37 +334,37 @@ discard block |
||
334 | 334 | } |
335 | 335 | |
336 | 336 | //Sending backup to remote storage |
337 | - if ( isset( $schedule['remote_storage'] ) && $schedule['remote_storage'] && array_key_exists( $schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages() ) ) { |
|
337 | + if (isset($schedule['remote_storage']) && $schedule['remote_storage'] && array_key_exists($schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages())) { |
|
338 | 338 | $backup_file = $return['extra']['backup_parent']; |
339 | 339 | |
340 | - $this->logger->info( sprintf( "Transferring backup to remote storage %s", strtoupper( $schedule['remote_storage'] ) ), array( "CRON" ) ); |
|
340 | + $this->logger->info(sprintf("Transferring backup to remote storage %s", strtoupper($schedule['remote_storage'])), array("CRON")); |
|
341 | 341 | |
342 | - if ( method_exists( $this->xcloner_remote_storage, "upload_backup_to_storage" ) ) { |
|
343 | - call_user_func_array( array( |
|
342 | + if (method_exists($this->xcloner_remote_storage, "upload_backup_to_storage")) { |
|
343 | + call_user_func_array(array( |
|
344 | 344 | $this->xcloner_remote_storage, |
345 | 345 | "upload_backup_to_storage" |
346 | - ), array( $backup_file, $schedule['remote_storage'] ) ); |
|
346 | + ), array($backup_file, $schedule['remote_storage'])); |
|
347 | 347 | } |
348 | 348 | } |
349 | 349 | |
350 | 350 | //Sending email notification |
351 | - if ( isset( $schedule['backup_params']->email_notification ) and $to = $schedule['backup_params']->email_notification ) { |
|
351 | + if (isset($schedule['backup_params']->email_notification) and $to = $schedule['backup_params']->email_notification) { |
|
352 | 352 | try { |
353 | 353 | $from = ""; |
354 | 354 | $additional['lines_total'] = $return['extra']['lines_total']; |
355 | - $subject = sprintf( __( "%s - new backup generated %s" ), $schedule['name'], $return['extra']['backup_parent'] ); |
|
355 | + $subject = sprintf(__("%s - new backup generated %s"), $schedule['name'], $return['extra']['backup_parent']); |
|
356 | 356 | |
357 | - $this->archive_system->send_notification( $to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional ); |
|
357 | + $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional); |
|
358 | 358 | |
359 | - } catch ( Exception $e ) { |
|
360 | - $this->logger->error( $e->getMessage() ); |
|
359 | + }catch (Exception $e) { |
|
360 | + $this->logger->error($e->getMessage()); |
|
361 | 361 | } |
362 | 362 | } |
363 | 363 | |
364 | 364 | //CHECK IF WE SHOULD DELETE BACKUP AFTER REMOTE TRANSFER IS DONE |
365 | - if ( $schedule['remote_storage'] && $this->xcloner_settings->get_xcloner_option( 'xcloner_cleanup_delete_after_remote_transfer' ) ) { |
|
366 | - $this->logger->info( sprintf( "Deleting %s from local storage matching rule xcloner_cleanup_delete_after_remote_transfer", $return['extra']['backup_parent'] ) ); |
|
367 | - $this->xcloner_file_system->delete_backup_by_name( $return['extra']['backup_parent'] ); |
|
365 | + if ($schedule['remote_storage'] && $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_delete_after_remote_transfer')) { |
|
366 | + $this->logger->info(sprintf("Deleting %s from local storage matching rule xcloner_cleanup_delete_after_remote_transfer", $return['extra']['backup_parent'])); |
|
367 | + $this->xcloner_file_system->delete_backup_by_name($return['extra']['backup_parent']); |
|
368 | 368 | |
369 | 369 | } |
370 | 370 | |
@@ -378,28 +378,28 @@ discard block |
||
378 | 378 | $this->xcloner_file_system->cleanup_tmp_directories(); |
379 | 379 | } |
380 | 380 | |
381 | - public function xcloner_scheduler_callback( $id, $schedule = "" ) { |
|
382 | - if ( $id ) { |
|
383 | - $schedule = $this->get_schedule_by_id( $id ); |
|
381 | + public function xcloner_scheduler_callback($id, $schedule = "") { |
|
382 | + if ($id) { |
|
383 | + $schedule = $this->get_schedule_by_id($id); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | try { |
387 | - if( get_option('xcloner_disable_email_notification') ) { |
|
387 | + if (get_option('xcloner_disable_email_notification')) { |
|
388 | 388 | //we disable email notifications |
389 | 389 | $schedule['backup_params']->email_notification = ""; |
390 | 390 | } |
391 | - $this->_xcloner_scheduler_callback( $id, $schedule ); |
|
391 | + $this->_xcloner_scheduler_callback($id, $schedule); |
|
392 | 392 | |
393 | - } catch ( Exception $e ) { |
|
393 | + }catch (Exception $e) { |
|
394 | 394 | |
395 | 395 | //send email to site admin if email notification is not set in the scheduler |
396 | - if ( ! isset( $schedule['backup_params']->email_notification ) || ! $schedule['backup_params']->email_notification ) { |
|
397 | - $schedule['backup_params']->email_notification = get_option( 'admin_email' ); |
|
396 | + if (!isset($schedule['backup_params']->email_notification) || !$schedule['backup_params']->email_notification) { |
|
397 | + $schedule['backup_params']->email_notification = get_option('admin_email'); |
|
398 | 398 | } |
399 | 399 | |
400 | - if ( isset( $schedule['backup_params']->email_notification ) && $to = $schedule['backup_params']->email_notification ) { |
|
400 | + if (isset($schedule['backup_params']->email_notification) && $to = $schedule['backup_params']->email_notification) { |
|
401 | 401 | $from = ""; |
402 | - $this->archive_system->send_notification( $to, $from, $schedule['name'] . " - backup error", "", "", $e->getMessage() ); |
|
402 | + $this->archive_system->send_notification($to, $from, $schedule['name']." - backup error", "", "", $e->getMessage()); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | } |
@@ -410,14 +410,14 @@ discard block |
||
410 | 410 | $schedules = wp_get_schedules(); |
411 | 411 | $new_schedules = array(); |
412 | 412 | |
413 | - foreach ( $schedules as $key => $row ) { |
|
414 | - if ( in_array( $key, $this->allowed_schedules ) ) { |
|
415 | - $new_schedules[ $key ] = $row; |
|
416 | - $intervals[ $key ] = $row['interval']; |
|
413 | + foreach ($schedules as $key => $row) { |
|
414 | + if (in_array($key, $this->allowed_schedules)) { |
|
415 | + $new_schedules[$key] = $row; |
|
416 | + $intervals[$key] = $row['interval']; |
|
417 | 417 | } |
418 | 418 | } |
419 | 419 | |
420 | - array_multisort( $intervals, SORT_ASC, $new_schedules ); |
|
420 | + array_multisort($intervals, SORT_ASC, $new_schedules); |
|
421 | 421 | |
422 | 422 | return $new_schedules; |
423 | 423 | } |