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 ( e65d67...dc9fa8 )
by Liuta
03:08
created
includes/class-xcloner-api.php 4 patches
Unused Use Statements   -5 removed lines patch added patch discarded remove patch
@@ -2,13 +2,8 @@
 block discarded – undo
2 2
 
3 3
 use League\Flysystem\Config;
4 4
 use League\Flysystem\Filesystem;
5
-use League\Flysystem\Util;
6 5
 use League\Flysystem\Adapter\Local;
7
-
8 6
 use splitbrain\PHPArchive\Tar;
9
-use splitbrain\PHPArchive\Zip;
10
-use splitbrain\PHPArchive\Archive;
11
-use splitbrain\PHPArchive\FileInfo;
12 7
 
13 8
 
14 9
 class Xcloner_Api{
Please login to merge, or discard this patch.
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -220,12 +220,12 @@  discard block
 block discarded – undo
220 220
 		}
221 221
 			
222 222
 		if( $wpdb->last_error ) {
223
-            $response['error'] = 1;
224
-            $response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/;
223
+			$response['error'] = 1;
224
+			$response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/;
225 225
             
226
-        }
226
+		}
227 227
         
228
-        $scheduler->update_wp_cron_hooks();
228
+		$scheduler->update_wp_cron_hooks();
229 229
 		$response['finished'] = 1;
230 230
 		
231 231
 		$this->send_response($response);
@@ -916,14 +916,14 @@  discard block
 block discarded – undo
916 916
 		$tar->close();
917 917
 		
918 918
 		if (file_exists($tmp_file)) {
919
-		    header('Content-Description: File Transfer');
920
-		    header('Content-Type: application/octet-stream');
921
-		    header('Content-Disposition: attachment; filename="'.basename($tmp_file).'"');
922
-		    header('Expires: 0');
923
-		    header('Cache-Control: must-revalidate');
924
-		    header('Pragma: public');
925
-		    header('Content-Length: ' . filesize($tmp_file));
926
-		    readfile($tmp_file);
919
+			header('Content-Description: File Transfer');
920
+			header('Content-Type: application/octet-stream');
921
+			header('Content-Disposition: attachment; filename="'.basename($tmp_file).'"');
922
+			header('Expires: 0');
923
+			header('Cache-Control: must-revalidate');
924
+			header('Pragma: public');
925
+			header('Content-Length: ' . filesize($tmp_file));
926
+			readfile($tmp_file);
927 927
 		    
928 928
 		}
929 929
 		
@@ -950,24 +950,24 @@  discard block
 block discarded – undo
950 950
 		
951 951
 		
952 952
 		header('Pragma: public');
953
-	    header('Expires: 0');
954
-	    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
955
-	    header('Cache-Control: private', false);
956
-	    header('Content-Transfer-Encoding: binary');
957
-	    header('Content-Disposition: attachment; filename="'.$metadata['path'].'";');
958
-	    header('Content-Type: application/octet-stream');
959
-	    header('Content-Length: ' . $metadata['size']);
953
+		header('Expires: 0');
954
+		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
955
+		header('Cache-Control: private', false);
956
+		header('Content-Transfer-Encoding: binary');
957
+		header('Content-Disposition: attachment; filename="'.$metadata['path'].'";');
958
+		header('Content-Type: application/octet-stream');
959
+		header('Content-Length: ' . $metadata['size']);
960 960
 	    
961
-	    @ob_end_clean();
961
+		@ob_end_clean();
962 962
 	    
963
-	    $chunkSize = 1024 * 1024;
964
-	    while (!feof($read_stream))
965
-	    {
966
-	        $buffer = fread($read_stream, $chunkSize);
967
-	        echo $buffer;
968
-	    }
969
-	    fclose($read_stream);
970
-	    exit;
963
+		$chunkSize = 1024 * 1024;
964
+		while (!feof($read_stream))
965
+		{
966
+			$buffer = fread($read_stream, $chunkSize);
967
+			echo $buffer;
968
+		}
969
+		fclose($read_stream);
970
+		exit;
971 971
     
972 972
 	}
973 973
 	
Please login to merge, or discard this patch.
Spacing   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 use splitbrain\PHPArchive\FileInfo;
12 12
 
13 13
 
14
-class Xcloner_Api{
14
+class Xcloner_Api {
15 15
 
16 16
 	private $xcloner_database;
17 17
 	private $xcloner_settings;
@@ -27,30 +27,30 @@  discard block
 block discarded – undo
27 27
 	{
28 28
 		global $wpdb;
29 29
 		
30
-		if(WP_DEBUG)
30
+		if (WP_DEBUG)
31 31
 		{
32 32
 			error_reporting(0);
33 33
 		}
34 34
 		
35
-		if( ob_get_length() )
35
+		if (ob_get_length())
36 36
 			ob_end_clean();
37 37
 		ob_start();
38 38
 		
39
-		$wpdb->show_errors			= false;
39
+		$wpdb->show_errors = false;
40 40
 			
41 41
 		$this->xcloner_container	= $xcloner_container;
42 42
 				
43 43
 		$this->xcloner_settings 	= $xcloner_container->get_xcloner_settings();
44
-		$this->logger				= $xcloner_container->get_xcloner_logger()->withName("xcloner_api");
44
+		$this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_api");
45 45
 		$this->xcloner_file_system 	= $xcloner_container->get_xcloner_filesystem();
46 46
 		$this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization();
47 47
 		$this->xcloner_requirements = $xcloner_container->get_xcloner_requirements();
48
-		$this->archive_system 		=  $xcloner_container->get_archive_system();
49
-		$this->xcloner_database 	=  $xcloner_container->get_xcloner_database();
50
-		$this->xcloner_scheduler 	=  $xcloner_container->get_xcloner_scheduler();
48
+		$this->archive_system = $xcloner_container->get_archive_system();
49
+		$this->xcloner_database = $xcloner_container->get_xcloner_database();
50
+		$this->xcloner_scheduler = $xcloner_container->get_xcloner_scheduler();
51 51
 		
52
-		if(isset($_POST['API_ID'])){
53
-			$this->logger->info("Processing ajax request ID ".substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), 0 , 15));
52
+		if (isset($_POST['API_ID'])) {
53
+			$this->logger->info("Processing ajax request ID ".substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), 0, 15));
54 54
 		}
55 55
 		
56 56
 	}
@@ -78,15 +78,15 @@  discard block
 block discarded – undo
78 78
 		$data['dbDatabase'] = $this->xcloner_settings->get_db_database();
79 79
 		
80 80
 		
81
-		$data['recordsPerSession'] 		= $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
82
-		$data['TEMP_DBPROCESS_FILE'] 	= $this->xcloner_settings->get_xcloner_tmp_path().DS.".database";
83
-		$data['TEMP_DUMP_FILE'] 		= $this->xcloner_settings->get_xcloner_tmp_path().DS."database-sql.sql";
81
+		$data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
82
+		$data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS.".database";
83
+		$data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS."database-sql.sql";
84 84
 		
85 85
 		try
86 86
 		{
87 87
 			$this->xcloner_database->init($data);
88 88
 
89
-		}catch(Exception $e){
89
+		}catch (Exception $e) {
90 90
 			
91 91
 			$this->send_response($e->getMessage());
92 92
 			$this->logger->error($e->getMessage());
@@ -113,19 +113,19 @@  discard block
 block discarded – undo
113 113
 		$schedule = array();
114 114
 		$response = array();
115 115
 		
116
-		if(isset($_POST['data']))
116
+		if (isset($_POST['data']))
117 117
 			$params = json_decode(stripslashes($_POST['data']));
118 118
 		
119 119
 		$this->process_params($params);
120 120
 		
121
-		if(isset($_POST['id']))
121
+		if (isset($_POST['id']))
122 122
 		{
123 123
 			
124 124
 			$this->form_params['backup_params']['backup_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_name']);
125 125
 			$this->form_params['backup_params']['email_notification'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['email_notification']);
126
-			if($_POST['diff_start_date']){
126
+			if ($_POST['diff_start_date']) {
127 127
 				$this->form_params['backup_params']['diff_start_date'] = strtotime($this->xcloner_sanitization->sanitize_input_as_string($_POST['diff_start_date']));
128
-			}else{
128
+			} else {
129 129
 				$this->form_params['backup_params']['diff_start_date'] = "";
130 130
 				}
131 131
 			$this->form_params['backup_params']['schedule_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_name']);
@@ -140,11 +140,11 @@  discard block
 block discarded – undo
140 140
 			$tables = explode(PHP_EOL, $this->form_params['database']);
141 141
 			$return = array();
142 142
 			
143
-			foreach($tables as $table)
143
+			foreach ($tables as $table)
144 144
 			{
145
-					$table = str_replace("\r","", $table);
145
+					$table = str_replace("\r", "", $table);
146 146
 					$data = explode(".", $table);
147
-					if(isset($data[1]))
147
+					if (isset($data[1]))
148 148
 						$return[$data[0]][] = $data[1];
149 149
 			}
150 150
 			
@@ -153,10 +153,10 @@  discard block
 block discarded – undo
153 153
 			$excluded_files = explode(PHP_EOL, $this->form_params['excluded_files']);
154 154
 			$return = array();
155 155
 			
156
-			foreach($excluded_files as $file)
156
+			foreach ($excluded_files as $file)
157 157
 			{
158
-				$file = str_replace("\r","", $file);
159
-				if($file)
158
+				$file = str_replace("\r", "", $file);
159
+				if ($file)
160 160
 					$return[] = $file;
161 161
 			}
162 162
 			
@@ -164,27 +164,27 @@  discard block
 block discarded – undo
164 164
 			
165 165
 			$schedule['start_at'] = $this->form_params['backup_params']['start_at'];
166 166
 			
167
-			if(!isset($_POST['status']))
167
+			if (!isset($_POST['status']))
168 168
 				$schedule['status'] = 0;
169 169
 			else	
170 170
 				$schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']);
171
-		}else{
171
+		} else {
172 172
 		
173 173
 			$schedule['status'] = 1;
174
-			$schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] .
174
+			$schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'].
175 175
 								" ".$this->form_params['backup_params']['schedule_start_time']);
176 176
 			
177
-			if($schedule['start_at'] <= time())
177
+			if ($schedule['start_at'] <= time())
178 178
 			{
179 179
 				$schedule['start_at'] = "";
180 180
 			}
181 181
 		}
182 182
 		
183
-		if(!$schedule['start_at'])						
183
+		if (!$schedule['start_at'])						
184 184
 		{
185 185
 			$schedule['start_at'] = date('Y-m-d H:i:s', time());
186
-		}else{
187
-			$schedule['start_at'] = date('Y-m-d H:i:s', $schedule['start_at'] - (get_option( 'gmt_offset' ) * HOUR_IN_SECONDS) );	
186
+		} else {
187
+			$schedule['start_at'] = date('Y-m-d H:i:s', $schedule['start_at'] - (get_option('gmt_offset') * HOUR_IN_SECONDS));	
188 188
 		}
189 189
 		
190 190
 		$schedule['name'] = $this->form_params['backup_params']['schedule_name'];
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 		//$schedule['backup_type'] = $this->form_params['backup_params']['backup_type'];
194 194
 		$schedule['params'] = json_encode($this->form_params);
195 195
 
196
-		if(!isset($_POST['id']))
196
+		if (!isset($_POST['id']))
197 197
 		{
198 198
 			$wpdb->insert( 
199 199
 				$wpdb->prefix.'xcloner_scheduler', 
@@ -203,23 +203,23 @@  discard block
 block discarded – undo
203 203
 					'%s' 
204 204
 				) 
205 205
 			);
206
-		}else		{
206
+		} else {
207 207
 			$wpdb->update( 
208 208
 				$wpdb->prefix.'xcloner_scheduler', 
209 209
 				$schedule, 
210
-				array( 'id' => $_POST['id'] ), 
210
+				array('id' => $_POST['id']), 
211 211
 				array( 
212 212
 					'%s', 
213 213
 					'%s' 
214 214
 				) 
215 215
 			);
216 216
 		}
217
-		if(isset($_POST['id']))
217
+		if (isset($_POST['id']))
218 218
 		{
219 219
 			$scheduler->update_cron_hook($_POST['id']);
220 220
 		}
221 221
 			
222
-		if( $wpdb->last_error ) {
222
+		if ($wpdb->last_error) {
223 223
             $response['error'] = 1;
224 224
             $response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/;
225 225
             
@@ -242,19 +242,19 @@  discard block
 block discarded – undo
242 242
 		
243 243
 		$params = json_decode(stripslashes($_POST['data']));
244 244
 		
245
-		$init 	= (int)$_POST['init'];
245
+		$init = (int)$_POST['init'];
246 246
 		
247
-		if($params === NULL)
248
-			 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
247
+		if ($params === NULL)
248
+			 die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
249 249
 			 
250 250
 		$this->process_params($params);
251 251
 		
252 252
 		$return['finished'] = 1;
253 253
 
254 254
 		//$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init);
255
-		try{
255
+		try {
256 256
 			$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init);
257
-		}catch(Exception $e)
257
+		}catch (Exception $e)
258 258
 		{
259 259
 			$return = array();
260 260
 			$return['error'] = true;
@@ -263,26 +263,26 @@  discard block
 block discarded – undo
263 263
 			return $this->send_response($return, $hash = 1);
264 264
 		}
265 265
 		
266
-		if($return['finished'])
266
+		if ($return['finished'])
267 267
 		{
268 268
 			$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension();
269
-			if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension()))
269
+			if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension()))
270 270
 				$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
271 271
 		}
272 272
 		
273 273
 		$data = $return;
274 274
 		
275 275
 		//check if backup is finished
276
-		if($return['finished'] )
276
+		if ($return['finished'])
277 277
 		{
278
-			if(isset($this->form_params['backup_params']['email_notification']) and $to=$this->form_params['backup_params']['email_notification'])
278
+			if (isset($this->form_params['backup_params']['email_notification']) and $to = $this->form_params['backup_params']['email_notification'])
279 279
 			{
280
-				try{
280
+				try {
281 281
 					$from = "";
282 282
 					$subject = "";
283 283
 					$additional['lines_total'] = $return['extra']['lines_total'];
284
-					$this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $this->form_params,"", $additional);
285
-				}catch(Exception $e)
284
+					$this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $this->form_params, "", $additional);
285
+				}catch (Exception $e)
286 286
 				{
287 287
 					$this->logger->error($e->getMessage());
288 288
 				}
@@ -304,17 +304,17 @@  discard block
 block discarded – undo
304 304
 		
305 305
 		$params = json_decode(stripslashes($_POST['data']));
306 306
 		
307
-		$init 	= (int)$_POST['init'];
307
+		$init = (int)$_POST['init'];
308 308
 		
309
-		if($params === NULL)
310
-			 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
309
+		if ($params === NULL)
310
+			 die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
311 311
 		
312 312
 		$this->process_params($params);
313 313
 			
314 314
 		//$xcloner_database = $this->init_db();	
315 315
 		$return = $this->xcloner_database->start_database_recursion($this->form_params['database'], $this->form_params['extra'], $init);
316 316
 		
317
-		if(isset($return['error']) and $return['error'])
317
+		if (isset($return['error']) and $return['error'])
318 318
 			$data['finished'] = 1;
319 319
 		else	
320 320
 			$data['finished'] = $return['finished'];
@@ -334,10 +334,10 @@  discard block
 block discarded – undo
334 334
 		$this->check_access();
335 335
 		
336 336
 		$params = json_decode(stripslashes($_POST['data']));
337
-		$init 	= (int)$_POST['init'];
337
+		$init = (int)$_POST['init'];
338 338
 		
339
-		if($params === NULL)
340
-			 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
339
+		if ($params === NULL)
340
+			 die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
341 341
 			 
342 342
 		$hash = $this->process_params($params);
343 343
 		
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 		$data["finished"] = !$return;
349 349
 		$data["total_files_num"] = $this->xcloner_file_system->get_scanned_files_num();
350 350
 		$data["last_logged_file"] = $this->xcloner_file_system->last_logged_file();
351
-		$data["total_files_size"] = sprintf("%.2f",$this->xcloner_file_system->get_scanned_files_total_size()/(1024*1024));
351
+		$data["total_files_size"] = sprintf("%.2f", $this->xcloner_file_system->get_scanned_files_total_size() / (1024 * 1024));
352 352
 		
353 353
 		return $this->send_response($data, $hash = 1);
354 354
 	}
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 	 */ 
361 361
 	private function process_params($params)
