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