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