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.
Completed
Push — master ( 67f878...5fe6bb )
by Liuta
07:51
created
admin/partials/xcloner_manage_backups_page.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 $storage_selection = "";
7 7
 
8 8
 if (isset($_GET['storage_selection']) and $_GET['storage_selection']) {
9
-    $storage_selection = $xcloner_sanitization->sanitize_input_as_string($_GET['storage_selection']);
9
+	$storage_selection = $xcloner_sanitization->sanitize_input_as_string($_GET['storage_selection']);
10 10
 }
11 11
 
12 12
 $backup_list = $xcloner_file_system->get_backup_archives_list($storage_selection);
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 
35 35
             <?php foreach ($available_storages as $storage => $text): ?>
36 36
                 <option value="<?php echo $storage ?>"<?php if ($storage == $storage_selection)
37
-                    echo "selected" ?>><?php echo $text ?></option>
37
+					echo "selected" ?>><?php echo $text ?></option>
38 38
             <?php endforeach ?>
39 39
         </select>
40 40
         <?php endif ?>
@@ -61,21 +61,21 @@  discard block
 block discarded – undo
61 61
 
62 62
 
63 63
         <?php
64
-        $i = 0;
65
-        foreach ($backup_list as $file_info):?>
64
+		$i = 0;
65
+		foreach ($backup_list as $file_info):?>
66 66
             <?php
67
-            if ($storage_selection == "gdrive") {
68
-                $file_info['path'] = $file_info['filename'] . "." . $file_info['extension'];
69
-            }
70
-            $file_exists_on_local_storage = true;
71
-
72
-            if ($storage_selection) {
73
-                if (!$xcloner_file_system->get_storage_filesystem()->has($file_info['path'])) {
74
-                    $file_exists_on_local_storage = false;
75
-                }
76
-            }
77
-
78
-            ?>
67
+			if ($storage_selection == "gdrive") {
68
+				$file_info['path'] = $file_info['filename'] . "." . $file_info['extension'];
69
+			}
70
+			$file_exists_on_local_storage = true;
71
+
72
+			if ($storage_selection) {
73
+				if (!$xcloner_file_system->get_storage_filesystem()->has($file_info['path'])) {
74
+					$file_exists_on_local_storage = false;
75
+				}
76
+			}
77
+
78
+			?>
79 79
             <?php if (!isset($file_info['parent'])): ?>
80 80
 
81 81
                 <tr>
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
                         <?php if (!$file_exists_on_local_storage): ?>
92 92
                             <a href="#"
93 93
                                title="<?php echo __("File does not exists on local storage",
94
-                                   "xcloner-backup-and-restore") ?>"><i
94
+								   "xcloner-backup-and-restore") ?>"><i
95 95
                                         class="material-icons backup_warning">warning</i></a>
96 96
                         <?php endif ?>
97 97
                         <?php
98
-                        if (isset($file_info['childs']) and is_array($file_info['childs'])):
99
-                            ?>
98
+						if (isset($file_info['childs']) and is_array($file_info['childs'])):
99
+							?>
100 100
                             <a href="#" title="expand" class="expand-multipart add"><i
101 101
                                         class="material-icons">add</i></a>
102 102
                             <a href="#" title="collapse" class="expand-multipart remove"><i class="material-icons">remove</i></a>
@@ -105,17 +105,17 @@  discard block
 block discarded – undo
105 105
                                     <li>
106 106
                                         <?php echo $child[0] ?> (<?php echo size_format($child[2]) ?>)
107 107
                                         <?php
108
-                                        $child_exists_on_local_storage = true;
109
-                                        if ($storage_selection) {
110
-                                            if (!$xcloner_file_system->get_storage_filesystem()->has($child[0])) {
111
-                                                $child_exists_on_local_storage = false;
112
-                                            }
113
-                                        }
114
-                                        ?>
108
+										$child_exists_on_local_storage = true;
109
+										if ($storage_selection) {
110
+											if (!$xcloner_file_system->get_storage_filesystem()->has($child[0])) {
111
+												$child_exists_on_local_storage = false;
112
+											}
113
+										}
114
+										?>
115 115
                                         <?php if (!$child_exists_on_local_storage): ?>
116 116
                                             <a href="#"
117 117
                                                title="<?php echo __("File does not exists on local storage",
118
-                                                   "xcloner-backup-and-restore") ?>"><i
118
+												   "xcloner-backup-and-restore") ?>"><i
119 119
                                                         class="material-icons backup_warning">warning</i></a>
120 120
                                         <?php endif ?>
121 121
                                         <?php if (!$storage_selection) : ?>
@@ -123,12 +123,12 @@  discard block
 block discarded – undo
123 123
                                                title="Download Backup"><i class="material-icons">file_download</i></a>
124 124
                                             <a href="#<?php echo $child[0] ?>" class="list-backup-content"
125 125
                                                title="<?php echo __('List Backup Content',
126
-                                                   'xcloner-backup-and-restore') ?>"><i
126
+												   'xcloner-backup-and-restore') ?>"><i
127 127
                                                         class="material-icons">folder_open</i></a>
128 128
                                         <?php elseif ($storage_selection != "gdrive" && !$xcloner_file_system->get_storage_filesystem()->has($child[0])): ?>
129 129
                                             <a href="#<?php echo $child[0] ?>" class="copy-remote-to-local"
130 130
                                                title="<?php echo __('Push Backup To Local Storage',
131
-                                                   'xcloner-backup-and-restore') ?>"><i
131
+												   'xcloner-backup-and-restore') ?>"><i
132 132
                                                         class="material-icons">file_upload</i></a>
133 133
                                         <?php endif ?>
134 134
                                     </li>
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
                         <?php endif; ?>
138 138
                     </td>
139 139
                     <td><?php if (isset($file_info['timestamp']))
140
-                            echo date("Y-m-d H:i", $file_info['timestamp']) ?></td>
140
+							echo date("Y-m-d H:i", $file_info['timestamp']) ?></td>
141 141
                     <td><?php echo size_format($file_info['size']) ?></td>
142 142
                     <td>
143 143
                         <?php if (!$storage_selection): ?>
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
                             <?php if (sizeof($available_storages)): ?>
149 149
                                 <a href="#<?php echo $file_info['basename'] ?>" class="cloud-upload"
150 150
                                    title="<?php echo __('Send Backup To Remote Storage',
151
-                                       'xcloner-backup-and-restore') ?>"><i
151
+									   'xcloner-backup-and-restore') ?>"><i
152 152
                                             class="material-icons">cloud_upload</i></a>
153 153
                             <?php endif ?>
154 154
                             <a href="#<?php echo $file_info['basename'] ?>" class="list-backup-content"
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
                 <div class="row">
221 221
                     <div class="col s12 label">
222 222
                         <label><?php echo sprintf(__('Send %s to remote storage', 'xcloner-backup-and-restore'),
223
-                                "<span class='backup_name'></span>") ?></label>
223
+								"<span class='backup_name'></span>") ?></label>
224 224
                     </div>
225 225
                     <div class="input-field col s8 m10">
226 226
                         <select name="transfer_storage" id="transfer_storage" class="validate" required>
Please login to merge, or discard this patch.
includes/class-xcloner-remote-storage.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -170,60 +170,60 @@
 block discarded – undo
170 170
 
171 171
 		foreach($this->storage_fields as $main_key=>$array){
172 172
 
173
-		    if(is_array($array)) {
174
-                foreach ($array as $key => $type) {
173
+			if(is_array($array)) {
174
+				foreach ($array as $key => $type) {
175 175
 
176
-                    if( $type == "raw") {
177
-                        add_filter("pre_update_option_" . $this->storage_fields['option_prefix'] . $key,
178
-                            function ($value) {
176
+					if( $type == "raw") {
177
+						add_filter("pre_update_option_" . $this->storage_fields['option_prefix'] . $key,
178
+							function ($value) {
179 179
 
180
-                                return $this->simple_crypt($value, 'e');
180
+								return $this->simple_crypt($value, 'e');
181 181
 
182
-                            }, 10, 1);
182
+							}, 10, 1);
183 183
 
184
-                        add_filter("option_" . $this->storage_fields['option_prefix'] . $key, function ($value) {
184
+						add_filter("option_" . $this->storage_fields['option_prefix'] . $key, function ($value) {
185 185
 
186
-                            return $this->simple_crypt($value, 'd');
186
+							return $this->simple_crypt($value, 'd');
187 187
 
188
-                        }, 10, 1);
189
-                    }
188
+						}, 10, 1);
189
+					}
190 190
 
191
-                }
192
-            }
193
-        }
191
+				}
192
+			}
193
+		}
194 194
 
195 195
 	}
196 196
 
197
-    /**
198
-     * Encrypts and Decrypt a string based on openssl lib
199
-     *
200
-     * @param $string
201
-     * @param string $action
202
-     * @return string
203
-     */
204
-    private function simple_crypt( $string, $action = 'e' ) {
205
-        // you may change these values to your own
206
-        $secret_key = NONCE_KEY;
207
-        $secret_iv = NONCE_SALT;
208
-
209
-        $output = $string;
210
-        $encrypt_method = "AES-256-CBC";
211
-        $key = hash( 'sha256', $secret_key );
212
-        $iv = substr( hash( 'sha256', $secret_iv ), 0, 16 );
213
-
214
-        if( $action == 'e' && function_exists('openssl_encrypt')) {
215
-            $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) );
216
-        }
217
-        else if( $action == 'd' && function_exists('openssl_decrypt') && base64_decode( $string )){
218
-            $decrypt = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );
219
-            if($decrypt) {
220
-                //we check if decrypt was succesful
221
-                $output = $decrypt;
222
-            }
223
-        }
224
-
225
-        return $output;
226
-    }
197
+	/**
198
+	 * Encrypts and Decrypt a string based on openssl lib
199
+	 *
200
+	 * @param $string
201
+	 * @param string $action
202
+	 * @return string
203
+	 */
204
+	private function simple_crypt( $string, $action = 'e' ) {
205
+		// you may change these values to your own
206
+		$secret_key = NONCE_KEY;
207
+		$secret_iv = NONCE_SALT;
208
+
209
+		$output = $string;
210
+		$encrypt_method = "AES-256-CBC";
211
+		$key = hash( 'sha256', $secret_key );
212
+		$iv = substr( hash( 'sha256', $secret_iv ), 0, 16 );
213
+
214
+		if( $action == 'e' && function_exists('openssl_encrypt')) {
215
+			$output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) );
216
+		}
217
+		else if( $action == 'd' && function_exists('openssl_decrypt') && base64_decode( $string )){
218
+			$decrypt = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );
219
+			if($decrypt) {
220
+				//we check if decrypt was succesful
221
+				$output = $decrypt;
222
+			}
223
+		}
224
+
225
+		return $output;
226
+	}
227 227
 
228 228
 	private function get_xcloner_container() {
229 229
 		return $this->xcloner_container;
Please login to merge, or discard this patch.
includes/class-xcloner-archive.php 1 patch
Indentation   +513 added lines, -513 removed lines patch added patch discarded remove patch
@@ -36,171 +36,171 @@  discard block
 block discarded – undo
36 36
  */
37 37
 class Xcloner_Archive extends Tar
38 38
 {
39
-    /**
40
-     * Process file size per API request
41
-     * @var float|int
42
-     */
43
-    private $file_size_per_request_limit = 52428800; //50MB = 52428800; 1MB = 1048576
44
-    /**
45
-     * Files count to process per API request
46
-     * @var int
47
-     */
48
-    private $files_to_process_per_request = 250; //block of 512 bytes
49
-    /**
50
-     * Compression level, 0-uncompressed, 9-maximum compression
51
-     * @var int
52
-     */
53
-    private $compression_level = 0; //0-9 , 0 uncompressed
54
-    /**
55
-     * Split backup size limit
56
-     * Create a new backup archive file once the set size is reached
57
-     * @var float|int
58
-     */
59
-    private $xcloner_split_backup_limit = 2048; //2048MB
60
-    /**
61
-     * Number of processed bytes
62
-     * @var int
63
-     */
64
-    private $processed_size_bytes = 0;
65
-
66
-    /**
67
-     * Archive name
68
-     * @var string
69
-     */
70
-    private $archive_name;
71
-    /**
72
-     * @var Tar
73
-     */
74
-    private $backup_archive;
75
-    /**
76
-     * @var Xcloner_File_System
77
-     */
78
-    private $filesystem;
79
-    /**
80
-     * @var Xcloner_Logger
81
-     */
82
-    private $logger;
83
-    /**
84
-     * @var Xcloner_Settings
85
-     */
86
-    private $xcloner_settings;
87
-
88
-    /**
89
-     * [__construct description]
90
-     * @param Xcloner $xcloner_container XCloner Container
91
-     * @param string $archive_name Achive Name
92
-     */
93
-    public function __construct(Xcloner $xcloner_container, $archive_name = "")
94
-    {
95
-        $this->filesystem = $xcloner_container->get_xcloner_filesystem();
96
-        $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_archive");
97
-        $this->xcloner_settings = $xcloner_container->get_xcloner_settings();
98
-
99
-        if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) {
100
-            $this->file_size_per_request_limit = $value * 1024 * 1024;
101
-        } //MB
102
-
103
-        if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) {
104
-            $this->files_to_process_per_request = $value;
105
-        }
39
+	/**
40
+	 * Process file size per API request
41
+	 * @var float|int
42
+	 */
43
+	private $file_size_per_request_limit = 52428800; //50MB = 52428800; 1MB = 1048576
44
+	/**
45
+	 * Files count to process per API request
46
+	 * @var int
47
+	 */
48
+	private $files_to_process_per_request = 250; //block of 512 bytes
49
+	/**
50
+	 * Compression level, 0-uncompressed, 9-maximum compression
51
+	 * @var int
52
+	 */
53
+	private $compression_level = 0; //0-9 , 0 uncompressed
54
+	/**
55
+	 * Split backup size limit
56
+	 * Create a new backup archive file once the set size is reached
57
+	 * @var float|int
58
+	 */
59
+	private $xcloner_split_backup_limit = 2048; //2048MB
60
+	/**
61
+	 * Number of processed bytes
62
+	 * @var int
63
+	 */
64
+	private $processed_size_bytes = 0;
65
+
66
+	/**
67
+	 * Archive name
68
+	 * @var string
69
+	 */
70
+	private $archive_name;
71
+	/**
72
+	 * @var Tar
73
+	 */
74
+	private $backup_archive;
75
+	/**
76
+	 * @var Xcloner_File_System
77
+	 */
78
+	private $filesystem;
79
+	/**
80
+	 * @var Xcloner_Logger
81
+	 */
82
+	private $logger;
83
+	/**
84
+	 * @var Xcloner_Settings
85
+	 */
86
+	private $xcloner_settings;
87
+
88
+	/**
89
+	 * [__construct description]
90
+	 * @param Xcloner $xcloner_container XCloner Container
91
+	 * @param string $archive_name Achive Name
92
+	 */
93
+	public function __construct(Xcloner $xcloner_container, $archive_name = "")
94
+	{
95
+		$this->filesystem = $xcloner_container->get_xcloner_filesystem();
96
+		$this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_archive");
97
+		$this->xcloner_settings = $xcloner_container->get_xcloner_settings();
98
+
99
+		if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) {
100
+			$this->file_size_per_request_limit = $value * 1024 * 1024;
101
+		} //MB
102
+
103
+		if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) {
104
+			$this->files_to_process_per_request = $value;
105
+		}
106 106
 
107
-        if ($value = get_option('xcloner_backup_compression_level')) {
108
-            $this->compression_level = $value;
109
-        }
107
+		if ($value = get_option('xcloner_backup_compression_level')) {
108
+			$this->compression_level = $value;
109
+		}
110 110
 
111
-        if ($value = get_option('xcloner_split_backup_limit')) {
112
-            $this->xcloner_split_backup_limit = $value;
113
-        }
111
+		if ($value = get_option('xcloner_split_backup_limit')) {
112
+			$this->xcloner_split_backup_limit = $value;
113
+		}
114 114
 
115
-        $this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024 * 1024; //transform to bytes
115
+		$this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024 * 1024; //transform to bytes
116 116
 
117
-        if (isset($archive_name) && $archive_name) {
118
-            $this->set_archive_name($archive_name);
119
-        }
120
-    }
117
+		if (isset($archive_name) && $archive_name) {
118
+			$this->set_archive_name($archive_name);
119
+		}
120
+	}
121 121
 
122
-    /*
122
+	/*
123 123
      * Rename backup archive
124 124
      *
125 125
      * @param string $old_name
126 126
      * @param string $new_name
127 127
      *
128 128
      */
129
-    public function rename_archive($old_name, $new_name)
130
-    {
131
-        $this->logger->info(sprintf("Renaming backup archive %s to %s", $old_name, $new_name));
132
-        $storage_filesystem = $this->filesystem->get_storage_filesystem();
133
-        $storage_filesystem->rename($old_name, $new_name);
134
-    }
135
-
136
-    /*
129
+	public function rename_archive($old_name, $new_name)
130
+	{
131
+		$this->logger->info(sprintf("Renaming backup archive %s to %s", $old_name, $new_name));
132
+		$storage_filesystem = $this->filesystem->get_storage_filesystem();
133
+		$storage_filesystem->rename($old_name, $new_name);
134
+	}
135
+
136
+	/*
137 137
      *
138 138
      * Set the backup archive name
139 139
      *
140 140
      */
141
-    public function set_archive_name($name = "", $part = 0)
142
-    {
141
+	public function set_archive_name($name = "", $part = 0)
142
+	{
143 143
 
144
-        $this->archive_name = $this->filesystem->process_backup_name($name);
144
+		$this->archive_name = $this->filesystem->process_backup_name($name);
145 145
 
146
-        if ($diff_timestamp_start = $this->filesystem->get_diff_timestamp_start()) {
147
-            //$this->archive_name = $this->archive_name."-diff-".date("Y-m-d_H-i",$diff_timestamp_start);
148
-            $new_name = $this->archive_name;
146
+		if ($diff_timestamp_start = $this->filesystem->get_diff_timestamp_start()) {
147
+			//$this->archive_name = $this->archive_name."-diff-".date("Y-m-d_H-i",$diff_timestamp_start);
148
+			$new_name = $this->archive_name;
149 149
 
150
-            if (!stristr($new_name, "-diff")) {
151
-                $new_name = $this->archive_name . "-diff" . date("Y-m-d_H-i", $diff_timestamp_start);
152
-            }
150
+			if (!stristr($new_name, "-diff")) {
151
+				$new_name = $this->archive_name . "-diff" . date("Y-m-d_H-i", $diff_timestamp_start);
152
+			}
153 153
 
154
-            $this->archive_name = $new_name;
154
+			$this->archive_name = $new_name;
155 155
 
156
-        }
156
+		}
157 157
 
158
-        if (isset($part) and $part) {
159
-            $new_name = preg_replace('/-part(\d*)/', "-part" . $part, $this->archive_name);
160
-            if (!stristr($new_name, "-part")) {
161
-                $new_name = $this->archive_name . "-part" . $part;
162
-            }
158
+		if (isset($part) and $part) {
159
+			$new_name = preg_replace('/-part(\d*)/', "-part" . $part, $this->archive_name);
160
+			if (!stristr($new_name, "-part")) {
161
+				$new_name = $this->archive_name . "-part" . $part;
162
+			}
163 163
 
164
-            $this->archive_name = $new_name;
165
-        }
164
+			$this->archive_name = $new_name;
165
+		}
166 166
 
167
-        return $this;
168
-    }
167
+		return $this;
168
+	}
169 169
 
170
-    /*
170
+	/*
171 171
      *
172 172
      * Returns the backup archive name
173 173
      *
174 174
      * @return string archive name
175 175
      */
176
-    public function get_archive_name()
177
-    {
178
-        return $this->archive_name;
179
-    }
176
+	public function get_archive_name()
177
+	{
178
+		return $this->archive_name;
179
+	}
180 180
 
181
-    /*
181
+	/*
182 182
      *
183 183
      * Returns the multipart naming for the backup archive
184 184
      *
185 185
      * @return string multi-part backup name
186 186
      */
187
-    public function get_archive_name_multipart()
188
-    {
189
-        $new_name = preg_replace('/-part(\d*)/', "", $this->archive_name);
190
-        return $new_name . "-multipart" . $this->xcloner_settings->get_backup_extension_name(".csv");
191
-    }
187
+	public function get_archive_name_multipart()
188
+	{
189
+		$new_name = preg_replace('/-part(\d*)/', "", $this->archive_name);
190
+		return $new_name . "-multipart" . $this->xcloner_settings->get_backup_extension_name(".csv");
191
+	}
192 192
 
193
-    /*
193
+	/*
194 194
      *
195 195
      * Returns the full backup name including extension
196 196
      *
197 197
      */
198
-    public function get_archive_name_with_extension()
199
-    {
200
-        return $this->archive_name . $this->xcloner_settings->get_backup_extension_name();
201
-    }
198
+	public function get_archive_name_with_extension()
199
+	{
200
+		return $this->archive_name . $this->xcloner_settings->get_backup_extension_name();
201
+	}
202 202
 
203
-    /*
203
+	/*
204 204
      *
205 205
      * Send notification error by E-Mail
206 206
      *
@@ -213,31 +213,31 @@  discard block
 block discarded – undo
213 213
      *
214 214
      * @return bool
215 215
      */
216
-    public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message)
217
-    {
216
+	public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message)
217
+	{
218 218
 
219
-        $body = "";
220
-        $body .= sprintf(__("Backup Site Url: %s"), get_site_url());
221
-        $body .= "<br /><>";
219
+		$body = "";
220
+		$body .= sprintf(__("Backup Site Url: %s"), get_site_url());
221
+		$body .= "<br /><>";
222 222
 
223
-        $body .= sprintf(__("Error Message: %s"), $error_message);
223
+		$body .= sprintf(__("Error Message: %s"), $error_message);
224 224
 
225
-        $this->logger->info(sprintf("Sending backup error notification to %s", $to));
225
+		$this->logger->info(sprintf("Sending backup error notification to %s", $to));
226 226
 
227
-        $admin_email = get_option("admin_email");
227
+		$admin_email = get_option("admin_email");
228 228
 
229
-        $headers = array('Content-Type: text/html; charset=UTF-8');
229
+		$headers = array('Content-Type: text/html; charset=UTF-8');
230 230
 
231
-        if ($admin_email and $from) {
232
-            $headers[] = 'From: ' . $from . ' <' . $admin_email . '>';
233
-        }
231
+		if ($admin_email and $from) {
232
+			$headers[] = 'From: ' . $from . ' <' . $admin_email . '>';
233
+		}
234 234
 
235
-        $return = wp_mail($to, $subject, $body, $headers);
235
+		$return = wp_mail($to, $subject, $body, $headers);
236 236
 
237
-        return $return;
238
-    }
237
+		return $return;
238
+	}
239 239
 
240
-    /*
240
+	/*
241 241
      *
242 242
      * Send backup archive notfication by E-Mail
243 243
      *
@@ -251,480 +251,480 @@  discard block
 block discarded – undo
251 251
      *
252 252
      * @return bool
253 253
      */
