GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Branch dev (4f6bab)
by Liuta
02:57
created
admin/partials/xcloner_manage_backups_page.php 1 patch
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,10 +31,13 @@
 block discarded – undo
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)
Please login to merge, or discard this patch.
admin/partials/xcloner_remote_storage_page.php 1 patch
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
                             <label>
27 27
                                 Off
28 28
                                 <input type="checkbox" name="xcloner_ftp_enable" class="status"
29
-                                       value="1" <?php if (get_option("xcloner_ftp_enable"))
29
+                                       value="1" <?php if (get_option("xcloner_ftp_enable")) {
30 30
 									echo "checked" ?> \>
31 31
                                 <span class="lever"></span>
32 32
                                 On
@@ -340,6 +340,7 @@  discard block
 block discarded – undo
340 340
                                             value=""><?php echo __("Please Select AWS S3 Region or Leave Unselected for Custom Endpoint") ?></option>
341 341
 									<?php
342 342
 									$aws_regions = $remote_storage->get_aws_regions();
343
+}
343 344
 
344 345
 									foreach ($aws_regions as $key => $region) {
345 346
 										?>
@@ -423,7 +424,7 @@  discard block
 block discarded – undo
423 424
                             <label>
424 425
                                 Off
425 426
                                 <input type="checkbox" name="xcloner_dropbox_enable" class="status"
426
-                                       value="1" <?php if (get_option("xcloner_dropbox_enable"))
427
+                                       value="1" <?php if (get_option("xcloner_dropbox_enable")) {
427 428
 									echo "checked" ?> \>
428 429
                                 <span class="lever"></span>
429 430
                                 On
@@ -957,6 +958,7 @@  discard block
 block discarded – undo
957 958
                                     <div class="center">
958 959
 										<?php
959 960
 										$url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=xcloner-google-drive'), 'install-plugin_xcloner-google-drive');
961
+}
960 962
 										?>
961 963
                                         <h6><?php echo __("This storage option requires the XCloner-Google-Drive Wordpress Plugin to be installed and activated.") ?></h6>
962 964
                                         <h6><?php echo __("PHP 5.5 minimum version is required.") ?></h6>
Please login to merge, or discard this patch.
admin/partials/xcloner_init_page.php 1 patch
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -110,7 +110,8 @@  discard block
 block discarded – undo
110 110
 											echo date($date_format." ".$time_format, $latest_backup['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS))
111 111
 											?>
112 112
                                         </div>
113
-									<?php else: ?>
113
+									<?php else {
114
+	: ?>
114 115
                                         <div class="item">
115 116
                                             <div class="title"><?php echo __("No Backup Yet", 'xcloner-backup-and-restore') ?></div>
116 117
                                         </div>
@@ -123,7 +124,9 @@  discard block
 block discarded – undo
123 124
                                             <div class="title"><?php echo __("Total Size", 'xcloner-backup-and-restore') ?>
124 125
                                                 :
125 126
                                             </div>
126
-											<?php echo size_format($xcloner_file_system->get_storage_usage()); ?>
127
+											<?php echo size_format($xcloner_file_system->get_storage_usage());
128
+}
129
+?>
127 130
                                         </div>
128 131
                                     </blockquote>
129 132
                                     <h5><?php echo __("Next Scheduled Backup", 'xcloner-backup-and-restore') ?></h5>
Please login to merge, or discard this patch.
includes/class-xcloner-file-system.php 2 patches
Indentation   +975 added lines, -975 removed lines patch added patch discarded remove patch
@@ -37,857 +37,857 @@  discard block
 block discarded – undo
37 37
 class Xcloner_File_System
38 38
 {
39 39
 
40
-    private $excluded_files = "";
41
-    private $additional_regex_patterns = array();
42
-    private $excluded_files_by_default = array("administrator/backups", "wp-content/backups");
43
-    private $included_files_handler = "backup_files.csv";
44
-    private $temp_dir_handler = ".dir";
45
-    public $filesystem;
46
-    public $tmp_filesystem;
47
-    public $storage_filesystem;
48
-    private $xcloner_container;
49
-    private $diff_timestamp_start = "";
50
-
51
-    private $logger;
52
-    private $start_adapter;
53
-    private $tmp_adapter;
54
-    private $storage_adapter;
55
-    private $xcloner_settings;
56
-    private $start_filesystem;
57
-    private $tmp_filesystem_append;
58
-    private $storage_filesystem_append;
59
-
60
-    private $files_counter;
61
-    private $files_size;
62
-    private $last_logged_file;
63
-    private $folders_to_process_per_session = 25;
64
-    private $backup_archive_extensions = array("tar", "tgz", "tar.gz", "gz", "csv", "encrypted", "decrypted");
65
-    private $backup_name_tags = array('[time]', '[hostname]', '[domain]');
66
-
67
-    /**
68
-     * Xcloner_File_System constructor.
69
-     * @param Xcloner $xcloner_container
70
-     * @param string $hash
71
-     */
72
-    public function __construct(Xcloner $xcloner_container, $hash = "")
73
-    {
74
-        $this->xcloner_container = $xcloner_container;
75
-
76
-        $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_file_system");
77
-        $this->xcloner_settings = $xcloner_container->get_xcloner_settings();
78
-
79
-        try {
80
-
81
-            $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS');
82
-            $this->start_filesystem = new Filesystem($this->start_adapter, new Config([
83
-                'disable_asserts' => true,
84
-            ]));
85
-
86
-            $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS');
87
-            $this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([
88
-                'disable_asserts' => true,
89
-            ]));
90
-            $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
91
-            $this->tmp_filesystem_append = new Filesystem($adapter, new Config([
92
-                'disable_asserts' => true,
93
-            ]));
94
-
95
-            $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS');
96
-            $this->storage_filesystem = new Filesystem($adapter, new Config([
97
-                'disable_asserts' => true,
98
-            ]));
99
-
100
-            $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND,
101
-                'SKIP_LINKS');
102
-            $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([
103
-                'disable_asserts' => true,
104
-            ]));
105
-        }catch (Exception $e) {
106
-            $this->logger->error("Filesystem Initialization Error: ".$e->getMessage());
107
-        }
108
-
109
-
110
-        if ($value = get_option('xcloner_directories_to_scan_per_request')) {
111
-            $this->folders_to_process_per_session = $value;
112
-        }
113
-
114
-    }
115
-
116
-    /**
117
-     * Set differential timestamp date
118
-     * @param string $timestamp
119
-     */
120
-    public function set_diff_timestamp_start($timestamp = "")
121
-    {
122
-        if ($timestamp) {
123
-            $this->logger->info(sprintf("Setting Differential Timestamp To %s", date("Y-m-d", $timestamp)), array(
124
-                "FILESYSTEM",
125
-                "DIFF"
126
-            ));
127
-            $this->diff_timestamp_start = $timestamp;
128
-        }
129
-    }
130
-
131
-    /**
132
-     * Gets the differential timestamp date
133
-     * @return string
134
-     */
135
-    public function get_diff_timestamp_start()
136
-    {
137
-        return $this->diff_timestamp_start;
138
-    }
139
-
140
-    private function get_xcloner_container()
141
-    {
142
-        return $this->xcloner_container;
143
-    }
144
-
145
-    public function set_hash($hash)
146
-    {
147
-        $this->xcloner_settings->set_hash($hash);
148
-    }
149
-
150
-    public function get_hash($hash)
151
-    {
152
-        $this->xcloner_settings->get_hash();
153
-    }
154
-
155
-    public function get_tmp_filesystem()
156
-    {
157
-        return $this->tmp_filesystem;
158
-    }
159
-
160
-    public function get_storage_filesystem($remote_storage_selection = "")
161
-    {
162
-        if ($remote_storage_selection != "") {
163
-            $remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
164
-            $method = "get_".$remote_storage_selection."_filesystem";
165
-
166
-            if (!method_exists($remote_storage, $method)) {
167
-                return false;
168
-            }
169
-
170
-            list($adapter, $filesystem) = $remote_storage->$method();
171
-
172
-            return $filesystem;
173
-        }
174
-
175
-        return $this->storage_filesystem;
176
-    }
177
-
178
-    public function get_tmp_filesystem_adapter()
179
-    {
180
-        return $this->tmp_adapter;
181
-    }
182
-
183
-    public function get_tmp_filesystem_append()
184
-    {
185
-        return $this->tmp_filesystem_append;
186
-    }
187
-
188
-    public function get_start_adapter()
189
-    {
190
-        return $this->start_adapter;
191
-    }
192
-
193
-    public function get_start_filesystem()
194
-    {
195
-        return $this->start_filesystem;
196
-    }
197
-
198
-    public function get_logger()
199
-    {
200
-        return $this->logger;
201
-    }
202
-
203
-    public function get_start_path_file_info($file)
204
-    {
205
-        $info = $this->getMetadataFull('start_adapter', $file);
206
-
207
-        return $this->start_filesystem->normalizeFileInfo($info);
208
-    }
209
-
210
-    /**
211
-     * @param string $file
212
-     */
213
-    public function get_storage_path_file_info($file)
214
-    {
215
-        return $this->getMetadataFull('storage_adapter', $file);
216
-    }
217
-
218
-    public function get_included_files_handler($metadata = 0)
219
-    {
220
-        $path = $this->included_files_handler;
221
-        if (!$metadata) {
222
-            return $path;
223
-        }
224
-
225
-        $spl_info = $this->getMetadataFull('tmp_adapter', $path);
226
-
227
-        return $spl_info;
228
-
229
-    }
230
-
231
-    public function get_temp_dir_handler()
232
-    {
233
-        return $this->temp_dir_handler;
234
-    }
235
-
236
-    public function get_latest_backup()
237
-    {
238
-        $files = $this->get_backup_archives_list();
239
-
240
-        if (is_array($files)) {
241
-            $this->sort_by($files, "timestamp", "desc");
242
-        }
243
-
244
-        $new_list = array();
245
-
246
-        foreach ($files as $key => $file) {
247
-            if (!isset($file['parent'])) {
248
-                $new_list[] = ($files[$key]);
249
-            }
250
-        }
251
-
252
-        if (isset($new_list[0])) {
253
-            return $new_list[0];
254
-        }
255
-    }
256
-
257
-    public function get_latest_backups()
258
-    {
259
-        $files = $this->get_backup_archives_list();
260
-
261
-        if (is_array($files)) {
262
-            $this->sort_by($files, "timestamp", "desc");
263
-        }
264
-
265
-        $new_list = array();
266
-
267
-        foreach ($files as $key => $file) {
268
-            if (!isset($file['parent'])) {
269
-                $new_list[] = ($files[$key]);
270
-            }
271
-        }
272
-
273
-        return $new_list;
274
-    }
275
-
276
-    public function get_storage_usage()
277
-    {
278
-        $files = $this->get_backup_archives_list();
279
-        $total = 0;
280
-
281
-        if (is_array($files)) {
282
-            foreach ($files as $file) {
283
-                $total += $file['size'];
284
-            }
285
-        }
286
-
287
-        return $total;
288
-    }
289
-
290
-    public function is_part($backup_name)
291
-    {
292
-        if (stristr($backup_name, "-part")) {
293
-            return true;
294
-        }
295
-
296
-        return false;
297
-    }
298
-
299
-    public function is_multipart($backup_name)
300
-    {
301
-        if (stristr($backup_name, "-multipart")) {
302
-            return true;
303
-        }
304
-
305
-        return false;
306
-    }
307
-
308
-    public function get_backup_size($backup_name)
309
-    {
310
-        $backup_size = $this->get_storage_filesystem()->getSize($backup_name);
311
-        if ($this->is_multipart($backup_name)) {
312
-            $backup_parts = $this->get_multipart_files($backup_name);
313
-            foreach ($backup_parts as $part_file) {
314
-                $backup_size += $this->get_storage_filesystem()->getSize($part_file);
315
-            }
316
-        }
317
-
318
-        return $backup_size;
319
-    }
320
-
321
-    public function get_multipart_files($backup_name, $storage_selection = "")
322
-    {
323
-        $files = array();
324
-
325
-        if ($this->is_multipart($backup_name)) {
326
-            $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
327
-            foreach ($lines as $line) {
328
-                if ($line) {
329
-                    $data = str_getcsv($line);
330
-                    $files[] = $data[0];
331
-                }
332
-            }
333
-        }
334
-
335
-        return $files;
336
-    }
337
-
338
-    public function delete_backup_by_name($backup_name, $storage_selection = "")
339
-    {
340
-        if ($this->is_multipart($backup_name)) {
341
-            $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
342
-            foreach ($lines as $line) {
343
-                if ($line) {
344
-                    $data = str_getcsv($line);
345
-                    $this->get_storage_filesystem($storage_selection)->delete($data[0]);
346
-                }
347
-            }
348
-        }
349
-
350
-        if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) {
351
-            $return = true;
352
-        } else {
353
-            $return = false;
354
-        }
355
-
356
-        return $return;
357
-    }
358
-
359
-    public function getMetadataFull($adapter = "storage_adapter", $path)
360
-    {
361
-        $location = $this->$adapter->applyPathPrefix($path);
362
-        $spl_info = new SplFileInfo($location);
363
-
364
-        return ($spl_info);
365
-    }
366
-
367
-
368
-    public function get_backup_archives_list($storage_selection = "")
369
-    {
370
-        $list = array();
371
-
372
-
373
-        if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) {
374
-            $list = $this->get_storage_filesystem($storage_selection)->listContents();
375
-        }
376
-
377
-        $backup_files = array();
378
-        $parents = array();
379
-
380
-        foreach ($list as $file_info) {
381
-            if (isset($file_info['extension']) and $file_info['extension'] == "csv") {
382
-                $data = array();
383
-
384
-                $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path']));
385
-                foreach ($lines as $line) {
386
-                    if ($line) {
387
-                        $data = str_getcsv($line);
388
-                        if (is_array($data)) {
389
-                            $parents[$data[0]] = $file_info['basename'];
390
-                            $file_info['childs'][] = $data;
391
-                            $file_info['size'] += $data[2];
392
-                        }
393
-                    }
394
-                }
395
-
396
-            }
397
-
398
-            if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'],
399
-                    $this->backup_archive_extensions)) {
400
-                $backup_files[$file_info['path']] = $file_info;
401
-            }
402
-        }
403
-
404
-        foreach ($backup_files as $key => $file_info) {
405
-            if (!isset($backup_files[$key]['timestamp'])) {
406
-                //$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']);
407
-            }
408
-
409
-            if (isset($parents[$file_info['basename']])) {
410
-                $backup_files[$key]['parent'] = $parents[$file_info['basename']];
411
-            }
412
-        }
413
-
414
-        return $backup_files;
415
-    }
416
-
417
-    public function start_file_recursion($init = 0)
418
-    {
419
-        if ($init) {
420
-            $this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"),
421
-                $this->xcloner_settings->get_xcloner_start_path()));
422
-            $this->do_system_init();
423
-        }
424
-
425
-        if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
426
-            //.dir exists, we presume we have files to iterate
427
-            $content = $this->tmp_filesystem->read($this->get_temp_dir_handler());
428
-            $files = array_filter(explode("\n", $content));
429
-            $this->tmp_filesystem->delete($this->get_temp_dir_handler());
430
-
431
-            $counter = 0;
432
-            foreach ($files as $file) {
433
-                if ($counter < $this->folders_to_process_per_session) {
434
-                    $this->build_files_list($file);
435
-                    $counter++;
436
-                } else {
437
-                    $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n");
438
-                }
439
-            }
440
-        } else {
441
-            $this->build_files_list();
442
-        }
443
-
444
-        if ($this->scan_finished()) {
445
-            $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html");
446
-            $this->store_file($metadata_dumpfile, 'tmp_filesystem');
447
-            $this->files_counter++;
448
-
449
-            //adding included dump file to the included files list
450
-            if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) {
451
-                $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler());
452
-                $this->store_file($metadata_dumpfile, 'tmp_filesystem');
453
-                $this->files_counter++;
454
-            }
455
-
456
-            //adding a default index.html to the temp xcloner folder
457
-            if (!$this->get_tmp_filesystem()->has("index.html")) {
458
-                $this->get_tmp_filesystem()->write("index.html", "");
459
-            }
460
-
461
-            //adding the default log file
462
-            if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) {
463
-                $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1));
464
-                $this->store_file($metadata_dumpfile, 'tmp_filesystem');
465
-                $this->files_counter++;
466
-            }
467
-
468
-            return false;
469
-        }
470
-
471
-        return true;
472
-    }
473
-
474
-    public function get_backup_attachments()
475
-    {
476
-        $return = array();
477
-
478
-        $files_list_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler();
479
-        if (file_exists($files_list_file)) {
480
-            $return[] = $files_list_file;
481
-        }
482
-
483
-        if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
484
-            $log_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
485
-            if (!file_exists($log_file)) {
486
-                $log_file = $this->xcloner_settings->get_xcloner_store_path().DS.$this->xcloner_settings->get_logger_filename();
487
-            }
488
-
489
-            if (file_exists($log_file)) {
490
-                $return[] = $log_file;
491
-            }
492
-        }
493
-
494
-        return $return;
495
-    }
496
-
497
-    public function remove_tmp_filesystem()
498
-    {
499
-        //delete the temporary folder
500
-        $this->logger->debug(sprintf("Deleting the temporary storage folder %s",
501
-            $this->xcloner_settings->get_xcloner_tmp_path()));
502
-
503
-        $contents = $this->get_tmp_filesystem()->listContents();
504
-
505
-        if (is_array($contents)) {
506
-            foreach ($contents as $file_info) {
507
-                $this->get_tmp_filesystem()->delete($file_info['path']);
508
-            }
509
-        }
510
-
511
-        @rmdir($this->xcloner_settings->get_xcloner_tmp_path());
512
-
513
-        return;
514
-    }
515
-
516
-    public function cleanup_tmp_directories()
517
-    {
518
-        $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
519
-        $tmp_filesystem = new Filesystem($adapter, new Config([
520
-            'disable_asserts' => true,
521
-        ]));
522
-
523
-        $contents = $tmp_filesystem->listContents();
524
-
525
-        foreach ($contents as $file) {
526
-
527
-            if (preg_match("/.xcloner-(.*)/", $file['path'])) {
528
-                if ($file['timestamp'] < strtotime("-1days")) {
529
-                    $tmp_filesystem->deleteDir($file['path']);
530
-                    $this->logger->debug(sprintf("Delete temporary directory %s", $file['path']));
531
-                }
532
-            }
533
-        }
534
-
535
-        return true;
536
-    }
537
-
538
-    private function do_system_init()
539
-    {
540
-        $this->files_counter = 0;
541
-
542
-        if (!$this->storage_filesystem->has("index.html")) {
543
-            $this->storage_filesystem->write("index.html", "");
544
-        }
545
-
546
-        if (!$this->tmp_filesystem->has("index.html")) {
547
-            $this->tmp_filesystem->write("index.html", "");
548
-        }
549
-
550
-        if ($this->tmp_filesystem->has($this->get_included_files_handler())) {
551
-            $this->tmp_filesystem->delete($this->get_included_files_handler());
552
-        }
553
-
554
-        if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
555
-            $this->tmp_filesystem->delete($this->get_temp_dir_handler());
556
-        }
557
-    }
558
-
559
-    public function get_scanned_files_num()
560
-    {
561
-        return $this->files_counter;
562
-    }
563
-
564
-    public function get_scanned_files_total_size()
565
-    {
566
-        return $this->files_size;
567
-    }
568
-
569
-    public function last_logged_file()
570
-    {
571
-        return $this->last_logged_file;
572
-    }
573
-
574
-    public static function is_regex($regex)
575
-    {
576
-        return preg_match("/^\^(.*)\$$/i", $regex);
577
-    }
40
+	private $excluded_files = "";
41
+	private $additional_regex_patterns = array();
42
+	private $excluded_files_by_default = array("administrator/backups", "wp-content/backups");
43
+	private $included_files_handler = "backup_files.csv";
44
+	private $temp_dir_handler = ".dir";
45
+	public $filesystem;
46
+	public $tmp_filesystem;
47
+	public $storage_filesystem;
48
+	private $xcloner_container;
49
+	private $diff_timestamp_start = "";
50
+
51
+	private $logger;
52
+	private $start_adapter;
53
+	private $tmp_adapter;
54
+	private $storage_adapter;
55
+	private $xcloner_settings;
56
+	private $start_filesystem;
57
+	private $tmp_filesystem_append;
58
+	private $storage_filesystem_append;
59
+
60
+	private $files_counter;
61
+	private $files_size;
62
+	private $last_logged_file;
63
+	private $folders_to_process_per_session = 25;
64
+	private $backup_archive_extensions = array("tar", "tgz", "tar.gz", "gz", "csv", "encrypted", "decrypted");
65
+	private $backup_name_tags = array('[time]', '[hostname]', '[domain]');
66
+
67
+	/**
68
+	 * Xcloner_File_System constructor.
69
+	 * @param Xcloner $xcloner_container
70
+	 * @param string $hash
71
+	 */
72
+	public function __construct(Xcloner $xcloner_container, $hash = "")
73
+	{
74
+		$this->xcloner_container = $xcloner_container;
75
+
76
+		$this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_file_system");
77
+		$this->xcloner_settings = $xcloner_container->get_xcloner_settings();
78
+
79
+		try {
80
+
81
+			$this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS');
82
+			$this->start_filesystem = new Filesystem($this->start_adapter, new Config([
83
+				'disable_asserts' => true,
84
+			]));
85
+
86
+			$this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS');
87
+			$this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([
88
+				'disable_asserts' => true,
89
+			]));
90
+			$adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
91
+			$this->tmp_filesystem_append = new Filesystem($adapter, new Config([
92
+				'disable_asserts' => true,
93
+			]));
94
+
95
+			$adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS');
96
+			$this->storage_filesystem = new Filesystem($adapter, new Config([
97
+				'disable_asserts' => true,
98
+			]));
99
+
100
+			$this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND,
101
+				'SKIP_LINKS');
102
+			$this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([
103
+				'disable_asserts' => true,
104
+			]));
105
+		}catch (Exception $e) {
106
+			$this->logger->error("Filesystem Initialization Error: ".$e->getMessage());
107
+		}
108
+
109
+
110
+		if ($value = get_option('xcloner_directories_to_scan_per_request')) {
111
+			$this->folders_to_process_per_session = $value;
112
+		}
113
+
114
+	}
115
+
116
+	/**
117
+	 * Set differential timestamp date
118
+	 * @param string $timestamp
119
+	 */
120
+	public function set_diff_timestamp_start($timestamp = "")
121
+	{
122
+		if ($timestamp) {
123
+			$this->logger->info(sprintf("Setting Differential Timestamp To %s", date("Y-m-d", $timestamp)), array(
124
+				"FILESYSTEM",
125
+				"DIFF"
126
+			));
127
+			$this->diff_timestamp_start = $timestamp;
128
+		}
129
+	}
130
+
131
+	/**
132
+	 * Gets the differential timestamp date
133
+	 * @return string
134
+	 */
135
+	public function get_diff_timestamp_start()
136
+	{
137
+		return $this->diff_timestamp_start;
138
+	}
139
+
140
+	private function get_xcloner_container()
141
+	{
142
+		return $this->xcloner_container;
143
+	}
144
+
145
+	public function set_hash($hash)
146
+	{
147
+		$this->xcloner_settings->set_hash($hash);
148
+	}
149
+
150
+	public function get_hash($hash)
151
+	{
152
+		$this->xcloner_settings->get_hash();
153
+	}
154
+
155
+	public function get_tmp_filesystem()
156
+	{
157
+		return $this->tmp_filesystem;
158
+	}
159
+
160
+	public function get_storage_filesystem($remote_storage_selection = "")
161
+	{
162
+		if ($remote_storage_selection != "") {
163
+			$remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
164
+			$method = "get_".$remote_storage_selection."_filesystem";
165
+
166
+			if (!method_exists($remote_storage, $method)) {
167
+				return false;
168
+			}
169
+
170
+			list($adapter, $filesystem) = $remote_storage->$method();
171
+
172
+			return $filesystem;
173
+		}
174
+
175
+		return $this->storage_filesystem;
176
+	}
177
+
178
+	public function get_tmp_filesystem_adapter()
179
+	{
180
+		return $this->tmp_adapter;
181
+	}
182
+
183
+	public function get_tmp_filesystem_append()
184
+	{
185
+		return $this->tmp_filesystem_append;
186
+	}
187
+
188
+	public function get_start_adapter()
189
+	{
190
+		return $this->start_adapter;
191
+	}
192
+
193
+	public function get_start_filesystem()
194
+	{
195
+		return $this->start_filesystem;
196
+	}
197
+
198
+	public function get_logger()
199
+	{
200
+		return $this->logger;
201
+	}
202
+
203
+	public function get_start_path_file_info($file)
204
+	{
205
+		$info = $this->getMetadataFull('start_adapter', $file);
206
+
207
+		return $this->start_filesystem->normalizeFileInfo($info);
208
+	}
209
+
210
+	/**
211
+	 * @param string $file
212
+	 */
213
+	public function get_storage_path_file_info($file)
214
+	{
215
+		return $this->getMetadataFull('storage_adapter', $file);
216
+	}
217
+
218
+	public function get_included_files_handler($metadata = 0)
219
+	{
220
+		$path = $this->included_files_handler;
221
+		if (!$metadata) {
222
+			return $path;
223
+		}
224
+
225
+		$spl_info = $this->getMetadataFull('tmp_adapter', $path);
226
+
227
+		return $spl_info;
228
+
229
+	}
230
+
231
+	public function get_temp_dir_handler()
232
+	{
233
+		return $this->temp_dir_handler;
234
+	}
235
+
236
+	public function get_latest_backup()
237
+	{
238
+		$files = $this->get_backup_archives_list();
239
+
240
+		if (is_array($files)) {
241
+			$this->sort_by($files, "timestamp", "desc");
242
+		}
243
+
244
+		$new_list = array();
245
+
246
+		foreach ($files as $key => $file) {
247
+			if (!isset($file['parent'])) {
248
+				$new_list[] = ($files[$key]);
249
+			}
250
+		}
251
+
252
+		if (isset($new_list[0])) {
253
+			return $new_list[0];
254
+		}
255
+	}
256
+
257
+	public function get_latest_backups()
258
+	{
259
+		$files = $this->get_backup_archives_list();
260
+
261
+		if (is_array($files)) {
262
+			$this->sort_by($files, "timestamp", "desc");
263
+		}
264
+
265
+		$new_list = array();
266
+
267
+		foreach ($files as $key => $file) {
268
+			if (!isset($file['parent'])) {
269
+				$new_list[] = ($files[$key]);
270
+			}
271
+		}
272
+
273
+		return $new_list;
274
+	}
275
+
276
+	public function get_storage_usage()
277
+	{
278
+		$files = $this->get_backup_archives_list();
279
+		$total = 0;
280
+
281
+		if (is_array($files)) {
282
+			foreach ($files as $file) {
283
+				$total += $file['size'];
284
+			}
285
+		}
286
+
287
+		return $total;
288
+	}
289
+
290
+	public function is_part($backup_name)
291
+	{
292
+		if (stristr($backup_name, "-part")) {
293
+			return true;
294
+		}
295
+
296
+		return false;
297
+	}
298
+
299
+	public function is_multipart($backup_name)
300
+	{
301
+		if (stristr($backup_name, "-multipart")) {
302
+			return true;
303
+		}
304
+
305
+		return false;
306
+	}
307
+
308
+	public function get_backup_size($backup_name)
309
+	{
310
+		$backup_size = $this->get_storage_filesystem()->getSize($backup_name);
311
+		if ($this->is_multipart($backup_name)) {
312
+			$backup_parts = $this->get_multipart_files($backup_name);
313
+			foreach ($backup_parts as $part_file) {
314
+				$backup_size += $this->get_storage_filesystem()->getSize($part_file);
315
+			}
316
+		}
317
+
318
+		return $backup_size;
319
+	}
320
+
321
+	public function get_multipart_files($backup_name, $storage_selection = "")
322
+	{
323
+		$files = array();
324
+
325
+		if ($this->is_multipart($backup_name)) {
326
+			$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
327
+			foreach ($lines as $line) {
328
+				if ($line) {
329
+					$data = str_getcsv($line);
330
+					$files[] = $data[0];
331
+				}
332
+			}
333
+		}
334
+
335
+		return $files;
336
+	}
337
+
338
+	public function delete_backup_by_name($backup_name, $storage_selection = "")
339
+	{
340
+		if ($this->is_multipart($backup_name)) {
341
+			$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
342
+			foreach ($lines as $line) {
343
+				if ($line) {
344
+					$data = str_getcsv($line);
345
+					$this->get_storage_filesystem($storage_selection)->delete($data[0]);
346
+				}
347
+			}
348
+		}
349
+
350
+		if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) {
351
+			$return = true;
352
+		} else {
353
+			$return = false;
354
+		}
355
+
356
+		return $return;
357
+	}
358
+
359
+	public function getMetadataFull($adapter = "storage_adapter", $path)
360
+	{
361
+		$location = $this->$adapter->applyPathPrefix($path);
362
+		$spl_info = new SplFileInfo($location);
363
+
364
+		return ($spl_info);
365
+	}
366
+
367
+
368
+	public function get_backup_archives_list($storage_selection = "")
369
+	{
370
+		$list = array();
371
+
372
+
373
+		if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) {
374
+			$list = $this->get_storage_filesystem($storage_selection)->listContents();
375
+		}
376
+
377
+		$backup_files = array();
378
+		$parents = array();
379
+
380
+		foreach ($list as $file_info) {
381
+			if (isset($file_info['extension']) and $file_info['extension'] == "csv") {
382
+				$data = array();
383
+
384
+				$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path']));
385
+				foreach ($lines as $line) {
386
+					if ($line) {
387
+						$data = str_getcsv($line);
388
+						if (is_array($data)) {
389
+							$parents[$data[0]] = $file_info['basename'];
390
+							$file_info['childs'][] = $data;
391
+							$file_info['size'] += $data[2];
392
+						}
393
+					}
394
+				}
395
+
396
+			}
397
+
398
+			if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'],
399
+					$this->backup_archive_extensions)) {
400
+				$backup_files[$file_info['path']] = $file_info;
401
+			}
402
+		}
403
+
404
+		foreach ($backup_files as $key => $file_info) {
405
+			if (!isset($backup_files[$key]['timestamp'])) {
406
+				//$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']);
407
+			}
408
+
409
+			if (isset($parents[$file_info['basename']])) {
410
+				$backup_files[$key]['parent'] = $parents[$file_info['basename']];
411
+			}
412
+		}
413
+
414
+		return $backup_files;
415
+	}
416
+
417
+	public function start_file_recursion($init = 0)
418
+	{
419
+		if ($init) {
420
+			$this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"),
421
+				$this->xcloner_settings->get_xcloner_start_path()));
422
+			$this->do_system_init();
423
+		}
424
+
425
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
426
+			//.dir exists, we presume we have files to iterate
427
+			$content = $this->tmp_filesystem->read($this->get_temp_dir_handler());
428
+			$files = array_filter(explode("\n", $content));
429
+			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
430
+
431
+			$counter = 0;
432
+			foreach ($files as $file) {
433
+				if ($counter < $this->folders_to_process_per_session) {
434
+					$this->build_files_list($file);
435
+					$counter++;
436
+				} else {
437
+					$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n");
438
+				}
439
+			}
440
+		} else {
441
+			$this->build_files_list();
442
+		}
443
+
444
+		if ($this->scan_finished()) {
445
+			$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html");
446
+			$this->store_file($metadata_dumpfile, 'tmp_filesystem');
447
+			$this->files_counter++;
448
+
449
+			//adding included dump file to the included files list
450
+			if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) {
451
+				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler());
452
+				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
453
+				$this->files_counter++;
454
+			}
455
+
456
+			//adding a default index.html to the temp xcloner folder
457
+			if (!$this->get_tmp_filesystem()->has("index.html")) {
458
+				$this->get_tmp_filesystem()->write("index.html", "");
459
+			}
460
+
461
+			//adding the default log file
462
+			if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) {
463
+				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1));
464
+				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
465
+				$this->files_counter++;
466
+			}
467
+
468
+			return false;
469
+		}
470
+
471
+		return true;
472
+	}
473
+
474
+	public function get_backup_attachments()
475
+	{
476
+		$return = array();
477
+
478
+		$files_list_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler();
479
+		if (file_exists($files_list_file)) {
480
+			$return[] = $files_list_file;
481
+		}
482
+
483
+		if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
484
+			$log_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
485
+			if (!file_exists($log_file)) {
486
+				$log_file = $this->xcloner_settings->get_xcloner_store_path().DS.$this->xcloner_settings->get_logger_filename();
487
+			}
488
+
489
+			if (file_exists($log_file)) {
490
+				$return[] = $log_file;
491
+			}
492
+		}
493
+
494
+		return $return;
495
+	}
496
+
497
+	public function remove_tmp_filesystem()
498
+	{
499
+		//delete the temporary folder
500
+		$this->logger->debug(sprintf("Deleting the temporary storage folder %s",
501
+			$this->xcloner_settings->get_xcloner_tmp_path()));
502
+
503
+		$contents = $this->get_tmp_filesystem()->listContents();
504
+
505
+		if (is_array($contents)) {
506
+			foreach ($contents as $file_info) {
507
+				$this->get_tmp_filesystem()->delete($file_info['path']);
508
+			}
509
+		}
510
+
511
+		@rmdir($this->xcloner_settings->get_xcloner_tmp_path());
512
+
513
+		return;
514
+	}
515
+
516
+	public function cleanup_tmp_directories()
517
+	{
518
+		$adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
519
+		$tmp_filesystem = new Filesystem($adapter, new Config([
520
+			'disable_asserts' => true,
521
+		]));
522
+
523
+		$contents = $tmp_filesystem->listContents();
524
+
525
+		foreach ($contents as $file) {
526
+
527
+			if (preg_match("/.xcloner-(.*)/", $file['path'])) {
528
+				if ($file['timestamp'] < strtotime("-1days")) {
529
+					$tmp_filesystem->deleteDir($file['path']);
530
+					$this->logger->debug(sprintf("Delete temporary directory %s", $file['path']));
531
+				}
532
+			}
533
+		}
534
+
535
+		return true;
536
+	}
537
+
538
+	private function do_system_init()
539
+	{
540
+		$this->files_counter = 0;
541
+
542
+		if (!$this->storage_filesystem->has("index.html")) {
543
+			$this->storage_filesystem->write("index.html", "");
544
+		}
545
+
546
+		if (!$this->tmp_filesystem->has("index.html")) {
547
+			$this->tmp_filesystem->write("index.html", "");
548
+		}
549
+
550
+		if ($this->tmp_filesystem->has($this->get_included_files_handler())) {
551
+			$this->tmp_filesystem->delete($this->get_included_files_handler());
552
+		}
553
+
554
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
555
+			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
556
+		}
557
+	}
558
+
559
+	public function get_scanned_files_num()
560
+	{
561
+		return $this->files_counter;
562
+	}
563
+
564
+	public function get_scanned_files_total_size()
565
+	{
566
+		return $this->files_size;
567
+	}
568
+
569
+	public function last_logged_file()
570
+	{
571
+		return $this->last_logged_file;
572
+	}
573
+
574
+	public static function is_regex($regex)
575
+	{
576
+		return preg_match("/^\^(.*)\$$/i", $regex);
577
+	}
578 578
 