362 362
 	{
363
-		if(isset($params->hash))
363
+		if (isset($params->hash))
364 364
 			$this->xcloner_settings->set_hash($params->hash);
365 365
 			
366 366
 		$this->form_params['extra'] = array();
@@ -368,9 +368,9 @@  discard block
 block discarded – undo
368 368
 		
369 369
 		$this->form_params['database'] = array();
370 370
 		
371
-		if(isset($params->backup_params))
371
+		if (isset($params->backup_params))
372 372
 		{
373
-			foreach($params->backup_params as $param)
373
+			foreach ($params->backup_params as $param)
374 374
 			{
375 375
 				$this->form_params['backup_params'][$param->name] = $this->xcloner_sanitization->sanitize_input_as_string($param->value);
376 376
 				$this->logger->debug("Adding form parameter ".$param->name.".".$param->value."\n", array('POST', 'fields filter'));
@@ -379,28 +379,28 @@  discard block
 block discarded – undo
379 379
 		
380 380
 		$this->form_params['database'] = array();
381 381
 		
382
-		if(isset($params->table_params))
382
+		if (isset($params->table_params))
383 383
 		{
384
-			foreach($params->table_params as $param)
384
+			foreach ($params->table_params as $param)
385 385
 			{
386 386
 				$this->form_params['database'][$param->parent][] = $this->xcloner_sanitization->sanitize_input_as_raw($param->id);
387 387
 				$this->logger->debug("Adding database filter ".$param->parent.".".$param->id."\n", array('POST', 'database filter'));
388 388
 			}
389 389
 		}
390 390
 		
391
-		$this->form_params['excluded_files'] =  array();
392
-		if(isset($params->files_params))
391
+		$this->form_params['excluded_files'] = array();
392
+		if (isset($params->files_params))
393 393
 		{
394
-			foreach($params->files_params as $param)
394
+			foreach ($params->files_params as $param)
395 395
 			{
396 396
 				$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
397 397
 			}
398 398
 			
399 399
 			$unique_exclude_files = array();
400 400
 			
401
-			foreach($params->files_params as $key=>$param)
401
+			foreach ($params->files_params as $key=>$param)
402 402
 			{
403
-				if(!in_array($param->parent, $this->form_params['excluded_files'])){
403
+				if (!in_array($param->parent, $this->form_params['excluded_files'])) {
404 404
 				//$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
405 405
 					$unique_exclude_files[] = $param->id;
406 406
 					$this->logger->debug("Adding file filter ".$param->id."\n", array('POST', 'exclude files filter'));
@@ -412,13 +412,13 @@  discard block
 block discarded – undo
412 412
 		
413 413
 		//$this->form_params['excluded_files'] =  array_merge($this->form_params['excluded_files'], $this->exclude_files_by_default);
414 414
 		
415
-		if(isset($params->extra))
415
+		if (isset($params->extra))
416 416
 		{
417
-			foreach($params->extra as $key=>$value)
417
+			foreach ($params->extra as $key=>$value)
418 418
 				$this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value);
419 419
 		}
420 420
 		
421
-		if(isset($this->form_params['backup_params']['diff_start_date']) and $this->form_params['backup_params']['diff_start_date'])
421
+		if (isset($this->form_params['backup_params']['diff_start_date']) and $this->form_params['backup_params']['diff_start_date'])
422 422
 		{
423 423
 			$this->form_params['backup_params']['diff_start_date'] = strtotime($this->form_params['backup_params']['diff_start_date']);
424 424
 			$this->xcloner_file_system->set_diff_timestamp_start($this->form_params['backup_params']['diff_start_date']);
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 		
441 441
 		$data = array();
442 442
 		
443
-		if($folder == "#"){
443
+		if ($folder == "#") {
444 444
 			
445 445
 			$folder = "/";
446 446
 			$data[] = array(
@@ -453,9 +453,9 @@  discard block
 block discarded – undo
453 453
 						);
454 454
 		}
455 455
 			
456
-			try{
456
+			try {
457 457
 				$files = $this->xcloner_file_system->list_directory($folder);
458
-			}catch(Exception $e){
458
+			}catch (Exception $e) {
459 459
 				
460 460
 				print $e->getMessage();
461 461
 				$this->logger->error($e->getMessage());
@@ -470,17 +470,17 @@  discard block
 block discarded – undo
470 470
 			}
471 471
 			array_multisort($type, SORT_ASC, $files);
472 472
 			
473
-			foreach($files as $file)
473
+			foreach ($files as $file)
474 474
 			{
475 475
 				$children = false;
476 476
 				$text = $file['basename'];
477 477
 				
478
-				if($file['type'] == "dir")
478
+				if ($file['type'] == "dir")
479 479
 					$children = true;
480 480
 				else
481
-					 $text .= " (". $this->xcloner_requirements->file_format_size($file['size']).")";
481
+					 $text .= " (".$this->xcloner_requirements->file_format_size($file['size']).")";
482 482
 				
483
-				if($this->xcloner_file_system->is_excluded($file))
483
+				if ($this->xcloner_file_system->is_excluded($file))
484 484
 					$selected = true;
485 485
 				else
486 486
 					$selected = false;
@@ -515,25 +515,25 @@  discard block
 block discarded – undo
515 515
 		
516 516
 		$xcloner_backup_only_wp_tables = $this->xcloner_settings->get_xcloner_option('xcloner_backup_only_wp_tables');
517 517
 	
518
-		if($database == "#")
518
+		if ($database == "#")
519 519
 		{
520
-			try{
520
+			try {
521 521
 				$return = $this->xcloner_database->get_all_databases();
522
-			}catch(Exception $e){
522
+			}catch (Exception $e) {
523 523
 				$this->logger->error($e->getMessage());
524 524
 			}
525 525
 			
526
-			foreach($return as $database)
526
+			foreach ($return as $database)
527 527
 			{
528
-				if($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database())
528
+				if ($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database())
529 529
 					continue;
530 530
 					
531 531
 				$state = array();
532 532
 				
533
-				if($database['name'] == $this->xcloner_settings->get_db_database())
533
+				if ($database['name'] == $this->xcloner_settings->get_db_database())
534 534
 				{
535 535
 					$state['selected'] = true;
536
-					if($database['num_tables'] < 25)
536
+					if ($database['num_tables'] < 25)
537 537
 						$state['opened'] = false;
538 538
 				}
539 539
 					
@@ -549,22 +549,22 @@  discard block
 block discarded – undo
549 549
 			
550 550
 		}
551 551
 		
552
-		else{
552
+		else {
553 553
 			
554
-			try{
554
+			try {
555 555
 				$return = $this->xcloner_database->list_tables($database, "", 1);
556
-			}catch(Exception $e){
556
+			}catch (Exception $e) {
557 557
 				$this->logger->error($e->getMessage());
558 558
 			}
559 559
 			
560
-			foreach($return as $table)
560
+			foreach ($return as $table)
561 561
 			{
562 562
 				$state = array();
563 563
 				
564
-				if($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix()))
564
+				if ($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix()))
565 565
 					continue;
566 566
 				
567
-				if(isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database())
567
+				if (isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database())
568 568
 					$state = array('selected' => true);
569 569
 					
570 570
 				$data[] = array(
@@ -592,12 +592,12 @@  discard block
 block discarded – undo
592 592
 		
593 593
 		$schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']);
594 594
 		$scheduler = $this->xcloner_scheduler;
595
-		$data  = $scheduler->get_schedule_by_id($schedule_id);
595
+		$data = $scheduler->get_schedule_by_id($schedule_id);
596 596
 		
597
-		$data['start_at'] = date("Y-m-d H:i", strtotime($data['start_at']) + (get_option( 'gmt_offset' ) * HOUR_IN_SECONDS));
598
-		if(isset($data['backup_params']->diff_start_date) && $data['backup_params']->diff_start_date != "")
597
+		$data['start_at'] = date("Y-m-d H:i", strtotime($data['start_at']) + (get_option('gmt_offset') * HOUR_IN_SECONDS));
598
+		if (isset($data['backup_params']->diff_start_date) && $data['backup_params']->diff_start_date != "")
599 599
 		{
600
-			$data['backup_params']->diff_start_date = date("Y-m-d", ($data['backup_params']->diff_start_date) );
600
+			$data['backup_params']->diff_start_date = date("Y-m-d", ($data['backup_params']->diff_start_date));
601 601
 		}
602 602
 		
603 603
 		return $this->send_response($data);
@@ -613,14 +613,14 @@  discard block
 block discarded – undo
613 613
 		$this->check_access();
614 614
 		
615 615
 		$scheduler = $this->xcloner_scheduler;
616
-		$data  = $scheduler->get_scheduler_list();
616
+		$data = $scheduler->get_scheduler_list();
617 617
 		$return['data'] = array();
618 618
 		
619
-		foreach($data as $res)
619
+		foreach ($data as $res)
620 620
 		{
621 621
 			$action = "<a href=\"#".$res->id."\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> 
622 622
 					<a href=\"#".$res->id."\" class=\"delete\" title='Delete'><i class=\"material-icons  \">delete</i></a>";
623
-			if($res->status)
623
+			if ($res->status)
624 624
 				$status = '<i class="material-icons active status">timer</i>';
625 625
 			else
626 626
 				$status = '<i class="material-icons status inactive">timer_off</i>';
@@ -631,14 +631,14 @@  discard block
 block discarded – undo
631 631
 			
632 632
 			$remote_storage = $res->remote_storage;
633 633
 			
634
-			if(!$next_run_time >= time())
634
+			if (!$next_run_time >= time())
635 635
 				$next_run = " ";
636 636
 			
637
-			if(trim($next_run))
637
+			if (trim($next_run))
638 638
 			{
639
-				$date_text = date(get_option('date_format')." ".get_option('time_format'), $next_run_time + (get_option( 'gmt_offset' ) * HOUR_IN_SECONDS));
639
+				$date_text = date(get_option('date_format')." ".get_option('time_format'), $next_run_time + (get_option('gmt_offset') * HOUR_IN_SECONDS));
640 640
 				
641
-				if($next_run_time >= time())
641
+				if ($next_run_time >= time())
642 642
 					$next_run = "in ".human_time_diff($next_run_time, time());
643 643
 				else
644 644
 					$next_run = __("executed", 'xcloner-backup-and-restore');
@@ -651,13 +651,13 @@  discard block
 block discarded – undo
651 651
 			$backup_size = "";
652 652
 			$backup_time = "";
653 653
 			
654
-			if($res->last_backup)
654
+			if ($res->last_backup)
655 655
 			{
656
-				if( $this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup))
656
+				if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup))
657 657
 				{
658 658
 					$metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup);
659 659
 					$backup_size  = size_format($this->xcloner_file_system->get_backup_size($res->last_backup));
660
-					$backup_time  = date(get_option('date_format')." ".get_option('time_format'), $metadata['timestamp']+(get_option( 'gmt_offset' ) * HOUR_IN_SECONDS));
660
+					$backup_time  = date(get_option('date_format')." ".get_option('time_format'), $metadata['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS));
661 661
 				}
662 662
 			
663 663
 				$backup_text = "<span title='".$backup_time."' class='shorten_string'>".$res->last_backup." (".$backup_size.")</span>";
@@ -665,12 +665,12 @@  discard block
 block discarded – undo
665 665
 			
666 666
 			$schedules = wp_get_schedules();
667 667
 
668
-			if(isset($schedules[$res->recurrence]))
668
+			if (isset($schedules[$res->recurrence]))
669 669
 			{
670 670
 				$res->recurrence = $schedules[$res->recurrence]['display'];
671 671
 			}
672 672
 				
673
-			$return['data'][] = array($res->id, $res->name, $res->recurrence,/*$res->start_at,*/ $next_run, $remote_storage, $backup_text, $status, $action);
673
+			$return['data'][] = array($res->id, $res->name, $res->recurrence, /*$res->start_at,*/ $next_run, $remote_storage, $backup_text, $status, $action);
674 674
 		}
675 675
 
676 676
 		return $this->send_response($return, 0);
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
 		
688 688
 		$schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']);
689 689
 		$scheduler = $this->xcloner_scheduler;
690
-		$data['finished']  = $scheduler->delete_schedule_by_id($schedule_id);
690
+		$data['finished'] = $scheduler->delete_schedule_by_id($schedule_id);
691 691
 		
692 692
 		return $this->send_response($data);
693 693
 	}
@@ -721,32 +721,32 @@  discard block
 block discarded – undo
721 721
 		
722 722
 		$backup_file = $source_backup_file;
723 723
 		
724
-		if($this->xcloner_file_system->is_multipart($backup_file))
724
+		if ($this->xcloner_file_system->is_multipart($backup_file))
725 725
 		{
726 726
 			$backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file);
727 727
 			$backup_file = $backup_parts[$return['part']];
728 728
 		}
729 729
 		
730
-		try{
730
+		try {
731 731
 			$tar = new Tar();
732 732
 			$tar->open($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file, $start);
733 733
 		
734 734
 			$data = $tar->contents(get_option('xcloner_files_to_process_per_request'));
735
-		}catch(Exception $e)
735
+		}catch (Exception $e)
736 736
 		{
737 737
 			$return['error'] = true;
738 738
 			$return['message'] = $e->getMessage();
739 739
 			$this->send_response($return, 0);
740 740
 		}
741 741
 		
742
-		$return['files'] 		= array();
743
-		$return['finished'] 	= 1;
744
-		$return['total_size'] 	= filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file);
742
+		$return['files'] = array();
743
+		$return['finished'] = 1;
744
+		$return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file);
745 745
 		$i = 0;
746 746
 		
747
-		if(isset($data['extracted_files']) and is_array($data['extracted_files']))
747
+		if (isset($data['extracted_files']) and is_array($data['extracted_files']))
748 748
 		{
749
-			foreach($data['extracted_files'] as $file)
749
+			foreach ($data['extracted_files'] as $file)
750 750
 			{
751 751
 				$return['files'][$i]['path'] = $file->getPath();
752 752
 				$return['files'][$i]['size'] = $file->getSize();
@@ -756,18 +756,18 @@  discard block
 block discarded – undo
756 756
 			}
757 757
 		}
758 758
 		
759
-		if(isset($data['start']))
759
+		if (isset($data['start']))
760 760
 		{
761 761
 			$return['start'] = $data['start'];
762 762
 			$return['finished'] = 0;	
763
-		}else{
764
-			if($this->xcloner_file_system->is_multipart($source_backup_file))
763
+		} else {
764
+			if ($this->xcloner_file_system->is_multipart($source_backup_file))
765 765
 			{
766 766
 				$return['start'] = 0;
767 767
 				
768 768
 				++$return['part'];
769 769
 			
770
-				if($return['part'] < sizeof($backup_parts))	
770
+				if ($return['part'] < sizeof($backup_parts))	
771 771
 					$return['finished'] = 0;
772 772
 				
773 773
 			}
@@ -790,17 +790,17 @@  discard block
 block discarded – undo
790 790
 		
791 791
 		try
792 792
 		{
793
-			if(method_exists($xcloner_remote_storage, "copy_backup_remote_to_local"))
793
+			if (method_exists($xcloner_remote_storage, "copy_backup_remote_to_local"))
794 794
 			{
795 795
 				$return = call_user_func_array(array($xcloner_remote_storage, "copy_backup_remote_to_local"), array($backup_file, $storage_type));
796 796
 			}
797
-		}catch(Exception $e){
797
+		}catch (Exception $e) {
798 798
 		
799 799
 			$return['error'] = 1;
800 800
 			$return['message'] = $e->getMessage();
801 801
 		}
802 802
 		
803
-		if(!$return)
803
+		if (!$return)
804 804
 		{
805 805
 			$return['error'] = 1;
806 806
 			$return['message'] = "Upload failed, please check the error log for more information!";
@@ -829,17 +829,17 @@  discard block
 block discarded – undo
829 829
 		
830 830
 		try
831 831
 		{
832
-			if(method_exists($xcloner_remote_storage, "upload_backup_to_storage"))
832
+			if (method_exists($xcloner_remote_storage, "upload_backup_to_storage"))
833 833
 			{
834 834
 				$return = call_user_func_array(array($xcloner_remote_storage, "upload_backup_to_storage"), array($backup_file, $storage_type));
835 835
 			}
836
-		}catch(Exception $e){
836
+		}catch (Exception $e) {
837 837
 		
838 838
 			$return['error'] = 1;
839 839
 			$return['message'] = $e->getMessage();
840 840
 		}
841 841
 		
842
-		if(!$return)
842
+		if (!$return)
843 843
 		{
844 844
 			$return['error'] = 1;
845 845
 			$return['message'] = "Upload failed, please check the error log for more information!";
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
 		
874 874
 		@ob_end_clean();
875 875
 		
876
-		$adapter = new Local(dirname(__DIR__) ,LOCK_EX, 'SKIP_LINKS');
876
+		$adapter = new Local(dirname(__DIR__), LOCK_EX, 'SKIP_LINKS');
877 877
 		$xcloner_plugin_filesystem = new Filesystem($adapter, new Config([
878 878
 				'disable_asserts' => true,
879 879
 			]));
@@ -903,7 +903,7 @@  discard block
 block discarded – undo
903 903
 		//$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz");
904 904
 		
905 905
 		$files = $xcloner_plugin_filesystem->listContents("vendor/", true);
906
-		foreach($files as $file)
906
+		foreach ($files as $file)
907 907
 		{
908 908
 			$tar->addFile(dirname(__DIR__).DS.$file['path'], $file['path']);
909 909
 		}
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
 		    header('Expires: 0');
923 923
 		    header('Cache-Control: must-revalidate');
924 924
 		    header('Pragma: public');
925
-		    header('Content-Length: ' . filesize($tmp_file));
925
+		    header('Content-Length: '.filesize($tmp_file));
926 926
 		    readfile($tmp_file);
927 927
 		    
928 928
 		}
@@ -945,8 +945,8 @@  discard block
 block discarded – undo
945 945
 		$backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_GET['name']);
946 946
 		
947 947
 		
948
-		$metadata  = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name);
949
-		$read_stream  = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name);
948
+		$metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name);
949
+		$read_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name);
950 950
 		
951 951
 		
952 952
 		header('Pragma: public');
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
 	    header('Content-Transfer-Encoding: binary');
957 957
 	    header('Content-Disposition: attachment; filename="'.$metadata['path'].'";');
958 958
 	    header('Content-Type: application/octet-stream');
959
-	    header('Content-Length: ' . $metadata['size']);
959
+	    header('Content-Length: '.$metadata['size']);
960 960
 	    
961 961
 	    @ob_end_clean();
962 962
 	    
@@ -984,10 +984,10 @@  discard block
 block discarded – undo
984 984
 		$file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
985 985
 		$hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']);
986 986
 		
987
-		if(isset($_POST['part']))
987
+		if (isset($_POST['part']))
988 988
 			$return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
989 989
 		
990
-		if(isset($_POST['uploaded_size']))
990
+		if (isset($_POST['uploaded_size']))
991 991
 			$return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']);
992 992
 		
993 993
 		$start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']);
@@ -995,46 +995,46 @@  discard block
 block discarded – undo
995 995
 		
996 996
 		$return['total_size'] = $this->xcloner_file_system->get_backup_size($file);
997 997
 		
998
-		if($this->xcloner_file_system->is_multipart($file))
998
+		if ($this->xcloner_file_system->is_multipart($file))
999 999
 		{
1000 1000
 			$backup_parts = $this->xcloner_file_system->get_multipart_files($file);
1001 1001
 			
1002
-			$return['total_parts'] = sizeof($backup_parts)+1;
1002
+			$return['total_parts'] = sizeof($backup_parts) + 1;
1003 1003
 			
1004
-			if($return['part'] and isset($backup_parts[$return['part']-1]))
1004
+			if ($return['part'] and isset($backup_parts[$return['part'] - 1]))
1005 1005
 			{
1006
-				$file = $backup_parts[$return['part']-1];
1006
+				$file = $backup_parts[$return['part'] - 1];
1007 1007
 			}
1008 1008
 			
1009 1009
 			$is_multipart = 1;	
1010 1010
 		}
1011 1011
 		
1012
-		try{
1012
+		try {
1013 1013
 		
1014 1014
 			$xcloner_file_transfer = $this->get_xcloner_container()->get_xcloner_file_transfer();
1015 1015
 			$xcloner_file_transfer->set_target($target_url);
1016 1016
 			$return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash);
1017 1017
 		
1018
-		}catch(Exception $e){
1018
+		}catch (Exception $e) {
1019 1019
 		
1020 1020
 			$return = array();
1021 1021
 			$return['error'] = true;
1022 1022
 			$return['status'] = 500;
1023 1023
 			$return['message'] = "CURL communication error with the restore host. ".$e->getMessage();
1024
-			$this->send_response( $return, 0);
1024
+			$this->send_response($return, 0);
1025 1025
 		
1026 1026
 		}
1027 1027
 		
1028 1028
 		$return['status'] = 200;
1029 1029
 		
1030 1030
 		//we have finished the upload
1031
-		if(!$return['start'] and $is_multipart)
1031
+		if (!$return['start'] and $is_multipart)
1032 1032
 		{
1033 1033
 			$return['part']++;
1034 1034
 			$return['uploaded_size'] += $this->xcloner_file_system->get_storage_filesystem()->getSize($file);
1035 1035
 		}
1036 1036
 		
1037
-		$this->send_response( $return, 0);
1037
+		$this->send_response($return, 0);
1038 1038
 	}
1039 1039
 	
1040 1040
 	public function restore_backup()
@@ -1042,7 +1042,7 @@  discard block
 block discarded – undo
1042 1042
 		$this->check_access();
1043 1043
 		
1044 1044
 		define("XCLONER_PLUGIN_ACCESS", 1);
1045
-		include_once(dirname(__DIR__) .DS."restore".DS."xcloner_restore.php");
1045
+		include_once(dirname(__DIR__).DS."restore".DS."xcloner_restore.php");
1046 1046
 		return;
1047 1047
 	}
1048 1048
 	
@@ -1054,12 +1054,12 @@  discard block
 block discarded – undo
1054 1054
 	private function send_response($data, $attach_hash = 1)
1055 1055
 	{
1056 1056
 		
1057
-		if($attach_hash and null !== $this->xcloner_settings->get_hash())
1057
+		if ($attach_hash and null !== $this->xcloner_settings->get_hash())
1058 1058
 		{
1059 1059
 			$data['hash'] = $this->xcloner_settings->get_hash();
1060 1060
 		}
1061 1061
 			
1062
-		if( ob_get_length() )
1062
+		if (ob_get_length())
1063 1063
 			ob_clean();
1064 1064
 		wp_send_json($data);
1065 1065
 		
Please login to merge, or discard this patch.
Braces   +103 added lines, -80 removed lines patch added patch discarded remove patch
@@ -32,8 +32,9 @@  discard block
 block discarded – undo
32 32
 			error_reporting(0);
33 33
 		}
34 34
 		
35
-		if( ob_get_length() )
36
-			ob_end_clean();
35
+		if( ob_get_length() ) {
36
+					ob_end_clean();
37
+		}
37 38
 		ob_start();
38 39
 		
39 40
 		$wpdb->show_errors			= false;
@@ -86,7 +87,7 @@  discard block
 block discarded – undo
86 87
 		{
87 88
 			$this->xcloner_database->init($data);
88 89
 
89
-		}catch(Exception $e){
90
+		} catch(Exception $e){
90 91
 			
91 92
 			$this->send_response($e->getMessage());
92 93
 			$this->logger->error($e->getMessage());
@@ -113,8 +114,9 @@  discard block
 block discarded – undo
113 114
 		$schedule = array();
114 115
 		$response = array();
115 116
 		
116
-		if(isset($_POST['data']))
117
-			$params = json_decode(stripslashes($_POST['data']));
117
+		if(isset($_POST['data'])) {
118
+					$params = json_decode(stripslashes($_POST['data']));
119
+		}
118 120
 		
119 121
 		$this->process_params($params);
120 122
 		
@@ -125,7 +127,7 @@  discard block
 block discarded – undo
125 127
 			$this->form_params['backup_params']['email_notification'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['email_notification']);
126 128
 			if($_POST['diff_start_date']){
127 129
 				$this->form_params['backup_params']['diff_start_date'] = strtotime($this->xcloner_sanitization->sanitize_input_as_string($_POST['diff_start_date']));
128
-			}else{
130
+			} else{
129 131
 				$this->form_params['backup_params']['diff_start_date'] = "";
130 132
 				}
131 133
 			$this->form_params['backup_params']['schedule_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_name']);
@@ -144,8 +146,9 @@  discard block
 block discarded – undo
144 146
 			{
145 147
 					$table = str_replace("\r","", $table);
146 148
 					$data = explode(".", $table);
147
-					if(isset($data[1]))
148
-						$return[$data[0]][] = $data[1];
149
+					if(isset($data[1])) {
150
+											$return[$data[0]][] = $data[1];
151
+					}
149 152
 			}
150 153
 			
151 154
 			$this->form_params['database'] = ($return);
@@ -156,19 +159,21 @@  discard block
 block discarded – undo
156 159
 			foreach($excluded_files as $file)
157 160
 			{
158 161
 				$file = str_replace("\r","", $file);
159
-				if($file)
160
-					$return[] = $file;
162
+				if($file) {
163
+									$return[] = $file;
164
+				}
161 165
 			}
162 166
 			
163 167
 			$this->form_params['excluded_files'] = ($return);
164 168
 			
165 169
 			$schedule['start_at'] = $this->form_params['backup_params']['start_at'];
166 170
 			
167
-			if(!isset($_POST['status']))
168
-				$schedule['status'] = 0;
169
-			else	
170
-				$schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']);
171
-		}else{
171
+			if(!isset($_POST['status'])) {
172
+							$schedule['status'] = 0;
173
+			} else {
174
+							$schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']);
175
+			}
176
+		} else{
172 177
 		
173 178
 			$schedule['status'] = 1;
174 179
 			$schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] .
@@ -183,7 +188,7 @@  discard block
 block discarded – undo
183 188
 		if(!$schedule['start_at'])						
184 189
 		{
185 190
 			$schedule['start_at'] = date('Y-m-d H:i:s', time());
186
-		}else{
191
+		} else{
187 192
 			$schedule['start_at'] = date('Y-m-d H:i:s', $schedule['start_at'] - (get_option( 'gmt_offset' ) * HOUR_IN_SECONDS) );	
188 193
 		}
189 194
 		
@@ -203,7 +208,7 @@  discard block
 block discarded – undo
203 208
 					'%s' 
204 209
 				) 
205 210
 			);
206
-		}else		{
211
+		} else		{
207 212
 			$wpdb->update( 
208 213
 				$wpdb->prefix.'xcloner_scheduler', 
209 214
 				$schedule, 
@@ -244,8 +249,9 @@  discard block
 block discarded – undo
244 249
 		
245 250
 		$init 	= (int)$_POST['init'];
246 251
 		
247
-		if($params === NULL)
248
-			 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
252
+		if($params === NULL) {
253
+					 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
254
+		}
249 255
 			 
250 256
 		$this->process_params($params);
251 257
 		
@@ -254,7 +260,7 @@  discard block
 block discarded – undo
254 260
 		//$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init);
255 261
 		try{
256 262
 			$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init);
257
-		}catch(Exception $e)
263
+		} catch(Exception $e)
258 264
 		{
259 265
 			$return = array();
260 266
 			$return['error'] = true;
@@ -266,8 +272,9 @@  discard block
 block discarded – undo
266 272
 		if($return['finished'])
267 273
 		{
268 274
 			$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension();
269
-			if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension()))
270
-				$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
275
+			if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) {
276
+							$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
277
+			}
271 278
 		}
272 279
 		
273 280
 		$data = $return;
@@ -282,7 +289,7 @@  discard block
 block discarded – undo
282 289
 					$subject = "";
283 290
 					$additional['lines_total'] = $return['extra']['lines_total'];
284 291
 					$this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $this->form_params,"", $additional);
285
-				}catch(Exception $e)
292
+				} catch(Exception $e)
286 293
 				{
287 294
 					$this->logger->error($e->getMessage());
288 295
 				}
@@ -306,18 +313,20 @@  discard block
 block discarded – undo
306 313
 		
307 314
 		$init 	= (int)$_POST['init'];
308 315
 		
309
-		if($params === NULL)
310
-			 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
316
+		if($params === NULL) {
317
+					 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
318
+		}
311 319
 		
312 320
 		$this->process_params($params);
313 321
 			
314 322
 		//$xcloner_database = $this->init_db();	
315 323
 		$return = $this->xcloner_database->start_database_recursion($this->form_params['database'], $this->form_params['extra'], $init);
316 324
 		
317
-		if(isset($return['error']) and $return['error'])
318
-			$data['finished'] = 1;
319
-		else	
320
-			$data['finished'] = $return['finished'];
325
+		if(isset($return['error']) and $return['error']) {
326
+					$data['finished'] = 1;
327
+		} else {
328
+					$data['finished'] = $return['finished'];
329
+		}
321 330
 			
322 331
 		$data['extra'] = $return;
323 332
 		
@@ -336,8 +345,9 @@  discard block
 block discarded – undo
336 345
 		$params = json_decode(stripslashes($_POST['data']));
337 346
 		$init 	= (int)$_POST['init'];
338 347
 		
339
-		if($params === NULL)
340
-			 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
348
+		if($params === NULL) {
349
+					 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
350
+		}
341 351
 			 
342 352
 		$hash = $this->process_params($params);
343 353
 		
@@ -360,8 +370,9 @@  discard block
 block discarded – undo
360 370
 	 */ 
361 371
 	private function process_params($params)
362 372
 	{
363
-		if(isset($params->hash))
364
-			$this->xcloner_settings->set_hash($params->hash);
373
+		if(isset($params->hash)) {
374
+					$this->xcloner_settings->set_hash($params->hash);
375
+		}
365 376
 			
366 377
 		$this->form_params['extra'] = array();
367 378
 		$this->form_params['backup_params'] = array();
@@ -414,8 +425,9 @@  discard block
 block discarded – undo
414 425
 		
415 426
 		if(isset($params->extra))
416 427
 		{
417
-			foreach($params->extra as $key=>$value)
418
-				$this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value);
428
+			foreach($params->extra as $key=>$value) {
429
+							$this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value);
430
+			}
419 431
 		}
420 432
 		
421 433
 		if(isset($this->form_params['backup_params']['diff_start_date']) and $this->form_params['backup_params']['diff_start_date'])
@@ -455,7 +467,7 @@  discard block
 block discarded – undo
455 467
 			
456 468
 			try{
457 469
 				$files = $this->xcloner_file_system->list_directory($folder);
458
-			}catch(Exception $e){
470
+			} catch(Exception $e){
459 471
 				
460 472
 				print $e->getMessage();
461 473
 				$this->logger->error($e->getMessage());
@@ -475,15 +487,17 @@  discard block
 block discarded – undo
475 487
 				$children = false;
476 488
 				$text = $file['basename'];
477 489
 				
478
-				if($file['type'] == "dir")
479
-					$children = true;
480
-				else
481
-					 $text .= " (". $this->xcloner_requirements->file_format_size($file['size']).")";
490
+				if($file['type'] == "dir") {
491
+									$children = true;
492
+				} else {
493
+									 $text .= " (". $this->xcloner_requirements->file_format_size($file['size']).")";
494
+				}
482 495
 				
483
-				if($this->xcloner_file_system->is_excluded($file))
484
-					$selected = true;
485
-				else
486
-					$selected = false;
496
+				if($this->xcloner_file_system->is_excluded($file)) {
497
+									$selected = true;
498
+				} else {
499
+									$selected = false;
500
+				}
487 501
 					
488 502
 				$data[] = array(
489 503
 							'id' => $file['path'],
@@ -519,22 +533,24 @@  discard block
 block discarded – undo
519 533
 		{
520 534
 			try{
521 535
 				$return = $this->xcloner_database->get_all_databases();
522
-			}catch(Exception $e){
536
+			} catch(Exception $e){
523 537
 				$this->logger->error($e->getMessage());
524 538
 			}
525 539
 			
526 540
 			foreach($return as $database)
527 541
 			{
528
-				if($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database())
529
-					continue;
542
+				if($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) {
543
+									continue;
544
+				}
530 545
 					
531 546
 				$state = array();
532 547
 				
533 548
 				if($database['name'] == $this->xcloner_settings->get_db_database())
534 549
 				{
535 550
 					$state['selected'] = true;
536
-					if($database['num_tables'] < 25)
537
-						$state['opened'] = false;
551
+					if($database['num_tables'] < 25) {
552
+											$state['opened'] = false;
553
+					}
538 554
 				}
539 555
 					
540 556
 				$data[] = array(
@@ -547,13 +563,11 @@  discard block
 block discarded – undo
547 563
 						);
548 564
 			}
549 565
 			
550
-		}
551
-		
552
-		else{
566
+		} else{
553 567
 			
554 568
 			try{
555 569
 				$return = $this->xcloner_database->list_tables($database, "", 1);
556
-			}catch(Exception $e){
570
+			} catch(Exception $e){
557 571
 				$this->logger->error($e->getMessage());
558 572
 			}
559 573
 			
@@ -561,11 +575,13 @@  discard block
 block discarded – undo
561 575
 			{
562 576
 				$state = array();
563 577
 				
564
-				if($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix()))
565
-					continue;
578
+				if($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix())) {
579
+									continue;
580
+				}
566 581
 				
567
-				if(isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database())
568
-					$state = array('selected' => true);
582
+				if(isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) {
583
+									$state = array('selected' => true);
584
+				}
569 585
 					
570 586
 				$data[] = array(
571 587
 						'id' => $table['name'],
@@ -620,10 +636,11 @@  discard block
 block discarded – undo
620 636
 		{
621 637
 			$action = "<a href=\"#".$res->id."\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> 
622 638
 					<a href=\"#".$res->id."\" class=\"delete\" title='Delete'><i class=\"material-icons  \">delete</i></a>";
623
-			if($res->status)
624
-				$status = '<i class="material-icons active status">timer</i>';
625
-			else
626
-				$status = '<i class="material-icons status inactive">timer_off</i>';
639
+			if($res->status) {
640
+							$status = '<i class="material-icons active status">timer</i>';
641
+			} else {
642
+							$status = '<i class="material-icons status inactive">timer_off</i>';
643
+			}
627 644
 				
628 645
 			$next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id));
629 646
 				
@@ -631,17 +648,19 @@  discard block
 block discarded – undo
631 648
 			
632 649
 			$remote_storage = $res->remote_storage;
633 650
 			
634
-			if(!$next_run_time >= time())
635
-				$next_run = " ";
651
+			if(!$next_run_time >= time()) {
652
+							$next_run = " ";
653
+			}
636 654
 			
637 655
 			if(trim($next_run))
638 656
 			{
639 657
 				$date_text = date(get_option('date_format')." ".get_option('time_format'), $next_run_time + (get_option( 'gmt_offset' ) * HOUR_IN_SECONDS));
640 658
 				
641
-				if($next_run_time >= time())
642
-					$next_run = "in ".human_time_diff($next_run_time, time());
643
-				else
644
-					$next_run = __("executed", 'xcloner-backup-and-restore');
659
+				if($next_run_time >= time()) {
660
+									$next_run = "in ".human_time_diff($next_run_time, time());
661
+				} else {
662
+									$next_run = __("executed", 'xcloner-backup-and-restore');
663
+				}
645 664
 				
646 665
 				$next_run = "<a href='#' title='".$date_text."'>".$next_run."</a>";
647 666
 				//$next_run .=" ($date_text)";	
@@ -732,7 +751,7 @@  discard block
 block discarded – undo
732 751
 			$tar->open($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file, $start);
733 752
 		
734 753
 			$data = $tar->contents(get_option('xcloner_files_to_process_per_request'));
735
-		}catch(Exception $e)
754
+		} catch(Exception $e)
736 755
 		{
737 756
 			$return['error'] = true;
738 757
 			$return['message'] = $e->getMessage();
@@ -760,15 +779,16 @@  discard block
 block discarded – undo
760 779
 		{
761 780
 			$return['start'] = $data['start'];
762 781
 			$return['finished'] = 0;	
763
-		}else{
782
+		} else{
764 783
 			if($this->xcloner_file_system->is_multipart($source_backup_file))
765 784
 			{
766 785
 				$return['start'] = 0;
767 786
 				
768 787
 				++$return['part'];
769 788
 			
770
-				if($return['part'] < sizeof($backup_parts))	
771
-					$return['finished'] = 0;
789
+				if($return['part'] < sizeof($backup_parts)) {
790
+									$return['finished'] = 0;
791
+				}
772 792
 				
773 793
 			}
774 794
 		}	
@@ -794,7 +814,7 @@  discard block
 block discarded – undo
794 814
 			{
795 815
 				$return = call_user_func_array(array($xcloner_remote_storage, "copy_backup_remote_to_local"), array($backup_file, $storage_type));
796 816
 			}
797
-		}catch(Exception $e){
817
+		} catch(Exception $e){
798 818
 		
799 819
 			$return['error'] = 1;
800 820
 			$return['message'] = $e->getMessage();
@@ -833,7 +853,7 @@  discard block
 block discarded – undo
833 853
 			{
834 854
 				$return = call_user_func_array(array($xcloner_remote_storage, "upload_backup_to_storage"), array($backup_file, $storage_type));
835 855
 			}
836
-		}catch(Exception $e){
856
+		} catch(Exception $e){
837 857
 		
838 858
 			$return['error'] = 1;
839 859
 			$return['message'] = $e->getMessage();
@@ -984,11 +1004,13 @@  discard block
 block discarded – undo
984 1004
 		$file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
985 1005
 		$hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']);
986 1006
 		
987
-		if(isset($_POST['part']))
988
-			$return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
1007
+		if(isset($_POST['part'])) {
1008
+					$return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
1009
+		}
989 1010
 		
990
-		if(isset($_POST['uploaded_size']))
991
-			$return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']);
1011
+		if(isset($_POST['uploaded_size'])) {
1012
+					$return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']);
1013
+		}
992 1014
 		
993 1015
 		$start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']);
994 1016
 		$target_url = $this->xcloner_sanitization->sanitize_input_as_string($_POST['target_url']);
@@ -1015,7 +1037,7 @@  discard block
 block discarded – undo
1015 1037
 			$xcloner_file_transfer->set_target($target_url);
1016 1038
 			$return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash);
1017 1039
 		
1018
-		}catch(Exception $e){
1040
+		} catch(Exception $e){
1019 1041
 		
1020 1042
 			$return = array();
1021 1043
 			$return['error'] = true;
@@ -1059,8 +1081,9 @@  discard block
 block discarded – undo
1059 1081
 			$data['hash'] = $this->xcloner_settings->get_hash();
1060 1082
 		}