254
-    public function send_notification(
255
-        $to,
256
-        $from,
257
-        $subject,
258
-        $backup_name,
259
-        $params,
260
-        $error_message = "",
261
-        $additional = array()
262
-    ) {
263
-        if (!$from) {
264
-            $from = "XCloner Backup";
265
-        }
254
+	public function send_notification(
255
+		$to,
256
+		$from,
257
+		$subject,
258
+		$backup_name,
259
+		$params,
260
+		$error_message = "",
261
+		$additional = array()
262
+	) {
263
+		if (!$from) {
264
+			$from = "XCloner Backup";
265
+		}
266 266
 
267
-        if (($error_message)) {
268
-            return $this->send_notification_error($to, $from, $subject, $backup_name, $params, $error_message);
269
-        }
267
+		if (($error_message)) {
268
+			return $this->send_notification_error($to, $from, $subject, $backup_name, $params, $error_message);
269
+		}
270 270
 
271
-        $params = (array)$params;
271
+		$params = (array)$params;
272 272
 
273
-        if (!$subject) {
274
-            $subject = sprintf(__("New backup generated %s"), $backup_name);
275
-        }
273
+		if (!$subject) {
274
+			$subject = sprintf(__("New backup generated %s"), $backup_name);
275
+		}
276 276
 
277
-        $body = sprintf(__("Generated Backup Size: %s"), size_format($this->filesystem->get_backup_size($backup_name)));
278
-        $body .= "<br /><br />";
277
+		$body = sprintf(__("Generated Backup Size: %s"), size_format($this->filesystem->get_backup_size($backup_name)));
278
+		$body .= "<br /><br />";
279 279
 
280
-        if (isset($additional['lines_total'])) {
281
-            $body .= sprintf(__("Total files added: %s"), $additional['lines_total']);
282
-            $body .= "<br /><br />";
283
-        }
280
+		if (isset($additional['lines_total'])) {
281
+			$body .= sprintf(__("Total files added: %s"), $additional['lines_total']);
282
+			$body .= "<br /><br />";
283
+		}
284 284
 
285
-        $backup_parts = $this->filesystem->get_multipart_files($backup_name);
285
+		$backup_parts = $this->filesystem->get_multipart_files($backup_name);
286 286
 
287
-        if (!$backups_counter = sizeof($backup_parts)) {
288
-            $backups_counter = 1;
289
-        }
287
+		if (!$backups_counter = sizeof($backup_parts)) {
288
+			$backups_counter = 1;
289
+		}
290 290
 
291
-        $body .= sprintf(__("Backup Parts: %s"), $backups_counter);
292
-        $body .= "<br />";
291
+		$body .= sprintf(__("Backup Parts: %s"), $backups_counter);
292
+		$body .= "<br />";
293 293
 
294
-        if (sizeof($backup_parts)) {
295
-            $body .= implode("<br />", $backup_parts);
296
-            $body .= "<br />";
297
-        }
294
+		if (sizeof($backup_parts)) {
295
+			$body .= implode("<br />", $backup_parts);
296
+			$body .= "<br />";
297
+		}
298 298
 
299
-        $body .= "<br />";
299
+		$body .= "<br />";
300 300
 
301
-        $body .= sprintf(__("Backup Site Url: %s"), get_site_url());
302
-        $body .= "<br />";
301
+		$body .= sprintf(__("Backup Site Url: %s"), get_site_url());
302
+		$body .= "<br />";
303 303
 
304
-        if (isset($params['backup_params']->backup_comments)) {
305
-            $body .= __("Backup Comments: ") . $params['backup_params']->backup_comments;
306
-            $body .= "<br /><br />";
307
-        }
304
+		if (isset($params['backup_params']->backup_comments)) {
305
+			$body .= __("Backup Comments: ") . $params['backup_params']->backup_comments;
306
+			$body .= "<br /><br />";
307
+		}
308 308
 
309
-        if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
310
-            $body .= __("Latest 50 Log Lines: ") . "<br />" . implode("<br />\n",
311
-                                                                        $this->logger->getLastDebugLines(50));
312
-        }
309
+		if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
310
+			$body .= __("Latest 50 Log Lines: ") . "<br />" . implode("<br />\n",
311
+																		$this->logger->getLastDebugLines(50));
312
+		}
313 313
 
314
-        $attachments = $this->filesystem->get_backup_attachments();
314
+		$attachments = $this->filesystem->get_backup_attachments();
315 315
 
316
-        $attachments_archive = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "info.tgz";
316
+		$attachments_archive = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "info.tgz";
317 317
 
318
-        $tar = new Tar();
319
-        $tar->create($attachments_archive);
318
+		$tar = new Tar();
319
+		$tar->create($attachments_archive);
320 320
 
321
-        foreach ($attachments as $key => $file) {
322
-            $tar->addFile($file, basename($file));
323
-        }
324
-        $tar->close();
321
+		foreach ($attachments as $key => $file) {
322
+			$tar->addFile($file, basename($file));
323
+		}
324
+		$tar->close();
325 325
 
326
-        $this->logger->info(sprintf("Sending backup notification to %s", $to));
326
+		$this->logger->info(sprintf("Sending backup notification to %s", $to));
327 327
 
328
-        $admin_email = get_option("admin_email");
328
+		$admin_email = get_option("admin_email");
329 329
 
330
-        $headers = array('Content-Type: text/html; charset=UTF-8', 'From: ' . $from . ' <' . $admin_email . '>');
330
+		$headers = array('Content-Type: text/html; charset=UTF-8', 'From: ' . $from . ' <' . $admin_email . '>');
331 331
 
332
-        $return = wp_mail($to, $subject, $body, $headers, array($attachments_archive));
332
+		$return = wp_mail($to, $subject, $body, $headers, array($attachments_archive));
333 333
 
334
-        return $return;
335
-    }
334
+		return $return;
335
+	}
336 336
 
337
-    /*
337
+	/*
338 338
      *
339 339
      * Incremental Backup method
340 340
      *
341 341
      */
342
-    public function start_incremental_backup($backup_params, $extra_params, $init)
343
-    {
344
-        $return = array();
342
+	public function start_incremental_backup($backup_params, $extra_params, $init)
343
+	{
344
+		$return = array();
345 345
 
346
-        if (!isset($extra_params['backup_part'])) {
347
-            $extra_params['backup_part'] = 0;
348
-        }
346
+		if (!isset($extra_params['backup_part'])) {
347
+			$extra_params['backup_part'] = 0;
348
+		}
349 349
 
350
-        $return['extra']['backup_part'] = $extra_params['backup_part'];
350
+		$return['extra']['backup_part'] = $extra_params['backup_part'];
351 351
 
352
-        if (isset($extra_params['backup_archive_name'])) {
353
-            $this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']);
354
-        } else {
355
-            $this->set_archive_name($backup_params['backup_name']);
356
-        }
352
+		if (isset($extra_params['backup_archive_name'])) {
353
+			$this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']);
354
+		} else {
355
+			$this->set_archive_name($backup_params['backup_name']);
356
+		}
357 357
 
358
-        if (!$this->get_archive_name()) {
359
-            $this->set_archive_name();
360
-        }
358
+		if (!$this->get_archive_name()) {
359
+			$this->set_archive_name();
360
+		}
361 361
 
362
-        $this->backup_archive = new Tar();
363
-        $this->backup_archive->setCompression($this->compression_level);
362
+		$this->backup_archive = new Tar();
363
+		$this->backup_archive->setCompression($this->compression_level);
364 364
 
365
-        $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension());
365
+		$archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension());
366 366
 
367
-        if ($init) {
368
-            $this->logger->info(sprintf(__("Initializing the backup archive %s"), $this->get_archive_name()));
367
+		if ($init) {
368
+			$this->logger->info(sprintf(__("Initializing the backup archive %s"), $this->get_archive_name()));
369 369
 
370
-            $this->backup_archive->create($archive_info->getPath() . DS . $archive_info->getFilename());
370
+			$this->backup_archive->create($archive_info->getPath() . DS . $archive_info->getFilename());
371 371
 
372
-            $return['extra']['backup_init'] = 1;
372
+			$return['extra']['backup_init'] = 1;
373 373
 
374
-        } else {
375
-            $this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name()));
374
+		} else {
375
+			$this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name()));
376 376
 
377
-            $this->backup_archive->openForAppend($archive_info->getPath() . DS . $archive_info->getFilename());
377
+			$this->backup_archive->openForAppend($archive_info->getPath() . DS . $archive_info->getFilename());
378 378
 
379
-            $return['extra']['backup_init'] = 0;
379
+			$return['extra']['backup_init'] = 0;
380 380
 
381
-        }
381
+		}
382 382
 
383
-        $return['extra']['backup_archive_name'] = $this->get_archive_name();
384
-        $return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension();
383
+		$return['extra']['backup_archive_name'] = $this->get_archive_name();
384
+		$return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension();
385 385
 
386
-        if (!isset($extra_params['start_at_line'])) {
387
-            $extra_params['start_at_line'] = 0;
388
-        }
386
+		if (!isset($extra_params['start_at_line'])) {
387
+			$extra_params['start_at_line'] = 0;
388
+		}
389 389
 
390
-        if (!isset($extra_params['start_at_byte'])) {
391
-            $extra_params['start_at_byte'] = 0;
392
-        }
390
+		if (!isset($extra_params['start_at_byte'])) {
391
+			$extra_params['start_at_byte'] = 0;
392
+		}
393 393
 
394
-        if (!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) {
395
-            $this->logger->error(sprintf("Missing the includes file handler %s, aborting...",
396
-                $this->filesystem->get_included_files_handler()));
394
+		if (!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) {
395
+			$this->logger->error(sprintf("Missing the includes file handler %s, aborting...",
396
+				$this->filesystem->get_included_files_handler()));
397 397
 
398
-            $return['finished'] = 1;
399
-            return $return;
400
-        }
398
+			$return['finished'] = 1;
399
+			return $return;
400
+		}
401 401
 
402
-        $included_files_handler = $this->filesystem->get_included_files_handler(1);
402
+		$included_files_handler = $this->filesystem->get_included_files_handler(1);
403 403
 
404
-        $file = new SplFileObject($included_files_handler);
404
+		$file = new SplFileObject($included_files_handler);
405 405
 
406
-        $file->seek(PHP_INT_MAX);
406
+		$file->seek(PHP_INT_MAX);
407 407
 
408
-        $return['extra']['lines_total'] = ($file->key() - 1);
408
+		$return['extra']['lines_total'] = ($file->key() - 1);
409 409
 
410
-        //we skip the first CSV line with headers
411
-        if (!$extra_params['start_at_line']) {
412
-            $file->seek(1);
413
-        } else {
414
-            $file->seek($extra_params['start_at_line'] + 1);
415
-        }
410
+		//we skip the first CSV line with headers
411
+		if (!$extra_params['start_at_line']) {
412
+			$file->seek(1);
413
+		} else {
414
+			$file->seek($extra_params['start_at_line'] + 1);
415
+		}
416 416
 
417
-        $this->processed_size_bytes = 0;
417
+		$this->processed_size_bytes = 0;
418 418
 
419
-        $counter = 0;
419
+		$counter = 0;
420 420
 
421
-        $start_byte = $extra_params['start_at_byte'];
421
+		$start_byte = $extra_params['start_at_byte'];
422 422
 
423
-        $byte_limit = 0;
423
+		$byte_limit = 0;
424 424
 
425
-        while (!$file->eof() and $counter <= $this->files_to_process_per_request) {
426
-            $current_line_str = $file->current();
425
+		while (!$file->eof() and $counter <= $this->files_to_process_per_request) {
426
+			$current_line_str = $file->current();
427 427
 
428
-            $line = str_getcsv($current_line_str);
428
+			$line = str_getcsv($current_line_str);
429 429
 
430
-            $relative_path = stripslashes($line[0]);
430
+			$relative_path = stripslashes($line[0]);
431 431
 
432
-            $start_filesystem = "start_filesystem";
432
+			$start_filesystem = "start_filesystem";
433 433
 
434
-            if (isset($line[4])) {
435
-                $start_filesystem = $line[4];
436
-            }
434
+			if (isset($line[4])) {
435
+				$start_filesystem = $line[4];
436
+			}
437 437
 
438
-            //$adapter = $this->filesystem->get_adapter($start_filesystem);
438
+			//$adapter = $this->filesystem->get_adapter($start_filesystem);
439 439
 
440
-            if (!$relative_path || !$this->filesystem->get_filesystem($start_filesystem)->has($relative_path)) {
441
-                if ($relative_path != "") {
442
-                    $this->logger->error(sprintf("Could not add file %b to backup archive, file not found",
443
-                        $relative_path));
444
-                }
440
+			if (!$relative_path || !$this->filesystem->get_filesystem($start_filesystem)->has($relative_path)) {
441
+				if ($relative_path != "") {
442
+					$this->logger->error(sprintf("Could not add file %b to backup archive, file not found",
443
+						$relative_path));
444
+				}
445 445
 
446
-                $extra_params['start_at_line']++;
447
-                $file->next();
448
-                continue;
449
-            }
446
+				$extra_params['start_at_line']++;
447
+				$file->next();
448
+				continue;
449
+			}
450 450
 
451
-            $file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path);
451
+			$file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path);
452 452
 
453
-            if (!isset($file_info['size'])) {
454
-                $file_info['size'] = 0;
455
-            }
453
+			if (!isset($file_info['size'])) {
454
+				$file_info['size'] = 0;
455
+			}
456 456
 
457
-            if ($start_filesystem == "tmp_filesystem") {
458
-                $file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix();
459
-            }
457
+			if ($start_filesystem == "tmp_filesystem") {
458
+				$file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix();
459
+			}
460 460
 
461
-            $byte_limit = (int)$this->file_size_per_request_limit / 512;
461
+			$byte_limit = (int)$this->file_size_per_request_limit / 512;
462 462
 
463
-            $append = 0;
463
+			$append = 0;
464 464
 
465
-            if ($file_info['size'] > $byte_limit * 512 or $start_byte) {
466
-                $append = 1;
467
-            }
465
+			if ($file_info['size'] > $byte_limit * 512 or $start_byte) {
466
+				$append = 1;
467
+			}
468 468
 
469
-            if (!isset($return['extra']['backup_size'])) {
470
-                $return['extra']['backup_size'] = 0;
471
-            }
469
+			if (!isset($return['extra']['backup_size'])) {
470
+				$return['extra']['backup_size'] = 0;
471
+			}
472 472
 
473
-            $return['extra']['backup_size'] = $archive_info->getSize();
473
+			$return['extra']['backup_size'] = $archive_info->getSize();
474 474
 
475
-            $estimated_new_size = $return['extra']['backup_size'] + $file_info['size'];
475
+			$estimated_new_size = $return['extra']['backup_size'] + $file_info['size'];
476 476
 
477
-            //we create a new backup part if we reach the Split Achive Limit
478
-            if ($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte)) {
479
-                $this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ",
480
-                    $this->xcloner_split_backup_limit, $estimated_new_size));
481
-                list($archive_info, $return['extra']['backup_part']) = $this->create_new_backup_part($return['extra']['backup_part']);
477
+			//we create a new backup part if we reach the Split Achive Limit
478
+			if ($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte)) {
479
+				$this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ",
480
+					$this->xcloner_split_backup_limit, $estimated_new_size));
481
+				list($archive_info, $return['extra']['backup_part']) = $this->create_new_backup_part($return['extra']['backup_part']);
482 482
 
483
-                if ($file_info['size'] > $this->xcloner_split_backup_limit) {
484
-                    $this->logger->info(sprintf("Excluding %s file as it's size(%s) is bigger than the backup split limit of %s and it won't fit a single backup file",
485
-                        $file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit));
486
-                    $extra_params['start_at_line']++;
487
-                }
483
+				if ($file_info['size'] > $this->xcloner_split_backup_limit) {
484
+					$this->logger->info(sprintf("Excluding %s file as it's size(%s) is bigger than the backup split limit of %s and it won't fit a single backup file",
485
+						$file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit));
486
+					$extra_params['start_at_line']++;
487
+				}
488 488
 
489
-                $return['extra']['start_at_line'] = $extra_params['start_at_line'];
490
-                $return['extra']['start_at_byte'] = 0;
489
+				$return['extra']['start_at_line'] = $extra_params['start_at_line'];
490
+				$return['extra']['start_at_byte'] = 0;
491 491
 
492
-                $return['finished'] = 0;
492
+				$return['finished'] = 0;
493 493
 
494
-                return $return;
495
-            }
494
+				return $return;
495
+			}
496 496
 
497
-            list($bytes_wrote, $last_position) = $this->add_file_to_archive($file_info, $start_byte, $byte_limit,
498
-                $append, $start_filesystem);
499
-            $this->processed_size_bytes += $bytes_wrote;
497
+			list($bytes_wrote, $last_position) = $this->add_file_to_archive($file_info, $start_byte, $byte_limit,
498
+				$append, $start_filesystem);
499
+			$this->processed_size_bytes += $bytes_wrote;
500 500
 
501
-            //echo" - processed ".$this->processed_size_bytes." bytes ".$this->file_size_per_request_limit." last_position:".$last_position." \n";
502
-            $return['extra']['processed_file'] = $file_info['path'];
503
-            $return['extra']['processed_file_size'] = $file_info['size'];
504
-            $return['extra']['backup_size'] = $archive_info->getSize();
501
+			//echo" - processed ".$this->processed_size_bytes." bytes ".$this->file_size_per_request_limit." last_position:".$last_position." \n";
502
+			$return['extra']['processed_file'] = $file_info['path'];
503
+			$return['extra']['processed_file_size'] = $file_info['size'];
504
+			$return['extra']['backup_size'] = $archive_info->getSize();
505 505
 
506
-            if ($last_position > 0) {
507
-                $start_byte = $last_position;
508
-            } else {
509
-                $extra_params['start_at_line']++;
510
-                $file->next();
511
-                $start_byte = 0;
512
-                $counter++;
513
-            }
506
+			if ($last_position > 0) {
507
+				$start_byte = $last_position;
508
+			} else {
509
+				$extra_params['start_at_line']++;
510
+				$file->next();
511
+				$start_byte = 0;
512
+				$counter++;
513
+			}
514 514
 
515
-            if ($this->processed_size_bytes >= $this->file_size_per_request_limit) {
516
-                clearstatcache();
517
-                $return['extra']['backup_size'] = $archive_info->getSize();
515
+			if ($this->processed_size_bytes >= $this->file_size_per_request_limit) {
516
+				clearstatcache();
517
+				$return['extra']['backup_size'] = $archive_info->getSize();
518 518
 
519
-                $return['finished'] = 0;
520
-                $return['extra']['start_at_line'] = $extra_params['start_at_line'];
521
-                $return['extra']['start_at_byte'] = $last_position;
522
-                $this->logger->info(sprintf("Reached the maximum %s request data limit, returning response",
523
-                    $this->file_size_per_request_limit));
524
-                return $return;
525
-            }
526
-        }
519
+				$return['finished'] = 0;
520
+				$return['extra']['start_at_line'] = $extra_params['start_at_line'];
521
+				$return['extra']['start_at_byte'] = $last_position;
522
+				$this->logger->info(sprintf("Reached the maximum %s request data limit, returning response",
523
+					$this->file_size_per_request_limit));
524
+				return $return;
525
+			}
526
+		}
527 527
 
528
-        if (!$file->eof()) {
529
-            clearstatcache();
530
-            $return['extra']['backup_size'] = $archive_info->getSize();
528
+		if (!$file->eof()) {
529
+			clearstatcache();
530
+			$return['extra']['backup_size'] = $archive_info->getSize();
531 531
 
532
-            $return['finished'] = 0;
533
-            $return['extra']['start_at_line'] = $extra_params['start_at_line'];
534
-            $return['extra']['start_at_byte'] = $last_position;
535
-            $this->logger->info(sprintf("We have reached the maximum files to process per request limit of %s, returning response",
536
-                $this->files_to_process_per_request));
532
+			$return['finished'] = 0;
533
+			$return['extra']['start_at_line'] = $extra_params['start_at_line'];
534
+			$return['extra']['start_at_byte'] = $last_position;
535
+			$this->logger->info(sprintf("We have reached the maximum files to process per request limit of %s, returning response",
536
+				$this->files_to_process_per_request));
537 537
 
538
-            return $return;
539
-        }
538
+			return $return;
539
+		}
540 540
 
541
-        //close the backup archive by adding 2*512 blocks of zero bytes
542
-        $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.",
543
-            $this->get_archive_name_with_extension()));
544
-        $this->backup_archive->close();
541
+		//close the backup archive by adding 2*512 blocks of zero bytes
542
+		$this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.",
543
+			$this->get_archive_name_with_extension()));
544
+		$this->backup_archive->close();
545 545
 
546
-        /**
547
-         * XCloner HOOK backup_archive_finished.
548
-         *
549
-         * This will get triggered when a backup archive is finished writing.
550
-         */
551
-        //do_action('backup_archive_finished', $this->backup_archive, $this);
546
+		/**
547
+		 * XCloner HOOK backup_archive_finished.
548
+		 *
549
+		 * This will get triggered when a backup archive is finished writing.
550
+		 */
551
+		//do_action('backup_archive_finished', $this->backup_archive, $this);
552 552
 
553
-        //updating archive_info
554
-        $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension());
553
+		//updating archive_info
554
+		$archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension());
555 555
 
556
-        if ($return['extra']['backup_part']) {
557
-            $this->write_multipart_file($this->get_archive_name_with_extension());
558
-        }
556
+		if ($return['extra']['backup_part']) {
557
+			$this->write_multipart_file($this->get_archive_name_with_extension());
558
+		}
559 559
 
560
-        $return['extra']['start_at_line'] = $extra_params['start_at_line'] - 1;
560
+		$return['extra']['start_at_line'] = $extra_params['start_at_line'] - 1;
561 561
 
562
-        if (isset($file_info)) {
563
-            $return['extra']['processed_file'] = $file_info['path'];
564
-            $return['extra']['processed_file_size'] = $file_info['size'];
565
-        }
562
+		if (isset($file_info)) {
563
+			$return['extra']['processed_file'] = $file_info['path'];
564
+			$return['extra']['processed_file_size'] = $file_info['size'];
565
+		}
566 566
 
567
-        clearstatcache();
568
-        $return['extra']['backup_size'] = $archive_info->getSize();
567
+		clearstatcache();
568
+		$return['extra']['backup_size'] = $archive_info->getSize();
569 569
 
570
-        $return['finished'] = 1;
571
-        return $return;
572
-    }
570
+		$return['finished'] = 1;
571
+		return $return;
572
+	}
573 573
 
574
-    /*
574
+	/*
575 575
      *
576 576
      * Write multipart file components
577 577
      *
578 578
      */
579
-    private function write_multipart_file($path)
580
-    {
581
-        $path = $this->get_archive_name_with_extension();
579
+	private function write_multipart_file($path)
580
+	{
581
+		$path = $this->get_archive_name_with_extension();
582 582
 
583
-        $file = $this->filesystem->get_filesystem("storage_filesystem_append")->getMetadata($path);
584
-        //print_r($file_info);
585
-        $line = '"' . $file['path'] . '","' . $file['timestamp'] . '","' . $file['size'] . '"' . PHP_EOL;
583
+		$file = $this->filesystem->get_filesystem("storage_filesystem_append")->getMetadata($path);
584
+		//print_r($file_info);
585
+		$line = '"' . $file['path'] . '","' . $file['timestamp'] . '","' . $file['size'] . '"' . PHP_EOL;
586 586
 
587 587
 
588
-        $this->filesystem->get_filesystem("storage_filesystem_append")
589
-            ->write($this->get_archive_name_multipart(), $line);
590
-    }
588
+		$this->filesystem->get_filesystem("storage_filesystem_append")
589
+			->write($this->get_archive_name_multipart(), $line);
590
+	}
591 591
 
592
-    /*
592
+	/*
593 593
      *
594 594
      * Create a new backup part
595 595
      *
596 596
      */
597
-    private function create_new_backup_part($part = 0)
598
-    {
599
-        //close the backup archive by adding 2*512 blocks of zero bytes
600
-        $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.",
601
-            $this->get_archive_name_with_extension()));
602
-        $this->backup_archive->close();
603
-
604
-        if (!$part) {
605
-            $old_name = $this->get_archive_name_with_extension();
606
-            $this->set_archive_name($this->get_archive_name(), ++$part);
607
-            $this->rename_archive($old_name, $this->get_archive_name_with_extension());
608
-
609
-            if ($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) {
610
-                $this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart());
611
-            }
612
-
613
-            $this->write_multipart_file($this->get_archive_name_with_extension());
614
-
615
-        } else {
616
-            $this->logger->info(sprintf("Creating new multipart info file %s",
617
-                $this->get_archive_name_with_extension()));
618
-            $this->write_multipart_file($this->get_archive_name_with_extension());
619
-        }
597
+	private function create_new_backup_part($part = 0)
598
+	{
599
+		//close the backup archive by adding 2*512 blocks of zero bytes
600
+		$this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.",
601
+			$this->get_archive_name_with_extension()));
602
+		$this->backup_archive->close();
603
+
604
+		if (!$part) {
605
+			$old_name = $this->get_archive_name_with_extension();
606
+			$this->set_archive_name($this->get_archive_name(), ++$part);
607
+			$this->rename_archive($old_name, $this->get_archive_name_with_extension());
608
+
609
+			if ($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) {
610
+				$this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart());
611
+			}
612
+
613
+			$this->write_multipart_file($this->get_archive_name_with_extension());
614
+
615
+		} else {
616
+			$this->logger->info(sprintf("Creating new multipart info file %s",
617
+				$this->get_archive_name_with_extension()));
618
+			$this->write_multipart_file($this->get_archive_name_with_extension());
619
+		}
620 620
 
621
-        $this->set_archive_name($this->get_archive_name(), ++$part);
621
+		$this->set_archive_name($this->get_archive_name(), ++$part);
622 622
 
623
-        $this->logger->info(sprintf("Creating new backup archive part %s", $this->get_archive_name_with_extension()));
623
+		$this->logger->info(sprintf("Creating new backup archive part %s", $this->get_archive_name_with_extension()));
624 624
 