579
-    public function set_excluded_files($excluded_files = array())
580
-    {
581
-        if (!is_array($excluded_files)) {
582
-            $excluded_files = array();
583
-        }
579
+	public function set_excluded_files($excluded_files = array())
580
+	{
581
+		if (!is_array($excluded_files)) {
582
+			$excluded_files = array();
583
+		}
584 584
 
585
-        foreach ($excluded_files as $excl) {
585
+		foreach ($excluded_files as $excl) {
586 586
 
587
-            if ($this->is_regex($excl)) {
588
-                $this->additional_regex_patterns[] = $excl;
589
-            }
590
-        }
587
+			if ($this->is_regex($excl)) {
588
+				$this->additional_regex_patterns[] = $excl;
589
+			}
590
+		}
591 591
 
592
-        $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
592
+		$this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
593 593
 
594
-        return $this->excluded_files;
595
-    }
594
+		return $this->excluded_files;
595
+	}
596 596
 
597
-    public function get_excluded_files()
598
-    {
599
-        return $this->excluded_files_by_default;
600
-    }
597
+	public function get_excluded_files()
598
+	{
599
+		return $this->excluded_files_by_default;
600
+	}
601 601
 
602
-    public function list_directory($path)
603
-    {
604
-        return $this->start_filesystem->listContents($path);
605
-    }
602
+	public function list_directory($path)
603
+	{
604
+		return $this->start_filesystem->listContents($path);
605
+	}
606 606
 