1061 1083
 			
1062
-		if( ob_get_length() )
1063
-			ob_clean();
1084
+		if( ob_get_length() ) {
1085
+					ob_clean();
1086
+		}
1064 1087
 		wp_send_json($data);
1065 1088
 		
1066 1089
 		die();
Please login to merge, or discard this patch.
includes/class-xcloner-archive.php 5 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,5 @@
 block discarded – undo
1 1
 <?php
2 2
 use splitbrain\PHPArchive\Tar;
3
-use splitbrain\PHPArchive\Archive;
4 3
 use splitbrain\PHPArchive\FileInfo;
5 4
 
6 5
 class Xcloner_Archive extends Tar
Please login to merge, or discard this patch.
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -555,15 +555,15 @@  discard block
 block discarded – undo
555 555
 		return array($bytes_wrote, $last_position);
556 556
 	}
557 557
 	    
558
-    /**
559
-     * Open a TAR archive and put the file cursor at the end for data appending
560
-     *
561
-     * If $file is empty, the tar file will be created in memory
562
-     *
563
-     * @param string $file
564
-     * @throws ArchiveIOException
565
-     */
566
-    /*
558
+	/**
559
+	 * Open a TAR archive and put the file cursor at the end for data appending
560
+	 *
561
+	 * If $file is empty, the tar file will be created in memory
562
+	 *
563
+	 * @param string $file
564
+	 * @throws ArchiveIOException
565
+	 */
566
+	/*
567 567
     public function openForAppend($file = '')
568 568
     {
569 569
         $this->file   = $file;
@@ -593,16 +593,16 @@  discard block
 block discarded – undo
593 593
     }
594 594
     */
595 595
     
596
-     /**
597
-     * Append data to a file to the current TAR archive using an existing file in the filesystem
598
-     *
599
-     * @param string          	$file     path to the original file
600
-     * @param int          		$start    starting reading position in file
601
-     * @param int          		$end      end position in reading multiple with 512
602
-     * @param string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with all meta data, empty to take from original
603
-     * @throws ArchiveIOException
604
-     */
605
-    /*
596
+	 /**
597
+	  * Append data to a file to the current TAR archive using an existing file in the filesystem
598
+	  *
599
+	  * @param string          	$file     path to the original file
600
+	  * @param int          		$start    starting reading position in file
601
+	  * @param int          		$end      end position in reading multiple with 512
602
+	  * @param string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with all meta data, empty to take from original
603
+	  * @throws ArchiveIOException
604
+	  */
605
+	/*
606 606
      * public function appendFileData($file, $fileinfo = '', $start = 0, $limit = 0)
607 607
     {
608 608
 		$end = $start+($limit*512);
@@ -658,14 +658,14 @@  discard block
 block discarded – undo
658 658
         return $last_position;
659 659
     }*/
660 660
     
661
-    /**
662
-     * Adds a file to a TAR archive by appending it's data
663
-     *
664
-     * @param string $archive			name of the archive file
665
-     * @param string $file				name of the file to read data from				
666
-     * @param string $start				start position from where to start reading data
667
-     * @throws ArchiveIOException
668
-     */
661
+	/**
662
+	 * Adds a file to a TAR archive by appending it's data
663
+	 *
664
+	 * @param string $archive			name of the archive file
665
+	 * @param string $file				name of the file to read data from				
666
+	 * @param string $start				start position from where to start reading data
667
+	 * @throws ArchiveIOException
668
+	 */
669 669
 	/*public function addFileToArchive($archive, $file, $start = 0)
670 670
 	{
671 671
 		$this->openForAppend($archive);
Please login to merge, or discard this patch.
Doc Comments   +26 added lines patch added patch discarded remove patch
@@ -49,6 +49,11 @@  discard block
 block discarded – undo
49 49
 	 * Rename backup archive
50 50
 	 * 
51 51
 	 */ 
52
+
53
+	/**
54
+	 * @param string $old_name
55
+	 * @param string $new_name
56
+	 */
52 57
 	public function rename_archive($old_name, $new_name)
53 58
 	{
54 59
 		$this->logger->info(sprintf("Renaming backup archive %s to %s", $old_name, $new_name));
@@ -113,6 +118,10 @@  discard block
 block discarded – undo
113 118
 	 * Send notification error by E-Mail
114 119
 	 * 
115 120
 	 */
121
+
122
+	/**
123
+	 * @param string $error_message
124
+	 */
116 125
 	public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message)