625
-        $this->backup_archive = new Tar();
626
-        $this->backup_archive->setCompression($this->compression_level);
627
-        $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension());
628
-        $this->backup_archive->create($archive_info->getPath() . DS . $archive_info->getFilename());
625
+		$this->backup_archive = new Tar();
626
+		$this->backup_archive->setCompression($this->compression_level);
627
+		$archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension());
628
+		$this->backup_archive->create($archive_info->getPath() . DS . $archive_info->getFilename());
629 629
 
630
-        return array($archive_info, $part);
630
+		return array($archive_info, $part);
631 631
 
632
-    }
632
+	}
633 633
 
634
-    /*
634
+	/*
635 635
      *
636 636
      * Add file to archive
637 637
      *
638 638
      */
639
-    public function add_file_to_archive($file_info, $start_at_byte, $byte_limit = 0, $append, $filesystem)
640
-    {
641
-
642
-        $start_adapter = $this->filesystem->get_adapter($filesystem);
643
-        $start_filesystem = $this->filesystem->get_adapter($filesystem);
644
-
645
-        if (!$file_info['path']) {
646
-            return;
647
-        }
648
-
649
-        if (isset($file_info['archive_prefix_path'])) {
650
-            $file_info['target_path'] = $file_info['archive_prefix_path'] . "/" . $file_info['path'];
651
-        } else {
652
-            $file_info['target_path'] = $file_info['path'];
653
-        }
654
-
655
-        $last_position = $start_at_byte;
656
-
657
-        //$start_adapter = $this->filesystem->get_start_adapter();
658
-
659
-        if (!$append) {
660
-            $bytes_wrote = $file_info['size'];
661
-            $this->logger->info(sprintf("Adding %s bytes of file %s to archive %s ", $bytes_wrote,
662
-                $file_info['target_path'], $this->get_archive_name_with_extension()));
663
-            $this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']),
664
-                $file_info['target_path']);
665
-        } else {
666
-            $tmp_file = md5($file_info['path']);
667
-
668
-            //we isolate file to tmp if we are at byte 0, the starting point of file reading
669
-            if (!$start_at_byte) {
670
-                $this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes",
671
-                    $file_info['path'], $tmp_file));
672
-                $file_stream = $start_filesystem->readStream($file_info['path']);
673
-
674
-                if (is_resource($file_stream['stream'])) {
675
-                    $this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']);
676
-                }
677
-            }
678
-
679
-            if ($this->filesystem->get_tmp_filesystem()->has($tmp_file)) {
680
-                $is_tmp = 1;
681
-                $last_position = $this->backup_archive->appendFileData($this->filesystem->get_tmp_filesystem_adapter()
682
-                                                        ->applyPathPrefix($tmp_file),
683
-                    $file_info['target_path'], $start_at_byte, $byte_limit);
684
-            } else {
685
-                $is_tmp = 0;
686
-                $last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']),
687
-                    $file_info['target_path'], $start_at_byte, $byte_limit);
688
-            }
689
-
690
-
691
-            if ($last_position == -1) {
692
-                $bytes_wrote = $file_info['size'] - $start_at_byte;
693
-            } else {
694
-                $bytes_wrote = $last_position - $start_at_byte;
695
-            }
639
+	public function add_file_to_archive($file_info, $start_at_byte, $byte_limit = 0, $append, $filesystem)
640
+	{
696 641
 
642
+		$start_adapter = $this->filesystem->get_adapter($filesystem);
643
+		$start_filesystem = $this->filesystem->get_adapter($filesystem);
697 644
 
698
-            if ($is_tmp) {
699
-                $this->logger->info(sprintf("Appended %s bytes, starting position %s, of tmp file %s (%s) to archive %s ",
700
-                    $bytes_wrote, $start_at_byte, $tmp_file, $file_info['target_path'], $this->get_archive_name()));
701
-            } else {
702
-                $this->logger->info(sprintf("Appended %s bytes, starting position %s, of original file %s to archive %s ",
703
-                    $bytes_wrote, $start_at_byte, $file_info['target_path'], $tmp_file, $this->get_archive_name()));
704
-            }
645
+		if (!$file_info['path']) {
646
+			return;
647
+		}
705 648
 
706
-            //we delete here the isolated tmp file
707
-            if ($last_position == -1) {
708
-                if ($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file)) {
709
-                    $this->logger->info(sprintf("Deleting %s from the tmp filesystem", $tmp_file));
710
-                    $this->filesystem->get_tmp_filesystem_adapter()->delete($tmp_file);
711
-                }
712
-            }
649
+		if (isset($file_info['archive_prefix_path'])) {
650
+			$file_info['target_path'] = $file_info['archive_prefix_path'] . "/" . $file_info['path'];
651
+		} else {
652
+			$file_info['target_path'] = $file_info['path'];
653
+		}
713 654
 
714
-        }
655
+		$last_position = $start_at_byte;
656
+
657
+		//$start_adapter = $this->filesystem->get_start_adapter();
658
+
659
+		if (!$append) {
660
+			$bytes_wrote = $file_info['size'];
661
+			$this->logger->info(sprintf("Adding %s bytes of file %s to archive %s ", $bytes_wrote,
662
+				$file_info['target_path'], $this->get_archive_name_with_extension()));
663
+			$this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']),
664
+				$file_info['target_path']);
665
+		} else {
666
+			$tmp_file = md5($file_info['path']);
667
+
668
+			//we isolate file to tmp if we are at byte 0, the starting point of file reading
669
+			if (!$start_at_byte) {
670
+				$this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes",
671
+					$file_info['path'], $tmp_file));
672
+				$file_stream = $start_filesystem->readStream($file_info['path']);
673
+
674
+				if (is_resource($file_stream['stream'])) {
675
+					$this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']);
676
+				}
677
+			}
678
+
679
+			if ($this->filesystem->get_tmp_filesystem()->has($tmp_file)) {
680
+				$is_tmp = 1;
681
+				$last_position = $this->backup_archive->appendFileData($this->filesystem->get_tmp_filesystem_adapter()
682
+														->applyPathPrefix($tmp_file),
683
+					$file_info['target_path'], $start_at_byte, $byte_limit);
684
+			} else {
685
+				$is_tmp = 0;
686
+				$last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']),
687
+					$file_info['target_path'], $start_at_byte, $byte_limit);
688
+			}
689
+
690
+
691
+			if ($last_position == -1) {
692
+				$bytes_wrote = $file_info['size'] - $start_at_byte;
693
+			} else {
694
+				$bytes_wrote = $last_position - $start_at_byte;
695
+			}
696
+
697
+
698
+			if ($is_tmp) {
699
+				$this->logger->info(sprintf("Appended %s bytes, starting position %s, of tmp file %s (%s) to archive %s ",
700
+					$bytes_wrote, $start_at_byte, $tmp_file, $file_info['target_path'], $this->get_archive_name()));
701
+			} else {
702
+				$this->logger->info(sprintf("Appended %s bytes, starting position %s, of original file %s to archive %s ",
703
+					$bytes_wrote, $start_at_byte, $file_info['target_path'], $tmp_file, $this->get_archive_name()));
704
+			}
705
+
706
+			//we delete here the isolated tmp file
707
+			if ($last_position == -1) {
708
+				if ($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file)) {
709
+					$this->logger->info(sprintf("Deleting %s from the tmp filesystem", $tmp_file));
710
+					$this->filesystem->get_tmp_filesystem_adapter()->delete($tmp_file);
711
+				}
712
+			}
715 713
 
716
-        return array($bytes_wrote, $last_position);
717
-    }
714
+		}
718 715
 
719
-    /**
720
-     * Open a TAR archive and put the file cursor at the end for data appending
721
-     *
722
-     * If $file is empty, the tar file will be created in memory
723
-     *
724
-     * @param string $file
725
-     * @throws ArchiveIOException
726
-     */
727
-    /*
716
+		return array($bytes_wrote, $last_position);
717
+	}
718
+
719
+	/**
720
+	 * Open a TAR archive and put the file cursor at the end for data appending
721
+	 *
722
+	 * If $file is empty, the tar file will be created in memory
723
+	 *
724
+	 * @param string $file
725
+	 * @throws ArchiveIOException
726
+	 */
727
+	/*
728 728
     public function openForAppend($file = '')
729 729
     {
730 730
         $this->file   = $file;
@@ -754,17 +754,17 @@  discard block
 block discarded – undo
754 754
     }
755 755
     */
756 756
 
757
-    /**
758
-     * Append data to a file to the current TAR archive using an existing file in the filesystem
759
-     *
760
-     * @param string $file path to the original file
761
-     * @param int $start starting reading position in file
762
-     * @param int $end end position in reading multiple with 512
763
-     * @param string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with
764
-     * all meta data, empty to take from original
765
-     * @throws ArchiveIOException
766
-     */
767
-    /*
757
+	/**
758
+	 * Append data to a file to the current TAR archive using an existing file in the filesystem
759
+	 *
760
+	 * @param string $file path to the original file
761
+	 * @param int $start starting reading position in file
762
+	 * @param int $end end position in reading multiple with 512
763
+	 * @param string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with
764
+	 * all meta data, empty to take from original
765
+	 * @throws ArchiveIOException
766
+	 */
767
+	/*
768 768
      * public function appendFileData($file, $fileinfo = '', $start = 0, $limit = 0)
769 769
     {
770 770
 		$end = $start+($limit*512);
@@ -820,15 +820,15 @@  discard block
 block discarded – undo
820 820
         return $last_position;
821 821
     }*/
822 822
 
823
-    /**
824
-     * Adds a file to a TAR archive by appending it's data
825
-     *
826
-     * @param string $archive name of the archive file
827
-     * @param string $file name of the file to read data from
828
-     * @param string $start start position from where to start reading data
829
-     * @throws ArchiveIOException
830
-     */
831
-    /*public function addFileToArchive($archive, $file, $start = 0)
823
+	/**
824
+	 * Adds a file to a TAR archive by appending it's data
825
+	 *
826
+	 * @param string $archive name of the archive file
827
+	 * @param string $file name of the file to read data from
828
+	 * @param string $start start position from where to start reading data
829
+	 * @throws ArchiveIOException
830
+	 */
831
+	/*public function addFileToArchive($archive, $file, $start = 0)
832 832
     {
833 833
         $this->openForAppend($archive);
834 834
         return $start = $this->appendFileData($file, $start, $this->file_size_per_request_limit);
Please login to merge, or discard this patch.
includes/class-xcloner.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 		$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
322 322
 
323 323
 		//wp_localize_script( 'ajax-script', 'my_ajax_object',
324
-        //   array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
324
+		//   array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
325 325
 
326 326
 	}
327 327
 
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
 
358 358
 	private function define_plugin_settings(){
359 359
 		/**
360
-		* register wporg_settings_init to the admin_init action hook
361
-		*/
360
+		 * register wporg_settings_init to the admin_init action hook
361
+		 */
362 362
 
363 363
 		$this->xcloner_settings = new XCloner_Settings($this);
364 364
 
@@ -513,15 +513,15 @@  discard block
 block discarded – undo
513 513
 	}
514 514
 
515 515
 	function friendly_error_type($type) {
516
-	    static $levels=null;
517
-	    if ($levels===null) {
518
-	        $levels=[];
519
-	        foreach (get_defined_constants() as $key=>$value) {
520
-	            if (strpos($key,'E_')!==0) {continue;}
516
+		static $levels=null;
517
+		if ($levels===null) {
518
+			$levels=[];
519
+			foreach (get_defined_constants() as $key=>$value) {
520
+				if (strpos($key,'E_')!==0) {continue;}
521 521
 					$levels[$value]= $key; //substr($key,2);
522
-	        }
523
-	    }
524
-	    return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}");
522
+			}
523
+		}
524
+		return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}");
525 525
 	}
526 526
 
527 527
 	private function define_ajax_hooks()
@@ -563,24 +563,24 @@  discard block
 block discarded – undo
563 563
 			add_action( 'wp_ajax_restore_backup', 				array($xcloner_api,'restore_backup')  );
564 564
 			add_action( 'admin_notices', 						array($this, 'xcloner_error_admin_notices' ));
565 565
 
566
-        }
566
+		}
567 567
 
568
-        //Do a pre-update backup of targeted files
569
-        if($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup'))
570
-        {
568
+		//Do a pre-update backup of targeted files
569
+		if($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup'))
570
+		{
571 571
 			add_action("pre_auto_update", array($this, "pre_auto_update"), 1, 3);
572 572
 		}
573 573
 	}
574 574
 
575 575
 	function add_plugin_action_links($links, $file) {
576
-        if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php'))
576
+		if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php'))
577 577
 		{
578 578
 			$links[] = '<a href="admin.php?page=xcloner_settings_page">'.__('Settings', 'xcloner-backup-and-restore').'</a>';
579 579
 			$links[] = '<a href="admin.php?page=xcloner_generate_backups_page">'.__('Generate Backup', 'xcloner-backup-and-restore').'</a>';
580 580
 		}
581 581
 
582
-        return $links;
583
-    }
582
+		return $links;
583
+	}
584 584
 
585 585
 	public function xcloner_error_admin_notices() {
586 586
 			settings_errors( 'xcloner_error_message' );
@@ -664,9 +664,9 @@  discard block
 block discarded – undo
664 664
 	function xcloner_display()
665 665
 	{
666 666
 		// check user capabilities
667
-	    if (!current_user_can('manage_options')) {
668
-	        return;
669
-	    }
667
+		if (!current_user_can('manage_options')) {
668
+			return;
669
+		}
670 670
 
671 671
 		$page = sanitize_key($_GET['page']);
672 672
 
Please login to merge, or discard this patch.
includes/class-xcloner-api.php 1 patch
Indentation   +889 added lines, -889 removed lines patch added patch discarded remove patch
@@ -43,905 +43,905 @@  discard block
 block discarded – undo
43 43
 class Xcloner_Api
44 44
 {
45 45
 
46
-    private $xcloner_database;
47
-    private $xcloner_settings;
48
-    private $xcloner_file_system;
49
-    private $xcloner_requirements;
50
-    private $xcloner_sanitization;
51
-    private $archive_system;
52
-    private $form_params;
53
-    private $logger;
54
-    private $xcloner_container;
55
-
56
-    /**
57
-     * XCloner_Api construct class
58
-     *
59
-     * @param Xcloner $xcloner_container [description]
60
-     */
61
-    public function __construct(Xcloner $xcloner_container)
62
-    {
63
-        global $wpdb;
64
-
65
-        if (WP_DEBUG) {
66
-            error_reporting(0);
67
-        }
68
-
69
-        if (ob_get_length()) {
70
-            ob_end_clean();
71
-        }
72
-        ob_start();
73
-
74
-        $wpdb->show_errors = false;
75
-
76
-        $this->xcloner_container = $xcloner_container;
77
-
78
-        $this->xcloner_settings = $xcloner_container->get_xcloner_settings();
79
-        $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_api");
80
-        $this->xcloner_file_system = $xcloner_container->get_xcloner_filesystem();
81
-        $this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization();
82
-        $this->xcloner_requirements = $xcloner_container->get_xcloner_requirements();
83
-        $this->archive_system = $xcloner_container->get_archive_system();
84
-        $this->xcloner_database = $xcloner_container->get_xcloner_database();
85
-        $this->xcloner_scheduler = $xcloner_container->get_xcloner_scheduler();
86
-
87
-        if (isset($_POST['API_ID'])) {
88
-            $this->logger->info("Processing ajax request ID " . substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']),
89
-                    0, 15));
90
-        }
91
-
92
-    }
93
-
94
-    /**
95
-     * Get XCloner Container
96
-     * @return XCloner return the XCloner container
97
-     */
98
-    public function get_xcloner_container()
99
-    {
100
-        return $this->xcloner_container;
101
-    }
102
-
103
-    /**
104
-     * Check if user has access to this class
105
-     * @return die() returns die() if user is not allowed
106
-     * @link http://www.wordpress.org
107
-     */
108
-    private function check_access()
109
-    {
110
-        if (function_exists('current_user_can') && !current_user_can('manage_options')) {
111
-            die("Not allowed access here!");
112
-        }
113
-    }
114
-
115
-    /**
116
-     * Initialize the database connection
117
-     */
118
-    public function init_db()
119
-    {
120
-        return;
121
-
122
-
123
-        $data['dbHostname'] = $this->xcloner_settings->get_db_hostname();
124
-        $data['dbUsername'] = $this->xcloner_settings->get_db_username();
125
-        $data['dbPassword'] = $this->xcloner_settings->get_db_password();
126
-        $data['dbDatabase'] = $this->xcloner_settings->get_db_database();
127
-
128
-
129
-        $data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
130
-        $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . ".database";
131
-        $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "database-sql.sql";
132
-
133
-        try {
134
-            $this->xcloner_database->init($data);
135
-
136
-        } catch (Exception $e) {
137
-
138
-            $this->send_response($e->getMessage());
139
-            $this->logger->error($e->getMessage());
140
-
141
-        }
142
-
143
-        return $this->xcloner_database;
144
-
145
-
146
-    }
147
-
148
-    /*
46
+	private $xcloner_database;
47
+	private $xcloner_settings;
48
+	private $xcloner_file_system;
49
+	private $xcloner_requirements;
50
+	private $xcloner_sanitization;
51
+	private $archive_system;
52
+	private $form_params;
53
+	private $logger;
54
+	private $xcloner_container;
55
+
56
+	/**
57
+	 * XCloner_Api construct class
58
+	 *
59
+	 * @param Xcloner $xcloner_container [description]
60
+	 */
61
+	public function __construct(Xcloner $xcloner_container)
62
+	{
63
+		global $wpdb;
64
+
65
+		if (WP_DEBUG) {
66
+			error_reporting(0);
67
+		}
68
+
69
+		if (ob_get_length()) {
70
+			ob_end_clean();
71
+		}
72
+		ob_start();
73
+
74
+		$wpdb->show_errors = false;
75
+
76
+		$this->xcloner_container = $xcloner_container;
77
+
78
+		$this->xcloner_settings = $xcloner_container->get_xcloner_settings();
79
+		$this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_api");
80
+		$this->xcloner_file_system = $xcloner_container->get_xcloner_filesystem();
81
+		$this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization();
82
+		$this->xcloner_requirements = $xcloner_container->get_xcloner_requirements();
83
+		$this->archive_system = $xcloner_container->get_archive_system();
84
+		$this->xcloner_database = $xcloner_container->get_xcloner_database();
85
+		$this->xcloner_scheduler = $xcloner_container->get_xcloner_scheduler();
86
+
87
+		if (isset($_POST['API_ID'])) {
88
+			$this->logger->info("Processing ajax request ID " . substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']),
89
+					0, 15));
90
+		}
91
+
92
+	}
93
+
94
+	/**
95
+	 * Get XCloner Container
96
+	 * @return XCloner return the XCloner container
97
+	 */
98
+	public function get_xcloner_container()
99
+	{
100
+		return $this->xcloner_container;
101
+	}
102
+
103
+	/**
104
+	 * Check if user has access to this class
105
+	 * @return die() returns die() if user is not allowed
106
+	 * @link http://www.wordpress.org
107
+	 */
108
+	private function check_access()
109
+	{
110
+		if (function_exists('current_user_can') && !current_user_can('manage_options')) {
111
+			die("Not allowed access here!");
112
+		}
113
+	}
114
+
115
+	/**
116
+	 * Initialize the database connection
117
+	 */
118
+	public function init_db()
119
+	{
120
+		return;
121
+
122
+
123
+		$data['dbHostname'] = $this->xcloner_settings->get_db_hostname();
124
+		$data['dbUsername'] = $this->xcloner_settings->get_db_username();
125
+		$data['dbPassword'] = $this->xcloner_settings->get_db_password();
126
+		$data['dbDatabase'] = $this->xcloner_settings->get_db_database();
127
+
128
+
129
+		$data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
130
+		$data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . ".database";
131
+		$data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "database-sql.sql";
132
+
133
+		try {
134
+			$this->xcloner_database->init($data);
135
+
136
+		} catch (Exception $e) {
137
+
138
+			$this->send_response($e->getMessage());
139
+			$this->logger->error($e->getMessage());
140
+
141
+		}
142
+
143
+		return $this->xcloner_database;
144
+
145
+
146
+	}
147
+
148
+	/*
149 149
      * Save Schedule API
150 150
      */
151
-    public function save_schedule()
152
-    {
153
-        global $wpdb;
154
-
155
-        $this->check_access();
156
-
157
-        $scheduler = $this->xcloner_scheduler;
158
-        $params = array();
159
-        $schedule = array();
160
-        $response = array();
161
-
162
-        if (isset($_POST['data'])) {
163
-            $params = json_decode(stripslashes($_POST['data']));
164
-        }
165
-
166
-        $this->process_params($params);
167
-
168
-        if (isset($_POST['id'])) {
169
-
170
-            $this->form_params['backup_params']['backup_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_name']);
171
-            $this->form_params['backup_params']['email_notification'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['email_notification']);
172
-            if ($_POST['diff_start_date']) {
173
-                $this->form_params['backup_params']['diff_start_date'] = strtotime($this->xcloner_sanitization->sanitize_input_as_string($_POST['diff_start_date']));
174
-            } else {
175
-                $this->form_params['backup_params']['diff_start_date'] = "";
176
-            }
177
-            $this->form_params['backup_params']['schedule_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_name']);
178
-            $this->form_params['backup_params']['start_at'] = strtotime($_POST['schedule_start_date']);
179
-            $this->form_params['backup_params']['schedule_frequency'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_frequency']);
180
-            $this->form_params['backup_params']['schedule_storage'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_storage']);
181
-            $this->form_params['database'] = (stripslashes($this->xcloner_sanitization->sanitize_input_as_raw($_POST['table_params'])));
182
-            $this->form_params['excluded_files'] = (stripslashes($this->xcloner_sanitization->sanitize_input_as_raw($_POST['excluded_files'])));
183
-
184
-            //$this->form_params['backup_params']['backup_type'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_type']);
185
-
186
-            $tables = explode(PHP_EOL, $this->form_params['database']);
187
-            $return = array();
188
-
189
-            foreach ($tables as $table) {
190
-                $table = str_replace("\r", "", $table);
191
-                $data = explode(".", $table);
192
-                if (isset($data[1])) {
193
-                    $return[$data[0]][] = $data[1];
194
-                }
195
-            }
196
-
197
-            $this->form_params['database'] = ($return);
198
-
199
-            $excluded_files = explode(PHP_EOL, $this->form_params['excluded_files']);
200
-            $return = array();
201
-
202
-            foreach ($excluded_files as $file) {
203
-                $file = str_replace("\r", "", $file);
204
-                if ($file) {
205
-                    $return[] = $file;
206
-                }
207
-            }
208
-
209
-            $this->form_params['excluded_files'] = ($return);
210
-
211
-            $schedule['start_at'] = $this->form_params['backup_params']['start_at'];
212
-
213
-            if (!isset($_POST['status'])) {
214
-                $schedule['status'] = 0;
215
-            } else {
216
-                $schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']);
217
-            }
218
-        } else {
219
-
220
-            $schedule['status'] = 1;
221
-            $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] .
222
-                " " . $this->form_params['backup_params']['schedule_start_time']);
223
-
224
-            if ($schedule['start_at'] <= time()) {
225
-                $schedule['start_at'] = "";
226
-            }
227
-        }
228
-
229
-        if (!$schedule['start_at']) {
230
-            $schedule['start_at'] = date('Y-m-d H:i:s', time());
231
-        } else {
232
-            $schedule['start_at'] = date('Y-m-d H:i:s',
233
-                $schedule['start_at'] - (get_option('gmt_offset') * HOUR_IN_SECONDS));
234
-        }
235
-
236
-        $schedule['name'] = $this->form_params['backup_params']['schedule_name'];
237
-        $schedule['recurrence'] = $this->form_params['backup_params']['schedule_frequency'];
238
-        if (!isset($this->form_params['backup_params']['schedule_storage'])) {
239
-            $this->form_params['backup_params']['schedule_storage'] = "";
240
-        }
241
-        $schedule['remote_storage'] = $this->form_params['backup_params']['schedule_storage'];
242
-        //$schedule['backup_type'] = $this->form_params['backup_params']['backup_type'];
243
-        $schedule['params'] = json_encode($this->form_params);
244
-
245
-        if (!isset($_POST['id'])) {
246
-            $wpdb->insert(
247
-                $wpdb->prefix . 'xcloner_scheduler',
248
-                $schedule,
249
-                array(
250
-                    '%s',
251
-                    '%s'
252
-                )
253
-            );
254
-        } else {
255
-            $wpdb->update(
256
-                $wpdb->prefix . 'xcloner_scheduler',
257
-                $schedule,
258
-                array('id' => $_POST['id']),
259
-                array(
260
-                    '%s',
261
-                    '%s'
262
-                )
263
-            );
264
-        }
265
-        if (isset($_POST['id'])) {
266
-            $scheduler->update_cron_hook($_POST['id']);
267
-        }
268
-
269
-        if ($wpdb->last_error) {
270
-            $response['error'] = 1;
271
-            $response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/
272
-            ;
273
-
274
-        }
275
-
276
-        $scheduler->update_wp_cron_hooks();
277
-        $response['finished'] = 1;
278
-
279
-        $this->send_response($response);
280
-    }
281
-
282
-    /*
151
+	public function save_schedule()
152
+	{
153
+		global $wpdb;
154
+
155
+		$this->check_access();
156
+
157
+		$scheduler = $this->xcloner_scheduler;
158
+		$params = array();
159
+		$schedule = array();
160
+		$response = array();
161
+
162
+		if (isset($_POST['data'])) {
163
+			$params = json_decode(stripslashes($_POST['data']));
164
+		}
165
+
166
+		$this->process_params($params);
167
+
168
+		if (isset($_POST['id'])) {
169
+
170
+			$this->form_params['backup_params']['backup_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_name']);
171
+			$this->form_params['backup_params']['email_notification'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['email_notification']);
172
+			if ($_POST['diff_start_date']) {
173
+				$this->form_params['backup_params']['diff_start_date'] = strtotime($this->xcloner_sanitization->sanitize_input_as_string($_POST['diff_start_date']));
174
+			} else {
175
+				$this->form_params['backup_params']['diff_start_date'] = "";
176
+			}
177
+			$this->form_params['backup_params']['schedule_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_name']);
178
+			$this->form_params['backup_params']['start_at'] = strtotime($_POST['schedule_start_date']);
179
+			$this->form_params['backup_params']['schedule_frequency'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_frequency']);
180
+			$this->form_params['backup_params']['schedule_storage'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_storage']);
181
+			$this->form_params['database'] = (stripslashes($this->xcloner_sanitization->sanitize_input_as_raw($_POST['table_params'])));
182
+			$this->form_params['excluded_files'] = (stripslashes($this->xcloner_sanitization->sanitize_input_as_raw($_POST['excluded_files'])));
183
+
184
+			//$this->form_params['backup_params']['backup_type'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_type']);
185
+
186
+			$tables = explode(PHP_EOL, $this->form_params['database']);
187
+			$return = array();
188
+
189
+			foreach ($tables as $table) {
190
+				$table = str_replace("\r", "", $table);
191
+				$data = explode(".", $table);
192
+				if (isset($data[1])) {
193
+					$return[$data[0]][] = $data[1];
194
+				}
195
+			}
196
+
197
+			$this->form_params['database'] = ($return);
198
+
199
+			$excluded_files = explode(PHP_EOL, $this->form_params['excluded_files']);
200
+			$return = array();
201
+
202
+			foreach ($excluded_files as $file) {
203
+				$file = str_replace("\r", "", $file);
204
+				if ($file) {
205
+					$return[] = $file;
206
+				}
207
+			}
208
+
209
+			$this->form_params['excluded_files'] = ($return);
210
+
211
+			$schedule['start_at'] = $this->form_params['backup_params']['start_at'];
212
+
213
+			if (!isset($_POST['status'])) {
214
+				$schedule['status'] = 0;
215
+			} else {
216
+				$schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']);
217
+			}
218
+		} else {
219
+
220
+			$schedule['status'] = 1;
221
+			$schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] .
222
+				" " . $this->form_params['backup_params']['schedule_start_time']);
223
+
224
+			if ($schedule['start_at'] <= time()) {
225
+				$schedule['start_at'] = "";
226
+			}
227
+		}
228
+
229
+		if (!$schedule['start_at']) {
230
+			$schedule['start_at'] = date('Y-m-d H:i:s', time());
231
+		} else {
232
+			$schedule['start_at'] = date('Y-m-d H:i:s',
233
+				$schedule['start_at'] - (get_option('gmt_offset') * HOUR_IN_SECONDS));
234
+		}
235
+
236
+		$schedule['name'] = $this->form_params['backup_params']['schedule_name'];
237
+		$schedule['recurrence'] = $this->form_params['backup_params']['schedule_frequency'];
238
+		if (!isset($this->form_params['backup_params']['schedule_storage'])) {
239
+			$this->form_params['backup_params']['schedule_storage'] = "";
240
+		}
241
+		$schedule['remote_storage'] = $this->form_params['backup_params']['schedule_storage'];
242
+		//$schedule['backup_type'] = $this->form_params['backup_params']['backup_type'];
243
+		$schedule['params'] = json_encode($this->form_params);
244
+
245
+		if (!isset($_POST['id'])) {
246
+			$wpdb->insert(
247
+				$wpdb->prefix . 'xcloner_scheduler',
248
+				$schedule,
249
+				array(
250
+					'%s',
251
+					'%s'
252
+				)
253
+			);
254
+		} else {
255
+			$wpdb->update(
256
+				$wpdb->prefix . 'xcloner_scheduler',
257
+				$schedule,
258
+				array('id' => $_POST['id']),
259
+				array(
260
+					'%s',
261
+					'%s'
262
+				)
263
+			);
264
+		}
265
+		if (isset($_POST['id'])) {
266
+			$scheduler->update_cron_hook($_POST['id']);
267
+		}
268
+
269
+		if ($wpdb->last_error) {
270
+			$response['error'] = 1;
271
+			$response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/
272
+			;
273
+
274
+		}
275
+
276
+		$scheduler->update_wp_cron_hooks();
277
+		$response['finished'] = 1;
278
+
279
+		$this->send_response($response);
280
+	}
281
+
282
+	/*
283 283
      *
284 284
      * Backup Files API
285 285
      *
286 286
      */