607
-    public function build_files_list($folder = "")
608
-    {
609
-        $this->logger->debug(sprintf(("Building the files system list")));
607
+	public function build_files_list($folder = "")
608
+	{
609
+		$this->logger->debug(sprintf(("Building the files system list")));
610 610
 
611
-        //if we start with the root folder(empty value), we initializa the file system
612
-        if (!$folder) {
611
+		//if we start with the root folder(empty value), we initializa the file system
612
+		if (!$folder) {
613 613
 
614
-        }
614
+		}
615 615
 
616
-        try {
616
+		try {
617 617
 
618
-            $files = $this->start_filesystem->listContents($folder);
619
-            foreach ($files as $file) {
620
-                if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) {
621
-                    $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"),
622
-                        $file['path']), array(
623
-                        "FILESYSTEM SCAN",
624
-                        "NOT READABLE"
625
-                    ));
626
-                } elseif (!$matching_pattern = $this->is_excluded($file)) {
627
-                    $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array(
628
-                        "FILESYSTEM SCAN",
629
-                        "INCLUDE"
630
-                    ));
631
-                    $file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
632
-                    if ($this->store_file($file)) {
633
-                        $this->files_counter++;
634
-                    }
635
-                    if (isset($file['size'])) {
636
-                        $this->files_size += $file['size'];
637
-                    }
638
-
639
-                } else {
640
-                    $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"),
641
-                        $file['path'], $matching_pattern), array(
642
-                        "FILESYSTEM SCAN",
643
-                        "EXCLUDE"
644
-                    ));
645
-                }
646
-            }
618
+			$files = $this->start_filesystem->listContents($folder);
619
+			foreach ($files as $file) {
620
+				if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) {
621
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"),
622
+						$file['path']), array(
623
+						"FILESYSTEM SCAN",
624
+						"NOT READABLE"
625
+					));
626
+				} elseif (!$matching_pattern = $this->is_excluded($file)) {
627
+					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array(
628
+						"FILESYSTEM SCAN",
629
+						"INCLUDE"
630
+					));
631
+					$file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
632
+					if ($this->store_file($file)) {
633
+						$this->files_counter++;
634
+					}
635
+					if (isset($file['size'])) {
636
+						$this->files_size += $file['size'];
637
+					}
638
+
639
+				} else {
640
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"),
641
+						$file['path'], $matching_pattern), array(
642
+						"FILESYSTEM SCAN",
643
+						"EXCLUDE"
644
+					));
645
+				}
646
+			}
647 647
 
