@@ -4,12 +4,12 @@ discard block |
||
4 | 4 | use League\Flysystem\Util; |
5 | 5 | use League\Flysystem\Adapter\Local; |
6 | 6 | |
7 | -class Xcloner_File_System{ |
|
7 | +class Xcloner_File_System { |
|
8 | 8 | |
9 | - private $excluded_files = ""; |
|
10 | - private $excluded_files_by_default = array("administrator/backups", "wp-content/backups"); |
|
11 | - private $included_files_handler = "backup_files.csv"; |
|
12 | - private $temp_dir_handler = ".dir"; |
|
9 | + private $excluded_files = ""; |
|
10 | + private $excluded_files_by_default = array("administrator/backups", "wp-content/backups"); |
|
11 | + private $included_files_handler = "backup_files.csv"; |
|
12 | + private $temp_dir_handler = ".dir"; |
|
13 | 13 | public $filesystem; |
14 | 14 | public $tmp_filesystem; |
15 | 15 | public $storage_filesystem; |
@@ -34,39 +34,39 @@ discard block |
||
34 | 34 | $this->logger = new XCloner_Logger('xcloner_file_system', $hash); |
35 | 35 | $this->xcloner_requirements = new Xcloner_Requirements(); |
36 | 36 | |
37 | - $this->xcloner_settings = new Xcloner_Settings($hash); |
|
37 | + $this->xcloner_settings = new Xcloner_Settings($hash); |
|
38 | 38 | |
39 | - try{ |
|
39 | + try { |
|
40 | 40 | |
41 | - $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(),LOCK_EX, 'SKIP_LINKS'); |
|
41 | + $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS'); |
|
42 | 42 | $this->start_filesystem = new Filesystem($this->start_adapter, new Config([ |
43 | 43 | 'disable_asserts' => true, |
44 | 44 | ])); |
45 | 45 | |
46 | - $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX, 'SKIP_LINKS'); |
|
46 | + $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS'); |
|
47 | 47 | $this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([ |
48 | 48 | 'disable_asserts' => true, |
49 | 49 | ])); |
50 | - $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX|FILE_APPEND, 'SKIP_LINKS'); |
|
50 | + $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS'); |
|
51 | 51 | $this->tmp_filesystem_append = new Filesystem($adapter, new Config([ |
52 | 52 | 'disable_asserts' => true, |
53 | 53 | ])); |
54 | 54 | |
55 | - $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),LOCK_EX, 'SKIP_LINKS'); |
|
55 | + $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS'); |
|
56 | 56 | $this->storage_filesystem = new Filesystem($adapter, new Config([ |
57 | 57 | 'disable_asserts' => true, |
58 | 58 | ])); |
59 | 59 | |
60 | - $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),FILE_APPEND, 'SKIP_LINKS'); |
|
60 | + $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND, 'SKIP_LINKS'); |
|
61 | 61 | $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ |
62 | 62 | 'disable_asserts' => true, |
63 | 63 | ])); |
64 | - }catch(Exception $e){ |
|
64 | + }catch (Exception $e) { |
|
65 | 65 | return false; |
66 | 66 | } |
67 | 67 | |
68 | 68 | |
69 | - if($value = get_option('xcloner_directories_to_scan_per_request')) |
|
69 | + if ($value = get_option('xcloner_directories_to_scan_per_request')) |
|
70 | 70 | $this->folders_to_process_per_session = $value; |
71 | 71 | |
72 | 72 | } |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | return $this->getMetadataFull('storage_adapter', $file); |
128 | 128 | } |
129 | 129 | |
130 | - public function get_included_files_handler($metadata = 0) |
|
130 | + public function get_included_files_handler($metadata = 0) |
|
131 | 131 | { |
132 | 132 | $path = $this->included_files_handler; |
133 | - if(!$metadata) |
|
133 | + if (!$metadata) |
|
134 | 134 | return $path; |
135 | 135 | |
136 | 136 | $spl_info = $this->getMetadataFull('tmp_adapter', $path); |
@@ -147,16 +147,16 @@ discard block |
||
147 | 147 | { |
148 | 148 | $files = $this->get_backup_archives_list(); |
149 | 149 | |
150 | - if(is_array($files)) |
|
151 | - $this->sort_by($files, "timestamp","desc"); |
|
150 | + if (is_array($files)) |
|
151 | + $this->sort_by($files, "timestamp", "desc"); |
|
152 | 152 | |
153 | 153 | $new_list = array(); |
154 | 154 | |
155 | - foreach($files as $key=>$file) |
|
156 | - if(!isset($file['parent'])) |
|
155 | + foreach ($files as $key=>$file) |
|
156 | + if (!isset($file['parent'])) |
|
157 | 157 | $new_list[] = ($files[$key]); |
158 | 158 | |
159 | - if(isset($new_list[0])) |
|
159 | + if (isset($new_list[0])) |
|
160 | 160 | return $new_list[0]; |
161 | 161 | } |
162 | 162 | |
@@ -164,13 +164,13 @@ discard block |
||
164 | 164 | { |
165 | 165 | $files = $this->get_backup_archives_list(); |
166 | 166 | |
167 | - if(is_array($files)) |
|
168 | - $this->sort_by($files, "timestamp","desc"); |
|
167 | + if (is_array($files)) |
|
168 | + $this->sort_by($files, "timestamp", "desc"); |
|
169 | 169 | |
170 | 170 | $new_list = array(); |
171 | 171 | |
172 | - foreach($files as $key=>$file) |
|
173 | - if(!isset($file['parent'])) |
|
172 | + foreach ($files as $key=>$file) |
|
173 | + if (!isset($file['parent'])) |
|
174 | 174 | $new_list[] = ($files[$key]); |
175 | 175 | |
176 | 176 | return $new_list; |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | $files = $this->get_backup_archives_list(); |
182 | 182 | $total = 0; |
183 | 183 | |
184 | - if(is_array($files)) |
|
185 | - foreach($files as $file) |
|
184 | + if (is_array($files)) |
|
185 | + foreach ($files as $file) |
|
186 | 186 | $total += $file['size']; |
187 | 187 | |
188 | 188 | return $total; |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | |
191 | 191 | public function is_part($backup_name) |
192 | 192 | { |
193 | - if(stristr($backup_name, "-part")) |
|
193 | + if (stristr($backup_name, "-part")) |
|
194 | 194 | return true; |
195 | 195 | |
196 | 196 | return false; |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | |
199 | 199 | public function is_multipart($backup_name) |
200 | 200 | { |
201 | - if(stristr($backup_name, "-multipart")) |
|
201 | + if (stristr($backup_name, "-multipart")) |
|
202 | 202 | return true; |
203 | 203 | |
204 | 204 | return false; |
@@ -207,10 +207,10 @@ discard block |
||
207 | 207 | public function get_backup_size($backup_name) |
208 | 208 | { |
209 | 209 | $backup_size = $this->get_storage_filesystem()->getSize($backup_name); |
210 | - if($this->is_multipart($backup_name)) |
|
210 | + if ($this->is_multipart($backup_name)) |
|
211 | 211 | { |
212 | 212 | $backup_parts = $this->get_multipart_files($backup_name); |
213 | - foreach($backup_parts as $part_file) |
|
213 | + foreach ($backup_parts as $part_file) |
|
214 | 214 | $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
215 | 215 | } |
216 | 216 | |
@@ -221,12 +221,12 @@ discard block |
||
221 | 221 | { |
222 | 222 | $files = array(); |
223 | 223 | |
224 | - if($this->is_multipart($backup_name)) |
|
224 | + if ($this->is_multipart($backup_name)) |
|
225 | 225 | { |
226 | 226 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($backup_name)); |
227 | - foreach($lines as $line) |
|
227 | + foreach ($lines as $line) |
|
228 | 228 | { |
229 | - if($line) |
|
229 | + if ($line) |
|
230 | 230 | { |
231 | 231 | $data = str_getcsv($line); |
232 | 232 | $files[] = $data[0]; |
@@ -239,12 +239,12 @@ discard block |
||
239 | 239 | |
240 | 240 | public function delete_backup_by_name($backup_name) |
241 | 241 | { |
242 | - if($this->is_multipart($backup_name)) |
|
242 | + if ($this->is_multipart($backup_name)) |
|
243 | 243 | { |
244 | 244 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($backup_name)); |
245 | - foreach($lines as $line) |
|
245 | + foreach ($lines as $line) |
|
246 | 246 | { |
247 | - if($line) |
|
247 | + if ($line) |
|
248 | 248 | { |
249 | 249 | $data = str_getcsv($line); |
250 | 250 | $this->get_storage_filesystem()->delete($data[0]); |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | } |
253 | 253 | } |
254 | 254 | |
255 | - if($this->get_storage_filesystem()->delete($backup_name)) |
|
255 | + if ($this->get_storage_filesystem()->delete($backup_name)) |
|
256 | 256 | $return = true; |
257 | 257 | else |
258 | 258 | $return = false; |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | return $return; |
261 | 261 | } |
262 | 262 | |
263 | - public function getMetadataFull($adapter = "storage_adapter" , $path) |
|
263 | + public function getMetadataFull($adapter = "storage_adapter", $path) |
|
264 | 264 | { |
265 | 265 | $location = $this->$adapter->applyPathPrefix($path); |
266 | 266 | $spl_info = new SplFileInfo($location); |
@@ -273,25 +273,25 @@ discard block |
||
273 | 273 | { |
274 | 274 | $list = array(); |
275 | 275 | |
276 | - if(method_exists($this->get_storage_filesystem(), "listContents")) |
|
276 | + if (method_exists($this->get_storage_filesystem(), "listContents")) |
|
277 | 277 | $list = $this->get_storage_filesystem()->listContents(); |
278 | 278 | |
279 | 279 | |
280 | 280 | $backup_files = array(); |
281 | 281 | $parents = array(); |
282 | 282 | |
283 | - foreach($list as $file_info) |
|
283 | + foreach ($list as $file_info) |
|
284 | 284 | { |
285 | 285 | $data = array(); |
286 | 286 | |
287 | - if(isset($file_info['extension']) and $file_info['extension'] == "csv") |
|
287 | + if (isset($file_info['extension']) and $file_info['extension'] == "csv") |
|
288 | 288 | { |
289 | 289 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($file_info['path'])); |
290 | - foreach($lines as $line) |
|
291 | - if($line) |
|
290 | + foreach ($lines as $line) |
|
291 | + if ($line) |
|
292 | 292 | { |
293 | 293 | $data = str_getcsv($line); |
294 | - if(is_array($data)){ |
|
294 | + if (is_array($data)) { |
|
295 | 295 | $parents[$data[0]] = $file_info['path']; |
296 | 296 | $file_info['childs'][] = $data; |
297 | 297 | $file_info['size'] += $data[2]; |
@@ -300,13 +300,13 @@ discard block |
||
300 | 300 | |
301 | 301 | } |
302 | 302 | |
303 | - if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
303 | + if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
304 | 304 | $backup_files[$file_info['path']] = $file_info; |
305 | 305 | } |
306 | 306 | |
307 | - foreach($backup_files as $key=>$file_info) |
|
307 | + foreach ($backup_files as $key=>$file_info) |
|
308 | 308 | { |
309 | - if(isset($parents[$file_info['path']])) |
|
309 | + if (isset($parents[$file_info['path']])) |
|
310 | 310 | $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
311 | 311 | } |
312 | 312 | |
@@ -315,40 +315,40 @@ discard block |
||
315 | 315 | |
316 | 316 | public function start_file_recursion($init = 0) |
317 | 317 | { |
318 | - if($init) |
|
318 | + if ($init) |
|
319 | 319 | { |
320 | 320 | $this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"), $this->xcloner_settings->get_xcloner_start_path())); |
321 | 321 | $this->do_system_init(); |
322 | 322 | } |
323 | 323 | |
324 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())){ |
|
324 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
325 | 325 | //.dir exists, we presume we have files to iterate |
326 | 326 | $content = $this->tmp_filesystem->read($this->get_temp_dir_handler()); |
327 | 327 | $files = array_filter(explode("\n", $content)); |
328 | 328 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
329 | 329 | |
330 | 330 | $counter = 0; |
331 | - foreach($files as $file) |
|
331 | + foreach ($files as $file) |
|
332 | 332 | { |
333 | - if($counter < $this->folders_to_process_per_session){ |
|
333 | + if ($counter < $this->folders_to_process_per_session) { |
|
334 | 334 | $this->build_files_list($file); |
335 | 335 | $counter++; |
336 | - }else{ |
|
336 | + } else { |
|
337 | 337 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n"); |
338 | 338 | } |
339 | 339 | } |
340 | - }else{ |
|
340 | + } else { |
|
341 | 341 | $this->build_files_list(); |
342 | 342 | } |
343 | 343 | |
344 | - if($this->scan_finished()) |
|
344 | + if ($this->scan_finished()) |
|
345 | 345 | { |
346 | 346 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html"); |
347 | 347 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
348 | 348 | $this->files_counter++; |
349 | 349 | |
350 | 350 | //adding included dump file to the included files list |
351 | - if($this->get_tmp_filesystem()->has($this->get_included_files_handler())) |
|
351 | + if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) |
|
352 | 352 | { |
353 | 353 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler()); |
354 | 354 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
@@ -356,13 +356,13 @@ discard block |
||
356 | 356 | } |
357 | 357 | |
358 | 358 | //adding a default index.html to the temp xcloner folder |
359 | - if(!$this->get_tmp_filesystem()->has("index.html")) |
|
359 | + if (!$this->get_tmp_filesystem()->has("index.html")) |
|
360 | 360 | { |
361 | - $this->get_tmp_filesystem()->write("index.html",""); |
|
361 | + $this->get_tmp_filesystem()->write("index.html", ""); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | //adding the default log file |
365 | - if($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) |
|
365 | + if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) |
|
366 | 366 | { |
367 | 367 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1)); |
368 | 368 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | { |
380 | 380 | $return = array(); |
381 | 381 | $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler(); |
382 | - if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
382 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
383 | 383 | $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); |
384 | 384 | |
385 | 385 | return $return; |
@@ -392,8 +392,8 @@ discard block |
||
392 | 392 | |
393 | 393 | $contents = $this->get_tmp_filesystem()->listContents(); |
394 | 394 | |
395 | - if(is_array($contents)) |
|
396 | - foreach($contents as $file_info) |
|
395 | + if (is_array($contents)) |
|
396 | + foreach ($contents as $file_info) |
|
397 | 397 | $this->get_tmp_filesystem()->delete($file_info['path']); |
398 | 398 | |
399 | 399 | @rmdir($this->xcloner_settings->get_xcloner_tmp_path()); |
@@ -405,16 +405,16 @@ discard block |
||
405 | 405 | { |
406 | 406 | $this->files_counter = 0; |
407 | 407 | |
408 | - if(!$this->storage_filesystem->has("index.html")) |
|
409 | - $this->storage_filesystem->write("index.html",""); |
|
408 | + if (!$this->storage_filesystem->has("index.html")) |
|
409 | + $this->storage_filesystem->write("index.html", ""); |
|
410 | 410 | |
411 | - if(!$this->tmp_filesystem->has("index.html")) |
|
412 | - $this->tmp_filesystem->write("index.html",""); |
|
411 | + if (!$this->tmp_filesystem->has("index.html")) |
|
412 | + $this->tmp_filesystem->write("index.html", ""); |
|
413 | 413 | |
414 | - if($this->tmp_filesystem->has($this->get_included_files_handler())) |
|
414 | + if ($this->tmp_filesystem->has($this->get_included_files_handler())) |
|
415 | 415 | $this->tmp_filesystem->delete($this->get_included_files_handler()); |
416 | 416 | |
417 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
417 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
418 | 418 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
419 | 419 | } |
420 | 420 | |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | |
436 | 436 | public function set_excluded_files($excluded_files = array()) |
437 | 437 | { |
438 | - if(!is_array($excluded_files)) |
|
438 | + if (!is_array($excluded_files)) |
|
439 | 439 | $excluded_files = array(); |
440 | 440 | |
441 | 441 | $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default); |
@@ -458,33 +458,33 @@ discard block |
||
458 | 458 | $this->logger->debug(sprintf(("Building the files system list"))); |
459 | 459 | |
460 | 460 | //if we start with the root folder(empty value), we initializa the file system |
461 | - if(!$folder){ |
|
461 | + if (!$folder) { |
|
462 | 462 | |
463 | 463 | } |
464 | 464 | |
465 | - try{ |
|
465 | + try { |
|
466 | 466 | |
467 | 467 | $files = $this->start_filesystem->listContents($folder); |
468 | - foreach($files as $file) |
|
468 | + foreach ($files as $file) |
|
469 | 469 | { |
470 | - if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) |
|
470 | + if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) |
|
471 | 471 | { |
472 | - $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE")); |
|
472 | + $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN", "NOT READABLE")); |
|
473 | 473 | } |
474 | - elseif(!$matching_pattern = $this->is_excluded($file) ){ |
|
475 | - $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE")); |
|
474 | + elseif (!$matching_pattern = $this->is_excluded($file)) { |
|
475 | + $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN", "INCLUDE")); |
|
476 | 476 | $file['visibility'] = $this->start_filesystem->getVisibility($file['path']); |
477 | 477 | $this->store_file($file); |
478 | 478 | $this->files_counter++; |
479 | - if(isset($file['size'])) |
|
479 | + if (isset($file['size'])) |
|
480 | 480 | $this->files_size += $file['size']; |
481 | 481 | |
482 | - }else{ |
|
483 | - $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE")); |
|
482 | + } else { |
|
483 | + $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN", "EXCLUDE")); |
|
484 | 484 | } |
485 | 485 | } |
486 | 486 | |
487 | - }catch(Exception $e){ |
|
487 | + }catch (Exception $e) { |
|
488 | 488 | |
489 | 489 | $this->logger->error($e->getMessage()); |
490 | 490 | |
@@ -498,9 +498,9 @@ discard block |
||
498 | 498 | |
499 | 499 | $start_time = microtime(); |
500 | 500 | |
501 | - $data = str_repeat(rand(0,9), 1024*1024); //write 1MB data |
|
501 | + $data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data |
|
502 | 502 | |
503 | - try{ |
|
503 | + try { |
|
504 | 504 | $this->tmp_filesystem->write($tmp_file, $data); |
505 | 505 | |
506 | 506 | $end_time = microtime() - $start_time; |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | |
512 | 512 | $this->tmp_filesystem->delete($tmp_file); |
513 | 513 | |
514 | - }catch(Exception $e){ |
|
514 | + }catch (Exception $e) { |
|
515 | 515 | |
516 | 516 | $this->logger->error($e->getMessage()); |
517 | 517 | |
@@ -532,10 +532,10 @@ discard block |
||
532 | 532 | |
533 | 533 | $files = $this->storage_filesystem->listContents(); |
534 | 534 | |
535 | - if(is_array($files)) |
|
536 | - foreach($files as $file) |
|
535 | + if (is_array($files)) |
|
536 | + foreach ($files as $file) |
|
537 | 537 | { |
538 | - if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) |
|
538 | + if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) |
|
539 | 539 | { |
540 | 540 | $_storage_size += $file['size']; //bytes |
541 | 541 | $_backup_files_list[] = $file; |
@@ -543,15 +543,15 @@ discard block |
||
543 | 543 | } |
544 | 544 | |
545 | 545 | |
546 | - $this->sort_by($_backup_files_list, "timestamp","asc"); |
|
546 | + $this->sort_by($_backup_files_list, "timestamp", "asc"); |
|
547 | 547 | |
548 | 548 | $_backups_counter = sizeof($_backup_files_list); |
549 | 549 | |
550 | - foreach($_backup_files_list as $file) |
|
550 | + foreach ($_backup_files_list as $file) |
|
551 | 551 | { |
552 | 552 | //processing rule folder capacity |
553 | - if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
|
554 | - $_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
553 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
|
554 | + $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
555 | 555 | { |
556 | 556 | $this->storage_filesystem->delete($file['path']); |
557 | 557 | $_storage_size -= $file['size']; |
@@ -559,14 +559,14 @@ discard block |
||
559 | 559 | } |
560 | 560 | |
561 | 561 | //processing rule days limit |
562 | - if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) |
|
562 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) |
|
563 | 563 | { |
564 | 564 | $this->storage_filesystem->delete($file['path']); |
565 | 565 | $this->logger->info("Deleting backup ".$file['path']." matching rule", array("RETENTION LIMIT TIMESTAMP", $file['timestamp']." =< ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days'))); |
566 | 566 | } |
567 | 567 | |
568 | 568 | //processing backup countert limit |
569 | - if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') && $_backups_counter >= $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')) |
|
569 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') && $_backups_counter >= $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')) |
|
570 | 570 | { |
571 | 571 | $this->storage_filesystem->delete($file['path']); |
572 | 572 | $_backups_counter--; |
@@ -592,33 +592,33 @@ discard block |
||
592 | 592 | |
593 | 593 | } |
594 | 594 | |
595 | - public function process_backup_name($name = "", $max_length=100) |
|
595 | + public function process_backup_name($name = "", $max_length = 100) |
|
596 | 596 | { |
597 | - if(!$name) |
|
597 | + if (!$name) |
|
598 | 598 | $name = $this->xcloner_settings->get_default_backup_name(); |
599 | 599 | |
600 | - foreach($this->backup_name_tags as $tag) |
|
600 | + foreach ($this->backup_name_tags as $tag) |
|
601 | 601 | { |
602 | - if($tag == '[time]') |
|
603 | - $name = str_replace($tag, date("Y-m-d_H-i"),$name); |
|
604 | - elseif($tag == '[hostname]') |
|
605 | - $name = str_replace($tag, gethostname() ,$name); |
|
606 | - elseif($tag == '[domain]') |
|
602 | + if ($tag == '[time]') |
|
603 | + $name = str_replace($tag, date("Y-m-d_H-i"), $name); |
|
604 | + elseif ($tag == '[hostname]') |
|
605 | + $name = str_replace($tag, gethostname(), $name); |
|
606 | + elseif ($tag == '[domain]') |
|
607 | 607 | { |
608 | 608 | $domain = parse_url(admin_url(), PHP_URL_HOST); |
609 | - $name = str_replace($tag, $domain ,$name); |
|
609 | + $name = str_replace($tag, $domain, $name); |
|
610 | 610 | } |
611 | 611 | } |
612 | 612 | |
613 | - if($max_length) |
|
613 | + if ($max_length) |
|
614 | 614 | $name = substr($name, 0, $max_length); |
615 | 615 | |
616 | 616 | return $name; |
617 | 617 | } |
618 | 618 | |
619 | - public function sort_by( &$array, $field, $direction = 'asc') |
|
619 | + public function sort_by(&$array, $field, $direction = 'asc') |
|
620 | 620 | { |
621 | - if(strtolower($direction) == "desc" || $direction == SORT_DESC) |
|
621 | + if (strtolower($direction) == "desc" || $direction == SORT_DESC) |
|
622 | 622 | $direction = SORT_DESC; |
623 | 623 | else |
624 | 624 | $direction = SORT_ASC; |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | $tmp = array(); |
639 | 639 | foreach ($data as $key => $row) |
640 | 640 | { |
641 | - if(is_array($row)) |
|
641 | + if (is_array($row)) |
|
642 | 642 | $tmp[$key] = $row[$field]; |
643 | 643 | else |
644 | 644 | $tmp[$key] = $row->$field; |
@@ -657,29 +657,29 @@ discard block |
||
657 | 657 | { |
658 | 658 | $this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path'])); |
659 | 659 | |
660 | - if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) |
|
660 | + if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) |
|
661 | 661 | { |
662 | - if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) |
|
662 | + if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) |
|
663 | 663 | return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
664 | 664 | } |
665 | 665 | |
666 | - if(!sizeof($this->excluded_files)) |
|
666 | + if (!sizeof($this->excluded_files)) |
|
667 | 667 | $this->set_excluded_files(); |
668 | 668 | |
669 | - if(is_array($this->excluded_files)) |
|
670 | - foreach($this->excluded_files as $excluded_file_pattern) |
|
669 | + if (is_array($this->excluded_files)) |
|
670 | + foreach ($this->excluded_files as $excluded_file_pattern) |
|
671 | 671 | { |
672 | - if($excluded_file_pattern == "/") |
|
672 | + if ($excluded_file_pattern == "/") |
|
673 | 673 | $needle = "$"; |
674 | 674 | else |
675 | 675 | $needle = "$".$excluded_file_pattern; |
676 | 676 | |
677 | - if(strstr("$".$file['path'], $needle)){ |
|
677 | + if (strstr("$".$file['path'], $needle)) { |
|
678 | 678 | return $excluded_file_pattern; |
679 | 679 | } |
680 | 680 | } |
681 | 681 | |
682 | - if( $regex = $this->is_excluded_regex($file)) |
|
682 | + if ($regex = $this->is_excluded_regex($file)) |
|
683 | 683 | return $regex; |
684 | 684 | |
685 | 685 | return false; |
@@ -725,25 +725,25 @@ discard block |
||
725 | 725 | |
726 | 726 | //print_r($regex_patterns);exit; |
727 | 727 | |
728 | - if(is_array($regex_patterns)) |
|
728 | + if (is_array($regex_patterns)) |
|
729 | 729 | { |
730 | 730 | //$this->excluded_files = array(); |
731 | 731 | //$this->excluded_files[] ="(.*)\.(git)(.*)$"; |
732 | 732 | //$this->excluded_files[] ="wp-content\/backups(.*)$"; |
733 | 733 | |
734 | - foreach($regex_patterns as $excluded_file_pattern) |
|
734 | + foreach ($regex_patterns as $excluded_file_pattern) |
|
735 | 735 | { |
736 | 736 | |
737 | - if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") |
|
738 | - $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); |
|
737 | + if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1, strlen($excluded_file_pattern)) == "\r") |
|
738 | + $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1); |
|
739 | 739 | |
740 | - if($file['path'] == "/") |
|
740 | + if ($file['path'] == "/") |
|
741 | 741 | $needle = "/"; |
742 | 742 | else |
743 | 743 | $needle = "/".$file['path']; |
744 | 744 | //echo $needle."---".$excluded_file_pattern."---\n"; |
745 | 745 | |
746 | - if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){ |
|
746 | + if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) { |
|
747 | 747 | return $excluded_file_pattern; |
748 | 748 | } |
749 | 749 | } |
@@ -756,27 +756,27 @@ discard block |
||
756 | 756 | { |
757 | 757 | $this->logger->debug(sprintf("Storing %s in the backup list", $file['path'])); |
758 | 758 | |
759 | - if(!isset($file['size'])) |
|
759 | + if (!isset($file['size'])) |
|
760 | 760 | $file['size'] = 0; |
761 | - if(!isset($file['visibility'])) |
|
761 | + if (!isset($file['visibility'])) |
|
762 | 762 | $file['visibility'] = "private"; |
763 | 763 | |
764 | 764 | $line = '"'.addslashes($file['path']).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL; |
765 | 765 | |
766 | 766 | $this->last_logged_file = $file['path']; |
767 | 767 | |
768 | - try{ |
|
768 | + try { |
|
769 | 769 | $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); |
770 | 770 | |
771 | - }catch(Exception $e){ |
|
771 | + }catch (Exception $e) { |
|
772 | 772 | |
773 | 773 | $this->logger->error($e->getMessage()); |
774 | 774 | } |
775 | 775 | |
776 | - if($file['type'] == "dir"){ |
|
777 | - try{ |
|
776 | + if ($file['type'] == "dir") { |
|
777 | + try { |
|
778 | 778 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n"); |
779 | - }catch(Exception $e){ |
|
779 | + }catch (Exception $e) { |
|
780 | 780 | $this->logger->error($e->getMessage()); |
781 | 781 | } |
782 | 782 | } |
@@ -789,13 +789,13 @@ discard block |
||
789 | 789 | |
790 | 790 | public function get_filesystem($system = "") |
791 | 791 | { |
792 | - if($system == "storage_filesystem_append") |
|
792 | + if ($system == "storage_filesystem_append") |
|
793 | 793 | return $this->storage_filesystem_append; |
794 | - elseif($system == "tmp_filesystem_append") |
|
794 | + elseif ($system == "tmp_filesystem_append") |
|
795 | 795 | return $this->tmp_filesystem_append; |
796 | - elseif($system == "tmp_filesystem") |
|
796 | + elseif ($system == "tmp_filesystem") |
|
797 | 797 | return $this->tmp_filesystem; |
798 | - elseif($system == "storage_filesystem") |
|
798 | + elseif ($system == "storage_filesystem") |
|
799 | 799 | return $this->storage_filesystem; |
800 | 800 | else |
801 | 801 | return $this->start_filesystem; |
@@ -803,9 +803,9 @@ discard block |
||
803 | 803 | |
804 | 804 | public function get_adapter($system) |
805 | 805 | { |
806 | - if($system == "tmp_filesystem") |
|
806 | + if ($system == "tmp_filesystem") |
|
807 | 807 | return $this->tmp_adapter; |
808 | - elseif($system == "storage_filesystem") |
|
808 | + elseif ($system == "storage_filesystem") |
|
809 | 809 | return $this->storage_adapter; |
810 | 810 | else |
811 | 811 | return $this->start_adapter; |
@@ -813,10 +813,10 @@ discard block |
||
813 | 813 | |
814 | 814 | private function scan_finished() |
815 | 815 | { |
816 | - if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) |
|
816 | + if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) |
|
817 | 817 | return false; |
818 | 818 | |
819 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
819 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
820 | 820 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
821 | 821 | |
822 | 822 | $this->logger->debug(sprintf(("File scan finished"))); |
@@ -826,7 +826,7 @@ discard block |
||
826 | 826 | |
827 | 827 | private function calc_to_bytes($mb_size) |
828 | 828 | { |
829 | - return $mb_size*(1024*1024); |
|
829 | + return $mb_size * (1024 * 1024); |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | } |
@@ -61,13 +61,14 @@ discard block |
||
61 | 61 | $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ |
62 | 62 | 'disable_asserts' => true, |
63 | 63 | ])); |
64 | - }catch(Exception $e){ |
|
64 | + } catch(Exception $e){ |
|
65 | 65 | return false; |
66 | 66 | } |
67 | 67 | |
68 | 68 | |
69 | - if($value = get_option('xcloner_directories_to_scan_per_request')) |
|
70 | - $this->folders_to_process_per_session = $value; |
|
69 | + if($value = get_option('xcloner_directories_to_scan_per_request')) { |
|
70 | + $this->folders_to_process_per_session = $value; |
|
71 | + } |
|
71 | 72 | |
72 | 73 | } |
73 | 74 | |
@@ -130,8 +131,9 @@ discard block |
||
130 | 131 | public function get_included_files_handler($metadata = 0) |
131 | 132 | { |
132 | 133 | $path = $this->included_files_handler; |
133 | - if(!$metadata) |
|
134 | - return $path; |
|
134 | + if(!$metadata) { |
|
135 | + return $path; |
|
136 | + } |
|
135 | 137 | |
136 | 138 | $spl_info = $this->getMetadataFull('tmp_adapter', $path); |
137 | 139 | return $spl_info; |
@@ -147,31 +149,36 @@ discard block |
||
147 | 149 | { |
148 | 150 | $files = $this->get_backup_archives_list(); |
149 | 151 | |
150 | - if(is_array($files)) |
|
151 | - $this->sort_by($files, "timestamp","desc"); |
|
152 | + if(is_array($files)) { |
|
153 | + $this->sort_by($files, "timestamp","desc"); |
|
154 | + } |
|
152 | 155 | |
153 | 156 | $new_list = array(); |
154 | 157 | |
155 | - foreach($files as $key=>$file) |
|
156 | - if(!isset($file['parent'])) |
|
158 | + foreach($files as $key=>$file) { |
|
159 | + if(!isset($file['parent'])) |
|
157 | 160 | $new_list[] = ($files[$key]); |
161 | + } |
|
158 | 162 | |
159 | - if(isset($new_list[0])) |
|
160 | - return $new_list[0]; |
|
163 | + if(isset($new_list[0])) { |
|
164 | + return $new_list[0]; |
|
165 | + } |
|
161 | 166 | } |
162 | 167 | |
163 | 168 | public function get_latest_backups() |
164 | 169 | { |
165 | 170 | $files = $this->get_backup_archives_list(); |
166 | 171 | |
167 | - if(is_array($files)) |
|
168 | - $this->sort_by($files, "timestamp","desc"); |
|
172 | + if(is_array($files)) { |
|
173 | + $this->sort_by($files, "timestamp","desc"); |
|
174 | + } |
|
169 | 175 | |
170 | 176 | $new_list = array(); |
171 | 177 | |
172 | - foreach($files as $key=>$file) |
|
173 | - if(!isset($file['parent'])) |
|
178 | + foreach($files as $key=>$file) { |
|
179 | + if(!isset($file['parent'])) |
|
174 | 180 | $new_list[] = ($files[$key]); |
181 | + } |
|
175 | 182 | |
176 | 183 | return $new_list; |
177 | 184 | } |
@@ -181,25 +188,28 @@ discard block |
||
181 | 188 | $files = $this->get_backup_archives_list(); |
182 | 189 | $total = 0; |
183 | 190 | |
184 | - if(is_array($files)) |
|
185 | - foreach($files as $file) |
|
191 | + if(is_array($files)) { |
|
192 | + foreach($files as $file) |
|
186 | 193 | $total += $file['size']; |
194 | + } |
|
187 | 195 | |
188 | 196 | return $total; |
189 | 197 | } |
190 | 198 | |
191 | 199 | public function is_part($backup_name) |
192 | 200 | { |
193 | - if(stristr($backup_name, "-part")) |
|
194 | - return true; |
|
201 | + if(stristr($backup_name, "-part")) { |
|
202 | + return true; |
|
203 | + } |
|
195 | 204 | |
196 | 205 | return false; |
197 | 206 | } |
198 | 207 | |
199 | 208 | public function is_multipart($backup_name) |
200 | 209 | { |
201 | - if(stristr($backup_name, "-multipart")) |
|
202 | - return true; |
|
210 | + if(stristr($backup_name, "-multipart")) { |
|
211 | + return true; |
|
212 | + } |
|
203 | 213 | |
204 | 214 | return false; |
205 | 215 | } |
@@ -210,8 +220,9 @@ discard block |
||
210 | 220 | if($this->is_multipart($backup_name)) |
211 | 221 | { |
212 | 222 | $backup_parts = $this->get_multipart_files($backup_name); |
213 | - foreach($backup_parts as $part_file) |
|
214 | - $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
|
223 | + foreach($backup_parts as $part_file) { |
|
224 | + $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
|
225 | + } |
|
215 | 226 | } |
216 | 227 | |
217 | 228 | return $backup_size; |
@@ -252,10 +263,11 @@ discard block |
||
252 | 263 | } |
253 | 264 | } |
254 | 265 | |
255 | - if($this->get_storage_filesystem()->delete($backup_name)) |
|
256 | - $return = true; |
|
257 | - else |
|
258 | - $return = false; |
|
266 | + if($this->get_storage_filesystem()->delete($backup_name)) { |
|
267 | + $return = true; |
|
268 | + } else { |
|
269 | + $return = false; |
|
270 | + } |
|
259 | 271 | |
260 | 272 | return $return; |
261 | 273 | } |
@@ -273,8 +285,9 @@ discard block |
||
273 | 285 | { |
274 | 286 | $list = array(); |
275 | 287 | |
276 | - if(method_exists($this->get_storage_filesystem(), "listContents")) |
|
277 | - $list = $this->get_storage_filesystem()->listContents(); |
|
288 | + if(method_exists($this->get_storage_filesystem(), "listContents")) { |
|
289 | + $list = $this->get_storage_filesystem()->listContents(); |
|
290 | + } |
|
278 | 291 | |
279 | 292 | |
280 | 293 | $backup_files = array(); |
@@ -287,10 +300,11 @@ discard block |
||
287 | 300 | if(isset($file_info['extension']) and $file_info['extension'] == "csv") |
288 | 301 | { |
289 | 302 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($file_info['path'])); |
290 | - foreach($lines as $line) |
|
291 | - if($line) |
|
303 | + foreach($lines as $line) { |
|
304 | + if($line) |
|
292 | 305 | { |
293 | 306 | $data = str_getcsv($line); |
307 | + } |
|
294 | 308 | if(is_array($data)){ |
295 | 309 | $parents[$data[0]] = $file_info['path']; |
296 | 310 | $file_info['childs'][] = $data; |
@@ -300,14 +314,16 @@ discard block |
||
300 | 314 | |
301 | 315 | } |
302 | 316 | |
303 | - if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
304 | - $backup_files[$file_info['path']] = $file_info; |
|
317 | + if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) { |
|
318 | + $backup_files[$file_info['path']] = $file_info; |
|
319 | + } |
|
305 | 320 | } |
306 | 321 | |
307 | 322 | foreach($backup_files as $key=>$file_info) |
308 | 323 | { |
309 | - if(isset($parents[$file_info['path']])) |
|
310 | - $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
324 | + if(isset($parents[$file_info['path']])) { |
|
325 | + $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
326 | + } |
|
311 | 327 | } |
312 | 328 | |
313 | 329 | return $backup_files; |
@@ -333,11 +349,11 @@ discard block |
||
333 | 349 | if($counter < $this->folders_to_process_per_session){ |
334 | 350 | $this->build_files_list($file); |
335 | 351 | $counter++; |
336 | - }else{ |
|
352 | + } else{ |
|
337 | 353 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n"); |
338 | 354 | } |
339 | 355 | } |
340 | - }else{ |
|
356 | + } else{ |
|
341 | 357 | $this->build_files_list(); |
342 | 358 | } |
343 | 359 | |
@@ -379,8 +395,9 @@ discard block |
||
379 | 395 | { |
380 | 396 | $return = array(); |
381 | 397 | $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler(); |
382 | - if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
383 | - $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); |
|
398 | + if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
|
399 | + $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); |
|
400 | + } |
|
384 | 401 | |
385 | 402 | return $return; |
386 | 403 | } |
@@ -392,9 +409,10 @@ discard block |
||
392 | 409 | |
393 | 410 | $contents = $this->get_tmp_filesystem()->listContents(); |
394 | 411 | |
395 | - if(is_array($contents)) |
|
396 | - foreach($contents as $file_info) |
|
412 | + if(is_array($contents)) { |
|
413 | + foreach($contents as $file_info) |
|
397 | 414 | $this->get_tmp_filesystem()->delete($file_info['path']); |
415 | + } |
|
398 | 416 | |
399 | 417 | @rmdir($this->xcloner_settings->get_xcloner_tmp_path()); |
400 | 418 | |
@@ -405,17 +423,21 @@ discard block |
||
405 | 423 | { |
406 | 424 | $this->files_counter = 0; |
407 | 425 | |
408 | - if(!$this->storage_filesystem->has("index.html")) |
|
409 | - $this->storage_filesystem->write("index.html",""); |
|
426 | + if(!$this->storage_filesystem->has("index.html")) { |
|
427 | + $this->storage_filesystem->write("index.html",""); |
|
428 | + } |
|
410 | 429 | |
411 | - if(!$this->tmp_filesystem->has("index.html")) |
|
412 | - $this->tmp_filesystem->write("index.html",""); |
|
430 | + if(!$this->tmp_filesystem->has("index.html")) { |
|
431 | + $this->tmp_filesystem->write("index.html",""); |
|
432 | + } |
|
413 | 433 | |
414 | - if($this->tmp_filesystem->has($this->get_included_files_handler())) |
|
415 | - $this->tmp_filesystem->delete($this->get_included_files_handler()); |
|
434 | + if($this->tmp_filesystem->has($this->get_included_files_handler())) { |
|
435 | + $this->tmp_filesystem->delete($this->get_included_files_handler()); |
|
436 | + } |
|
416 | 437 | |
417 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
418 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
438 | + if($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
439 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
440 | + } |
|
419 | 441 | } |
420 | 442 | |
421 | 443 | public function get_scanned_files_num() |
@@ -435,8 +457,9 @@ discard block |
||
435 | 457 | |
436 | 458 | public function set_excluded_files($excluded_files = array()) |
437 | 459 | { |
438 | - if(!is_array($excluded_files)) |
|
439 | - $excluded_files = array(); |
|
460 | + if(!is_array($excluded_files)) { |
|
461 | + $excluded_files = array(); |
|
462 | + } |
|
440 | 463 | |
441 | 464 | $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default); |
442 | 465 | |
@@ -470,21 +493,21 @@ discard block |
||
470 | 493 | if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) |
471 | 494 | { |
472 | 495 | $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE")); |
473 | - } |
|
474 | - elseif(!$matching_pattern = $this->is_excluded($file) ){ |
|
496 | + } elseif(!$matching_pattern = $this->is_excluded($file) ){ |
|
475 | 497 | $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE")); |
476 | 498 | $file['visibility'] = $this->start_filesystem->getVisibility($file['path']); |
477 | 499 | $this->store_file($file); |
478 | 500 | $this->files_counter++; |
479 | - if(isset($file['size'])) |
|
480 | - $this->files_size += $file['size']; |
|
501 | + if(isset($file['size'])) { |
|
502 | + $this->files_size += $file['size']; |
|
503 | + } |
|
481 | 504 | |
482 | - }else{ |
|
505 | + } else{ |
|
483 | 506 | $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE")); |
484 | 507 | } |
485 | 508 | } |
486 | 509 | |
487 | - }catch(Exception $e){ |
|
510 | + } catch(Exception $e){ |
|
488 | 511 | |
489 | 512 | $this->logger->error($e->getMessage()); |
490 | 513 | |
@@ -511,7 +534,7 @@ discard block |
||
511 | 534 | |
512 | 535 | $this->tmp_filesystem->delete($tmp_file); |
513 | 536 | |
514 | - }catch(Exception $e){ |
|
537 | + } catch(Exception $e){ |
|
515 | 538 | |
516 | 539 | $this->logger->error($e->getMessage()); |
517 | 540 | |
@@ -532,12 +555,14 @@ discard block |
||
532 | 555 | |
533 | 556 | $files = $this->storage_filesystem->listContents(); |
534 | 557 | |
535 | - if(is_array($files)) |
|
536 | - foreach($files as $file) |
|
558 | + if(is_array($files)) { |
|
559 | + foreach($files as $file) |
|
537 | 560 | { |
538 | 561 | if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) |
539 | 562 | { |
540 | - $_storage_size += $file['size']; //bytes |
|
563 | + $_storage_size += $file['size']; |
|
564 | + } |
|
565 | + //bytes |
|
541 | 566 | $_backup_files_list[] = $file; |
542 | 567 | } |
543 | 568 | } |
@@ -551,9 +576,11 @@ discard block |
||
551 | 576 | { |
552 | 577 | //processing rule folder capacity |
553 | 578 | if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
554 | - $_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
579 | + $_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) { |
|
580 | + //bytes |
|
555 | 581 | { |
556 | 582 | $this->storage_filesystem->delete($file['path']); |
583 | + } |
|
557 | 584 | $_storage_size -= $file['size']; |
558 | 585 | $this->logger->info("Deleting backup ".$file['path']." matching rule", array("STORAGE SIZE LIMIT", $_storage_size." >= ".$set_storage_limit)); |
559 | 586 | } |
@@ -594,34 +621,37 @@ discard block |
||
594 | 621 | |
595 | 622 | public function process_backup_name($name = "", $max_length=100) |
596 | 623 | { |
597 | - if(!$name) |
|
598 | - $name = $this->xcloner_settings->get_default_backup_name(); |
|
624 | + if(!$name) { |
|
625 | + $name = $this->xcloner_settings->get_default_backup_name(); |
|
626 | + } |
|
599 | 627 | |
600 | 628 | foreach($this->backup_name_tags as $tag) |
601 | 629 | { |
602 | - if($tag == '[time]') |
|
603 | - $name = str_replace($tag, date("Y-m-d_H-i"),$name); |
|
604 | - elseif($tag == '[hostname]') |
|
605 | - $name = str_replace($tag, gethostname() ,$name); |
|
606 | - elseif($tag == '[domain]') |
|
630 | + if($tag == '[time]') { |
|
631 | + $name = str_replace($tag, date("Y-m-d_H-i"),$name); |
|
632 | + } elseif($tag == '[hostname]') { |
|
633 | + $name = str_replace($tag, gethostname() ,$name); |
|
634 | + } elseif($tag == '[domain]') |
|
607 | 635 | { |
608 | 636 | $domain = parse_url(admin_url(), PHP_URL_HOST); |
609 | 637 | $name = str_replace($tag, $domain ,$name); |
610 | 638 | } |
611 | 639 | } |
612 | 640 | |
613 | - if($max_length) |
|
614 | - $name = substr($name, 0, $max_length); |
|
641 | + if($max_length) { |
|
642 | + $name = substr($name, 0, $max_length); |
|
643 | + } |
|
615 | 644 | |
616 | 645 | return $name; |
617 | 646 | } |
618 | 647 | |
619 | 648 | public function sort_by( &$array, $field, $direction = 'asc') |
620 | 649 | { |
621 | - if(strtolower($direction) == "desc" || $direction == SORT_DESC) |
|
622 | - $direction = SORT_DESC; |
|
623 | - else |
|
624 | - $direction = SORT_ASC; |
|
650 | + if(strtolower($direction) == "desc" || $direction == SORT_DESC) { |
|
651 | + $direction = SORT_DESC; |
|
652 | + } else { |
|
653 | + $direction = SORT_ASC; |
|
654 | + } |
|
625 | 655 | |
626 | 656 | $array = $this->array_orderby($array, $field, $direction); |
627 | 657 | |
@@ -638,10 +668,11 @@ discard block |
||
638 | 668 | $tmp = array(); |
639 | 669 | foreach ($data as $key => $row) |
640 | 670 | { |
641 | - if(is_array($row)) |
|
642 | - $tmp[$key] = $row[$field]; |
|
643 | - else |
|
644 | - $tmp[$key] = $row->$field; |
|
671 | + if(is_array($row)) { |
|
672 | + $tmp[$key] = $row[$field]; |
|
673 | + } else { |
|
674 | + $tmp[$key] = $row->$field; |
|
675 | + } |
|
645 | 676 | } |
646 | 677 | $args[$n] = $tmp; |
647 | 678 | } |
@@ -659,28 +690,32 @@ discard block |
||
659 | 690 | |
660 | 691 | if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) |
661 | 692 | { |
662 | - if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) |
|
663 | - return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
|
693 | + if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) { |
|
694 | + return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
|
695 | + } |
|
664 | 696 | } |
665 | 697 | |
666 | - if(!sizeof($this->excluded_files)) |
|
667 | - $this->set_excluded_files(); |
|
698 | + if(!sizeof($this->excluded_files)) { |
|
699 | + $this->set_excluded_files(); |
|
700 | + } |
|
668 | 701 | |
669 | - if(is_array($this->excluded_files)) |
|
670 | - foreach($this->excluded_files as $excluded_file_pattern) |
|
702 | + if(is_array($this->excluded_files)) { |
|
703 | + foreach($this->excluded_files as $excluded_file_pattern) |
|
671 | 704 | { |
672 | 705 | if($excluded_file_pattern == "/") |
673 | 706 | $needle = "$"; |
674 | - else |
|
675 | - $needle = "$".$excluded_file_pattern; |
|
707 | + } else { |
|
708 | + $needle = "$".$excluded_file_pattern; |
|
709 | + } |
|
676 | 710 | |
677 | 711 | if(strstr("$".$file['path'], $needle)){ |
678 | 712 | return $excluded_file_pattern; |
679 | 713 | } |
680 | 714 | } |
681 | 715 | |
682 | - if( $regex = $this->is_excluded_regex($file)) |
|
683 | - return $regex; |
|
716 | + if( $regex = $this->is_excluded_regex($file)) { |
|
717 | + return $regex; |
|
718 | + } |
|
684 | 719 | |
685 | 720 | return false; |
686 | 721 | } |
@@ -734,13 +769,15 @@ discard block |
||
734 | 769 | foreach($regex_patterns as $excluded_file_pattern) |
735 | 770 | { |
736 | 771 | |
737 | - if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") |
|
738 | - $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); |
|
772 | + if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") { |
|
773 | + $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); |
|
774 | + } |
|
739 | 775 | |
740 | - if($file['path'] == "/") |
|
741 | - $needle = "/"; |
|
742 | - else |
|
743 | - $needle = "/".$file['path']; |
|
776 | + if($file['path'] == "/") { |
|
777 | + $needle = "/"; |
|
778 | + } else { |
|
779 | + $needle = "/".$file['path']; |
|
780 | + } |
|
744 | 781 | //echo $needle."---".$excluded_file_pattern."---\n"; |
745 | 782 | |
746 | 783 | if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){ |
@@ -756,10 +793,12 @@ discard block |
||
756 | 793 | { |
757 | 794 | $this->logger->debug(sprintf("Storing %s in the backup list", $file['path'])); |
758 | 795 | |
759 | - if(!isset($file['size'])) |
|
760 | - $file['size'] = 0; |
|
761 | - if(!isset($file['visibility'])) |
|
762 | - $file['visibility'] = "private"; |
|
796 | + if(!isset($file['size'])) { |
|
797 | + $file['size'] = 0; |
|
798 | + } |
|
799 | + if(!isset($file['visibility'])) { |
|
800 | + $file['visibility'] = "private"; |
|
801 | + } |
|
763 | 802 | |
764 | 803 | $line = '"'.addslashes($file['path']).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL; |
765 | 804 | |
@@ -768,7 +807,7 @@ discard block |
||
768 | 807 | try{ |
769 | 808 | $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); |
770 | 809 | |
771 | - }catch(Exception $e){ |
|
810 | + } catch(Exception $e){ |
|
772 | 811 | |
773 | 812 | $this->logger->error($e->getMessage()); |
774 | 813 | } |
@@ -776,7 +815,7 @@ discard block |
||
776 | 815 | if($file['type'] == "dir"){ |
777 | 816 | try{ |
778 | 817 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n"); |
779 | - }catch(Exception $e){ |
|
818 | + } catch(Exception $e){ |
|
780 | 819 | $this->logger->error($e->getMessage()); |
781 | 820 | } |
782 | 821 | } |
@@ -789,35 +828,39 @@ discard block |
||
789 | 828 | |
790 | 829 | public function get_filesystem($system = "") |
791 | 830 | { |
792 | - if($system == "storage_filesystem_append") |
|
793 | - return $this->storage_filesystem_append; |
|
794 | - elseif($system == "tmp_filesystem_append") |
|
795 | - return $this->tmp_filesystem_append; |
|
796 | - elseif($system == "tmp_filesystem") |
|
797 | - return $this->tmp_filesystem; |
|
798 | - elseif($system == "storage_filesystem") |
|
799 | - return $this->storage_filesystem; |
|
800 | - else |
|
801 | - return $this->start_filesystem; |
|
831 | + if($system == "storage_filesystem_append") { |
|
832 | + return $this->storage_filesystem_append; |
|
833 | + } elseif($system == "tmp_filesystem_append") { |
|
834 | + return $this->tmp_filesystem_append; |
|
835 | + } elseif($system == "tmp_filesystem") { |
|
836 | + return $this->tmp_filesystem; |
|
837 | + } elseif($system == "storage_filesystem") { |
|
838 | + return $this->storage_filesystem; |
|
839 | + } else { |
|
840 | + return $this->start_filesystem; |
|
841 | + } |
|
802 | 842 | } |
803 | 843 | |
804 | 844 | public function get_adapter($system) |
805 | 845 | { |
806 | - if($system == "tmp_filesystem") |
|
807 | - return $this->tmp_adapter; |
|
808 | - elseif($system == "storage_filesystem") |
|
809 | - return $this->storage_adapter; |
|
810 | - else |
|
811 | - return $this->start_adapter; |
|
846 | + if($system == "tmp_filesystem") { |
|
847 | + return $this->tmp_adapter; |
|
848 | + } elseif($system == "storage_filesystem") { |
|
849 | + return $this->storage_adapter; |
|
850 | + } else { |
|
851 | + return $this->start_adapter; |
|
852 | + } |
|
812 | 853 | } |
813 | 854 | |
814 | 855 | private function scan_finished() |
815 | 856 | { |
816 | - if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) |
|
817 | - return false; |
|
857 | + if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) { |
|
858 | + return false; |
|
859 | + } |
|
818 | 860 | |
819 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
820 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
861 | + if($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
862 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
863 | + } |
|
821 | 864 | |
822 | 865 | $this->logger->debug(sprintf(("File scan finished"))); |
823 | 866 |