287
-    public function backup_files()
288
-    {
289
-        $this->check_access();
290
-
291
-        $params = json_decode(stripslashes($_POST['data']));
292
-
293
-        $init = (int)$_POST['init'];
294
-
295
-        if ($params === null) {
296
-            die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
297
-        }
298
-
299
-        $this->process_params($params);
300
-
301
-        $return['finished'] = 1;
302
-
303
-        //$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init);
304
-        try {
305
-            $return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'],
306
-                $this->form_params['extra'], $init);
307
-        } catch (Exception $e) {
308
-            $return = array();
309
-            $return['error'] = true;
310
-            $return['status'] = 500;
311
-            $return['error_message'] = $e->getMessage();
312
-
313
-            return $this->send_response($return, $hash = 1);
314
-        }
315
-
316
-        if ($return['finished']) {
317
-            $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension();
318
-            if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) {
319
-                $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
320
-            }
321
-        }
322
-
323
-        $data = $return;
324
-
325
-        //check if backup is finished
326
-        if ($return['finished']) {
327
-            if (isset($this->form_params['backup_params']['email_notification']) and $to = $this->form_params['backup_params']['email_notification']) {
328
-                try {
329
-                    $from = "";
330
-                    $subject = "";
331
-                    $additional['lines_total'] = $return['extra']['lines_total'];
332
-                    $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'],
333
-                        $this->form_params, "", $additional);
334
-                } catch (Exception $e) {
335
-                    $this->logger->error($e->getMessage());
336
-                }
337
-            }
338
-            $this->xcloner_file_system->remove_tmp_filesystem();
339
-        }
340
-
341
-        return $this->send_response($data, $hash = 1);
342
-    }
343
-
344
-    /*
287
+	public function backup_files()
288
+	{
289
+		$this->check_access();
290
+
291
+		$params = json_decode(stripslashes($_POST['data']));
292
+
293
+		$init = (int)$_POST['init'];
294
+
295
+		if ($params === null) {
296
+			die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
297
+		}
298
+
299
+		$this->process_params($params);
300
+
301
+		$return['finished'] = 1;
302
+
303
+		//$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init);
304
+		try {
305
+			$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'],
306
+				$this->form_params['extra'], $init);
307
+		} catch (Exception $e) {
308
+			$return = array();
309
+			$return['error'] = true;
310
+			$return['status'] = 500;
311
+			$return['error_message'] = $e->getMessage();
312
+
313
+			return $this->send_response($return, $hash = 1);
314
+		}
315
+
316
+		if ($return['finished']) {
317
+			$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension();
318
+			if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) {
319
+				$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
320
+			}
321
+		}
322
+
323
+		$data = $return;
324
+
325
+		//check if backup is finished
326
+		if ($return['finished']) {
327
+			if (isset($this->form_params['backup_params']['email_notification']) and $to = $this->form_params['backup_params']['email_notification']) {
328
+				try {
329
+					$from = "";
330
+					$subject = "";
331
+					$additional['lines_total'] = $return['extra']['lines_total'];
332
+					$this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'],
333
+						$this->form_params, "", $additional);
334
+				} catch (Exception $e) {
335
+					$this->logger->error($e->getMessage());
336
+				}
337
+			}
338
+			$this->xcloner_file_system->remove_tmp_filesystem();
339
+		}
340
+
341
+		return $this->send_response($data, $hash = 1);
342
+	}
343
+
344
+	/*
345 345
      *
346 346
      * Backup Database API
347 347
      *
348 348
      */
349
-    public function backup_database()
350
-    {
351
-        $this->check_access();
349
+	public function backup_database()
350
+	{
351
+		$this->check_access();
352 352
 
353
-        $params = json_decode(stripslashes($_POST['data']));
353
+		$params = json_decode(stripslashes($_POST['data']));
354 354
 
355
-        $init = (int)$_POST['init'];
355
+		$init = (int)$_POST['init'];
356 356
 
357
-        if ($params === null) {
358
-            die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
359
-        }
357
+		if ($params === null) {
358
+			die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
359
+		}
360 360
 
361
-        $this->process_params($params);
361
+		$this->process_params($params);
362 362
 
363
-        //$xcloner_database = $this->init_db();
364
-        $return = $this->xcloner_database->start_database_recursion($this->form_params['database'],
365
-            $this->form_params['extra'], $init);
363
+		//$xcloner_database = $this->init_db();
364
+		$return = $this->xcloner_database->start_database_recursion($this->form_params['database'],
365
+			$this->form_params['extra'], $init);
366 366
 
367
-        if (isset($return['error']) and $return['error']) {
368
-            $data['finished'] = 1;
369
-        } else {
370
-            $data['finished'] = $return['finished'];
371
-        }
367
+		if (isset($return['error']) and $return['error']) {
368
+			$data['finished'] = 1;
369
+		} else {
370
+			$data['finished'] = $return['finished'];
371
+		}
372 372
 
373
-        $data['extra'] = $return;
373
+		$data['extra'] = $return;
374 374
 
375
-        return $this->send_response($data, $hash = 1);
376
-    }
375
+		return $this->send_response($data, $hash = 1);
376
+	}
377 377
 
378
-    /*
378
+	/*
379 379
      *
380 380
      * Scan Filesystem API
381 381
      *
382 382
      */
383
-    public function scan_filesystem()
384
-    {
385
-        $this->check_access();
383
+	public function scan_filesystem()
384
+	{
385
+		$this->check_access();
386 386
 
387
-        $params = json_decode(stripslashes($_POST['data']));
388
-        $init = (int)$_POST['init'];
387
+		$params = json_decode(stripslashes($_POST['data']));
388
+		$init = (int)$_POST['init'];
389 389
 
390
-        if ($params === null) {
391
-            die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
392
-        }
390
+		if ($params === null) {
391
+			die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
392
+		}
393 393
 
394
-        $hash = $this->process_params($params);
394
+		$hash = $this->process_params($params);
395 395
 
396
-        $this->xcloner_file_system->set_excluded_files($this->form_params['excluded_files']);
396
+		$this->xcloner_file_system->set_excluded_files($this->form_params['excluded_files']);
397 397
 
398
-        $return = $this->xcloner_file_system->start_file_recursion($init);
398
+		$return = $this->xcloner_file_system->start_file_recursion($init);
399 399
 
400
-        $data["finished"] = !$return;
401
-        $data["total_files_num"] = $this->xcloner_file_system->get_scanned_files_num();
402
-        $data["last_logged_file"] = $this->xcloner_file_system->last_logged_file();
403
-        $data["total_files_size"] = sprintf("%.2f",
404
-            $this->xcloner_file_system->get_scanned_files_total_size() / (1024 * 1024));
400
+		$data["finished"] = !$return;
401
+		$data["total_files_num"] = $this->xcloner_file_system->get_scanned_files_num();
402
+		$data["last_logged_file"] = $this->xcloner_file_system->last_logged_file();
403
+		$data["total_files_size"] = sprintf("%.2f",
404
+			$this->xcloner_file_system->get_scanned_files_total_size() / (1024 * 1024));
405 405
 
406
-        return $this->send_response($data, $hash = 1);
407
-    }
406
+		return $this->send_response($data, $hash = 1);
407
+	}
408 408
 
409
-    /*
409
+	/*
410 410
      *
411 411
      * Process params sent by the user
412 412
      *
413 413
      */
414
-    private function process_params($params)
415
-    {
416
-        if (isset($params->hash)) {
417
-            $this->xcloner_settings->set_hash($params->hash);
418
-        }
419
-
420
-        $this->form_params['extra'] = array();
421
-        $this->form_params['backup_params'] = array();
422
-
423
-        $this->form_params['database'] = array();
424
-
425
-        if (isset($params->backup_params)) {
426
-            foreach ($params->backup_params as $param) {
427
-                $this->form_params['backup_params'][$param->name] = $this->xcloner_sanitization->sanitize_input_as_string($param->value);
428
-                $this->logger->debug("Adding form parameter " . $param->name . "." . $param->value . "\n", array(
429
-                    'POST',
430
-                    'fields filter'
431
-                ));
432
-            }
433
-        }
434
-
435
-        $this->form_params['database'] = array();
436
-
437
-        if (isset($params->table_params)) {
438
-            foreach ($params->table_params as $param) {
439
-                $this->form_params['database'][$param->parent][] = $this->xcloner_sanitization->sanitize_input_as_raw($param->id);
440
-                $this->logger->debug("Adding database filter " . $param->parent . "." . $param->id . "\n", array(
441
-                    'POST',
442
-                    'database filter'
443
-                ));
444
-            }
445
-        }
446
-
447
-        $this->form_params['excluded_files'] = array();
448
-        if (isset($params->files_params)) {
449
-            foreach ($params->files_params as $param) {
450
-                $this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
451
-            }
452
-
453
-            $unique_exclude_files = array();
454
-
455
-            foreach ($params->files_params as $key => $param) {
456
-                if (!in_array($param->parent, $this->form_params['excluded_files'])) {
457
-                    //$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
458
-                    $unique_exclude_files[] = $param->id;
459
-                    $this->logger->debug("Adding file filter " . $param->id . "\n", array(
460
-                        'POST',
461
-                        'exclude files filter'
462
-                    ));
463
-                }
464
-            }
465
-            $this->form_params['excluded_files'] = (array)$unique_exclude_files;
466
-
467
-        }
468
-
469
-        //$this->form_params['excluded_files'] =  array_merge($this->form_params['excluded_files'], $this->exclude_files_by_default);
470
-
471
-        if (isset($params->extra)) {
472
-            foreach ($params->extra as $key => $value) {
473
-                $this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value);
474
-            }
475
-        }
476
-
477
-        if (isset($this->form_params['backup_params']['diff_start_date']) and $this->form_params['backup_params']['diff_start_date']) {
478
-            $this->form_params['backup_params']['diff_start_date'] = strtotime($this->form_params['backup_params']['diff_start_date']);
479
-            $this->xcloner_file_system->set_diff_timestamp_start($this->form_params['backup_params']['diff_start_date']);
480
-        }
481
-
482
-        return $this->xcloner_settings->get_hash();
483
-    }
484
-
485
-    /*
414
+	private function process_params($params)
415
+	{
416
+		if (isset($params->hash)) {
417
+			$this->xcloner_settings->set_hash($params->hash);
418
+		}
419
+
420
+		$this->form_params['extra'] = array();
421
+		$this->form_params['backup_params'] = array();
422
+
423
+		$this->form_params['database'] = array();
424
+
425
+		if (isset($params->backup_params)) {
426
+			foreach ($params->backup_params as $param) {
427
+				$this->form_params['backup_params'][$param->name] = $this->xcloner_sanitization->sanitize_input_as_string($param->value);
428
+				$this->logger->debug("Adding form parameter " . $param->name . "." . $param->value . "\n", array(
429
+					'POST',
430
+					'fields filter'
431
+				));
432
+			}
433
+		}
434
+
435
+		$this->form_params['database'] = array();
436
+
437
+		if (isset($params->table_params)) {
438
+			foreach ($params->table_params as $param) {
439
+				$this->form_params['database'][$param->parent][] = $this->xcloner_sanitization->sanitize_input_as_raw($param->id);
440
+				$this->logger->debug("Adding database filter " . $param->parent . "." . $param->id . "\n", array(
441
+					'POST',
442
+					'database filter'
443
+				));
444
+			}
445
+		}
446
+
447
+		$this->form_params['excluded_files'] = array();
448
+		if (isset($params->files_params)) {
449
+			foreach ($params->files_params as $param) {
450
+				$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
451
+			}
452
+
453
+			$unique_exclude_files = array();
454
+
455
+			foreach ($params->files_params as $key => $param) {
456
+				if (!in_array($param->parent, $this->form_params['excluded_files'])) {
457
+					//$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
458
+					$unique_exclude_files[] = $param->id;
459
+					$this->logger->debug("Adding file filter " . $param->id . "\n", array(
460
+						'POST',
461
+						'exclude files filter'
462
+					));
463
+				}
464
+			}
465
+			$this->form_params['excluded_files'] = (array)$unique_exclude_files;
466
+
467
+		}
468
+
469
+		//$this->form_params['excluded_files'] =  array_merge($this->form_params['excluded_files'], $this->exclude_files_by_default);
470
+
471
+		if (isset($params->extra)) {
472
+			foreach ($params->extra as $key => $value) {
473
+				$this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value);
474
+			}
475
+		}
476
+
477
+		if (isset($this->form_params['backup_params']['diff_start_date']) and $this->form_params['backup_params']['diff_start_date']) {
478
+			$this->form_params['backup_params']['diff_start_date'] = strtotime($this->form_params['backup_params']['diff_start_date']);
479
+			$this->xcloner_file_system->set_diff_timestamp_start($this->form_params['backup_params']['diff_start_date']);
480
+		}
481
+
482
+		return $this->xcloner_settings->get_hash();
483
+	}
484
+
485
+	/*
486 486
      *
487 487
      * Get file list for tree view API
488 488
      *
489 489
      */
490
-    public function get_file_system_action()
491
-    {
492
-        $this->check_access();
493
-
494
-        $folder = $this->xcloner_sanitization->sanitize_input_as_relative_path($_POST['id']);
495
-
496
-        $data = array();
497
-
498
-        if ($folder == "#") {
499
-
500
-            $folder = "/";
501
-            $data[] = array(
502
-                'id' => $folder,
503
-                'parent' => '#',
504
-                'text' => $this->xcloner_settings->get_xcloner_start_path(),
505
-                //'children' => true,
506
-                'state' => array('selected' => false, 'opened' => true),
507
-                'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-root.png"
508
-            );
509
-        }
510
-
511
-        try {
512
-            $files = $this->xcloner_file_system->list_directory($folder);
513
-        } catch (Exception $e) {
514
-
515
-            print $e->getMessage();
516
-            $this->logger->error($e->getMessage());
517
-
518
-            return;
519
-        }
520
-
521
-        $type = array();
522
-        foreach ($files as $key => $row) {
523
-            $type[$key] = $row['type'];
524
-        }
525
-        array_multisort($type, SORT_ASC, $files);
526
-
527
-        foreach ($files as $file) {
528
-            $children = false;
529
-            $text = $file['basename'];
530
-
531
-            if ($file['type'] == "dir") {
532
-                $children = true;
533
-            } else {
534
-                $text .= " (" . $this->xcloner_requirements->file_format_size($file['size']) . ")";
535
-            }
536
-
537
-            if ($this->xcloner_file_system->is_excluded($file)) {
538
-                $selected = true;
539
-            } else {
540
-                $selected = false;
541
-            }
542
-
543
-            $data[] = array(
544
-                'id' => $file['path'],
545
-                'parent' => $folder,
546
-                'text' => $text,
547
-                //'title' => "test",
548
-                'children' => $children,
549
-                'state' => array('selected' => $selected, 'opened' => false, "checkbox_disabled" => $selected),
550
-                'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-" . strtolower(substr($file['type'],
551
-                        0, 1)) . ".png"
552
-            );
553
-        }
554
-
555
-
556
-        return $this->send_response($data, 0);
557
-    }
558
-
559
-    /*
490
+	public function get_file_system_action()
491
+	{
492
+		$this->check_access();
493
+
494
+		$folder = $this->xcloner_sanitization->sanitize_input_as_relative_path($_POST['id']);
495
+
496
+		$data = array();
497
+
498
+		if ($folder == "#") {
499
+
500
+			$folder = "/";
501
+			$data[] = array(
502
+				'id' => $folder,
503
+				'parent' => '#',
504
+				'text' => $this->xcloner_settings->get_xcloner_start_path(),
505
+				//'children' => true,
506
+				'state' => array('selected' => false, 'opened' => true),
507
+				'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-root.png"
508
+			);
509
+		}
510
+
511
+		try {
512
+			$files = $this->xcloner_file_system->list_directory($folder);
513
+		} catch (Exception $e) {
514
+
515
+			print $e->getMessage();
516
+			$this->logger->error($e->getMessage());
517
+
518
+			return;
519
+		}
520
+
521
+		$type = array();
522
+		foreach ($files as $key => $row) {
523
+			$type[$key] = $row['type'];
524
+		}
525
+		array_multisort($type, SORT_ASC, $files);
526
+
527
+		foreach ($files as $file) {
528
+			$children = false;
529
+			$text = $file['basename'];
530
+
531
+			if ($file['type'] == "dir") {
532
+				$children = true;
533
+			} else {
534
+				$text .= " (" . $this->xcloner_requirements->file_format_size($file['size']) . ")";
535
+			}
536
+
537
+			if ($this->xcloner_file_system->is_excluded($file)) {
538
+				$selected = true;
539
+			} else {
540
+				$selected = false;
541
+			}
542
+
543
+			$data[] = array(
544
+				'id' => $file['path'],
545
+				'parent' => $folder,
546
+				'text' => $text,
547
+				//'title' => "test",
548
+				'children' => $children,
549
+				'state' => array('selected' => $selected, 'opened' => false, "checkbox_disabled" => $selected),
550
+				'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-" . strtolower(substr($file['type'],
551
+						0, 1)) . ".png"
552
+			);
553
+		}
554
+
555
+
556
+		return $this->send_response($data, 0);
557
+	}
558
+
559
+	/*
560 560
      *
561 561
      * Get databases/tables list for frontend tree display API
562 562
      *
563 563
      */