648
-        }catch (Exception $e) {
648
+		}catch (Exception $e) {
649 649
 
650
-            $this->logger->error($e->getMessage());
651
-
652
-        }
650
+			$this->logger->error($e->getMessage());
651
+
652
+		}
653 653
 
654
-    }
654
+	}
655 655
 
656
-    public function estimate_read_write_time()
657
-    {
658
-        $tmp_file = ".xcloner".substr(md5(time()), 0, 5);
656
+	public function estimate_read_write_time()
657
+	{
658
+		$tmp_file = ".xcloner".substr(md5(time()), 0, 5);
659 659
 
660
-        $start_time = microtime(true);
660
+		$start_time = microtime(true);
661 661
 
662
-        $data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data
662
+		$data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data
663 663
 
664
-        try {
665
-            $this->tmp_filesystem->write($tmp_file, $data);
664
+		try {
665
+			$this->tmp_filesystem->write($tmp_file, $data);
666 666
 
667
-            $end_time = microtime(true) - $start_time;
667
+			$end_time = microtime(true) - $start_time;
668 668
 
669
-            $return['writing_time'] = $end_time;
669
+			$return['writing_time'] = $end_time;
670 670
 
671
-            $return['reading_time'] = $this->estimate_reading_time($tmp_file);
671
+			$return['reading_time'] = $this->estimate_reading_time($tmp_file);
672 672
 
673
-            $this->tmp_filesystem->delete($tmp_file);
673
+			$this->tmp_filesystem->delete($tmp_file);
674 674
 
675
-        }catch (Exception $e) {
675
+		}catch (Exception $e) {
676 676
 
677
-            $this->logger->error($e->getMessage());
677
+			$this->logger->error($e->getMessage());
678 678
 
679
-        }
679
+		}
680 680
 
681
-        return $return;
682
-    }
681
+		return $return;
682
+	}
683 683
 
684
-    public function backup_storage_cleanup()
685
-    {
686
-        $this->logger->info(sprintf(("Cleaning the backup storage on matching rules")));
684
+	public function backup_storage_cleanup()
685
+	{
686
+		$this->logger->info(sprintf(("Cleaning the backup storage on matching rules")));
687 687
 
688
-        $_storage_size = 0;
689
-        $_backup_files_list = array();
688
+		$_storage_size = 0;
689
+		$_backup_files_list = array();
690 690
 
691
-        //rule date limit
692
-        $current_timestamp = strtotime("-".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')." days");
693
-
694
-        $files = $this->storage_filesystem->listContents();
695
-
696
-        if (is_array($files)) {
697
-            foreach ($files as $file) {
698
-                if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) {
699
-                    $_storage_size += $file['size']; //bytes
700
-                    $_backup_files_list[] = $file;
701
-                }
702
-            }
703
-        }
691
+		//rule date limit
692
+		$current_timestamp = strtotime("-".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')." days");
693
+
694
+		$files = $this->storage_filesystem->listContents();
695
+
696
+		if (is_array($files)) {
697
+			foreach ($files as $file) {
698
+				if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) {
699
+					$_storage_size += $file['size']; //bytes
700
+					$_backup_files_list[] = $file;
701
+				}
702
+			}
703
+		}
704 704
 
705 705
 
706
-        $this->sort_by($_backup_files_list, "timestamp", "asc");
707
-
708
-        $_backups_counter = sizeof($_backup_files_list);
709
-
710
-        foreach ($_backup_files_list as $file) {
711
-            //processing rule folder capacity
712
-            if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
713
-                $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))    //bytes
714
-            {
715
-                $this->storage_filesystem->delete($file['path']);
716
-                $_storage_size -= $file['size'];
717
-                $this->logger->info("Deleting backup ".$file['path']." matching rule", array(
718
-                    "STORAGE SIZE LIMIT",
719
-                    $_storage_size." >= ".$set_storage_limit
720
-                ));
721
-            }
722
-
723
-            //processing rule days limit
724
-            if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) {
725
-                $this->storage_filesystem->delete($file['path']);
726
-                $this->logger->info("Deleting backup ".$file['path']." matching rule", array(
727
-                    "RETENTION LIMIT TIMESTAMP",
728
-                    $file['timestamp']." =< ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')
729
-                ));
730
-            }
731
-
732
-            //processing backup countert limit
733
-            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')) {
734
-                $this->storage_filesystem->delete($file['path']);
735
-                $_backups_counter--;
736
-                $this->logger->info("Deleting backup ".$file['path']." matching rule", array(
737
-                    "BACKUP QUANTITY LIMIT",
738
-                    $_backups_counter." >= ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')
739
-                ));
740
-            }
741
-
742
-
743
-        }
706
+		$this->sort_by($_backup_files_list, "timestamp", "asc");
707
+
708
+		$_backups_counter = sizeof($_backup_files_list);
709
+
710
+		foreach ($_backup_files_list as $file) {
711
+			//processing rule folder capacity
712
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
713
+				$_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))    //bytes
714
+			{
715
+				$this->storage_filesystem->delete($file['path']);
716
+				$_storage_size -= $file['size'];
717
+				$this->logger->info("Deleting backup ".$file['path']." matching rule", array(
718
+					"STORAGE SIZE LIMIT",
719
+					$_storage_size." >= ".$set_storage_limit
720
+				));
721
+			}
722
+
723
+			//processing rule days limit
724
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) {
725
+				$this->storage_filesystem->delete($file['path']);
726
+				$this->logger->info("Deleting backup ".$file['path']." matching rule", array(
727
+					"RETENTION LIMIT TIMESTAMP",
728
+					$file['timestamp']." =< ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')
729
+				));
730
+			}
731
+
732
+			//processing backup countert limit
733
+			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')) {
734
+				$this->storage_filesystem->delete($file['path']);
735
+				$_backups_counter--;
736
+				$this->logger->info("Deleting backup ".$file['path']." matching rule", array(
737
+					"BACKUP QUANTITY LIMIT",
738
+					$_backups_counter." >= ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')
739
+				));
740
+			}
741
+
742
+
743
+		}
744 744
 
745
-    }
745
+	}
746 746
 
