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 ( a3be56...1cbc26 )
by Liuta
14:23 queued 11:15
created
includes/class-xcloner-file-system.php 1 patch
Spacing   +135 added lines, -135 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
 			return false;
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
 	}
@@ -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.