564
-    public function get_database_tables_action()
565
-    {
566
-        $this->check_access();
567
-
568
-        $database = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['id']);
569
-
570
-        $data = array();
571
-
572
-        $xcloner_backup_only_wp_tables = $this->xcloner_settings->get_xcloner_option('xcloner_backup_only_wp_tables');
573
-
574
-        if ($database == "#") {
575
-            try {
576
-                $return = $this->xcloner_database->get_all_databases();
577
-            } catch (Exception $e) {
578
-                $this->logger->error($e->getMessage());
579
-            }
580
-
581
-            foreach ($return as $database) {
582
-                if ($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) {
583
-                    continue;
584
-                }
585
-
586
-                $state = array();
587
-
588
-                if ($database['name'] == $this->xcloner_settings->get_db_database()) {
589
-                    $state['selected'] = true;
590
-                    if ($database['num_tables'] < 25) {
591
-                        $state['opened'] = false;
592
-                    }
593
-                }
594
-
595
-                $data[] = array(
596
-                    'id' => $database['name'],
597
-                    'parent' => '#',
598
-                    'text' => $database['name'] . " (" . (int)$database['num_tables'] . ")",
599
-                    'children' => true,
600
-                    'state' => $state,
601
-                    'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/database-icon.png"
602
-                );
603
-            }
604
-
605
-        } else {
606
-
607
-            try {
608
-                $return = $this->xcloner_database->list_tables($database, "", 1);
609
-            } catch (Exception $e) {
610
-                $this->logger->error($e->getMessage());
611
-            }
612
-
613
-            foreach ($return as $table) {
614
-                $state = array();
615
-
616
-                if ($xcloner_backup_only_wp_tables and !stristr($table['name'],
617
-                        $this->xcloner_settings->get_table_prefix())) {
618
-                    continue;
619
-                }
620
-
621
-                if (isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) {
622
-                    $state = array('selected' => true);
623
-                }
624
-
625
-                $data[] = array(
626
-                    'id' => $database . "." . $table['name'],
627
-                    'parent' => $database,
628
-                    'text' => $table['name'] . " (" . (int)$table['records'] . ")",
629
-                    'children' => false,
630
-                    'state' => $state,
631
-                    'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/table-icon.png"
632
-                );
633
-            }
634
-        }
635
-
636
-        return $this->send_response($data, 0);
637
-    }
638
-
639
-    /*
564
+	public function get_database_tables_action()
565
+	{
566
+		$this->check_access();
567
+
568
+		$database = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['id']);
569
+
570
+		$data = array();
571
+
572
+		$xcloner_backup_only_wp_tables = $this->xcloner_settings->get_xcloner_option('xcloner_backup_only_wp_tables');
573
+
574
+		if ($database == "#") {
575
+			try {
576
+				$return = $this->xcloner_database->get_all_databases();
577
+			} catch (Exception $e) {
578
+				$this->logger->error($e->getMessage());
579
+			}
580
+
581
+			foreach ($return as $database) {
582
+				if ($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) {
583
+					continue;
584
+				}
585
+
586
+				$state = array();
587
+
588
+				if ($database['name'] == $this->xcloner_settings->get_db_database()) {
589
+					$state['selected'] = true;
590
+					if ($database['num_tables'] < 25) {
591
+						$state['opened'] = false;
592
+					}
593
+				}
594
+
595
+				$data[] = array(
596
+					'id' => $database['name'],
597
+					'parent' => '#',
598
+					'text' => $database['name'] . " (" . (int)$database['num_tables'] . ")",
599
+					'children' => true,
600
+					'state' => $state,
601
+					'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/database-icon.png"
602
+				);
603
+			}
604
+
605
+		} else {
606
+
607
+			try {
608
+				$return = $this->xcloner_database->list_tables($database, "", 1);
609
+			} catch (Exception $e) {
610
+				$this->logger->error($e->getMessage());
611
+			}
612
+
613
+			foreach ($return as $table) {
614
+				$state = array();
615
+
616
+				if ($xcloner_backup_only_wp_tables and !stristr($table['name'],
617
+						$this->xcloner_settings->get_table_prefix())) {
618
+					continue;
619
+				}
620
+
621
+				if (isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) {
622
+					$state = array('selected' => true);
623
+				}
624
+
625
+				$data[] = array(
626
+					'id' => $database . "." . $table['name'],
627
+					'parent' => $database,
628
+					'text' => $table['name'] . " (" . (int)$table['records'] . ")",
629
+					'children' => false,
630
+					'state' => $state,
631
+					'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/table-icon.png"
632
+				);
633
+			}
634
+		}
635
+
636
+		return $this->send_response($data, 0);
637
+	}
638
+
639
+	/*
640 640
      *
641 641
      * Get schedule by id API
642 642
      *
643 643
      */
644
-    public function get_schedule_by_id()
645
-    {
646
-        $this->check_access();
644
+	public function get_schedule_by_id()
645
+	{
646
+		$this->check_access();
647 647
 
648
-        $schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']);
649
-        $scheduler = $this->xcloner_scheduler;
650
-        $data = $scheduler->get_schedule_by_id($schedule_id);
648
+		$schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']);
649
+		$scheduler = $this->xcloner_scheduler;
650
+		$data = $scheduler->get_schedule_by_id($schedule_id);
651 651
 
652
-        $data['start_at'] = date("Y-m-d H:i",
653
-            strtotime($data['start_at']) + (get_option('gmt_offset') * HOUR_IN_SECONDS));
654
-        if (isset($data['backup_params']->diff_start_date) && $data['backup_params']->diff_start_date != "") {
655
-            $data['backup_params']->diff_start_date = date("Y-m-d", ($data['backup_params']->diff_start_date));
656
-        }
652
+		$data['start_at'] = date("Y-m-d H:i",
653
+			strtotime($data['start_at']) + (get_option('gmt_offset') * HOUR_IN_SECONDS));
654
+		if (isset($data['backup_params']->diff_start_date) && $data['backup_params']->diff_start_date != "") {
655
+			$data['backup_params']->diff_start_date = date("Y-m-d", ($data['backup_params']->diff_start_date));
656
+		}
657 657
 
658
-        return $this->send_response($data);
659
-    }
658
+		return $this->send_response($data);
659
+	}
660 660
 
661
-    /*
661
+	/*
662 662
      *
663 663
      * Get Schedule list API
664 664
      *
665 665
      */
666
-    public function get_scheduler_list()
667
-    {
668
-        $this->check_access();
666
+	public function get_scheduler_list()
667
+	{
668
+		$this->check_access();
669 669
 
670
-        $scheduler = $this->xcloner_scheduler;
671
-        $data = $scheduler->get_scheduler_list();
672
-        $return['data'] = array();
670
+		$scheduler = $this->xcloner_scheduler;
671
+		$data = $scheduler->get_scheduler_list();
672
+		$return['data'] = array();
673 673
 
674
-        foreach ($data as $res) {
675
-            $action = "<a href=\"#" . $res->id . "\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a>
674
+		foreach ($data as $res) {
675
+			$action = "<a href=\"#" . $res->id . "\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a>
676 676
 					<a href=\"#" . $res->id . "\" class=\"delete\" title='Delete'><i class=\"material-icons  \">delete</i></a>";
677
-            if ($res->status) {
678
-                $status = '<i class="material-icons active status">timer</i>';
679
-            } else {
680
-                $status = '<i class="material-icons status inactive">timer_off</i>';
681
-            }
682
-
683
-            $next_run_time = wp_next_scheduled('xcloner_scheduler_' . $res->id, array($res->id));
684
-
685
-            $next_run = date(get_option('date_format') . " " . get_option('time_format'), $next_run_time);
686
-
687
-            $remote_storage = $res->remote_storage;
688
-
689
-            if (!$next_run_time >= time()) {
690
-                $next_run = " ";
691
-            }
692
-
693
-            if (trim($next_run)) {
694
-                $date_text = date(get_option('date_format') . " " . get_option('time_format'),
695
-                    $next_run_time + (get_option('gmt_offset') * HOUR_IN_SECONDS));
696
-
697
-                if ($next_run_time >= time()) {
698
-                    $next_run = "in " . human_time_diff($next_run_time, time());
699
-                } else {
700
-                    $next_run = __("executed", 'xcloner-backup-and-restore');
701
-                }
702
-
703
-                $next_run = "<a href='#' title='" . $date_text . "'>" . $next_run . "</a>";
704
-                //$next_run .=" ($date_text)";
705
-            }
706
-
707
-            $backup_text = "";
708
-            $backup_size = "";
709
-            $backup_time = "";
710
-
711
-            if ($res->last_backup) {
712
-                if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) {
713
-                    $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup);
714
-                    $backup_size = size_format($this->xcloner_file_system->get_backup_size($res->last_backup));
715
-                    $backup_time = date(get_option('date_format') . " " . get_option('time_format'),
716
-                        $metadata['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS));
717
-                }
718
-
719
-                $backup_text = "<span title='" . $backup_time . "' class='shorten_string'>" . $res->last_backup . " (" . $backup_size . ")</span>";
720
-            }
721
-
722
-            $schedules = wp_get_schedules();
723
-
724
-            if (isset($schedules[$res->recurrence])) {
725
-                $res->recurrence = $schedules[$res->recurrence]['display'];
726
-            }
727
-
728
-            $return['data'][] = array(
729
-                $res->id,
730
-                $res->name,
731
-                $res->recurrence,/*$res->start_at,*/
732
-                $next_run,
733
-                $remote_storage,
734
-                $backup_text,
735
-                $status,
736
-                $action
737
-            );
738
-        }
739
-
740
-        return $this->send_response($return, 0);
741
-    }
742
-
743
-    /*
677
+			if ($res->status) {
678
+				$status = '<i class="material-icons active status">timer</i>';
679
+			} else {
680
+				$status = '<i class="material-icons status inactive">timer_off</i>';
681
+			}
682
+
683
+			$next_run_time = wp_next_scheduled('xcloner_scheduler_' . $res->id, array($res->id));
684
+
685
+			$next_run = date(get_option('date_format') . " " . get_option('time_format'), $next_run_time);
686
+
687
+			$remote_storage = $res->remote_storage;
688
+
689
+			if (!$next_run_time >= time()) {
690
+				$next_run = " ";
691
+			}
692
+
693
+			if (trim($next_run)) {
694
+				$date_text = date(get_option('date_format') . " " . get_option('time_format'),
695
+					$next_run_time + (get_option('gmt_offset') * HOUR_IN_SECONDS));
696
+
697
+				if ($next_run_time >= time()) {
698
+					$next_run = "in " . human_time_diff($next_run_time, time());
699
+				} else {
700
+					$next_run = __("executed", 'xcloner-backup-and-restore');
701
+				}
702
+
703
+				$next_run = "<a href='#' title='" . $date_text . "'>" . $next_run . "</a>";
704
+				//$next_run .=" ($date_text)";
705
+			}
706
+
707
+			$backup_text = "";
708
+			$backup_size = "";
709
+			$backup_time = "";
710
+
711
+			if ($res->last_backup) {
712
+				if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) {
713
+					$metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup);
714
+					$backup_size = size_format($this->xcloner_file_system->get_backup_size($res->last_backup));
715
+					$backup_time = date(get_option('date_format') . " " . get_option('time_format'),
716
+						$metadata['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS));
717
+				}
718
+
719
+				$backup_text = "<span title='" . $backup_time . "' class='shorten_string'>" . $res->last_backup . " (" . $backup_size . ")</span>";
720
+			}
721
+
722
+			$schedules = wp_get_schedules();
723
+
724
+			if (isset($schedules[$res->recurrence])) {
725
+				$res->recurrence = $schedules[$res->recurrence]['display'];
726
+			}
727
+
728
+			$return['data'][] = array(
729
+				$res->id,
730
+				$res->name,
731
+				$res->recurrence,/*$res->start_at,*/
732
+				$next_run,
733
+				$remote_storage,
734
+				$backup_text,
735
+				$status,
736
+				$action
737
+			);
738
+		}
739
+
740
+		return $this->send_response($return, 0);
741
+	}
742
+
743
+	/*
744 744
      *
745 745
      * Delete Schedule by ID API
746 746
      *
747 747
      */
748
-    public function delete_schedule_by_id()
749
-    {
750
-        $this->check_access();
748
+	public function delete_schedule_by_id()
749
+	{
750
+		$this->check_access();
751 751
 
752
-        $schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']);
753
-        $scheduler = $this->xcloner_scheduler;
754
-        $data['finished'] = $scheduler->delete_schedule_by_id($schedule_id);
752
+		$schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']);
753
+		$scheduler = $this->xcloner_scheduler;
754
+		$data['finished'] = $scheduler->delete_schedule_by_id($schedule_id);
755 755
 
756
-        return $this->send_response($data);
757
-    }
756
+		return $this->send_response($data);
757
+	}
758 758
 
759
-    /*
759
+	/*
760 760
      *
761 761
      * Delete backup by name from the storage path
762 762
      *
763 763
      */
764
-    public function delete_backup_by_name()
765
-    {
766
-        $this->check_access();
764
+	public function delete_backup_by_name()
765
+	{
766
+		$this->check_access();
767 767
 
768
-        $backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_POST['name']);
769
-        $storage_selection = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_selection']);
768
+		$backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_POST['name']);
769
+		$storage_selection = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_selection']);
770 770
 
771
-        $data['finished'] = $this->xcloner_file_system->delete_backup_by_name($backup_name, $storage_selection);
771
+		$data['finished'] = $this->xcloner_file_system->delete_backup_by_name($backup_name, $storage_selection);
772 772
 
773
-        return $this->send_response($data);
774
-    }
773
+		return $this->send_response($data);
774
+	}
775 775
 
776
-    public function list_backup_files()
777
-    {
778
-        $this->check_access();
776
+	public function list_backup_files()
777
+	{
778
+		$this->check_access();
779 779
 
780
-        $backup_parts = array();
780
+		$backup_parts = array();
781 781
 
782
-        $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
783
-        $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']);
784
-        $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
782
+		$source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
783
+		$start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']);
784
+		$return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
785 785
 
786
-        $backup_file = $source_backup_file;
786
+		$backup_file = $source_backup_file;
787 787
 
788
-        if ($this->xcloner_file_system->is_multipart($backup_file)) {
789
-            $backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file);
790
-            $backup_file = $backup_parts[$return['part']];
791
-        }
788
+		if ($this->xcloner_file_system->is_multipart($backup_file)) {
789
+			$backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file);
790
+			$backup_file = $backup_parts[$return['part']];
791
+		}
792 792
 
793
-        try {
794
-            $tar = new Tar();
795
-            $tar->open($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file, $start);
793
+		try {
794
+			$tar = new Tar();
795
+			$tar->open($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file, $start);
796 796
 
797
-            $data = $tar->contents(get_option('xcloner_files_to_process_per_request'));
798
-        } catch (Exception $e) {
799
-            $return['error'] = true;
800
-            $return['message'] = $e->getMessage();
801
-            $this->send_response($return, 0);
802
-        }
797
+			$data = $tar->contents(get_option('xcloner_files_to_process_per_request'));
798
+		} catch (Exception $e) {
799
+			$return['error'] = true;
800
+			$return['message'] = $e->getMessage();
801
+			$this->send_response($return, 0);
802
+		}
803 803
 
804
-        $return['files'] = array();
805
-        $return['finished'] = 1;
806
-        $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file);
807
-        $i = 0;
804
+		$return['files'] = array();
805
+		$return['finished'] = 1;
806
+		$return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file);
807
+		$i = 0;
808 808
 
809
-        if (isset($data['extracted_files']) and is_array($data['extracted_files'])) {
810
-            foreach ($data['extracted_files'] as $file) {
811
-                $return['files'][$i]['path'] = $file->getPath();
812
-                $return['files'][$i]['size'] = $file->getSize();
813
-                $return['files'][$i]['mtime'] = date(get_option('date_format') . " " . get_option('time_format'),
814
-                    $file->getMtime());
809
+		if (isset($data['extracted_files']) and is_array($data['extracted_files'])) {
810
+			foreach ($data['extracted_files'] as $file) {
811
+				$return['files'][$i]['path'] = $file->getPath();
812
+				$return['files'][$i]['size'] = $file->getSize();
813
+				$return['files'][$i]['mtime'] = date(get_option('date_format') . " " . get_option('time_format'),
814
+					$file->getMtime());
815 815
 
816
-                $i++;
817
-            }
818
-        }
816
+				$i++;
817
+			}
818
+		}
819 819
 
820
-        if (isset($data['start'])) {
821
-            $return['start'] = $data['start'];
822
-            $return['finished'] = 0;
823
-        } else {
824
-            if ($this->xcloner_file_system->is_multipart($source_backup_file)) {
825
-                $return['start'] = 0;
820
+		if (isset($data['start'])) {
821
+			$return['start'] = $data['start'];
822
+			$return['finished'] = 0;
823
+		} else {
824
+			if ($this->xcloner_file_system->is_multipart($source_backup_file)) {
825
+				$return['start'] = 0;
826 826
 
827
-                ++$return['part'];
827
+				++$return['part'];
828 828
 
829
-                if ($return['part'] < sizeof($backup_parts)) {
830
-                    $return['finished'] = 0;
831
-                }
829
+				if ($return['part'] < sizeof($backup_parts)) {
830
+					$return['finished'] = 0;
831
+				}
832 832
 
833
-            }
834
-        }
833
+			}
834
+		}
835 835
 
836
-        $this->send_response($return, 0);
837
-    }
836
+		$this->send_response($return, 0);
837
+	}
838 838
 
839
-    /*
839
+	/*
840 840
      * Copy remote backup to local storage
841 841
      */
842
-    public function copy_backup_remote_to_local()
843
-    {
842
+	public function copy_backup_remote_to_local()
843
+	{
844 844
 
845
-        $this->check_access();
845
+		$this->check_access();
846 846
 
847
-        $backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
848
-        $storage_type = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_type']);
847
+		$backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
848
+		$storage_type = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_type']);
849 849
 
850
-        $xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
850
+		$xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
851 851
 
852
-        $return = array();
852
+		$return = array();
853 853
 
854
-        try {
855
-            if (method_exists($xcloner_remote_storage, "copy_backup_remote_to_local")) {
856
-                $return = call_user_func_array(array(
857
-                    $xcloner_remote_storage,
858
-                    "copy_backup_remote_to_local"
859
-                ), array($backup_file, $storage_type));
860
-            }
861
-        } catch (Exception $e) {
854
+		try {
855
+			if (method_exists($xcloner_remote_storage, "copy_backup_remote_to_local")) {
856
+				$return = call_user_func_array(array(
857
+					$xcloner_remote_storage,
858
+					"copy_backup_remote_to_local"
859
+				), array($backup_file, $storage_type));
860
+			}
861
+		} catch (Exception $e) {
862 862
 
863
-            $return['error'] = 1;
864
-            $return['message'] = $e->getMessage();
865
-        }
863
+			$return['error'] = 1;
864
+			$return['message'] = $e->getMessage();
865
+		}
866 866
 
867
-        if (!$return) {
868
-            $return['error'] = 1;
869
-            $return['message'] = "Upload failed, please check the error log for more information!";
870
-        }
867
+		if (!$return) {
868
+			$return['error'] = 1;
869
+			$return['message'] = "Upload failed, please check the error log for more information!";
870
+		}
871 871
 
872 872
 
873
-        $this->send_response($return, 0);
873
+		$this->send_response($return, 0);
874 874
 
875
-    }
875
+	}
876 876
 
877
-    /*
877
+	/*
878 878
      *
879 879
      * Upload backup to remote API
880 880
      *
881 881
      */
882
-    public function upload_backup_to_remote()
883
-    {
884
-        $this->check_access();
882
+	public function upload_backup_to_remote()
883
+	{
884
+		$this->check_access();
885 885
 
886
-        $backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
887
-        $storage_type = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_type']);
886
+		$backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
887
+		$storage_type = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_type']);
888 888
 
889
-        $xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
889
+		$xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
890 890
 
891
-        $return = array();
891
+		$return = array();
892 892
 
893
-        try {
894
-            if (method_exists($xcloner_remote_storage, "upload_backup_to_storage")) {
895
-                $return = call_user_func_array(array(
896
-                    $xcloner_remote_storage,
897
-                    "upload_backup_to_storage"
898
-                ), array($backup_file, $storage_type));
899
-            }
900
-        } catch (Exception $e) {
893
+		try {
894
+			if (method_exists($xcloner_remote_storage, "upload_backup_to_storage")) {
895
+				$return = call_user_func_array(array(
896
+					$xcloner_remote_storage,
897
+					"upload_backup_to_storage"
898
+				), array($backup_file, $storage_type));
899
+			}
900
+		} catch (Exception $e) {
901 901
 
902
-            $return['error'] = 1;
903
-            $return['message'] = $e->getMessage();
904
-        }
902
+			$return['error'] = 1;
903
+			$return['message'] = $e->getMessage();
904
+		}
905 905
 
906
-        if (!$return) {
907
-            $return['error'] = 1;
908
-            $return['message'] = "Upload failed, please check the error log for more information!";
909
-        }
906
+		if (!$return) {
907
+			$return['error'] = 1;
908
+			$return['message'] = "Upload failed, please check the error log for more information!";
909
+		}
910 910
 
911 911
 
912
-        $this->send_response($return, 0);
912
+		$this->send_response($return, 0);
913 913
 
914
-    }
914
+	}
915 915
 
916
-    /*
916
+	/*
917 917
      *
918 918
      * Remote Storage Status Save
919 919
      *
920 920
      */
921
-    public function remote_storage_save_status()
922
-    {
923
-        $this->check_access();
921
+	public function remote_storage_save_status()
922
+	{
923
+		$this->check_access();
924 924
 
925
-        $xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
925
+		$xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
926 926
 
927
-        $return['finished'] = $xcloner_remote_storage->change_storage_status($_POST['id'], $_POST['value']);
927
+		$return['finished'] = $xcloner_remote_storage->change_storage_status($_POST['id'], $_POST['value']);
928 928
 
929
-        $this->send_response($return, 0);
930
-    }
929
+		$this->send_response($return, 0);
930
+	}
931 931
 
932 932
 
933
-    public function download_restore_script()
934
-    {
935
-        $this->check_access();
933
+	public function download_restore_script()
934
+	{
935
+		$this->check_access();
936 936
 
937
-        @ob_end_clean();
937
+		@ob_end_clean();
938 938
 
939
-        $adapter = new Local(dirname(__DIR__), LOCK_EX, 'SKIP_LINKS');
940
-        $xcloner_plugin_filesystem = new Filesystem($adapter, new Config([
941
-            'disable_asserts' => true,
942
-        ]));
939
+		$adapter = new Local(dirname(__DIR__), LOCK_EX, 'SKIP_LINKS');
940
+		$xcloner_plugin_filesystem = new Filesystem($adapter, new Config([
941
+			'disable_asserts' => true,
942
+		]));
943 943
 
944
-        /* Generate PHAR FILE
944
+		/* Generate PHAR FILE
945 945
         $file = 'restore/vendor.built';
946 946
 
947 947
         if(file_exists($file))
@@ -957,178 +957,178 @@  discard block
 block discarded – undo
957 957
         $phar2->setStub($phar2->createDefaultStub('vendor/autoload.php', 'vendor/autoload.php'));
958 958
          * */
959 959
 
960
-        $tmp_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "xcloner-restore.tgz";
960
+		$tmp_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "xcloner-restore.tgz";
961 961
 
962
-        $tar = new Tar();
963
-        $tar->create($tmp_file);
962
+		$tar = new Tar();
963
+		$tar->create($tmp_file);
964 964
 
965
-        $tar->addFile(dirname(__DIR__) . "/restore/vendor.build.txt", "vendor.phar");
966
-        //$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz");
965
+		$tar->addFile(dirname(__DIR__) . "/restore/vendor.build.txt", "vendor.phar");
966
+		//$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz");
967 967
 
968
-        $files = $xcloner_plugin_filesystem->listContents("vendor/", true);
969
-        foreach ($files as $file) {
970
-            $tar->addFile(dirname(__DIR__) . DS . $file['path'], $file['path']);
971
-        }
968
+		$files = $xcloner_plugin_filesystem->listContents("vendor/", true);
969
+		foreach ($files as $file) {
970
+			$tar->addFile(dirname(__DIR__) . DS . $file['path'], $file['path']);
971
+		}
972 972
 
973
-        $content = file_get_contents(dirname(__DIR__) . "/restore/xcloner_restore.php");
974
-        $content = str_replace("define('AUTH_KEY', '');", "define('AUTH_KEY', '" . md5(AUTH_KEY) . "');", $content);
973
+		$content = file_get_contents(dirname(__DIR__) . "/restore/xcloner_restore.php");
974
+		$content = str_replace("define('AUTH_KEY', '');", "define('AUTH_KEY', '" . md5(AUTH_KEY) . "');", $content);
975 975
 
976
-        $tar->addData("xcloner_restore.php", $content);
976
+		$tar->addData("xcloner_restore.php", $content);
977 977
 
978
-        $tar->close();
978
+		$tar->close();
979 979
 
980
-        if (file_exists($tmp_file)) {
981
-            header('Content-Description: File Transfer');
982
-            header('Content-Type: application/octet-stream');
983
-            header('Content-Disposition: attachment; filename="' . basename($tmp_file) . '"');
984
-            header('Expires: 0');
985
-            header('Cache-Control: must-revalidate');
986
-            header('Pragma: public');
987
-            header('Content-Length: ' . filesize($tmp_file));
988
-            readfile($tmp_file);
980
+		if (file_exists($tmp_file)) {
981
+			header('Content-Description: File Transfer');
982
+			header('Content-Type: application/octet-stream');
983
+			header('Content-Disposition: attachment; filename="' . basename($tmp_file) . '"');
984
+			header('Expires: 0');
985
+			header('Cache-Control: must-revalidate');
986
+			header('Pragma: public');
987
+			header('Content-Length: ' . filesize($tmp_file));
988
+			readfile($tmp_file);
989 989
 
990
-        }
990
+		}
991 991
 
992
-        @unlink($tmp_file);
993
-        exit;
994
-    }
992
+		@unlink($tmp_file);
993
+		exit;
994
+	}
995 995
 
996
-    /*
996
+	/*
997 997
      *
998 998
      * Download backup by Name from the Storage Path
999 999
      *
1000 1000
      */