747
-    /**
748
-     * @param string $tmp_file
749
-     */
750
-    public function estimate_reading_time($tmp_file)
751
-    {
752
-        $this->logger->debug(sprintf(("Estimating file system reading time")));
753
-
754
-        $start_time = microtime(true);
755
-
756
-        if ($this->tmp_filesystem->has($tmp_file)) {
757
-            $this->tmp_filesystem->read($tmp_file);
758
-        }
759
-
760
-        $end_time = microtime(true) - $start_time;
761
-
762
-        return $end_time;
763
-
764
-    }
765
-
766
-    public function process_backup_name($name = "", $max_length = 100)
767
-    {
768
-        if (!$name) {
769
-            $name = $this->xcloner_settings->get_default_backup_name();
770
-        }
771
-
772
-        foreach ($this->backup_name_tags as $tag) {
773
-            if ($tag == '[time]') {
774
-                $name = str_replace($tag, date("Y-m-d_H-i"), $name);
775
-            } elseif ($tag == '[hostname]') {
776
-                $name = str_replace($tag, gethostname(), $name);
777
-            } elseif ($tag == '[domain]') {
778
-                $domain = parse_url(admin_url(), PHP_URL_HOST);
779
-                $name = str_replace($tag, $domain, $name);
780
-            }
781
-        }
782
-
783
-        if ($max_length) {
784
-            $name = substr($name, 0, $max_length);
785
-        }
786
-
787
-        return $name;
788
-    }
789
-
790
-    /**
791
-     * @param string $field
792
-     */
793
-    public function sort_by(&$array, $field, $direction = 'asc')
794
-    {
795
-        if (strtolower($direction) == "desc" || $direction == SORT_DESC) {
796
-            $direction = SORT_DESC;
797
-        } else {
798
-            $direction = SORT_ASC;
799
-        }
800
-
801
-        $array = $this->array_orderby($array, $field, $direction);
802
-
803
-        return true;
804
-    }
805
-
806
-    private function array_orderby()
807
-    {
808
-        $args = func_get_args();
809
-        $data = array_shift($args);
810
-
811
-        foreach ($args as $n => $field) {
812
-            if (is_string($field)) {
813
-                $tmp = array();
814
-                foreach ($data as $key => $row) {
815
-                    if (is_array($row)) {
816
-                        $tmp[$key] = $row[$field];
817
-                    } else {
818
-                        $tmp[$key] = $row->$field;
819
-                    }
820
-                }
821
-                $args[$n] = $tmp;
822
-            }
823
-        }
824
-        $args[] = &$data;
825
-
826
-        call_user_func_array('array_multisort', $args);
827
-
828
-        return array_pop($args);
829
-    }
830
-
831
-    private function check_file_diff_time($file)
832
-    {
833
-        if ($this->get_diff_timestamp_start() != "") {
834
-            $fileMeta = $this->getMetadataFull("start_adapter", $file['path']);
835
-            $timestamp = $fileMeta->getMTime();
836
-            if ($timestamp < $fileMeta->getCTime()) {
837
-                $timestamp = $fileMeta->getCTime();
838
-            }
839
-
840
-            if ($timestamp <= $this->get_diff_timestamp_start()) {
841
-                return " file DIFF timestamp ".$timestamp." < ".$this->diff_timestamp_start;
842
-            }
843
-        }
844
-
845
-        return false;
846
-    }
847
-
848
-    public function is_excluded($file)
849
-    {
850
-        $this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
851
-
852
-        if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) {
853
-            if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) {
854
-                return "> ".$xcloner_exclude_files_larger_than_mb."MB";
855
-            }
856
-        }
857
-
858
-        if (!is_array($this->excluded_files) || !sizeof($this->excluded_files)) {
859
-            $this->set_excluded_files();
860
-        }
861
-
862
-        if (is_array($this->excluded_files)) {
863
-            foreach ($this->excluded_files as $excluded_file_pattern) {
864
-                if ($excluded_file_pattern == "/") {
865
-                    $needle = "$";
866
-                } else {
867
-                    $needle = "$".$excluded_file_pattern;
868
-                }
869
-
870
-                if (strstr("$".$file['path'], $needle)) {
871
-                    return $excluded_file_pattern;
872
-                }
873
-            }
874
-        }
875
-
876
-        if ($regex = $this->is_excluded_regex($file)) {
877
-            return $regex;
878
-        }
879
-
880
-        if ($file['type'] == "file") {
881
-            $check_file_diff_timestamp = $this->check_file_diff_time($file);
882
-            if ($check_file_diff_timestamp) {
883
-                return $check_file_diff_timestamp;
884
-            }
885
-        }
886
-
887
-        return false;
888
-    }
889
-
890
-    /*REGEX examples
747
+	/**
748
+	 * @param string $tmp_file
749
+	 */
750
+	public function estimate_reading_time($tmp_file)
751
+	{
752
+		$this->logger->debug(sprintf(("Estimating file system reading time")));
753
+
754
+		$start_time = microtime(true);
755
+
756
+		if ($this->tmp_filesystem->has($tmp_file)) {
757
+			$this->tmp_filesystem->read($tmp_file);
758
+		}
759
+
760
+		$end_time = microtime(true) - $start_time;
761
+
762
+		return $end_time;
763
+
764
+	}
765
+
766
+	public function process_backup_name($name = "", $max_length = 100)
767
+	{
768
+		if (!$name) {
769
+			$name = $this->xcloner_settings->get_default_backup_name();
770
+		}
771
+
772
+		foreach ($this->backup_name_tags as $tag) {
773
+			if ($tag == '[time]') {
774
+				$name = str_replace($tag, date("Y-m-d_H-i"), $name);
775
+			} elseif ($tag == '[hostname]') {
776
+				$name = str_replace($tag, gethostname(), $name);
777
+			} elseif ($tag == '[domain]') {
778
+				$domain = parse_url(admin_url(), PHP_URL_HOST);
779
+				$name = str_replace($tag, $domain, $name);
780
+			}
781
+		}
782
+
783
+		if ($max_length) {
784
+			$name = substr($name, 0, $max_length);
785
+		}
786
+
787
+		return $name;
788
+	}
789
+
790
+	/**
791
+	 * @param string $field
792
+	 */
793
+	public function sort_by(&$array, $field, $direction = 'asc')
794
+	{
795
+		if (strtolower($direction) == "desc" || $direction == SORT_DESC) {
796
+			$direction = SORT_DESC;
797
+		} else {
798
+			$direction = SORT_ASC;
799
+		}
800
+
801
+		$array = $this->array_orderby($array, $field, $direction);
802
+
803
+		return true;
804
+	}
805
+
806
+	private function array_orderby()
807
+	{
808
+		$args = func_get_args();
809
+		$data = array_shift($args);
810
+
811
+		foreach ($args as $n => $field) {
812
+			if (is_string($field)) {
813
+				$tmp = array();
814
+				foreach ($data as $key => $row) {
815
+					if (is_array($row)) {
816
+						$tmp[$key] = $row[$field];
817
+					} else {
818
+						$tmp[$key] = $row->$field;
819
+					}
820
+				}
821
+				$args[$n] = $tmp;
822
+			}
823
+		}
824
+		$args[] = &$data;
825
+
826
+		call_user_func_array('array_multisort', $args);
827
+
828
+		return array_pop($args);
829
+	}
830
+
831
+	private function check_file_diff_time($file)
832
+	{
833
+		if ($this->get_diff_timestamp_start() != "") {
834
+			$fileMeta = $this->getMetadataFull("start_adapter", $file['path']);
835
+			$timestamp = $fileMeta->getMTime();
836
+			if ($timestamp < $fileMeta->getCTime()) {
837
+				$timestamp = $fileMeta->getCTime();
838
+			}
839
+
840
+			if ($timestamp <= $this->get_diff_timestamp_start()) {
841
+				return " file DIFF timestamp ".$timestamp." < ".$this->diff_timestamp_start;
842
+			}
843
+		}
844
+
845
+		return false;
846
+	}
847
+
848
+	public function is_excluded($file)
849
+	{
850
+		$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
851
+
852
+		if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) {
853
+			if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) {
854
+				return "> ".$xcloner_exclude_files_larger_than_mb."MB";
855
+			}
856
+		}
857
+
858
+		if (!is_array($this->excluded_files) || !sizeof($this->excluded_files)) {
859
+			$this->set_excluded_files();
860
+		}
861
+
862
+		if (is_array($this->excluded_files)) {
863
+			foreach ($this->excluded_files as $excluded_file_pattern) {
864
+				if ($excluded_file_pattern == "/") {
865
+					$needle = "$";
866
+				} else {
867
+					$needle = "$".$excluded_file_pattern;
868
+				}
869
+
870
+				if (strstr("$".$file['path'], $needle)) {
871
+					return $excluded_file_pattern;
872
+				}
873
+			}
874
+		}
875
+
876
+		if ($regex = $this->is_excluded_regex($file)) {
877
+			return $regex;
878
+		}
879
+
880
+		if ($file['type'] == "file") {
881
+			$check_file_diff_timestamp = $this->check_file_diff_time($file);
882
+			if ($check_file_diff_timestamp) {
883
+				return $check_file_diff_timestamp;
884
+			}
885
+		}
886
+
887
+		return false;
888
+	}
889
+
890
+	/*REGEX examples
891 891
      *
892 892
     * exclude all except .php file
893 893
     * PATTERN: ^(.*)\.(.+)$(?<!(php))
@@ -919,163 +919,163 @@  discard block
 block discarded – undo
919 919
     * exclude the backup folders
920 920
     * PATTERN: (^|^\/)(wp-content\/backups|administrator\/backups)(.*)$";
921 921
     */