117 126
 	{
118 127
 		
@@ -137,6 +146,11 @@  discard block
 block discarded – undo
137 146
 	 * Send backup archive notfication by E-Mail
138 147
 	 * 
139 148
 	 */ 
149
+
150
+	/**
151
+	 * @param string $from
152
+	 * @param string $subject
153
+	 */
140 154
 	public function send_notification($to, $from, $subject, $backup_name, $params, $error_message="", $additional = array())
141 155
 	{
142 156
 		if(!$from)
@@ -215,6 +229,10 @@  discard block
 block discarded – undo
215 229
 	 * Incremental Backup method
216 230
 	 * 
217 231
 	 */ 
232
+
233
+	/**
234
+	 * @param integer $init
235
+	 */
218 236
 	public function start_incremental_backup($backup_params, $extra_params, $init)
219 237
 	{
220 238
 		$return = array();
@@ -438,6 +456,10 @@  discard block
 block discarded – undo
438 456
 	 * Write multipart file components
439 457
 	 * 
440 458
 	 */ 
459
+
460
+	/**
461
+	 * @param string $path
462
+	 */
441 463
 	private function write_multipart_file($path)
442 464
 	{
443 465
 		$path = $this->get_archive_name_with_extension();
@@ -497,6 +519,10 @@  discard block
 block discarded – undo
497 519
 	 * Add file to archive
498 520
 	 * 
499 521
 	 */ 
522
+
523
+	/**
524
+	 * @param integer $append
525
+	 */
500 526
 	public function add_file_to_archive($file_info, $start_at_byte, $byte_limit = 0, $append, $filesystem)
501 527
 	{
502 528
 		
Please login to merge, or discard this patch.
Spacing   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -8,11 +8,11 @@  discard block
 block discarded – undo
8 8
 	/*
9 9
 	 * bytes
10 10
 	 */ 
11
-	private $file_size_per_request_limit	= 52428800 ; //50MB = 52428800; 1MB = 1048576
12
-	private $files_to_process_per_request 	= 250; //block of 512 bytes
13
-	private $compression_level 				= 0; //0-9 , 0 uncompressed
11
+	private $file_size_per_request_limit	= 52428800; //50MB = 52428800; 1MB = 1048576
12
+	private $files_to_process_per_request = 250; //block of 512 bytes
13
+	private $compression_level = 0; //0-9 , 0 uncompressed
14 14
 	private $xcloner_split_backup_limit		= 2048; //2048MB
15
-	private $processed_size_bytes			= 0 ;
15
+	private $processed_size_bytes = 0;
16 16
 	
17 17
 	private $archive_name;
18 18
 	private $backup_archive;
@@ -22,25 +22,25 @@  discard block
 block discarded – undo
22 22
 	
23 23
 	public function __construct(Xcloner $xcloner_container, $archive_name = "")
24 24
 	{
25
-		$this->filesystem 		= $xcloner_container->get_xcloner_filesystem();
26
-		$this->logger 			= $xcloner_container->get_xcloner_logger()->withName("xcloner_archive");
25
+		$this->filesystem = $xcloner_container->get_xcloner_filesystem();
26
+		$this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_archive");
27 27
 		$this->xcloner_settings = $xcloner_container->get_xcloner_settings();
28 28
 		
29
-		if($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request'))
30
-			$this->file_size_per_request_limit = $value*1024*1024; //MB
29
+		if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request'))
30
+			$this->file_size_per_request_limit = $value * 1024 * 1024; //MB
31 31
 			
32
-		if($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request'))
32
+		if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request'))
33 33
 			$this->files_to_process_per_request = $value;
34 34
 		
35
-		if($value = get_option('xcloner_backup_compression_level'))
35
+		if ($value = get_option('xcloner_backup_compression_level'))
36 36
 			$this->compression_level = $value;
37 37
 		
38
-		if($value = get_option('xcloner_split_backup_limit'))
38
+		if ($value = get_option('xcloner_split_backup_limit'))
39 39
 			$this->xcloner_split_backup_limit = $value;
40 40
 		
41
-		$this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024*1024; //transform to bytes
41
+		$this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024 * 1024; //transform to bytes
42 42
 			
43
-		if(isset($archive_name) && $archive_name)
43
+		if (isset($archive_name) && $archive_name)
44 44
 		{
45 45
 			$this->set_archive_name($archive_name);
46 46
 		}
@@ -68,23 +68,23 @@  discard block
 block discarded – undo
68 68
 		
69 69
 		$this->archive_name = $this->filesystem->process_backup_name($name);
70 70
 		
71
-		if($diff_timestamp_start = $this->filesystem->get_diff_timestamp_start())
71
+		if ($diff_timestamp_start = $this->filesystem->get_diff_timestamp_start())
72 72
 		{
73 73
 			//$this->archive_name = $this->archive_name."-diff-".date("Y-m-d_H-i",$diff_timestamp_start);
74 74
 			$new_name = $this->archive_name;
75 75
 			
76
-			if(!stristr($new_name, "-diff"))
77
-				$new_name = $this->archive_name . "-diff".date("Y-m-d_H-i",$diff_timestamp_start);
76
+			if (!stristr($new_name, "-diff"))
77
+				$new_name = $this->archive_name."-diff".date("Y-m-d_H-i", $diff_timestamp_start);
78 78
 			
79 79
 			$this->archive_name = $new_name;
80 80
 			
81 81
 		}
82 82
 		
83
-		if(isset($part) and $part)
83
+		if (isset($part) and $part)
84 84
 		{
85
-			$new_name =  preg_replace('/-part(\d*)/', "-part".$part, $this->archive_name);
86
-			if(!stristr($new_name, "-part"))
87
-				$new_name = $this->archive_name . "-part".$part;
85
+			$new_name = preg_replace('/-part(\d*)/', "-part".$part, $this->archive_name);
86
+			if (!stristr($new_name, "-part"))
87
+				$new_name = $this->archive_name."-part".$part;
88 88
 			
89 89
 			$this->archive_name = $new_name;	
90 90
 		}
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 */ 
110 110
 	public function get_archive_name_multipart()
111 111
 	{
112
-		$new_name =  preg_replace('/-part(\d*)/', "", $this->archive_name);
112
+		$new_name = preg_replace('/-part(\d*)/', "", $this->archive_name);
113 113
 		return $new_name."-multipart".$this->xcloner_settings->get_backup_extension_name(".csv");
114 114
 	}
115 115
 	
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 	public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message)
132 132
 	{
133 133
 		
134
-		$body  = $error_message; 
134
+		$body = $error_message; 
135 135
 		
136 136
 		$this->logger->info(sprintf("Sending backup error notification to %s", $to));
137 137
 		
@@ -139,10 +139,10 @@  discard block
 block discarded – undo
139 139
 		
140 140
 		$headers = array('Content-Type: text/html; charset=UTF-8');
141 141
 		
142
-		if($admin_email and $from )
142
+		if ($admin_email and $from)
143 143
 			$headers[] = 'From: '.$from.' <'.$admin_email.'>';
144 144
 
145
-		$return = wp_mail( $to, $subject, $body, $headers );
145
+		$return = wp_mail($to, $subject, $body, $headers);
146 146
 		
147 147
 		return $return;
148 148
 	}
@@ -152,29 +152,29 @@  discard block
 block discarded – undo
152 152
 	 * Send backup archive notfication by E-Mail
153 153
 	 * 
154 154
 	 */ 
155
-	public function send_notification($to, $from, $subject, $backup_name, $params, $error_message="", $additional = array())
155
+	public function send_notification($to, $from, $subject, $backup_name, $params, $error_message = "", $additional = array())
156 156
 	{
157
-		if(!$from)
157
+		if (!$from)
158 158
 		{
159 159
 			$from = "XCloner Backup";
160 160
 		}
161 161
 			
162
-		if(($error_message))
162
+		if (($error_message))
163 163
 		{
164 164
 			return $this->send_notification_error($to, $from, $subject, $backup_name, $params, $error_message);
165 165
 		}
166 166
 		
167 167
 		$params = (array)$params;
168 168
 		
169
-		if(!$subject)
169
+		if (!$subject)
170 170
 		{
171
-			$subject = sprintf(__("New backup generated %s") ,$backup_name);
171
+			$subject = sprintf(__("New backup generated %s"), $backup_name);
172 172
 		}
173 173
 			
174 174
 		$body = sprintf(__("Generated Backup Size: %s"), size_format($this->filesystem->get_backup_size($backup_name)));
175 175
 		$body .= "<br /><br />";
176 176
 		
177
-		if(isset($additional['lines_total']))
177
+		if (isset($additional['lines_total']))
178 178
 		{
179 179
 			$body .= sprintf(__("Total files added: %s"), $additional['lines_total']);
180 180
 			$body .= "<br /><br />";
@@ -182,27 +182,27 @@  discard block
 block discarded – undo
182 182
 		
183 183
 		$backup_parts = $this->filesystem->get_multipart_files($backup_name);
184 184
 		
185
-		if(!$backups_counter = sizeof($backup_parts))
185
+		if (!$backups_counter = sizeof($backup_parts))
186 186
 			$backups_counter = 1;
187 187
 		
188 188
 		$body .= sprintf(__("Backup Parts: %s"), $backups_counter);
189 189
 		$body .= "<br />";
190 190
 		
191
-		if(sizeof($backup_parts))
191
+		if (sizeof($backup_parts))
192 192
 		{
193
-			$body .= implode("<br />",$backup_parts);
193
+			$body .= implode("<br />", $backup_parts);
194 194
 			$body .= "<br />";
195 195
 		}
196 196
 		
197
-		$body.= "<br />";
197
+		$body .= "<br />";
198 198
 		
199
-		if(isset($params['backup_params']->backup_comments))
199
+		if (isset($params['backup_params']->backup_comments))
200 200
 		{
201 201
 			$body .= __("Backup Comments: ").$params['backup_params']->backup_comments;
202 202
 			$body .= "<br /><br />";
203 203
 		}
204 204
 		
205
-		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log'))
205
+		if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log'))
206 206
 			$body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n", $this->logger->getLastDebugLines(50));
207 207
 		
208 208
 		$attachments = $this->filesystem->get_backup_attachments();
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 		$tar = new Tar();
213 213
 		$tar->create($attachments_archive);
214 214
 			
215
-		foreach($attachments as $key => $file)
215
+		foreach ($attachments as $key => $file)
216 216
 		{
217 217
 			$tar->addFile($file, basename($file));
218 218
 		}
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 		
225 225
 		$headers = array('Content-Type: text/html; charset=UTF-8', 'From: '.$from.' <'.$admin_email.'>');
226 226
 		
227
-		$return = wp_mail( $to, $subject, $body, $headers, array($attachments_archive) );
227
+		$return = wp_mail($to, $subject, $body, $headers, array($attachments_archive));
228 228
 	
229 229
 		return $return;
230 230
 	}
@@ -238,17 +238,17 @@  discard block
 block discarded – undo
238 238
 	{
239 239
 		$return = array();
240 240
 		
241
-		if(!isset($extra_params['backup_part']))
241
+		if (!isset($extra_params['backup_part']))
242 242
 			$extra_params['backup_part'] = 0;
243 243
 		
244 244
 		$return['extra']['backup_part'] = $extra_params['backup_part'];
245 245
 					
246
-		if(isset( $extra_params['backup_archive_name']))
246
+		if (isset($extra_params['backup_archive_name']))
247 247
 			$this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']);
248 248
 		else
249 249
 			$this->set_archive_name($backup_params['backup_name']);
250 250
 			
251
-		if(!$this->get_archive_name())
251
+		if (!$this->get_archive_name())
252 252
 			$this->set_archive_name();
253 253
 		
254 254
 		$this->backup_archive = new Tar();
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 		
257 257
 		$archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension());
258 258
 		
259
-		if($init)
259
+		if ($init)
260 260
 		{
261 261
 			$this->logger->info(sprintf(__("Initializing the backup archive %s"), $this->get_archive_name()));
262 262
 		
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 			
265 265
 			$return['extra']['backup_init'] = 1;
266 266
 			
267
-		}else{
267
+		} else {
268 268
 			$this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name()));
269 269
 			
270 270
 			$this->backup_archive->openForAppend($archive_info->getPath().DS.$archive_info->getFilename());
@@ -276,13 +276,13 @@  discard block
 block discarded – undo
276 276
 		$return['extra']['backup_archive_name'] = $this->get_archive_name();
277 277
 		$return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension();
278 278
 		
279
-		if(!isset($extra_params['start_at_line']))
279
+		if (!isset($extra_params['start_at_line']))
280 280
 			$extra_params['start_at_line'] = 0;
281 281
 		
282
-		if(!isset($extra_params['start_at_byte']))
282
+		if (!isset($extra_params['start_at_byte']))
283 283
 			$extra_params['start_at_byte'] = 0;
284 284
 		
285
-		if(!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler()))
285
+		if (!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler()))
286 286
 		{
287 287
 			$this->logger->error(sprintf("Missing the includes file handler %s, aborting...", $this->filesystem->get_included_files_handler()));
288 288
 			
@@ -296,14 +296,14 @@  discard block
 block discarded – undo
296 296
 		
297 297
 		$file->seek(PHP_INT_MAX);
298 298
 
299
-		$return['extra']['lines_total'] = ($file->key()-1);
299
+		$return['extra']['lines_total'] = ($file->key() - 1);
300 300
 		
301 301
 		//we skip the first CSV line with headers 
302
-		if(!$extra_params['start_at_line'])
302
+		if (!$extra_params['start_at_line'])
303 303
 		{
304 304
 			$file->seek(1);
305
-		}else{
306
-			$file->seek($extra_params['start_at_line']+1);
305
+		} else {
306
+			$file->seek($extra_params['start_at_line'] + 1);
307 307
 		}
308 308
 		
309 309
 		$this->processed_size_bytes = 0;
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 		
315 315
 		$byte_limit = 0;
316 316
 		
317
-		while(!$file->eof() and $counter<=$this->files_to_process_per_request)
317
+		while (!$file->eof() and $counter <= $this->files_to_process_per_request)
318 318
 		{
319 319
 			$current_line_str = $file->current();
320 320
 			
@@ -324,15 +324,15 @@  discard block
 block discarded – undo
324 324
 			
325 325
 			$start_filesystem = "start_filesystem";
326 326
 			
327
-			if(isset($line[4])){
327
+			if (isset($line[4])) {
328 328
 				$start_filesystem = $line[4];
329 329
 			}
330 330
 			
331 331
 			//$adapter = $this->filesystem->get_adapter($start_filesystem);
332 332
 			
333
-			if(!$relative_path || !$this->filesystem->get_filesystem($start_filesystem)->has($relative_path))
333
+			if (!$relative_path || !$this->filesystem->get_filesystem($start_filesystem)->has($relative_path))
334 334
 			{
335
-				if($relative_path != "")
335
+				if ($relative_path != "")
336 336
 				{
337 337
 					$this->logger->error(sprintf("Could not add file %b to backup archive, file not found", $relative_path));
338 338
 				}
@@ -344,37 +344,37 @@  discard block
 block discarded – undo
344 344
 			
345 345
 			$file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path);
346 346
 			
347
-			if(!isset($file_info['size']))
347
+			if (!isset($file_info['size']))
348 348
 				$file_info['size'] = 0;
349 349
 			
350
-			if($start_filesystem == "tmp_filesystem")
350
+			if ($start_filesystem == "tmp_filesystem")
351 351
 			{	
352 352
 				$file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix();
353 353
 			}
354 354
 			
355
-			$byte_limit = (int)$this->file_size_per_request_limit/512;
355
+			$byte_limit = (int)$this->file_size_per_request_limit / 512;
356 356
 			
357 357
 			$append = 0;
358 358
 			
359
-			if($file_info['size'] > $byte_limit*512 or $start_byte)
359
+			if ($file_info['size'] > $byte_limit * 512 or $start_byte)
360 360
 				$append = 1;
361 361
 						
362
-			if(!isset($return['extra']['backup_size']))
363
-				$return['extra']['backup_size'] =0;
362
+			if (!isset($return['extra']['backup_size']))
363
+				$return['extra']['backup_size'] = 0;
364 364
 			
365 365
 			$return['extra']['backup_size'] = $archive_info->getSize();
366 366
 			
367 367
 			$estimated_new_size = $return['extra']['backup_size'] + $file_info['size'];
368 368
 			
369 369
 			//we create a new backup part if we reach the Split Achive Limit
370
-			if($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte))
370
+			if ($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte))
371 371
 			{
372
-				$this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ",$this->xcloner_split_backup_limit, $estimated_new_size));
372
+				$this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ", $this->xcloner_split_backup_limit, $estimated_new_size));
373 373
 				list($archive_info, $return['extra']['backup_part']) = $this->create_new_backup_part($return['extra']['backup_part']);
374 374
 				
375
-				if($file_info['size'] > $this->xcloner_split_backup_limit)
375
+				if ($file_info['size'] > $this->xcloner_split_backup_limit)
376 376
 				{
377
-					$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",$file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit));
377
+					$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", $file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit));
378 378
 					$extra_params['start_at_line']++;
379 379
 				}
380 380
 				
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 				return $return;
387 387
 			}
388 388
 			
389
-			list($bytes_wrote, $last_position) = $this->add_file_to_archive( $file_info, $start_byte, $byte_limit, $append, $start_filesystem);
389
+			list($bytes_wrote, $last_position) = $this->add_file_to_archive($file_info, $start_byte, $byte_limit, $append, $start_filesystem);
390 390
 			$this->processed_size_bytes += $bytes_wrote;
391 391
 			
392 392
 			//echo" - processed ".$this->processed_size_bytes." bytes ".$this->file_size_per_request_limit." last_position:".$last_position." \n";
@@ -394,17 +394,17 @@  discard block
 block discarded – undo
394 394
 			$return['extra']['processed_file_size'] = $file_info['size'];
395 395
 			$return['extra']['backup_size'] = $archive_info->getSize();
396 396
 			
397
-			if($last_position>0){	
397
+			if ($last_position > 0) {	
398 398
 				$start_byte = $last_position;
399 399
 			}
400
-			else{	
400
+			else {	
401 401
 				$extra_params['start_at_line']++;
402 402
 				$file->next();
403 403
 				$start_byte = 0;
404 404
 				$counter++;
405 405
 			}
406 406
 			
407
-			if($this->processed_size_bytes >= $this->file_size_per_request_limit)
407
+			if ($this->processed_size_bytes >= $this->file_size_per_request_limit)
408 408
 			{
409 409
 				clearstatcache();
410 410
 				$return['extra']['backup_size'] = $archive_info->getSize();
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 			}
418 418
 		}
419 419
 		
420
-		if(!$file->eof())
420
+		if (!$file->eof())
421 421
 		{
422 422
 			clearstatcache();
423 423
 			$return['extra']['backup_size'] = $archive_info->getSize();
@@ -434,12 +434,12 @@  discard block
 block discarded – undo
434 434
 		$this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", $this->get_archive_name_with_extension()));
435 435
 		$this->backup_archive->close();
436 436
 				
437
-		if($return['extra']['backup_part'])
437
+		if ($return['extra']['backup_part'])
438 438
 			$this->write_multipart_file($this->get_archive_name_with_extension());
439 439
 		
440
-		$return['extra']['start_at_line'] = $extra_params['start_at_line']-1;
440
+		$return['extra']['start_at_line'] = $extra_params['start_at_line'] - 1;
441 441
 		
442
-		if(isset($file_info))
442
+		if (isset($file_info))
443 443
 		{
444 444
 			$return['extra']['processed_file'] = $file_info['path'];
445 445
 			$return['extra']['processed_file_size'] = $file_info['size'];
@@ -481,20 +481,20 @@  discard block
 block discarded – undo
481 481
 		$this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", $this->get_archive_name_with_extension()));
482 482
 		$this->backup_archive->close();		
483 483
 		
484
-		if(!$part)
484
+		if (!$part)
485 485
 		{
486 486
 			$old_name = $this->get_archive_name_with_extension();
487 487
 			$this->set_archive_name($this->get_archive_name(), ++$part);
488 488
 			$this->rename_archive($old_name, $this->get_archive_name_with_extension());
489 489
 			
490
-			if($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart()))
490
+			if ($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart()))
491 491
 				$this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart());
492 492
 				
493 493
 			$this->write_multipart_file($this->get_archive_name_with_extension());
494 494
 			
495
-		}else
495
+		} else
496 496
 		{
497
-			$this->logger->info(sprintf("Creating new multipart info file %s",$this->get_archive_name_with_extension()));
497
+			$this->logger->info(sprintf("Creating new multipart info file %s", $this->get_archive_name_with_extension()));
498 498
 			$this->write_multipart_file($this->get_archive_name_with_extension());
499 499
 		}
500 500
 				
@@ -522,10 +522,10 @@  discard block
 block discarded – undo
522 522
 		$start_adapter = $this->filesystem->get_adapter($filesystem);
523 523
 		$start_filesystem = $this->filesystem->get_adapter($filesystem);
524 524
 		
525
-		if(!$file_info['path'])
525
+		if (!$file_info['path'])
526 526
 			return;
527 527
 		
528
-		if(isset($file_info['archive_prefix_path']))	
528
+		if (isset($file_info['archive_prefix_path']))	
529 529
 			$file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path'];
530 530
 		else
531 531
 			$file_info['target_path'] = $file_info['path'];
@@ -534,36 +534,36 @@  discard block
 block discarded – undo
534 534
 		
535 535
 		//$start_adapter = $this->filesystem->get_start_adapter();
536 536
 
537
-		if(!$append){
537
+		if (!$append) {
538 538
 			$bytes_wrote = $file_info['size'];
539 539
 			$this->logger->info(sprintf("Adding %s bytes of file %s to archive %s ", $bytes_wrote, $file_info['target_path'], $this->get_archive_name_with_extension()));
540 540
 			$this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path']);
541 541
 		}
542
-		else{	
542
+		else {	
543 543
 			$tmp_file = md5($file_info['path']);
544 544
 			
545 545
 			//we isolate file to tmp if we are at byte 0, the starting point of file reading
546
-			if(!$start_at_byte)
546
+			if (!$start_at_byte)
547 547
 			{
548 548
 				$this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes", $file_info['path'], $tmp_file));
549 549
 				$file_stream = $start_filesystem->readStream($file_info['path']);
550 550
 				
551
-				if(is_resource($file_stream['stream']))
551
+				if (is_resource($file_stream['stream']))
552 552
 					$this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']);
553 553
 			}
554 554
 			
555
-			if($this->filesystem->get_tmp_filesystem()->has($tmp_file))
555
+			if ($this->filesystem->get_tmp_filesystem()->has($tmp_file))
556 556
 			{
557 557
 				$is_tmp = 1;
558 558
 				$last_position = $this->backup_archive->appendFileData($this->filesystem->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_file), $file_info['target_path'], $start_at_byte, $byte_limit);
559 559
 			}
560
-			else{
560
+			else {
561 561
 				$is_tmp = 0;
562 562
 				$last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path'], $start_at_byte, $byte_limit);
563 563
 			}
564 564
 				
565 565
 			
566
-			if($last_position == -1)
566
+			if ($last_position == -1)
567 567
 			{
568 568
 				$bytes_wrote = $file_info['size'] - $start_at_byte;
569 569
 			}
@@ -573,18 +573,18 @@  discard block
 block discarded – undo
573 573
 			}
574 574
 			
575 575
 			
576
-			if($is_tmp)
576
+			if ($is_tmp)
577 577
 			{
578 578
 				$this->logger->info(sprintf("Appended %s bytes, starting position %s, of tmp file %s (%s) to archive %s ", $bytes_wrote, $start_at_byte, $tmp_file, $file_info['target_path'], $this->get_archive_name()));
579 579
 			}
580
-			else{
580
+			else {
581 581
 				$this->logger->info(sprintf("Appended %s bytes, starting position %s, of original file %s to archive %s ", $bytes_wrote, $start_at_byte, $file_info['target_path'], $tmp_file, $this->get_archive_name()));
582 582
 			}
583 583
 			
584 584
 			//we delete here the isolated tmp file
585
-			if($last_position == -1)
585
+			if ($last_position == -1)
586 586
 			{
587
-				if($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file))
587
+				if ($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file))
588 588
 				{
589 589
 					$this->logger->info(sprintf("Deleting %s from the tmp filesystem", $tmp_file));
590 590
 					$this->filesystem->get_tmp_filesystem_adapter()->delete($tmp_file);
Please login to merge, or discard this patch.
Braces   +79 added lines, -61 removed lines patch added patch discarded remove patch
@@ -26,17 +26,22 @@  discard block
 block discarded – undo
26 26
 		$this->logger 			= $xcloner_container->get_xcloner_logger()->withName("xcloner_archive");
27 27
 		$this->xcloner_settings = $xcloner_container->get_xcloner_settings();
28 28
 		
29
-		if($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request'))
30
-			$this->file_size_per_request_limit = $value*1024*1024; //MB
29
+		if($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) {
30
+					$this->file_size_per_request_limit = $value*1024*1024;
31
+		}
32
+		//MB
31 33
 			
32
-		if($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request'))
33
-			$this->files_to_process_per_request = $value;
34
+		if($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) {
35
+					$this->files_to_process_per_request = $value;
36
+		}
34 37
 		
35
-		if($value = get_option('xcloner_backup_compression_level'))
36
-			$this->compression_level = $value;
38
+		if($value = get_option('xcloner_backup_compression_level')) {
39
+					$this->compression_level = $value;
40
+		}
37 41
 		
38
-		if($value = get_option('xcloner_split_backup_limit'))
39
-			$this->xcloner_split_backup_limit = $value;
42
+		if($value = get_option('xcloner_split_backup_limit')) {
43
+					$this->xcloner_split_backup_limit = $value;
44
+		}
40 45
 		
41 46
 		$this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024*1024; //transform to bytes
42 47
 			
@@ -73,8 +78,9 @@  discard block
 block discarded – undo
73 78
 			//$this->archive_name = $this->archive_name."-diff-".date("Y-m-d_H-i",$diff_timestamp_start);
74 79
 			$new_name = $this->archive_name;
75 80
 			
76
-			if(!stristr($new_name, "-diff"))
77
-				$new_name = $this->archive_name . "-diff".date("Y-m-d_H-i",$diff_timestamp_start);
81
+			if(!stristr($new_name, "-diff")) {
82
+							$new_name = $this->archive_name . "-diff".date("Y-m-d_H-i",$diff_timestamp_start);
83
+			}
78 84
 			
79 85
 			$this->archive_name = $new_name;
80 86
 			
@@ -83,8 +89,9 @@  discard block
 block discarded – undo
83 89
 		if(isset($part) and $part)
84 90
 		{
85 91
 			$new_name =  preg_replace('/-part(\d*)/', "-part".$part, $this->archive_name);
86
-			if(!stristr($new_name, "-part"))
87
-				$new_name = $this->archive_name . "-part".$part;
92
+			if(!stristr($new_name, "-part")) {
93
+							$new_name = $this->archive_name . "-part".$part;
94
+			}
88 95
 			
89 96
 			$this->archive_name = $new_name;	
90 97
 		}
@@ -139,8 +146,9 @@  discard block
 block discarded – undo
139 146
 		
140 147
 		$headers = array('Content-Type: text/html; charset=UTF-8');
141 148
 		
142
-		if($admin_email and $from )
143
-			$headers[] = 'From: '.$from.' <'.$admin_email.'>';
149
+		if($admin_email and $from ) {
150
+					$headers[] = 'From: '.$from.' <'.$admin_email.'>';
151
+		}
144 152
 
145 153
 		$return = wp_mail( $to, $subject, $body, $headers );
146 154
 		
@@ -182,8 +190,9 @@  discard block
 block discarded – undo
182 190
 		
183 191
 		$backup_parts = $this->filesystem->get_multipart_files($backup_name);
184 192
 		
185
-		if(!$backups_counter = sizeof($backup_parts))
186
-			$backups_counter = 1;
193
+		if(!$backups_counter = sizeof($backup_parts)) {
194
+					$backups_counter = 1;
195
+		}
187 196
 		
188 197
 		$body .= sprintf(__("Backup Parts: %s"), $backups_counter);
189 198
 		$body .= "<br />";
@@ -202,8 +211,9 @@  discard block
 block discarded – undo
202 211
 			$body .= "<br /><br />";
203 212
 		}
204 213
 		
205
-		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log'))
206
-			$body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n", $this->logger->getLastDebugLines(50));
214
+		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
215
+					$body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n", $this->logger->getLastDebugLines(50));
216
+		}
207 217
 		
208 218
 		$attachments = $this->filesystem->get_backup_attachments();
209 219
 		
@@ -238,18 +248,21 @@  discard block
 block discarded – undo
238 248
 	{
239 249
 		$return = array();
240 250
 		
241
-		if(!isset($extra_params['backup_part']))
242
-			$extra_params['backup_part'] = 0;
251
+		if(!isset($extra_params['backup_part'])) {
252
+					$extra_params['backup_part'] = 0;
253
+		}
243 254
 		
244 255
 		$return['extra']['backup_part'] = $extra_params['backup_part'];
245 256
 					
246
-		if(isset( $extra_params['backup_archive_name']))
247
-			$this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']);
248
-		else
249
-			$this->set_archive_name($backup_params['backup_name']);
257
+		if(isset( $extra_params['backup_archive_name'])) {
258
+					$this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']);
259
+		} else {
260
+					$this->set_archive_name($backup_params['backup_name']);
261
+		}
250 262
 			
251
-		if(!$this->get_archive_name())
252
-			$this->set_archive_name();
263
+		if(!$this->get_archive_name()) {
264
+					$this->set_archive_name();
265
+		}
253 266
 		
254 267
 		$this->backup_archive = new Tar();
255 268
 		$this->backup_archive->setCompression($this->compression_level);
@@ -264,7 +277,7 @@  discard block
 block discarded – undo
264 277
 			
265 278
 			$return['extra']['backup_init'] = 1;
266 279
 			
267
-		}else{
280
+		} else{
268 281
 			$this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name()));
269 282
 			
270 283
 			$this->backup_archive->openForAppend($archive_info->getPath().DS.$archive_info->getFilename());
@@ -276,11 +289,13 @@  discard block
 block discarded – undo
276 289
 		$return['extra']['backup_archive_name'] = $this->get_archive_name();
277 290
 		$return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension();
278 291
 		
279
-		if(!isset($extra_params['start_at_line']))
280
-			$extra_params['start_at_line'] = 0;
292
+		if(!isset($extra_params['start_at_line'])) {
293
+					$extra_params['start_at_line'] = 0;
294
+		}
281 295
 		
282
-		if(!isset($extra_params['start_at_byte']))
283
-			$extra_params['start_at_byte'] = 0;
296
+		if(!isset($extra_params['start_at_byte'])) {
297
+					$extra_params['start_at_byte'] = 0;
298
+		}
284 299
 		
285 300
 		if(!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler()))
286 301
 		{
@@ -302,7 +317,7 @@  discard block
 block discarded – undo
302 317
 		if(!$extra_params['start_at_line'])
303 318
 		{
304 319
 			$file->seek(1);
305
-		}else{
320
+		} else{
306 321
 			$file->seek($extra_params['start_at_line']+1);
307 322
 		}
308 323
 		
@@ -344,8 +359,9 @@  discard block
 block discarded – undo
344 359
 			
345 360
 			$file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path);
346 361
 			
347
-			if(!isset($file_info['size']))
348
-				$file_info['size'] = 0;
362
+			if(!isset($file_info['size'])) {
363
+							$file_info['size'] = 0;
364
+			}
349 365
 			
350 366
 			if($start_filesystem == "tmp_filesystem")
351 367
 			{	
@@ -356,11 +372,13 @@  discard block
 block discarded – undo
356 372
 			
357 373
 			$append = 0;
358 374
 			
359
-			if($file_info['size'] > $byte_limit*512 or $start_byte)
360
-				$append = 1;
375
+			if($file_info['size'] > $byte_limit*512 or $start_byte) {
376
+							$append = 1;
377
+			}
361 378
 						
362
-			if(!isset($return['extra']['backup_size']))
363
-				$return['extra']['backup_size'] =0;
379
+			if(!isset($return['extra']['backup_size'])) {
380
+							$return['extra']['backup_size'] =0;
381
+			}
364 382
 			
365 383
 			$return['extra']['backup_size'] = $archive_info->getSize();
366 384
 			
@@ -396,8 +414,7 @@  discard block
 block discarded – undo
396 414
 			
397 415
 			if($last_position>0){	
398 416
 				$start_byte = $last_position;
399
-			}
400
-			else{	
417
+			} else{	
401 418
 				$extra_params['start_at_line']++;
402 419
 				$file->next();
403 420
 				$start_byte = 0;
@@ -434,8 +451,9 @@  discard block
 block discarded – undo
434 451
 		$this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", $this->get_archive_name_with_extension()));
435 452
 		$this->backup_archive->close();
436 453
 				
437
-		if($return['extra']['backup_part'])
438
-			$this->write_multipart_file($this->get_archive_name_with_extension());
454
+		if($return['extra']['backup_part']) {
455
+					$this->write_multipart_file($this->get_archive_name_with_extension());
456
+		}
439 457
 		
440 458
 		$return['extra']['start_at_line'] = $extra_params['start_at_line']-1;
441 459
 		
@@ -487,12 +505,13 @@  discard block
 block discarded – undo
487 505
 			$this->set_archive_name($this->get_archive_name(), ++$part);
488 506
 			$this->rename_archive($old_name, $this->get_archive_name_with_extension());
489 507
 			
490
-			if($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart()))
491
-				$this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart());
508
+			if($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) {
509
+							$this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart());
510
+			}
492 511
 				
493 512
 			$this->write_multipart_file($this->get_archive_name_with_extension());
494 513
 			
495
-		}else
514
+		} else
496 515
 		{
497 516
 			$this->logger->info(sprintf("Creating new multipart info file %s",$this->get_archive_name_with_extension()));
498 517
 			$this->write_multipart_file($this->get_archive_name_with_extension());
@@ -522,13 +541,15 @@  discard block
 block discarded – undo
522 541
 		$start_adapter = $this->filesystem->get_adapter($filesystem);
523 542
 		$start_filesystem = $this->filesystem->get_adapter($filesystem);
524 543
 		
525
-		if(!$file_info['path'])
526
-			return;
544
+		if(!$file_info['path']) {
545
+					return;
546
+		}
527 547
 		
528
-		if(isset($file_info['archive_prefix_path']))	
529
-			$file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path'];
530
-		else
531
-			$file_info['target_path'] = $file_info['path'];
548
+		if(isset($file_info['archive_prefix_path'])) {
549
+					$file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path'];
550
+		} else {
551
+					$file_info['target_path'] = $file_info['path'];
552
+		}
532 553
 			
533 554
 		$last_position = $start_at_byte;
534 555
 		
@@ -538,8 +559,7 @@  discard block
 block discarded – undo
538 559
 			$bytes_wrote = $file_info['size'];
539 560
 			$this->logger->info(sprintf("Adding %s bytes of file %s to archive %s ", $bytes_wrote, $file_info['target_path'], $this->get_archive_name_with_extension()));
540 561
 			$this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path']);
541
-		}
542
-		else{	
562
+		} else{	
543 563
 			$tmp_file = md5($file_info['path']);
544 564
 			
545 565
 			//we isolate file to tmp if we are at byte 0, the starting point of file reading
@@ -548,16 +568,16 @@  discard block
 block discarded – undo
548 568
 				$this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes", $file_info['path'], $tmp_file));
549 569
 				$file_stream = $start_filesystem->readStream($file_info['path']);
550 570
 				
551
-				if(is_resource($file_stream['stream']))
552
-					$this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']);
571
+				if(is_resource($file_stream['stream'])) {
572
+									$this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']);
573
+				}
553 574
 			}
554 575
 			
555 576
 			if($this->filesystem->get_tmp_filesystem()->has($tmp_file))
556 577
 			{
557 578
 				$is_tmp = 1;
558 579
 				$last_position = $this->backup_archive->appendFileData($this->filesystem->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_file), $file_info['target_path'], $start_at_byte, $byte_limit);
559
-			}
560
-			else{
580
+			} else{
561 581
 				$is_tmp = 0;
562 582
 				$last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path'], $start_at_byte, $byte_limit);
563 583
 			}
@@ -566,8 +586,7 @@  discard block
 block discarded – undo
566 586
 			if($last_position == -1)
567 587
 			{
568 588
 				$bytes_wrote = $file_info['size'] - $start_at_byte;
569
-			}
570
-			else
589
+			} else
571 590
 			{
572 591
 				$bytes_wrote = $last_position - $start_at_byte;
573 592
 			}
@@ -576,8 +595,7 @@  discard block
 block discarded – undo
576 595
 			if($is_tmp)
577 596
 			{
578 597
 				$this->logger->info(sprintf("Appended %s bytes, starting position %s, of tmp file %s (%s) to archive %s ", $bytes_wrote, $start_at_byte, $tmp_file, $file_info['target_path'], $this->get_archive_name()));
579
-			}
580
-			else{
598
+			} else{
581 599
 				$this->logger->info(sprintf("Appended %s bytes, starting position %s, of original file %s to archive %s ", $bytes_wrote, $start_at_byte, $file_info['target_path'], $tmp_file, $this->get_archive_name()));
582 600
 			}
583 601
 			
Please login to merge, or discard this patch.
includes/class-xcloner-database.php 4 patches
Doc Comments   +5 added lines patch added patch discarded remove patch
@@ -469,6 +469,11 @@
 block discarded – undo
469 469
 	 * 		handler $fd - file handler where to write the records
470 470
 	 * @return
471 471
 	 */
472
+
473
+	/**
474
+	 * @param integer $start
475
+	 * @param integer $limit
476
+	 */
472 477
 	public function export_table($databaseName, $tableName, $start, $limit, $dumpfile)
473 478
 	{
474 479
 		$this->logger->debug(sprintf(("Exporting table  %s.%s data"), $databaseName, $tableName));
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 					$this->log(sprintf(__("Excluding table %s.%s from backup"), $table, $database));
280 280
 				}
281 281
 			$inc++;
282
-        }
282
+		}
283 283
 
284 284
 		return $tablesList;
285 285
 
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 					$buffer = "";
504 504
 					$this->countRecords++;
505 505
 