1001
-    public function download_backup_by_name()
1002
-    {
1003
-        $this->check_access();
1001
+	public function download_backup_by_name()
1002
+	{
1003
+		$this->check_access();
1004 1004
 
1005
-        @ob_end_clean();
1005
+		@ob_end_clean();
1006 1006
 
1007
-        $backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_GET['name']);
1007
+		$backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_GET['name']);
1008 1008
 
1009 1009
 
1010
-        $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name);
1011
-        $read_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name);
1010
+		$metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name);
1011
+		$read_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name);
1012 1012
 
1013 1013
 
1014
-        header('Pragma: public');
1015
-        header('Expires: 0');
1016
-        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1017
-        header('Cache-Control: private', false);
1018
-        header('Content-Transfer-Encoding: binary');
1019
-        header('Content-Disposition: attachment; filename="' . $metadata['path'] . '";');
1020
-        header('Content-Type: application/octet-stream');
1021
-        header('Content-Length: ' . $metadata['size']);
1014
+		header('Pragma: public');
1015
+		header('Expires: 0');
1016
+		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1017
+		header('Cache-Control: private', false);
1018
+		header('Content-Transfer-Encoding: binary');
1019
+		header('Content-Disposition: attachment; filename="' . $metadata['path'] . '";');
1020
+		header('Content-Type: application/octet-stream');
1021
+		header('Content-Length: ' . $metadata['size']);
1022 1022
 
1023
-        @ob_end_clean();
1023
+		@ob_end_clean();
1024 1024
 
1025
-        $chunkSize = 1024 * 1024;
1026
-        while (!feof($read_stream)) {
1027
-            $buffer = fread($read_stream, $chunkSize);
1028
-            echo $buffer;
1029
-        }
1030
-        fclose($read_stream);
1031
-        exit;
1025
+		$chunkSize = 1024 * 1024;
1026
+		while (!feof($read_stream)) {
1027
+			$buffer = fread($read_stream, $chunkSize);
1028
+			echo $buffer;
1029
+		}
1030
+		fclose($read_stream);
1031
+		exit;
1032 1032
 
1033
-    }
1033
+	}
1034 1034
 
1035
-    /*
1035
+	/*
1036 1036
      * Restore upload backup
1037 1037
      */
1038
-    public function restore_upload_backup()
1039
-    {
1040
-        $this->check_access();
1038
+	public function restore_upload_backup()
1039
+	{
1040
+		$this->check_access();
1041 1041
 
1042
-        $return['part'] = 0;
1043
-        $return['total_parts'] = 0;
1044
-        $return['uploaded_size'] = 0;
1045
-        $is_multipart = 0;
1042
+		$return['part'] = 0;
1043
+		$return['total_parts'] = 0;
1044
+		$return['uploaded_size'] = 0;
1045
+		$is_multipart = 0;
1046 1046
 
1047
-        $file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
1048
-        $hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']);
1047
+		$file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
1048
+		$hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']);
1049 1049
 
1050
-        if (isset($_POST['part'])) {
1051
-            $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
1052
-        }
1050
+		if (isset($_POST['part'])) {
1051
+			$return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
1052
+		}
1053 1053
 
1054
-        if (isset($_POST['uploaded_size'])) {
1055
-            $return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']);
1056
-        }
1054
+		if (isset($_POST['uploaded_size'])) {
1055
+			$return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']);
1056
+		}
1057 1057
 
1058
-        $start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']);
1059
-        $target_url = $this->xcloner_sanitization->sanitize_input_as_string($_POST['target_url']);
1058
+		$start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']);
1059
+		$target_url = $this->xcloner_sanitization->sanitize_input_as_string($_POST['target_url']);
1060 1060
 
1061
-        $return['total_size'] = $this->xcloner_file_system->get_backup_size($file);
1061
+		$return['total_size'] = $this->xcloner_file_system->get_backup_size($file);
1062 1062
 
1063
-        if ($this->xcloner_file_system->is_multipart($file)) {
1064
-            $backup_parts = $this->xcloner_file_system->get_multipart_files($file);
1063
+		if ($this->xcloner_file_system->is_multipart($file)) {
1064
+			$backup_parts = $this->xcloner_file_system->get_multipart_files($file);
1065 1065
 
1066
-            $return['total_parts'] = sizeof($backup_parts) + 1;
1066
+			$return['total_parts'] = sizeof($backup_parts) + 1;
1067 1067
 
1068
-            if ($return['part'] and isset($backup_parts[$return['part'] - 1])) {
1069
-                $file = $backup_parts[$return['part'] - 1];
1070
-            }
1068
+			if ($return['part'] and isset($backup_parts[$return['part'] - 1])) {
1069
+				$file = $backup_parts[$return['part'] - 1];
1070
+			}
1071 1071
 
1072
-            $is_multipart = 1;
1073
-        }
1072
+			$is_multipart = 1;
1073
+		}
1074 1074
 
1075
-        try {
1075
+		try {
1076 1076
 
1077
-            $xcloner_file_transfer = $this->get_xcloner_container()->get_xcloner_file_transfer();
1078
-            $xcloner_file_transfer->set_target($target_url);
1079
-            $return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash);
1077
+			$xcloner_file_transfer = $this->get_xcloner_container()->get_xcloner_file_transfer();
1078
+			$xcloner_file_transfer->set_target($target_url);
1079
+			$return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash);
1080 1080
 
1081
-        } catch (Exception $e) {
1081
+		} catch (Exception $e) {
1082 1082
 
1083
-            $return = array();
1084
-            $return['error'] = true;
1085
-            $return['status'] = 500;
1086
-            $return['message'] = "CURL communication error with the restore host. " . $e->getMessage();
1087
-            $this->send_response($return, 0);
1083
+			$return = array();
1084
+			$return['error'] = true;
1085
+			$return['status'] = 500;
1086
+			$return['message'] = "CURL communication error with the restore host. " . $e->getMessage();
1087
+			$this->send_response($return, 0);
1088 1088
 
1089
-        }
1089
+		}
1090 1090
 
1091
-        $return['status'] = 200;
1091
+		$return['status'] = 200;
1092 1092
 
1093
-        //we have finished the upload
1094
-        if (!$return['start'] and $is_multipart) {
1095
-            $return['part']++;
1096
-            $return['uploaded_size'] += $this->xcloner_file_system->get_storage_filesystem()->getSize($file);
1097
-        }
1093
+		//we have finished the upload
1094
+		if (!$return['start'] and $is_multipart) {
1095
+			$return['part']++;
1096
+			$return['uploaded_size'] += $this->xcloner_file_system->get_storage_filesystem()->getSize($file);
1097
+		}
1098 1098
 
1099
-        $this->send_response($return, 0);
1100
-    }
1099
+		$this->send_response($return, 0);
1100
+	}
1101 1101
 
1102
-    /*
1102
+	/*
1103 1103
      * Restore backup
1104 1104
      */
1105
-    public function restore_backup()
1106
-    {
1107
-        $this->check_access();
1105
+	public function restore_backup()
1106
+	{
1107
+		$this->check_access();
1108 1108
 
1109
-        define("XCLONER_PLUGIN_ACCESS", 1);
1110
-        include_once(dirname(__DIR__) . DS . "restore" . DS . "xcloner_restore.php");
1109
+		define("XCLONER_PLUGIN_ACCESS", 1);
1110
+		include_once(dirname(__DIR__) . DS . "restore" . DS . "xcloner_restore.php");
1111 1111
 
1112
-        return;
1113
-    }
1112
+		return;
1113
+	}
1114 1114
 
1115
-    /*
1115
+	/*
1116 1116
      *
1117 1117
      * Send the json response back
1118 1118
      *
1119 1119
      */
1120
-    private function send_response($data, $attach_hash = 1)
1121
-    {
1120
+	private function send_response($data, $attach_hash = 1)
1121
+	{
1122 1122
 
1123
-        if ($attach_hash and null !== $this->xcloner_settings->get_hash()) {
1124
-            $data['hash'] = $this->xcloner_settings->get_hash();
1125
-        }
1123
+		if ($attach_hash and null !== $this->xcloner_settings->get_hash()) {
1124
+			$data['hash'] = $this->xcloner_settings->get_hash();
1125
+		}
1126 1126
 
1127
-        if (ob_get_length()) {
1128
-            ob_clean();
1129
-        }
1130
-        wp_send_json($data);
1127
+		if (ob_get_length()) {
1128
+			ob_clean();
1129
+		}
1130
+		wp_send_json($data);
1131 1131
 
1132
-        die();
1133
-    }
1132
+		die();
1133
+	}
1134 1134
 }
Please login to merge, or discard this patch.
includes/class-xcloner-i18n.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -41,21 +41,21 @@
 block discarded – undo
41 41
 class Xcloner_i18n
42 42
 {
43 43
 
44
-    /**
45
-     * Load the plugin text domain for translation.
46
-     *
47
-     * @since    1.0.0
48
-     */
49
-    public function load_plugin_textdomain()
50
-    {
44
+	/**
45
+	 * Load the plugin text domain for translation.
46
+	 *
47
+	 * @since    1.0.0
48
+	 */
49
+	public function load_plugin_textdomain()
50
+	{
51 51
 
52
-        load_plugin_textdomain(
53
-            'xcloner-backup-and-restore',
54
-            false,
55
-            dirname(dirname(plugin_basename(__FILE__))) . '/languages/'
56
-        );
52
+		load_plugin_textdomain(
53
+			'xcloner-backup-and-restore',
54
+			false,
55
+			dirname(dirname(plugin_basename(__FILE__))) . '/languages/'
56
+		);
57 57
 
58
-    }
58
+	}
59 59
 
60 60
 
61 61
 }
Please login to merge, or discard this patch.
includes/class-xcloner-file-system.php 1 patch
Indentation   +957 added lines, -957 removed lines patch added patch discarded remove patch
@@ -37,848 +37,848 @@  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");
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
-    public function get_storage_path_file_info($file)
211
-    {
212
-        return $this->getMetadataFull('storage_adapter', $file);
213
-    }
214
-
215
-    public function get_included_files_handler($metadata = 0)
216
-    {
217
-        $path = $this->included_files_handler;
218
-        if (!$metadata) {
219
-            return $path;
220
-        }
221
-
222
-        $spl_info = $this->getMetadataFull('tmp_adapter', $path);
223
-
224
-        return $spl_info;
225
-
226
-    }
227
-
228
-    public function get_temp_dir_handler()
229
-    {
230
-        return $this->temp_dir_handler;
231
-    }
232
-
233
-    public function get_latest_backup()
234
-    {
235
-        $files = $this->get_backup_archives_list();
236
-
237
-        if (is_array($files)) {
238
-            $this->sort_by($files, "timestamp", "desc");
239
-        }
240
-
241
-        $new_list = array();
242
-
243
-        foreach ($files as $key => $file) {
244
-            if (!isset($file['parent'])) {
245
-                $new_list[] = ($files[$key]);
246
-            }
247
-        }
248
-
249
-        if (isset($new_list[0])) {
250
-            return $new_list[0];
251
-        }
252
-    }
253
-
254
-    public function get_latest_backups()
255
-    {
256
-        $files = $this->get_backup_archives_list();
257
-
258
-        if (is_array($files)) {
259
-            $this->sort_by($files, "timestamp", "desc");
260
-        }
261
-
262
-        $new_list = array();
263
-
264
-        foreach ($files as $key => $file) {
265
-            if (!isset($file['parent'])) {
266
-                $new_list[] = ($files[$key]);
267
-            }
268
-        }
269
-
270
-        return $new_list;
271
-    }
272
-
273
-    public function get_storage_usage()
274
-    {
275
-        $files = $this->get_backup_archives_list();
276
-        $total = 0;
277
-
278
-        if (is_array($files)) {
279
-            foreach ($files as $file) {
280
-                $total += $file['size'];
281
-            }
282
-        }
283
-
284
-        return $total;
285
-    }
286
-
287
-    public function is_part($backup_name)
288
-    {
289
-        if (stristr($backup_name, "-part")) {
290
-            return true;
291
-        }
292
-
293
-        return false;
294
-    }
295
-
296
-    public function is_multipart($backup_name)
297
-    {
298
-        if (stristr($backup_name, "-multipart")) {
299
-            return true;
300
-        }
301
-
302
-        return false;
303
-    }
304
-
305
-    public function get_backup_size($backup_name)
306
-    {
307
-        $backup_size = $this->get_storage_filesystem()->getSize($backup_name);
308
-        if ($this->is_multipart($backup_name)) {
309
-            $backup_parts = $this->get_multipart_files($backup_name);
310
-            foreach ($backup_parts as $part_file) {
311
-                $backup_size += $this->get_storage_filesystem()->getSize($part_file);
312
-            }
313
-        }
314
-
315
-        return $backup_size;
316
-    }
317
-
318
-    public function get_multipart_files($backup_name, $storage_selection = "")
319
-    {
320
-        $files = array();
321
-
322
-        if ($this->is_multipart($backup_name)) {
323
-            $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
324
-            foreach ($lines as $line) {
325
-                if ($line) {
326
-                    $data = str_getcsv($line);
327
-                    $files[] = $data[0];
328
-                }
329
-            }
330
-        }
331
-
332
-        return $files;
333
-    }
334
-
335
-    public function delete_backup_by_name($backup_name, $storage_selection = "")
336
-    {
337
-        if ($this->is_multipart($backup_name)) {
338
-            $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
339
-            foreach ($lines as $line) {
340
-                if ($line) {
341
-                    $data = str_getcsv($line);
342
-                    $this->get_storage_filesystem($storage_selection)->delete($data[0]);
343
-                }
344
-            }
345
-        }
346
-
347
-        if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) {
348
-            $return = true;
349
-        } else {
350
-            $return = false;
351
-        }
352
-
353
-        return $return;
354
-    }
355
-
356
-    public function getMetadataFull($adapter = "storage_adapter", $path)
357
-    {
358
-        $location = $this->$adapter->applyPathPrefix($path);
359
-        $spl_info = new SplFileInfo($location);
360
-
361
-        return ($spl_info);
362
-    }
363
-
364
-
365
-    public function get_backup_archives_list($storage_selection = "")
366
-    {
367
-        $list = array();
368
-
369
-
370
-        if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) {
371
-            $list = $this->get_storage_filesystem($storage_selection)->listContents();
372
-        }
373
-
374
-        $backup_files = array();
375
-        $parents = array();
376
-
377
-        foreach ($list as $file_info) {
378
-            if (isset($file_info['extension']) and $file_info['extension'] == "csv") {
379
-                $data = array();
380
-
381
-                $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path']));
382
-                foreach ($lines as $line) {
383
-                    if ($line) {
384
-                        $data = str_getcsv($line);
385
-                        if (is_array($data)) {
386
-                            $parents[$data[0]] = $file_info['basename'];
387
-                            $file_info['childs'][] = $data;
388
-                            $file_info['size'] += $data[2];
389
-                        }
390
-                    }
391
-                }
392
-
393
-            }
394
-
395
-            if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'],
396
-                    $this->backup_archive_extensions)) {
397
-                $backup_files[$file_info['path']] = $file_info;
398
-            }
399
-        }
400
-
401
-        foreach ($backup_files as $key => $file_info) {
402
-            if (!isset($backup_files[$key]['timestamp'])) {
403
-                //$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']);
404
-            }
405
-
406
-            if (isset($parents[$file_info['basename']])) {
407
-                $backup_files[$key]['parent'] = $parents[$file_info['basename']];
408
-            }
409
-        }
410
-
411
-        return $backup_files;
412
-    }
413
-
414
-    public function start_file_recursion($init = 0)
415
-    {
416
-        if ($init) {
417
-            $this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"),
418
-                $this->xcloner_settings->get_xcloner_start_path()));
419
-            $this->do_system_init();
420
-        }
421
-
422
-        if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
423
-            //.dir exists, we presume we have files to iterate
424
-            $content = $this->tmp_filesystem->read($this->get_temp_dir_handler());
425
-            $files = array_filter(explode("\n", $content));
426
-            $this->tmp_filesystem->delete($this->get_temp_dir_handler());
427
-
428
-            $counter = 0;
429
-            foreach ($files as $file) {
430
-                if ($counter < $this->folders_to_process_per_session) {
431
-                    $this->build_files_list($file);
432
-                    $counter++;
433
-                } else {
434
-                    $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file . "\n");
435
-                }
436
-            }
437
-        } else {
438
-            $this->build_files_list();
439
-        }
440
-
441
-        if ($this->scan_finished()) {
442
-            $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html");
443
-            $this->store_file($metadata_dumpfile, 'tmp_filesystem');
444
-            $this->files_counter++;
445
-
446
-            //adding included dump file to the included files list
447
-            if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) {
448
-                $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler());
449
-                $this->store_file($metadata_dumpfile, 'tmp_filesystem');
450
-                $this->files_counter++;
451
-            }
452
-
453
-            //adding a default index.html to the temp xcloner folder
454
-            if (!$this->get_tmp_filesystem()->has("index.html")) {
455
-                $this->get_tmp_filesystem()->write("index.html", "");
456
-            }
457
-
458
-            //adding the default log file
459
-            if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) {
460
-                $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1));
461
-                $this->store_file($metadata_dumpfile, 'tmp_filesystem');
462
-                $this->files_counter++;
463
-            }
464
-
465
-            return false;
466
-        }
467
-
468
-        return true;
469
-    }
470
-
471
-    public function get_backup_attachments()
472
-    {
473
-        $return = array();
474
-
475
-        $files_list_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->get_included_files_handler();
476
-        if (file_exists($files_list_file)) {
477
-            $return[] = $files_list_file;
478
-        }
479
-
480
-        if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
481
-            $log_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->xcloner_settings->get_logger_filename(1);
482
-            if (!file_exists($log_file)) {
483
-                $log_file = $this->xcloner_settings->get_xcloner_store_path() . DS . $this->xcloner_settings->get_logger_filename();
484
-            }
485
-
486
-            if (file_exists($log_file)) {
487
-                $return[] = $log_file;
488
-            }
489
-        }
490
-
491
-        return $return;
492
-    }
493
-
494
-    public function remove_tmp_filesystem()
495
-    {
496
-        //delete the temporary folder
497
-        $this->logger->debug(sprintf("Deleting the temporary storage folder %s",
498
-            $this->xcloner_settings->get_xcloner_tmp_path()));
499
-
500
-        $contents = $this->get_tmp_filesystem()->listContents();
501
-
502
-        if (is_array($contents)) {
503
-            foreach ($contents as $file_info) {
504
-                $this->get_tmp_filesystem()->delete($file_info['path']);
505
-            }
506
-        }
507
-
508
-        @rmdir($this->xcloner_settings->get_xcloner_tmp_path());
509
-
510
-        return;
511
-    }
512
-
513
-    public function cleanup_tmp_directories()
514
-    {
515
-        $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
516
-        $tmp_filesystem = new Filesystem($adapter, new Config([
517
-            'disable_asserts' => true,
518
-        ]));
519
-
520
-        $contents = $tmp_filesystem->listContents();
521
-
522
-        foreach ($contents as $file) {
523
-
524
-            if (preg_match("/.xcloner-(.*)/", $file['path'])) {
525
-                if ($file['timestamp'] < strtotime("-1days")) {
526
-                    $tmp_filesystem->deleteDir($file['path']);
527
-                    $this->logger->debug(sprintf("Delete temporary directory %s", $file['path']));
528
-                }
529
-            }
530
-        }
531
-
532
-        return true;
533
-    }
534
-
535
-    private function do_system_init()
536
-    {
537
-        $this->files_counter = 0;
538
-
539
-        if (!$this->storage_filesystem->has("index.html")) {
540
-            $this->storage_filesystem->write("index.html", "");
541
-        }
542
-
543
-        if (!$this->tmp_filesystem->has("index.html")) {
544
-            $this->tmp_filesystem->write("index.html", "");
545
-        }
546
-
547
-        if ($this->tmp_filesystem->has($this->get_included_files_handler())) {
548
-            $this->tmp_filesystem->delete($this->get_included_files_handler());
549
-        }
550
-
551
-        if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
552
-            $this->tmp_filesystem->delete($this->get_temp_dir_handler());
553
-        }
554
-    }
555
-
556
-    public function get_scanned_files_num()
557
-    {
558
-        return $this->files_counter;
559
-    }
560
-
561
-    public function get_scanned_files_total_size()
562
-    {
563
-        return $this->files_size;
564
-    }
565
-
566
-    public function last_logged_file()
567
-    {
568
-        return $this->last_logged_file;
569
-    }
570
-
571
-    public static function is_regex($regex)
572
-    {
573
-        return preg_match("/^\^(.*)\$$/i", $regex);
574
-    }
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");
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
+	public function get_storage_path_file_info($file)
211
+	{
212
+		return $this->getMetadataFull('storage_adapter', $file);
213
+	}
214
+
215
+	public function get_included_files_handler($metadata = 0)
216
+	{
217
+		$path = $this->included_files_handler;
218
+		if (!$metadata) {
219
+			return $path;
220
+		}
221
+
222
+		$spl_info = $this->getMetadataFull('tmp_adapter', $path);
223
+
224
+		return $spl_info;
225
+
226
+	}
227
+
228
+	public function get_temp_dir_handler()
229
+	{
230
+		return $this->temp_dir_handler;
231
+	}
232
+
233
+	public function get_latest_backup()
234
+	{
235
+		$files = $this->get_backup_archives_list();
236
+
237
+		if (is_array($files)) {
238
+			$this->sort_by($files, "timestamp", "desc");
239
+		}
240
+
241
+		$new_list = array();
242
+
243
+		foreach ($files as $key => $file) {
244
+			if (!isset($file['parent'])) {
245
+				$new_list[] = ($files[$key]);
246
+			}
247
+		}
248
+
249
+		if (isset($new_list[0])) {
250
+			return $new_list[0];
251
+		}
252
+	}
253
+
254
+	public function get_latest_backups()
255
+	{
256
+		$files = $this->get_backup_archives_list();
257
+
258
+		if (is_array($files)) {
259
+			$this->sort_by($files, "timestamp", "desc");
260
+		}
261
+
262
+		$new_list = array();
263
+
264
+		foreach ($files as $key => $file) {
265
+			if (!isset($file['parent'])) {
266
+				$new_list[] = ($files[$key]);
267
+			}
268
+		}
269
+
270
+		return $new_list;
271
+	}
272
+
273
+	public function get_storage_usage()
274
+	{
275
+		$files = $this->get_backup_archives_list();
276
+		$total = 0;
277
+
278
+		if (is_array($files)) {
279
+			foreach ($files as $file) {
280
+				$total += $file['size'];
281
+			}
282
+		}
283
+
284
+		return $total;
285
+	}
286
+
287
+	public function is_part($backup_name)
288
+	{
289
+		if (stristr($backup_name, "-part")) {
290
+			return true;
291
+		}
292
+
293
+		return false;
294
+	}
295
+
296
+	public function is_multipart($backup_name)
297
+	{
298
+		if (stristr($backup_name, "-multipart")) {
299
+			return true;
300
+		}
301
+
302
+		return false;
303
+	}
304
+
305
+	public function get_backup_size($backup_name)
306
+	{
307
+		$backup_size = $this->get_storage_filesystem()->getSize($backup_name);
308
+		if ($this->is_multipart($backup_name)) {
309
+			$backup_parts = $this->get_multipart_files($backup_name);
310
+			foreach ($backup_parts as $part_file) {
311
+				$backup_size += $this->get_storage_filesystem()->getSize($part_file);
312
+			}
313
+		}
314
+
315
+		return $backup_size;
316
+	}
317
+
318
+	public function get_multipart_files($backup_name, $storage_selection = "")
319
+	{
320
+		$files = array();
321
+
322
+		if ($this->is_multipart($backup_name)) {
323
+			$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
324
+			foreach ($lines as $line) {
325
+				if ($line) {
326
+					$data = str_getcsv($line);
327
+					$files[] = $data[0];
328
+				}
329
+			}
330
+		}
331
+
332
+		return $files;
333
+	}
334
+
335
+	public function delete_backup_by_name($backup_name, $storage_selection = "")
336
+	{
337
+		if ($this->is_multipart($backup_name)) {
338
+			$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
339
+			foreach ($lines as $line) {
340
+				if ($line) {
341
+					$data = str_getcsv($line);
342
+					$this->get_storage_filesystem($storage_selection)->delete($data[0]);
343
+				}
344
+			}
345
+		}
346
+
347
+		if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) {
348
+			$return = true;
349
+		} else {
350
+			$return = false;
351
+		}
352
+
353
+		return $return;
354
+	}
355
+
356
+	public function getMetadataFull($adapter = "storage_adapter", $path)
357
+	{
358
+		$location = $this->$adapter->applyPathPrefix($path);
359
+		$spl_info = new SplFileInfo($location);
360
+
361
+		return ($spl_info);
362
+	}
363
+
364
+
365
+	public function get_backup_archives_list($storage_selection = "")
366
+	{
367
+		$list = array();
368
+
369
+
370
+		if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) {
371
+			$list = $this->get_storage_filesystem($storage_selection)->listContents();
372
+		}
373
+
374
+		$backup_files = array();
375
+		$parents = array();
376
+
377
+		foreach ($list as $file_info) {
378
+			if (isset($file_info['extension']) and $file_info['extension'] == "csv") {
379
+				$data = array();
380
+
381
+				$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path']));
382
+				foreach ($lines as $line) {
383
+					if ($line) {
384
+						$data = str_getcsv($line);
385
+						if (is_array($data)) {
386
+							$parents[$data[0]] = $file_info['basename'];
387
+							$file_info['childs'][] = $data;
388
+							$file_info['size'] += $data[2];
389
+						}
390
+					}
391
+				}
392
+
393
+			}
394
+
395
+			if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'],
396
+					$this->backup_archive_extensions)) {
397
+				$backup_files[$file_info['path']] = $file_info;
398
+			}
399
+		}
400
+
401
+		foreach ($backup_files as $key => $file_info) {
402
+			if (!isset($backup_files[$key]['timestamp'])) {
403
+				//$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']);
404
+			}
405
+
406
+			if (isset($parents[$file_info['basename']])) {
407
+				$backup_files[$key]['parent'] = $parents[$file_info['basename']];
408
+			}
409
+		}
410
+
411
+		return $backup_files;
412
+	}
413
+
414
+	public function start_file_recursion($init = 0)
415
+	{
416
+		if ($init) {
417
+			$this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"),
418
+				$this->xcloner_settings->get_xcloner_start_path()));
419
+			$this->do_system_init();
420
+		}
421
+
422
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
423
+			//.dir exists, we presume we have files to iterate
424
+			$content = $this->tmp_filesystem->read($this->get_temp_dir_handler());
425
+			$files = array_filter(explode("\n", $content));
426
+			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
427
+
428
+			$counter = 0;
429
+			foreach ($files as $file) {
430
+				if ($counter < $this->folders_to_process_per_session) {
431
+					$this->build_files_list($file);
432
+					$counter++;
433
+				} else {
434
+					$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file . "\n");
435
+				}
436
+			}
437
+		} else {
438
+			$this->build_files_list();
439
+		}
440
+
441
+		if ($this->scan_finished()) {
442
+			$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html");
443
+			$this->store_file($metadata_dumpfile, 'tmp_filesystem');
444
+			$this->files_counter++;
445
+
446
+			//adding included dump file to the included files list
447
+			if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) {
448
+				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler());
449
+				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
450
+				$this->files_counter++;
451
+			}
452
+
453
+			//adding a default index.html to the temp xcloner folder
454
+			if (!$this->get_tmp_filesystem()->has("index.html")) {
455
+				$this->get_tmp_filesystem()->write("index.html", "");
456
+			}
457
+
458
+			//adding the default log file
459
+			if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) {
460
+				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1));
461
+				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
462
+				$this->files_counter++;
463
+			}
464
+
465
+			return false;
466
+		}
467
+
468
+		return true;
469
+	}
470
+
471
+	public function get_backup_attachments()
472
+	{
473
+		$return = array();
474
+
475
+		$files_list_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->get_included_files_handler();
476
+		if (file_exists($files_list_file)) {
477
+			$return[] = $files_list_file;
478
+		}
479
+
480
+		if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
481
+			$log_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->xcloner_settings->get_logger_filename(1);
482
+			if (!file_exists($log_file)) {
483
+				$log_file = $this->xcloner_settings->get_xcloner_store_path() . DS . $this->xcloner_settings->get_logger_filename();
484
+			}
485
+
486
+			if (file_exists($log_file)) {
487
+				$return[] = $log_file;
488
+			}
489
+		}
490
+
491
+		return $return;
492
+	}
493
+
494
+	public function remove_tmp_filesystem()
495
+	{
496
+		//delete the temporary folder
497
+		$this->logger->debug(sprintf("Deleting the temporary storage folder %s",
498
+			$this->xcloner_settings->get_xcloner_tmp_path()));
499
+
500
+		$contents = $this->get_tmp_filesystem()->listContents();
501
+
502
+		if (is_array($contents)) {
503
+			foreach ($contents as $file_info) {
504
+				$this->get_tmp_filesystem()->delete($file_info['path']);
505
+			}
506
+		}
507
+
508
+		@rmdir($this->xcloner_settings->get_xcloner_tmp_path());
509
+
510
+		return;
511
+	}
512
+
513
+	public function cleanup_tmp_directories()
514
+	{
515
+		$adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
516
+		$tmp_filesystem = new Filesystem($adapter, new Config([
517
+			'disable_asserts' => true,
518
+		]));
519
+
520
+		$contents = $tmp_filesystem->listContents();
521
+
522
+		foreach ($contents as $file) {
523
+
524
+			if (preg_match("/.xcloner-(.*)/", $file['path'])) {
525
+				if ($file['timestamp'] < strtotime("-1days")) {
526
+					$tmp_filesystem->deleteDir($file['path']);
527
+					$this->logger->debug(sprintf("Delete temporary directory %s", $file['path']));
528
+				}
529
+			}
530
+		}
531
+
532
+		return true;
533
+	}
534
+
535
+	private function do_system_init()
536
+	{
537
+		$this->files_counter = 0;
538
+
539
+		if (!$this->storage_filesystem->has("index.html")) {
540
+			$this->storage_filesystem->write("index.html", "");
541
+		}
542
+
543
+		if (!$this->tmp_filesystem->has("index.html")) {
544
+			$this->tmp_filesystem->write("index.html", "");
545
+		}
546
+
547
+		if ($this->tmp_filesystem->has($this->get_included_files_handler())) {
548
+			$this->tmp_filesystem->delete($this->get_included_files_handler());
549
+		}
550
+
551
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
552
+			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
553
+		}
554
+	}
555
+
556
+	public function get_scanned_files_num()
557
+	{
558
+		return $this->files_counter;
559
+	}
560
+
561
+	public function get_scanned_files_total_size()
562
+	{
563
+		return $this->files_size;
564
+	}
565
+
566
+	public function last_logged_file()
567
+	{
568
+		return $this->last_logged_file;
569
+	}
570
+
571
+	public static function is_regex($regex)
572
+	{
573
+		return preg_match("/^\^(.*)\$$/i", $regex);
574
+	}
575 575
 