922
-    private function is_excluded_regex($file)
923
-    {
924
-        //$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
925
-
926
-        $regex_patterns = explode(PHP_EOL, $this->xcloner_settings->get_xcloner_option('xcloner_regex_exclude'));
927
-
928
-        if (is_array($this->additional_regex_patterns)) {
929
-            $regex_patterns = array_merge($regex_patterns, $this->additional_regex_patterns);
930
-        }
931
-
932
-        //print_r($regex_patterns);exit;
933
-
934
-        if (is_array($regex_patterns)) {
935
-            //$this->excluded_files = array();
936
-            //$this->excluded_files[] ="(.*)\.(git)(.*)$";
937
-            //$this->excluded_files[] ="wp-content\/backups(.*)$";
938
-
939
-            foreach ($regex_patterns as $excluded_file_pattern) {
940
-
941
-                if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1,
942
-                        strlen($excluded_file_pattern)) == "\r") {
943
-                    $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1);
944
-                }
945
-
946
-                if ($file['path'] == "/") {
947
-                    $needle = "/";
948
-                } else {
949
-                    $needle = "/".$file['path'];
950
-                }
951
-                //echo $needle."---".$excluded_file_pattern."---\n";
952
-
953
-                if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) {
954
-                    return $excluded_file_pattern;
955
-                }
956
-            }
957
-        }
958
-
959
-        return false;
960
-    }
961
-
962
-    public function store_file($file, $storage = 'start_filesystem')
963
-    {
964
-        $this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
965
-
966
-        if (!isset($file['size'])) {
967
-            $file['size'] = 0;
968
-        }
969
-        if (!isset($file['visibility'])) {
970
-            $file['visibility'] = "private";
971
-        }
972
-
973
-        $csv_filename = str_replace('"', '""', $file['path']);
974
-
975
-        $line = '"'.($csv_filename).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL;
976
-
977
-        $this->last_logged_file = $file['path'];
978
-
979
-        if ($file['type'] == "dir") {
980
-            try {
981
-                $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n");
982
-            }catch (Exception $e) {
983
-                $this->logger->error($e->getMessage());
984
-            }
985
-        }
986
-
987
-        if ($this->get_diff_timestamp_start()) {
988
-            if ($file['type'] != "file" && $response = $this->check_file_diff_time($file)) {
989
-                $this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'],
990
-                    $response), array(
991
-                    "FILESYSTEM SCAN",
992
-                    "DIR DIFF"
993
-                ));
994
-
995
-                return false;
996
-            }
997
-        }
998
-
999
-        try {
1000
-            if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) {
1001
-                //adding fix for UTF-8 CSV preview
1002
-                $start_line = "\xEF\xBB\xBF".'"Filename","Timestamp","Size","Visibility","Storage"'.PHP_EOL;
1003
-                $this->tmp_filesystem_append->write($this->get_included_files_handler(), $start_line);
1004
-            }
1005
-
1006
-            $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
1007
-
1008
-        }catch (Exception $e) {
1009
-
1010
-            $this->logger->error($e->getMessage());
1011
-        }
1012
-
1013
-        return true;
1014
-    }
1015
-
1016
-    public function get_fileystem_handler()
1017
-    {
1018
-        return $this;
1019
-    }
1020
-
1021
-    public function get_filesystem($system = "")
1022
-    {
1023
-        if ($system == "storage_filesystem_append") {
1024
-            return $this->storage_filesystem_append;
1025
-        } elseif ($system == "tmp_filesystem_append") {
1026
-            return $this->tmp_filesystem_append;
1027
-        } elseif ($system == "tmp_filesystem") {
1028
-            return $this->tmp_filesystem;
1029
-        } elseif ($system == "storage_filesystem") {
1030
-            return $this->storage_filesystem;
1031
-        } else {
1032
-            return $this->start_filesystem;
1033
-        }
1034
-    }
1035
-
1036
-    public function get_adapter($system)
1037
-    {
1038
-        if ($system == "tmp_filesystem") {
1039
-            return $this->tmp_adapter;
1040
-        } elseif ($system == "storage_filesystem") {
1041
-            return $this->storage_adapter;
1042
-        } else {
1043
-            return $this->start_adapter;
1044
-        }
1045
-    }
1046
-
1047
-    /**
1048
-     * File scan finished
1049
-     * Method called when file scan is finished
1050
-     *
1051
-     * @return bool
1052
-     */
1053
-    private function scan_finished()
1054
-    {
1055
-        if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) &&
1056
-            $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) {
1057
-            return false;
1058
-        }
1059
-
1060
-        if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
1061
-            $this->tmp_filesystem->delete($this->get_temp_dir_handler());
1062
-        }
1063
-
1064
-        $this->logger->debug(sprintf(("File scan finished")));
1065
-
1066
-        return true;
1067
-    }
1068
-
1069
-    /**
1070
-     * Calculate bytes from MB value
1071
-     *
1072
-     * @param int $mb_size
1073
-     *
1074
-     * @return float|int
1075
-     */
1076
-    private function calc_to_bytes($mb_size)
1077
-    {
1078
-        return $mb_size * (1024 * 1024);
1079
-    }
922
+	private function is_excluded_regex($file)
923
+	{
924
+		//$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
925
+
926
+		$regex_patterns = explode(PHP_EOL, $this->xcloner_settings->get_xcloner_option('xcloner_regex_exclude'));
927
+
928
+		if (is_array($this->additional_regex_patterns)) {
929
+			$regex_patterns = array_merge($regex_patterns, $this->additional_regex_patterns);
930
+		}
931
+
932
+		//print_r($regex_patterns);exit;
933
+
934
+		if (is_array($regex_patterns)) {
935
+			//$this->excluded_files = array();
936
+			//$this->excluded_files[] ="(.*)\.(git)(.*)$";
937
+			//$this->excluded_files[] ="wp-content\/backups(.*)$";
938
+
939
+			foreach ($regex_patterns as $excluded_file_pattern) {
940
+
941
+				if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1,
942
+						strlen($excluded_file_pattern)) == "\r") {
943
+					$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1);
944
+				}
945
+
946
+				if ($file['path'] == "/") {
947
+					$needle = "/";
948
+				} else {
949
+					$needle = "/".$file['path'];
950
+				}
951
+				//echo $needle."---".$excluded_file_pattern."---\n";
952
+
953
+				if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) {
954
+					return $excluded_file_pattern;
955
+				}
956
+			}
957
+		}
958
+
959
+		return false;
960
+	}
961
+
962
+	public function store_file($file, $storage = 'start_filesystem')
963
+	{
964
+		$this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
965
+
966
+		if (!isset($file['size'])) {
967
+			$file['size'] = 0;
968
+		}
969
+		if (!isset($file['visibility'])) {
970
+			$file['visibility'] = "private";
971
+		}
972
+
973
+		$csv_filename = str_replace('"', '""', $file['path']);
974
+
975
+		$line = '"'.($csv_filename).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL;
976
+
977
+		$this->last_logged_file = $file['path'];
978
+
979
+		if ($file['type'] == "dir") {
980
+			try {
981
+				$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n");
982
+			}catch (Exception $e) {
983
+				$this->logger->error($e->getMessage());
984
+			}
985
+		}
986
+
987
+		if ($this->get_diff_timestamp_start()) {
988
+			if ($file['type'] != "file" && $response = $this->check_file_diff_time($file)) {
989
+				$this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'],
990
+					$response), array(
991
+					"FILESYSTEM SCAN",
992
+					"DIR DIFF"
993
+				));
994
+
995
+				return false;
996
+			}
997
+		}
998
+
999
+		try {
1000
+			if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) {
1001
+				//adding fix for UTF-8 CSV preview
1002
+				$start_line = "\xEF\xBB\xBF".'"Filename","Timestamp","Size","Visibility","Storage"'.PHP_EOL;
1003
+				$this->tmp_filesystem_append->write($this->get_included_files_handler(), $start_line);
1004
+			}
1005
+
1006
+			$this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
1007
+
1008
+		}catch (Exception $e) {
1009
+
1010
+			$this->logger->error($e->getMessage());
1011
+		}
1012
+
1013
+		return true;
1014
+	}
1015
+
1016
+	public function get_fileystem_handler()
1017
+	{
1018
+		return $this;
1019
+	}
1020
+
1021
+	public function get_filesystem($system = "")
1022
+	{
1023
+		if ($system == "storage_filesystem_append") {
1024
+			return $this->storage_filesystem_append;
1025
+		} elseif ($system == "tmp_filesystem_append") {
1026
+			return $this->tmp_filesystem_append;
1027
+		} elseif ($system == "tmp_filesystem") {
1028
+			return $this->tmp_filesystem;
1029
+		} elseif ($system == "storage_filesystem") {
1030
+			return $this->storage_filesystem;
1031
+		} else {
1032
+			return $this->start_filesystem;
1033
+		}
1034
+	}
1035
+
1036
+	public function get_adapter($system)
1037
+	{
1038
+		if ($system == "tmp_filesystem") {
1039
+			return $this->tmp_adapter;
1040
+		} elseif ($system == "storage_filesystem") {
1041
+			return $this->storage_adapter;
1042
+		} else {
1043
+			return $this->start_adapter;
1044
+		}
1045
+	}
1046
+
1047
+	/**
1048
+	 * File scan finished
1049
+	 * Method called when file scan is finished
1050
+	 *
1051
+	 * @return bool
1052
+	 */
1053
+	private function scan_finished()
1054
+	{
1055
+		if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) &&
1056
+			$this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) {
1057
+			return false;
1058
+		}
1059
+
1060
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
1061
+			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
1062
+		}
1063
+
1064
+		$this->logger->debug(sprintf(("File scan finished")));
1065
+
1066
+		return true;
1067
+	}
1068
+
1069
+	/**
1070
+	 * Calculate bytes from MB value
1071
+	 *
1072
+	 * @param int $mb_size
1073
+	 *
1074
+	 * @return float|int
1075
+	 */
1076
+	private function calc_to_bytes($mb_size)
1077
+	{
1078
+		return $mb_size * (1024 * 1024);
1079
+	}
1080 1080
 
1081 1081
 }
Please login to merge, or discard this patch.
Braces   +8 added lines, -6 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
             $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([
103 103
                 'disable_asserts' => true,
104 104
             ]));
105
-        }catch (Exception $e) {
105
+        } catch (Exception $e) {
106 106
             $this->logger->error("Filesystem Initialization Error: ".$e->getMessage());
107 107
         }
108 108
 
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
                 }
646 646
             }
647 647
 