506
-	                foreach ($arr as $key => $value) {
506
+					foreach ($arr as $key => $value) {
507 507
 						$value = $this->_real_escape($value);
508 508
 						$buffer .= "'".$value."', ";
509 509
 					}
@@ -529,8 +529,8 @@  discard block
 block discarded – undo
529 529
 		$line = ("\n#\n# Table structure for table `$tableName`\n#\n\n");
530 530
 		$this->fs->get_tmp_filesystem_append()->write($dumpfile, $line);
531 531
 
532
-        if ($this->dbDropSyntax)
533
-        {
532
+		if ($this->dbDropSyntax)
533
+		{
534 534
 			$line = ("\nDROP table IF EXISTS `$tableName`;\n");
535 535
 			$this->fs->get_tmp_filesystem_append()->write($dumpfile, $line);
536 536
 		}
Please login to merge, or discard this patch.
Spacing   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -21,12 +21,12 @@  discard block
 block discarded – undo
21 21
  */
22 22
 
23 23
 
24
-class Xcloner_Database extends wpdb{
24
+class Xcloner_Database extends wpdb {
25 25
 
26 26
 
27
-	public  $debug 						= 0;
28
-	public  $recordsPerSession			= 10000;
29
-	public  $dbCompatibility			= "";
27
+	public  $debug = 0;
28
+	public  $recordsPerSession = 10000;
29
+	public  $dbCompatibility = "";
30 30
 	public  $dbDropSyntax				= 1;
31 31
 	public  $countRecords				= 0;
32 32
 
@@ -38,24 +38,24 @@  discard block
 block discarded – undo
38 38
 	private   $TEMP_DBPROCESS_FILE = ".database";
39 39
 	private   $TEMP_DUMP_FILE = "database-backup.sql";
40 40
 	
41
-	public function __construct(Xcloner $xcloner_container, $wp_user="", $wp_pass="", $wp_db="", $wp_host="")
41
+	public function __construct(Xcloner $xcloner_container, $wp_user = "", $wp_pass = "", $wp_db = "", $wp_host = "")
42 42
 	{
43
-		$this->logger 					= $xcloner_container->get_xcloner_logger()->withName("xcloner_database");
44
-		$this->xcloner_settings 		= $xcloner_container->get_xcloner_settings();
45
-		$this->fs 						= $xcloner_container->get_xcloner_filesystem();
43
+		$this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_database");
44
+		$this->xcloner_settings = $xcloner_container->get_xcloner_settings();
45
+		$this->fs = $xcloner_container->get_xcloner_filesystem();
46 46
 		
47
-		if($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'))
48
-			$this->recordsPerSession		= $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
47
+		if ($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'))
48
+			$this->recordsPerSession = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
49 49
 		
50
-		if(!$this->recordsPerSession)
50
+		if (!$this->recordsPerSession)
51 51
 			$this->recordsPerSession = 100;
52 52
 		
53
-		if(!$wp_user && !$wp_pass && !$wp_host && !$wp_db )
53
+		if (!$wp_user && !$wp_pass && !$wp_host && !$wp_db)
54 54
 		{
55 55
 			$wp_host 	= $this->xcloner_settings->get_db_hostname();
56 56
 			$wp_user 	= $this->xcloner_settings->get_db_username();
57 57
 			$wp_pass 	= $this->xcloner_settings->get_db_password();
58
-			$wp_db 		= $this->xcloner_settings->get_db_database();
58
+			$wp_db = $this->xcloner_settings->get_db_database();
59 59
 		}
60 60
 		
61 61
 		parent::__construct($wp_user, $wp_pass, $wp_db, $wp_host);
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 */
72 72
 	public function init($data, $start = 0)
73 73
 	{
74
-		if($start and $this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)){
74
+		if ($start and $this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) {
75 75
 				$this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE);
76 76
 		}
77 77
 		
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 				"database_count"=>0,
91 91
 		);
92 92
 		
93
-		if(!$this->xcloner_settings->get_enable_mysql_backup())
93
+		if (!$this->xcloner_settings->get_enable_mysql_backup())
94 94
 		{
95 95
 			$return['finished'] = 1;
96 96
 			return $return;
@@ -100,44 +100,44 @@  discard block
 block discarded – undo
100 100
 		
101 101
 		$this->init($params, $init);
102 102
 		
103
-		if($init)
103
+		if ($init)
104 104
 		{
105 105
 			$db_count = 0;
106 106
 			
107
-			if(isset($params['#']))
107
+			if (isset($params['#']))
108 108
 			{
109
-				foreach($params['#'] as $database)
109
+				foreach ($params['#'] as $database)
110 110
 				{
111
-					if(!isset($params[$database]) or !is_array($params[$database]))
111
+					if (!isset($params[$database]) or !is_array($params[$database]))
112 112
 						$params[$database] = array();
113 113
 				}
114 114
 				$db_count = -1;
115 115
 			}
116 116
 			
117
-			if(isset($params) and is_array($params))
118
-				foreach($params as $database=>$tables)
117
+			if (isset($params) and is_array($params))
118
+				foreach ($params as $database=>$tables)
119 119
 				{	
120
-					if($database != "#")
120
+					if ($database != "#")
121 121
 					{
122 122
 						$stats = $this->write_backup_process_list($database, $tables);	
123
-						$return['stats']['tables_count'] 	+= $stats['tables_count'];
124
-						$return['stats']['total_records'] 	+= $stats['total_records'];
123
+						$return['stats']['tables_count'] += $stats['tables_count'];
124
+						$return['stats']['total_records'] += $stats['total_records'];
125 125
 					}
126 126
 				}
127 127
 
128
-			if(sizeof($params))
129
-				$return['stats']['database_count'] = sizeof($params)+$db_count;
128
+			if (sizeof($params))
129
+				$return['stats']['database_count'] = sizeof($params) + $db_count;
130 130
 			else	
131 131
 				$return['stats']['database_count'] = 0;
132 132
 				
133 133
 			return $return;
134 134
 		}
135 135
 		
136
-		if(!isset($extra_params['startAtLine']))
136
+		if (!isset($extra_params['startAtLine']))
137 137
 			$extra_params['startAtLine'] = 0;
138
-		if(!isset($extra_params['startAtRecord']))
138
+		if (!isset($extra_params['startAtRecord']))
139 139
 			$extra_params['startAtRecord'] = 0;
140
-		if(!isset($extra_params['dumpfile']))
140
+		if (!isset($extra_params['dumpfile']))
141 141
 			$extra_params['dumpfile'] = "";
142 142
 		
143 143
 		$return = $this->process_incremental($extra_params['startAtLine'], $extra_params['startAtRecord'], $extra_params['dumpfile']);
@@ -148,13 +148,13 @@  discard block
 block discarded – undo
148 148
 	public function log($message = "")
149 149
 	{
150 150
 		
151
-		if($message){
152
-			$this->logger->info( $message, array(""));
153
-		}else{	
154
-			if($this->last_query)
155
-				$this->logger->debug( $this->last_query, array(""));
156
-			if($this->last_error)
157
-				$this->logger->error( $this->last_error, array(""));
151
+		if ($message) {
152
+			$this->logger->info($message, array(""));
153
+		} else {	
154
+			if ($this->last_query)
155
+				$this->logger->debug($this->last_query, array(""));
156
+			if ($this->last_error)
157
+				$this->logger->error($this->last_error, array(""));
158 158
 		}
159 159
 		
160 160
 		return;
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 	*/
170 170
 	public function error($message)
171 171
 	{
172
-		$this->logger->error( $message, array(""));
172
+		$this->logger->error($message, array(""));
173 173
 		
174 174
 		return;
175 175
 	}
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 		
203 203
 		$query = "show tables in `".$database."`";
204 204
 		
205
-		$res =  $this->get_results($query);
205
+		$res = $this->get_results($query);
206 206
 		$this->log();
207 207
 			
208 208
 		return count($res);
@@ -225,9 +225,9 @@  discard block
 block discarded – undo
225 225
 		$databases_list[$i]['num_tables'] = $this->get_database_num_tables($this->dbname);
226 226
 		$i++;
227 227
 		
228
-		if(is_array($databases))
229
-		foreach( $databases as $db){
230
-			if($db->Database != $this->dbname)
228
+		if (is_array($databases))
229
+		foreach ($databases as $db) {
230
+			if ($db->Database != $this->dbname)
231 231
 			{
232 232
 				$databases_list[$i]['name'] = $db->Database;
233 233
 				$databases_list[$i]['num_tables'] = $this->get_database_num_tables($db->Database);
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 		$tablesList[0] = array( );
253 253
 		$inc = 0;
254 254
 
255
-		if(!$database)
255
+		if (!$database)
256 256
 			$database = $this->dbname;
257 257
 		
258 258
 		$this->logger->debug(sprintf(("Listing tables in %s database"), $database));
@@ -260,14 +260,14 @@  discard block
 block discarded – undo
260 260
 		$tables = $this->get_results("SHOW TABLES in `".$database."`");
261 261
 		$this->log();
262 262
 
263
-		foreach ($tables as $table){
263
+		foreach ($tables as $table) {
264 264
 			
265 265
 			$table = array_values((array)$table)[0];
266 266
 			
267 267
 			$tablesList[$inc]['name'] = $table;
268 268
 			$tablesList[$inc]['database'] = $database;
269 269
 
270
-			if($get_num_records)
270
+			if ($get_num_records)
271 271
 			{
272 272
 				$records_num_result = $this->get_var("SELECT count(*) FROM `".$database."`.`".$table."`");
273 273
 				$this->log();
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
 			
278 278
 			$tablesList[$inc]['excluded'] = 0;
279 279
 						
280
-			if(sizeof($included) and is_array($included))
281
-				if(!in_array($table, $included) )
280
+			if (sizeof($included) and is_array($included))
281
+				if (!in_array($table, $included))
282 282
 				{
283 283
 					$tablesList[$inc]['excluded'] = 1;
284 284
 					$this->log(sprintf(__("Excluding table %s.%s from backup"), $table, $database));
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 		
300 300
 		$tables = $this->list_tables($dbname, $incl_tables, 1);
301 301
 		
302
-		if($this->dbname != $dbname)
302
+		if ($this->dbname != $dbname)
303 303
 			$dumpfile = $dbname."-backup.sql";
304 304
 		else
305 305
 			$dumpfile = $this->TEMP_DUMP_FILE;
@@ -308,8 +308,8 @@  discard block
 block discarded – undo
308 308
 		$this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line);
309 309
 			
310 310
 		// write this to the class and write to $TEMP_DBPROCESS_FILE file as database.table records
311
-		foreach($tables as $key=>$table) 
312
-		if($table!= "" and !$tables[$key]['excluded']){
311
+		foreach ($tables as $key=>$table) 
312
+		if ($table != "" and !$tables[$key]['excluded']) {
313 313
 
314 314
 			$line = sprintf("`%s`.`%s`\t%s\t%s\n", $dbname, $tables[$key]['name'], $tables[$key]['records'], $tables[$key]['excluded']);
315 315
 			$this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line);
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 
338 338
 			$result = $this->get_var("SELECT count(*) FROM $table;");
339 339
 
340
-			return intval($result) ;// not max limit on 32 bit systems 2147483647; on 64 bit 999999999999
340
+			return intval($result); // not max limit on 32 bit systems 2147483647; on 64 bit 999999999999
341 341
 
342 342
 	}
343 343
 
@@ -353,25 +353,25 @@  discard block
 block discarded – undo
353 353
 	 * 		int $dbDropSyntax	- check if the DROP TABLE syntax should be added
354 354
 	 * @return array $return
355 355
 	 */
356
-	public function process_incremental($startAtLine= 0, $startAtRecord = 0, $dumpfile = "", $dbCompatibility= ""){
356
+	public function process_incremental($startAtLine = 0, $startAtRecord = 0, $dumpfile = "", $dbCompatibility = "") {
357 357
 
358 358
 		$count = 0;
359 359
 		$return['finished'] = 0;
360 360
 		$lines = array();
361 361
 		
362
-		if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE))
363
-			$lines = array_filter(explode("\n",$this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE)));
362
+		if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE))
363
+			$lines = array_filter(explode("\n", $this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE)));
364 364
 	
365
-		foreach ($lines as $buffer){
365
+		foreach ($lines as $buffer) {
366 366
 			
367
-			if($count == $startAtLine)
367
+			if ($count == $startAtLine)
368 368
 			{
369 369
 	
370
-				$tableInfo =explode("\t", $buffer);
370
+				$tableInfo = explode("\t", $buffer);
371 371
 				
372
-				if($tableInfo[0] == "###newdump###"){
372
+				if ($tableInfo[0] == "###newdump###") {
373 373
 						// we create a new mysql dump file
374
-						if($dumpfile != ""){
374
+						if ($dumpfile != "") {
375 375
 								// we finished a previous one and write the footers
376 376
 								$return['dumpsize'] = $this->data_footers($dumpfile);
377 377
 						}
@@ -385,13 +385,13 @@  discard block
 block discarded – undo
385 385
 						$startAtLine++;
386 386
 						$return['new_dump'] = 1;
387 387
 						//break;
388
-				}else{
388
+				} else {
389 389
 						//we export the table
390
-						if($tableInfo[0] == "###enddump###")
390
+						if ($tableInfo[0] == "###enddump###")
391 391
 							$return['endDump'] = 1;
392 392
 	
393 393
 						//table is excluded
394
-						if($tableInfo[2])
394
+						if ($tableInfo[2])
395 395
 							continue;
396 396
 							
397 397
 						$next = $startAtRecord + $this->recordsPerSession;
@@ -403,28 +403,28 @@  discard block
 block discarded – undo
403 403
 
404 404
 						//return something to the browser
405 405
 						$return['databaseName'] 	= $databaseName;
406
-						$return['tableName'] 		= $tableName;
406
+						$return['tableName'] = $tableName;
407 407
 						$return['totalRecords'] 	= $tableInfo[1];
408 408
 
409 409
 						$processed_records = 0;
410 410
 						
411
-						if(trim($tableName) !=""  and !$tableInfo[2])
411
+						if (trim($tableName) != "" and !$tableInfo[2])
412 412
 							$processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile);
413 413
 						
414
-						$return['processedRecords'] = $startAtRecord+$processed_records;
414
+						$return['processedRecords'] = $startAtRecord + $processed_records;
415 415
 						
416
-						if($next >= $tableInfo[1]) //we finished loading the records for next sessions, will go to the new record
416
+						if ($next >= $tableInfo[1]) //we finished loading the records for next sessions, will go to the new record
417 417
 						{
418
-								$startAtLine ++;
418
+								$startAtLine++;
419 419
 								$startAtRecord = 0;
420
-						}else{
420
+						} else {
421 421
 								$startAtRecord = $startAtRecord + $this->recordsPerSession;
422 422
 							}
423 423
 
424 424
 						//$return['dbCompatibility'] 	= self::$dbCompatibility;
425 425
 						
426
-						$return['startAtLine']		= $startAtLine;
427
-						$return['startAtRecord']	= $startAtRecord;
426
+						$return['startAtLine'] = $startAtLine;
427
+						$return['startAtRecord'] = $startAtRecord;
428 428
 						$return['dumpfile']			= $dumpfile;
429 429
 						$return['dumpsize']			= $this->fs->get_tmp_filesystem_append()->getSize($dumpfile);
430 430
 
@@ -442,15 +442,15 @@  discard block
 block discarded – undo
442 442
 		}
443 443
 	
444 444
 		//while is finished, lets go home...
445
-		if($dumpfile != ""){
445
+		if ($dumpfile != "") {
446 446
 			// we finished a previous one and write the footers
447 447
 			$return['dumpsize'] = $this->data_footers($dumpfile);
448 448
 			$return['dumpfile'] = ($dumpfile);
449 449
 		}
450 450
 		$return['finished'] = 1;
451
-		$return['startAtLine']	= $startAtLine;
451
+		$return['startAtLine'] = $startAtLine;
452 452
 		
453
-		if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE))
453
+		if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE))
454 454
 			$this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE);
455 455
 		
456 456
 		$this->logger->debug(sprintf(("Database backup finished!")));
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
 		
480 480
 		$records = 0;
481 481
 		
482
-		if($start == 0)
482
+		if ($start == 0)
483 483
 			$this->dump_structure($databaseName, $tableName, $dumpfile);
484 484
 
485 485
 		$start = intval($start);
@@ -487,20 +487,20 @@  discard block
 block discarded – undo
487 487
 		//exporting the table content now
488 488
 
489 489
 		$query = "SELECT * from `$databaseName`.`$tableName` Limit $start, $limit ;";
490
-		if($this->use_mysqli)
490
+		if ($this->use_mysqli)
491 491
 		{
492 492
 			$result = mysqli_query($this->dbh, $query);
493 493
 			$mysql_fetch_function = "mysqli_fetch_array";
494 494
 		
495
-		}else{
495
+		} else {
496 496
 			$result = mysql_query($query, $this->dbh);
497 497
 			$mysql_fetch_function = "mysql_fetch_array";
498 498
 		}
499 499
 		//$result = $this->get_results($query, ARRAY_N);
500 500
 		//print_r($result); exit;
501 501
 		
502
-		if($result){
503
-			while($row = $mysql_fetch_function($result, MYSQLI_ASSOC)){
502
+		if ($result) {
503
+			while ($row = $mysql_fetch_function($result, MYSQLI_ASSOC)) {
504 504
 					
505 505
 					$this->fs->get_tmp_filesystem_append()->write($dumpfile, "INSERT INTO `$tableName` VALUES (");
506 506
 					$arr = $row;
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 						$value = $this->_real_escape($value);
512 512
 						$buffer .= "'".$value."', ";
513 513
 					}
514
-					$buffer = rtrim($buffer, ', ') . ");\n";
514
+					$buffer = rtrim($buffer, ', ').");\n";
515 515
 					$this->fs->get_tmp_filesystem_append()->write($dumpfile, $buffer);
516 516
 					unset($buffer);
517 517
 					
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
 
527 527
 	}
528 528
 
529
-	public function dump_structure($databaseName, $tableName ,$dumpfile)
529
+	public function dump_structure($databaseName, $tableName, $dumpfile)
530 530
 	{
531 531
 		$this->log(sprintf(__("Dumping the structure for %s.%s table"), $databaseName, $tableName));
532 532
 		
@@ -541,14 +541,14 @@  discard block
 block discarded – undo
541 541
 
542 542
 		//$result = mysqli_query($this->dbh,"SHOW CREATE table `$databaseName`.`$tableName`;");
543 543
 		$result = $this->get_row("SHOW CREATE table `$databaseName`.`$tableName`;", ARRAY_N);
544
-		if($result){
544
+		if ($result) {
545 545
 			//$row = mysqli_fetch_row( $result);
546 546
 			$line = ($result[1].";\n");
547 547
 			$this->fs->get_tmp_filesystem_append()->write($dumpfile, $line);
548 548
 		}
549 549
 
550
-		$line = ( "\n#\n# End Structure for table `$tableName`\n#\n\n");
551
-		$line .=("#\n# Dumping data for table `$tableName`\n#\n\n");
550
+		$line = ("\n#\n# End Structure for table `$tableName`\n#\n\n");
551
+		$line .= ("#\n# Dumping data for table `$tableName`\n#\n\n");
552 552
 		$this->fs->get_tmp_filesystem_append()->write($dumpfile, $line);
553 553
 		
554 554
 		return;
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
 
572 572
 	}
573 573
 
574
-	public function resetcountRecords(){
574
+	public function resetcountRecords() {
575 575
 		
576 576
 		$this->countRecords = 0;
577 577
 
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
 	
580 580
 	}
581 581
 
582
-	public function getcountRecords(){
582
+	public function getcountRecords() {
583 583
 		
584 584
 		return $this->countRecords;
585 585
 		
@@ -596,14 +596,14 @@  discard block
 block discarded – undo
596 596
 		$return .= "# Powered by XCloner Site Backup\n";
597 597
 		$return .= "# http://www.xcloner.com\n";
598 598
 		$return .= "#\n";
599
-		$return .= "# Host: " . get_site_url() . "\n";
600
-		$return .= "# Generation Time: " . date("M j, Y \a\\t H:i") . "\n";
601
-		$return .= "# PHP Version: " . phpversion() . "\n";
602
-		$return .= "# Database Charset: ". $this->charset . "\n";
599
+		$return .= "# Host: ".get_site_url()."\n";
600
+		$return .= "# Generation Time: ".date("M j, Y \a\\t H:i")."\n";
601
+		$return .= "# PHP Version: ".phpversion()."\n";
602
+		$return .= "# Database Charset: ".$this->charset."\n";
603 603
 		
604 604
 		$results = $this->get_results("SHOW VARIABLES LIKE \"%version%\";", ARRAY_N);
605
-		if(isset($results)){
606
-			foreach($results as $result){
605
+		if (isset($results)) {
606
+			foreach ($results as $result) {
607 607
 
608 608
 					$return .= "# MYSQL ".$result[0].": ".$result[1]."\n";
609 609
 
@@ -613,13 +613,13 @@  discard block
 block discarded – undo
613 613
 		$results = $this->get_results("SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME
614 614
 					FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '".$database."';");
615 615
 		
616
-		if(isset($results[0])){
616
+		if (isset($results[0])) {
617 617
 
618 618
 			$return .= "# MYSQL DEFAULT_CHARACTER_SET_NAME: ".$results[0]->DEFAULT_CHARACTER_SET_NAME."\n";
619 619
 			$return .= "# MYSQL SCHEMA_NAME: ".$results[0]->DEFAULT_COLLATION_NAME."\n";
620 620
 		}
621 621
 
622
-		$return .= "#\n# Database : `" . $database . "`\n# --------------------------------------------------------\n\n";
622
+		$return .= "#\n# Database : `".$database."`\n# --------------------------------------------------------\n\n";
623 623
 		
624 624
 		$this->log(sprintf(__("Writing %s database dump headers"), $database));
625 625
 		
Please login to merge, or discard this patch.
Braces   +75 added lines, -52 removed lines patch added patch discarded remove patch
@@ -44,11 +44,13 @@  discard block
 block discarded – undo
44 44
 		$this->xcloner_settings 		= $xcloner_container->get_xcloner_settings();
45 45
 		$this->fs 						= $xcloner_container->get_xcloner_filesystem();
46 46
 		
47
-		if($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'))
48
-			$this->recordsPerSession		= $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
47
+		if($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request')) {
48
+					$this->recordsPerSession		= $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
49
+		}
49 50
 		
50
-		if(!$this->recordsPerSession)
51
-			$this->recordsPerSession = 100;
51
+		if(!$this->recordsPerSession) {
52
+					$this->recordsPerSession = 100;
53
+		}
52 54
 		
53 55
 		if(!$wp_user && !$wp_pass && !$wp_host && !$wp_db )
54 56
 		{
@@ -108,37 +110,43 @@  discard block
 block discarded – undo
108 110
 			{
109 111
 				foreach($params['#'] as $database)
110 112
 				{
111
-					if(!isset($params[$database]) or !is_array($params[$database]))
112
-						$params[$database] = array();
113
+					if(!isset($params[$database]) or !is_array($params[$database])) {
114
+											$params[$database] = array();
115
+					}
113 116
 				}
114 117
 				$db_count = -1;
115 118
 			}
116 119
 			
117
-			if(isset($params) and is_array($params))
118
-				foreach($params as $database=>$tables)
120
+			if(isset($params) and is_array($params)) {
121
+							foreach($params as $database=>$tables)
119 122
 				{	
120 123
 					if($database != "#")
121 124
 					{
122
-						$stats = $this->write_backup_process_list($database, $tables);	
125
+						$stats = $this->write_backup_process_list($database, $tables);
126
+			}
123 127
 						$return['stats']['tables_count'] 	+= $stats['tables_count'];
124 128
 						$return['stats']['total_records'] 	+= $stats['total_records'];
125 129
 					}
126 130
 				}
127 131
 
128
-			if(sizeof($params))
129
-				$return['stats']['database_count'] = sizeof($params)+$db_count;
130
-			else	
131
-				$return['stats']['database_count'] = 0;
132
+			if(sizeof($params)) {
133
+							$return['stats']['database_count'] = sizeof($params)+$db_count;
134
+			} else {
135
+							$return['stats']['database_count'] = 0;
136
+			}
132 137
 				
133 138
 			return $return;
134 139
 		}
135 140
 		
136
-		if(!isset($extra_params['startAtLine']))
137
-			$extra_params['startAtLine'] = 0;
138
-		if(!isset($extra_params['startAtRecord']))
139
-			$extra_params['startAtRecord'] = 0;
140
-		if(!isset($extra_params['dumpfile']))
141
-			$extra_params['dumpfile'] = "";
141
+		if(!isset($extra_params['startAtLine'])) {
142
+					$extra_params['startAtLine'] = 0;
143
+		}
144
+		if(!isset($extra_params['startAtRecord'])) {
145
+					$extra_params['startAtRecord'] = 0;
146
+		}
147
+		if(!isset($extra_params['dumpfile'])) {
148
+					$extra_params['dumpfile'] = "";
149
+		}
142 150
 		
143 151
 		$return = $this->process_incremental($extra_params['startAtLine'], $extra_params['startAtRecord'], $extra_params['dumpfile']);
144 152
 		
@@ -150,11 +158,13 @@  discard block
 block discarded – undo
150 158
 		
151 159
 		if($message){
152 160
 			$this->logger->info( $message, array(""));
153
-		}else{	
154
-			if($this->last_query)
155
-				$this->logger->debug( $this->last_query, array(""));
156
-			if($this->last_error)
157
-				$this->logger->error( $this->last_error, array(""));
161
+		} else{	
162
+			if($this->last_query) {
163
+							$this->logger->debug( $this->last_query, array(""));
164
+			}
165
+			if($this->last_error) {
166
+							$this->logger->error( $this->last_error, array(""));
167
+			}
158 168
 		}
159 169
 		
160 170
 		return;
@@ -225,11 +235,12 @@  discard block
 block discarded – undo
225 235
 		$databases_list[$i]['num_tables'] = $this->get_database_num_tables($this->dbname);
226 236
 		$i++;
227 237
 		
228
-		if(is_array($databases))
229
-		foreach( $databases as $db){
238
+		if(is_array($databases)) {
239
+				foreach( $databases as $db){
230 240
 			if($db->Database != $this->dbname)
231 241
 			{
232 242
 				$databases_list[$i]['name'] = $db->Database;
243
+		}
233 244
 				$databases_list[$i]['num_tables'] = $this->get_database_num_tables($db->Database);
234 245
 				$i++;
235 246
 			}
@@ -252,8 +263,9 @@  discard block
 block discarded – undo
252 263
 		$tablesList[0] = array( );
253 264
 		$inc = 0;
254 265
 
255
-		if(!$database)
256
-			$database = $this->dbname;
266
+		if(!$database) {
267
+					$database = $this->dbname;
268
+		}
257 269
 		
258 270
 		$this->logger->debug(sprintf(("Listing tables in %s database"), $database));
259 271
 		
@@ -277,10 +289,11 @@  discard block
 block discarded – undo
277 289
 			
278 290
 			$tablesList[$inc]['excluded'] = 0;
279 291
 						
280
-			if(sizeof($included) and is_array($included))
281
-				if(!in_array($table, $included) )
292
+			if(sizeof($included) and is_array($included)) {
293
+							if(!in_array($table, $included) )
282 294
 				{
283 295
 					$tablesList[$inc]['excluded'] = 1;
296
+			}
284 297
 					$this->log(sprintf(__("Excluding table %s.%s from backup"), $table, $database));
285 298
 				}
286 299
 			$inc++;
@@ -299,19 +312,21 @@  discard block
 block discarded – undo
299 312
 		
300 313
 		$tables = $this->list_tables($dbname, $incl_tables, 1);
301 314
 		
302
-		if($this->dbname != $dbname)
303
-			$dumpfile = $dbname."-backup.sql";
304
-		else
305
-			$dumpfile = $this->TEMP_DUMP_FILE;
315
+		if($this->dbname != $dbname) {
316
+					$dumpfile = $dbname."-backup.sql";
317
+		} else {
318
+					$dumpfile = $this->TEMP_DUMP_FILE;
319
+		}
306 320
 		
307 321
 		$line = sprintf("###newdump###\t%s\t%s\n", $dbname, $dumpfile);
308 322
 		$this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line);
309 323
 			
310 324
 		// write this to the class and write to $TEMP_DBPROCESS_FILE file as database.table records
311
-		foreach($tables as $key=>$table) 
312
-		if($table!= "" and !$tables[$key]['excluded']){
325
+		foreach($tables as $key=>$table) {
326
+				if($table!= "" and !$tables[$key]['excluded']){
313 327
 
314 328
 			$line = sprintf("`%s`.`%s`\t%s\t%s\n", $dbname, $tables[$key]['name'], $tables[$key]['records'], $tables[$key]['excluded']);
329
+		}
315 330
 			$this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line);
316 331
 			$return['tables_count']++;
317 332
 			$return['total_records'] += $tables[$key]['records'];
@@ -359,8 +374,9 @@  discard block
 block discarded – undo
359 374
 		$return['finished'] = 0;
360 375
 		$lines = array();
361 376
 		
362
-		if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE))
363
-			$lines = array_filter(explode("\n",$this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE)));
377
+		if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) {
378
+					$lines = array_filter(explode("\n",$this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE)));
379
+		}
364 380
 	
365 381
 		foreach ($lines as $buffer){
366 382
 			
@@ -385,14 +401,16 @@  discard block
 block discarded – undo
385 401
 						$startAtLine++;
386 402
 						$return['new_dump'] = 1;
387 403
 						//break;
388
-				}else{
404
+				} else{
389 405
 						//we export the table
390
-						if($tableInfo[0] == "###enddump###")
391
-							$return['endDump'] = 1;
406
+						if($tableInfo[0] == "###enddump###") {
407
+													$return['endDump'] = 1;
408
+						}
392 409
 	
393 410
 						//table is excluded
394
-						if($tableInfo[2])
395
-							continue;
411
+						if($tableInfo[2]) {
412
+													continue;
413
+						}
396 414
 							
397 415
 						$next = $startAtRecord + $this->recordsPerSession;
398 416
 						
@@ -408,16 +426,19 @@  discard block
 block discarded – undo
408 426
 
409 427
 						$processed_records = 0;
410 428
 						
411
-						if(trim($tableName) !=""  and !$tableInfo[2])
412
-							$processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile);
429
+						if(trim($tableName) !=""  and !$tableInfo[2]) {
430
+													$processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile);
431
+						}
413 432
 						
414 433
 						$return['processedRecords'] = $startAtRecord+$processed_records;
415 434
 						
416
-						if($next >= $tableInfo[1]) //we finished loading the records for next sessions, will go to the new record
435
+						if($next >= $tableInfo[1]) {
436
+							//we finished loading the records for next sessions, will go to the new record
417 437
 						{
418 438
 								$startAtLine ++;
439
+						}
419 440
 								$startAtRecord = 0;
420
-						}else{
441
+						} else{
421 442
 								$startAtRecord = $startAtRecord + $this->recordsPerSession;
422 443
 							}
423 444
 
@@ -450,8 +471,9 @@  discard block
 block discarded – undo
450 471
 		$return['finished'] = 1;
451 472
 		$return['startAtLine']	= $startAtLine;
452 473
 		
453
-		if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE))
454
-			$this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE);
474
+		if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) {
475
+					$this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE);
476
+		}
455 477
 		
456 478
 		$this->logger->debug(sprintf(("Database backup finished!")));
457 479
 		
@@ -479,8 +501,9 @@  discard block
 block discarded – undo
479 501
 		
480 502
 		$records = 0;
481 503
 		
482
-		if($start == 0)
483
-			$this->dump_structure($databaseName, $tableName, $dumpfile);
504
+		if($start == 0) {
505
+					$this->dump_structure($databaseName, $tableName, $dumpfile);
506
+		}
484 507
 
485 508
 		$start = intval($start);
486 509
 		$limit = intval($limit);
@@ -492,7 +515,7 @@  discard block
 block discarded – undo
492 515
 			$result = mysqli_query($this->dbh, $query);
493 516
 			$mysql_fetch_function = "mysqli_fetch_array";
494 517
 		
495
-		}else{
518
+		} else{
496 519
 			$result = mysql_query($query, $this->dbh);
497 520
 			$mysql_fetch_function = "mysql_fetch_array";
498 521
 		}
Please login to merge, or discard this patch.
includes/class-xcloner-file-system.php 5 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 use League\Flysystem\Config;
3 3
 use League\Flysystem\Filesystem;
4
-use League\Flysystem\Util;
5 4
 use League\Flysystem\Adapter\Local;
6 5
 
7 6
 class Xcloner_File_System{
Please login to merge, or discard this patch.
Doc Comments   +12 added lines patch added patch discarded remove patch
@@ -122,6 +122,9 @@  discard block
 block discarded – undo
122 122
 		return $this->start_filesystem->normalizeFileInfo($info);
123 123
 	}
124 124
 	
125
+	/**
126
+	 * @param string $file
127
+	 */
125 128
 	public function get_storage_path_file_info($file)
126 129
 	{
127 130
 		return $this->getMetadataFull('storage_adapter', $file);
@@ -188,6 +191,9 @@  discard block
 block discarded – undo
188 191
 		return $total;		
189 192
 	}
190 193
 	
194
+	/**
195
+	 * @param string $backup_name
196
+	 */
191 197
 	public function is_part($backup_name)
192 198
 	{
193 199
 		if(stristr($backup_name, "-part"))
@@ -578,6 +584,9 @@  discard block
 block discarded – undo
578 584
 		
579 585
 	}
580 586
 	
587
+	/**
588
+	 * @param string $tmp_file
589
+	 */
581 590
 	public function estimate_reading_time($tmp_file)
582 591
 	{
583 592
 		$this->logger->debug(sprintf(("Estimating file system reading time")));
@@ -616,6 +625,9 @@  discard block
 block discarded – undo
616 625
 		return $name;	
617 626
 	}
618 627
 	
628
+	/**
629
+	 * @param string $field
630
+	 */
619 631
 	public function sort_by( &$array, $field, $direction = 'asc')
620 632
 	{
621 633
 		if(strtolower($direction) == "desc" || $direction == SORT_DESC)
Please login to merge, or discard this patch.
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -299,12 +299,12 @@  discard block
 block discarded – undo
299 299
 	}
300 300
 	
301 301
 	public function getMetadataFull($adapter = "storage_adapter" , $path)
302
-    {
303
-        $location = $this->$adapter->applyPathPrefix($path);
304
-        $spl_info = new SplFileInfo($location);
302
+	{
303
+		$location = $this->$adapter->applyPathPrefix($path);
304
+		$spl_info = new SplFileInfo($location);
305 305
         
306
-        return ($spl_info);
307
-    }
306
+		return ($spl_info);
307
+	}
308 308
 	
309 309
 	
310 310
 	public function get_backup_archives_list($storage_selection = "")
@@ -697,27 +697,27 @@  discard block
 block discarded – undo
697 697
 	
698 698
 	private function array_orderby()
699 699
 	{
700
-	    $args = func_get_args();
701
-	    $data = array_shift($args);
700
+		$args = func_get_args();
701
+		$data = array_shift($args);
702 702
 	    
703
-	    foreach ($args as $n => $field) {
704
-	        if (is_string($field)) {
705
-	            $tmp = array();
706
-	            foreach ($data as $key => $row)
707
-	            {
703
+		foreach ($args as $n => $field) {
704
+			if (is_string($field)) {
705
+				$tmp = array();
706
+				foreach ($data as $key => $row)
707
+				{
708 708
 					if(is_array($row))
709 709
 						$tmp[$key] = $row[$field];
710 710
 					else
711 711
 						$tmp[$key] = $row->$field;
712 712
 				}
713
-	            $args[$n] = $tmp;
714
-	            }
715
-	    }
716
-	    $args[] = &$data;
713
+				$args[$n] = $tmp;
714
+				}
715
+		}
716
+		$args[] = &$data;
717 717
 	    
718
-	    call_user_func_array('array_multisort', $args);
718
+		call_user_func_array('array_multisort', $args);
719 719
 	    
720
-	    return array_pop($args);
720
+		return array_pop($args);
721 721
 	}
722 722
 	
723 723
 	private function check_file_diff_time($file)
Please login to merge, or discard this patch.
Spacing   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -4,18 +4,18 @@  discard block
 block discarded – undo
4 4
 use League\Flysystem\Util;
5 5
 use League\Flysystem\Adapter\Local;
6 6
 
7
-class Xcloner_File_System{
7
+class Xcloner_File_System {
8 8
 	
9
-	private $excluded_files 			= "";
10
-	private $excluded_files_by_default	= array("administrator/backups", "wp-content/backups");
11
-	private $included_files_handler 	= "backup_files.csv";
12
-	private $temp_dir_handler 			= ".dir";
9
+	private $excluded_files = "";
10
+	private $excluded_files_by_default = array("administrator/backups", "wp-content/backups");
11
+	private $included_files_handler = "backup_files.csv";
12
+	private $temp_dir_handler = ".dir";
13 13
 	public  $filesystem;
14 14
 	public  $tmp_filesystem;
15 15
 	public  $storage_filesystem;
16 16
 	private $xcloner_settings_append;
17 17
 	private $xcloner_container;
18
-	private $diff_timestamp_start		= "";
18
+	private $diff_timestamp_start = "";
19 19
 	
20 20
 	private $logger;
21 21
 	private $start_adapter;
@@ -38,47 +38,47 @@  discard block
 block discarded – undo
38 38
 	{
39 39
 		$this->xcloner_container = $xcloner_container;
40 40
 		
41
-		$this->logger 				= $xcloner_container->get_xcloner_logger()->withName("xcloner_file_system");
41
+		$this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_file_system");
42 42
 		$this->xcloner_settings 	= $xcloner_container->get_xcloner_settings();
43 43
 
44
-		try{
44
+		try {
45 45
 			
46
-			$this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(),LOCK_EX, 'SKIP_LINKS');
46
+			$this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS');
47 47
 			$this->start_filesystem = new Filesystem($this->start_adapter, new Config([
48 48
 					'disable_asserts' => true,
49 49
 				]));
50 50
 			
51
-			$this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX, 'SKIP_LINKS');
51
+			$this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS');
52 52
 			$this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([
53 53
 					'disable_asserts' => true,
54 54
 				]));
55
-			$adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX|FILE_APPEND, 'SKIP_LINKS');
55
+			$adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
56 56
 			$this->tmp_filesystem_append = new Filesystem($adapter, new Config([
57 57
 					'disable_asserts' => true,
58 58
 				]));
59 59
 
60
-			$adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),LOCK_EX, 'SKIP_LINKS');
60
+			$adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS');
61 61
 			$this->storage_filesystem = new Filesystem($adapter, new Config([
62 62
 					'disable_asserts' => true,
63 63
 				]));	
64 64
 			
65
-			$this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),FILE_APPEND, 'SKIP_LINKS');
65
+			$this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND, 'SKIP_LINKS');
66 66
 			$this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([
67 67
 					'disable_asserts' => true,
68 68
 				]));
69
-		}catch(Exception $e){
69
+		}catch (Exception $e) {
70 70
 			$this->logger->error("Filesystem Initialization Error: ".$e->getMessage());
71 71
 		}
72 72
 		
73 73
 		
74
-		if($value = get_option('xcloner_directories_to_scan_per_request'))
74
+		if ($value = get_option('xcloner_directories_to_scan_per_request'))
75 75
 			$this->folders_to_process_per_session = $value;
76 76
 
77 77
 	}
78 78
 	
79 79
 	public function set_diff_timestamp_start($timestamp = "")
80 80
 	{
81
-		if($timestamp)
81
+		if ($timestamp)
82 82
 		{
83 83
 			$this->logger->info(sprintf("Setting Differential Timestamp To %s", date("Y-m-d", $timestamp)), array("FILESYSTEM", "DIFF"));
84 84
 			$this->diff_timestamp_start = $timestamp;
@@ -113,12 +113,12 @@  discard block
 block discarded – undo
113 113
 	
114 114
 	public function get_storage_filesystem($remote_storage_selection = "")
115 115
 	{
116
-		if($remote_storage_selection != "")
116
+		if ($remote_storage_selection != "")
117 117
 		{
118 118
 			$remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
119 119
 			$method = "get_".$remote_storage_selection."_filesystem";
120 120
 			
121
-			if(!method_exists($remote_storage, $method))
121
+			if (!method_exists($remote_storage, $method))
122 122
 				return false;
123 123
 				
124 124
 			list($adapter, $filesystem) = $remote_storage->$method();	
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 	
157 157
 	public function get_start_path_file_info($file)
158 158
 	{
159
-		$info= $this->getMetadataFull('start_adapter', $file);
159
+		$info = $this->getMetadataFull('start_adapter', $file);
160 160
 		return $this->start_filesystem->normalizeFileInfo($info);
161 161
 	}
162 162
 	
@@ -165,10 +165,10 @@  discard block
 block discarded – undo
165 165
 		return $this->getMetadataFull('storage_adapter', $file);
166 166
 	}
167 167
 	
168
-	public function get_included_files_handler($metadata  = 0)
168
+	public function get_included_files_handler($metadata = 0)
169 169
 	{
170 170
 		$path = $this->included_files_handler;
171
-		if(!$metadata)
171
+		if (!$metadata)
172 172
 			return $path;
173 173
 		
174 174
 		$spl_info = $this->getMetadataFull('tmp_adapter', $path);
@@ -185,16 +185,16 @@  discard block
 block discarded – undo
185 185
 	{
186 186
 		$files = $this->get_backup_archives_list();
187 187
 		
188
-		if(is_array($files))
189
-			$this->sort_by($files, "timestamp","desc");
188
+		if (is_array($files))
189
+			$this->sort_by($files, "timestamp", "desc");
190 190
 		
191 191
 		$new_list = array();
192 192
 		
193
-		foreach($files as $key=>$file)
194
-			if(!isset($file['parent']))
193
+		foreach ($files as $key=>$file)
194
+			if (!isset($file['parent']))
195 195
 				$new_list[] = ($files[$key]);
196 196
 
197
-		if(isset($new_list[0]))
197
+		if (isset($new_list[0]))
198 198
 			return $new_list[0];
199 199
 	}
200 200
 	
@@ -202,13 +202,13 @@  discard block
 block discarded – undo
202 202
 	{
203 203
 		$files = $this->get_backup_archives_list();
204 204
 
205
-		if(is_array($files))
206
-			$this->sort_by($files, "timestamp","desc");
205
+		if (is_array($files))
206
+			$this->sort_by($files, "timestamp", "desc");
207 207
 		
208 208
 		$new_list = array();
209 209
 		
210
-		foreach($files as $key=>$file)
211
-			if(!isset($file['parent']))
210
+		foreach ($files as $key=>$file)
211
+			if (!isset($file['parent']))
212 212
 				$new_list[] = ($files[$key]);
213 213
 
214 214
 		return $new_list;
@@ -219,8 +219,8 @@  discard block
 block discarded – undo
219 219
 		$files = $this->get_backup_archives_list();
220 220
 		$total = 0;
221 221
 		
222
-		if(is_array($files))
223
-			foreach($files as $file)
222
+		if (is_array($files))
223
+			foreach ($files as $file)
224 224
 				$total += $file['size'];
225 225
 				
226 226
 		return $total;		
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 	
229 229
 	public function is_part($backup_name)
230 230
 	{
231
-		if(stristr($backup_name, "-part"))
231
+		if (stristr($backup_name, "-part"))
232 232
 			return true;
233 233
 		
234 234
 		return false;	
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 	
237 237
 	public function is_multipart($backup_name)
238 238
 	{
239
-		if(stristr($backup_name, "-multipart"))
239
+		if (stristr($backup_name, "-multipart"))
240 240
 			return true;
241 241
 		
242 242
 		return false;	
@@ -245,10 +245,10 @@  discard block
 block discarded – undo
245 245
 	public function get_backup_size($backup_name)
246 246
 	{
247 247
 		$backup_size = $this->get_storage_filesystem()->getSize($backup_name);
248
-		if($this->is_multipart($backup_name))
248
+		if ($this->is_multipart($backup_name))
249 249
 		{
250 250
 			$backup_parts = $this->get_multipart_files($backup_name);
251
-			foreach($backup_parts as $part_file)
251
+			foreach ($backup_parts as $part_file)
252 252
 				$backup_size += $this->get_storage_filesystem()->getSize($part_file);
253 253
 		}
254 254
 		
@@ -259,12 +259,12 @@  discard block
 block discarded – undo
259 259
 	{
260 260
 		$files = array();
261 261
 		
262
-		if($this->is_multipart($backup_name))
262
+		if ($this->is_multipart($backup_name))
263 263
 		{
264 264
 			$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
265
-			foreach($lines as $line)
265
+			foreach ($lines as $line)
266 266
 			{
267
-				if($line)
267
+				if ($line)
268 268
 				{
269 269
 					$data = str_getcsv($line);
270 270
 					$files[] = $data[0];
@@ -277,12 +277,12 @@  discard block
 block discarded – undo
277 277
 	
278 278
 	public function delete_backup_by_name($backup_name, $storage_selection = "")
279 279
 	{
280
-		if($this->is_multipart($backup_name))
280
+		if ($this->is_multipart($backup_name))
281 281
 		{
282 282
 			$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
283
-			foreach($lines as $line)
283
+			foreach ($lines as $line)
284 284
 			{
285
-				if($line)
285
+				if ($line)
286 286
 				{
287 287
 					$data = str_getcsv($line);
288 288
 					$this->get_storage_filesystem($storage_selection)->delete($data[0]);
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 			}
291 291
 		}
292 292
 		
293
-		if($this->get_storage_filesystem($storage_selection)->delete($backup_name))
293
+		if ($this->get_storage_filesystem($storage_selection)->delete($backup_name))
294 294
 			$return = true;
295 295
 		else
296 296
 			$return = false;
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 		return $return;	
299 299
 	}
300 300
 	
301
-	public function getMetadataFull($adapter = "storage_adapter" , $path)
301
+	public function getMetadataFull($adapter = "storage_adapter", $path)
302 302
     {
303 303
         $location = $this->$adapter->applyPathPrefix($path);
304 304
         $spl_info = new SplFileInfo($location);
@@ -312,25 +312,25 @@  discard block
 block discarded – undo
312 312
 		$list = array();
313 313
 		
314 314
 
315
-		if(method_exists($this->get_storage_filesystem($storage_selection), "listContents"))
315
+		if (method_exists($this->get_storage_filesystem($storage_selection), "listContents"))
316 316
 			$list = $this->get_storage_filesystem($storage_selection)->listContents();
317 317
 
318 318
 		
319 319
 		$backup_files = array();
320 320
 		$parents = array();
321 321
 		
322
-		foreach($list as $file_info)
322
+		foreach ($list as $file_info)
323 323
 		{
324
-			if(isset($file_info['extension']) and $file_info['extension'] == "csv")
324
+			if (isset($file_info['extension']) and $file_info['extension'] == "csv")
325 325
 			{
326 326
 				$data = array();
327 327
 				
328 328
 				$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path']));
329
-				foreach($lines as $line)
330
-					if($line)
329
+				foreach ($lines as $line)
330
+					if ($line)
331 331
 					{
332 332
 						$data = str_getcsv($line);
333
-						if(is_array($data)){
333
+						if (is_array($data)) {
334 334
 							$parents[$data[0]] = $file_info['basename'];
335 335
 							$file_info['childs'][] = $data;
336 336
 							$file_info['size'] += $data[2];
@@ -339,18 +339,18 @@  discard block
 block discarded – undo
339 339
 						
340 340
 			}
341 341
 			
342
-			if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions))
342
+			if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions))
343 343
 				$backup_files[$file_info['path']] = $file_info;
344 344
 		}
345 345
 		
346
-		foreach($backup_files as $key=>$file_info)
346
+		foreach ($backup_files as $key=>$file_info)
347 347
 		{
348
-			if(!isset($backup_files[$key]['timestamp']))
348
+			if (!isset($backup_files[$key]['timestamp']))
349 349
 			{
350 350
 				//$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']);
351 351
 			}
352 352
 			
353
-			if(isset($parents[$file_info['basename']]))
353
+			if (isset($parents[$file_info['basename']]))
354 354
 				$backup_files[$key]['parent'] = $parents[$file_info['basename']];
355 355
 		}
356 356
 		
@@ -359,40 +359,40 @@  discard block
 block discarded – undo
359 359
 	
360 360
 	public function start_file_recursion($init = 0)
361 361
 	{
362
-		if($init)
362
+		if ($init)
363 363
 		{
364 364
 			$this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"), $this->xcloner_settings->get_xcloner_start_path()));
365 365
 			$this->do_system_init();
366 366
 		}
367 367
 		
368
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler())){
368
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
369 369
 		//.dir exists, we presume we have files to iterate	
370 370
 			$content = $this->tmp_filesystem->read($this->get_temp_dir_handler());
371 371
 			$files = array_filter(explode("\n", $content));
372 372
 			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
373 373
 			
374 374
 			$counter = 0;
375
-			foreach($files as $file)
375
+			foreach ($files as $file)
376 376
 			{
377
-				if($counter < $this->folders_to_process_per_session){
377
+				if ($counter < $this->folders_to_process_per_session) {
378 378
 					$this->build_files_list($file);
379 379
 					$counter++;
380
-				}else{
380
+				} else {
381 381
 					$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n");
382 382
 				}
383 383
 			}
384
-		}else{
384
+		} else {
385 385
 			$this->build_files_list();
386 386
 		}
387 387
 		
388
-		if($this->scan_finished())
388
+		if ($this->scan_finished())
389 389
 		{
390 390
 			$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html");
391 391
 			$this->store_file($metadata_dumpfile, 'tmp_filesystem');
392 392
 			$this->files_counter++;
393 393
 		
394 394
 			//adding included dump file to the included files list
395
-			if($this->get_tmp_filesystem()->has($this->get_included_files_handler()))
395
+			if ($this->get_tmp_filesystem()->has($this->get_included_files_handler()))
396 396
 			{
397 397
 				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler());
398 398
 				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
@@ -400,13 +400,13 @@  discard block
 block discarded – undo
400 400
 			}
401 401
 		
402 402
 			//adding a default index.html to the temp xcloner folder
403
-			if(!$this->get_tmp_filesystem()->has("index.html"))
403
+			if (!$this->get_tmp_filesystem()->has("index.html"))
404 404
 			{
405
-				$this->get_tmp_filesystem()->write("index.html","");
405
+				$this->get_tmp_filesystem()->write("index.html", "");
406 406
 			}
407 407
 			
408 408
 			//adding the default log file
409
-			if($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1)))
409
+			if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1)))
410 410
 			{
411 411
 				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1));
412 412
 				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
 	{
424 424
 		$return = array();
425 425
 		$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler();
426
-		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log'))
426
+		if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log'))
427 427
 			$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
428 428
 		
429 429
 		return $return;
@@ -436,8 +436,8 @@  discard block
 block discarded – undo
436 436
 		
437 437
 		$contents = $this->get_tmp_filesystem()->listContents();
438 438
 	
439
-		if(is_array($contents))
440
-		foreach($contents as $file_info)
439
+		if (is_array($contents))
440
+		foreach ($contents as $file_info)
441 441
 			$this->get_tmp_filesystem()->delete($file_info['path']);
442 442
 			
443 443
 		@rmdir($this->xcloner_settings->get_xcloner_tmp_path());
@@ -447,16 +447,16 @@  discard block
 block discarded – undo
447 447
 	
448 448
 	public function cleanup_tmp_directories()
449 449
 	{
450
-		$adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false),LOCK_EX|FILE_APPEND, 'SKIP_LINKS');
450
+		$adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
451 451
 		$tmp_filesystem = new Filesystem($adapter, new Config([
452 452
 					'disable_asserts' => true,
453 453
 				]));
454 454
 				
455 455
 		$contents = $tmp_filesystem->listContents();
456 456
 		
457
-		foreach($contents as $file)
457
+		foreach ($contents as $file)
458 458
 		{
459
-			if(preg_match("/.xcloner-(.*)/",$file['path']))
459
+			if (preg_match("/.xcloner-(.*)/", $file['path']))
460 460
 			{
461 461
 				$tmp_filesystem->deleteDir($file['path']);
462 462
 				$this->logger->info(sprintf("Delete temporary directory %s", $file['path']));
@@ -470,16 +470,16 @@  discard block
 block discarded – undo
470 470
 	{
471 471
 		$this->files_counter = 0;
472 472
 		
473
-		if(!$this->storage_filesystem->has("index.html"))	
474
-			$this->storage_filesystem->write("index.html","");
473
+		if (!$this->storage_filesystem->has("index.html"))	
474
+			$this->storage_filesystem->write("index.html", "");
475 475
 		
476
-		if(!$this->tmp_filesystem->has("index.html"))	
477
-			$this->tmp_filesystem->write("index.html","");
476
+		if (!$this->tmp_filesystem->has("index.html"))	
477
+			$this->tmp_filesystem->write("index.html", "");
478 478
 			
479
-		if($this->tmp_filesystem->has($this->get_included_files_handler()))
479
+		if ($this->tmp_filesystem->has($this->get_included_files_handler()))
480 480
 			$this->tmp_filesystem->delete($this->get_included_files_handler());
481 481
 		
482
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler()))	
482
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler()))	
483 483
 			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
484 484
 	}
485 485
 	
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 	
501 501
 	public function set_excluded_files($excluded_files = array())
502 502
 	{
503
-		if(!is_array($excluded_files))
503
+		if (!is_array($excluded_files))
504 504
 			$excluded_files = array();
505 505
 			
506 506
 		$this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
@@ -523,35 +523,35 @@  discard block
 block discarded – undo
523 523
 		$this->logger->debug(sprintf(("Building the files system list")));
524 524
 		
525 525
 		//if we start with the root folder(empty value), we initializa the file system
526
-		if(!$folder){
526
+		if (!$folder) {
527 527
 			
528 528
 		}
529 529
 			
530
-		try{
530
+		try {
531 531
 			
532 532
 			$files = $this->start_filesystem->listContents($folder);
533
-			foreach($files as $file)
533
+			foreach ($files as $file)
534 534
 			{
535
-				if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path']))
535
+				if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path']))
536 536
 				{
537
-					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE"));
537
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN", "NOT READABLE"));
538 538
 				}
539
-				elseif(!$matching_pattern = $this->is_excluded($file) ){
540
-					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE"));
539
+				elseif (!$matching_pattern = $this->is_excluded($file)) {
540
+					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN", "INCLUDE"));
541 541
 					$file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
542
-					if($this->store_file($file))
542
+					if ($this->store_file($file))
543 543
 					{
544 544
 						$this->files_counter++;
545 545
 					}
546
-					if(isset($file['size']))
546
+					if (isset($file['size']))
547 547
 						$this->files_size += $file['size'];
548 548
 					
549
-				}else{
550
-					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE"));
549
+				} else {
550
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN", "EXCLUDE"));
551 551
 					}
552 552
 			}
553 553
 			
554
-		}catch(Exception $e){
554
+		}catch (Exception $e) {
555 555
 			
556 556
 			$this->logger->error($e->getMessage());
557 557
 		
@@ -565,9 +565,9 @@  discard block
 block discarded – undo
565 565
 				
566 566
 		$start_time = microtime();
567 567
 		
568
-		$data = str_repeat(rand(0,9), 1024*1024); //write 1MB data
568
+		$data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data
569 569
 		
570
-		try{
570
+		try {
571 571
 			$this->tmp_filesystem->write($tmp_file, $data);
572 572
 			
573 573
 			$end_time = microtime() - $start_time;
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
 		
579 579
 			$this->tmp_filesystem->delete($tmp_file);
580 580
 		
581
-		}catch(Exception $e){
581
+		}catch (Exception $e) {
582 582
 			
583 583
 			$this->logger->error($e->getMessage());
584 584
 			
@@ -599,10 +599,10 @@  discard block
 block discarded – undo
599 599
 		
600 600
 		$files = $this->storage_filesystem->listContents();
601 601
 		
602
-		if(is_array($files))
603
-			foreach($files as $file)
602
+		if (is_array($files))
603
+			foreach ($files as $file)
604 604
 			{
605
-				if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions))
605
+				if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions))
606 606
 				{
607 607
 					$_storage_size += $file['size']; //bytes
608 608
 					$_backup_files_list[] = $file;
@@ -610,15 +610,15 @@  discard block
 block discarded – undo
610 610
 			}
611 611
 		
612 612
 		
613
-		$this->sort_by($_backup_files_list, "timestamp","asc");
613
+		$this->sort_by($_backup_files_list, "timestamp", "asc");
614 614
 		
615 615
 		$_backups_counter = sizeof($_backup_files_list);
616 616
 				
617
-		foreach($_backup_files_list as $file)
617
+		foreach ($_backup_files_list as $file)
618 618
 		{
619 619
 			//processing rule folder capacity
620
-			if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
621
-			$_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))	//bytes	
620
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
621
+			$_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))	//bytes	
622 622
 			{
623 623
 				$this->storage_filesystem->delete($file['path']);
624 624
 				$_storage_size -= $file['size'];
@@ -626,14 +626,14 @@  discard block
 block discarded – undo
626 626
 			}
627 627
 			
628 628
 			//processing rule days limit
629
-			if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp'])
629
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp'])
630 630
 			{
631 631
 				$this->storage_filesystem->delete($file['path']);
632 632
 				$this->logger->info("Deleting backup ".$file['path']." matching rule", array("RETENTION LIMIT TIMESTAMP", $file['timestamp']." =< ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')));
633 633
 			}
634 634
 			
635 635
 			//processing backup countert limit
636
-			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'))
636
+			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'))
637 637
 			{
638 638
 				$this->storage_filesystem->delete($file['path']);
639 639
 				$_backups_counter--;
@@ -659,33 +659,33 @@  discard block
 block discarded – undo
659 659
 	
660 660
 	}
661 661
 	
662
-	public function process_backup_name($name = "", $max_length=100)
662
+	public function process_backup_name($name = "", $max_length = 100)
663 663
 	{
664
-		if(!$name)
664
+		if (!$name)
665 665
 			$name = $this->xcloner_settings->get_default_backup_name();
666 666
 		
667
-		foreach($this->backup_name_tags as $tag)
667
+		foreach ($this->backup_name_tags as $tag)
668 668
 		{
669
-			if($tag == '[time]')
670
-				$name = str_replace($tag, date("Y-m-d_H-i"),$name);
671
-			elseif($tag == '[hostname]')
672
-				$name = str_replace($tag, gethostname() ,$name);	
673
-			elseif($tag == '[domain]')
669
+			if ($tag == '[time]')
670
+				$name = str_replace($tag, date("Y-m-d_H-i"), $name);
671
+			elseif ($tag == '[hostname]')
672
+				$name = str_replace($tag, gethostname(), $name);	
673
+			elseif ($tag == '[domain]')
674 674
 			{
675 675
 				$domain = parse_url(admin_url(), PHP_URL_HOST);
676
-				$name = str_replace($tag, $domain ,$name);	
676
+				$name = str_replace($tag, $domain, $name);	
677 677
 			}
678 678
 		}
679 679
 		
680
-		if($max_length)
680
+		if ($max_length)
681 681
 			$name = substr($name, 0, $max_length);
682 682
 			
683 683
 		return $name;	
684 684
 	}
685 685
 	
686
-	public function sort_by( &$array, $field, $direction = 'asc')
686
+	public function sort_by(&$array, $field, $direction = 'asc')
687 687
 	{
688
-		if(strtolower($direction) == "desc" || $direction == SORT_DESC)
688
+		if (strtolower($direction) == "desc" || $direction == SORT_DESC)
689 689
 			$direction = SORT_DESC;
690 690
 		else
691 691
 			$direction = SORT_ASC;
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
 	            $tmp = array();
706 706
 	            foreach ($data as $key => $row)
707 707
 	            {
708
-					if(is_array($row))
708
+					if (is_array($row))
709 709
 						$tmp[$key] = $row[$field];
710 710
 					else
711 711
 						$tmp[$key] = $row->$field;
@@ -722,18 +722,18 @@  discard block
 block discarded – undo
722 722
 	
723 723
 	private function check_file_diff_time($file)
724 724
 	{
725
-		if($this->get_diff_timestamp_start() != "")
725
+		if ($this->get_diff_timestamp_start() != "")
726 726
 		{
727 727
 			$fileMeta = $this->getMetadataFull("start_adapter", $file['path']);
728 728
 			$timestamp = $fileMeta->getMTime();
729
-			if($timestamp < $fileMeta->getCTime())
729
+			if ($timestamp < $fileMeta->getCTime())
730 730
 			{
731 731
 				$timestamp = $fileMeta->getCTime();
732 732
 			}
733 733
 			
734
-			if($timestamp <= $this->get_diff_timestamp_start())
734
+			if ($timestamp <= $this->get_diff_timestamp_start())
735 735
 			{
736
-				return  " file DIFF timestamp ".$timestamp." < ". $this->diff_timestamp_start;
736
+				return  " file DIFF timestamp ".$timestamp." < ".$this->diff_timestamp_start;
737 737
 			}
738 738
 		}
739 739
 		
@@ -744,35 +744,35 @@  discard block
 block discarded – undo
744 744
 	{
745 745
 		$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
746 746
 		
747
-		if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb'))
747
+		if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb'))
748 748
 		{
749
-			if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb))
749
+			if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb))
750 750
 				return "> ".$xcloner_exclude_files_larger_than_mb."MB";
751 751
 		}
752 752
 		
753
-		if(!sizeof($this->excluded_files))
753
+		if (!sizeof($this->excluded_files))
754 754
 			$this->set_excluded_files();
755 755
 				
756
-		if(is_array($this->excluded_files))
757
-		foreach($this->excluded_files as $excluded_file_pattern)
756
+		if (is_array($this->excluded_files))
757
+		foreach ($this->excluded_files as $excluded_file_pattern)
758 758
 		{
759
-			if($excluded_file_pattern == "/")
759
+			if ($excluded_file_pattern == "/")
760 760
 				$needle = "$";
761 761
 			else
762 762
 				$needle = "$".$excluded_file_pattern;
763 763
 				
764
-			if(strstr("$".$file['path'], $needle)){
764
+			if (strstr("$".$file['path'], $needle)) {
765 765
 				return $excluded_file_pattern;
766 766
 			}
767 767
 		}
768 768
 		
769
-		if( $regex = $this->is_excluded_regex($file))
769
+		if ($regex = $this->is_excluded_regex($file))
770 770
 			return $regex;
771 771
 		
772
-		if($file['type'] == "file")
772
+		if ($file['type'] == "file")
773 773
 		{
774 774
 			$check_file_diff_timestamp = $this->check_file_diff_time($file);
775
-			if($check_file_diff_timestamp)
775
+			if ($check_file_diff_timestamp)
776 776
 			{
777 777
 				return $check_file_diff_timestamp;
778 778
 			}
@@ -821,25 +821,25 @@  discard block
 block discarded – undo
821 821
 		
822 822
 		//print_r($regex_patterns);exit;
823 823
 		
824
-		if(is_array($regex_patterns))
824
+		if (is_array($regex_patterns))
825 825
 		{
826 826
 			//$this->excluded_files = array();
827 827
 			//$this->excluded_files[] ="(.*)\.(git)(.*)$";
828 828
 			//$this->excluded_files[] ="wp-content\/backups(.*)$";
829 829
 			
830
-			foreach($regex_patterns as $excluded_file_pattern)
830
+			foreach ($regex_patterns as $excluded_file_pattern)
831 831
 			{
832 832
 				
833
-				if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r")
834
-					$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1);
833
+				if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1, strlen($excluded_file_pattern)) == "\r")
834
+					$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1);
835 835
 					
836
-				if($file['path'] == "/")
836
+				if ($file['path'] == "/")
837 837
 					$needle = "/";
838 838
 				else
839 839
 					$needle = "/".$file['path'];
840 840
 				//echo $needle."---".$excluded_file_pattern."---\n";
841 841
 				
842
-				if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){
842
+				if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) {
843 843
 					return $excluded_file_pattern;
844 844
 				}
845 845
 			}
@@ -852,36 +852,36 @@  discard block
 block discarded – undo
852 852
 	{
853 853
 		$this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
854 854
 		
855
-		if(!isset($file['size']))
855
+		if (!isset($file['size']))
856 856
 			$file['size'] = 0;
857
-		if(!isset($file['visibility']))	
857
+		if (!isset($file['visibility']))	
858 858
 			$file['visibility'] = "private";
859 859
 		
860
-		$csv_filename = str_replace('"','""', $file['path']);
860
+		$csv_filename = str_replace('"', '""', $file['path']);
861 861
 		
862 862
 		$line = '"'.($csv_filename).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL;
863 863
 		
864 864
 		$this->last_logged_file = $file['path'];
865 865
 		
866
-		if($file['type'] == "dir"){
867
-			try{
866
+		if ($file['type'] == "dir") {
867
+			try {
868 868
 				$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n");
869
-			}catch(Exception $e){
869
+			}catch (Exception $e) {
870 870
 				$this->logger->error($e->getMessage());	
871 871
 			}
872 872
 		}
873 873
 		
874
-		if($this->get_diff_timestamp_start())
874
+		if ($this->get_diff_timestamp_start())
875 875
 		{
876
-			if($file['type'] != "file" && $response = $this->check_file_diff_time($file))
876
+			if ($file['type'] != "file" && $response = $this->check_file_diff_time($file))
877 877
 			{
878
-				$this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'], $response), array("FILESYSTEM SCAN","DIR DIFF"));
878
+				$this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'], $response), array("FILESYSTEM SCAN", "DIR DIFF"));
879 879
 				return false;
880 880
 			}
881 881
 		}
882 882
 		
883
-		try{
884
-			if(!$this->tmp_filesystem_append->has($this->get_included_files_handler()))
883
+		try {
884
+			if (!$this->tmp_filesystem_append->has($this->get_included_files_handler()))
885 885
 			{
886 886
 				//adding fix for UTF-8 CSV preview
887 887
 				$start_line = "\xEF\xBB\xBF".'"Filename","Timestamp","Size","Visibility","Storage"'.PHP_EOL;
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
 			
891 891
 			$this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
892 892
 		
893
-		}catch(Exception $e){
893
+		}catch (Exception $e) {
894 894
 		
895 895
 			$this->logger->error($e->getMessage());	
896 896
 		}
@@ -905,13 +905,13 @@  discard block
 block discarded – undo
905 905
 	
906 906
 	public function get_filesystem($system = "")
907 907
 	{
908
-		if($system == "storage_filesystem_append")
908
+		if ($system == "storage_filesystem_append")
909 909
 			return $this->storage_filesystem_append;
910
-		elseif($system == "tmp_filesystem_append")
910
+		elseif ($system == "tmp_filesystem_append")
911 911
 			return $this->tmp_filesystem_append;
912
-		elseif($system == "tmp_filesystem")
912
+		elseif ($system == "tmp_filesystem")
913 913
 			return $this->tmp_filesystem;
914
-		elseif($system == "storage_filesystem")
914
+		elseif ($system == "storage_filesystem")
915 915
 			return $this->storage_filesystem;
916 916
 		else
917 917
 			return $this->start_filesystem;	
@@ -919,9 +919,9 @@  discard block
 block discarded – undo
919 919
 	
920 920
 	public function get_adapter($system)
921 921
 	{
922
-		if($system == "tmp_filesystem")
922
+		if ($system == "tmp_filesystem")
923 923
 			return $this->tmp_adapter;
924
-		elseif($system == "storage_filesystem")
924
+		elseif ($system == "storage_filesystem")
925 925
 			return $this->storage_adapter;
926 926
 		else
927 927
 			return $this->start_adapter;	
@@ -929,10 +929,10 @@  discard block
 block discarded – undo
929 929
 	
930 930
 	private function scan_finished()
931 931
 	{
932
-		if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler()))
932
+		if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler()))
933 933
 			return false;
934 934
 		
935
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler()))
935
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler()))
936 936
 			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
937 937
 		
938 938
 		$this->logger->debug(sprintf(("File scan finished")));
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
 	
943 943
 	private function calc_to_bytes($mb_size)
944 944
 	{
945
-		return $mb_size*(1024*1024);
945
+		return $mb_size * (1024 * 1024);
946 946
 	}
947 947
 	
948 948
 }
Please login to merge, or discard this patch.
Braces   +167 added lines, -123 removed lines patch added patch discarded remove patch
@@ -66,13 +66,14 @@  discard block
 block discarded – undo
66 66
 			$this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([
67 67
 					'disable_asserts' => true,
68 68
 				]));
69
-		}catch(Exception $e){
69
+		} catch(Exception $e){
70 70
 			$this->logger->error("Filesystem Initialization Error: ".$e->getMessage());
71 71
 		}
72 72
 		
73 73
 		
74
-		if($value = get_option('xcloner_directories_to_scan_per_request'))
75
-			$this->folders_to_process_per_session = $value;
74
+		if($value = get_option('xcloner_directories_to_scan_per_request')) {
75
+					$this->folders_to_process_per_session = $value;
76
+		}
76 77
 
77 78
 	}
78 79
 	
@@ -118,8 +119,9 @@  discard block
 block discarded – undo
118 119
 			$remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
119 120
 			$method = "get_".$remote_storage_selection."_filesystem";
120 121
 			
121
-			if(!method_exists($remote_storage, $method))
122
-				return false;
122
+			if(!method_exists($remote_storage, $method)) {
123
+							return false;
124
+			}
123 125
 				
124 126
 			list($adapter, $filesystem) = $remote_storage->$method();	
125 127
 			
@@ -168,8 +170,9 @@  discard block
 block discarded – undo
168 170
 	public function get_included_files_handler($metadata  = 0)
169 171
 	{
170 172
 		$path = $this->included_files_handler;
171
-		if(!$metadata)
172
-			return $path;
173
+		if(!$metadata) {
174
+					return $path;
175
+		}
173 176
 		
174 177
 		$spl_info = $this->getMetadataFull('tmp_adapter', $path);
175 178
 		return $spl_info;
@@ -185,31 +188,36 @@  discard block
 block discarded – undo
185 188
 	{
186 189
 		$files = $this->get_backup_archives_list();
187 190
 		
188
-		if(is_array($files))
189
-			$this->sort_by($files, "timestamp","desc");
191
+		if(is_array($files)) {
192
+					$this->sort_by($files, "timestamp","desc");
193
+		}
190 194
 		
191 195
 		$new_list = array();
192 196
 		
193
-		foreach($files as $key=>$file)
194
-			if(!isset($file['parent']))
197
+		foreach($files as $key=>$file) {
198
+					if(!isset($file['parent']))
195 199
 				$new_list[] = ($files[$key]);
200
+		}
196 201
 
197
-		if(isset($new_list[0]))
198
-			return $new_list[0];
202
+		if(isset($new_list[0])) {
203
+					return $new_list[0];
204
+		}
199 205
 	}
200 206
 	
201 207
 	public function get_latest_backups()
202 208
 	{
203 209
 		$files = $this->get_backup_archives_list();
204 210
 
205
-		if(is_array($files))
206
-			$this->sort_by($files, "timestamp","desc");
211
+		if(is_array($files)) {
212
+					$this->sort_by($files, "timestamp","desc");
213
+		}
207 214
 		
208 215
 		$new_list = array();
209 216
 		
210
-		foreach($files as $key=>$file)
211
-			if(!isset($file['parent']))
217
+		foreach($files as $key=>$file) {
218
+					if(!isset($file['parent']))
212 219
 				$new_list[] = ($files[$key]);
220
+		}
213 221
 
214 222
 		return $new_list;
215 223
 	}
@@ -219,25 +227,28 @@  discard block
 block discarded – undo
219 227
 		$files = $this->get_backup_archives_list();
220 228
 		$total = 0;
221 229
 		
222
-		if(is_array($files))
223
-			foreach($files as $file)
230
+		if(is_array($files)) {
231
+					foreach($files as $file)
224 232
 				$total += $file['size'];
233
+		}
225 234
 				
226 235
 		return $total;		
227 236
 	}
228 237
 	
229 238
 	public function is_part($backup_name)
230 239
 	{
231
-		if(stristr($backup_name, "-part"))
232
-			return true;
240
+		if(stristr($backup_name, "-part")) {
241
+					return true;
242
+		}
233 243
 		
234 244
 		return false;	
235 245
 	}
236 246
 	
237 247
 	public function is_multipart($backup_name)
238 248
 	{
239
-		if(stristr($backup_name, "-multipart"))
240
-			return true;
249
+		if(stristr($backup_name, "-multipart")) {
250
+					return true;
251
+		}
241 252
 		
242 253
 		return false;	
243 254
 	}
@@ -248,8 +259,9 @@  discard block
 block discarded – undo
248 259
 		if($this->is_multipart($backup_name))
249 260
 		{
250 261
 			$backup_parts = $this->get_multipart_files($backup_name);
251
-			foreach($backup_parts as $part_file)
252
-				$backup_size += $this->get_storage_filesystem()->getSize($part_file);
262
+			foreach($backup_parts as $part_file) {
263
+							$backup_size += $this->get_storage_filesystem()->getSize($part_file);
264
+			}
253 265
 		}
254 266
 		
255 267
 		return $backup_size;
@@ -290,10 +302,11 @@  discard block
 block discarded – undo
290 302
 			}
291 303
 		}
292 304
 		
293
-		if($this->get_storage_filesystem($storage_selection)->delete($backup_name))
294
-			$return = true;
295
-		else
296
-			$return = false;
305
+		if($this->get_storage_filesystem($storage_selection)->delete($backup_name)) {
306
+					$return = true;
307
+		} else {
308
+					$return = false;
309
+		}
297 310
 			
298 311
 		return $return;	
299 312
 	}
@@ -312,8 +325,9 @@  discard block
 block discarded – undo
312 325
 		$list = array();
313 326
 		
314 327
 
315
-		if(method_exists($this->get_storage_filesystem($storage_selection), "listContents"))
316
-			$list = $this->get_storage_filesystem($storage_selection)->listContents();
328
+		if(method_exists($this->get_storage_filesystem($storage_selection), "listContents")) {
329
+					$list = $this->get_storage_filesystem($storage_selection)->listContents();
330
+		}
317 331
 
318 332
 		
319 333
 		$backup_files = array();
@@ -326,10 +340,11 @@  discard block
 block discarded – undo
326 340
 				$data = array();
327 341
 				
328 342
 				$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path']));
329
-				foreach($lines as $line)
330
-					if($line)
343
+				foreach($lines as $line) {
344
+									if($line)
331 345
 					{
332 346
 						$data = str_getcsv($line);
347
+				}
333 348
 						if(is_array($data)){
334 349
 							$parents[$data[0]] = $file_info['basename'];
335 350
 							$file_info['childs'][] = $data;
@@ -339,8 +354,9 @@  discard block
 block discarded – undo
339 354
 						
340 355
 			}
341 356
 			
342
-			if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions))
343
-				$backup_files[$file_info['path']] = $file_info;
357
+			if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) {
358
+							$backup_files[$file_info['path']] = $file_info;
359
+			}
344 360
 		}
345 361
 		
346 362
 		foreach($backup_files as $key=>$file_info)
@@ -350,8 +366,9 @@  discard block
 block discarded – undo
350 366
 				//$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']);
351 367
 			}
352 368
 			
353
-			if(isset($parents[$file_info['basename']]))
354
-				$backup_files[$key]['parent'] = $parents[$file_info['basename']];
369
+			if(isset($parents[$file_info['basename']])) {
370
+							$backup_files[$key]['parent'] = $parents[$file_info['basename']];
371
+			}
355 372
 		}
356 373
 		
357 374
 		return $backup_files;
@@ -377,11 +394,11 @@  discard block
 block discarded – undo
377 394
 				if($counter < $this->folders_to_process_per_session){
378 395
 					$this->build_files_list($file);
379 396
 					$counter++;
380
-				}else{
397
+				} else{
381 398
 					$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n");
382 399
 				}
383 400
 			}
384
-		}else{
401
+		} else{
385 402
 			$this->build_files_list();
386 403
 		}