576
-    public function set_excluded_files($excluded_files = array())
577
-    {
578
-        if (!is_array($excluded_files)) {
579
-            $excluded_files = array();
580
-        }
576
+	public function set_excluded_files($excluded_files = array())
577
+	{
578
+		if (!is_array($excluded_files)) {
579
+			$excluded_files = array();
580
+		}
581 581
 
582
-        foreach ($excluded_files as $excl) {
582
+		foreach ($excluded_files as $excl) {
583 583
 
584
-            if ($this->is_regex($excl)) {
585
-                $this->additional_regex_patterns[] = $excl;
586
-            }
587
-        }
584
+			if ($this->is_regex($excl)) {
585
+				$this->additional_regex_patterns[] = $excl;
586
+			}
587
+		}
588 588
 
589
-        $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
589
+		$this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
590 590
 
591
-        return $this->excluded_files;
592
-    }
591
+		return $this->excluded_files;
592
+	}
593 593
 
594
-    public function get_excluded_files()
595
-    {
596
-        return $this->excluded_files_by_default;
597
-    }
594
+	public function get_excluded_files()
595
+	{
596
+		return $this->excluded_files_by_default;
597
+	}
598 598
 
599
-    public function list_directory($path)
600
-    {
601
-        return $this->start_filesystem->listContents($path);
602
-    }
599
+	public function list_directory($path)
600
+	{
601
+		return $this->start_filesystem->listContents($path);
602
+	}
603 603
 
604
-    public function build_files_list($folder = "")
605
-    {
606
-        $this->logger->debug(sprintf(("Building the files system list")));
604
+	public function build_files_list($folder = "")
605
+	{
606
+		$this->logger->debug(sprintf(("Building the files system list")));
607 607
 
608
-        //if we start with the root folder(empty value), we initializa the file system
609
-        if (!$folder) {
608
+		//if we start with the root folder(empty value), we initializa the file system
609
+		if (!$folder) {
610 610
 
611
-        }
611
+		}
612 612
 
613
-        try {
613
+		try {
614 614
 
615
-            $files = $this->start_filesystem->listContents($folder);
616
-            foreach ($files as $file) {
617
-                if (!is_readable($this->xcloner_settings->get_xcloner_start_path() . DS . $file['path'])) {
618
-                    $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"),
619
-                        $file['path']), array(
620
-                        "FILESYSTEM SCAN",
621
-                        "NOT READABLE"
622
-                    ));
623
-                } elseif (!$matching_pattern = $this->is_excluded($file)) {
624
-                    $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array(
625
-                        "FILESYSTEM SCAN",
626
-                        "INCLUDE"
627
-                    ));
628
-                    $file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
629
-                    if ($this->store_file($file)) {
630
-                        $this->files_counter++;
631
-                    }
632
-                    if (isset($file['size'])) {
633
-                        $this->files_size += $file['size'];
634
-                    }
635
-
636
-                } else {
637
-                    $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"),
638
-                        $file['path'], $matching_pattern), array(
639
-                        "FILESYSTEM SCAN",
640
-                        "EXCLUDE"
641
-                    ));
642
-                }
643
-            }
615
+			$files = $this->start_filesystem->listContents($folder);
616
+			foreach ($files as $file) {
617
+				if (!is_readable($this->xcloner_settings->get_xcloner_start_path() . DS . $file['path'])) {
618
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"),
619
+						$file['path']), array(
620
+						"FILESYSTEM SCAN",
621
+						"NOT READABLE"
622
+					));
623
+				} elseif (!$matching_pattern = $this->is_excluded($file)) {
624
+					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array(
625
+						"FILESYSTEM SCAN",
626
+						"INCLUDE"
627
+					));
628
+					$file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
629
+					if ($this->store_file($file)) {
630
+						$this->files_counter++;
631
+					}
632
+					if (isset($file['size'])) {
633
+						$this->files_size += $file['size'];
634
+					}
635
+
636
+				} else {
637
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"),
638
+						$file['path'], $matching_pattern), array(
639
+						"FILESYSTEM SCAN",
640
+						"EXCLUDE"
641
+					));
642
+				}
643
+			}
644 644
 
645
-        } catch (Exception $e) {
645
+		} catch (Exception $e) {
646 646
 
647
-            $this->logger->error($e->getMessage());
647
+			$this->logger->error($e->getMessage());
648 648
 
649
-        }
649
+		}
650 650
 
651
-    }
651
+	}
652 652
 
653
-    public function estimate_read_write_time()
654
-    {
655
-        $tmp_file = ".xcloner" . substr(md5(time()), 0, 5);
653
+	public function estimate_read_write_time()
654
+	{
655
+		$tmp_file = ".xcloner" . substr(md5(time()), 0, 5);
656 656
 
657
-        $start_time = microtime(true);
657
+		$start_time = microtime(true);
658 658
 
659
-        $data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data
659
+		$data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data
660 660
 
661
-        try {
662
-            $this->tmp_filesystem->write($tmp_file, $data);
661
+		try {
662
+			$this->tmp_filesystem->write($tmp_file, $data);
663 663
 
664
-            $end_time = microtime(true) - $start_time;
664
+			$end_time = microtime(true) - $start_time;
665 665
 
666
-            $return['writing_time'] = $end_time;
666
+			$return['writing_time'] = $end_time;
667 667
 
668
-            $return['reading_time'] = $this->estimate_reading_time($tmp_file);
668
+			$return['reading_time'] = $this->estimate_reading_time($tmp_file);
669 669
 
670
-            $this->tmp_filesystem->delete($tmp_file);
670
+			$this->tmp_filesystem->delete($tmp_file);
671 671
 
672
-        } catch (Exception $e) {
672
+		} catch (Exception $e) {
673 673
 
674
-            $this->logger->error($e->getMessage());
674
+			$this->logger->error($e->getMessage());
675 675
 
676
-        }
676
+		}
677 677
 
678
-        return $return;
679
-    }
678
+		return $return;
679
+	}
680 680
 
681
-    public function backup_storage_cleanup()
682
-    {
683
-        $this->logger->info(sprintf(("Cleaning the backup storage on matching rules")));
681
+	public function backup_storage_cleanup()
682
+	{
683
+		$this->logger->info(sprintf(("Cleaning the backup storage on matching rules")));
684 684
 
685
-        $_storage_size = 0;
686
-        $_backup_files_list = array();
685
+		$_storage_size = 0;
686
+		$_backup_files_list = array();
687 687
 
688
-        //rule date limit
689
-        $current_timestamp = strtotime("-" . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') . " days");
688
+		//rule date limit
689
+		$current_timestamp = strtotime("-" . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') . " days");
690 690
 
691
-        $files = $this->storage_filesystem->listContents();
691
+		$files = $this->storage_filesystem->listContents();
692 692
 
693
-        if (is_array($files)) {
694
-            foreach ($files as $file) {
695
-                if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) {
696
-                    $_storage_size += $file['size']; //bytes
697
-                    $_backup_files_list[] = $file;
698
-                }
699
-            }
700
-        }
693
+		if (is_array($files)) {
694
+			foreach ($files as $file) {
695
+				if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) {
696
+					$_storage_size += $file['size']; //bytes
697
+					$_backup_files_list[] = $file;
698
+				}
699
+			}
700
+		}
701 701
 
702 702
 
703
-        $this->sort_by($_backup_files_list, "timestamp", "asc");
703
+		$this->sort_by($_backup_files_list, "timestamp", "asc");
704 704
 
705
-        $_backups_counter = sizeof($_backup_files_list);
705
+		$_backups_counter = sizeof($_backup_files_list);
706 706
 
707
-        foreach ($_backup_files_list as $file) {
708
-            //processing rule folder capacity
709
-            if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
710
-                $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))    //bytes
711
-            {
712
-                $this->storage_filesystem->delete($file['path']);
713
-                $_storage_size -= $file['size'];
714
-                $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
715
-                    "STORAGE SIZE LIMIT",
716
-                    $_storage_size . " >= " . $set_storage_limit
717
-                ));
718
-            }
719
-
720
-            //processing rule days limit
721
-            if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) {
722
-                $this->storage_filesystem->delete($file['path']);
723
-                $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
724
-                    "RETENTION LIMIT TIMESTAMP",
725
-                    $file['timestamp'] . " =< " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')
726
-                ));
727
-            }
728
-
729
-            //processing backup countert limit
730
-            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')) {
731
-                $this->storage_filesystem->delete($file['path']);
732
-                $_backups_counter--;
733
-                $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
734
-                    "BACKUP QUANTITY LIMIT",
735
-                    $_backups_counter . " >= " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')
736
-                ));
737
-            }
707
+		foreach ($_backup_files_list as $file) {
708
+			//processing rule folder capacity
709
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
710
+				$_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))    //bytes
711
+			{
712
+				$this->storage_filesystem->delete($file['path']);
713
+				$_storage_size -= $file['size'];
714
+				$this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
715
+					"STORAGE SIZE LIMIT",
716
+					$_storage_size . " >= " . $set_storage_limit
717
+				));
718
+			}
719
+
720
+			//processing rule days limit
721
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) {
722
+				$this->storage_filesystem->delete($file['path']);
723
+				$this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
724
+					"RETENTION LIMIT TIMESTAMP",
725
+					$file['timestamp'] . " =< " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')
726
+				));
727
+			}
728
+
729
+			//processing backup countert limit
730
+			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')) {
731
+				$this->storage_filesystem->delete($file['path']);
732
+				$_backups_counter--;
733
+				$this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
734
+					"BACKUP QUANTITY LIMIT",
735
+					$_backups_counter . " >= " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')
736
+				));
737
+			}
738 738
 
739 739
 
740
-        }
740
+		}
741 741
 
742
-    }
742
+	}
743 743
 
744
-    public function estimate_reading_time($tmp_file)
745
-    {
746
-        $this->logger->debug(sprintf(("Estimating file system reading time")));
744
+	public function estimate_reading_time($tmp_file)
745
+	{
746
+		$this->logger->debug(sprintf(("Estimating file system reading time")));
747 747
 
748
-        $start_time = microtime(true);
748
+		$start_time = microtime(true);
749 749
 
750
-        if ($this->tmp_filesystem->has($tmp_file)) {
751
-            $this->tmp_filesystem->read($tmp_file);
752
-        }
753
-
754
-        $end_time = microtime(true) - $start_time;
755
-
756
-        return $end_time;
757
-
758
-    }
759
-
760
-    public function process_backup_name($name = "", $max_length = 100)
761
-    {
762
-        if (!$name) {
763
-            $name = $this->xcloner_settings->get_default_backup_name();
764
-        }
765
-
766
-        foreach ($this->backup_name_tags as $tag) {
767
-            if ($tag == '[time]') {
768
-                $name = str_replace($tag, date("Y-m-d_H-i"), $name);
769
-            } elseif ($tag == '[hostname]') {
770
-                $name = str_replace($tag, gethostname(), $name);
771
-            } elseif ($tag == '[domain]') {
772
-                $domain = parse_url(admin_url(), PHP_URL_HOST);
773
-                $name = str_replace($tag, $domain, $name);
774
-            }
775
-        }
776
-
777
-        if ($max_length) {
778
-            $name = substr($name, 0, $max_length);
779
-        }
780
-
781
-        return $name;
782
-    }
783
-
784
-    public function sort_by(&$array, $field, $direction = 'asc')
785
-    {
786
-        if (strtolower($direction) == "desc" || $direction == SORT_DESC) {
787
-            $direction = SORT_DESC;
788
-        } else {
789
-            $direction = SORT_ASC;
790
-        }
791
-
792
-        $array = $this->array_orderby($array, $field, $direction);
793
-
794
-        return true;
795
-    }
796
-
797
-    private function array_orderby()
798
-    {
799
-        $args = func_get_args();
800
-        $data = array_shift($args);
801
-
802
-        foreach ($args as $n => $field) {
803
-            if (is_string($field)) {
804
-                $tmp = array();
805
-                foreach ($data as $key => $row) {
806
-                    if (is_array($row)) {
807
-                        $tmp[$key] = $row[$field];
808
-                    } else {
809
-                        $tmp[$key] = $row->$field;
810
-                    }
811
-                }
812
-                $args[$n] = $tmp;
813
-            }
814
-        }
815
-        $args[] = &$data;
816
-
817
-        call_user_func_array('array_multisort', $args);
818
-
819
-        return array_pop($args);
820
-    }
821
-
822
-    private function check_file_diff_time($file)
823
-    {
824
-        if ($this->get_diff_timestamp_start() != "") {
825
-            $fileMeta = $this->getMetadataFull("start_adapter", $file['path']);
826
-            $timestamp = $fileMeta->getMTime();
827
-            if ($timestamp < $fileMeta->getCTime()) {
828
-                $timestamp = $fileMeta->getCTime();
829
-            }
830
-
831
-            if ($timestamp <= $this->get_diff_timestamp_start()) {
832
-                return " file DIFF timestamp " . $timestamp . " < " . $this->diff_timestamp_start;
833
-            }
834
-        }
835
-
836
-        return false;
837
-    }
838
-
839
-    public function is_excluded($file)
840
-    {
841
-        $this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
842
-
843
-        if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) {
844
-            if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) {
845
-                return "> " . $xcloner_exclude_files_larger_than_mb . "MB";
846
-            }
847
-        }
848
-
849
-        if (!is_array($this->excluded_files) || !sizeof($this->excluded_files)) {
850
-            $this->set_excluded_files();
851
-        }
852
-
853
-        if (is_array($this->excluded_files)) {
854
-            foreach ($this->excluded_files as $excluded_file_pattern) {
855
-                if ($excluded_file_pattern == "/") {
856
-                    $needle = "$";
857
-                } else {
858
-                    $needle = "$" . $excluded_file_pattern;
859
-                }
860
-
861
-                if (strstr("$" . $file['path'], $needle)) {
862
-                    return $excluded_file_pattern;
863
-                }
864
-            }
865
-        }
866
-
867
-        if ($regex = $this->is_excluded_regex($file)) {
868
-            return $regex;
869
-        }
870
-
871
-        if ($file['type'] == "file") {
872
-            $check_file_diff_timestamp = $this->check_file_diff_time($file);
873
-            if ($check_file_diff_timestamp) {
874
-                return $check_file_diff_timestamp;
875
-            }
876
-        }
877
-
878
-        return false;
879
-    }
880
-
881
-    /*REGEX examples
750
+		if ($this->tmp_filesystem->has($tmp_file)) {
751
+			$this->tmp_filesystem->read($tmp_file);
752
+		}
753
+
754
+		$end_time = microtime(true) - $start_time;
755
+
756
+		return $end_time;
757
+
758
+	}
759
+
760
+	public function process_backup_name($name = "", $max_length = 100)
761
+	{
762
+		if (!$name) {
763
+			$name = $this->xcloner_settings->get_default_backup_name();
764
+		}
765
+
766
+		foreach ($this->backup_name_tags as $tag) {
767
+			if ($tag == '[time]') {
768
+				$name = str_replace($tag, date("Y-m-d_H-i"), $name);
769
+			} elseif ($tag == '[hostname]') {
770
+				$name = str_replace($tag, gethostname(), $name);
771
+			} elseif ($tag == '[domain]') {
772
+				$domain = parse_url(admin_url(), PHP_URL_HOST);
773
+				$name = str_replace($tag, $domain, $name);
774
+			}
775
+		}
776
+
777
+		if ($max_length) {
778
+			$name = substr($name, 0, $max_length);
779
+		}
780
+
781
+		return $name;
782
+	}
783
+
784
+	public function sort_by(&$array, $field, $direction = 'asc')
785
+	{
786
+		if (strtolower($direction) == "desc" || $direction == SORT_DESC) {
787
+			$direction = SORT_DESC;
788
+		} else {
789
+			$direction = SORT_ASC;
790
+		}
791
+
792
+		$array = $this->array_orderby($array, $field, $direction);
793
+
794
+		return true;
795
+	}
796
+
797
+	private function array_orderby()
798
+	{
799
+		$args = func_get_args();
800
+		$data = array_shift($args);
801
+
802
+		foreach ($args as $n => $field) {
803
+			if (is_string($field)) {
804
+				$tmp = array();
805
+				foreach ($data as $key => $row) {
806
+					if (is_array($row)) {
807
+						$tmp[$key] = $row[$field];
808
+					} else {
809
+						$tmp[$key] = $row->$field;
810
+					}
811
+				}
812
+				$args[$n] = $tmp;
813
+			}
814
+		}
815
+		$args[] = &$data;
816
+
817
+		call_user_func_array('array_multisort', $args);
818
+
819
+		return array_pop($args);
820
+	}
821
+
822
+	private function check_file_diff_time($file)
823
+	{
824
+		if ($this->get_diff_timestamp_start() != "") {
825
+			$fileMeta = $this->getMetadataFull("start_adapter", $file['path']);
826
+			$timestamp = $fileMeta->getMTime();
827
+			if ($timestamp < $fileMeta->getCTime()) {
828
+				$timestamp = $fileMeta->getCTime();
829
+			}
830
+
831
+			if ($timestamp <= $this->get_diff_timestamp_start()) {
832
+				return " file DIFF timestamp " . $timestamp . " < " . $this->diff_timestamp_start;
833
+			}
834
+		}
835
+
836
+		return false;
837
+	}
838
+
839
+	public function is_excluded($file)
840
+	{
841
+		$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
842
+
843
+		if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) {
844
+			if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) {
845
+				return "> " . $xcloner_exclude_files_larger_than_mb . "MB";
846
+			}
847
+		}
848
+
849
+		if (!is_array($this->excluded_files) || !sizeof($this->excluded_files)) {
850
+			$this->set_excluded_files();
851
+		}
852
+
853
+		if (is_array($this->excluded_files)) {
854
+			foreach ($this->excluded_files as $excluded_file_pattern) {
855
+				if ($excluded_file_pattern == "/") {
856
+					$needle = "$";
857
+				} else {
858
+					$needle = "$" . $excluded_file_pattern;
859
+				}
860
+
861
+				if (strstr("$" . $file['path'], $needle)) {
862
+					return $excluded_file_pattern;
863
+				}
864
+			}
865
+		}
866
+
867
+		if ($regex = $this->is_excluded_regex($file)) {
868
+			return $regex;
869
+		}
870
+
871
+		if ($file['type'] == "file") {
872
+			$check_file_diff_timestamp = $this->check_file_diff_time($file);
873
+			if ($check_file_diff_timestamp) {
874
+				return $check_file_diff_timestamp;
875
+			}
876
+		}
877
+
878
+		return false;
879
+	}
880
+
881
+	/*REGEX examples
882 882
      *
883 883
     * exclude all except .php file
884 884
     * PATTERN: ^(.*)\.(.+)$(?<!(php))
@@ -910,163 +910,163 @@  discard block
 block discarded – undo
910 910
     * exclude the backup folders
911 911
     * PATTERN: (^|^\/)(wp-content\/backups|administrator\/backups)(.*)$";
912 912
     */