648
-        }catch (Exception $e) {
648
+        } catch (Exception $e) {
649 649
 
650 650
             $this->logger->error($e->getMessage());
651 651
 
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
 
673 673
             $this->tmp_filesystem->delete($tmp_file);
674 674
 
675
-        }catch (Exception $e) {
675
+        } catch (Exception $e) {
676 676
 
677 677
             $this->logger->error($e->getMessage());
678 678
 
@@ -710,9 +710,11 @@  discard block
 block discarded – undo
710 710
         foreach ($_backup_files_list as $file) {
711 711
             //processing rule folder capacity
712 712
             if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
713
-                $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))    //bytes
713
+                $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) {
714
+            	//bytes
714 715
             {
715 716
                 $this->storage_filesystem->delete($file['path']);
717
+            }
716 718
                 $_storage_size -= $file['size'];
717 719
                 $this->logger->info("Deleting backup ".$file['path']." matching rule", array(
718 720
                     "STORAGE SIZE LIMIT",
@@ -979,7 +981,7 @@  discard block
 block discarded – undo
979 981
         if ($file['type'] == "dir") {
980 982
             try {
981 983
                 $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n");
982
-            }catch (Exception $e) {
984
+            } catch (Exception $e) {
983 985
                 $this->logger->error($e->getMessage());
984 986
             }
985 987
         }
@@ -1005,7 +1007,7 @@  discard block
 block discarded – undo
1005 1007
 
1006 1008
             $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
1007 1009
 
1008
-        }catch (Exception $e) {
1010
+        } catch (Exception $e) {
1009 1011
 
1010 1012
             $this->logger->error($e->getMessage());
1011 1013
         }
Please login to merge, or discard this patch.
includes/class-xcloner-deactivator.php 1 patch
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@
 block discarded – undo
54 54
 		if (is_a($xcloner_plugin, 'Xcloner')) {
55 55
 			try {
56 56
 				$xcloner_plugin->get_xcloner_filesystem()->cleanup_tmp_directories();
57
-			}catch (Exception $e) {
57
+			} catch (Exception $e) {
58 58
 				$xcloner_plugin->trigger_message_notice($e->getMessage());
59 59
 			}
60 60
 
Please login to merge, or discard this patch.
includes/class-xcloner.php 2 patches
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -233,84 +233,84 @@  discard block
 block discarded – undo
233 233
 		 * The class responsible for orchestrating the actions and filters of the
234 234
 		 * core plugin.
235 235
 		 */
236
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-loader.php';
236
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-loader.php';
237 237
 
238 238
 		/**
239 239
 		 * The class responsible for defining internationalization functionality
240 240
 		 * of the plugin.
241 241
 		 */
242
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-i18n.php';
242
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-i18n.php';
243 243
 
244 244
 		/**
245 245
 		 * The class responsible for defining all actions that occur in the admin area.
246 246
 		 */
247
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-xcloner-admin.php';
247
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-xcloner-admin.php';
248 248
 
249 249
 		/**
250 250
 		 * The class responsible for debugging XCloner.
251 251
 		 */
252
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-logger.php';
252
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-logger.php';
253 253
 
254 254
 		/**
255 255
 		 * The class responsible for defining the admin settings area.
256 256
 		 */
257
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-settings.php';
257
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-settings.php';
258 258
 
259 259
 		/**
260 260
 		 * The class responsible for defining the Remote Storage settings area.
261 261
 		 */
262
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-remote-storage.php';
262
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-remote-storage.php';
263 263
 
264 264
 		/**
265 265
 		 * The class responsible for implementing the database backup methods.
266 266
 		 */
267
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-database.php';
267
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-database.php';
268 268
 
269 269
 		/**
270 270
 		 * The class responsible for sanitization of users input.
271 271
 		 */
272
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-sanitization.php';
272
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-sanitization.php';
273 273
 
274 274
 		/**
275 275
 		 * The class responsible for XCloner system requirements validation.
276 276
 		 */
277
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-requirements.php';
277
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-requirements.php';
278 278
 
279 279
 		/**
280 280
 		 * The class responsible for XCloner backup archive creation.
281 281
 		 */
282
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-archive.php';
282
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-archive.php';
283 283
 
284 284
 		/**
285 285
 		 * The class responsible for XCloner API requests.
286 286
 		 */
287
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-api.php';
287
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-api.php';
288 288
 
289 289
 		/**
290 290
 		 * The class responsible for the XCloner File System methods.
291 291
 		 */
292
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-file-system.php';
292
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-file-system.php';
293 293
 
294 294
 		/**
295 295
 		 * The class responsible for the XCloner File Transfer methods.
296 296
 		 */
297
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-file-transfer.php';
297
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-file-transfer.php';
298 298
 
299 299
 		/**
300 300
 		 * The class responsible for the XCloner Scheduler methods.
301 301
 		 */
302
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-scheduler.php';
302
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-scheduler.php';
303 303
 
304 304
 		/**
305 305
 		 * The class responsible for the XCloner Encryption methods.
306 306
 		 */
307
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-encryption.php';
307
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-encryption.php';
308 308
 
309 309
 		/**
310 310
 		 * The class responsible for defining all actions that occur in the public-facing
311 311
 		 * side of the site.
312 312
 		 */
313
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-xcloner-public.php';
313
+		require_once plugin_dir_path(dirname(__FILE__)).'public/class-xcloner-public.php';
314 314
 
315 315
 		$this->loader = new Xcloner_Loader($this);
316 316
 
@@ -360,31 +360,31 @@  discard block
 block discarded – undo
360 360
 	 * @access    private
361 361
 	 *
362 362
 	 */
363
-	private function define_admin_menu(){
363
+	private function define_admin_menu() {
364 364
 
365 365
 		add_action('admin_menu', array($this->loader, 'xcloner_backup_add_admin_menu'));
366 366
 
367 367
 	}
368 368
 
369
-	private function define_plugin_settings(){
369
+	private function define_plugin_settings() {
370 370
 		/**
371 371
 		 * register wporg_settings_init to the admin_init action hook
372 372
 		 */
373 373
 
374 374
 		$this->xcloner_settings = new XCloner_Settings($this);
375 375
 
376
-		if(defined('DOING_CRON') || isset($_POST['hash'])){
376
+		if (defined('DOING_CRON') || isset($_POST['hash'])) {
377 377
 
378
-			if(defined('DOING_CRON') || $_POST['hash'] == "generate_hash"){
378
+			if (defined('DOING_CRON') || $_POST['hash'] == "generate_hash") {
379 379
 				$this->xcloner_settings->generate_new_hash();
380
-			}else{
380
+			} else {
381 381
 				$this->xcloner_settings->set_hash($_POST['hash']);
382 382
 			}
383 383
 		}
384 384
 
385
-		if(defined('DOING_CRON') || !isset($_POST['hash']))
385
+		if (defined('DOING_CRON') || !isset($_POST['hash']))
386 386
 		{
387
-			add_action( 'shutdown', function(){
387
+			add_action('shutdown', function() {
388 388
 				$this->xcloner_filesystem = new Xcloner_File_System($this);
389 389
 				$this->xcloner_filesystem->remove_tmp_filesystem();
390 390
 			});
@@ -516,20 +516,20 @@  discard block
 block discarded – undo
516 516
 		$logger = new XCloner_Logger($this, "php_system");
517 517
 		$error = error_get_last();
518 518
 
519
-		if($error['type'] and $logger)
519
+		if ($error['type'] and $logger)
520 520
 		{
521
-			$logger->info($this->friendly_error_type ($error['type']).": ".var_export($error, true));
521
+			$logger->info($this->friendly_error_type($error['type']).": ".var_export($error, true));
522 522
 		}
523 523
 
524 524
 	}
525 525
 
526 526
 	function friendly_error_type($type) {
527
-		static $levels=null;
528
-		if ($levels===null) {
529
-			$levels=[];
527
+		static $levels = null;
528
+		if ($levels === null) {
529
+			$levels = [];
530 530
 			foreach (get_defined_constants() as $key=>$value) {
531
-				if (strpos($key,'E_')!==0) {continue;}
532
-					$levels[$value]= $key; //substr($key,2);
531
+				if (strpos($key, 'E_') !== 0) {continue; }
532
+					$levels[$value] = $key; //substr($key,2);
533 533
 			}
534 534
 		}
535 535
 		return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}");
@@ -539,56 +539,56 @@  discard block
 block discarded – undo
539 539
 	{
540 540
 		//adding the pre-update hook
541 541
 
542
-		if(is_admin() || defined('DOING_CRON'))
542
+		if (is_admin() || defined('DOING_CRON'))
543 543
 		{
544
-			$this->xcloner_logger 			= new XCloner_Logger($this, "xcloner_api");
545
-			$this->xcloner_filesystem 		= new Xcloner_File_System($this);
544
+			$this->xcloner_logger = new XCloner_Logger($this, "xcloner_api");
545
+			$this->xcloner_filesystem = new Xcloner_File_System($this);
546 546
 
547 547
 			//$this->xcloner_filesystem->set_diff_timestamp_start (strtotime("-15 days"));
548 548
 
549
-			$this->archive_system 			= new Xcloner_Archive($this);
550
-			$this->xcloner_database 		= new Xcloner_Database($this);
551
-			$this->xcloner_scheduler 		= new Xcloner_Scheduler($this);
552
-			$this->xcloner_remote_storage 	= new Xcloner_Remote_Storage($this);
549
+			$this->archive_system = new Xcloner_Archive($this);
550
+			$this->xcloner_database = new Xcloner_Database($this);
551
+			$this->xcloner_scheduler = new Xcloner_Scheduler($this);
552
+			$this->xcloner_remote_storage = new Xcloner_Remote_Storage($this);
553 553
 			$this->xcloner_file_transfer 	= new Xcloner_File_Transfer($this);
554 554
 			$this->xcloner_encryption    	= new Xcloner_Encryption($this);
555 555
 
556
-			$xcloner_api 					= new Xcloner_Api($this);
557
-
558
-			add_action( 'wp_ajax_get_database_tables_action', 	array($xcloner_api,'get_database_tables_action')  );
559
-			add_action( 'wp_ajax_get_file_system_action', 		array($xcloner_api,'get_file_system_action')  );
560
-			add_action( 'wp_ajax_scan_filesystem', 				array($xcloner_api,'scan_filesystem')  );
561
-			add_action( 'wp_ajax_backup_database', 				array($xcloner_api,'backup_database')  );
562
-			add_action( 'wp_ajax_backup_files'	, 				array($xcloner_api,'backup_files')  );
563
-			add_action( 'wp_ajax_save_schedule'	, 				array($xcloner_api,'save_schedule')  );
564
-			add_action( 'wp_ajax_get_schedule_by_id',	 		array($xcloner_api,'get_schedule_by_id')  );
565
-			add_action( 'wp_ajax_get_scheduler_list',	 		array($xcloner_api,'get_scheduler_list')  );
566
-			add_action( 'wp_ajax_delete_schedule_by_id'	, 		array($xcloner_api,'delete_schedule_by_id')  );
567
-			add_action( 'wp_ajax_delete_backup_by_name'	, 		array($xcloner_api,'delete_backup_by_name')  );
568
-			add_action( 'wp_ajax_download_backup_by_name', 		array($xcloner_api,'download_backup_by_name')  );
569
-			add_action( 'wp_ajax_remote_storage_save_status', 	array($xcloner_api,'remote_storage_save_status')  );
570
-			add_action( 'wp_ajax_upload_backup_to_remote', 		array($xcloner_api,'upload_backup_to_remote')  );
571
-			add_action( 'wp_ajax_list_backup_files'	,			array($xcloner_api,'list_backup_files')  );
572
-			add_action( 'wp_ajax_restore_upload_backup'	, 		array($xcloner_api,'restore_upload_backup')  );
573
-			add_action( 'wp_ajax_download_restore_script', 		array($xcloner_api,'download_restore_script')  );
574
-			add_action( 'wp_ajax_copy_backup_remote_to_local', 	array($xcloner_api,'copy_backup_remote_to_local')  );
575
-			add_action( 'wp_ajax_restore_backup', 				array($xcloner_api,'restore_backup')  );
576
-			add_action( 'wp_ajax_backup_encryption', 			array($xcloner_api,'backup_encryption')  );
577
-			add_action( 'wp_ajax_backup_decryption', 			array($xcloner_api,'backup_decryption')  );
578
-			add_action( 'wp_ajax_get_manage_backups_list', 		array($xcloner_api,'get_manage_backups_list')  );
579
-			add_action( 'admin_notices', 						array($this, 'xcloner_error_admin_notices' ));
556
+			$xcloner_api = new Xcloner_Api($this);
557
+
558
+			add_action('wp_ajax_get_database_tables_action', array($xcloner_api, 'get_database_tables_action'));
559
+			add_action('wp_ajax_get_file_system_action', array($xcloner_api, 'get_file_system_action'));
560
+			add_action('wp_ajax_scan_filesystem', array($xcloner_api, 'scan_filesystem'));
561
+			add_action('wp_ajax_backup_database', array($xcloner_api, 'backup_database'));
562
+			add_action('wp_ajax_backup_files', array($xcloner_api, 'backup_files'));
563
+			add_action('wp_ajax_save_schedule', array($xcloner_api, 'save_schedule'));
564
+			add_action('wp_ajax_get_schedule_by_id', array($xcloner_api, 'get_schedule_by_id'));
565
+			add_action('wp_ajax_get_scheduler_list', array($xcloner_api, 'get_scheduler_list'));
566
+			add_action('wp_ajax_delete_schedule_by_id', array($xcloner_api, 'delete_schedule_by_id'));
567
+			add_action('wp_ajax_delete_backup_by_name', array($xcloner_api, 'delete_backup_by_name'));
568
+			add_action('wp_ajax_download_backup_by_name', array($xcloner_api, 'download_backup_by_name'));
569
+			add_action('wp_ajax_remote_storage_save_status', array($xcloner_api, 'remote_storage_save_status'));
570
+			add_action('wp_ajax_upload_backup_to_remote', array($xcloner_api, 'upload_backup_to_remote'));
571
+			add_action('wp_ajax_list_backup_files', array($xcloner_api, 'list_backup_files'));
572
+			add_action('wp_ajax_restore_upload_backup', array($xcloner_api, 'restore_upload_backup'));
573
+			add_action('wp_ajax_download_restore_script', array($xcloner_api, 'download_restore_script'));
574
+			add_action('wp_ajax_copy_backup_remote_to_local', array($xcloner_api, 'copy_backup_remote_to_local'));
575
+			add_action('wp_ajax_restore_backup', array($xcloner_api, 'restore_backup'));
576
+			add_action('wp_ajax_backup_encryption', array($xcloner_api, 'backup_encryption'));
577
+			add_action('wp_ajax_backup_decryption', array($xcloner_api, 'backup_decryption'));
578
+			add_action('wp_ajax_get_manage_backups_list', array($xcloner_api, 'get_manage_backups_list'));
579
+			add_action('admin_notices', array($this, 'xcloner_error_admin_notices'));
580 580
 
581 581
 		}
582 582
 
583 583
 		//Do a pre-update backup of targeted files
584
-		if($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup'))
584
+		if ($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup'))
585 585
 		{
586 586
 			add_action("pre_auto_update", array($this, "pre_auto_update"), 1, 3);
587 587
 		}
588 588
 	}
589 589
 
590 590
 	function add_plugin_action_links($links, $file) {
591
-		if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php'))
591
+		if ($file == plugin_basename(dirname(dirname(__FILE__)).'/xcloner.php'))
592 592
 		{
593 593
 			$links[] = '<a href="admin.php?page=xcloner_settings_page">'.__('Settings', 'xcloner-backup-and-restore').'</a>';
594 594
 			$links[] = '<a href="admin.php?page=xcloner_generate_backups_page">'.__('Generate Backup', 'xcloner-backup-and-restore').'</a>';
Please login to merge, or discard this patch.
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
 
378 378
 			if(defined('DOING_CRON') || $_POST['hash'] == "generate_hash"){
379 379
 				$this->xcloner_settings->generate_new_hash();
380
-			}else{
380
+			} else{
381 381
 				$this->xcloner_settings->set_hash($_POST['hash']);
382 382
 			}
383 383
 		}
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
 
490 490
 		try {
491 491
 			$this->xcloner_scheduler->xcloner_scheduler_callback(0, $schedule);
492
-		}catch (Exception $e) {
492
+		} catch (Exception $e) {
493 493
 			$this->get_xcloner_logger()->error($e->getMessage());
494 494
 		}
495 495
 
Please login to merge, or discard this patch.
includes/class-xcloner-activator.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -61,22 +61,22 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
includes/class-xcloner-i18n.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@
 block discarded – undo
52 52
 		load_plugin_textdomain(
53 53
 			'xcloner-backup-and-restore',
54 54
 			false,
55
-			dirname(dirname(plugin_basename(__FILE__))) . '/languages/'
55
+			dirname(dirname(plugin_basename(__FILE__))).'/languages/'
56 56
 		);
57 57
 
58 58
 	}
Please login to merge, or discard this patch.
includes/class-xcloner-database.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -337,7 +337,7 @@
 block discarded – undo
337 337
 
338 338
 			$result = $this->get_var("SELECT count(*) FROM $table;");
339 339
 
340
-			return intval($result) ;// not max limit on 32 bit systems 2147483647; on 64 bit 999999999999
340
+			return intval($result); // not max limit on 32 bit systems 2147483647; on 64 bit 999999999999
341 341
 
342 342
 	}
343 343
 
Please login to merge, or discard this patch.
Braces   +71 added lines, -48 removed lines patch added patch discarded remove patch
@@ -44,11 +44,13 @@  discard block
 block discarded – undo
44 44
 		$this->xcloner_settings = $xcloner_container->get_xcloner_settings();
45 45
 		$this->fs = $xcloner_container->get_xcloner_filesystem();
46 46
 		
47
-		if ($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'))
48
-			$this->recordsPerSession = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
47
+		if ($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request')) {
48
+					$this->recordsPerSession = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
49
+		}
49 50
 		
50
-		if (!$this->recordsPerSession)
51
-			$this->recordsPerSession = 100;
51
+		if (!$this->recordsPerSession) {
52
+					$this->recordsPerSession = 100;
53
+		}
52 54
 		
53 55
 		if (!$wp_user && !$wp_pass && !$wp_host && !$wp_db)
54 56
 		{
@@ -108,37 +110,43 @@  discard block
 block discarded – undo
108 110
 			{
109 111
 				foreach ($params['#'] as $database)
110 112
 				{
111
-					if (!isset($params[$database]) or !is_array($params[$database]))
112
-						$params[$database] = array();
113
+					if (!isset($params[$database]) or !is_array($params[$database])) {
114
+											$params[$database] = array();
115
+					}
113 116
 				}
114 117
 				$db_count = -1;
115 118
 			}
116 119
 			
117
-			if (isset($params) and is_array($params))
118
-				foreach ($params as $database=>$tables)
120
+			if (isset($params) and is_array($params)) {
121
+							foreach ($params as $database=>$tables)
119 122
 				{	
120 123
 					if ($database != "#")
121 124
 					{
122
-						$stats = $this->write_backup_process_list($database, $tables);	
125
+						$stats = $this->write_backup_process_list($database, $tables);
126
+			}
123 127
 						$return['stats']['tables_count'] += $stats['tables_count'];
124 128
 						$return['stats']['total_records'] += $stats['total_records'];
125 129
 					}
126 130
 				}
127 131
 
128
-			if (sizeof($params))
129
-				$return['stats']['database_count'] = sizeof($params) + $db_count;
130
-			else	
131
-				$return['stats']['database_count'] = 0;
132
+			if (sizeof($params)) {
133
+							$return['stats']['database_count'] = sizeof($params) + $db_count;
134
+			} else {
135
+							$return['stats']['database_count'] = 0;
136
+			}
132 137
 				
133 138
 			return $return;
134 139
 		}
135 140
 		
136
-		if (!isset($extra_params['startAtLine']))
137
-			$extra_params['startAtLine'] = 0;
138
-		if (!isset($extra_params['startAtRecord']))
139
-			$extra_params['startAtRecord'] = 0;
140
-		if (!isset($extra_params['dumpfile']))
141
-			$extra_params['dumpfile'] = "";
141
+		if (!isset($extra_params['startAtLine'])) {
142
+					$extra_params['startAtLine'] = 0;
143
+		}
144
+		if (!isset($extra_params['startAtRecord'])) {
145
+					$extra_params['startAtRecord'] = 0;
146
+		}
147
+		if (!isset($extra_params['dumpfile'])) {
148
+					$extra_params['dumpfile'] = "";
149
+		}
142 150
 		
143 151
 		$return = $this->process_incremental($extra_params['startAtLine'], $extra_params['startAtRecord'], $extra_params['dumpfile']);
144 152
 		
@@ -151,10 +159,12 @@  discard block
 block discarded – undo
151 159
 		if ($message) {
152 160
 			$this->logger->info($message, array(""));
153 161
 		} else {	
154
-			if ($this->last_query)
155
-				$this->logger->debug($this->last_query, array(""));
156
-			if ($this->last_error)
157
-				$this->logger->error($this->last_error, array(""));
162
+			if ($this->last_query) {
163
+							$this->logger->debug($this->last_query, array(""));
164
+			}
165
+			if ($this->last_error) {
166
+							$this->logger->error($this->last_error, array(""));
167
+			}
158 168
 		}
159 169
 		
160 170
 		return;
@@ -225,11 +235,12 @@  discard block
 block discarded – undo
225 235
 		$databases_list[$i]['num_tables'] = $this->get_database_num_tables($this->dbname);
226 236
 		$i++;
227 237
 		
228
-		if (is_array($databases))
229
-		foreach ($databases as $db) {
238
+		if (is_array($databases)) {
239
+				foreach ($databases as $db) {
230 240
 			if ($db->Database != $this->dbname)
231 241
 			{
232 242
 				$databases_list[$i]['name'] = $db->Database;
243
+		}
233 244
 				$databases_list[$i]['num_tables'] = $this->get_database_num_tables($db->Database);
234 245
 				$i++;
235 246
 			}
@@ -252,8 +263,9 @@  discard block
 block discarded – undo
252 263
 		$tablesList[0] = array( );
253 264
 		$inc = 0;
254 265
 
255
-		if (!$database)
256
-			$database = $this->dbname;
266
+		if (!$database) {
267
+					$database = $this->dbname;
268
+		}
257 269
 		
258 270
 		$this->logger->debug(sprintf(("Listing tables in %s database"), $database));
259 271
 		
@@ -277,10 +289,11 @@  discard block
 block discarded – undo
277 289
 			
278 290
 			$tablesList[$inc]['excluded'] = 0;
279 291
 						
280
-			if (sizeof($included) and is_array($included))
281
-				if (!in_array($table, $included))
292
+			if (sizeof($included) and is_array($included)) {
293
+							if (!in_array($table, $included))
282 294
 				{
283 295
 					$tablesList[$inc]['excluded'] = 1;
296
+			}
284 297
 					$this->log(sprintf(__("Excluding table %s.%s from backup"), $table, $database));
285 298
 				}
286 299
 			$inc++;
@@ -299,19 +312,21 @@  discard block
 block discarded – undo
299 312
 		
300 313
 		$tables = $this->list_tables($dbname, $incl_tables, 1);
301 314
 		
302
-		if ($this->dbname != $dbname)
303
-			$dumpfile = $dbname."-backup.sql";
304
-		else
305
-			$dumpfile = $this->TEMP_DUMP_FILE;
315
+		if ($this->dbname != $dbname) {
316
+					$dumpfile = $dbname."-backup.sql";
317
+		} else {
318
+					$dumpfile = $this->TEMP_DUMP_FILE;
319
+		}
306 320
 		
307 321
 		$line = sprintf("###newdump###\t%s\t%s\n", $dbname, $dumpfile);
308 322
 		$this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line);
309 323
 			
310 324
 		// write this to the class and write to $TEMP_DBPROCESS_FILE file as database.table records
311
-		foreach ($tables as $key=>$table) 
312
-		if ($table != "" and !$tables[$key]['excluded']) {
325
+		foreach ($tables as $key=>$table) {
326
+				if ($table != "" and !$tables[$key]['excluded']) {
313 327
 
314 328
 			$line = sprintf("`%s`.`%s`\t%s\t%s\n", $dbname, $tables[$key]['name'], $tables[$key]['records'], $tables[$key]['excluded']);
329
+		}
315 330
 			$this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line);
316 331
 			$return['tables_count']++;
317 332
 			$return['total_records'] += $tables[$key]['records'];
@@ -359,8 +374,9 @@  discard block
 block discarded – undo
359 374
 		$return['finished'] = 0;
360 375
 		$lines = array();
361 376
 		
362
-		if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE))
363
-			$lines = array_filter(explode("\n", $this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE)));
377
+		if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) {
378
+					$lines = array_filter(explode("\n", $this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE)));
379
+		}
364 380
 	
365 381
 		foreach ($lines as $buffer) {
366 382
 			
@@ -387,12 +403,14 @@  discard block
 block discarded – undo
387 403
 						//break;
388 404
 				} else {
389 405
 						//we export the table
390
-						if ($tableInfo[0] == "###enddump###")
391
-							$return['endDump'] = 1;
406
+						if ($tableInfo[0] == "###enddump###") {
407
+													$return['endDump'] = 1;
408
+						}
392 409
 	
393 410
 						//table is excluded
394
-						if ($tableInfo[2])
395
-							continue;
411
+						if ($tableInfo[2]) {
412
+													continue;
413
+						}
396 414
 							
397 415
 						$next = $startAtRecord + $this->recordsPerSession;
398 416
 						
@@ -408,14 +426,17 @@  discard block
 block discarded – undo
408 426
 
409 427
 						$processed_records = 0;
410 428
 						
411
-						if (trim($tableName) != "" and !$tableInfo[2])
412
-							$processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile);
429
+						if (trim($tableName) != "" and !$tableInfo[2]) {
430
+													$processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile);
431
+						}
413 432
 						
414 433
 						$return['processedRecords'] = $startAtRecord + $processed_records;
415 434
 						
416
-						if ($next >= $tableInfo[1]) //we finished loading the records for next sessions, will go to the new record
435
+						if ($next >= $tableInfo[1]) {
436
+							//we finished loading the records for next sessions, will go to the new record
417 437
 						{
418 438
 								$startAtLine++;
439
+						}
419 440
 								$startAtRecord = 0;
420 441
 						} else {
421 442
 								$startAtRecord = $startAtRecord + $this->recordsPerSession;
@@ -450,8 +471,9 @@  discard block
 block discarded – undo
450 471
 		$return['finished'] = 1;
451 472
 		$return['startAtLine'] = $startAtLine;
452 473
 		
453
-		if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE))
454
-			$this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE);
474
+		if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) {
475
+					$this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE);
476
+		}
455 477
 		
456 478
 		$this->logger->debug(sprintf(("Database backup finished!")));
457 479
 		
@@ -484,8 +506,9 @@  discard block
 block discarded – undo
484 506
 		
485 507
 		$records = 0;
486 508
 		
487
-		if ($start == 0)
488
-			$this->dump_structure($databaseName, $tableName, $dumpfile);
509
+		if ($start == 0) {
510
+					$this->dump_structure($databaseName, $tableName, $dumpfile);
511
+		}
489 512
 
490 513
 		$start = intval($start);
491 514
 		$limit = intval($limit);
Please login to merge, or discard this patch.