387 404
 		
@@ -423,8 +440,9 @@  discard block
 block discarded – undo
423 440
 	{
424 441
 		$return = array();
425 442
 		$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler();
426
-		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log'))
427
-			$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
443
+		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
444
+					$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
445
+		}
428 446
 		
429 447
 		return $return;
430 448
 	}
@@ -436,9 +454,10 @@  discard block
 block discarded – undo
436 454
 		
437 455
 		$contents = $this->get_tmp_filesystem()->listContents();
438 456
 	
439
-		if(is_array($contents))
440
-		foreach($contents as $file_info)
457
+		if(is_array($contents)) {
458
+				foreach($contents as $file_info)
441 459
 			$this->get_tmp_filesystem()->delete($file_info['path']);
460
+		}
442 461
 			
443 462
 		@rmdir($this->xcloner_settings->get_xcloner_tmp_path());
444 463
 		
@@ -470,17 +489,21 @@  discard block
 block discarded – undo
470 489
 	{
471 490
 		$this->files_counter = 0;
472 491
 		
473
-		if(!$this->storage_filesystem->has("index.html"))	
474
-			$this->storage_filesystem->write("index.html","");
492
+		if(!$this->storage_filesystem->has("index.html")) {
493
+					$this->storage_filesystem->write("index.html","");
494
+		}
475 495
 		
476
-		if(!$this->tmp_filesystem->has("index.html"))	
477
-			$this->tmp_filesystem->write("index.html","");
496
+		if(!$this->tmp_filesystem->has("index.html")) {
497
+					$this->tmp_filesystem->write("index.html","");
498
+		}
478 499
 			
479
-		if($this->tmp_filesystem->has($this->get_included_files_handler()))
480
-			$this->tmp_filesystem->delete($this->get_included_files_handler());
500
+		if($this->tmp_filesystem->has($this->get_included_files_handler())) {
501
+					$this->tmp_filesystem->delete($this->get_included_files_handler());
502
+		}
481 503
 		
482
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler()))	
483
-			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
504
+		if($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
505
+					$this->tmp_filesystem->delete($this->get_temp_dir_handler());
506
+		}
484 507
 	}
