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/class-xcloner-admin.php 2 patches
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -47,8 +47,6 @@
 block discarded – undo
47 47
 	 *
48 48
 	 * @since    1.0.0
49 49
 	 *
50
-	 * @param      string $plugin_name The name of this plugin.
51
-	 * @param      string $version The version of this plugin.
52 50
 	 */
53 51
 	public function __construct( Xcloner $xcloner_container ) {
54 52
 
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 * @param      string $plugin_name The name of this plugin.
51 51
 	 * @param      string $version The version of this plugin.
52 52
 	 */
53
-	public function __construct( Xcloner $xcloner_container ) {
53
+	public function __construct(Xcloner $xcloner_container) {
54 54
 
55 55
 		$this->plugin_name       = $xcloner_container->get_plugin_name();
56 56
 		$this->version           = $xcloner_container->get_version();
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
 	 *
67 67
 	 * @since    1.0.0
68 68
 	 */
69
-	public function enqueue_styles( $hook ) {
69
+	public function enqueue_styles($hook) {
70 70
 
71
-		if ( ! stristr( $hook, "page_" . $this->plugin_name ) || ( isset( $_GET['option'] ) and $_GET['option'] == "com_cloner" ) ) {
71
+		if (!stristr($hook, "page_".$this->plugin_name) || (isset($_GET['option']) and $_GET['option'] == "com_cloner")) {
72 72
 			return;
73 73
 		}
74 74
 
@@ -84,13 +84,13 @@  discard block
 block discarded – undo
84 84
 		 * class.
85 85
 		 */
86 86
 
87
-		wp_enqueue_style( $this->plugin_name . "_materialize", plugin_dir_url( __FILE__ ) . 'css/materialize.min.css', array(), $this->version, 'all' );
88
-		wp_enqueue_style( $this->plugin_name . "_materialize.clockpicker", plugin_dir_url( __FILE__ ) . 'css/materialize.clockpicker.css', array(), $this->version, 'all' );
89
-		wp_enqueue_style( $this->plugin_name . "_materialize.icons", '//fonts.googleapis.com/icon?family=Material+Icons', array(), $this->version, 'all' );
90
-		wp_enqueue_style( $this->plugin_name . "_jquery.datatables", plugin_dir_url( __FILE__ ) . 'css/jquery.dataTables.min.css', array(), $this->version, 'all' );
91
-		wp_enqueue_style( $this->plugin_name . "_jquery.datatables.responsive", plugin_dir_url( __FILE__ ) . 'css/responsive.dataTables.css', array(), $this->version, 'all' );
92
-		wp_enqueue_style( $this->plugin_name . "_jstree", dirname( plugin_dir_url( __FILE__ ) ) . '/vendor/vakata/jstree/dist/themes/default/style.min.css', array(), '3.3', 'all' );
93
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/xcloner-admin.css', array(), $this->version, 'all' );
87
+		wp_enqueue_style($this->plugin_name."_materialize", plugin_dir_url(__FILE__).'css/materialize.min.css', array(), $this->version, 'all');
88
+		wp_enqueue_style($this->plugin_name."_materialize.clockpicker", plugin_dir_url(__FILE__).'css/materialize.clockpicker.css', array(), $this->version, 'all');
89
+		wp_enqueue_style($this->plugin_name."_materialize.icons", '//fonts.googleapis.com/icon?family=Material+Icons', array(), $this->version, 'all');
90
+		wp_enqueue_style($this->plugin_name."_jquery.datatables", plugin_dir_url(__FILE__).'css/jquery.dataTables.min.css', array(), $this->version, 'all');
91
+		wp_enqueue_style($this->plugin_name."_jquery.datatables.responsive", plugin_dir_url(__FILE__).'css/responsive.dataTables.css', array(), $this->version, 'all');
92
+		wp_enqueue_style($this->plugin_name."_jstree", dirname(plugin_dir_url(__FILE__)).'/vendor/vakata/jstree/dist/themes/default/style.min.css', array(), '3.3', 'all');
93
+		wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/xcloner-admin.css', array(), $this->version, 'all');
94 94
 
95 95
 	}
96 96
 
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
 	 *
100 100
 	 * @since    1.0.0
101 101
 	 */
102
-	public function enqueue_scripts( $hook ) {
102
+	public function enqueue_scripts($hook) {
103 103
 
104
-		if ( ! stristr( $hook, "page_" . $this->plugin_name ) ) {
104
+		if (!stristr($hook, "page_".$this->plugin_name)) {
105 105
 			return;
106 106
 		}
107 107
 
@@ -118,25 +118,25 @@  discard block
 block discarded – undo
118 118
 		 */
119 119
 
120 120
 		add_thickbox();
121
-		wp_enqueue_script( 'plugin-install' );
122
-		wp_enqueue_script( 'updates' );
123
-		wp_enqueue_script( $this->plugin_name . "_materialize", plugin_dir_url( __FILE__ ) . 'js/materialize.min.js', array( 'jquery' ), $this->version, false );
124
-		wp_enqueue_script( $this->plugin_name . "_materialize.clockpicker", plugin_dir_url( __FILE__ ) . 'js/materialize.clockpicker.js', array( 'jquery' ), $this->version, false );
125
-		wp_enqueue_script( $this->plugin_name . "_jquery.datatables", plugin_dir_url( __FILE__ ) . 'js/jquery.dataTables.min.js', array( 'jquery' ), $this->version, false );
126
-		wp_enqueue_script( $this->plugin_name . "_jquery.datatables.respnsive", plugin_dir_url( __FILE__ ) . 'js/dataTables.responsive.js', array( 'jquery' ), $this->version, false );
127
-		wp_enqueue_script( $this->plugin_name . "_vakata", dirname( plugin_dir_url( __FILE__ ) ) . '/vendor/vakata/jstree/dist/jstree.min.js', array( 'jquery' ), '3.3', false );
128
-		wp_enqueue_script( $this->plugin_name . "_xcloner-backup-class", plugin_dir_url( __FILE__ ) . 'js/xcloner-backup-class.js', array( 'jquery' ), $this->version, false );
129
-		wp_enqueue_script( $this->plugin_name . "_xcloner-scheduler-class", plugin_dir_url( __FILE__ ) . 'js/xcloner-scheduler-class.js', array( 'jquery' ), $this->version, false );
130
-		wp_enqueue_script( $this->plugin_name . "_xcloner-restore-class", plugin_dir_url( __FILE__ ) . 'js/xcloner-restore-class.js', array( 'jquery' ), $this->version, false );
131
-		wp_enqueue_script( $this->plugin_name . "_xcloner-manage-backups-class", plugin_dir_url( __FILE__ ) . 'js/xcloner-manage-backups-class.js', array( 'jquery' ), $this->version, false );
132
-		wp_enqueue_script( $this->plugin_name . "_xcloner-remote-storage-class", plugin_dir_url( __FILE__ ) . 'js/xcloner-remote-storage-class.js', array( 'jquery' ), $this->version, false );
133
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/xcloner-admin.js', array( 'jquery' ), $this->version, false );
121
+		wp_enqueue_script('plugin-install');
122
+		wp_enqueue_script('updates');
123
+		wp_enqueue_script($this->plugin_name."_materialize", plugin_dir_url(__FILE__).'js/materialize.min.js', array('jquery'), $this->version, false);
124
+		wp_enqueue_script($this->plugin_name."_materialize.clockpicker", plugin_dir_url(__FILE__).'js/materialize.clockpicker.js', array('jquery'), $this->version, false);
125
+		wp_enqueue_script($this->plugin_name."_jquery.datatables", plugin_dir_url(__FILE__).'js/jquery.dataTables.min.js', array('jquery'), $this->version, false);
126
+		wp_enqueue_script($this->plugin_name."_jquery.datatables.respnsive", plugin_dir_url(__FILE__).'js/dataTables.responsive.js', array('jquery'), $this->version, false);
127
+		wp_enqueue_script($this->plugin_name."_vakata", dirname(plugin_dir_url(__FILE__)).'/vendor/vakata/jstree/dist/jstree.min.js', array('jquery'), '3.3', false);
128
+		wp_enqueue_script($this->plugin_name."_xcloner-backup-class", plugin_dir_url(__FILE__).'js/xcloner-backup-class.js', array('jquery'), $this->version, false);
129
+		wp_enqueue_script($this->plugin_name."_xcloner-scheduler-class", plugin_dir_url(__FILE__).'js/xcloner-scheduler-class.js', array('jquery'), $this->version, false);
130
+		wp_enqueue_script($this->plugin_name."_xcloner-restore-class", plugin_dir_url(__FILE__).'js/xcloner-restore-class.js', array('jquery'), $this->version, false);
131
+		wp_enqueue_script($this->plugin_name."_xcloner-manage-backups-class", plugin_dir_url(__FILE__).'js/xcloner-manage-backups-class.js', array('jquery'), $this->version, false);
132
+		wp_enqueue_script($this->plugin_name."_xcloner-remote-storage-class", plugin_dir_url(__FILE__).'js/xcloner-remote-storage-class.js', array('jquery'), $this->version, false);
133
+		wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__).'js/xcloner-admin.js', array('jquery'), $this->version, false);
134 134
 
135 135
 
136 136
 	}
137 137
 
138 138
 	public function xcloner_init_page() {
139
-		require_once( "partials/xcloner_init_page.php" );
139
+		require_once("partials/xcloner_init_page.php");
140 140
 
141 141
 	}
142 142
 
@@ -145,70 +145,70 @@  discard block
 block discarded – undo
145 145
 		$remote_storage       = $this->get_xcloner_container()->get_xcloner_remote_storage();
146 146
 
147 147
 
148
-		if ( isset( $_POST['action'] ) ) {
149
-			$_POST['action'] = $xcloner_sanitization->sanitize_input_as_string( $_POST['action'] );
150
-			$remote_storage->save( $_POST['action'] );
148
+		if (isset($_POST['action'])) {
149
+			$_POST['action'] = $xcloner_sanitization->sanitize_input_as_string($_POST['action']);
150
+			$remote_storage->save($_POST['action']);
151 151
 		}
152 152
 
153
-		if ( isset( $_POST['authentification_code'] ) && $_POST['authentification_code'] != "" ) {
154
-			$_POST['authentification_code'] = $xcloner_sanitization->sanitize_input_as_string( $_POST['authentification_code'] );
153
+		if (isset($_POST['authentification_code']) && $_POST['authentification_code'] != "") {
154
+			$_POST['authentification_code'] = $xcloner_sanitization->sanitize_input_as_string($_POST['authentification_code']);
155 155
 
156
-			$remote_storage->set_access_token( $_POST['authentification_code'] );
156
+			$remote_storage->set_access_token($_POST['authentification_code']);
157 157
 		}
158 158
 
159
-		if ( isset( $_POST['connection_check'] ) && $_POST['connection_check'] ) {
160
-			$remote_storage->check( $_POST['action'] );
159
+		if (isset($_POST['connection_check']) && $_POST['connection_check']) {
160
+			$remote_storage->check($_POST['action']);
161 161
 		}
162 162
 
163
-		require_once( "partials/xcloner_remote_storage_page.php" );
163
+		require_once("partials/xcloner_remote_storage_page.php");
164 164
 
165 165
 	}
166 166
 
167 167
 	public function xcloner_scheduled_backups_page() {
168 168
 		$requirements = $this->xcloner_container->get_xcloner_requirements();
169 169
 
170
-		if ( ! $requirements->check_backup_ready_status() ) {
171
-			require_once( "partials/xcloner_init_page.php" );
170
+		if (!$requirements->check_backup_ready_status()) {
171
+			require_once("partials/xcloner_init_page.php");
172 172
 
173 173
 			return false;
174 174
 		}
175 175
 
176
-		require_once( "partials/xcloner_scheduled_backups_page.php" );
176
+		require_once("partials/xcloner_scheduled_backups_page.php");
177 177
 
178 178
 	}
179 179
 
180 180
 	public function xcloner_manage_backups_page() {
181
-		require_once( "partials/xcloner_manage_backups_page.php" );
181
+		require_once("partials/xcloner_manage_backups_page.php");
182 182
 
183 183
 	}
184 184
 
185 185
 	public function xcloner_debugger_page() {
186
-		require_once( "partials/xcloner_console_page.php" );
186
+		require_once("partials/xcloner_console_page.php");
187 187
 
188 188
 	}
189 189
 
190 190
 	public function xcloner_restore_page() {
191
-		require_once( "partials/xcloner_restore_page.php" );
191
+		require_once("partials/xcloner_restore_page.php");
192 192
 
193 193
 	}
194 194
 
195 195
 	public function xcloner_generate_backups_page() {
196 196
 		$requirements = $this->xcloner_container->get_xcloner_requirements();
197 197
 
198
-		if ( ! $requirements->check_backup_ready_status() ) {
199
-			require_once( "partials/xcloner_init_page.php" );
198
+		if (!$requirements->check_backup_ready_status()) {
199
+			require_once("partials/xcloner_init_page.php");
200 200
 
201 201
 			return false;
202 202
 		}
203 203
 
204
-		require_once( "partials/xcloner_generate_backups_page.php" );
204
+		require_once("partials/xcloner_generate_backups_page.php");
205 205
 
206 206
 		return;
207 207
 	}
208 208
 
209 209
 	public function xcloner_settings_page() {
210 210
 		// check user capabilities
211
-		if ( ! current_user_can( 'manage_options' ) ) {
211
+		if (!current_user_can('manage_options')) {
212 212
 			return;
213 213
 		}
214 214
 
@@ -216,40 +216,40 @@  discard block
 block discarded – undo
216 216
 
217 217
 		// check if the user have submitted the settings
218 218
 		// wordpress will add the "settings-updated" $_GET parameter to the url
219
-		if ( isset( $_GET['settings-updated'] ) ) {
219
+		if (isset($_GET['settings-updated'])) {
220 220
 			// add settings saved message with the class of "updated"
221
-			add_settings_error( 'wporg_messages', 'wporg_message', __( 'Settings Saved', 'wporg' ), 'updated' );
221
+			add_settings_error('wporg_messages', 'wporg_message', __('Settings Saved', 'wporg'), 'updated');
222 222
 		}
223 223
 
224 224
 		// show error/update messages
225
-		settings_errors( 'wporg_messages' );
225
+		settings_errors('wporg_messages');
226 226
 		?>
227 227
 
228 228
 		<?php
229 229
 		$xcloner_sanitization = $this->get_xcloner_container()->get_xcloner_sanitization();
230 230
 
231
-		if ( isset( $_GET['tab'] ) ) {
232
-			$active_tab = $xcloner_sanitization->sanitize_input_as_string( $_GET['tab'] );
231
+		if (isset($_GET['tab'])) {
232
+			$active_tab = $xcloner_sanitization->sanitize_input_as_string($_GET['tab']);
233 233
 		} // end if
234 234
 		else {
235 235
 			$active_tab = "general_options";
236 236
 		}
237 237
 
238 238
 		?>
239
-        <h1><?= esc_html( get_admin_page_title() ); ?></h1>
239
+        <h1><?= esc_html(get_admin_page_title()); ?></h1>
240 240
 
241 241
         <ul class="nav-tab-wrapper row">
242 242
             <li><a href="?page=xcloner_settings_page&tab=general_options"
243
-                   class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'general_options' ? 'nav-tab-active' : ''; ?>"><?php echo __( 'General Options', 'xcloner-backup-and-restore' ) ?></a>
243
+                   class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'general_options' ? 'nav-tab-active' : ''; ?>"><?php echo __('General Options', 'xcloner-backup-and-restore') ?></a>
244 244
             </li>
245 245
             <li><a href="?page=xcloner_settings_page&tab=mysql_options"
246
-                   class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'mysql_options' ? 'nav-tab-active' : ''; ?>"><?php echo __( 'Mysql Options', 'xcloner-backup-and-restore' ) ?></a>
246
+                   class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'mysql_options' ? 'nav-tab-active' : ''; ?>"><?php echo __('Mysql Options', 'xcloner-backup-and-restore') ?></a>
247 247
             </li>
248 248
             <li><a href="?page=xcloner_settings_page&tab=system_options"
249
-                   class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'system_options' ? 'nav-tab-active' : ''; ?>"><?php echo __( 'System Options', 'xcloner-backup-and-restore' ) ?></a>
249
+                   class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'system_options' ? 'nav-tab-active' : ''; ?>"><?php echo __('System Options', 'xcloner-backup-and-restore') ?></a>
250 250
             </li>
251 251
             <li><a href="?page=xcloner_settings_page&tab=cleanup_options"
252
-                   class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'cleanup_options' ? 'nav-tab-active' : ''; ?>"><?php echo __( 'Cleanup Options', 'xcloner-backup-and-restore' ) ?></a>
252
+                   class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'cleanup_options' ? 'nav-tab-active' : ''; ?>"><?php echo __('Cleanup Options', 'xcloner-backup-and-restore') ?></a>
253 253
             </li>
254 254
         </ul>
255 255
 
@@ -258,27 +258,27 @@  discard block
 block discarded – undo
258 258
             <form action="options.php" method="post">
259 259
 				<?php
260 260
 
261
-				if ( $active_tab == 'general_options' ) {
261
+				if ($active_tab == 'general_options') {
262 262
 
263
-					settings_fields( 'xcloner_general_settings_group' );
264
-					do_settings_sections( 'xcloner_settings_page' );
263
+					settings_fields('xcloner_general_settings_group');
264
+					do_settings_sections('xcloner_settings_page');
265 265
 
266
-				} elseif ( $active_tab == 'mysql_options' ) {
266
+				} elseif ($active_tab == 'mysql_options') {
267 267
 
268
-					settings_fields( 'xcloner_mysql_settings_group' );
269
-					do_settings_sections( 'xcloner_mysql_settings_page' );
270
-				} elseif ( $active_tab == 'system_options' ) {
268
+					settings_fields('xcloner_mysql_settings_group');
269
+					do_settings_sections('xcloner_mysql_settings_page');
270
+				} elseif ($active_tab == 'system_options') {
271 271
 
272
-					settings_fields( 'xcloner_system_settings_group' );
273
-					do_settings_sections( 'xcloner_system_settings_page' );
274
-				} elseif ( $active_tab == 'cleanup_options' ) {
272
+					settings_fields('xcloner_system_settings_group');
273
+					do_settings_sections('xcloner_system_settings_page');
274
+				} elseif ($active_tab == 'cleanup_options') {
275 275
 
276
-					settings_fields( 'xcloner_cleanup_settings_group' );
277
-					do_settings_sections( 'xcloner_cleanup_settings_page' );
276
+					settings_fields('xcloner_cleanup_settings_group');
277
+					do_settings_sections('xcloner_cleanup_settings_page');
278 278
 				}
279 279
 
280 280
 				// output save settings button
281
-				submit_button( 'Save Settings' );
281
+				submit_button('Save Settings');
282 282
 				?>
283 283
             </form>
284 284
 
Please login to merge, or discard this patch.
includes/class-xcloner-api.php 3 patches
Unused Use Statements   -5 removed lines patch added patch discarded remove patch
@@ -28,13 +28,8 @@
 block discarded – undo
28 28
 
29 29
 use League\Flysystem\Config;
30 30
 use League\Flysystem\Filesystem;
31
-use League\Flysystem\Util;
32 31
 use League\Flysystem\Adapter\Local;
33
-
34 32
 use splitbrain\PHPArchive\Tar;
35
-use splitbrain\PHPArchive\Zip;
36
-use splitbrain\PHPArchive\Archive;
37
-use splitbrain\PHPArchive\FileInfo;
38 33
 
39 34
 
40 35
 /**
Please login to merge, or discard this 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.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
         $this->xcloner_scheduler = $xcloner_container->get_xcloner_scheduler();
86 86
 
87 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']),
88
+            $this->logger->info("Processing ajax request ID ".substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']),
89 89
                     0, 15));
90 90
         }
91 91
 
@@ -127,13 +127,13 @@  discard block
 block discarded – undo
127 127
 
128 128
 
129 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";
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 132
 
133 133
         try {
134 134
             $this->xcloner_database->init($data);
135 135
 
136
-        } catch (Exception $e) {
136
+        }catch (Exception $e) {
137 137
 
138 138
             $this->send_response($e->getMessage());
139 139
             $this->logger->error($e->getMessage());
@@ -218,8 +218,8 @@  discard block
 block discarded – undo
218 218
         } else {
219 219
 
220 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']);
221
+            $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'].
222
+                " ".$this->form_params['backup_params']['schedule_start_time']);
223 223
 
224 224
             if ($schedule['start_at'] <= time()) {
225 225
                 $schedule['start_at'] = "";
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 
245 245
         if (!isset($_POST['id'])) {
246 246
             $wpdb->insert(
247
-                $wpdb->prefix . 'xcloner_scheduler',
247
+                $wpdb->prefix.'xcloner_scheduler',
248 248
                 $schedule,
249 249
                 array(
250 250
                     '%s',
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
             );
254 254
         } else {
255 255
             $wpdb->update(
256
-                $wpdb->prefix . 'xcloner_scheduler',
256
+                $wpdb->prefix.'xcloner_scheduler',
257 257
                 $schedule,
258 258
                 array('id' => $_POST['id']),
259 259
                 array(
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
         try {
305 305
             $return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'],
306 306
                 $this->form_params['extra'], $init);
307
-        } catch (Exception $e) {
307
+        }catch (Exception $e) {
308 308
             $return = array();
309 309
             $return['error'] = true;
310 310
             $return['status'] = 500;
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
                     $additional['lines_total'] = $return['extra']['lines_total'];
332 332
                     $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'],
333 333
                         $this->form_params, "", $additional);
334
-                } catch (Exception $e) {
334
+                }catch (Exception $e) {
335 335
                     $this->logger->error($e->getMessage());
336 336
                 }
337 337
             }
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
         if (isset($params->backup_params)) {
426 426
             foreach ($params->backup_params as $param) {
427 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(
428
+                $this->logger->debug("Adding form parameter ".$param->name.".".$param->value."\n", array(
429 429
                     'POST',
430 430
                     'fields filter'
431 431
                 ));
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
         if (isset($params->table_params)) {
438 438
             foreach ($params->table_params as $param) {
439 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(
440
+                $this->logger->debug("Adding database filter ".$param->parent.".".$param->id."\n", array(
441 441
                     'POST',
442 442
                     'database filter'
443 443
                 ));
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
                 if (!in_array($param->parent, $this->form_params['excluded_files'])) {
457 457
                     //$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
458 458
                     $unique_exclude_files[] = $param->id;
459
-                    $this->logger->debug("Adding file filter " . $param->id . "\n", array(
459
+                    $this->logger->debug("Adding file filter ".$param->id."\n", array(
460 460
                         'POST',
461 461
                         'exclude files filter'
462 462
                     ));
@@ -504,13 +504,13 @@  discard block
 block discarded – undo
504 504
                 'text' => $this->xcloner_settings->get_xcloner_start_path(),
505 505
                 //'children' => true,
506 506
                 'state' => array('selected' => false, 'opened' => true),
507
-                'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-root.png"
507
+                'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/file-icon-root.png"
508 508
             );
509 509
         }
510 510
 
511 511
         try {
512 512
             $files = $this->xcloner_file_system->list_directory($folder);
513
-        } catch (Exception $e) {
513
+        }catch (Exception $e) {
514 514
 
515 515
             print $e->getMessage();
516 516
             $this->logger->error($e->getMessage());
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
             if ($file['type'] == "dir") {
532 532
                 $children = true;
533 533
             } else {
534
-                $text .= " (" . $this->xcloner_requirements->file_format_size($file['size']) . ")";
534
+                $text .= " (".$this->xcloner_requirements->file_format_size($file['size']).")";
535 535
             }
536 536
 
537 537
             if ($this->xcloner_file_system->is_excluded($file)) {
@@ -547,8 +547,8 @@  discard block
 block discarded – undo
547 547
                 //'title' => "test",
548 548
                 'children' => $children,
549 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"
550
+                'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/file-icon-".strtolower(substr($file['type'],
551
+                        0, 1)).".png"
552 552
             );
553 553
         }
554 554
 
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
         if ($database == "#") {
575 575
             try {
576 576
                 $return = $this->xcloner_database->get_all_databases();
577
-            } catch (Exception $e) {
577
+            }catch (Exception $e) {
578 578
                 $this->logger->error($e->getMessage());
579 579
             }
580 580
 
@@ -595,10 +595,10 @@  discard block
 block discarded – undo
595 595
                 $data[] = array(
596 596
                     'id' => $database['name'],
597 597
                     'parent' => '#',
598
-                    'text' => $database['name'] . " (" . (int)$database['num_tables'] . ")",
598
+                    'text' => $database['name']." (".(int)$database['num_tables'].")",
599 599
                     'children' => true,
600 600
                     'state' => $state,
601
-                    'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/database-icon.png"
601
+                    'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/database-icon.png"
602 602
                 );
603 603
             }
604 604
 
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 
607 607
             try {
608 608
                 $return = $this->xcloner_database->list_tables($database, "", 1);
609
-            } catch (Exception $e) {
609
+            }catch (Exception $e) {
610 610
                 $this->logger->error($e->getMessage());
611 611
             }
612 612
 
@@ -623,12 +623,12 @@  discard block
 block discarded – undo
623 623
                 }
624 624
 
625 625
                 $data[] = array(
626
-                    'id' => $database . "." . $table['name'],
626
+                    'id' => $database.".".$table['name'],
627 627
                     'parent' => $database,
628
-                    'text' => $table['name'] . " (" . (int)$table['records'] . ")",
628
+                    'text' => $table['name']." (".(int)$table['records'].")",
629 629
                     'children' => false,
630 630
                     'state' => $state,
631
-                    'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/table-icon.png"
631
+                    'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/table-icon.png"
632 632
                 );
633 633
             }
634 634
         }
@@ -672,17 +672,17 @@  discard block
 block discarded – undo
672 672
         $return['data'] = array();
673 673
 
674 674
         foreach ($data as $res) {
675
-            $action = "<a href=\"#" . $res->id . "\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a>
676
-					<a href=\"#" . $res->id . "\" class=\"delete\" title='Delete'><i class=\"material-icons  \">delete</i></a>";
675
+            $action = "<a href=\"#".$res->id."\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a>
676
+					<a href=\"#" . $res->id."\" class=\"delete\" title='Delete'><i class=\"material-icons  \">delete</i></a>";
677 677
             if ($res->status) {
678 678
                 $status = '<i class="material-icons active status">timer</i>';
679 679
             } else {
680 680
                 $status = '<i class="material-icons status inactive">timer_off</i>';
681 681
             }
682 682
 
683
-            $next_run_time = wp_next_scheduled('xcloner_scheduler_' . $res->id, array($res->id));
683
+            $next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id));
684 684
 
685
-            $next_run = date(get_option('date_format') . " " . get_option('time_format'), $next_run_time);
685
+            $next_run = date(get_option('date_format')." ".get_option('time_format'), $next_run_time);
686 686
 
687 687
             $remote_storage = $res->remote_storage;
688 688
 
@@ -691,16 +691,16 @@  discard block
 block discarded – undo
691 691
             }
692 692
 
693 693
             if (trim($next_run)) {
694
-                $date_text = date(get_option('date_format') . " " . get_option('time_format'),
694
+                $date_text = date(get_option('date_format')." ".get_option('time_format'),
695 695
                     $next_run_time + (get_option('gmt_offset') * HOUR_IN_SECONDS));
696 696
 
697 697
                 if ($next_run_time >= time()) {
698
-                    $next_run = "in " . human_time_diff($next_run_time, time());
698
+                    $next_run = "in ".human_time_diff($next_run_time, time());
699 699
                 } else {
700 700
                     $next_run = __("executed", 'xcloner-backup-and-restore');
701 701
                 }
702 702
 
703
-                $next_run = "<a href='#' title='" . $date_text . "'>" . $next_run . "</a>";
703
+                $next_run = "<a href='#' title='".$date_text."'>".$next_run."</a>";
704 704
                 //$next_run .=" ($date_text)";
705 705
             }
706 706
 
@@ -712,11 +712,11 @@  discard block
 block discarded – undo
712 712
                 if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) {
713 713
                     $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup);
714 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'),
715
+                    $backup_time = date(get_option('date_format')." ".get_option('time_format'),
716 716
                         $metadata['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS));
717 717
                 }
718 718
 
719
-                $backup_text = "<span title='" . $backup_time . "' class='shorten_string'>" . $res->last_backup . " (" . $backup_size . ")</span>";
719
+                $backup_text = "<span title='".$backup_time."' class='shorten_string'>".$res->last_backup." (".$backup_size.")</span>";
720 720
             }
721 721
 
722 722
             $schedules = wp_get_schedules();
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
             $return['data'][] = array(
729 729
                 $res->id,
730 730
                 $res->name,
731
-                $res->recurrence,/*$res->start_at,*/
731
+                $res->recurrence, /*$res->start_at,*/
732 732
                 $next_run,
733 733
                 $remote_storage,
734 734
                 $backup_text,
@@ -792,10 +792,10 @@  discard block
 block discarded – undo
792 792
 
793 793
         try {
794 794
             $tar = new Tar();
795
-            $tar->open($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file, $start);
795
+            $tar->open($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file, $start);
796 796
 
797 797
             $data = $tar->contents(get_option('xcloner_files_to_process_per_request'));
798
-        } catch (Exception $e) {
798
+        }catch (Exception $e) {
799 799
             $return['error'] = true;
800 800
             $return['message'] = $e->getMessage();
801 801
             $this->send_response($return, 0);
@@ -803,14 +803,14 @@  discard block
 block discarded – undo
803 803
 
804 804
         $return['files'] = array();
805 805
         $return['finished'] = 1;
806
-        $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file);
806
+        $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file);
807 807
         $i = 0;
808 808
 
809 809
         if (isset($data['extracted_files']) and is_array($data['extracted_files'])) {
810 810
             foreach ($data['extracted_files'] as $file) {
811 811
                 $return['files'][$i]['path'] = $file->getPath();
812 812
                 $return['files'][$i]['size'] = $file->getSize();
813
-                $return['files'][$i]['mtime'] = date(get_option('date_format') . " " . get_option('time_format'),
813
+                $return['files'][$i]['mtime'] = date(get_option('date_format')." ".get_option('time_format'),
814 814
                     $file->getMtime());
815 815
 
816 816
                 $i++;
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
                     "copy_backup_remote_to_local"
859 859
                 ), array($backup_file, $storage_type));
860 860
             }
861
-        } catch (Exception $e) {
861
+        }catch (Exception $e) {
862 862
 
863 863
             $return['error'] = 1;
864 864
             $return['message'] = $e->getMessage();
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
                     "upload_backup_to_storage"
898 898
                 ), array($backup_file, $storage_type));
899 899
             }
900
-        } catch (Exception $e) {
900
+        }catch (Exception $e) {
901 901
 
902 902
             $return['error'] = 1;
903 903
             $return['message'] = $e->getMessage();
@@ -957,21 +957,21 @@  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 962
         $tar = new Tar();
963 963
         $tar->create($tmp_file);
964 964
 
965
-        $tar->addFile(dirname(__DIR__) . "/restore/vendor.build.txt", "vendor.phar");
965
+        $tar->addFile(dirname(__DIR__)."/restore/vendor.build.txt", "vendor.phar");
966 966
         //$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz");
967 967
 
968 968
         $files = $xcloner_plugin_filesystem->listContents("vendor/", true);
969 969
         foreach ($files as $file) {
970
-            $tar->addFile(dirname(__DIR__) . DS . $file['path'], $file['path']);
970
+            $tar->addFile(dirname(__DIR__).DS.$file['path'], $file['path']);
971 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 976
         $tar->addData("xcloner_restore.php", $content);
977 977
 
@@ -980,11 +980,11 @@  discard block
 block discarded – undo
980 980
         if (file_exists($tmp_file)) {
981 981
             header('Content-Description: File Transfer');
982 982
             header('Content-Type: application/octet-stream');
983
-            header('Content-Disposition: attachment; filename="' . basename($tmp_file) . '"');
983
+            header('Content-Disposition: attachment; filename="'.basename($tmp_file).'"');
984 984
             header('Expires: 0');
985 985
             header('Cache-Control: must-revalidate');
986 986
             header('Pragma: public');
987
-            header('Content-Length: ' . filesize($tmp_file));
987
+            header('Content-Length: '.filesize($tmp_file));
988 988
             readfile($tmp_file);
989 989
 
990 990
         }
@@ -1016,9 +1016,9 @@  discard block
 block discarded – undo
1016 1016
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1017 1017
         header('Cache-Control: private', false);
1018 1018
         header('Content-Transfer-Encoding: binary');
1019
-        header('Content-Disposition: attachment; filename="' . $metadata['path'] . '";');
1019
+        header('Content-Disposition: attachment; filename="'.$metadata['path'].'";');
1020 1020
         header('Content-Type: application/octet-stream');
1021
-        header('Content-Length: ' . $metadata['size']);
1021
+        header('Content-Length: '.$metadata['size']);
1022 1022
 
1023 1023
         @ob_end_clean();
1024 1024
 
@@ -1078,12 +1078,12 @@  discard block
 block discarded – undo
1078 1078
             $xcloner_file_transfer->set_target($target_url);
1079 1079
             $return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash);
1080 1080
 
1081
-        } catch (Exception $e) {
1081
+        }catch (Exception $e) {
1082 1082
 
1083 1083
             $return = array();
1084 1084
             $return['error'] = true;
1085 1085
             $return['status'] = 500;
1086
-            $return['message'] = "CURL communication error with the restore host. " . $e->getMessage();
1086
+            $return['message'] = "CURL communication error with the restore host. ".$e->getMessage();
1087 1087
             $this->send_response($return, 0);
1088 1088
 
1089 1089
         }
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
         $this->check_access();
1108 1108
 
1109 1109
         define("XCLONER_PLUGIN_ACCESS", 1);
1110
-        include_once(dirname(__DIR__) . DS . "restore" . DS . "xcloner_restore.php");
1110
+        include_once(dirname(__DIR__).DS."restore".DS."xcloner_restore.php");
1111 1111
 
1112 1112
         return;
1113 1113
     }
Please login to merge, or discard this patch.
includes/class-xcloner-archive.php 3 patches
Doc Comments   +21 added lines patch added patch discarded remove patch
@@ -213,6 +213,10 @@  discard block
 block discarded – undo
213 213
      *
214 214
      * @return bool
215 215
      */
216
+
217
+    /**
218
+     * @param string $error_message
219
+     */
216 220
     public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message)
217 221
     {
218 222
 
@@ -251,6 +255,11 @@  discard block
 block discarded – undo
251 255
      *
252 256
      * @return bool
253 257
      */
258
+
259
+    /**
260
+     * @param string $from
261
+     * @param string $subject
262
+     */
254 263
     public function send_notification(
255 264
         $to,
256 265
         $from,
@@ -339,6 +348,10 @@  discard block
 block discarded – undo
339 348
      * Incremental Backup method
340 349
      *
341 350
      */
351
+
352
+    /**
353
+     * @param integer $init
354
+     */
342 355
     public function start_incremental_backup($backup_params, $extra_params, $init)
343 356
     {
344 357
         $return = array();
@@ -576,6 +589,10 @@  discard block
 block discarded – undo
576 589
      * Write multipart file components
577 590
      *
578 591
      */
592
+
593
+    /**
594
+     * @param string $path
595
+     */
579 596
     private function write_multipart_file($path)
580 597
     {
581 598
         $path = $this->get_archive_name_with_extension();
@@ -636,6 +653,10 @@  discard block
 block discarded – undo
636 653
      * Add file to archive
637 654
      *
638 655
      */
656
+
657
+    /**
658
+     * @param integer $append
659
+     */
639 660
     public function add_file_to_archive($file_info, $start_at_byte, $byte_limit = 0, $append, $filesystem)
640 661
     {
641 662
 
Please login to merge, or discard this 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.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
             $new_name = $this->archive_name;
149 149
 
150 150
             if (!stristr($new_name, "-diff")) {
151
-                $new_name = $this->archive_name . "-diff" . date("Y-m-d_H-i", $diff_timestamp_start);
151
+                $new_name = $this->archive_name."-diff".date("Y-m-d_H-i", $diff_timestamp_start);
152 152
             }
153 153
 
154 154
             $this->archive_name = $new_name;
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
         }
157 157
 
158 158
         if (isset($part) and $part) {
159
-            $new_name = preg_replace('/-part(\d*)/', "-part" . $part, $this->archive_name);
159
+            $new_name = preg_replace('/-part(\d*)/', "-part".$part, $this->archive_name);
160 160
             if (!stristr($new_name, "-part")) {
161
-                $new_name = $this->archive_name . "-part" . $part;
161
+                $new_name = $this->archive_name."-part".$part;
162 162
             }
163 163
 
164 164
             $this->archive_name = $new_name;
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
     public function get_archive_name_multipart()
188 188
     {
189 189
         $new_name = preg_replace('/-part(\d*)/', "", $this->archive_name);
190
-        return $new_name . "-multipart" . $this->xcloner_settings->get_backup_extension_name(".csv");
190
+        return $new_name."-multipart".$this->xcloner_settings->get_backup_extension_name(".csv");
191 191
     }
192 192
 
193 193
     /*
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
      */
198 198
     public function get_archive_name_with_extension()
199 199
     {
200
-        return $this->archive_name . $this->xcloner_settings->get_backup_extension_name();
200
+        return $this->archive_name.$this->xcloner_settings->get_backup_extension_name();
201 201
     }
202 202
 
203 203
     /*
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
         $headers = array('Content-Type: text/html; charset=UTF-8');
230 230
 
231 231
         if ($admin_email and $from) {
232
-            $headers[] = 'From: ' . $from . ' <' . $admin_email . '>';
232
+            $headers[] = 'From: '.$from.' <'.$admin_email.'>';
233 233
         }
234 234
 
235 235
         $return = wp_mail($to, $subject, $body, $headers);
@@ -302,18 +302,18 @@  discard block
 block discarded – undo
302 302
         $body .= "<br />";
303 303
 
304 304
         if (isset($params['backup_params']->backup_comments)) {
305
-            $body .= __("Backup Comments: ") . $params['backup_params']->backup_comments;
305
+            $body .= __("Backup Comments: ").$params['backup_params']->backup_comments;
306 306
             $body .= "<br /><br />";
307 307
         }
308 308
 
309 309
         if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
310
-            $body .= __("Latest 50 Log Lines: ") . "<br />" . implode("<br />\n",
310
+            $body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n",
311 311
                                                                         $this->logger->getLastDebugLines(50));
312 312
         }
313 313
 
314 314
         $attachments = $this->filesystem->get_backup_attachments();
315 315
 
316
-        $attachments_archive = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "info.tgz";
316
+        $attachments_archive = $this->xcloner_settings->get_xcloner_tmp_path().DS."info.tgz";
317 317
 
318 318
         $tar = new Tar();
319 319
         $tar->create($attachments_archive);
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 
328 328
         $admin_email = get_option("admin_email");
329 329
 
330
-        $headers = array('Content-Type: text/html; charset=UTF-8', 'From: ' . $from . ' <' . $admin_email . '>');
330
+        $headers = array('Content-Type: text/html; charset=UTF-8', 'From: '.$from.' <'.$admin_email.'>');
331 331
 
332 332
         $return = wp_mail($to, $subject, $body, $headers, array($attachments_archive));
333 333
 
@@ -367,14 +367,14 @@  discard block
 block discarded – undo
367 367
         if ($init) {
368 368
             $this->logger->info(sprintf(__("Initializing the backup archive %s"), $this->get_archive_name()));
369 369
 
370
-            $this->backup_archive->create($archive_info->getPath() . DS . $archive_info->getFilename());
370
+            $this->backup_archive->create($archive_info->getPath().DS.$archive_info->getFilename());
371 371
 
372 372
             $return['extra']['backup_init'] = 1;
373 373
 
374 374
         } else {
375 375
             $this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name()));
376 376
 
377
-            $this->backup_archive->openForAppend($archive_info->getPath() . DS . $archive_info->getFilename());
377
+            $this->backup_archive->openForAppend($archive_info->getPath().DS.$archive_info->getFilename());
378 378
 
379 379
             $return['extra']['backup_init'] = 0;
380 380
 
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 
583 583
         $file = $this->filesystem->get_filesystem("storage_filesystem_append")->getMetadata($path);
584 584
         //print_r($file_info);
585
-        $line = '"' . $file['path'] . '","' . $file['timestamp'] . '","' . $file['size'] . '"' . PHP_EOL;
585
+        $line = '"'.$file['path'].'","'.$file['timestamp'].'","'.$file['size'].'"'.PHP_EOL;
586 586
 
587 587
 
588 588
         $this->filesystem->get_filesystem("storage_filesystem_append")
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
         $this->backup_archive = new Tar();
626 626
         $this->backup_archive->setCompression($this->compression_level);
627 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());
628
+        $this->backup_archive->create($archive_info->getPath().DS.$archive_info->getFilename());
629 629
 
630 630
         return array($archive_info, $part);
631 631
 
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
         }
648 648
 
649 649
         if (isset($file_info['archive_prefix_path'])) {
650
-            $file_info['target_path'] = $file_info['archive_prefix_path'] . "/" . $file_info['path'];
650
+            $file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path'];
651 651
         } else {
652 652
             $file_info['target_path'] = $file_info['path'];
653 653
         }
Please login to merge, or discard this patch.
includes/class-xcloner-file-system.php 5 patches
Doc Comments   +12 added lines patch added patch discarded remove patch
@@ -207,6 +207,9 @@  discard block
 block discarded – undo
207 207
         return $this->start_filesystem->normalizeFileInfo($info);
208 208
     }
209 209
 
210
+    /**
211
+     * @param string $file
212
+     */
210 213
     public function get_storage_path_file_info($file)
211 214
     {
212 215
         return $this->getMetadataFull('storage_adapter', $file);
@@ -284,6 +287,9 @@  discard block
 block discarded – undo
284 287
         return $total;
285 288
     }
286 289
 
290
+    /**
291
+     * @param string $backup_name
292
+     */
287 293
     public function is_part($backup_name)
288 294
     {
289 295
         if (stristr($backup_name, "-part")) {
@@ -741,6 +747,9 @@  discard block
 block discarded – undo
741 747
 
742 748
     }
743 749
 
750
+    /**
751
+     * @param string $tmp_file
752
+     */
744 753
     public function estimate_reading_time($tmp_file)
745 754
     {
746 755
         $this->logger->debug(sprintf(("Estimating file system reading time")));
@@ -781,6 +790,9 @@  discard block
 block discarded – undo
781 790
         return $name;
782 791
     }
783 792
 
793
+    /**
794
+     * @param string $field
795
+     */
784 796
     public function sort_by(&$array, $field, $direction = 'asc')
785 797
     {
786 798
         if (strtolower($direction) == "desc" || $direction == SORT_DESC) {
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,6 @@
 block discarded – undo
28 28
 
29 29
 use League\Flysystem\Config;
30 30
 use League\Flysystem\Filesystem;
31
-use League\Flysystem\Util;
32 31
 use League\Flysystem\Adapter\Local;
33 32
 
34 33
 /**
Please login to merge, or discard this 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.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -102,8 +102,8 @@  discard block
 block discarded – undo
102 102
             $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([
103 103
                 'disable_asserts' => true,
104 104
             ]));
105
-        } catch (Exception $e) {
106
-            $this->logger->error("Filesystem Initialization Error: " . $e->getMessage());
105
+        }catch (Exception $e) {
106
+            $this->logger->error("Filesystem Initialization Error: ".$e->getMessage());
107 107
         }
108 108
 
109 109
 
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
     {
162 162
         if ($remote_storage_selection != "") {
163 163
             $remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
164
-            $method = "get_" . $remote_storage_selection . "_filesystem";
164
+            $method = "get_".$remote_storage_selection."_filesystem";
165 165
 
166 166
             if (!method_exists($remote_storage, $method)) {
167 167
                 return false;
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
                     $this->build_files_list($file);
432 432
                     $counter++;
433 433
                 } else {
434
-                    $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file . "\n");
434
+                    $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n");
435 435
                 }
436 436
             }
437 437
         } else {
@@ -472,15 +472,15 @@  discard block
 block discarded – undo
472 472
     {
473 473
         $return = array();
474 474
 
475
-        $files_list_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->get_included_files_handler();
475
+        $files_list_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler();
476 476
         if (file_exists($files_list_file)) {
477 477
             $return[] = $files_list_file;
478 478
         }
479 479
 
480 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);
481
+            $log_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
482 482
             if (!file_exists($log_file)) {
483
-                $log_file = $this->xcloner_settings->get_xcloner_store_path() . DS . $this->xcloner_settings->get_logger_filename();
483
+                $log_file = $this->xcloner_settings->get_xcloner_store_path().DS.$this->xcloner_settings->get_logger_filename();
484 484
             }
485 485
 
486 486
             if (file_exists($log_file)) {
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
 
615 615
             $files = $this->start_filesystem->listContents($folder);
616 616
             foreach ($files as $file) {
617
-                if (!is_readable($this->xcloner_settings->get_xcloner_start_path() . DS . $file['path'])) {
617
+                if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) {
618 618
                     $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"),
619 619
                         $file['path']), array(
620 620
                         "FILESYSTEM SCAN",
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
                 }
643 643
             }
644 644
 
645
-        } catch (Exception $e) {
645
+        }catch (Exception $e) {
646 646
 
647 647
             $this->logger->error($e->getMessage());
648 648
 
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
 
653 653
     public function estimate_read_write_time()
654 654
     {
655
-        $tmp_file = ".xcloner" . substr(md5(time()), 0, 5);
655
+        $tmp_file = ".xcloner".substr(md5(time()), 0, 5);
656 656
 
657 657
         $start_time = microtime(true);
658 658
 
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
 
670 670
             $this->tmp_filesystem->delete($tmp_file);
671 671
 
672
-        } catch (Exception $e) {
672
+        }catch (Exception $e) {
673 673
 
674 674
             $this->logger->error($e->getMessage());
675 675
 
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
         $_backup_files_list = array();
687 687
 
688 688
         //rule date limit
689
-        $current_timestamp = strtotime("-" . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') . " days");
689
+        $current_timestamp = strtotime("-".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')." days");
690 690
 
691 691
         $files = $this->storage_filesystem->listContents();
692 692
 
@@ -711,18 +711,18 @@  discard block
 block discarded – undo
711 711
             {
712 712
                 $this->storage_filesystem->delete($file['path']);
713 713
                 $_storage_size -= $file['size'];
714
-                $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
714
+                $this->logger->info("Deleting backup ".$file['path']." matching rule", array(
715 715
                     "STORAGE SIZE LIMIT",
716
-                    $_storage_size . " >= " . $set_storage_limit
716
+                    $_storage_size." >= ".$set_storage_limit
717 717
                 ));
718 718
             }
719 719
 
720 720
             //processing rule days limit
721 721
             if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) {
722 722
                 $this->storage_filesystem->delete($file['path']);
723
-                $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
723
+                $this->logger->info("Deleting backup ".$file['path']." matching rule", array(
724 724
                     "RETENTION LIMIT TIMESTAMP",
725
-                    $file['timestamp'] . " =< " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')
725
+                    $file['timestamp']." =< ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')
726 726
                 ));
727 727
             }
728 728
 
@@ -730,9 +730,9 @@  discard block
 block discarded – undo
730 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 731
                 $this->storage_filesystem->delete($file['path']);
732 732
                 $_backups_counter--;
733
-                $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
733
+                $this->logger->info("Deleting backup ".$file['path']." matching rule", array(
734 734
                     "BACKUP QUANTITY LIMIT",
735
-                    $_backups_counter . " >= " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')
735
+                    $_backups_counter." >= ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')
736 736
                 ));
737 737
             }
738 738
 
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
             }
830 830
 
831 831
             if ($timestamp <= $this->get_diff_timestamp_start()) {
832
-                return " file DIFF timestamp " . $timestamp . " < " . $this->diff_timestamp_start;
832
+                return " file DIFF timestamp ".$timestamp." < ".$this->diff_timestamp_start;
833 833
             }
834 834
         }
835 835
 
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
 
843 843
         if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) {
844 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";
845
+                return "> ".$xcloner_exclude_files_larger_than_mb."MB";
846 846
             }
847 847
         }
848 848
 
@@ -855,10 +855,10 @@  discard block
 block discarded – undo
855 855
                 if ($excluded_file_pattern == "/") {
856 856
                     $needle = "$";
857 857
                 } else {
858
-                    $needle = "$" . $excluded_file_pattern;
858
+                    $needle = "$".$excluded_file_pattern;
859 859
                 }
860 860
 
861
-                if (strstr("$" . $file['path'], $needle)) {
861
+                if (strstr("$".$file['path'], $needle)) {
862 862
                     return $excluded_file_pattern;
863 863
                 }
864 864
             }
@@ -937,11 +937,11 @@  discard block
 block discarded – undo
937 937
                 if ($file['path'] == "/") {
938 938
                     $needle = "/";
939 939
                 } else {
940
-                    $needle = "/" . $file['path'];
940
+                    $needle = "/".$file['path'];
941 941
                 }
942 942
                 //echo $needle."---".$excluded_file_pattern."---\n";
943 943
 
944
-                if (@preg_match("/(^|^\/)" . $excluded_file_pattern . "/i", $needle)) {
944
+                if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) {
945 945
                     return $excluded_file_pattern;
946 946
                 }
947 947
             }
@@ -963,14 +963,14 @@  discard block
 block discarded – undo
963 963
 
964 964
         $csv_filename = str_replace('"', '""', $file['path']);
965 965
 
966
-        $line = '"' . ($csv_filename) . '","' . $file['timestamp'] . '","' . $file['size'] . '","' . $file['visibility'] . '","' . $storage . '"' . PHP_EOL;
966
+        $line = '"'.($csv_filename).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL;
967 967
 
968 968
         $this->last_logged_file = $file['path'];
969 969
 
970 970
         if ($file['type'] == "dir") {
971 971
             try {
972
-                $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path'] . "\n");
973
-            } catch (Exception $e) {
972
+                $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n");
973
+            }catch (Exception $e) {
974 974
                 $this->logger->error($e->getMessage());
975 975
             }
976 976
         }
@@ -990,13 +990,13 @@  discard block
 block discarded – undo
990 990
         try {
991 991
             if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) {
992 992
                 //adding fix for UTF-8 CSV preview
993
-                $start_line = "\xEF\xBB\xBF" . '"Filename","Timestamp","Size","Visibility","Storage"' . PHP_EOL;
993
+                $start_line = "\xEF\xBB\xBF".'"Filename","Timestamp","Size","Visibility","Storage"'.PHP_EOL;
994 994
                 $this->tmp_filesystem_append->write($this->get_included_files_handler(), $start_line);
995 995
             }
996 996
 
997 997
             $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
998 998
 
999
-        } catch (Exception $e) {
999
+        }catch (Exception $e) {
1000 1000
 
1001 1001
             $this->logger->error($e->getMessage());
1002 1002
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -707,9 +707,11 @@
 block discarded – undo
707 707
         foreach ($_backup_files_list as $file) {
708 708
             //processing rule folder capacity
709 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
710
+                $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) {
711
+            	//bytes
711 712
             {
712 713
                 $this->storage_filesystem->delete($file['path']);
714
+            }
713 715
                 $_storage_size -= $file['size'];
714 716
                 $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
715 717
                     "STORAGE SIZE LIMIT",
Please login to merge, or discard this patch.
includes/class-xcloner-file-transfer.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     }
53 53
 
54 54
     /**
55
-     * @return mixed
55
+     * @return string
56 56
      */
57 57
     public function get_target()
58 58
     {
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
     }
142 142
 
143 143
     /**
144
-     * @param $filename
144
+     * @param string $filename
145 145
      * @param string $mimetype
146 146
      * @param string $postname
147 147
      *
Please login to merge, or discard this patch.
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -29,136 +29,136 @@
 block discarded – undo
29 29
 class Xcloner_File_Transfer extends Xcloner_File_System
30 30
 {
31 31
 
32
-    /**
33
-     * Target url web address of the restore script
34
-     * @var string
35
-     */
36
-    private $target_url;
37
-    /**
38
-     * Transfer data limit in bytes
39
-     * @var int
40
-     */
41
-    private $transfer_limit = 1048576; //bytes 1MB= 1048576 300KB = 358400
32
+	/**
33
+	 * Target url web address of the restore script
34
+	 * @var string
35
+	 */
36
+	private $target_url;
37
+	/**
38
+	 * Transfer data limit in bytes
39
+	 * @var int
40
+	 */
41
+	private $transfer_limit = 1048576; //bytes 1MB= 1048576 300KB = 358400
42 42
 
43 43
 
44
-    /**
45
-     * @param $target_url
46
-     *
47
-     * @return mixed
48
-     */
49
-    public function set_target($target_url)
50
-    {
51
-        return $this->target_url = $target_url;
52
-    }
44
+	/**
45
+	 * @param $target_url
46
+	 *
47
+	 * @return mixed
48
+	 */
49
+	public function set_target($target_url)
50
+	{
51
+		return $this->target_url = $target_url;
52
+	}
53 53
 
54
-    /**
55
-     * @return mixed
56
-     */
57
-    public function get_target()
58
-    {
59
-        return $this->target_url;
60
-    }
54
+	/**
55
+	 * @return mixed
56
+	 */
57
+	public function get_target()
58
+	{
59
+		return $this->target_url;
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * @param $file
65
-     * @param int $start
66
-     * @param string $hash
67
-     *
68
-     * @return bool|int
69
-     * @throws Exception
70
-     */
71
-    public function transfer_file($file, $start = 0, $hash = "")
72
-    {
73
-        if (!$this->target_url) {
74
-            throw new Exception("Please setup a target url for upload");
75
-        }
63
+	/**
64
+	 * @param $file
65
+	 * @param int $start
66
+	 * @param string $hash
67
+	 *
68
+	 * @return bool|int
69
+	 * @throws Exception
70
+	 */
71
+	public function transfer_file($file, $start = 0, $hash = "")
72
+	{
73
+		if (!$this->target_url) {
74
+			throw new Exception("Please setup a target url for upload");
75
+		}
76 76
 
77 77
 
78
-        $fp = $this->get_storage_filesystem()->readStream($file);
78
+		$fp = $this->get_storage_filesystem()->readStream($file);
79 79
 
80
-        fseek($fp, $start, SEEK_SET);
80
+		fseek($fp, $start, SEEK_SET);
81 81
 
82
-        $binary_data = fread($fp, $this->transfer_limit);
82
+		$binary_data = fread($fp, $this->transfer_limit);
83 83
 
84
-        $tmp_filename = "xcloner_upload_" . substr(md5(time()), 0, 5);
84
+		$tmp_filename = "xcloner_upload_" . substr(md5(time()), 0, 5);
85 85
 
86
-        $this->get_tmp_filesystem()->write($tmp_filename, $binary_data);
86
+		$this->get_tmp_filesystem()->write($tmp_filename, $binary_data);
87 87
 
88
-        $tmp_file_path = $this->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_filename);
88
+		$tmp_file_path = $this->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_filename);
89 89
 
90
-        $send_array = array();
90
+		$send_array = array();
91 91
 
92
-        $send_array['file'] = $file;
93
-        $send_array['start'] = $start;
94
-        $send_array['xcloner_action'] = "write_file";
95
-        $send_array['hash'] = $hash;
96
-        #$send_array['blob'] 	= $binary_data;
97
-        $send_array['blob'] = $this->curl_file_create($tmp_file_path, 'application/x-binary', $tmp_filename);
92
+		$send_array['file'] = $file;
93
+		$send_array['start'] = $start;
94
+		$send_array['xcloner_action'] = "write_file";
95
+		$send_array['hash'] = $hash;
96
+		#$send_array['blob'] 	= $binary_data;
97
+		$send_array['blob'] = $this->curl_file_create($tmp_file_path, 'application/x-binary', $tmp_filename);
98 98
 
99
-        //$data = http_build_query($send_array);
99
+		//$data = http_build_query($send_array);
100 100
 
101
-        $this->get_logger()->info(sprintf("Sending curl request to %s with %s data of file %s starting position %s using temporary file %s",
102
-            $this->target_url, $this->transfer_limit, $file, $start, $tmp_filename));
101
+		$this->get_logger()->info(sprintf("Sending curl request to %s with %s data of file %s starting position %s using temporary file %s",
102
+			$this->target_url, $this->transfer_limit, $file, $start, $tmp_filename));
103 103
 
104 104
 
105
-        $ch = curl_init();
106
-        curl_setopt($ch, CURLOPT_URL, $this->target_url);
105
+		$ch = curl_init();
106
+		curl_setopt($ch, CURLOPT_URL, $this->target_url);
107 107
 
108
-        curl_setopt($ch, CURLOPT_POST, 1);
109
-        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
110
-        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
111
-        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
112
-        curl_setopt($ch, CURLOPT_TIMEOUT, 1200);
113
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
108
+		curl_setopt($ch, CURLOPT_POST, 1);
109
+		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
110
+		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
111
+		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
112
+		curl_setopt($ch, CURLOPT_TIMEOUT, 1200);
113
+		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
114 114
 
115
-        curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array);
116
-        curl_setopt($ch, CURLOPT_VERBOSE, true);
115
+		curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array);
116
+		curl_setopt($ch, CURLOPT_VERBOSE, true);
117 117
 
118
-        $original_result = curl_exec($ch);
118
+		$original_result = curl_exec($ch);
119 119
 
120
-        $this->get_tmp_filesystem()->delete($tmp_filename);
120
+		$this->get_tmp_filesystem()->delete($tmp_filename);
121 121
 
122
-        $result = json_decode($original_result);
122
+		$result = json_decode($original_result);
123 123
 
124
-        if (!$result) {
125
-            throw new Exception("We have received no valid response from the remote host, original message: " . $original_result);
126
-        }
124
+		if (!$result) {
125
+			throw new Exception("We have received no valid response from the remote host, original message: " . $original_result);
126
+		}
127 127
 
128
-        if ($result->status != 200) {
129
-            throw new Exception($result->response);
130
-        }
128
+		if ($result->status != 200) {
129
+			throw new Exception($result->response);
130
+		}
131 131
 
132
-        if (ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) {
133
-            $this->get_logger()->info(sprintf("Upload done for file %s to target url %s, transferred a total of %s bytes",
134
-                $file, $this->target_url, ftell($fp)));
135
-            $this->remove_tmp_filesystem();
132
+		if (ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) {
133
+			$this->get_logger()->info(sprintf("Upload done for file %s to target url %s, transferred a total of %s bytes",
134
+				$file, $this->target_url, ftell($fp)));
135
+			$this->remove_tmp_filesystem();
136 136
 
137
-            return false;
138
-        }
137
+			return false;
138
+		}
139 139
 
140
-        return ftell($fp);
141
-    }
140
+		return ftell($fp);
141
+	}
142 142
 
143
-    /**
144
-     * @param $filename
145
-     * @param string $mimetype
146
-     * @param string $postname
147
-     *
148
-     * @return CURLFile|string
149
-     */
150
-    private function curl_file_create($filename, $mimetype = '', $postname = '')
151
-    {
152
-        if (!function_exists('curl_file_create')) {
143
+	/**
144
+	 * @param $filename
145
+	 * @param string $mimetype
146
+	 * @param string $postname
147
+	 *
148
+	 * @return CURLFile|string
149
+	 */
150
+	private function curl_file_create($filename, $mimetype = '', $postname = '')
151
+	{
152
+		if (!function_exists('curl_file_create')) {
153 153
 
154
-            return "@$filename;filename="
155
-                . ($postname ?: basename($filename))
156
-                . ($mimetype ? ";type=$mimetype" : '');
154
+			return "@$filename;filename="
155
+				. ($postname ?: basename($filename))
156
+				. ($mimetype ? ";type=$mimetype" : '');
157 157
 
158
-        } else {
158
+		} else {
159 159
 
160
-            return curl_file_create($filename, $mimetype, $postname);
160
+			return curl_file_create($filename, $mimetype, $postname);
161 161
 
162
-        }
163
-    }
162
+		}
163
+	}
164 164
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 
82 82
         $binary_data = fread($fp, $this->transfer_limit);
83 83
 
84
-        $tmp_filename = "xcloner_upload_" . substr(md5(time()), 0, 5);
84
+        $tmp_filename = "xcloner_upload_".substr(md5(time()), 0, 5);
85 85
 
86 86
         $this->get_tmp_filesystem()->write($tmp_filename, $binary_data);
87 87
 
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
         $result = json_decode($original_result);
123 123
 
124 124
         if (!$result) {
125
-            throw new Exception("We have received no valid response from the remote host, original message: " . $original_result);
125
+            throw new Exception("We have received no valid response from the remote host, original message: ".$original_result);
126 126
         }
127 127
 
128 128
         if ($result->status != 200) {
Please login to merge, or discard this patch.
includes/class-xcloner-remote-storage.php 5 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -281,6 +281,9 @@
 block discarded – undo
281 281
 		}
282 282
 	}
283 283
 
284
+	/**
285
+	 * @param string $storage_type
286
+	 */
284 287
 	public function verify_filesystem( $storage_type ) {
285 288
 		$method = "get_" . $storage_type . "_filesystem";
286 289
 
Please login to merge, or discard this patch.
Unused Use Statements   -7 removed lines patch added patch discarded remove patch
@@ -28,23 +28,16 @@
 block discarded – undo
28 28
 
29 29
 use League\Flysystem\Config;
30 30
 use League\Flysystem\Filesystem;
31
-
32 31
 use League\Flysystem\Adapter\Ftp as Adapter;
33
-
34 32
 use League\Flysystem\Sftp\SftpAdapter;
35
-
36 33
 use Srmklive\Dropbox\Client\DropboxClient;
37 34
 use Srmklive\Dropbox\Adapter\DropboxAdapter;
38
-
39 35
 use MicrosoftAzure\Storage\Common\ServicesBuilder;
40 36
 use League\Flysystem\Azure\AzureAdapter;
41
-
42 37
 use Aws\S3\S3Client;
43 38
 use League\Flysystem\AwsS3v3\AwsS3Adapter;
44
-
45 39
 use Mhetreramesh\Flysystem\BackblazeAdapter;
46 40
 use BackblazeB2\Client as B2Client;
47
-
48 41
 use Sabre\DAV\Client as SabreClient;
49 42
 use League\Flysystem\WebDAV\WebDAVAdapter;
50 43
 
Please login to merge, or discard this 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.
Spacing   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -162,26 +162,26 @@  discard block
 block discarded – undo
162 162
 	private $logger;
163 163
 	private $xcloner;
164 164
 
165
-	public function __construct( Xcloner $xcloner_container ) {
165
+	public function __construct(Xcloner $xcloner_container) {
166 166
 		$this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization();
167 167
 		$this->xcloner_file_system  = $xcloner_container->get_xcloner_filesystem();
168
-		$this->logger               = $xcloner_container->get_xcloner_logger()->withName( "xcloner_remote_storage" );
168
+		$this->logger               = $xcloner_container->get_xcloner_logger()->withName("xcloner_remote_storage");
169 169
 		$this->xcloner              = $xcloner_container;
170 170
 
171
-		foreach($this->storage_fields as $main_key=>$array){
171
+		foreach ($this->storage_fields as $main_key=>$array) {
172 172
 
173
-		    if(is_array($array)) {
173
+		    if (is_array($array)) {
174 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 180
                                 return $this->simple_crypt($value, 'e');
181 181
 
182 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 186
                             return $this->simple_crypt($value, 'd');
187 187
 
@@ -201,22 +201,22 @@  discard block
 block discarded – undo
201 201
      * @param string $action
202 202
      * @return string
203 203
      */
204
-    private function simple_crypt( $string, $action = 'e' ) {
204
+    private function simple_crypt($string, $action = 'e') {
205 205
         // you may change these values to your own
206 206
         $secret_key = NONCE_KEY;
207 207
         $secret_iv = NONCE_SALT;
208 208
 
209 209
         $output = $string;
210 210
         $encrypt_method = "AES-256-CBC";
211
-        $key = hash( 'sha256', $secret_key );
212
-        $iv = substr( hash( 'sha256', $secret_iv ), 0, 16 );
211
+        $key = hash('sha256', $secret_key);
212
+        $iv = substr(hash('sha256', $secret_iv), 0, 16);
213 213
 
214
-        if( $action == 'e' && function_exists('openssl_encrypt')) {
215
-            $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) );
214
+        if ($action == 'e' && function_exists('openssl_encrypt')) {
215
+            $output = base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0, $iv));
216 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) {
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 220
                 //we check if decrypt was succesful
221 221
                 $output = $decrypt;
222 222
             }
@@ -231,118 +231,118 @@  discard block
 block discarded – undo
231 231
 
232 232
 	public function get_available_storages() {
233 233
 		$return = array();
234
-		foreach ( $this->storage_fields as $storage => $data ) {
235
-			$check_field = $this->storage_fields["option_prefix"] . $storage . "_enable";
236
-			if ( get_option( $check_field ) ) {
237
-				$return[ $storage ] = $data['text'];
234
+		foreach ($this->storage_fields as $storage => $data) {
235
+			$check_field = $this->storage_fields["option_prefix"].$storage."_enable";
236
+			if (get_option($check_field)) {
237
+				$return[$storage] = $data['text'];
238 238
 			}
239 239
 		}
240 240
 
241 241
 		return $return;
242 242
 	}
243 243
 
244
-	public function save( $action = "ftp" ) {
245
-		if ( ! $action ) {
244
+	public function save($action = "ftp") {
245
+		if (!$action) {
246 246
 			return false;
247 247
 		}
248 248
 
249
-		$storage = $this->xcloner_sanitization->sanitize_input_as_string( $action );
250
-		$this->logger->debug( sprintf( "Saving the remote storage %s options", strtoupper( $action ) ) );
249
+		$storage = $this->xcloner_sanitization->sanitize_input_as_string($action);
250
+		$this->logger->debug(sprintf("Saving the remote storage %s options", strtoupper($action)));
251 251
 
252
-		if ( is_array( $this->storage_fields[ $storage ] ) ) {
253
-			foreach ( $this->storage_fields[ $storage ] as $field => $validation ) {
254
-				$check_field     = $this->storage_fields["option_prefix"] . $field;
255
-				$sanitize_method = "sanitize_input_as_" . $validation;
252
+		if (is_array($this->storage_fields[$storage])) {
253
+			foreach ($this->storage_fields[$storage] as $field => $validation) {
254
+				$check_field     = $this->storage_fields["option_prefix"].$field;
255
+				$sanitize_method = "sanitize_input_as_".$validation;
256 256
 
257
-				if ( ! isset( $_POST[ $check_field ] ) ) {
258
-					$_POST[ $check_field ] = 0;
257
+				if (!isset($_POST[$check_field])) {
258
+					$_POST[$check_field] = 0;
259 259
 				}
260 260
 
261
-				if ( ! method_exists( $this->xcloner_sanitization, $sanitize_method ) ) {
261
+				if (!method_exists($this->xcloner_sanitization, $sanitize_method)) {
262 262
 					$sanitize_method = "sanitize_input_as_string";
263 263
 				}
264 264
 
265
-				$sanitized_value = $this->xcloner_sanitization->$sanitize_method( stripslashes( $_POST[ $check_field ] ) );
266
-				update_option( $check_field, $sanitized_value );
265
+				$sanitized_value = $this->xcloner_sanitization->$sanitize_method(stripslashes($_POST[$check_field]));
266
+				update_option($check_field, $sanitized_value);
267 267
 			}
268 268
 
269
-			$this->xcloner->trigger_message( __( "%s storage settings saved.", 'xcloner-backup-and-restore' ), "success", $this->storage_fields[ $action ]['text'] );
269
+			$this->xcloner->trigger_message(__("%s storage settings saved.", 'xcloner-backup-and-restore'), "success", $this->storage_fields[$action]['text']);
270 270
 		}
271 271
 
272 272
 	}
273 273
 
274
-	public function check( $action = "ftp" ) {
274
+	public function check($action = "ftp") {
275 275
 		try {
276
-			$this->verify_filesystem( $action );
277
-			$this->xcloner->trigger_message( __( "%s connection is valid.", 'xcloner-backup-and-restore' ), "success", $this->storage_fields[ $action ]['text'] );
278
-			$this->logger->debug( sprintf( "Connection to remote storage %s is valid", strtoupper( $action ) ) );
279
-		} catch ( Exception $e ) {
280
-			$this->xcloner->trigger_message( "%s connection error: " . $e->getMessage(), "error", $this->storage_fields[ $action ]['text'] );
276
+			$this->verify_filesystem($action);
277
+			$this->xcloner->trigger_message(__("%s connection is valid.", 'xcloner-backup-and-restore'), "success", $this->storage_fields[$action]['text']);
278
+			$this->logger->debug(sprintf("Connection to remote storage %s is valid", strtoupper($action)));
279
+		}catch (Exception $e) {
280
+			$this->xcloner->trigger_message("%s connection error: ".$e->getMessage(), "error", $this->storage_fields[$action]['text']);
281 281
 		}
282 282
 	}
283 283
 
284
-	public function verify_filesystem( $storage_type ) {
285
-		$method = "get_" . $storage_type . "_filesystem";
284
+	public function verify_filesystem($storage_type) {
285
+		$method = "get_".$storage_type."_filesystem";
286 286
 
287
-		$this->logger->info( sprintf( "Checking validity of the remote storage %s filesystem", strtoupper( $storage_type ) ) );
287
+		$this->logger->info(sprintf("Checking validity of the remote storage %s filesystem", strtoupper($storage_type)));
288 288
 
289
-		if ( ! method_exists( $this, $method ) ) {
289
+		if (!method_exists($this, $method)) {
290 290
 			return false;
291 291
 		}
292 292
 
293
-		list( $adapter, $filesystem ) = $this->$method();
293
+		list($adapter, $filesystem) = $this->$method();
294 294
 
295
-		$test_file = substr( ".xcloner_" . md5( time() ), 0, 15 );
295
+		$test_file = substr(".xcloner_".md5(time()), 0, 15);
296 296
 
297
-		if ( $storage_type == "gdrive" ) {
298
-			if ( ! is_array( $filesystem->listContents() ) ) {
299
-				throw new Exception( __( "Could not read data", 'xcloner-backup-and-restore' ) );
297
+		if ($storage_type == "gdrive") {
298
+			if (!is_array($filesystem->listContents())) {
299
+				throw new Exception(__("Could not read data", 'xcloner-backup-and-restore'));
300 300
 			}
301
-			$this->logger->debug( sprintf( "I can list data from remote storage %s", strtoupper( $storage_type ) ) );
301
+			$this->logger->debug(sprintf("I can list data from remote storage %s", strtoupper($storage_type)));
302 302
 
303 303
 			return true;
304 304
 		}
305 305
 
306 306
 		//testing write access
307
-		if ( ! $filesystem->write( $test_file, "data" ) ) {
308
-			throw new Exception( __( "Could not write data", 'xcloner-backup-and-restore' ) );
307
+		if (!$filesystem->write($test_file, "data")) {
308
+			throw new Exception(__("Could not write data", 'xcloner-backup-and-restore'));
309 309
 		}
310
-		$this->logger->debug( sprintf( "I can write data to remote storage %s", strtoupper( $storage_type ) ) );
310
+		$this->logger->debug(sprintf("I can write data to remote storage %s", strtoupper($storage_type)));
311 311
 
312 312
 		//testing read access
313
-		if ( ! $filesystem->has( $test_file ) ) {
314
-			throw new Exception( __( "Could not read data", 'xcloner-backup-and-restore' ) );
313
+		if (!$filesystem->has($test_file)) {
314
+			throw new Exception(__("Could not read data", 'xcloner-backup-and-restore'));
315 315
 		}
316
-		$this->logger->debug( sprintf( "I can read data to remote storage %s", strtoupper( $storage_type ) ) );
316
+		$this->logger->debug(sprintf("I can read data to remote storage %s", strtoupper($storage_type)));
317 317
 
318 318
 		//delete test file
319
-		if ( ! $filesystem->delete( $test_file ) ) {
320
-			throw new Exception( __( "Could not delete data", 'xcloner-backup-and-restore' ) );
319
+		if (!$filesystem->delete($test_file)) {
320
+			throw new Exception(__("Could not delete data", 'xcloner-backup-and-restore'));
321 321
 		}
322
-		$this->logger->debug( sprintf( "I can delete data to remote storage %s", strtoupper( $storage_type ) ) );
322
+		$this->logger->debug(sprintf("I can delete data to remote storage %s", strtoupper($storage_type)));
323 323
 
324 324
 		return true;
325 325
 	}
326 326
 
327
-	public function upload_backup_to_storage( $file, $storage ) {
328
-		if ( ! $this->xcloner_file_system->get_storage_filesystem()->has( $file ) ) {
329
-			$this->logger->info( sprintf( "File not found %s in local storage", $file ) );
327
+	public function upload_backup_to_storage($file, $storage) {
328
+		if (!$this->xcloner_file_system->get_storage_filesystem()->has($file)) {
329
+			$this->logger->info(sprintf("File not found %s in local storage", $file));
330 330
 
331 331
 			return false;
332 332
 		}
333 333
 
334
-		$method = "get_" . $storage . "_filesystem";
334
+		$method = "get_".$storage."_filesystem";
335 335
 
336
-		if ( ! method_exists( $this, $method ) ) {
336
+		if (!method_exists($this, $method)) {
337 337
 			return false;
338 338
 		}
339 339
 
340
-		list( $remote_storage_adapter, $remote_storage_filesystem ) = $this->$method();
340
+		list($remote_storage_adapter, $remote_storage_filesystem) = $this->$method();
341 341
 
342 342
 		//doing remote storage cleaning here
343
-		$this->clean_remote_storage( $storage, $remote_storage_filesystem );
343
+		$this->clean_remote_storage($storage, $remote_storage_filesystem);
344 344
 
345
-		$this->logger->info( sprintf( "Transferring backup %s to remote storage %s", $file, strtoupper( $storage ) ), array( "" ) );
345
+		$this->logger->info(sprintf("Transferring backup %s to remote storage %s", $file, strtoupper($storage)), array(""));
346 346
 
347 347
 		/*if(!$this->xcloner_file_system->get_storage_filesystem()->has($file))
348 348
 		{
@@ -350,104 +350,104 @@  discard block
 block discarded – undo
350 350
 			return false;
351 351
 		}*/
352 352
 
353
-		$backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream( $file );
353
+		$backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($file);
354 354
 
355
-		if ( ! $remote_storage_filesystem->writeStream( $file, $backup_file_stream ) ) {
356
-			$this->logger->info( sprintf( "Could not transfer file %s", $file ) );
355
+		if (!$remote_storage_filesystem->writeStream($file, $backup_file_stream)) {
356
+			$this->logger->info(sprintf("Could not transfer file %s", $file));
357 357
 
358 358
 			return false;
359 359
 		}
360 360
 
361
-		if ( $this->xcloner_file_system->is_multipart( $file ) ) {
362
-			$parts = $this->xcloner_file_system->get_multipart_files( $file );
363
-			if ( is_array( $parts ) ) {
364
-				foreach ( $parts as $part_file ) {
365
-					$this->logger->info( sprintf( "Transferring backup %s to remote storage %s", $part_file, strtoupper( $storage ) ), array( "" ) );
361
+		if ($this->xcloner_file_system->is_multipart($file)) {
362
+			$parts = $this->xcloner_file_system->get_multipart_files($file);
363
+			if (is_array($parts)) {
364
+				foreach ($parts as $part_file) {
365
+					$this->logger->info(sprintf("Transferring backup %s to remote storage %s", $part_file, strtoupper($storage)), array(""));
366 366
 
367
-					$backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream( $part_file );
368
-					if ( ! $remote_storage_filesystem->writeStream( $part_file, $backup_file_stream ) ) {
367
+					$backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($part_file);
368
+					if (!$remote_storage_filesystem->writeStream($part_file, $backup_file_stream)) {
369 369
 						return false;
370 370
 					}
371 371
 				}
372 372
 			}
373 373
 		}
374 374
 
375
-		$this->logger->info( sprintf( "Upload done, disconnecting from remote storage %s", strtoupper( $storage ) ) );
375
+		$this->logger->info(sprintf("Upload done, disconnecting from remote storage %s", strtoupper($storage)));
376 376
 
377 377
 		return true;
378 378
 
379 379
 	}
380 380
 
381
-	public function copy_backup_remote_to_local( $file, $storage ) {
382
-		$method = "get_" . $storage . "_filesystem";
381
+	public function copy_backup_remote_to_local($file, $storage) {
382
+		$method = "get_".$storage."_filesystem";
383 383
 
384 384
 		$target_filename = $file;
385 385
 
386
-		if ( ! method_exists( $this, $method ) ) {
386
+		if (!method_exists($this, $method)) {
387 387
 			return false;
388 388
 		}
389 389
 
390
-		list( $remote_storage_adapter, $remote_storage_filesystem ) = $this->$method();
390
+		list($remote_storage_adapter, $remote_storage_filesystem) = $this->$method();
391 391
 
392
-		if ( ! $remote_storage_filesystem->has( $file ) ) {
393
-			$this->logger->info( sprintf( "File not found %s in remote storage %s", $file, strtoupper( $storage ) ) );
392
+		if (!$remote_storage_filesystem->has($file)) {
393
+			$this->logger->info(sprintf("File not found %s in remote storage %s", $file, strtoupper($storage)));
394 394
 
395 395
 			return false;
396 396
 		}
397 397
 
398
-		if ( $storage == "gdrive" ) {
399
-			$metadata        = $remote_storage_filesystem->getMetadata( $file );
400
-			$target_filename = $metadata['filename'] . "." . $metadata['extension'];
398
+		if ($storage == "gdrive") {
399
+			$metadata        = $remote_storage_filesystem->getMetadata($file);
400
+			$target_filename = $metadata['filename'].".".$metadata['extension'];
401 401
 		}
402 402
 
403
-		$this->logger->info( sprintf( "Transferring backup %s to local storage from %s storage", $file, strtoupper( $storage ) ), array( "" ) );
403
+		$this->logger->info(sprintf("Transferring backup %s to local storage from %s storage", $file, strtoupper($storage)), array(""));
404 404
 
405
-		$backup_file_stream = $remote_storage_filesystem->readStream( $file );
405
+		$backup_file_stream = $remote_storage_filesystem->readStream($file);
406 406
 
407
-		if ( ! $this->xcloner_file_system->get_storage_filesystem()->writeStream( $target_filename, $backup_file_stream ) ) {
408
-			$this->logger->info( sprintf( "Could not transfer file %s", $file ) );
407
+		if (!$this->xcloner_file_system->get_storage_filesystem()->writeStream($target_filename, $backup_file_stream)) {
408
+			$this->logger->info(sprintf("Could not transfer file %s", $file));
409 409
 
410 410
 			return false;
411 411
 		}
412 412
 
413
-		if ( $this->xcloner_file_system->is_multipart( $target_filename ) ) {
414
-			$parts = $this->xcloner_file_system->get_multipart_files( $file, $storage );
415
-			if ( is_array( $parts ) ) {
416
-				foreach ( $parts as $part_file ) {
417
-					$this->logger->info( sprintf( "Transferring backup %s to local storage from %s storage", $part_file, strtoupper( $storage ) ), array( "" ) );
413
+		if ($this->xcloner_file_system->is_multipart($target_filename)) {
414
+			$parts = $this->xcloner_file_system->get_multipart_files($file, $storage);
415
+			if (is_array($parts)) {
416
+				foreach ($parts as $part_file) {
417
+					$this->logger->info(sprintf("Transferring backup %s to local storage from %s storage", $part_file, strtoupper($storage)), array(""));
418 418
 
419
-					$backup_file_stream = $remote_storage_filesystem->readStream( $part_file );
420
-					if ( ! $this->xcloner_file_system->get_storage_filesystem()->writeStream( $part_file, $backup_file_stream ) ) {
419
+					$backup_file_stream = $remote_storage_filesystem->readStream($part_file);
420
+					if (!$this->xcloner_file_system->get_storage_filesystem()->writeStream($part_file, $backup_file_stream)) {
421 421
 						return false;
422 422
 					}
423 423
 				}
424 424
 			}
425 425
 		}
426 426
 
427
-		$this->logger->info( sprintf( "Upload done, disconnecting from remote storage %s", strtoupper( $storage ) ) );
427
+		$this->logger->info(sprintf("Upload done, disconnecting from remote storage %s", strtoupper($storage)));
428 428
 
429 429
 		return true;
430 430
 
431 431
 	}
432 432
 
433
-	public function clean_remote_storage( $storage, $remote_storage_filesystem ) {
434
-		$check_field = $this->storage_fields["option_prefix"] . $storage . "_cleanup_days";
435
-		if ( $expire_days = get_option( $check_field ) ) {
436
-			$this->logger->info( sprintf( "Doing %s remote storage cleanup for %s days limit", strtoupper( $storage ), $expire_days ) );
433
+	public function clean_remote_storage($storage, $remote_storage_filesystem) {
434
+		$check_field = $this->storage_fields["option_prefix"].$storage."_cleanup_days";
435
+		if ($expire_days = get_option($check_field)) {
436
+			$this->logger->info(sprintf("Doing %s remote storage cleanup for %s days limit", strtoupper($storage), $expire_days));
437 437
 			$files = $remote_storage_filesystem->listContents();
438 438
 
439
-			$current_timestamp = strtotime( "-" . $expire_days . " days" );
439
+			$current_timestamp = strtotime("-".$expire_days." days");
440 440
 
441
-			if ( is_array( $files ) ) {
442
-				foreach ( $files as $file ) {
443
-					$file['timestamp'] = $remote_storage_filesystem->getTimestamp( $file['path'] );
441
+			if (is_array($files)) {
442
+				foreach ($files as $file) {
443
+					$file['timestamp'] = $remote_storage_filesystem->getTimestamp($file['path']);
444 444
 
445
-					if ( $current_timestamp >= $file['timestamp'] ) {
446
-						$remote_storage_filesystem->delete( $file['path'] );
447
-						$this->logger->info( "Deleting remote file " . $file['path'] . " matching rule", array(
445
+					if ($current_timestamp >= $file['timestamp']) {
446
+						$remote_storage_filesystem->delete($file['path']);
447
+						$this->logger->info("Deleting remote file ".$file['path']." matching rule", array(
448 448
 							"RETENTION LIMIT TIMESTAMP",
449
-							$file['timestamp'] . " =< " . $expire_days
450
-						) );
449
+							$file['timestamp']." =< ".$expire_days
450
+						));
451 451
 					}
452 452
 
453 453
 				}
@@ -456,153 +456,153 @@  discard block
 block discarded – undo
456 456
 	}
457 457
 
458 458
 	public function get_azure_filesystem() {
459
-		$this->logger->info( sprintf( "Creating the AZURE BLOB remote storage connection" ), array( "" ) );
459
+		$this->logger->info(sprintf("Creating the AZURE BLOB remote storage connection"), array(""));
460 460
 
461
-		if ( version_compare( phpversion(), '5.6.0', '<' ) ) {
462
-			throw new Exception( "AZURE BLOB requires PHP 5.6 to be installed!" );
461
+		if (version_compare(phpversion(), '5.6.0', '<')) {
462
+			throw new Exception("AZURE BLOB requires PHP 5.6 to be installed!");
463 463
 		}
464 464
 
465
-		if ( ! class_exists( 'XmlWriter' ) ) {
466
-			throw new Exception( "AZURE BLOB requires libxml PHP module to be installed with XmlWriter class enabled!" );
465
+		if (!class_exists('XmlWriter')) {
466
+			throw new Exception("AZURE BLOB requires libxml PHP module to be installed with XmlWriter class enabled!");
467 467
 		}
468 468
 
469 469
 		$endpoint = sprintf(
470 470
 			'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s',
471
-			get_option( "xcloner_azure_account_name" ),
472
-			get_option( "xcloner_azure_api_key" )
471
+			get_option("xcloner_azure_account_name"),
472
+			get_option("xcloner_azure_api_key")
473 473
 		);
474 474
 
475
-		$blobRestProxy = ServicesBuilder::getInstance()->createBlobService( $endpoint );
475
+		$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($endpoint);
476 476
 
477
-		$adapter = new AzureAdapter( $blobRestProxy, get_option( "xcloner_azure_container" ) );
477
+		$adapter = new AzureAdapter($blobRestProxy, get_option("xcloner_azure_container"));
478 478
 
479
-		$filesystem = new Filesystem( $adapter, new Config( [
479
+		$filesystem = new Filesystem($adapter, new Config([
480 480
 			'disable_asserts' => true,
481
-		] ) );
481
+		]));
482 482
 
483
-		return array( $adapter, $filesystem );
483
+		return array($adapter, $filesystem);
484 484
 	}
485 485
 
486 486
 	public function get_dropbox_filesystem() {
487
-		$this->logger->info( sprintf( "Creating the DROPBOX remote storage connection" ), array( "" ) );
487
+		$this->logger->info(sprintf("Creating the DROPBOX remote storage connection"), array(""));
488 488
 
489
-		if ( version_compare( phpversion(), '5.6.0', '<' ) ) {
490
-			throw new Exception( "DROPBOX requires PHP 5.6 to be installed!" );
489
+		if (version_compare(phpversion(), '5.6.0', '<')) {
490
+			throw new Exception("DROPBOX requires PHP 5.6 to be installed!");
491 491
 		}
492 492
 
493
-		$client  = new DropboxClient( get_option( "xcloner_dropbox_access_token" ) );
494
-		$adapter = new DropboxAdapter( $client, get_option( "xcloner_dropbox_prefix" ) );
493
+		$client  = new DropboxClient(get_option("xcloner_dropbox_access_token"));
494
+		$adapter = new DropboxAdapter($client, get_option("xcloner_dropbox_prefix"));
495 495
 
496
-		$filesystem = new Filesystem( $adapter, new Config( [
496
+		$filesystem = new Filesystem($adapter, new Config([
497 497
 			'disable_asserts' => true,
498
-		] ) );
498
+		]));
499 499
 
500
-		return array( $adapter, $filesystem );
500
+		return array($adapter, $filesystem);
501 501
 	}
502 502
 
503 503
 	public function get_aws_filesystem() {
504
-		$this->logger->info( sprintf( "Creating the S3 remote storage connection" ), array( "" ) );
504
+		$this->logger->info(sprintf("Creating the S3 remote storage connection"), array(""));
505 505
 
506
-		if ( version_compare( phpversion(), '5.6.0', '<' ) ) {
507
-			throw new Exception( "S3 class requires PHP 5.6 to be installed!" );
506
+		if (version_compare(phpversion(), '5.6.0', '<')) {
507
+			throw new Exception("S3 class requires PHP 5.6 to be installed!");
508 508
 		}
509 509
 
510
-		if ( ! class_exists( 'XmlWriter' ) ) {
511
-			throw new Exception( "AZURE BLOB requires libxml PHP module to be installed with XmlWriter class enabled!" );
510
+		if (!class_exists('XmlWriter')) {
511
+			throw new Exception("AZURE BLOB requires libxml PHP module to be installed with XmlWriter class enabled!");
512 512
 		}
513 513
 
514 514
 
515 515
 		$credentials = array(
516 516
 			'credentials' => array(
517
-				'key'    => get_option( "xcloner_aws_key" ),
518
-				'secret' => get_option( "xcloner_aws_secret" )
517
+				'key'    => get_option("xcloner_aws_key"),
518
+				'secret' => get_option("xcloner_aws_secret")
519 519
 			),
520
-			'region'      => get_option( "xcloner_aws_region" ),
520
+			'region'      => get_option("xcloner_aws_region"),
521 521
 			'version'     => 'latest',
522 522
 		);
523 523
 
524
-		if ( get_option( 'xcloner_aws_endpoint' ) != "" && ! get_option( "xcloner_aws_region" ) ) {
524
+		if (get_option('xcloner_aws_endpoint') != "" && !get_option("xcloner_aws_region")) {
525 525
 
526
-			$credentials['endpoint'] = get_option( 'xcloner_aws_endpoint' );
526
+			$credentials['endpoint'] = get_option('xcloner_aws_endpoint');
527 527
 			#$credentials['use_path_style_endpoint'] = true;
528 528
 			#$credentials['bucket_endpoint'] = false;
529 529
 
530 530
 
531 531
 		}
532 532
 
533
-		$client = new S3Client( $credentials );
533
+		$client = new S3Client($credentials);
534 534
 
535
-		$adapter    = new AwsS3Adapter( $client, get_option( "xcloner_aws_bucket_name" ), get_option( "xcloner_aws_prefix" ) );
536
-		$filesystem = new Filesystem( $adapter, new Config( [
535
+		$adapter    = new AwsS3Adapter($client, get_option("xcloner_aws_bucket_name"), get_option("xcloner_aws_prefix"));
536
+		$filesystem = new Filesystem($adapter, new Config([
537 537
 			'disable_asserts' => true,
538
-		] ) );
538
+		]));
539 539
 
540
-		return array( $adapter, $filesystem );
540
+		return array($adapter, $filesystem);
541 541
 	}
542 542
 
543 543
 	public function get_backblaze_filesystem() {
544
-		$this->logger->info( sprintf( "Creating the BACKBLAZE remote storage connection" ), array( "" ) );
544
+		$this->logger->info(sprintf("Creating the BACKBLAZE remote storage connection"), array(""));
545 545
 
546
-		if ( version_compare( phpversion(), '5.6.0', '<' ) ) {
547
-			throw new Exception( "BACKBLAZE API requires PHP 5.6 to be installed!" );
546
+		if (version_compare(phpversion(), '5.6.0', '<')) {
547
+			throw new Exception("BACKBLAZE API requires PHP 5.6 to be installed!");
548 548
 		}
549 549
 
550 550
 
551
-		$client  = new B2Client( get_option( "xcloner_backblaze_account_id" ), get_option( "xcloner_backblaze_application_key" ) );
552
-		$adapter = new BackblazeAdapter( $client, get_option( "xcloner_backblaze_bucket_name" ) );
551
+		$client  = new B2Client(get_option("xcloner_backblaze_account_id"), get_option("xcloner_backblaze_application_key"));
552
+		$adapter = new BackblazeAdapter($client, get_option("xcloner_backblaze_bucket_name"));
553 553
 
554
-		$filesystem = new Filesystem( $adapter, new Config( [
554
+		$filesystem = new Filesystem($adapter, new Config([
555 555
 			'disable_asserts' => true,
556
-		] ) );
556
+		]));
557 557
 
558
-		return array( $adapter, $filesystem );
558
+		return array($adapter, $filesystem);
559 559
 	}
560 560
 
561 561
 	public function get_webdav_filesystem() {
562
-		$this->logger->info( sprintf( "Creating the WEBDAV remote storage connection" ), array( "" ) );
562
+		$this->logger->info(sprintf("Creating the WEBDAV remote storage connection"), array(""));
563 563
 
564
-		if ( version_compare( phpversion(), '5.6.0', '<' ) ) {
565
-			throw new Exception( "WEBDAV API requires PHP 5.6 to be installed!" );
564
+		if (version_compare(phpversion(), '5.6.0', '<')) {
565
+			throw new Exception("WEBDAV API requires PHP 5.6 to be installed!");
566 566
 		}
567 567
 
568 568
 		$settings = array(
569
-			'baseUri'  => get_option( "xcloner_webdav_url" ),
570
-			'userName' => get_option( "xcloner_webdav_username" ),
571
-			'password' => get_option( "xcloner_webdav_password" ),
569
+			'baseUri'  => get_option("xcloner_webdav_url"),
570
+			'userName' => get_option("xcloner_webdav_username"),
571
+			'password' => get_option("xcloner_webdav_password"),
572 572
 			//'proxy' => 'locahost:8888',
573 573
 		);
574 574
 
575 575
 
576
-		$client     = new SabreClient( $settings );
577
-		$adapter    = new WebDAVAdapter( $client, get_option( "xcloner_webdav_target_folder" ) );
578
-		$filesystem = new Filesystem( $adapter, new Config( [
576
+		$client     = new SabreClient($settings);
577
+		$adapter    = new WebDAVAdapter($client, get_option("xcloner_webdav_target_folder"));
578
+		$filesystem = new Filesystem($adapter, new Config([
579 579
 			'disable_asserts' => true,
580
-		] ) );
580
+		]));
581 581
 
582
-		return array( $adapter, $filesystem );
582
+		return array($adapter, $filesystem);
583 583
 	}
584 584
 
585 585
 
586 586
 	public function gdrive_construct() {
587 587
 
588 588
 		//if((function_exists("is_plugin_active") && !is_plugin_active("xcloner-google-drive/xcloner-google-drive.php")) || !file_exists(__DIR__ . "/../../xcloner-google-drive/vendor/autoload.php"))
589
-		if ( ! class_exists( 'Google_Client' ) ) {
589
+		if (!class_exists('Google_Client')) {
590 590
 			return false;
591 591
 		}
592 592
 
593 593
 		//require_once(__DIR__ . "/../../xcloner-google-drive/vendor/autoload.php");
594 594
 
595 595
 		$client = new \Google_Client();
596
-		$client->setApplicationName( $this->gdrive_app_name );
597
-		$client->setClientId( get_option( "xcloner_gdrive_client_id" ) );
598
-		$client->setClientSecret( get_option( "xcloner_gdrive_client_secret" ) );
596
+		$client->setApplicationName($this->gdrive_app_name);
597
+		$client->setClientId(get_option("xcloner_gdrive_client_id"));
598
+		$client->setClientSecret(get_option("xcloner_gdrive_client_secret"));
599 599
 
600 600
 		//$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']."?page=xcloner_remote_storage_page&action=set_gdrive_code";
601 601
 		$redirect_uri = "urn:ietf:wg:oauth:2.0:oob";
602 602
 
603
-		$client->setRedirectUri( $redirect_uri ); //urn:ietf:wg:oauth:2.0:oob
604
-		$client->addScope( "https://www.googleapis.com/auth/drive" );
605
-		$client->setAccessType( 'offline' );
603
+		$client->setRedirectUri($redirect_uri); //urn:ietf:wg:oauth:2.0:oob
604
+		$client->addScope("https://www.googleapis.com/auth/drive");
605
+		$client->setAccessType('offline');
606 606
 
607 607
 		return $client;
608 608
 	}
@@ -610,30 +610,30 @@  discard block
 block discarded – undo
610 610
 	public function get_gdrive_auth_url() {
611 611
 		$client = $this->gdrive_construct();
612 612
 
613
-		if ( ! $client ) {
613
+		if (!$client) {
614 614
 			return false;
615 615
 		}
616 616
 
617 617
 		return $authUrl = $client->createAuthUrl();
618 618
 	}
619 619
 
620
-	public function set_access_token( $code ) {
620
+	public function set_access_token($code) {
621 621
 		$client = $this->gdrive_construct();
622 622
 
623
-		if ( ! $client ) {
623
+		if (!$client) {
624 624
 			$error_msg = "Could not initialize the Google Drive Class, please check that the xcloner-google-drive plugin is enabled...";
625
-			$this->logger->error( $error_msg );
625
+			$this->logger->error($error_msg);
626 626
 
627 627
 			return false;
628 628
 		}
629 629
 
630
-		$token = $client->fetchAccessTokenWithAuthCode( $code );
631
-		$client->setAccessToken( $token );
630
+		$token = $client->fetchAccessTokenWithAuthCode($code);
631
+		$client->setAccessToken($token);
632 632
 
633
-		update_option( "xcloner_gdrive_access_token", $token['access_token'] );
634
-		update_option( "xcloner_gdrive_refresh_token", $token['refresh_token'] );
633
+		update_option("xcloner_gdrive_access_token", $token['access_token']);
634
+		update_option("xcloner_gdrive_refresh_token", $token['refresh_token']);
635 635
 
636
-		$redirect_url = ( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "?page=xcloner_remote_storage_page#gdrive" );
636
+		$redirect_url = ('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?page=xcloner_remote_storage_page#gdrive");
637 637
 
638 638
 		?>
639 639
         <script>
@@ -649,23 +649,23 @@  discard block
 block discarded – undo
649 649
 	 */
650 650
 	public function get_gdrive_filesystem() {
651 651
 
652
-		if ( version_compare( phpversion(), '5.6.0', '<' ) ) {
653
-			throw new Exception( "Google Drive API requires PHP 5.6 to be installed!" );
652
+		if (version_compare(phpversion(), '5.6.0', '<')) {
653
+			throw new Exception("Google Drive API requires PHP 5.6 to be installed!");
654 654
 		}
655 655
 
656
-		$this->logger->info( sprintf( "Creating the Google Drive remote storage connection" ), array( "" ) );
656
+		$this->logger->info(sprintf("Creating the Google Drive remote storage connection"), array(""));
657 657
 
658 658
 		$client = $this->gdrive_construct();
659 659
 
660
-		if ( ! $client ) {
660
+		if (!$client) {
661 661
 			$error_msg = "Could not initialize the Google Drive Class, please check that the xcloner-google-drive plugin is enabled...";
662
-			$this->logger->error( $error_msg );
663
-			throw new Exception( $error_msg );
662
+			$this->logger->error($error_msg);
663
+			throw new Exception($error_msg);
664 664
 		}
665 665
 
666
-		$client->refreshToken( get_option( "xcloner_gdrive_refresh_token" ) );
666
+		$client->refreshToken(get_option("xcloner_gdrive_refresh_token"));
667 667
 
668
-		$service = new \Google_Service_Drive( $client );
668
+		$service = new \Google_Service_Drive($client);
669 669
 
670 670
 		/*if( get_option("xcloner_gdrive_empty_trash",0) ){
671 671
 			$this->logger->info(sprintf("Doing a Google Drive emptyTrash call"), array(""));
@@ -673,102 +673,102 @@  discard block
 block discarded – undo
673 673
 		}*/
674 674
 
675 675
 		$parent = 'root';
676
-		$dir    = basename( get_option( "xcloner_gdrive_target_folder" ) );
676
+		$dir    = basename(get_option("xcloner_gdrive_target_folder"));
677 677
 
678
-		$folderID = get_option( "xcloner_gdrive_target_folder" );
678
+		$folderID = get_option("xcloner_gdrive_target_folder");
679 679
 
680
-		$tmp = parse_url( $folderID );
680
+		$tmp = parse_url($folderID);
681 681
 
682
-		if ( isset( $tmp['query'] ) ) {
683
-			$folderID = str_replace( "id=", "", $tmp['query'] );
682
+		if (isset($tmp['query'])) {
683
+			$folderID = str_replace("id=", "", $tmp['query']);
684 684
 		}
685 685
 
686
-		if ( stristr( $folderID, "/" ) ) {
687
-			$query    = sprintf( 'mimeType = \'application/vnd.google-apps.folder\' and \'%s\' in parents and name contains \'%s\'', $parent, $dir );
688
-			$response = $service->files->listFiles( [
686
+		if (stristr($folderID, "/")) {
687
+			$query    = sprintf('mimeType = \'application/vnd.google-apps.folder\' and \'%s\' in parents and name contains \'%s\'', $parent, $dir);
688
+			$response = $service->files->listFiles([
689 689
 				'pageSize' => 1,
690 690
 				'q'        => $query
691
-			] );
691
+			]);
692 692
 
693
-			if ( sizeof( $response ) ) {
694
-				foreach ( $response as $obj ) {
693
+			if (sizeof($response)) {
694
+				foreach ($response as $obj) {
695 695
 					$folderID = $obj->getId();
696 696
 				}
697 697
 			} else {
698
-				$this->xcloner->trigger_message( sprintf( __( "Could not find folder ID by name %s", 'xcloner-backup-and-restore' ), $folderID ), "error" );
698
+				$this->xcloner->trigger_message(sprintf(__("Could not find folder ID by name %s", 'xcloner-backup-and-restore'), $folderID), "error");
699 699
 			}
700 700
 		}
701 701
 
702
-		$this->logger->info( sprintf( "Using target folder with ID %s on the remote storage", $folderID ) );
702
+		$this->logger->info(sprintf("Using target folder with ID %s on the remote storage", $folderID));
703 703
 
704
-		if ( class_exists( 'XCloner_Google_Drive_Adapter' ) ) {
705
-			$adapter = new XCloner_Google_Drive_Adapter( $service, $folderID );
704
+		if (class_exists('XCloner_Google_Drive_Adapter')) {
705
+			$adapter = new XCloner_Google_Drive_Adapter($service, $folderID);
706 706
 		} else {
707
-			$adapter = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter( $service, $folderID );
707
+			$adapter = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter($service, $folderID);
708 708
 		}
709 709
 
710
-		$filesystem = new \League\Flysystem\Filesystem( $adapter, new Config( [
710
+		$filesystem = new \League\Flysystem\Filesystem($adapter, new Config([
711 711
 			'disable_asserts' => true,
712
-		] ) );
712
+		]));
713 713
 
714 714
 
715
-		return array( $adapter, $filesystem );
715
+		return array($adapter, $filesystem);
716 716
 	}
717 717
 
718 718
 	public function get_ftp_filesystem() {
719
-		$this->logger->info( sprintf( "Creating the FTP remote storage connection" ), array( "" ) );
719
+		$this->logger->info(sprintf("Creating the FTP remote storage connection"), array(""));
720 720
 
721
-		$adapter = new Adapter( [
722
-			'host'     => get_option( "xcloner_ftp_hostname" ),
723
-			'username' => get_option( "xcloner_ftp_username" ),
724
-			'password' => get_option( "xcloner_ftp_password" ),
721
+		$adapter = new Adapter([
722
+			'host'     => get_option("xcloner_ftp_hostname"),
723
+			'username' => get_option("xcloner_ftp_username"),
724
+			'password' => get_option("xcloner_ftp_password"),
725 725
 
726 726
 			/** optional config settings */
727
-			'port'     => get_option( "xcloner_ftp_port", 21 ),
728
-			'root'     => get_option( "xcloner_ftp_path" ),
729
-			'passive'  => get_option( "xcloner_ftp_transfer_mode" ),
730
-			'ssl'      => get_option( "xcloner_ftp_ssl_mode" ),
731
-			'timeout'  => get_option( "xcloner_ftp_timeout", 30 ),
732
-		] );
727
+			'port'     => get_option("xcloner_ftp_port", 21),
728
+			'root'     => get_option("xcloner_ftp_path"),
729
+			'passive'  => get_option("xcloner_ftp_transfer_mode"),
730
+			'ssl'      => get_option("xcloner_ftp_ssl_mode"),
731
+			'timeout'  => get_option("xcloner_ftp_timeout", 30),
732
+		]);
733 733
 
734 734
 		$adapter->connect();
735 735
 
736
-		$filesystem = new Filesystem( $adapter, new Config( [
736
+		$filesystem = new Filesystem($adapter, new Config([
737 737
 			'disable_asserts' => true,
738
-		] ) );
738
+		]));
739 739
 
740
-		return array( $adapter, $filesystem );
740
+		return array($adapter, $filesystem);
741 741
 	}
742 742
 
743 743
 	public function get_sftp_filesystem() {
744
-		$this->logger->info( sprintf( "Creating the SFTP remote storage connection" ), array( "" ) );
744
+		$this->logger->info(sprintf("Creating the SFTP remote storage connection"), array(""));
745 745
 
746
-		$adapter = new SftpAdapter( [
747
-			'host'       => get_option( "xcloner_sftp_hostname" ),
748
-			'username'   => get_option( "xcloner_sftp_username" ),
749
-			'password'   => get_option( "xcloner_sftp_password" ),
746
+		$adapter = new SftpAdapter([
747
+			'host'       => get_option("xcloner_sftp_hostname"),
748
+			'username'   => get_option("xcloner_sftp_username"),
749
+			'password'   => get_option("xcloner_sftp_password"),
750 750
 
751 751
 			/** optional config settings */
752
-			'port'       => get_option( "xcloner_sftp_port", 22 ),
753
-			'root'       => get_option( "xcloner_sftp_path" ),
754
-			'privateKey' => get_option( "xcloner_sftp_private_key" ),
755
-			'timeout'    => get_option( "xcloner_ftp_timeout", 30 ),
756
-		] );
752
+			'port'       => get_option("xcloner_sftp_port", 22),
753
+			'root'       => get_option("xcloner_sftp_path"),
754
+			'privateKey' => get_option("xcloner_sftp_private_key"),
755
+			'timeout'    => get_option("xcloner_ftp_timeout", 30),
756
+		]);
757 757
 
758 758
 		$adapter->connect();
759 759
 
760
-		$filesystem = new Filesystem( $adapter, new Config( [
760
+		$filesystem = new Filesystem($adapter, new Config([
761 761
 			'disable_asserts' => true,
762
-		] ) );
762
+		]));
763 763
 
764
-		return array( $adapter, $filesystem );
764
+		return array($adapter, $filesystem);
765 765
 	}
766 766
 
767
-	public function change_storage_status( $field, $value ) {
768
-		$field = $this->xcloner_sanitization->sanitize_input_as_string( $field );
769
-		$value = $this->xcloner_sanitization->sanitize_input_as_int( $value );
767
+	public function change_storage_status($field, $value) {
768
+		$field = $this->xcloner_sanitization->sanitize_input_as_string($field);
769
+		$value = $this->xcloner_sanitization->sanitize_input_as_int($value);
770 770
 
771
-		return update_option( $field, $value );
771
+		return update_option($field, $value);
772 772
 	}
773 773
 
774 774
 	public function get_aws_regions() {
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -213,8 +213,7 @@
 block discarded – undo
213 213
 
214 214
         if( $action == 'e' && function_exists('openssl_encrypt')) {
215 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 )){
216
+        } else if( $action == 'd' && function_exists('openssl_decrypt') && base64_decode( $string )){
218 217
             $decrypt = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );
219 218
             if($decrypt) {
220 219
                 //we check if decrypt was succesful
Please login to merge, or discard this patch.
includes/class-xcloner-scheduler.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -327,6 +327,9 @@
 block discarded – undo
327 327
 		$this->xcloner_file_system->cleanup_tmp_directories();
328 328
 	}
329 329
 
330
+	/**
331
+	 * @param integer $id
332
+	 */
330 333
 	public function xcloner_scheduler_callback( $id, $schedule = "" ) {
331 334
 		if ( $id ) {
332 335
 			$schedule = $this->get_schedule_by_id( $id );
Please login to merge, or discard this patch.
Spacing   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -12,13 +12,13 @@  discard block
 block discarded – undo
12 12
 	private $logger;
13 13
 	private $xcloner_file_system;
14 14
 
15
-	private $allowed_schedules = array( "hourly", "twicedaily", "daily", "weekly", "monthly" );
15
+	private $allowed_schedules = array("hourly", "twicedaily", "daily", "weekly", "monthly");
16 16
 
17 17
 	/*public function __call($method, $args) {
18 18
 		echo "$method is not defined";
19 19
 	}*/
20 20
 
21
-	public function __construct( Xcloner $xcloner_container ) {
21
+	public function __construct(Xcloner $xcloner_container) {
22 22
 		global $wpdb;
23 23
 
24 24
 		$this->db          = $wpdb;
@@ -27,26 +27,26 @@  discard block
 block discarded – undo
27 27
 		$this->xcloner_container = $xcloner_container;
28 28
 		$this->xcloner_settings  = $xcloner_container->get_xcloner_settings();
29 29
 
30
-		$this->scheduler_table = $this->db->prefix . $this->scheduler_table;
30
+		$this->scheduler_table = $this->db->prefix.$this->scheduler_table;
31 31
 	}
32 32
 
33 33
 	private function get_xcloner_container() {
34 34
 		return $this->xcloner_container;
35 35
 	}
36 36
 
37
-	private function set_xcloner_container( Xcloner $container ) {
37
+	private function set_xcloner_container(Xcloner $container) {
38 38
 		$this->xcloner_container = $container;
39 39
 	}
40 40
 
41
-	public function get_scheduler_list( $return_only_enabled = 0 ) {
42
-		$list = $this->db->get_results( "SELECT * FROM " . $this->scheduler_table );
41
+	public function get_scheduler_list($return_only_enabled = 0) {
42
+		$list = $this->db->get_results("SELECT * FROM ".$this->scheduler_table);
43 43
 
44
-		if ( $return_only_enabled ) {
44
+		if ($return_only_enabled) {
45 45
 			$new_list = array();
46 46
 
47
-			foreach ( $list as $res ) {
48
-				if ( $res->status ) {
49
-					$res->next_run_time = wp_next_scheduled( 'xcloner_scheduler_' . $res->id, array( $res->id ) ) + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
47
+			foreach ($list as $res) {
48
+				if ($res->status) {
49
+					$res->next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id)) + (get_option('gmt_offset') * HOUR_IN_SECONDS);
50 50
 					$new_list[]         = $res;
51 51
 				}
52 52
 			}
@@ -56,42 +56,42 @@  discard block
 block discarded – undo
56 56
 		return $list;
57 57
 	}
58 58
 
59
-	public function get_next_run_schedule( $xcloner_file_system = "" ) {
60
-		$list = $this->get_scheduler_list( $return_only_enabled = 1 );
59
+	public function get_next_run_schedule($xcloner_file_system = "") {
60
+		$list = $this->get_scheduler_list($return_only_enabled = 1);
61 61
 
62 62
 		return $list;
63 63
 	}
64 64
 
65
-	public function get_schedule_by_id_object( $id ) {
66
-		$data = $this->db->get_row( "SELECT * FROM " . $this->scheduler_table . " WHERE id=" . $id );
65
+	public function get_schedule_by_id_object($id) {
66
+		$data = $this->db->get_row("SELECT * FROM ".$this->scheduler_table." WHERE id=".$id);
67 67
 
68 68
 		return $data;
69 69
 	}
70 70
 
71
-	public function get_schedule_by_id( $id ) {
72
-		$data = $this->db->get_row( "SELECT * FROM " . $this->scheduler_table . " WHERE id=" . $id, ARRAY_A );
71
+	public function get_schedule_by_id($id) {
72
+		$data = $this->db->get_row("SELECT * FROM ".$this->scheduler_table." WHERE id=".$id, ARRAY_A);
73 73
 
74
-		if ( ! $data ) {
74
+		if (!$data) {
75 75
 			return false;
76 76
 		}
77 77
 
78
-		$params = json_decode( $data['params'] );
78
+		$params = json_decode($data['params']);
79 79
 
80 80
 		//print_r($params);
81 81
 		$data['params']         = "";
82 82
 		$data['backup_params']  = $params->backup_params;
83
-		$data['table_params']   = json_encode( $params->database );
84
-		$data['excluded_files'] = json_encode( $params->excluded_files );
83
+		$data['table_params']   = json_encode($params->database);
84
+		$data['excluded_files'] = json_encode($params->excluded_files);
85 85
 
86 86
 
87 87
 		return $data;
88 88
 	}
89 89
 
90
-	public function delete_schedule_by_id( $id ) {
91
-		$hook = 'xcloner_scheduler_' . $id;
92
-		wp_clear_scheduled_hook( $hook, array( $id ) );
90
+	public function delete_schedule_by_id($id) {
91
+		$hook = 'xcloner_scheduler_'.$id;
92
+		wp_clear_scheduled_hook($hook, array($id));
93 93
 
94
-		$data = $this->db->delete( $this->scheduler_table, array( 'id' => $id ) );
94
+		$data = $this->db->delete($this->scheduler_table, array('id' => $id));
95 95
 
96 96
 		return $data;
97 97
 	}
@@ -99,68 +99,68 @@  discard block
 block discarded – undo
99 99
 	public function deactivate_wp_cron_hooks() {
100 100
 		$list = $this->get_scheduler_list();
101 101
 
102
-		foreach ( $list as $schedule ) {
103
-			$hook = 'xcloner_scheduler_' . $schedule->id;
102
+		foreach ($list as $schedule) {
103
+			$hook = 'xcloner_scheduler_'.$schedule->id;
104 104
 
105
-			$timestamp = wp_next_scheduled( $hook, array( $schedule->id ) );
106
-			wp_unschedule_event( $timestamp, $hook, array( $schedule->id ) );
105
+			$timestamp = wp_next_scheduled($hook, array($schedule->id));
106
+			wp_unschedule_event($timestamp, $hook, array($schedule->id));
107 107
 		}
108 108
 	}
109 109
 
110 110
 	public function update_wp_cron_hooks() {
111 111
 		$list = $this->get_scheduler_list();
112 112
 
113
-		foreach ( $list as $schedule ) {
114
-			$hook = 'xcloner_scheduler_' . $schedule->id;
113
+		foreach ($list as $schedule) {
114
+			$hook = 'xcloner_scheduler_'.$schedule->id;
115 115
 
116 116
 			//adding the xcloner_scheduler hook with xcloner_scheduler_callback callback
117
-			add_action( $hook, array( $this, 'xcloner_scheduler_callback' ), 10, 1 );
117
+			add_action($hook, array($this, 'xcloner_scheduler_callback'), 10, 1);
118 118
 
119
-			if ( ! wp_next_scheduled( $hook, array( $schedule->id ) ) and $schedule->status ) {
119
+			if (!wp_next_scheduled($hook, array($schedule->id)) and $schedule->status) {
120 120
 
121
-				if ( $schedule->recurrence == "single" ) {
122
-					wp_schedule_single_event( strtotime( $schedule->start_at ), $hook, array( $schedule->id ) );
121
+				if ($schedule->recurrence == "single") {
122
+					wp_schedule_single_event(strtotime($schedule->start_at), $hook, array($schedule->id));
123 123
 				} else {
124
-					wp_schedule_event( strtotime( $schedule->start_at ), $schedule->recurrence, $hook, array( $schedule->id ) );
124
+					wp_schedule_event(strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id));
125 125
 				}
126 126
 
127
-			} elseif ( ! $schedule->status ) {
128
-				$timestamp = wp_next_scheduled( $hook, array( $schedule->id ) );
129
-				wp_unschedule_event( $timestamp, $hook, array( $schedule->id ) );
127
+			} elseif (!$schedule->status) {
128
+				$timestamp = wp_next_scheduled($hook, array($schedule->id));
129
+				wp_unschedule_event($timestamp, $hook, array($schedule->id));
130 130
 			}
131 131
 		}
132 132
 
133 133
 	}
134 134
 
135
-	public function update_cron_hook( $id ) {
136
-		$schedule = $this->get_schedule_by_id_object( $id );
137
-		$hook     = 'xcloner_scheduler_' . $schedule->id;
135
+	public function update_cron_hook($id) {
136
+		$schedule = $this->get_schedule_by_id_object($id);
137
+		$hook     = 'xcloner_scheduler_'.$schedule->id;
138 138
 
139
-		$timestamp = wp_next_scheduled( $hook, array( $schedule->id ) );
140
-		wp_unschedule_event( $timestamp, $hook, array( $schedule->id ) );
139
+		$timestamp = wp_next_scheduled($hook, array($schedule->id));
140
+		wp_unschedule_event($timestamp, $hook, array($schedule->id));
141 141
 
142
-		if ( $schedule->status ) {
142
+		if ($schedule->status) {
143 143
 
144
-			if ( $schedule->recurrence == "single" ) {
145
-				wp_schedule_single_event( strtotime( $schedule->start_at ), $hook, array( $schedule->id ) );
144
+			if ($schedule->recurrence == "single") {
145
+				wp_schedule_single_event(strtotime($schedule->start_at), $hook, array($schedule->id));
146 146
 			} else {
147
-				wp_schedule_event( strtotime( $schedule->start_at ), $schedule->recurrence, $hook, array( $schedule->id ) );
147
+				wp_schedule_event(strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id));
148 148
 			}
149 149
 
150 150
 		}
151 151
 	}
152 152
 
153
-	public function disable_single_cron( $schedule_id ) {
154
-		$hook      = 'xcloner_scheduler_' . $schedule_id;
155
-		$timestamp = wp_next_scheduled( $hook, array( $schedule_id ) );
156
-		wp_unschedule_event( $timestamp, $hook, array( $schedule_id ) );
153
+	public function disable_single_cron($schedule_id) {
154
+		$hook      = 'xcloner_scheduler_'.$schedule_id;
155
+		$timestamp = wp_next_scheduled($hook, array($schedule_id));
156
+		wp_unschedule_event($timestamp, $hook, array($schedule_id));
157 157
 
158 158
 		$schedule['status'] = 0;
159 159
 
160 160
 		$update = $this->db->update(
161 161
 			$this->scheduler_table,
162 162
 			$schedule,
163
-			array( 'id' => $schedule_id ),
163
+			array('id' => $schedule_id),
164 164
 			array(
165 165
 				'%s',
166 166
 				'%s'
@@ -170,13 +170,13 @@  discard block
 block discarded – undo
170 170
 		return $update;
171 171
 	}
172 172
 
173
-	public function update_hash( $schedule_id, $hash ) {
173
+	public function update_hash($schedule_id, $hash) {
174 174
 		$schedule['hash'] = $hash;
175 175
 
176 176
 		$update = $this->db->update(
177 177
 			$this->scheduler_table,
178 178
 			$schedule,
179
-			array( 'id' => $schedule_id ),
179
+			array('id' => $schedule_id),
180 180
 			array(
181 181
 				'%s',
182 182
 				'%s'
@@ -186,13 +186,13 @@  discard block
 block discarded – undo
186 186
 		return $update;
187 187
 	}
188 188
 
189
-	public function update_last_backup( $schedule_id, $last_backup ) {
189
+	public function update_last_backup($schedule_id, $last_backup) {
190 190
 		$schedule['last_backup'] = $last_backup;
191 191
 
192 192
 		$update = $this->db->update(
193 193
 			$this->scheduler_table,
194 194
 			$schedule,
195
-			array( 'id' => $schedule_id ),
195
+			array('id' => $schedule_id),
196 196
 			array(
197 197
 				'%s',
198 198
 				'%s'
@@ -202,12 +202,12 @@  discard block
 block discarded – undo
202 202
 		return $update;
203 203
 	}
204 204
 
205
-	private function _xcloner_scheduler_callback( $id, $schedule ) {
206
-		set_time_limit( 0 );
205
+	private function _xcloner_scheduler_callback($id, $schedule) {
206
+		set_time_limit(0);
207 207
 
208 208
 		$xcloner = new XCloner();
209 209
 		$xcloner->init();
210
-		$this->set_xcloner_container( $xcloner );
210
+		$this->set_xcloner_container($xcloner);
211 211
 
212 212
 		#$hash = $this->xcloner_settings->get_hash();
213 213
 		#$this->get_xcloner_container()->get_xcloner_settings()->set_hash($hash);
@@ -216,106 +216,106 @@  discard block
 block discarded – undo
216 216
 		$this->xcloner_file_system    = $this->get_xcloner_container()->get_xcloner_filesystem();
217 217
 		$this->xcloner_database       = $this->get_xcloner_container()->get_xcloner_database();
218 218
 		$this->archive_system         = $this->get_xcloner_container()->get_archive_system();
219
-		$this->logger                 = $this->get_xcloner_container()->get_xcloner_logger()->withName( "xcloner_scheduler" );
219
+		$this->logger                 = $this->get_xcloner_container()->get_xcloner_logger()->withName("xcloner_scheduler");
220 220
 		$this->xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
221 221
 
222
-		$this->logger->info( sprintf( "New schedule hash is %s", $this->xcloner_settings->get_hash() ) );
222
+		$this->logger->info(sprintf("New schedule hash is %s", $this->xcloner_settings->get_hash()));
223 223
 
224
-		if ( isset( $schedule['backup_params']->diff_start_date ) && $schedule['backup_params']->diff_start_date ) {
225
-			$this->xcloner_file_system->set_diff_timestamp_start( $schedule['backup_params']->diff_start_date );
224
+		if (isset($schedule['backup_params']->diff_start_date) && $schedule['backup_params']->diff_start_date) {
225
+			$this->xcloner_file_system->set_diff_timestamp_start($schedule['backup_params']->diff_start_date);
226 226
 		}
227 227
 
228
-		if ( $schedule['recurrence'] == "single" ) {
229
-			$this->disable_single_cron( $schedule['id'] );
228
+		if ($schedule['recurrence'] == "single") {
229
+			$this->disable_single_cron($schedule['id']);
230 230
 		}
231 231
 
232
-		if ( ! $schedule ) {
233
-			$this->logger->info( sprintf( "Could not load schedule with id'%s'", $id ), array( "CRON" ) );
232
+		if (!$schedule) {
233
+			$this->logger->info(sprintf("Could not load schedule with id'%s'", $id), array("CRON"));
234 234
 
235 235
 			return;
236 236
 		}
237 237
 
238 238
 		//echo $this->get_xcloner_container()->get_xcloner_settings()->get_hash(); exit;
239 239
 
240
-		$this->update_hash( $schedule['id'], $this->xcloner_settings->get_hash() );
240
+		$this->update_hash($schedule['id'], $this->xcloner_settings->get_hash());
241 241
 
242
-		$this->logger->info( sprintf( "Starting cron schedule '%s'", $schedule['name'] ), array( "CRON" ) );
242
+		$this->logger->info(sprintf("Starting cron schedule '%s'", $schedule['name']), array("CRON"));
243 243
 
244
-		$this->xcloner_file_system->set_excluded_files( json_decode( $schedule['excluded_files'] ) );
244
+		$this->xcloner_file_system->set_excluded_files(json_decode($schedule['excluded_files']));
245 245
 
246 246
 		$init     = 1;
247 247
 		$continue = 1;
248 248
 
249
-		while ( $continue ) {
250
-			$continue = $this->xcloner_file_system->start_file_recursion( $init );
249
+		while ($continue) {
250
+			$continue = $this->xcloner_file_system->start_file_recursion($init);
251 251
 
252 252
 			$init = 0;
253 253
 		}
254 254
 
255
-		$this->logger->info( sprintf( "File scan finished" ), array( "CRON" ) );
255
+		$this->logger->info(sprintf("File scan finished"), array("CRON"));
256 256
 
257
-		$this->logger->info( sprintf( "Starting the database backup" ), array( "CRON" ) );
257
+		$this->logger->info(sprintf("Starting the database backup"), array("CRON"));
258 258
 
259 259
 		$init               = 1;
260 260
 		$return['finished'] = 0;
261 261
 
262
-		while ( ! $return['finished'] ) {
263
-			$return = $this->xcloner_database->start_database_recursion( (array) json_decode( $schedule['table_params'] ), $return, $init );
262
+		while (!$return['finished']) {
263
+			$return = $this->xcloner_database->start_database_recursion((array)json_decode($schedule['table_params']), $return, $init);
264 264
 			$init   = 0;
265 265
 		}
266 266
 
267
-		$this->logger->info( sprintf( "Database backup done" ), array( "CRON" ) );
267
+		$this->logger->info(sprintf("Database backup done"), array("CRON"));
268 268
 
269
-		$this->logger->info( sprintf( "Starting file archive process" ), array( "CRON" ) );
269
+		$this->logger->info(sprintf("Starting file archive process"), array("CRON"));
270 270
 
271 271
 		$init               = 0;
272 272
 		$return['finished'] = 0;
273 273
 		$return['extra']    = array();
274 274
 
275
-		while ( ! $return['finished'] ) {
276
-			$return = $this->archive_system->start_incremental_backup( (array) $schedule['backup_params'], $return['extra'], $init );
275
+		while (!$return['finished']) {
276
+			$return = $this->archive_system->start_incremental_backup((array)$schedule['backup_params'], $return['extra'], $init);
277 277
 			$init   = 0;
278 278
 		}
279
-		$this->logger->info( sprintf( "File archive process FINISHED." ), array( "CRON" ) );
279
+		$this->logger->info(sprintf("File archive process FINISHED."), array("CRON"));
280 280
 
281 281
 		//getting the last backup archive file
282 282
 		$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension();
283
-		if ( $this->xcloner_file_system->is_part( $this->archive_system->get_archive_name_with_extension() ) ) {
283
+		if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) {
284 284
 			$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
285 285
 		}
286 286
 
287
-		$this->update_last_backup( $schedule['id'], $return['extra']['backup_parent'] );
287
+		$this->update_last_backup($schedule['id'], $return['extra']['backup_parent']);
288 288
 
289
-		if ( isset( $schedule['remote_storage'] ) && $schedule['remote_storage'] && array_key_exists( $schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages() ) ) {
289
+		if (isset($schedule['remote_storage']) && $schedule['remote_storage'] && array_key_exists($schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages())) {
290 290
 			$backup_file = $return['extra']['backup_parent'];
291 291
 
292
-			$this->logger->info( sprintf( "Transferring backup to remote storage %s", strtoupper( $schedule['remote_storage'] ) ), array( "CRON" ) );
292
+			$this->logger->info(sprintf("Transferring backup to remote storage %s", strtoupper($schedule['remote_storage'])), array("CRON"));
293 293
 
294
-			if ( method_exists( $this->xcloner_remote_storage, "upload_backup_to_storage" ) ) {
295
-				call_user_func_array( array(
294
+			if (method_exists($this->xcloner_remote_storage, "upload_backup_to_storage")) {
295
+				call_user_func_array(array(
296 296
 					$this->xcloner_remote_storage,
297 297
 					"upload_backup_to_storage"
298
-				), array( $backup_file, $schedule['remote_storage'] ) );
298
+				), array($backup_file, $schedule['remote_storage']));
299 299
 			}
300 300
 		}
301 301
 
302
-		if ( isset( $schedule['backup_params']->email_notification ) and $to = $schedule['backup_params']->email_notification ) {
302
+		if (isset($schedule['backup_params']->email_notification) and $to = $schedule['backup_params']->email_notification) {
303 303
 			try {
304 304
 				$from                      = "";
305 305
 				$additional['lines_total'] = $return['extra']['lines_total'];
306
-				$subject                   = sprintf( __( "%s - new backup generated %s" ), $schedule['name'], $return['extra']['backup_parent'] );
306
+				$subject                   = sprintf(__("%s - new backup generated %s"), $schedule['name'], $return['extra']['backup_parent']);
307 307
 
308
-				$this->archive_system->send_notification( $to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional );
308
+				$this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional);
309 309
 
310
-			} catch ( Exception $e ) {
311
-				$this->logger->error( $e->getMessage() );
310
+			}catch (Exception $e) {
311
+				$this->logger->error($e->getMessage());
312 312
 			}
313 313
 		}
314 314
 
315 315
 		//CHECK IF WE SHOULD DELETE BACKUP AFTER REMOTE TRANSFER IS DONE
316
-		if ( $schedule['remote_storage'] && $this->xcloner_settings->get_xcloner_option( 'xcloner_cleanup_delete_after_remote_transfer' ) ) {
317
-			$this->logger->info( sprintf( "Deleting %s from local storage matching rule xcloner_cleanup_delete_after_remote_transfer", $return['extra']['backup_parent'] ) );
318
-			$this->xcloner_file_system->delete_backup_by_name( $return['extra']['backup_parent'] );
316
+		if ($schedule['remote_storage'] && $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_delete_after_remote_transfer')) {
317
+			$this->logger->info(sprintf("Deleting %s from local storage matching rule xcloner_cleanup_delete_after_remote_transfer", $return['extra']['backup_parent']));
318
+			$this->xcloner_file_system->delete_backup_by_name($return['extra']['backup_parent']);
319 319
 
320 320
 		}
321 321
 
@@ -327,25 +327,25 @@  discard block
 block discarded – undo
327 327
 		$this->xcloner_file_system->cleanup_tmp_directories();
328 328
 	}
329 329
 
330
-	public function xcloner_scheduler_callback( $id, $schedule = "" ) {
331
-		if ( $id ) {
332
-			$schedule = $this->get_schedule_by_id( $id );
330
+	public function xcloner_scheduler_callback($id, $schedule = "") {
331
+		if ($id) {
332
+			$schedule = $this->get_schedule_by_id($id);
333 333
 		}
334 334
 
335 335
 		try {
336 336
 
337
-			$this->_xcloner_scheduler_callback( $id, $schedule );
337
+			$this->_xcloner_scheduler_callback($id, $schedule);
338 338
 
339
-		} catch ( Exception $e ) {
339
+		}catch (Exception $e) {
340 340
 
341 341
 			//send email to site admin if email notification is not set in the scheduler
342
-			if ( ! isset( $schedule['backup_params']->email_notification ) || ! $schedule['backup_params']->email_notification ) {
343
-				$schedule['backup_params']->email_notification = get_option( 'admin_email' );
342
+			if (!isset($schedule['backup_params']->email_notification) || !$schedule['backup_params']->email_notification) {
343
+				$schedule['backup_params']->email_notification = get_option('admin_email');
344 344
 			}
345 345
 
346
-			if ( isset( $schedule['backup_params']->email_notification ) && $to = $schedule['backup_params']->email_notification ) {
346
+			if (isset($schedule['backup_params']->email_notification) && $to = $schedule['backup_params']->email_notification) {
347 347
 				$from = "";
348
-				$this->archive_system->send_notification( $to, $from, $schedule['name'] . " - backup error", "", "", $e->getMessage() );
348
+				$this->archive_system->send_notification($to, $from, $schedule['name']." - backup error", "", "", $e->getMessage());
349 349
 			}
350 350
 
351 351
 		}
@@ -356,14 +356,14 @@  discard block
 block discarded – undo
356 356
 		$schedules     = wp_get_schedules();
357 357
 		$new_schedules = array();
358 358
 
359
-		foreach ( $schedules as $key => $row ) {
360
-			if ( in_array( $key, $this->allowed_schedules ) ) {
361
-				$new_schedules[ $key ] = $row;
362
-				$intervals[ $key ]     = $row['interval'];
359
+		foreach ($schedules as $key => $row) {
360
+			if (in_array($key, $this->allowed_schedules)) {
361
+				$new_schedules[$key] = $row;
362
+				$intervals[$key]     = $row['interval'];
363 363
 			}
364 364
 		}
365 365
 
366
-		array_multisort( $intervals, SORT_ASC, $new_schedules );
366
+		array_multisort($intervals, SORT_ASC, $new_schedules);
367 367
 
368 368
 		return $new_schedules;
369 369
 	}
Please login to merge, or discard this patch.
includes/class-xcloner-settings.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -183,6 +183,9 @@
 block discarded – undo
183 183
 		return $wpdb->prefix;
184 184
 	}
185 185
 
186
+	/**
187
+	 * @param string $option
188
+	 */
186 189
 	public function get_xcloner_option( $option ) {
187 190
 		$data = get_option( $option );
188 191
 
Please login to merge, or discard this patch.
Spacing   +228 added lines, -228 removed lines patch added patch discarded remove patch
@@ -7,10 +7,10 @@  discard block
 block discarded – undo
7 7
 	private $xcloner_sanitization;
8 8
 	private $xcloner_container;
9 9
 
10
-	public function __construct( Xcloner $xcloner_container, $hash = "" ) {
10
+	public function __construct(Xcloner $xcloner_container, $hash = "") {
11 11
 		$this->xcloner_container = $xcloner_container;
12
-		if ( isset( $hash ) ) {
13
-			$this->set_hash( $hash );
12
+		if (isset($hash)) {
13
+			$this->set_hash($hash);
14 14
 		}
15 15
 	}
16 16
 
@@ -18,93 +18,93 @@  discard block
 block discarded – undo
18 18
 		return $this->xcloner_container;
19 19
 	}
20 20
 
21
-	public function get_logger_filename( $include_hash = 0 ) {
22
-		if ( $include_hash ) {
23
-			$filename = sprintf( $this->logger_file_hash, $this->get_hash() );
21
+	public function get_logger_filename($include_hash = 0) {
22
+		if ($include_hash) {
23
+			$filename = sprintf($this->logger_file_hash, $this->get_hash());
24 24
 		} else {
25
-			$filename = sprintf( $this->logger_file, $this->get_server_unique_hash( 5 ) );
25
+			$filename = sprintf($this->logger_file, $this->get_server_unique_hash(5));
26 26
 		}
27 27
 
28 28
 		return $filename;
29 29
 	}
30 30
 
31 31
 	public function get_xcloner_start_path() {
32
-		if ( ! get_option( 'xcloner_start_path' ) or ! is_dir( get_option( 'xcloner_start_path' ) ) ) {
33
-			$path = realpath( ABSPATH );
32
+		if (!get_option('xcloner_start_path') or !is_dir(get_option('xcloner_start_path'))) {
33
+			$path = realpath(ABSPATH);
34 34
 		} else {
35
-			$path = get_option( 'xcloner_start_path' );
35
+			$path = get_option('xcloner_start_path');
36 36
 		}
37 37
 
38 38
 		return $path;
39 39
 	}
40 40
 
41
-	public function get_xcloner_dir_path( $dir ) {
42
-		$path = self::get_xcloner_start_path() . DS . $dir;
41
+	public function get_xcloner_dir_path($dir) {
42
+		$path = self::get_xcloner_start_path().DS.$dir;
43 43
 
44 44
 		return $path;
45 45
 	}
46 46
 
47 47
 	public function get_xcloner_store_path() {
48
-		if ( ! get_option( 'xcloner_store_path' ) or ! is_dir( get_option( 'xcloner_store_path' ) ) ) {
49
-			$path = realpath( XCLONER_STORAGE_PATH );
48
+		if (!get_option('xcloner_store_path') or !is_dir(get_option('xcloner_store_path'))) {
49
+			$path = realpath(XCLONER_STORAGE_PATH);
50 50
 		} else {
51
-			$path = get_option( 'xcloner_store_path' );
51
+			$path = get_option('xcloner_store_path');
52 52
 		}
53 53
 
54 54
 		return $path;
55 55
 	}
56 56
 
57 57
 	public function get_xcloner_tmp_path_suffix() {
58
-		return "xcloner" . $this->get_hash();
58
+		return "xcloner".$this->get_hash();
59 59
 	}
60 60
 
61 61
 
62
-	public function get_xcloner_tmp_path( $suffix = true ) {
63
-		if ( get_option( 'xcloner_force_tmp_path_site_root' ) ) {
62
+	public function get_xcloner_tmp_path($suffix = true) {
63
+		if (get_option('xcloner_force_tmp_path_site_root')) {
64 64
 			$path = $this->get_xcloner_store_path();
65 65
 		} else {
66 66
 
67 67
 			$path = sys_get_temp_dir();
68
-			if ( ! is_dir( $path ) ) {
69
-				@mkdir( $path );
70
-				@chmod( $path, 0777 );
68
+			if (!is_dir($path)) {
69
+				@mkdir($path);
70
+				@chmod($path, 0777);
71 71
 			}
72 72
 
73
-			if ( ! is_dir( $path ) or ! is_writeable( $path ) ) {
73
+			if (!is_dir($path) or !is_writeable($path)) {
74 74
 				$path = $this->get_xcloner_store_path();
75 75
 			}
76 76
 		}
77 77
 
78
-		if ( $suffix ) {
79
-			$path = $path . DS . "." . $this->get_xcloner_tmp_path_suffix();
78
+		if ($suffix) {
79
+			$path = $path.DS.".".$this->get_xcloner_tmp_path_suffix();
80 80
 		}
81 81
 
82 82
 		return $path;
83 83
 	}
84 84
 
85 85
 	public function get_enable_mysql_backup() {
86
-		if ( get_option( 'xcloner_enable_mysql_backup' ) ) {
86
+		if (get_option('xcloner_enable_mysql_backup')) {
87 87
 			return true;
88 88
 		}
89 89
 
90 90
 		return false;
91 91
 	}
92 92
 
93
-	public function get_backup_extension_name( $ext = "" ) {
94
-		if ( ! $ext ) {
95
-			if ( get_option( 'xcloner_backup_compression_level' ) ) {
93
+	public function get_backup_extension_name($ext = "") {
94
+		if (!$ext) {
95
+			if (get_option('xcloner_backup_compression_level')) {
96 96
 				$ext = ".tgz";
97 97
 			} else {
98 98
 				$ext = ".tar";
99 99
 			}
100 100
 		}
101 101
 
102
-		return ( $this->get_hash() ) . $ext;
102
+		return ($this->get_hash()).$ext;
103 103
 	}
104 104
 
105 105
 	public function get_hash() {
106
-		if ( ! $this->hash ) {
107
-			$this->set_hash( "-" . $this->get_server_unique_hash( 5 ) );
106
+		if (!$this->hash) {
107
+			$this->set_hash("-".$this->get_server_unique_hash(5));
108 108
 		}
109 109
 
110 110
 		//echo $this->hash;	
@@ -112,27 +112,27 @@  discard block
 block discarded – undo
112 112
 	}
113 113
 
114 114
 	public function generate_new_hash() {
115
-		$hash = "-" . md5( rand() );
115
+		$hash = "-".md5(rand());
116 116
 
117
-		$this->set_hash( substr( $hash, 0, 6 ) );
117
+		$this->set_hash(substr($hash, 0, 6));
118 118
 
119 119
 		return $hash;
120 120
 	}
121 121
 
122
-	public function set_hash( $hash = "" ) {
123
-		if ( substr( $hash, 0, 1 ) != "-" and strlen( $hash ) ) {
124
-			$hash = "-" . $hash;
122
+	public function set_hash($hash = "") {
123
+		if (substr($hash, 0, 1) != "-" and strlen($hash)) {
124
+			$hash = "-".$hash;
125 125
 		}
126 126
 
127
-		$this->hash = substr( $hash, 0, 6 );
127
+		$this->hash = substr($hash, 0, 6);
128 128
 
129 129
 		return $this;
130 130
 	}
131 131
 
132 132
 	public function get_default_backup_name() {
133
-		$data = parse_url( get_site_url() );
133
+		$data = parse_url(get_site_url());
134 134
 
135
-		$backup_name = "backup_[domain]" . ( isset( $data['port'] ) ? "_" . $data['port'] : "" ) . "-[time]-" . ( $this->get_enable_mysql_backup() ? "sql" : "nosql" );
135
+		$backup_name = "backup_[domain]".(isset($data['port']) ? "_".$data['port'] : "")."-[time]-".($this->get_enable_mysql_backup() ? "sql" : "nosql");
136 136
 
137 137
 		return $backup_name;
138 138
 	}
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 	public function get_db_hostname() {
141 141
 		global $wpdb;
142 142
 
143
-		if ( ! $data = get_option( 'xcloner_mysql_hostname' ) ) {
143
+		if (!$data = get_option('xcloner_mysql_hostname')) {
144 144
 			$data = $wpdb->dbhost;
145 145
 		}
146 146
 
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	public function get_db_username() {
151 151
 		global $wpdb;
152 152
 
153
-		if ( ! $data = get_option( 'xcloner_mysql_username' ) ) {
153
+		if (!$data = get_option('xcloner_mysql_username')) {
154 154
 			$data = $wpdb->dbuser;
155 155
 		}
156 156
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	public function get_db_password() {
161 161
 		global $wpdb;
162 162
 
163
-		if ( ! $data = get_option( 'xcloner_mysql_password' ) ) {
163
+		if (!$data = get_option('xcloner_mysql_password')) {
164 164
 			$data = $wpdb->dbpassword;
165 165
 		}
166 166
 
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	public function get_db_database() {
171 171
 		global $wpdb;
172 172
 
173
-		if ( ! $data = get_option( 'xcloner_mysql_database' ) ) {
173
+		if (!$data = get_option('xcloner_mysql_database')) {
174 174
 			$data = $wpdb->dbname;
175 175
 		}
176 176
 
@@ -183,17 +183,17 @@  discard block
 block discarded – undo
183 183
 		return $wpdb->prefix;
184 184
 	}
185 185
 
186
-	public function get_xcloner_option( $option ) {
187
-		$data = get_option( $option );
186
+	public function get_xcloner_option($option) {
187
+		$data = get_option($option);
188 188
 
189 189
 		return $data;
190 190
 	}
191 191
 
192
-	public function get_server_unique_hash( $strlen = 0 ) {
193
-		$hash = md5( get_home_url() . __DIR__ );
192
+	public function get_server_unique_hash($strlen = 0) {
193
+		$hash = md5(get_home_url().__DIR__);
194 194
 
195
-		if ( $strlen ) {
196
-			$hash = substr( $hash, 0, $strlen );
195
+		if ($strlen) {
196
+			$hash = substr($hash, 0, $strlen);
197 197
 		}
198 198
 
199 199
 		return $hash;
@@ -204,20 +204,20 @@  discard block
 block discarded – undo
204 204
 		$this->xcloner_sanitization = $this->get_xcloner_container()->get_xcloner_sanitization();
205 205
 
206 206
 		//ADDING MISSING OPTIONS
207
-		if ( false == get_option( 'xcloner_mysql_settings_page' ) ) {
208
-			add_option( 'xcloner_mysql_settings_page' );
207
+		if (false == get_option('xcloner_mysql_settings_page')) {
208
+			add_option('xcloner_mysql_settings_page');
209 209
 		} // end if
210 210
 
211
-		if ( false == get_option( 'xcloner_cron_settings_page' ) ) {
212
-			add_option( 'xcloner_cron_settings_page' );
211
+		if (false == get_option('xcloner_cron_settings_page')) {
212
+			add_option('xcloner_cron_settings_page');
213 213
 		} // end if
214 214
 
215
-		if ( false == get_option( 'xcloner_system_settings_page' ) ) {
216
-			add_option( 'xcloner_system_settings_page' );
215
+		if (false == get_option('xcloner_system_settings_page')) {
216
+			add_option('xcloner_system_settings_page');
217 217
 		} // end if
218 218
 
219
-		if ( false == get_option( 'xcloner_cleanup_settings_page' ) ) {
220
-			add_option( 'xcloner_cleanup_settings_page' );
219
+		if (false == get_option('xcloner_cleanup_settings_page')) {
220
+			add_option('xcloner_cleanup_settings_page');
221 221
 		} // end if
222 222
 
223 223
 
@@ -225,31 +225,31 @@  discard block
 block discarded – undo
225 225
 		//GENERAL section
226 226
 		add_settings_section(
227 227
 			'xcloner_general_settings_group',
228
-			__( ' ' ),
229
-			array( $this, 'xcloner_settings_section_cb' ),
228
+			__(' '),
229
+			array($this, 'xcloner_settings_section_cb'),
230 230
 			'xcloner_settings_page'
231 231
 		);
232 232
 		//MYSQL section
233 233
 		add_settings_section(
234 234
 			'xcloner_mysql_settings_group',
235
-			__( ' ' ),
236
-			array( $this, 'xcloner_settings_section_cb' ),
235
+			__(' '),
236
+			array($this, 'xcloner_settings_section_cb'),
237 237
 			'xcloner_mysql_settings_page'
238 238
 		);
239 239
 
240 240
 		//SYSTEM section
241 241
 		add_settings_section(
242 242
 			'xcloner_system_settings_group',
243
-			__( 'These are advanced options recommended for developers!', 'xcloner-backup-and-restore' ),
244
-			array( $this, 'xcloner_settings_section_cb' ),
243
+			__('These are advanced options recommended for developers!', 'xcloner-backup-and-restore'),
244
+			array($this, 'xcloner_settings_section_cb'),
245 245
 			'xcloner_system_settings_page'
246 246
 		);
247 247
 
248 248
 		//CLEANUP section
249 249
 		add_settings_section(
250 250
 			'xcloner_cleanup_settings_group',
251
-			__( ' ' ),
252
-			array( $this, 'xcloner_settings_section_cb' ),
251
+			__(' '),
252
+			array($this, 'xcloner_settings_section_cb'),
253 253
 			'xcloner_cleanup_settings_page'
254 254
 		);
255 255
 
@@ -257,269 +257,269 @@  discard block
 block discarded – undo
257 257
 		//CRON section
258 258
 		add_settings_section(
259 259
 			'xcloner_cron_settings_group',
260
-			__( ' ' ),
261
-			array( $this, 'xcloner_settings_section_cb' ),
260
+			__(' '),
261
+			array($this, 'xcloner_settings_section_cb'),
262 262
 			'xcloner_cron_settings_page'
263 263
 		);
264 264
 
265 265
 
266 266
 		//REGISTERING THE 'GENERAL SECTION' FIELDS
267
-		register_setting( 'xcloner_general_settings_group', 'xcloner_backup_compression_level', array(
267
+		register_setting('xcloner_general_settings_group', 'xcloner_backup_compression_level', array(
268 268
 			$this->xcloner_sanitization,
269 269
 			"sanitize_input_as_int"
270
-		) );
270
+		));
271 271
 		add_settings_field(
272 272
 			'xcloner_backup_compression_level',
273
-			__( 'Backup Compression Level', 'xcloner-backup-and-restore' ),
274
-			array( $this, 'do_form_range_field' ),
273
+			__('Backup Compression Level', 'xcloner-backup-and-restore'),
274
+			array($this, 'do_form_range_field'),
275 275
 			'xcloner_settings_page',
276 276
 			'xcloner_general_settings_group',
277 277
 			array(
278 278
 				'xcloner_backup_compression_level',
279
-				__( 'Options between [0-9]. Value 0 means no compression, while 9 is maximum compression affecting cpu load', 'xcloner-backup-and-restore' ),
279
+				__('Options between [0-9]. Value 0 means no compression, while 9 is maximum compression affecting cpu load', 'xcloner-backup-and-restore'),
280 280
 				0,
281 281
 				9
282 282
 			)
283 283
 		);
284 284
 
285
-		register_setting( 'xcloner_general_settings_group', 'xcloner_start_path', array(
285
+		register_setting('xcloner_general_settings_group', 'xcloner_start_path', array(
286 286
 			$this->xcloner_sanitization,
287 287
 			"sanitize_input_as_absolute_path"
288
-		) );
288
+		));
289 289
 		add_settings_field(
290 290
 			'xcloner_start_path',
291
-			__( 'Backup Start Location', 'xcloner-backup-and-restore' ),
292
-			array( $this, 'do_form_text_field' ),
291
+			__('Backup Start Location', 'xcloner-backup-and-restore'),
292
+			array($this, 'do_form_text_field'),
293 293
 			'xcloner_settings_page',
294 294
 			'xcloner_general_settings_group',
295 295
 			array(
296 296
 				'xcloner_start_path',
297
-				__( 'Base path location from where XCloner can start the Backup.', 'xcloner-backup-and-restore' ),
297
+				__('Base path location from where XCloner can start the Backup.', 'xcloner-backup-and-restore'),
298 298
 				$this->get_xcloner_start_path(),
299 299
 				//'disabled'
300 300
 			)
301 301
 		);
302 302
 
303
-		register_setting( 'xcloner_general_settings_group', 'xcloner_store_path', array(
303
+		register_setting('xcloner_general_settings_group', 'xcloner_store_path', array(
304 304
 			$this->xcloner_sanitization,
305 305
 			"sanitize_input_as_absolute_path"
306
-		) );
306
+		));
307 307
 		add_settings_field(
308 308
 			'xcloner_store_path',
309
-			__( 'Backup Storage Location', 'xcloner-backup-and-restore' ),
310
-			array( $this, 'do_form_text_field' ),
309
+			__('Backup Storage Location', 'xcloner-backup-and-restore'),
310
+			array($this, 'do_form_text_field'),
311 311
 			'xcloner_settings_page',
312 312
 			'xcloner_general_settings_group',
313 313
 			array(
314 314
 				'xcloner_store_path',
315
-				__( 'Location where XCloner will store the Backup archives.', 'xcloner-backup-and-restore' ),
315
+				__('Location where XCloner will store the Backup archives.', 'xcloner-backup-and-restore'),
316 316
 				$this->get_xcloner_store_path(),
317 317
 				//'disabled'
318 318
 			)
319 319
 		);
320 320
 
321
-		register_setting( 'xcloner_general_settings_group', 'xcloner_enable_log', array(
321
+		register_setting('xcloner_general_settings_group', 'xcloner_enable_log', array(
322 322
 			$this->xcloner_sanitization,
323 323
 			"sanitize_input_as_int"
324
-		) );
324
+		));
325 325
 		add_settings_field(
326 326
 			'xcloner_enable_log',
327
-			__( 'Enable XCloner Backup Log', 'xcloner-backup-and-restore' ),
328
-			array( $this, 'do_form_switch_field' ),
327
+			__('Enable XCloner Backup Log', 'xcloner-backup-and-restore'),
328
+			array($this, 'do_form_switch_field'),
329 329
 			'xcloner_settings_page',
330 330
 			'xcloner_general_settings_group',
331 331
 			array(
332 332
 				'xcloner_enable_log',
333
-				sprintf( __( 'Enable the XCloner Backup log. You will find it stored unde the Backup Storage Location, file %s', 'xcloner-backup-and-restore' ), $this->get_logger_filename() )
333
+				sprintf(__('Enable the XCloner Backup log. You will find it stored unde the Backup Storage Location, file %s', 'xcloner-backup-and-restore'), $this->get_logger_filename())
334 334
 			)
335 335
 		);
336 336
 
337
-		register_setting( 'xcloner_general_settings_group', 'xcloner_enable_pre_update_backup', array(
337
+		register_setting('xcloner_general_settings_group', 'xcloner_enable_pre_update_backup', array(
338 338
 			$this->xcloner_sanitization,
339 339
 			"sanitize_input_as_int"
340
-		) );
340
+		));
341 341
 		add_settings_field(
342 342
 			'xcloner_enable_pre_update_backup',
343
-			__( 'Generate Backups before Automatic WP Upgrades', 'xcloner-backup-and-restore' ),
344
-			array( $this, 'do_form_switch_field' ),
343
+			__('Generate Backups before Automatic WP Upgrades', 'xcloner-backup-and-restore'),
344
+			array($this, 'do_form_switch_field'),
345 345
 			'xcloner_settings_page',
346 346
 			'xcloner_general_settings_group',
347 347
 			array(
348 348
 				'xcloner_enable_pre_update_backup',
349
-				sprintf( __( 'Attempt to generate a core, plugins, themes or languages files backup before the automatic update of Wordpress core, plugins, themes or languages files.', 'xcloner-backup-and-restore' ), $this->get_logger_filename() )
349
+				sprintf(__('Attempt to generate a core, plugins, themes or languages files backup before the automatic update of Wordpress core, plugins, themes or languages files.', 'xcloner-backup-and-restore'), $this->get_logger_filename())
350 350
 			)
351 351
 		);
352 352
 
353
-		register_setting( 'xcloner_general_settings_group', 'xcloner_regex_exclude', array(
353
+		register_setting('xcloner_general_settings_group', 'xcloner_regex_exclude', array(
354 354
 			$this->xcloner_sanitization,
355 355
 			"sanitize_input_as_raw"
356
-		) );
356
+		));
357 357
 		add_settings_field(
358 358
 			'xcloner_regex_exclude',
359
-			__( 'Regex Exclude Files', 'xcloner-backup-and-restore' ),
360
-			array( $this, 'do_form_textarea_field' ),
359
+			__('Regex Exclude Files', 'xcloner-backup-and-restore'),
360
+			array($this, 'do_form_textarea_field'),
361 361
 			'xcloner_settings_page',
362 362
 			'xcloner_general_settings_group',
363 363
 			array(
364 364
 				'xcloner_regex_exclude',
365
-				__( 'Regular expression match to exclude files and folders, example patterns provided below, one pattern per line', 'xcloner-backup-and-restore' ),
365
+				__('Regular expression match to exclude files and folders, example patterns provided below, one pattern per line', 'xcloner-backup-and-restore'),
366 366
 				//$this->get_xcloner_store_path(), 
367 367
 				//'disabled'
368 368
 			)
369 369
 		);
370 370
 
371 371
 		//REGISTERING THE 'MYSQL SECTION' FIELDS
372
-		register_setting( 'xcloner_mysql_settings_group', 'xcloner_enable_mysql_backup', array(
372
+		register_setting('xcloner_mysql_settings_group', 'xcloner_enable_mysql_backup', array(
373 373
 			$this->xcloner_sanitization,
374 374
 			"sanitize_input_as_int"
375
-		) );
375
+		));
376 376
 		add_settings_field(
377 377
 			'xcloner_enable_mysql_backup',
378
-			__( 'Enable Mysql Backup', 'xcloner-backup-and-restore' ),
379
-			array( $this, 'do_form_switch_field' ),
378
+			__('Enable Mysql Backup', 'xcloner-backup-and-restore'),
379
+			array($this, 'do_form_switch_field'),
380 380
 			'xcloner_mysql_settings_page',
381 381
 			'xcloner_mysql_settings_group',
382 382
 			array(
383 383
 				'xcloner_enable_mysql_backup',
384
-				__( 'Enable Mysql Backup Option. If you don\'t want to backup the database, you can disable this.', 'xcloner-backup-and-restore' )
384
+				__('Enable Mysql Backup Option. If you don\'t want to backup the database, you can disable this.', 'xcloner-backup-and-restore')
385 385
 			)
386 386
 		);
387 387
 
388
-		register_setting( 'xcloner_mysql_settings_group', 'xcloner_backup_only_wp_tables' );
388
+		register_setting('xcloner_mysql_settings_group', 'xcloner_backup_only_wp_tables');
389 389
 		add_settings_field(
390 390
 			'xcloner_backup_only_wp_tables',
391
-			__( 'Backup only WP tables', 'xcloner-backup-and-restore' ),
392
-			array( $this, 'do_form_switch_field' ),
391
+			__('Backup only WP tables', 'xcloner-backup-and-restore'),
392
+			array($this, 'do_form_switch_field'),
393 393
 			'xcloner_mysql_settings_page',
394 394
 			'xcloner_mysql_settings_group',
395 395
 			array(
396 396
 				'xcloner_backup_only_wp_tables',
397
-				sprintf( __( 'Enable this if you only want to Backup only tables starting with \'%s\' prefix', 'xcloner-backup-and-restore' ), $this->get_table_prefix() )
397
+				sprintf(__('Enable this if you only want to Backup only tables starting with \'%s\' prefix', 'xcloner-backup-and-restore'), $this->get_table_prefix())
398 398
 			)
399 399
 		);
400 400
 
401
-		register_setting( 'xcloner_mysql_settings_group', 'xcloner_mysql_hostname', array(
401
+		register_setting('xcloner_mysql_settings_group', 'xcloner_mysql_hostname', array(
402 402
 			$this->xcloner_sanitization,
403 403
 			"sanitize_input_as_raw"
404
-		) );
404
+		));
405 405
 		add_settings_field(
406 406
 			'xcloner_mysql_hostname',
407
-			__( 'Mysql Hostname', 'xcloner-backup-and-restore' ),
408
-			array( $this, 'do_form_text_field' ),
407
+			__('Mysql Hostname', 'xcloner-backup-and-restore'),
408
+			array($this, 'do_form_text_field'),
409 409
 			'xcloner_mysql_settings_page',
410 410
 			'xcloner_mysql_settings_group',
411 411
 			array(
412 412
 				'xcloner_mysql_hostname',
413
-				__( 'Wordpress mysql hostname', 'xcloner-backup-and-restore' ),
413
+				__('Wordpress mysql hostname', 'xcloner-backup-and-restore'),
414 414
 				$this->get_db_hostname(),
415 415
 				'disabled'
416 416
 			)
417 417
 		);
418 418
 
419
-		register_setting( 'xcloner_mysql_settings_group', 'xcloner_mysql_username', array(
419
+		register_setting('xcloner_mysql_settings_group', 'xcloner_mysql_username', array(
420 420
 			$this->xcloner_sanitization,
421 421
 			"sanitize_input_as_raw"
422
-		) );
422
+		));
423 423
 		add_settings_field(
424 424
 			'xcloner_mysql_username',
425
-			__( 'Mysql Username', 'xcloner-backup-and-restore' ),
426
-			array( $this, 'do_form_text_field' ),
425
+			__('Mysql Username', 'xcloner-backup-and-restore'),
426
+			array($this, 'do_form_text_field'),
427 427
 			'xcloner_mysql_settings_page',
428 428
 			'xcloner_mysql_settings_group',
429 429
 			array(
430 430
 				'xcloner_mysql_username',
431
-				__( 'Wordpress mysql username', 'xcloner-backup-and-restore' ),
431
+				__('Wordpress mysql username', 'xcloner-backup-and-restore'),
432 432
 				$this->get_db_username(),
433 433
 				'disabled'
434 434
 			)
435 435
 		);
436 436
 
437
-		register_setting( 'xcloner_mysql_settings_group', 'xcloner_mysql_database', array(
437
+		register_setting('xcloner_mysql_settings_group', 'xcloner_mysql_database', array(
438 438
 			$this->xcloner_sanitization,
439 439
 			"sanitize_input_as_raw"
440
-		) );
440
+		));
441 441
 		add_settings_field(
442 442
 			'xcloner_mysql_database',
443
-			__( 'Mysql Database', 'xcloner-backup-and-restore' ),
444
-			array( $this, 'do_form_text_field' ),
443
+			__('Mysql Database', 'xcloner-backup-and-restore'),
444
+			array($this, 'do_form_text_field'),
445 445
 			'xcloner_mysql_settings_page',
446 446
 			'xcloner_mysql_settings_group',
447 447
 			array(
448 448
 				'xcloner_mysql_database',
449
-				__( 'Wordpress mysql database', 'xcloner-backup-and-restore' ),
449
+				__('Wordpress mysql database', 'xcloner-backup-and-restore'),
450 450
 				$this->get_db_database(),
451 451
 				'disabled'
452 452
 			)
453 453
 		);
454 454
 
455 455
 		//REGISTERING THE 'SYSTEM SECTION' FIELDS
456
-		register_setting( 'xcloner_system_settings_group', 'xcloner_size_limit_per_request', array(
456
+		register_setting('xcloner_system_settings_group', 'xcloner_size_limit_per_request', array(
457 457
 			$this->xcloner_sanitization,
458 458
 			"sanitize_input_as_int"
459
-		) );
459
+		));
460 460
 		add_settings_field(
461 461
 			'xcloner_size_limit_per_request',
462
-			__( 'Data Size Limit Per Request', 'xcloner-backup-and-restore' ),
463
-			array( $this, 'do_form_range_field' ),
462
+			__('Data Size Limit Per Request', 'xcloner-backup-and-restore'),
463
+			array($this, 'do_form_range_field'),
464 464
 			'xcloner_system_settings_page',
465 465
 			'xcloner_system_settings_group',
466 466
 			array(
467 467
 				'xcloner_size_limit_per_request',
468
-				__( 'Use this option to set how much file data can XCloner backup in one AJAX request. Range 0-1024 MB', 'xcloner-backup-and-restore' ),
468
+				__('Use this option to set how much file data can XCloner backup in one AJAX request. Range 0-1024 MB', 'xcloner-backup-and-restore'),
469 469
 				0,
470 470
 				1024
471 471
 			)
472 472
 		);
473 473
 
474
-		register_setting( 'xcloner_system_settings_group', 'xcloner_files_to_process_per_request', array(
474
+		register_setting('xcloner_system_settings_group', 'xcloner_files_to_process_per_request', array(
475 475
 			$this->xcloner_sanitization,
476 476
 			"sanitize_input_as_int"
477
-		) );
477
+		));
478 478
 		add_settings_field(
479 479
 			'xcloner_files_to_process_per_request',
480
-			__( 'Files To Process Per Request', 'xcloner-backup-and-restore' ),
481
-			array( $this, 'do_form_range_field' ),
480
+			__('Files To Process Per Request', 'xcloner-backup-and-restore'),
481
+			array($this, 'do_form_range_field'),
482 482
 			'xcloner_system_settings_page',
483 483
 			'xcloner_system_settings_group',
484 484
 			array(
485 485
 				'xcloner_files_to_process_per_request',
486
-				__( 'Use this option to set how many files XCloner should process at one time before doing another AJAX call', 'xcloner-backup-and-restore' ),
486
+				__('Use this option to set how many files XCloner should process at one time before doing another AJAX call', 'xcloner-backup-and-restore'),
487 487
 				0,
488 488
 				1000
489 489
 			)
490 490
 		);
491 491
 
492
-		register_setting( 'xcloner_system_settings_group', 'xcloner_directories_to_scan_per_request', array(
492
+		register_setting('xcloner_system_settings_group', 'xcloner_directories_to_scan_per_request', array(
493 493
 			$this->xcloner_sanitization,
494 494
 			"sanitize_input_as_int"
495
-		) );
495
+		));
496 496
 		add_settings_field(
497 497
 			'xcloner_directories_to_scan_per_request',
498
-			__( 'Directories To Scan Per Request', 'xcloner-backup-and-restore' ),
499
-			array( $this, 'do_form_range_field' ),
498
+			__('Directories To Scan Per Request', 'xcloner-backup-and-restore'),
499
+			array($this, 'do_form_range_field'),
500 500
 			'xcloner_system_settings_page',
501 501
 			'xcloner_system_settings_group',
502 502
 			array(
503 503
 				'xcloner_directories_to_scan_per_request',
504
-				__( 'Use this option to set how many directories XCloner should scan at one time before doing another AJAX call', 'xcloner-backup-and-restore' ),
504
+				__('Use this option to set how many directories XCloner should scan at one time before doing another AJAX call', 'xcloner-backup-and-restore'),
505 505
 				0,
506 506
 				1000
507 507
 			)
508 508
 		);
509 509
 
510
-		register_setting( 'xcloner_system_settings_group', 'xcloner_database_records_per_request', array(
510
+		register_setting('xcloner_system_settings_group', 'xcloner_database_records_per_request', array(
511 511
 			$this->xcloner_sanitization,
512 512
 			"sanitize_input_as_int"
513
-		) );
513
+		));
514 514
 		add_settings_field(
515 515
 			'xcloner_database_records_per_request',
516
-			__( 'Database Records Per Request', 'xcloner-backup-and-restore' ),
517
-			array( $this, 'do_form_range_field' ),
516
+			__('Database Records Per Request', 'xcloner-backup-and-restore'),
517
+			array($this, 'do_form_range_field'),
518 518
 			'xcloner_system_settings_page',
519 519
 			'xcloner_system_settings_group',
520 520
 			array(
521 521
 				'xcloner_database_records_per_request',
522
-				__( 'Use this option to set how many database table records should be fetched per AJAX request, or set to 0 to fetch all.  Range 0-100000 records', 'xcloner-backup-and-restore' ),
522
+				__('Use this option to set how many database table records should be fetched per AJAX request, or set to 0 to fetch all.  Range 0-100000 records', 'xcloner-backup-and-restore'),
523 523
 				0,
524 524
 				100000
525 525
 			)
@@ -537,127 +537,127 @@  discard block
 block discarded – undo
537 537
 	         )
538 538
 	    );*/
539 539
 
540
-		register_setting( 'xcloner_system_settings_group', 'xcloner_exclude_files_larger_than_mb', array(
540
+		register_setting('xcloner_system_settings_group', 'xcloner_exclude_files_larger_than_mb', array(
541 541
 			$this->xcloner_sanitization,
542 542
 			"sanitize_input_as_int"
543
-		) );
543
+		));
544 544
 		add_settings_field(
545 545
 			'xcloner_exclude_files_larger_than_mb',
546
-			__( 'Exclude files larger than (MB)', 'xcloner-backup-and-restore' ),
547
-			array( $this, 'do_form_number_field' ),
546
+			__('Exclude files larger than (MB)', 'xcloner-backup-and-restore'),
547
+			array($this, 'do_form_number_field'),
548 548
 			'xcloner_system_settings_page',
549 549
 			'xcloner_system_settings_group',
550 550
 			array(
551 551
 				'xcloner_exclude_files_larger_than_mb',
552
-				__( 'Use this option to automatically exclude files larger than a certain size in MB, or set to 0 to include all. Range 0-1000 MB', 'xcloner-backup-and-restore' ),
552
+				__('Use this option to automatically exclude files larger than a certain size in MB, or set to 0 to include all. Range 0-1000 MB', 'xcloner-backup-and-restore'),
553 553
 			)
554 554
 		);
555 555
 
556
-		register_setting( 'xcloner_system_settings_group', 'xcloner_split_backup_limit', array(
556
+		register_setting('xcloner_system_settings_group', 'xcloner_split_backup_limit', array(
557 557
 			$this->xcloner_sanitization,
558 558
 			"sanitize_input_as_int"
559
-		) );
559
+		));
560 560
 		add_settings_field(
561 561
 			'xcloner_split_backup_limit',
562
-			__( 'Split Backup Archive Limit (MB)', 'xcloner-backup-and-restore' ),
563
-			array( $this, 'do_form_number_field' ),
562
+			__('Split Backup Archive Limit (MB)', 'xcloner-backup-and-restore'),
563
+			array($this, 'do_form_number_field'),
564 564
 			'xcloner_system_settings_page',
565 565
 			'xcloner_system_settings_group',
566 566
 			array(
567 567
 				'xcloner_split_backup_limit',
568
-				__( 'Use this option to automatically split the backup archive into smaller parts. Range  0-10000 MB', 'xcloner-backup-and-restore' ),
568
+				__('Use this option to automatically split the backup archive into smaller parts. Range  0-10000 MB', 'xcloner-backup-and-restore'),
569 569
 			)
570 570
 		);
571 571
 
572
-		register_setting( 'xcloner_system_settings_group', 'xcloner_force_tmp_path_site_root' );
572
+		register_setting('xcloner_system_settings_group', 'xcloner_force_tmp_path_site_root');
573 573
 		add_settings_field(
574 574
 			'xcloner_force_tmp_path_site_root',
575
-			__( 'Force Temporary Path Within XCloner Storage', 'xcloner-backup-and-restore' ),
576
-			array( $this, 'do_form_switch_field' ),
575
+			__('Force Temporary Path Within XCloner Storage', 'xcloner-backup-and-restore'),
576
+			array($this, 'do_form_switch_field'),
577 577
 			'xcloner_system_settings_page',
578 578
 			'xcloner_system_settings_group',
579 579
 			array(
580 580
 				'xcloner_force_tmp_path_site_root',
581
-				sprintf( __( 'Enable this option if you want the XCloner Temporary Path to be within your XCloner Storage Location', 'xcloner-backup-and-restore' ), $this->get_table_prefix() )
581
+				sprintf(__('Enable this option if you want the XCloner Temporary Path to be within your XCloner Storage Location', 'xcloner-backup-and-restore'), $this->get_table_prefix())
582 582
 			)
583 583
 		);
584 584
 
585 585
 		//REGISTERING THE 'CLEANUP SECTION' FIELDS
586
-		register_setting( 'xcloner_cleanup_settings_group', 'xcloner_cleanup_retention_limit_days', array(
586
+		register_setting('xcloner_cleanup_settings_group', 'xcloner_cleanup_retention_limit_days', array(
587 587
 			$this->xcloner_sanitization,
588 588
 			"sanitize_input_as_int"
589
-		) );
589
+		));
590 590
 		add_settings_field(
591 591
 			'xcloner_cleanup_retention_limit_days',
592
-			__( 'Cleanup by Date(days)', 'xcloner-backup-and-restore' ),
593
-			array( $this, 'do_form_number_field' ),
592
+			__('Cleanup by Date(days)', 'xcloner-backup-and-restore'),
593
+			array($this, 'do_form_number_field'),
594 594
 			'xcloner_cleanup_settings_page',
595 595
 			'xcloner_cleanup_settings_group',
596 596
 			array(
597 597
 				'xcloner_cleanup_retention_limit_days',
598
-				__( 'Specify the maximum number of days a backup archive can be kept on the server. 0 disables this option', 'xcloner-backup-and-restore' )
598
+				__('Specify the maximum number of days a backup archive can be kept on the server. 0 disables this option', 'xcloner-backup-and-restore')
599 599
 			)
600 600
 		);
601 601
 
602
-		register_setting( 'xcloner_cleanup_settings_group', 'xcloner_cleanup_retention_limit_archives', array(
602
+		register_setting('xcloner_cleanup_settings_group', 'xcloner_cleanup_retention_limit_archives', array(
603 603
 			$this->xcloner_sanitization,
604 604
 			"sanitize_input_as_int"
605
-		) );
605
+		));
606 606
 		add_settings_field(
607 607
 			'xcloner_cleanup_retention_limit_archives',
608
-			__( 'Cleanup by Quantity', 'xcloner-backup-and-restore' ),
609
-			array( $this, 'do_form_number_field' ),
608
+			__('Cleanup by Quantity', 'xcloner-backup-and-restore'),
609
+			array($this, 'do_form_number_field'),
610 610
 			'xcloner_cleanup_settings_page',
611 611
 			'xcloner_cleanup_settings_group',
612 612
 			array(
613 613
 				'xcloner_cleanup_retention_limit_archives',
614
-				__( 'Specify the maximum number of backup archives to keep on the server. 0 disables this option', 'xcloner-backup-and-restore' )
614
+				__('Specify the maximum number of backup archives to keep on the server. 0 disables this option', 'xcloner-backup-and-restore')
615 615
 			)
616 616
 		);
617 617
 
618
-		register_setting( 'xcloner_cleanup_settings_group', 'xcloner_cleanup_capacity_limit', array(
618
+		register_setting('xcloner_cleanup_settings_group', 'xcloner_cleanup_capacity_limit', array(
619 619
 			$this->xcloner_sanitization,
620 620
 			"sanitize_input_as_int"
621
-		) );
621
+		));
622 622
 		add_settings_field(
623 623
 			'xcloner_cleanup_capacity_limit',
624
-			__( 'Cleanup by Capacity(MB)', 'xcloner-backup-and-restore' ),
625
-			array( $this, 'do_form_number_field' ),
624
+			__('Cleanup by Capacity(MB)', 'xcloner-backup-and-restore'),
625
+			array($this, 'do_form_number_field'),
626 626
 			'xcloner_cleanup_settings_page',
627 627
 			'xcloner_cleanup_settings_group',
628 628
 			array(
629 629
 				'xcloner_cleanup_capacity_limit',
630
-				__( 'Remove oldest backups if all created backups exceed the configured limit in Megabytes. 0 disables this option', 'xcloner-backup-and-restore' )
630
+				__('Remove oldest backups if all created backups exceed the configured limit in Megabytes. 0 disables this option', 'xcloner-backup-and-restore')
631 631
 			)
632 632
 		);
633 633
 
634
-		register_setting( 'xcloner_cleanup_settings_group', 'xcloner_cleanup_delete_after_remote_transfer', array(
634
+		register_setting('xcloner_cleanup_settings_group', 'xcloner_cleanup_delete_after_remote_transfer', array(
635 635
 			$this->xcloner_sanitization,
636 636
 			"sanitize_input_as_int"
637
-		) );
637
+		));
638 638
 		add_settings_field(
639 639
 			'xcloner_cleanup_delete_after_remote_transfer',
640
-			__( 'Delete Backup After Remote Storage Transfer', 'xcloner-backup-and-restore' ),
641
-			array( $this, 'do_form_switch_field' ),
640
+			__('Delete Backup After Remote Storage Transfer', 'xcloner-backup-and-restore'),
641
+			array($this, 'do_form_switch_field'),
642 642
 			'xcloner_cleanup_settings_page',
643 643
 			'xcloner_cleanup_settings_group',
644 644
 			array(
645 645
 				'xcloner_cleanup_delete_after_remote_transfer',
646
-				__( 'Remove backup created automatically from local storage after sending the backup to Remote Storage', 'xcloner-backup-and-restore' )
646
+				__('Remove backup created automatically from local storage after sending the backup to Remote Storage', 'xcloner-backup-and-restore')
647 647
 			)
648 648
 		);
649 649
 
650 650
 		//REGISTERING THE 'CRON SECTION' FIELDS
651
-		register_setting( 'xcloner_cron_settings_group', 'xcloner_cron_frequency' );
651
+		register_setting('xcloner_cron_settings_group', 'xcloner_cron_frequency');
652 652
 		add_settings_field(
653 653
 			'xcloner_cron_frequency',
654
-			__( 'Cron frequency', 'xcloner-backup-and-restore' ),
655
-			array( $this, 'do_form_text_field' ),
654
+			__('Cron frequency', 'xcloner-backup-and-restore'),
655
+			array($this, 'do_form_text_field'),
656 656
 			'xcloner_cron_settings_page',
657 657
 			'xcloner_cron_settings_group',
658 658
 			array(
659 659
 				'xcloner_cron_frequency',
660
-				__( 'Cron frequency' )
660
+				__('Cron frequency')
661 661
 			)
662 662
 		);
663 663
 	}
@@ -675,26 +675,26 @@  discard block
 block discarded – undo
675 675
 	}
676 676
 
677 677
 	// text field content cb
678
-	public function do_form_text_field( $params ) {
679
-		if ( ! isset( $params['3'] ) ) {
678
+	public function do_form_text_field($params) {
679
+		if (!isset($params['3'])) {
680 680
 			$params[3] = 0;
681 681
 		}
682
-		if ( ! isset( $params['2'] ) ) {
682
+		if (!isset($params['2'])) {
683 683
 			$params[2] = 0;
684 684
 		}
685 685
 
686
-		list( $fieldname, $label, $value, $disabled ) = $params;
686
+		list($fieldname, $label, $value, $disabled) = $params;
687 687
 
688
-		if ( ! $value ) {
689
-			$value = get_option( $fieldname );
688
+		if (!$value) {
689
+			$value = get_option($fieldname);
690 690
 		}
691 691
 		// output the field
692 692
 		?>
693 693
         <div class="row">
694 694
             <div class="input-field col s10 m10 l8">
695
-                <input class="validate" <?php echo ( $disabled ) ? "disabled" : "" ?> name="<?php echo $fieldname ?>"
695
+                <input class="validate" <?php echo ($disabled) ? "disabled" : "" ?> name="<?php echo $fieldname ?>"
696 696
                        id="<?php echo $fieldname ?>" type="text" class="validate"
697
-                       value="<?php echo isset( $value ) ? esc_attr( $value ) : ''; ?>">
697
+                       value="<?php echo isset($value) ? esc_attr($value) : ''; ?>">
698 698
             </div>
699 699
             <div class="col s2 m2 ">
700 700
                 <a class="btn-floating tooltipped btn-small" data-position="left" data-delay="50"
@@ -707,26 +707,26 @@  discard block
 block discarded – undo
707 707
 	}
708 708
 
709 709
 	// textarea field content cb
710
-	public function do_form_textarea_field( $params ) {
711
-		if ( ! isset( $params['3'] ) ) {
710
+	public function do_form_textarea_field($params) {
711
+		if (!isset($params['3'])) {
712 712
 			$params[3] = 0;
713 713
 		}
714
-		if ( ! isset( $params['2'] ) ) {
714
+		if (!isset($params['2'])) {
715 715
 			$params[2] = 0;
716 716
 		}
717 717
 
718
-		list( $fieldname, $label, $value, $disabled ) = $params;
718
+		list($fieldname, $label, $value, $disabled) = $params;
719 719
 
720
-		if ( ! $value ) {
721
-			$value = get_option( $fieldname );
720
+		if (!$value) {
721
+			$value = get_option($fieldname);
722 722
 		}
723 723
 		// output the field
724 724
 		?>
725 725
         <div class="row">
726 726
             <div class="input-field col s10 m10 l8">
727
-                <textarea class="validate" <?php echo ( $disabled ) ? "disabled" : "" ?> name="<?php echo $fieldname ?>"
727
+                <textarea class="validate" <?php echo ($disabled) ? "disabled" : "" ?> name="<?php echo $fieldname ?>"
728 728
                           id="<?php echo $fieldname ?>" type="text" class="validate"
729
-                          value=""><?php echo isset( $value ) ? esc_attr( $value ) : ''; ?></textarea>
729
+                          value=""><?php echo isset($value) ? esc_attr($value) : ''; ?></textarea>
730 730
             </div>
731 731
             <div class="col s2 m2 ">
732 732
                 <a class="btn-floating tooltipped btn-small" data-position="center" data-html="true" data-delay="50"
@@ -735,39 +735,39 @@  discard block
 block discarded – undo
735 735
             <div class="col s12">
736 736
                 <ul class="xcloner_regex_exclude_limit">
737 737
                     <li>Exclude all except .php file: <span
738
-                                class="regex_pattern"><?php echo htmlentities( '(.*)\.(.+)$(?<!(php))' ) ?></span></li>
738
+                                class="regex_pattern"><?php echo htmlentities('(.*)\.(.+)$(?<!(php))') ?></span></li>
739 739
                     <li>Exclude all except .php and .txt: <span
740
-                                class="regex_pattern"> <?php echo htmlentities( '(.*)\.(.+)$(?<!(php|txt))' ) ?></span>
740
+                                class="regex_pattern"> <?php echo htmlentities('(.*)\.(.+)$(?<!(php|txt))') ?></span>
741 741
                     </li>
742 742
                     <li>Exclude all .avi files: <span
743
-                                class="regex_pattern"> <?php echo htmlentities( '(.*)\.(.+)$(?<=(avi))' ) ?></span></li>
743
+                                class="regex_pattern"> <?php echo htmlentities('(.*)\.(.+)$(?<=(avi))') ?></span></li>
744 744
                     <li>Exclude all .jpg,.gif and .png files: <span
745
-                                class="regex_pattern"> <?php echo htmlentities( '(.*)\.(.+)$(?<=(gif|png|jpg))' ) ?></span>
745
+                                class="regex_pattern"> <?php echo htmlentities('(.*)\.(.+)$(?<=(gif|png|jpg))') ?></span>
746 746
                     </li>
747 747
                     <li>Exclude all .svn and .git: <span
748
-                                class="regex_pattern"> <?php echo htmlentities( '(.*)\.(svn|git)(.*)$' ) ?></span></li>
748
+                                class="regex_pattern"> <?php echo htmlentities('(.*)\.(svn|git)(.*)$') ?></span></li>
749 749
                     <li>Exclude root directory /test: <span
750
-                                class="regex_pattern"> <?php echo htmlentities( '\/test(.*)$' ) ?></span> or <span
751
-                                class="regex_pattern"> <?php echo htmlentities( 'test(.*)$' ) ?></span></li>
750
+                                class="regex_pattern"> <?php echo htmlentities('\/test(.*)$') ?></span> or <span
751
+                                class="regex_pattern"> <?php echo htmlentities('test(.*)$') ?></span></li>
752 752
                     <li>Exclude the wp-admin folder: <span
753
-                                class="regex_pattern"> <?php echo htmlentities( '(\/wp-admin)(.*)$' ) ?></span></li>
753
+                                class="regex_pattern"> <?php echo htmlentities('(\/wp-admin)(.*)$') ?></span></li>
754 754
                     <li>Exclude the wp-content/uploads folder: <span
755
-                                class="regex_pattern"> <?php echo htmlentities( '(\/wp-content\/uploads)(.*)$' ) ?></span>
755
+                                class="regex_pattern"> <?php echo htmlentities('(\/wp-content\/uploads)(.*)$') ?></span>
756 756
                     </li>
757 757
                     <li>Exclude the wp-admin, wp-includes and wp-config.php: <span
758
-                                class="regex_pattern"> <?php echo htmlentities( '\/(wp-admin|wp-includes|wp-config.php)(.*)$' ) ?></span>
758
+                                class="regex_pattern"> <?php echo htmlentities('\/(wp-admin|wp-includes|wp-config.php)(.*)$') ?></span>
759 759
                     </li>
760 760
                     <li>Exclude wp-content/updraft and wp/content/uploads/wp_all_backup folder :<span
761 761
                                 class="regex_pattern">\/(wp-content\/updraft|\/wp-content\/uploads\/wp_all_backup)(.*)$</span>
762 762
                     </li>
763 763
                     <li>Exclude all cache folders from wp-content/ and it's subdirectories: <span
764
-                                class="regex_pattern"> <?php echo htmlentities( '\/wp-content(.*)\/cache($|\/)(.*)' ) ?></span>
764
+                                class="regex_pattern"> <?php echo htmlentities('\/wp-content(.*)\/cache($|\/)(.*)') ?></span>
765 765
                     </li>
766 766
                     <li>Exclude wp-content/cache/ folder: <span
767
-                                class="regex_pattern"> <?php echo htmlentities( '\/wp-content\/cache(.*)' ) ?></span>
767
+                                class="regex_pattern"> <?php echo htmlentities('\/wp-content\/cache(.*)') ?></span>
768 768
                     </li>
769 769
                     <li>Exclude all error_log files: <span
770
-                                class="regex_pattern"> <?php echo htmlentities( '(.*)error_log$' ) ?></span></li>
770
+                                class="regex_pattern"> <?php echo htmlentities('(.*)error_log$') ?></span></li>
771 771
                 </ul>
772 772
             </div>
773 773
         </div>
@@ -777,26 +777,26 @@  discard block
 block discarded – undo
777 777
 	}
778 778
 
779 779
 	// number field content cb
780
-	public function do_form_number_field( $params ) {
781
-		if ( ! isset( $params['3'] ) ) {
780
+	public function do_form_number_field($params) {
781
+		if (!isset($params['3'])) {
782 782
 			$params[3] = 0;
783 783
 		}
784
-		if ( ! isset( $params['2'] ) ) {
784
+		if (!isset($params['2'])) {
785 785
 			$params[2] = 0;
786 786
 		}
787 787
 
788
-		list( $fieldname, $label, $value, $disabled ) = $params;
788
+		list($fieldname, $label, $value, $disabled) = $params;
789 789
 
790
-		if ( ! $value ) {
791
-			$value = get_option( $fieldname );
790
+		if (!$value) {
791
+			$value = get_option($fieldname);
792 792
 		}
793 793
 		// output the field
794 794
 		?>
795 795
         <div class="row">
796 796
             <div class="input-field col s10 m5 l3">
797
-                <input class="validate" <?php echo ( $disabled ) ? "disabled" : "" ?> name="<?php echo $fieldname ?>"
797
+                <input class="validate" <?php echo ($disabled) ? "disabled" : "" ?> name="<?php echo $fieldname ?>"
798 798
                        id="<?php echo $fieldname ?>" type="number" class="validate"
799
-                       value="<?php echo isset( $value ) ? esc_attr( $value ) : ''; ?>">
799
+                       value="<?php echo isset($value) ? esc_attr($value) : ''; ?>">
800 800
             </div>
801 801
             <div class="col s2 m2 ">
802 802
                 <a class="btn-floating tooltipped btn-small" data-html="true" data-position="center" data-delay="50"
@@ -808,22 +808,22 @@  discard block
 block discarded – undo
808 808
 		<?php
809 809
 	}
810 810
 
811
-	public function do_form_range_field( $params ) {
812
-		if ( ! isset( $params['4'] ) ) {
811
+	public function do_form_range_field($params) {
812
+		if (!isset($params['4'])) {
813 813
 			$params[4] = 0;
814 814
 		}
815 815
 
816
-		list( $fieldname, $label, $range_start, $range_end, $disabled ) = $params;
817
-		$value = get_option( $fieldname );
816
+		list($fieldname, $label, $range_start, $range_end, $disabled) = $params;
817
+		$value = get_option($fieldname);
818 818
 		?>
819 819
         <div class="row">
820 820
             <div class="input-field col s10 m10 l8">
821 821
                 <p class="range-field">
822
-                    <input <?php echo ( $disabled ) ? "disabled" : "" ?> type="range" name="<?php echo $fieldname ?>"
822
+                    <input <?php echo ($disabled) ? "disabled" : "" ?> type="range" name="<?php echo $fieldname ?>"
823 823
                                                                          id="<?php echo $fieldname ?>"
824 824
                                                                          min="<?php echo $range_start ?>"
825 825
                                                                          max="<?php echo $range_end ?>"
826
-                                                                         value="<?php echo isset( $value ) ? esc_attr( $value ) : ''; ?>"/>
826
+                                                                         value="<?php echo isset($value) ? esc_attr($value) : ''; ?>"/>
827 827
                 </p>
828 828
             </div>
829 829
             <div class="col s2 m2 ">
@@ -835,22 +835,22 @@  discard block
 block discarded – undo
835 835
 	}
836 836
 
837 837
 
838
-	public function do_form_switch_field( $params ) {
839
-		if ( ! isset( $params['2'] ) ) {
838
+	public function do_form_switch_field($params) {
839
+		if (!isset($params['2'])) {
840 840
 			$params[2] = 0;
841 841
 		}
842
-		list( $fieldname, $label, $disabled ) = $params;
843
-		$value = get_option( $fieldname );
842
+		list($fieldname, $label, $disabled) = $params;
843
+		$value = get_option($fieldname);
844 844
 		?>
845 845
         <div class="row">
846 846
             <div class="input-field col s10 m5 l3">
847 847
                 <div class="switch">
848 848
                     <label>
849 849
                         Off
850
-                        <input <?php echo ( $disabled ) ? "disabled" : "" ?> type="checkbox"
850
+                        <input <?php echo ($disabled) ? "disabled" : "" ?> type="checkbox"
851 851
                                                                              name="<?php echo $fieldname ?>"
852 852
                                                                              id="<?php echo $fieldname ?>"
853
-                                                                             value="1" <?php echo ( $value ) ? 'checked="checked"' : ''; ?>
853
+                                                                             value="1" <?php echo ($value) ? 'checked="checked"' : ''; ?>
854 854
                         ">
855 855
                         <span class="lever"></span>
856 856
                         On
Please login to merge, or discard this patch.
public/class-xcloner-public.php 2 patches
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -45,8 +45,6 @@
 block discarded – undo
45 45
 	 *
46 46
 	 * @since    1.0.0
47 47
 	 *
48
-	 * @param      string $plugin_name The name of the plugin.
49
-	 * @param      string $version The version of this plugin.
50 48
 	 */
51 49
 	public function __construct( Xcloner $xcloner_container ) {
52 50
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	 * @param      string $plugin_name The name of the plugin.
49 49
 	 * @param      string $version The version of this plugin.
50 50
 	 */
51
-	public function __construct( Xcloner $xcloner_container ) {
51
+	public function __construct(Xcloner $xcloner_container) {
52 52
 
53 53
 		$this->plugin_name = $xcloner_container->get_plugin_name();
54 54
 		$this->version     = $xcloner_container->get_version();
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 		 * class.
75 75
 		 */
76 76
 
77
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/xcloner-public.css', array(), $this->version, 'all' );
77
+		wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/xcloner-public.css', array(), $this->version, 'all');
78 78
 
79 79
 	}
80 80
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		 * class.
98 98
 		 */
99 99
 
100
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/xcloner-public.js', array( 'jquery' ), $this->version, false );
100
+		wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__).'js/xcloner-public.js', array('jquery'), $this->version, false);
101 101
 
102 102
 	}
103 103
 
Please login to merge, or discard this patch.