913
-    private function is_excluded_regex($file)
914
-    {
915
-        //$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
916
-
917
-        $regex_patterns = explode(PHP_EOL, $this->xcloner_settings->get_xcloner_option('xcloner_regex_exclude'));
918
-
919
-        if (is_array($this->additional_regex_patterns)) {
920
-            $regex_patterns = array_merge($regex_patterns, $this->additional_regex_patterns);
921
-        }
922
-
923
-        //print_r($regex_patterns);exit;
924
-
925
-        if (is_array($regex_patterns)) {
926
-            //$this->excluded_files = array();
927
-            //$this->excluded_files[] ="(.*)\.(git)(.*)$";
928
-            //$this->excluded_files[] ="wp-content\/backups(.*)$";
929
-
930
-            foreach ($regex_patterns as $excluded_file_pattern) {
931
-
932
-                if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1,
933
-                        strlen($excluded_file_pattern)) == "\r") {
934
-                    $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1);
935
-                }
936
-
937
-                if ($file['path'] == "/") {
938
-                    $needle = "/";
939
-                } else {
940
-                    $needle = "/" . $file['path'];
941
-                }
942
-                //echo $needle."---".$excluded_file_pattern."---\n";
943
-
944
-                if (@preg_match("/(^|^\/)" . $excluded_file_pattern . "/i", $needle)) {
945
-                    return $excluded_file_pattern;
946
-                }
947
-            }
948
-        }
949
-
950
-        return false;
951
-    }
952
-
953
-    public function store_file($file, $storage = 'start_filesystem')
954
-    {
955
-        $this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
956
-
957
-        if (!isset($file['size'])) {
958
-            $file['size'] = 0;
959
-        }
960
-        if (!isset($file['visibility'])) {
961
-            $file['visibility'] = "private";
962
-        }
963
-
964
-        $csv_filename = str_replace('"', '""', $file['path']);
965
-
966
-        $line = '"' . ($csv_filename) . '","' . $file['timestamp'] . '","' . $file['size'] . '","' . $file['visibility'] . '","' . $storage . '"' . PHP_EOL;
967
-
968
-        $this->last_logged_file = $file['path'];
969
-
970
-        if ($file['type'] == "dir") {
971
-            try {
972
-                $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path'] . "\n");
973
-            } catch (Exception $e) {
974
-                $this->logger->error($e->getMessage());
975
-            }
976
-        }
977
-
978
-        if ($this->get_diff_timestamp_start()) {
979
-            if ($file['type'] != "file" && $response = $this->check_file_diff_time($file)) {
980
-                $this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'],
981
-                    $response), array(
982
-                    "FILESYSTEM SCAN",
983
-                    "DIR DIFF"
984
-                ));
985
-
986
-                return false;
987
-            }
988
-        }
989
-
990
-        try {
991
-            if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) {
992
-                //adding fix for UTF-8 CSV preview
993
-                $start_line = "\xEF\xBB\xBF" . '"Filename","Timestamp","Size","Visibility","Storage"' . PHP_EOL;
994
-                $this->tmp_filesystem_append->write($this->get_included_files_handler(), $start_line);
995
-            }
996
-
997
-            $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
998
-
999
-        } catch (Exception $e) {
1000
-
1001
-            $this->logger->error($e->getMessage());
1002
-        }
1003
-
1004
-        return true;
1005
-    }
1006
-
1007
-    public function get_fileystem_handler()
1008
-    {
1009
-        return $this;
1010
-    }
1011
-
1012
-    public function get_filesystem($system = "")
1013
-    {
1014
-        if ($system == "storage_filesystem_append") {
1015
-            return $this->storage_filesystem_append;
1016
-        } elseif ($system == "tmp_filesystem_append") {
1017
-            return $this->tmp_filesystem_append;
1018
-        } elseif ($system == "tmp_filesystem") {
1019
-            return $this->tmp_filesystem;
1020
-        } elseif ($system == "storage_filesystem") {
1021
-            return $this->storage_filesystem;
1022
-        } else {
1023
-            return $this->start_filesystem;
1024
-        }
1025
-    }
1026
-
1027
-    public function get_adapter($system)
1028
-    {
1029
-        if ($system == "tmp_filesystem") {
1030
-            return $this->tmp_adapter;
1031
-        } elseif ($system == "storage_filesystem") {
1032
-            return $this->storage_adapter;
1033
-        } else {
1034
-            return $this->start_adapter;
1035
-        }
1036
-    }
1037
-
1038
-    /**
1039
-     * File scan finished
1040
-     * Method called when file scan is finished
1041
-     *
1042
-     * @return bool
1043
-     */
1044
-    private function scan_finished()
1045
-    {
1046
-        if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) &&
1047
-            $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) {
1048
-            return false;
1049
-        }
1050
-
1051
-        if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
1052
-            $this->tmp_filesystem->delete($this->get_temp_dir_handler());
1053
-        }
1054
-
1055
-        $this->logger->debug(sprintf(("File scan finished")));
1056
-
1057
-        return true;
1058
-    }
1059
-
1060
-    /**
1061
-     * Calculate bytes from MB value
1062
-     *
1063
-     * @param int $mb_size
1064
-     *
1065
-     * @return float|int
1066
-     */
1067
-    private function calc_to_bytes($mb_size)
1068
-    {
1069
-        return $mb_size * (1024 * 1024);
1070
-    }
913
+	private function is_excluded_regex($file)
914
+	{
915
+		//$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
916
+
917
+		$regex_patterns = explode(PHP_EOL, $this->xcloner_settings->get_xcloner_option('xcloner_regex_exclude'));
918
+
919
+		if (is_array($this->additional_regex_patterns)) {
920
+			$regex_patterns = array_merge($regex_patterns, $this->additional_regex_patterns);
921
+		}
922
+
923
+		//print_r($regex_patterns);exit;
924
+
925
+		if (is_array($regex_patterns)) {
926
+			//$this->excluded_files = array();
927
+			//$this->excluded_files[] ="(.*)\.(git)(.*)$";
928
+			//$this->excluded_files[] ="wp-content\/backups(.*)$";
929
+
930
+			foreach ($regex_patterns as $excluded_file_pattern) {
931
+
932
+				if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1,
933
+						strlen($excluded_file_pattern)) == "\r") {
934
+					$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1);
935
+				}
936
+
937
+				if ($file['path'] == "/") {
938
+					$needle = "/";
939
+				} else {
940
+					$needle = "/" . $file['path'];
941
+				}
942
+				//echo $needle."---".$excluded_file_pattern."---\n";
943
+
944
+				if (@preg_match("/(^|^\/)" . $excluded_file_pattern . "/i", $needle)) {
945
+					return $excluded_file_pattern;
946
+				}
947
+			}
948
+		}
949
+
950
+		return false;
951
+	}
952
+
953
+	public function store_file($file, $storage = 'start_filesystem')
954
+	{
955
+		$this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
956
+
957
+		if (!isset($file['size'])) {
958
+			$file['size'] = 0;
959
+		}
960
+		if (!isset($file['visibility'])) {
961
+			$file['visibility'] = "private";
962
+		}
963
+
964
+		$csv_filename = str_replace('"', '""', $file['path']);
965
+
966
+		$line = '"' . ($csv_filename) . '","' . $file['timestamp'] . '","' . $file['size'] . '","' . $file['visibility'] . '","' . $storage . '"' . PHP_EOL;
967
+
968
+		$this->last_logged_file = $file['path'];
969
+
970
+		if ($file['type'] == "dir") {
971
+			try {
972
+				$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path'] . "\n");
973
+			} catch (Exception $e) {
974
+				$this->logger->error($e->getMessage());
975
+			}
976
+		}
977
+
978
+		if ($this->get_diff_timestamp_start()) {
979
+			if ($file['type'] != "file" && $response = $this->check_file_diff_time($file)) {
980
+				$this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'],
981
+					$response), array(
982
+					"FILESYSTEM SCAN",
983
+					"DIR DIFF"
984
+				));
985
+
986
+				return false;
987
+			}
988
+		}
989
+
990
+		try {
991
+			if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) {
992
+				//adding fix for UTF-8 CSV preview
993
+				$start_line = "\xEF\xBB\xBF" . '"Filename","Timestamp","Size","Visibility","Storage"' . PHP_EOL;
994
+				$this->tmp_filesystem_append->write($this->get_included_files_handler(), $start_line);
995
+			}
996
+
997
+			$this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
998
+
999
+		} catch (Exception $e) {
1000
+
1001
+			$this->logger->error($e->getMessage());
1002
+		}
1003
+
1004
+		return true;
1005
+	}
1006
+
1007
+	public function get_fileystem_handler()
1008
+	{
1009
+		return $this;
1010
+	}
1011
+
1012
+	public function get_filesystem($system = "")
1013
+	{
1014
+		if ($system == "storage_filesystem_append") {
1015
+			return $this->storage_filesystem_append;
1016
+		} elseif ($system == "tmp_filesystem_append") {
1017
+			return $this->tmp_filesystem_append;
1018
+		} elseif ($system == "tmp_filesystem") {
1019
+			return $this->tmp_filesystem;
1020
+		} elseif ($system == "storage_filesystem") {
1021
+			return $this->storage_filesystem;
1022
+		} else {
1023
+			return $this->start_filesystem;
1024
+		}
1025
+	}
1026
+
1027
+	public function get_adapter($system)
1028
+	{
1029
+		if ($system == "tmp_filesystem") {
1030
+			return $this->tmp_adapter;
1031
+		} elseif ($system == "storage_filesystem") {
1032
+			return $this->storage_adapter;
1033
+		} else {
1034
+			return $this->start_adapter;
1035
+		}
1036
+	}
1037
+
1038
+	/**
1039
+	 * File scan finished
1040
+	 * Method called when file scan is finished
1041
+	 *
1042
+	 * @return bool
1043
+	 */
1044
+	private function scan_finished()
1045
+	{
1046
+		if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) &&
1047
+			$this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) {
1048
+			return false;
1049
+		}
1050
+
1051
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
1052
+			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
1053
+		}
1054
+
1055
+		$this->logger->debug(sprintf(("File scan finished")));
1056
+
1057
+		return true;
1058
+	}
1059
+
1060
+	/**
1061
+	 * Calculate bytes from MB value
1062
+	 *
1063
+	 * @param int $mb_size
1064
+	 *
1065
+	 * @return float|int
1066
+	 */
1067
+	private function calc_to_bytes($mb_size)
1068
+	{
1069
+		return $mb_size * (1024 * 1024);
1070
+	}
1071 1071
 
1072 1072
 }
Please login to merge, or discard this patch.
includes/class-xcloner-loader.php 1 patch
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -41,154 +41,154 @@
 block discarded – undo
41 41
 class Xcloner_Loader
42 42
 {
43 43
 
44
-    /**
45
-     * The array of actions registered with WordPress.
46
-     *
47
-     * @since    1.0.0
48
-     * @access   protected
49
-     * @var      array $actions The actions registered with WordPress to fire when the plugin loads.
50
-     */
51
-    protected $actions;
52
-
53
-    /**
54
-     * The array of filters registered with WordPress.
55
-     *
56
-     * @since    1.0.0
57
-     * @access   protected
58
-     * @var      array $filters The filters registered with WordPress to fire when the plugin loads.
59
-     */
60
-    protected $filters;
61
-
62
-    private $xcloner_plugin;
63
-
64
-    /**
65
-     * Initialize the collections used to maintain the actions and filters.
66
-     *
67
-     * @since    1.0.0
68
-     */
69
-    public function __construct(Xcloner $xcloner_container)
70
-    {
71
-
72
-        $this->actions = array();
73
-        $this->filters = array();
74
-
75
-        $this->xcloner_container = $xcloner_container;
76
-
77
-    }
78
-
79
-    public function xcloner_backup_add_admin_menu()
80
-    {
81
-        if (function_exists('add_menu_page')) {
82
-            add_menu_page(__('Site Backup', 'xcloner-backup-and-restore'),
83
-                __('Site Backup', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_init_page',
84
-                array($this->xcloner_container, 'xcloner_display'), 'dashicons-backup');
85
-        }
86
-
87
-        if (function_exists('add_submenu_page')) {
88
-
89
-            add_submenu_page('xcloner_init_page', __('XCloner Dashboard', 'xcloner-backup-and-restore'),
90
-                __('Dashboard', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_init_page',
91
-                array($this->xcloner_container, 'xcloner_display'));
92
-            add_submenu_page('xcloner_init_page', __('XCloner Backup Settings', 'xcloner-backup-and-restore'),
93
-                __('Settings', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_settings_page',
94
-                array($this->xcloner_container, 'xcloner_display'));
95
-            add_submenu_page('xcloner_init_page', __('Remote Storage Settings', 'xcloner-backup-and-restore'),
96
-                __('Remote Storage', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_remote_storage_page',
97
-                array($this->xcloner_container, 'xcloner_display'));
98
-            add_submenu_page('xcloner_init_page', __('Manage Backups', 'xcloner-backup-and-restore'),
99
-                __('Manage Backups', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_manage_backups_page',
100
-                array($this->xcloner_container, 'xcloner_display'));
101
-            add_submenu_page('xcloner_init_page', __('Scheduled Backups', 'xcloner-backup-and-restore'),
102
-                __('Scheduled Backups', 'xcloner-backup-and-restore'), 'manage_options',
103
-                'xcloner_scheduled_backups_page', array($this->xcloner_container, 'xcloner_display'));
104
-            add_submenu_page('xcloner_init_page', __('Generate Backups', 'xcloner-backup-and-restore'),
105
-                __('Generate Backups', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_generate_backups_page',
106
-                array($this->xcloner_container, 'xcloner_display'));
107
-            add_submenu_page('xcloner_init_page', __('Restore Backups', 'xcloner-backup-and-restore'),
108
-                __('Restore Backups', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_restore_page',
109
-                array($this->xcloner_container, 'xcloner_display'));
110
-        }
111
-
112
-    }
113
-
114
-
115
-    /**
116
-     * Add a new action to the collection to be registered with WordPress.
117
-     *
118
-     * @since    1.0.0
119
-     * @param    string $hook The name of the WordPress action that is being registered.
120
-     * @param    object $component A reference to the instance of the object on which the action is defined.
121
-     * @param    string $callback The name of the function definition on the $component.
122
-     * @param    int $priority Optional. he priority at which the function should be fired. Default is 10.
123
-     * @param    int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
124
-     */
125
-    public function add_action($hook, $component, $callback, $priority = 10, $accepted_args = 1)
126
-    {
127
-        $this->actions = $this->add($this->actions, $hook, $component, $callback, $priority, $accepted_args);
128
-    }
129
-
130
-    /**
131
-     * Add a new filter to the collection to be registered with WordPress.
132
-     *
133
-     * @since    1.0.0
134
-     * @param    string $hook The name of the WordPress filter that is being registered.
135
-     * @param    object $component A reference to the instance of the object on which the filter is defined.
136
-     * @param    string $callback The name of the function definition on the $component.
137
-     * @param    int $priority Optional. he priority at which the function should be fired. Default is 10.
138
-     * @param    int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
139
-     */
140
-    public function add_filter($hook, $component, $callback, $priority = 10, $accepted_args = 1)
141
-    {
142
-        $this->filters = $this->add($this->filters, $hook, $component, $callback, $priority, $accepted_args);
143
-    }
144
-
145
-    /**
146
-     * A utility function that is used to register the actions and hooks into a single
147
-     * collection.
148
-     *
149
-     * @since    1.0.0
150
-     * @access   private
151
-     * @param    array $hooks The collection of hooks that is being registered (that is, actions or filters).
152
-     * @param    string $hook The name of the WordPress filter that is being registered.
153
-     * @param    object $component A reference to the instance of the object on which the filter is defined.
154
-     * @param    string $callback The name of the function definition on the $component.
155
-     * @param    int $priority The priority at which the function should be fired.
156
-     * @param    int $accepted_args The number of arguments that should be passed to the $callback.
157
-     * @return   array                                  The collection of actions and filters registered with WordPress.
158
-     */
159
-    private function add($hooks, $hook, $component, $callback, $priority, $accepted_args)
160
-    {
161
-
162
-        $hooks[] = array(
163
-            'hook' => $hook,
164
-            'component' => $component,
165
-            'callback' => $callback,
166
-            'priority' => $priority,
167
-            'accepted_args' => $accepted_args
168
-        );
169
-
170
-        return $hooks;
171
-
172
-    }
173
-
174
-    /**
175
-     * Register the filters and actions with WordPress.
176
-     *
177
-     * @since    1.0.0
178
-     */
179
-    public function run()
180
-    {
181
-
182
-        foreach ($this->filters as $hook) {
183
-            add_filter($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'],
184
-                $hook['accepted_args']);
185
-        }
186
-
187
-        foreach ($this->actions as $hook) {
188
-            add_action($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'],
189
-                $hook['accepted_args']);
190
-        }
191
-
192
-    }
44
+	/**
45
+	 * The array of actions registered with WordPress.
46
+	 *
47
+	 * @since    1.0.0
48
+	 * @access   protected
49
+	 * @var      array $actions The actions registered with WordPress to fire when the plugin loads.
50
+	 */
51
+	protected $actions;
52
+
53
+	/**
54
+	 * The array of filters registered with WordPress.
55
+	 *
56
+	 * @since    1.0.0
57
+	 * @access   protected
58
+	 * @var      array $filters The filters registered with WordPress to fire when the plugin loads.
59
+	 */
60
+	protected $filters;
61
+
62
+	private $xcloner_plugin;
63
+
64
+	/**
65
+	 * Initialize the collections used to maintain the actions and filters.
66
+	 *
67
+	 * @since    1.0.0
68
+	 */
69
+	public function __construct(Xcloner $xcloner_container)
70
+	{
71
+
72
+		$this->actions = array();
73
+		$this->filters = array();
74
+
75
+		$this->xcloner_container = $xcloner_container;
76
+
77
+	}
78
+
79
+	public function xcloner_backup_add_admin_menu()
80
+	{
81
+		if (function_exists('add_menu_page')) {
82
+			add_menu_page(__('Site Backup', 'xcloner-backup-and-restore'),
83
+				__('Site Backup', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_init_page',
84
+				array($this->xcloner_container, 'xcloner_display'), 'dashicons-backup');
85
+		}
86
+
87
+		if (function_exists('add_submenu_page')) {
88
+
89
+			add_submenu_page('xcloner_init_page', __('XCloner Dashboard', 'xcloner-backup-and-restore'),
90
+				__('Dashboard', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_init_page',
91
+				array($this->xcloner_container, 'xcloner_display'));
92
+			add_submenu_page('xcloner_init_page', __('XCloner Backup Settings', 'xcloner-backup-and-restore'),
93
+				__('Settings', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_settings_page',
94
+				array($this->xcloner_container, 'xcloner_display'));
95
+			add_submenu_page('xcloner_init_page', __('Remote Storage Settings', 'xcloner-backup-and-restore'),
96
+				__('Remote Storage', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_remote_storage_page',
97
+				array($this->xcloner_container, 'xcloner_display'));
98
+			add_submenu_page('xcloner_init_page', __('Manage Backups', 'xcloner-backup-and-restore'),
99
+				__('Manage Backups', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_manage_backups_page',
100
+				array($this->xcloner_container, 'xcloner_display'));
101
+			add_submenu_page('xcloner_init_page', __('Scheduled Backups', 'xcloner-backup-and-restore'),
102
+				__('Scheduled Backups', 'xcloner-backup-and-restore'), 'manage_options',
103
+				'xcloner_scheduled_backups_page', array($this->xcloner_container, 'xcloner_display'));
104
+			add_submenu_page('xcloner_init_page', __('Generate Backups', 'xcloner-backup-and-restore'),
105
+				__('Generate Backups', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_generate_backups_page',
106
+				array($this->xcloner_container, 'xcloner_display'));
107
+			add_submenu_page('xcloner_init_page', __('Restore Backups', 'xcloner-backup-and-restore'),
108
+				__('Restore Backups', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_restore_page',
109
+				array($this->xcloner_container, 'xcloner_display'));
110
+		}
111
+
112
+	}
113
+
114
+
115
+	/**
116
+	 * Add a new action to the collection to be registered with WordPress.
117
+	 *
118
+	 * @since    1.0.0
119
+	 * @param    string $hook The name of the WordPress action that is being registered.
120
+	 * @param    object $component A reference to the instance of the object on which the action is defined.
121
+	 * @param    string $callback The name of the function definition on the $component.
122
+	 * @param    int $priority Optional. he priority at which the function should be fired. Default is 10.
123
+	 * @param    int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
124
+	 */
125
+	public function add_action($hook, $component, $callback, $priority = 10, $accepted_args = 1)
126
+	{
127
+		$this->actions = $this->add($this->actions, $hook, $component, $callback, $priority, $accepted_args);
128
+	}
129
+
130
+	/**
131
+	 * Add a new filter to the collection to be registered with WordPress.
132
+	 *
133
+	 * @since    1.0.0
134
+	 * @param    string $hook The name of the WordPress filter that is being registered.
135
+	 * @param    object $component A reference to the instance of the object on which the filter is defined.
136
+	 * @param    string $callback The name of the function definition on the $component.
137
+	 * @param    int $priority Optional. he priority at which the function should be fired. Default is 10.
138
+	 * @param    int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
139
+	 */
140
+	public function add_filter($hook, $component, $callback, $priority = 10, $accepted_args = 1)
141
+	{
142
+		$this->filters = $this->add($this->filters, $hook, $component, $callback, $priority, $accepted_args);
143
+	}
144
+
145
+	/**
146
+	 * A utility function that is used to register the actions and hooks into a single
147
+	 * collection.
148
+	 *
149
+	 * @since    1.0.0
150
+	 * @access   private
151
+	 * @param    array $hooks The collection of hooks that is being registered (that is, actions or filters).
152
+	 * @param    string $hook The name of the WordPress filter that is being registered.
153
+	 * @param    object $component A reference to the instance of the object on which the filter is defined.
154
+	 * @param    string $callback The name of the function definition on the $component.
155
+	 * @param    int $priority The priority at which the function should be fired.
156
+	 * @param    int $accepted_args The number of arguments that should be passed to the $callback.
157
+	 * @return   array                                  The collection of actions and filters registered with WordPress.
158
+	 */
159
+	private function add($hooks, $hook, $component, $callback, $priority, $accepted_args)
160
+	{
161
+
162
+		$hooks[] = array(
163
+			'hook' => $hook,
164
+			'component' => $component,
165
+			'callback' => $callback,
166
+			'priority' => $priority,
167
+			'accepted_args' => $accepted_args
168
+		);
169
+
170
+		return $hooks;
171
+
172
+	}
173
+
174
+	/**
175
+	 * Register the filters and actions with WordPress.
176
+	 *
177
+	 * @since    1.0.0
178
+	 */
179
+	public function run()
180
+	{
181
+
182
+		foreach ($this->filters as $hook) {
183
+			add_filter($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'],
184
+				$hook['accepted_args']);
185
+		}
186
+
187
+		foreach ($this->actions as $hook) {
188
+			add_action($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'],
189
+				$hook['accepted_args']);
190
+		}
191
+
192
+	}
193 193
 
194 194
 }
Please login to merge, or discard this patch.
includes/class-xcloner-activator.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@
 block discarded – undo
63 63
 
64 64
 		if ( version_compare( phpversion(), Xcloner_Activator::xcloner_minimum_version, '<' ) ) {
65 65
 			wp_die( '<p>' . sprintf( __( "XCloner requires minimum PHP version %s in order to run correctly. We have detected your version as %s" ), Xcloner_Activator::xcloner_minimum_version, phpversion() ) . '</p>', __( "XCloner Activation Error" ), array( 'response'  => 500,
66
-			                                                                                                                                                                                                                                                       'back_link' => true
66
+																																																																   'back_link' => true
67 67
 			) );
68 68
 		}
69 69
 
Please login to merge, or discard this patch.