485 508
 	
486 509
 	public function get_scanned_files_num()
@@ -500,8 +523,9 @@  discard block
 block discarded – undo
500 523
 	
501 524
 	public function set_excluded_files($excluded_files = array())
502 525
 	{
503
-		if(!is_array($excluded_files))
504
-			$excluded_files = array();
526
+		if(!is_array($excluded_files)) {
527
+					$excluded_files = array();
528
+		}
505 529
 			
506 530
 		$this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
507 531
 		
@@ -535,23 +559,23 @@  discard block
 block discarded – undo
535 559
 				if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path']))
536 560
 				{
537 561
 					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE"));
538
-				}
539
-				elseif(!$matching_pattern = $this->is_excluded($file) ){
562
+				} elseif(!$matching_pattern = $this->is_excluded($file) ){
540 563
 					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE"));
541 564
 					$file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
542 565
 					if($this->store_file($file))
543 566
 					{
544 567
 						$this->files_counter++;
545 568
 					}
546
-					if(isset($file['size']))
547
-						$this->files_size += $file['size'];
569
+					if(isset($file['size'])) {
570
+											$this->files_size += $file['size'];
571
+					}
548 572
 					
549
-				}else{
573
+				} else{
550 574
 					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE"));
551 575
 					}
552 576
 			}
553 577
 			
554
-		}catch(Exception $e){
578
+		} catch(Exception $e){
555 579
 			
556 580
 			$this->logger->error($e->getMessage());
557 581
 		
@@ -578,7 +602,7 @@  discard block
 block discarded – undo
578 602
 		
579 603
 			$this->tmp_filesystem->delete($tmp_file);
580 604
 		
581
-		}catch(Exception $e){
605
+		} catch(Exception $e){
582 606
 			
583 607
 			$this->logger->error($e->getMessage());
584 608
 			
@@ -599,12 +623,14 @@  discard block
 block discarded – undo
599 623
 		
600 624
 		$files = $this->storage_filesystem->listContents();
601 625
 		
602
-		if(is_array($files))
603
-			foreach($files as $file)
626
+		if(is_array($files)) {
627
+					foreach($files as $file)
604 628
 			{
605 629
 				if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions))
606 630
 				{
607
-					$_storage_size += $file['size']; //bytes
631
+					$_storage_size += $file['size'];
632
+		}
633
+		//bytes
608 634
 					$_backup_files_list[] = $file;
609 635
 				}
610 636
 			}
@@ -618,9 +644,11 @@  discard block
 block discarded – undo
618 644
 		{
619 645
 			//processing rule folder capacity
620 646
 			if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
621
-			$_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))	//bytes	
647
+			$_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) {
648
+				//bytes	
622 649
 			{
623 650
 				$this->storage_filesystem->delete($file['path']);
651
+			}
624 652
 				$_storage_size -= $file['size'];
625 653
 				$this->logger->info("Deleting backup ".$file['path']." matching rule", array("STORAGE SIZE LIMIT", $_storage_size." >= ".$set_storage_limit));
626 654
 			}
@@ -661,34 +689,37 @@  discard block
 block discarded – undo
661 689
 	
662 690
 	public function process_backup_name($name = "", $max_length=100)
663 691
 	{
664
-		if(!$name)
665
-			$name = $this->xcloner_settings->get_default_backup_name();
692
+		if(!$name) {
693
+					$name = $this->xcloner_settings->get_default_backup_name();
694
+		}
666 695
 		
667 696
 		foreach($this->backup_name_tags as $tag)
668 697
 		{
669
-			if($tag == '[time]')
670
-				$name = str_replace($tag, date("Y-m-d_H-i"),$name);
671
-			elseif($tag == '[hostname]')
672
-				$name = str_replace($tag, gethostname() ,$name);	
673
-			elseif($tag == '[domain]')
698
+			if($tag == '[time]') {
699
+							$name = str_replace($tag, date("Y-m-d_H-i"),$name);
700
+			} elseif($tag == '[hostname]') {
701
+							$name = str_replace($tag, gethostname() ,$name);
702
+			} elseif($tag == '[domain]')
674 703
 			{
675 704
 				$domain = parse_url(admin_url(), PHP_URL_HOST);
676 705
 				$name = str_replace($tag, $domain ,$name);	
677 706
 			}
678 707
 		}
679 708
 		
680
-		if($max_length)
681
-			$name = substr($name, 0, $max_length);
709
+		if($max_length) {
710
+					$name = substr($name, 0, $max_length);
711
+		}
682 712
 			
683 713
 		return $name;	
684 714
 	}
685 715
 	
686 716
 	public function sort_by( &$array, $field, $direction = 'asc')
687 717
 	{
688
-		if(strtolower($direction) == "desc" || $direction == SORT_DESC)
689
-			$direction = SORT_DESC;
690
-		else
691
-			$direction = SORT_ASC;
718
+		if(strtolower($direction) == "desc" || $direction == SORT_DESC) {
719
+					$direction = SORT_DESC;
720
+		} else {
721
+					$direction = SORT_ASC;
722
+		}
692 723
 					
693 724
 	   $array = $this->array_orderby($array, $field, $direction);
694 725
 	    
@@ -705,10 +736,11 @@  discard block
 block discarded – undo
705 736
 	            $tmp = array();
706 737
 	            foreach ($data as $key => $row)
707 738
 	            {
708
-					if(is_array($row))
709
-						$tmp[$key] = $row[$field];
710
-					else
711
-						$tmp[$key] = $row->$field;
739
+					if(is_array($row)) {
740
+											$tmp[$key] = $row[$field];
741
+					} else {
742
+											$tmp[$key] = $row->$field;
743
+					}
712 744
 				}
713 745
 	            $args[$n] = $tmp;
714 746
 	            }
@@ -746,28 +778,32 @@  discard block
 block discarded – undo
746 778
 		
747 779
 		if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb'))
748 780
 		{
749
-			if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb))
750
-				return "> ".$xcloner_exclude_files_larger_than_mb."MB";
781
+			if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) {
782
+							return "> ".$xcloner_exclude_files_larger_than_mb."MB";
783
+			}
751 784
 		}
752 785
 		
753
-		if(!sizeof($this->excluded_files))
754
-			$this->set_excluded_files();
786
+		if(!sizeof($this->excluded_files)) {
787
+					$this->set_excluded_files();
788
+		}
755 789
 				
756
-		if(is_array($this->excluded_files))
757
-		foreach($this->excluded_files as $excluded_file_pattern)
790
+		if(is_array($this->excluded_files)) {
791
+				foreach($this->excluded_files as $excluded_file_pattern)
758 792
 		{
759 793
 			if($excluded_file_pattern == "/")
760 794
 				$needle = "$";
761
-			else
762
-				$needle = "$".$excluded_file_pattern;
795
+		} else {
796
+							$needle = "$".$excluded_file_pattern;
797
+			}
763 798
 				
764 799
 			if(strstr("$".$file['path'], $needle)){
765 800
 				return $excluded_file_pattern;
766 801
 			}
767 802
 		}
768 803
 		
769
-		if( $regex = $this->is_excluded_regex($file))
770
-			return $regex;
804
+		if( $regex = $this->is_excluded_regex($file)) {
805
+					return $regex;
806
+		}
771 807
 		
772 808
 		if($file['type'] == "file")
773 809
 		{
@@ -830,13 +866,15 @@  discard block
 block discarded – undo
830 866
 			foreach($regex_patterns as $excluded_file_pattern)
831 867
 			{
832 868
 				
833
-				if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r")
834
-					$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1);
869
+				if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") {
870
+									$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1);
871
+				}
835 872
 					
836
-				if($file['path'] == "/")
837
-					$needle = "/";
838
-				else
839
-					$needle = "/".$file['path'];
873
+				if($file['path'] == "/") {
874
+									$needle = "/";
875
+				} else {
876
+									$needle = "/".$file['path'];
877
+				}
840 878
 				//echo $needle."---".$excluded_file_pattern."---\n";
841 879
 				
842 880
 				if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){
@@ -852,10 +890,12 @@  discard block
 block discarded – undo
852 890
 	{
853 891
 		$this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
854 892
 		
855
-		if(!isset($file['size']))
856
-			$file['size'] = 0;
857
-		if(!isset($file['visibility']))	
858
-			$file['visibility'] = "private";
893
+		if(!isset($file['size'])) {
894
+					$file['size'] = 0;
895
+		}
896
+		if(!isset($file['visibility'])) {
897
+					$file['visibility'] = "private";
898
+		}
859 899
 		
860 900
 		$csv_filename = str_replace('"','""', $file['path']);
861 901
 		
@@ -866,7 +906,7 @@  discard block
 block discarded – undo
866 906
 		if($file['type'] == "dir"){
867 907
 			try{
868 908
 				$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n");
869
-			}catch(Exception $e){
909
+			} catch(Exception $e){
870 910
 				$this->logger->error($e->getMessage());	
871 911
 			}
872 912
 		}
@@ -890,7 +930,7 @@  discard block
 block discarded – undo
890 930
 			
891 931
 			$this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
892 932
 		
893
-		}catch(Exception $e){
933
+		} catch(Exception $e){
894 934
 		
895 935
 			$this->logger->error($e->getMessage());	
896 936
 		}
@@ -905,35 +945,39 @@  discard block
 block discarded – undo
905 945
 	
906 946
 	public function get_filesystem($system = "")
907 947
 	{
908
-		if($system == "storage_filesystem_append")
909
-			return $this->storage_filesystem_append;
910
-		elseif($system == "tmp_filesystem_append")
911
-			return $this->tmp_filesystem_append;
912
-		elseif($system == "tmp_filesystem")
913
-			return $this->tmp_filesystem;
914
-		elseif($system == "storage_filesystem")
915
-			return $this->storage_filesystem;
916
-		else
917
-			return $this->start_filesystem;	
948
+		if($system == "storage_filesystem_append") {
949
+					return $this->storage_filesystem_append;
950
+		} elseif($system == "tmp_filesystem_append") {
951
+					return $this->tmp_filesystem_append;
952
+		} elseif($system == "tmp_filesystem") {
953
+					return $this->tmp_filesystem;
954
+		} elseif($system == "storage_filesystem") {
955
+					return $this->storage_filesystem;
956
+		} else {
957
+					return $this->start_filesystem;
958
+		}
918 959
 	}
919 960
 	
920 961
 	public function get_adapter($system)
921 962
 	{
922
-		if($system == "tmp_filesystem")
923
-			return $this->tmp_adapter;
924
-		elseif($system == "storage_filesystem")
925
-			return $this->storage_adapter;
926
-		else
927
-			return $this->start_adapter;	
963
+		if($system == "tmp_filesystem") {
964
+					return $this->tmp_adapter;
965
+		} elseif($system == "storage_filesystem") {
966
+					return $this->storage_adapter;
967
+		} else {
968
+					return $this->start_adapter;
969
+		}
928 970
 	}
929 971
 	
930 972
 	private function scan_finished()
931 973
 	{
932
-		if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler()))
933
-			return false;
974
+		if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) {
975
+					return false;
976
+		}
934 977
 		
935
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler()))
936
-			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
978
+		if($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
979
+					$this->tmp_filesystem->delete($this->get_temp_dir_handler());
980
+		}
937 981
 		
938 982
 		$this->logger->debug(sprintf(("File scan finished")));
939 983
 			
Please login to merge, or discard this patch.
uninstall.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,6 +26,6 @@
 block discarded – undo
26 26
  */
27 27
 
28 28
 // If uninstall not called from WordPress, then exit.
29
-if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
29
+if (!defined('WP_UNINSTALL_PLUGIN')) {
30 30
 	exit;
31 31
 }
Please login to merge, or discard this patch.
includes/class-xcloner-sanitization.php 2 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
 		
25 25
 		try{
26 26
 			$option = Util::normalizePath($path);
27
-		}catch(Exception $e){
27
+		} catch(Exception $e){
28 28
 			add_settings_error('xcloner_error_message', '', __($e->getMessage()), 'error');
29 29
 		}
30 30
 		
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 
4 4
 class Xcloner_Sanitization {
5 5
 	
6
-	public function __construct(){}
6
+	public function __construct() {}
7 7
 	
8 8
 	public function sanitize_input_as_int($option)
9 9
 	{
@@ -24,14 +24,14 @@  discard block
 block discarded – undo
24 24
 	{
25 25
 		$path = filter_var($option, FILTER_SANITIZE_URL);
26 26
 		
27
-		try{
27
+		try {
28 28
 			$option = Util::normalizePath($path);
29
-		}catch(Exception $e){
29
+		}catch (Exception $e) {
30 30
 			add_settings_error('xcloner_error_message', '', __($e->getMessage()), 'error');
31 31
 		}
32 32
 		
33
-		if($path and !is_dir($path)){
34
-			add_settings_error('xcloner_error_message', '', __(sprintf('Invalid Server Path %s',$option)), 'error');
33
+		if ($path and !is_dir($path)) {
34
+			add_settings_error('xcloner_error_message', '', __(sprintf('Invalid Server Path %s', $option)), 'error');
35 35
 			return false;
36 36
 		}
37 37
 		
Please login to merge, or discard this patch.
includes/class-xcloner-requirements.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -147,14 +147,14 @@
 block discarded – undo
147 147
 	  $unit_list = array('B', 'KB', 'MB', 'GB', 'PB');
148 148
 	
149 149
 	  if ($bytes == 0) {
150
-	    return $bytes . ' ' . $unit_list[0];
150
+		return $bytes . ' ' . $unit_list[0];
151 151
 	  }
152 152
 	
153 153
 	  $unit_count = count($unit_list);
154 154
 	  for ($i = $unit_count - 1; $i >= 0; $i--) {
155
-	    $power = $i * 10;
156
-	    if (($bytes >> $power) >= 1)
157
-	      return round($bytes / (1 << $power), $decimals) . ' ' . $unit_list[$i];
155
+		$power = $i * 10;
156
+		if (($bytes >> $power) >= 1)
157
+		  return round($bytes / (1 << $power), $decimals) . ' ' . $unit_list[$i];
158 158
 	  }
159 159
 	}
160 160
 }
Please login to merge, or discard this patch.
Braces   +49 added lines, -34 removed lines patch added patch discarded remove patch
@@ -13,20 +13,25 @@  discard block
 block discarded – undo
13 13
 	
14 14
 	public function check_backup_ready_status()
15 15
 	{
16
-		if(!$this->check_min_php_version(1))
17
-			return false;
16
+		if(!$this->check_min_php_version(1)) {
17
+					return false;
18
+		}
18 19
 		
19
-		if(!$this->check_safe_mode(1))
20
-			return false;
20
+		if(!$this->check_safe_mode(1)) {
21
+					return false;
22
+		}
21 23
 		
22
-		if(!$this->check_xcloner_start_path(1))
23
-			return false;
24
+		if(!$this->check_xcloner_start_path(1)) {
25
+					return false;
26
+		}
24 27
 		
25
-		if(!$this->check_xcloner_store_path(1))
26
-			return false;
28
+		if(!$this->check_xcloner_store_path(1)) {
29
+					return false;
30
+		}
27 31
 		
28
-		if(!$this->check_xcloner_tmp_path(1))
29
-			return false;
32
+		if(!$this->check_xcloner_tmp_path(1)) {
33
+					return false;
34
+		}
30 35
 			
31 36
 		return true;	
32 37
 	}
@@ -41,10 +46,11 @@  discard block
 block discarded – undo
41 46
 		
42 47
 		if($return_bool == 1)
43 48
 		{
44
-			if(version_compare(phpversion(), $this->min_php_version, '<'))
45
-				return false;
46
-			else
47
-				return true;
49
+			if(version_compare(phpversion(), $this->min_php_version, '<')) {
50
+							return false;
51
+			} else {
52
+							return true;
53
+			}
48 54
 		}
49 55
 		
50 56
 		return phpversion();
@@ -56,14 +62,16 @@  discard block
 block discarded – undo
56 62
 		
57 63
 		if($return_bool)
58 64
 		{
59
-			if( ini_get('safe_mode') )
60
-				return false;
61
-			else
62
-				return true;
65
+			if( ini_get('safe_mode') ) {
66
+							return false;
67
+			} else {
68
+							return true;
69
+			}
63 70
 		}
64 71
 		
65
-		if( ini_get('safe_mode') )
66
-			$safe_mode = "On";
72
+		if( ini_get('safe_mode') ) {
73
+					$safe_mode = "On";
74
+		}
67 75
 			
68 76
 		return $safe_mode;
69 77
 	}
@@ -74,8 +82,9 @@  discard block
 block discarded – undo
74 82
 		
75 83
 		if($return_bool)
76 84
 		{
77
-			if(!file_exists($path))
78
-				return false;
85
+			if(!file_exists($path)) {
86
+							return false;
87
+			}
79 88
 				
80 89
 			return is_readable($path);
81 90
 		}
@@ -89,11 +98,13 @@  discard block
 block discarded – undo
89 98
 		
90 99
 		if($return_bool)
91 100
 		{
92
-			if(!file_exists($path))
93
-				return false;
101
+			if(!file_exists($path)) {
102
+							return false;
103
+			}
94 104
 			
95
-			if(!is_writeable($path))	
96
-				@chmod($path, 0777);
105
+			if(!is_writeable($path)) {
106
+							@chmod($path, 0777);
107
+			}
97 108
 					
98 109
 			return is_writeable($path);
99 110
 		}
@@ -107,11 +118,13 @@  discard block
 block discarded – undo
107 118
 		
108 119
 		if($return_bool)
109 120
 		{
110
-			if(!file_exists($path))
111
-				return false;
121
+			if(!file_exists($path)) {
122
+							return false;
123
+			}
112 124
 			
113
-			if(!is_writeable($path))	
114
-				@chmod($path, 0777);
125
+			if(!is_writeable($path)) {
126
+							@chmod($path, 0777);
127
+			}
115 128
 				
116 129
 			return is_writeable($path);
117 130
 		}
@@ -133,8 +146,9 @@  discard block
 block discarded – undo
133 146
 	{
134 147
 		$open_basedir =  ini_get('open_basedir');
135 148
 		
136
-		if(!$open_basedir)
137
-			$open_basedir = "none";
149
+		if(!$open_basedir) {
150
+					$open_basedir = "none";
151
+		}
138 152
 		return $open_basedir;	
139 153
 	}
140 154
 	
@@ -153,8 +167,9 @@  discard block
 block discarded – undo
153 167
 	  $unit_count = count($unit_list);
154 168
 	  for ($i = $unit_count - 1; $i >= 0; $i--) {
155 169
 	    $power = $i * 10;
156
-	    if (($bytes >> $power) >= 1)
157
-	      return round($bytes / (1 << $power), $decimals) . ' ' . $unit_list[$i];
170
+	    if (($bytes >> $power) >= 1) {
171
+	    	      return round($bytes / (1 << $power), $decimals) . ' ' . $unit_list[$i];
172
+	    }
158 173
 	  }
159 174
 	}
160 175
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@  discard block
 block discarded – undo
3 3
 class Xcloner_Requirements
4 4
 {
5 5
 	
6
-	var $min_php_version 	= "5.4.0";
7
-	var $safe_mode			= "Off";
6
+	var $min_php_version = "5.4.0";
7
+	var $safe_mode = "Off";
8 8
 	
9 9
 	private $xcloner_settings;
10 10
 	private $xcloner_container;
@@ -22,19 +22,19 @@  discard block
 block discarded – undo
22 22
 	
23 23
 	public function check_backup_ready_status()
24 24
 	{
25
-		if(!$this->check_min_php_version(1))
25
+		if (!$this->check_min_php_version(1))
26 26
 			return false;
27 27
 		
28
-		if(!$this->check_safe_mode(1))
28
+		if (!$this->check_safe_mode(1))
29 29
 			return false;
30 30
 		
31
-		if(!$this->check_xcloner_start_path(1))
31
+		if (!$this->check_xcloner_start_path(1))
32 32
 			return false;
33 33
 		
34
-		if(!$this->check_xcloner_store_path(1))
34
+		if (!$this->check_xcloner_store_path(1))
35 35
 			return false;
36 36
 		
37
-		if(!$this->check_xcloner_tmp_path(1))
37
+		if (!$this->check_xcloner_tmp_path(1))
38 38
 			return false;
39 39
 			
40 40
 		return true;	
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
 	public function check_min_php_version($return_bool = 0)
49 49
 	{
50 50
 		
51
-		if($return_bool == 1)
51
+		if ($return_bool == 1)
52 52
 		{
53
-			if(version_compare(phpversion(), $this->min_php_version, '<'))
53
+			if (version_compare(phpversion(), $this->min_php_version, '<'))
54 54
 				return false;
55 55
 			else
56 56
 				return true;
@@ -59,31 +59,31 @@  discard block
 block discarded – undo
59 59
 		return phpversion();
60 60
 	}
61 61
 	
62
-	public function check_safe_mode($return_bool=0)
62
+	public function check_safe_mode($return_bool = 0)
63 63
 	{
64 64
 		$safe_mode = "Off";
65 65
 		
66
-		if($return_bool)
66
+		if ($return_bool)
67 67
 		{
68
-			if( ini_get('safe_mode') )
68
+			if (ini_get('safe_mode'))
69 69
 				return false;
70 70
 			else
71 71
 				return true;
72 72
 		}
73 73
 		
74
-		if( ini_get('safe_mode') )
74
+		if (ini_get('safe_mode'))
75 75
 			$safe_mode = "On";
76 76
 			
77 77
 		return $safe_mode;
78 78
 	}
79 79
 	
80
-	public function check_xcloner_start_path($return_bool=0)
80
+	public function check_xcloner_start_path($return_bool = 0)
81 81
 	{
82 82
 		$path = $this->xcloner_settings->get_xcloner_start_path();
83 83
 		
84
-		if($return_bool)
84
+		if ($return_bool)
85 85
 		{
86
-			if(!file_exists($path))
86
+			if (!file_exists($path))
87 87
 				return false;
88 88
 				
89 89
 			return is_readable($path);
@@ -92,16 +92,16 @@  discard block
 block discarded – undo
92 92
 		return $path;
93 93
 	}
94 94
 	
95
-	public function check_xcloner_tmp_path($return_bool=0)
95
+	public function check_xcloner_tmp_path($return_bool = 0)
96 96
 	{
97 97
 		$path = $this->xcloner_settings->get_xcloner_tmp_path();
98 98
 		
99
-		if($return_bool)
99
+		if ($return_bool)
100 100
 		{
101
-			if(!file_exists($path))
101
+			if (!file_exists($path))
102 102
 				return false;
103 103
 			
104
-			if(!is_writeable($path))	
104
+			if (!is_writeable($path))	
105 105
 				@chmod($path, 0777);
106 106
 					
107 107
 			return is_writeable($path);
@@ -110,16 +110,16 @@  discard block
 block discarded – undo
110 110
 		return $path;
111 111
 	}
112 112
 	
113
-	public function check_xcloner_store_path($return_bool=0)
113
+	public function check_xcloner_store_path($return_bool = 0)
114 114
 	{
115 115
 		$path = $this->xcloner_settings->get_xcloner_store_path();
116 116
 		
117
-		if($return_bool)
117
+		if ($return_bool)
118 118
 		{
119
-			if(!file_exists($path))
119
+			if (!file_exists($path))
120 120
 				return false;
121 121
 			
122
-			if(!is_writeable($path))	
122
+			if (!is_writeable($path))	
123 123
 				@chmod($path, 0777);
124 124
 				
125 125
 			return is_writeable($path);
@@ -140,9 +140,9 @@  discard block
 block discarded – undo
140 140
 	
141 141
 	public function get_open_basedir()
142 142
 	{
143
-		$open_basedir =  ini_get('open_basedir');
143
+		$open_basedir = ini_get('open_basedir');
144 144
 		
145
-		if(!$open_basedir)
145
+		if (!$open_basedir)
146 146
 			$open_basedir = "none";
147 147
 		return $open_basedir;	
148 148
 	}
@@ -156,14 +156,14 @@  discard block
 block discarded – undo
156 156
 	  $unit_list = array('B', 'KB', 'MB', 'GB', 'PB');
157 157
 	
158 158
 	  if ($bytes == 0) {
159
-	    return $bytes . ' ' . $unit_list[0];
159
+	    return $bytes.' '.$unit_list[0];
160 160
 	  }
161 161
 	
162 162
 	  $unit_count = count($unit_list);
163 163
 	  for ($i = $unit_count - 1; $i >= 0; $i--) {
164 164
 	    $power = $i * 10;
165 165
 	    if (($bytes >> $power) >= 1)
166
-	      return round($bytes / (1 << $power), $decimals) . ' ' . $unit_list[$i];
166
+	      return round($bytes / (1 << $power), $decimals).' '.$unit_list[$i];
167 167
 	  }
168 168
 	}
169 169
 }
Please login to merge, or discard this patch.
includes/class-xcloner-file-transfer.php 4 patches
Braces   +7 added lines, -5 removed lines patch added patch discarded remove patch
@@ -19,8 +19,9 @@  discard block
 block discarded – undo
19 19
 	
20 20
 	public function transfer_file($file, $start = 0, $hash = "")
21 21
 	{
22
-		if(!$this->target_url)
23
-			throw new Exception("Please setup a target url for upload");
22
+		if(!$this->target_url) {
23
+					throw new Exception("Please setup a target url for upload");
24
+		}
24 25
 
25 26
 		
26 27
 		$fp = $this->get_storage_filesystem()->readStream($file);
@@ -68,8 +69,9 @@  discard block
 block discarded – undo
68 69
 		
69 70
 		$result = json_decode($original_result);
70 71
 				
71
-		if(!$result)
72
-			throw new Exception("We have received no valid response from the remote host, original message: ". $original_result);
72
+		if(!$result) {
73
+					throw new Exception("We have received no valid response from the remote host, original message: ". $original_result);
74
+		}
73 75
 			
74 76
 		if($result->status != 200)
75 77
 		{
@@ -94,7 +96,7 @@  discard block
 block discarded – undo
94 96
 	            . ($postname ?: basename($filename))
95 97
 	            . ($mimetype ? ";type=$mimetype" : '');
96 98
 		
97
-		}else{
99
+		} else{
98 100
 			
99 101
 			return curl_file_create($filename, $mimetype, $postname);	
100 102
 				
Please login to merge, or discard this patch.
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -86,6 +86,9 @@
 block discarded – undo
86 86
 		return ftell($fp);
87 87
 	}
88 88
 	
89
+	/**
90
+	 * @param string $filename
91
+	 */
89 92
 	private function curl_file_create($filename, $mimetype = '', $postname = '') {
90 93
 		if (!function_exists('curl_file_create')) {
91 94
 	        
Please login to merge, or discard this patch.
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -54,10 +54,10 @@  discard block
 block discarded – undo
54 54
 		
55 55
 		curl_setopt($ch, CURLOPT_POST, 1);
56 56
 		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
57
-        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
58
-        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
59
-        curl_setopt($ch, CURLOPT_TIMEOUT, 1200);
60
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
57
+		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
58
+		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
59
+		curl_setopt($ch, CURLOPT_TIMEOUT, 1200);
60
+		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
61 61
         
62 62
 		curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array );
63 63
 		curl_setopt($ch, CURLOPT_VERBOSE, true);
@@ -89,9 +89,9 @@  discard block
 block discarded – undo
89 89
 	private function curl_file_create($filename, $mimetype = '', $postname = '') {
90 90
 		if (!function_exists('curl_file_create')) {
91 91
 	        
92
-	        return "@$filename;filename="
93
-	            . ($postname ?: basename($filename))
94
-	            . ($mimetype ? ";type=$mimetype" : '');
92
+			return "@$filename;filename="
93
+				. ($postname ?: basename($filename))
94
+				. ($mimetype ? ";type=$mimetype" : '');
95 95
 		
96 96
 		}else{
97 97
 			
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-class Xcloner_File_Transfer extends Xcloner_File_System{
3
+class Xcloner_File_Transfer extends Xcloner_File_System {
4 4
 	
5 5
 	private $target_url;
6 6
 	private $transfer_limit = 1048576; //bytes 1MB= 1048576 300KB = 358400
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 	
9 9
 	public function set_target($target_url)
10 10
 	{
11
-		return $this->target_url= $target_url;
11
+		return $this->target_url = $target_url;
12 12
 	}
13 13
 	
14 14
 	public function get_target()
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	
20 20
 	public function transfer_file($file, $start = 0, $hash = "")
21 21
 	{
22
-		if(!$this->target_url)
22
+		if (!$this->target_url)
23 23
 			throw new Exception("Please setup a target url for upload");
24 24
 
25 25
 		
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 		
28 28
 		fseek($fp, $start, SEEK_SET);
29 29
 		
30
-		$binary_data =  fread($fp, $this->transfer_limit);
30
+		$binary_data = fread($fp, $this->transfer_limit);
31 31
 		
32 32
 		$tmp_filename = "xcloner_upload_".substr(md5(time()), 0, 5);
33 33
 		
@@ -38,11 +38,11 @@  discard block
 block discarded – undo
38 38
 		$send_array = array();
39 39
 		
40 40
 		$send_array['file'] 	= $file;
41
-		$send_array['start'] 	= $start;
42
-		$send_array['xcloner_action'] 	= "write_file";
41
+		$send_array['start'] = $start;
42
+		$send_array['xcloner_action'] = "write_file";
43 43
 		$send_array['hash'] 	= $hash;
44 44
 		#$send_array['blob'] 	= $binary_data;
45
-		$send_array['blob'] 	= $this->curl_file_create($tmp_file_path,'application/x-binary',$tmp_filename);
45
+		$send_array['blob'] 	= $this->curl_file_create($tmp_file_path, 'application/x-binary', $tmp_filename);
46 46
 		
47 47
 		//$data = http_build_query($send_array);
48 48
 		
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 		
51 51
 		
52 52
 		$ch = curl_init();
53
-		curl_setopt($ch, CURLOPT_URL,$this->target_url);
53
+		curl_setopt($ch, CURLOPT_URL, $this->target_url);
54 54
 		
55 55
 		curl_setopt($ch, CURLOPT_POST, 1);
56 56
 		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
@@ -59,24 +59,24 @@  discard block
 block discarded – undo
59 59
         curl_setopt($ch, CURLOPT_TIMEOUT, 1200);
60 60
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
61 61
         
62
-		curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array );
62
+		curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array);
63 63
 		curl_setopt($ch, CURLOPT_VERBOSE, true);
64 64
 		
65
-		$original_result = curl_exec ($ch);
65
+		$original_result = curl_exec($ch);
66 66
 		
67 67
 		$this->get_tmp_filesystem()->delete($tmp_filename);
68 68
 		
69 69
 		$result = json_decode($original_result);
70 70
 				
71
-		if(!$result)
72
-			throw new Exception("We have received no valid response from the remote host, original message: ". $original_result);
71
+		if (!$result)
72
+			throw new Exception("We have received no valid response from the remote host, original message: ".$original_result);
73 73
 			
74
-		if($result->status != 200)
74
+		if ($result->status != 200)
75 75
 		{
76 76
 			throw new Exception($result->response);
77 77
 		}
78 78
 		
79
-		if(ftell($fp) >= $this->get_storage_filesystem()->getSize($file))
79
+		if (ftell($fp) >= $this->get_storage_filesystem()->getSize($file))
80 80
 		{
81 81
 			$this->get_logger()->info(sprintf("Upload done for file %s to target url %s, transferred a total of %s bytes", $file, $this->target_url, ftell($fp)));
82 82
 			$this->remove_tmp_filesystem();
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	            . ($postname ?: basename($filename))
94 94
 	            . ($mimetype ? ";type=$mimetype" : '');
95 95
 		
96
-		}else{
96
+		} else {
97 97
 			
98 98
 			return curl_file_create($filename, $mimetype, $postname);	
99 99
 				
Please login to merge, or discard this patch.
includes/class-xcloner-i18n.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
 		load_plugin_textdomain(
38 38
 			'xcloner-backup-and-restore',
39 39
 			false,
40
-			dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
40
+			dirname(dirname(plugin_basename(__FILE__))).'/languages/'
41 41
 		);
42 42
 
43 43
 	}
Please login to merge, or discard this patch.