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 ( 02764c...e4dc90 )
by Liuta
02:47
created
includes/class-xcloner-file-system.php 1 patch
Spacing   +134 added lines, -134 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;
@@ -32,39 +32,39 @@  discard block
 block discarded – undo
32 32
 		$this->logger = new XCloner_Logger('xcloner_file_system', $hash);
33 33
 		$this->xcloner_requirements = new Xcloner_Requirements();
34 34
 
35
-		$this->xcloner_settings 		= new Xcloner_Settings($hash);
35
+		$this->xcloner_settings = new Xcloner_Settings($hash);
36 36
 
37
-		try{
37
+		try {
38 38
 			
39
-			$this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(),LOCK_EX, 'SKIP_LINKS');
39
+			$this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS');
40 40
 			$this->start_filesystem = new Filesystem($this->start_adapter, new Config([
41 41
 					'disable_asserts' => true,
42 42
 				]));
43 43
 			
44
-			$this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX, 'SKIP_LINKS');
44
+			$this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS');
45 45
 			$this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([
46 46
 					'disable_asserts' => true,
47 47
 				]));
48
-			$adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX|FILE_APPEND, 'SKIP_LINKS');
48
+			$adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
49 49
 			$this->tmp_filesystem_append = new Filesystem($adapter, new Config([
50 50
 					'disable_asserts' => true,
51 51
 				]));
52 52
 
53
-			$adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),LOCK_EX, 'SKIP_LINKS');
53
+			$adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS');
54 54
 			$this->storage_filesystem = new Filesystem($adapter, new Config([
55 55
 					'disable_asserts' => true,
56 56
 				]));	
57 57
 			
58
-			$this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),FILE_APPEND, 'SKIP_LINKS');
58
+			$this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND, 'SKIP_LINKS');
59 59
 			$this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([
60 60
 					'disable_asserts' => true,
61 61
 				]));
62
-		}catch(Exception $e){
62
+		}catch (Exception $e) {
63 63
 			return false;
64 64
 		}
65 65
 		
66 66
 		
67
-		if($value = get_option('xcloner_directories_to_scan_per_request'))
67
+		if ($value = get_option('xcloner_directories_to_scan_per_request'))
68 68
 			$this->folders_to_process_per_session = $value;
69 69
 
70 70
 	}
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
 		return $this->getMetadataFull('storage_adapter', $file);
126 126
 	}
127 127
 	
128
-	public function get_included_files_handler($metadata  = 0)
128
+	public function get_included_files_handler($metadata = 0)
129 129
 	{
130 130
 		$path = $this->included_files_handler;
131
-		if(!$metadata)
131
+		if (!$metadata)
132 132
 			return $path;
133 133
 		
134 134
 		$spl_info = $this->getMetadataFull('tmp_adapter', $path);
@@ -145,16 +145,16 @@  discard block
 block discarded – undo
145 145
 	{
146 146
 		$files = $this->get_backup_archives_list();
147 147
 		
148
-		if(is_array($files))
149
-			$this->sort_by($files, "timestamp","desc");
148
+		if (is_array($files))
149
+			$this->sort_by($files, "timestamp", "desc");
150 150
 		
151 151
 		$new_list = array();
152 152
 		
153
-		foreach($files as $key=>$file)
154
-			if(!isset($file['parent']))
153
+		foreach ($files as $key=>$file)
154
+			if (!isset($file['parent']))
155 155
 				$new_list[] = ($files[$key]);
156 156
 
157
-		if(isset($new_list[0]))
157
+		if (isset($new_list[0]))
158 158
 			return $new_list[0];
159 159
 	}
160 160
 	
@@ -162,13 +162,13 @@  discard block
 block discarded – undo
162 162
 	{
163 163
 		$files = $this->get_backup_archives_list();
164 164
 
165
-		if(is_array($files))
166
-			$this->sort_by($files, "timestamp","desc");
165
+		if (is_array($files))
166
+			$this->sort_by($files, "timestamp", "desc");
167 167
 		
168 168
 		$new_list = array();
169 169
 		
170
-		foreach($files as $key=>$file)
171
-			if(!isset($file['parent']))
170
+		foreach ($files as $key=>$file)
171
+			if (!isset($file['parent']))
172 172
 				$new_list[] = ($files[$key]);
173 173
 
174 174
 		return $new_list;
@@ -179,8 +179,8 @@  discard block
 block discarded – undo
179 179
 		$files = $this->get_backup_archives_list();
180 180
 		$total = 0;
181 181
 		
182
-		if(is_array($files))
183
-			foreach($files as $file)
182
+		if (is_array($files))
183
+			foreach ($files as $file)
184 184
 				$total += $file['size'];
185 185
 				
186 186
 		return $total;		
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	
189 189
 	public function is_part($backup_name)
190 190
 	{
191
-		if(stristr($backup_name, "-part"))
191
+		if (stristr($backup_name, "-part"))
192 192
 			return true;
193 193
 		
194 194
 		return false;	
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	
197 197
 	public function is_multipart($backup_name)
198 198
 	{
199
-		if(stristr($backup_name, "-multipart"))
199
+		if (stristr($backup_name, "-multipart"))
200 200
 			return true;
201 201
 		
202 202
 		return false;	
@@ -205,10 +205,10 @@  discard block
 block discarded – undo
205 205
 	public function get_backup_size($backup_name)
206 206
 	{
207 207
 		$backup_size = $this->get_storage_filesystem()->getSize($backup_name);
208
-		if($this->is_multipart($backup_name))
208
+		if ($this->is_multipart($backup_name))
209 209
 		{
210 210
 			$backup_parts = $this->get_multipart_files($backup_name);
211
-			foreach($backup_parts as $part_file)
211
+			foreach ($backup_parts as $part_file)
212 212
 				$backup_size += $this->get_storage_filesystem()->getSize($part_file);
213 213
 		}
214 214
 		
@@ -219,12 +219,12 @@  discard block
 block discarded – undo
219 219
 	{
220 220
 		$files = array();
221 221
 		
222
-		if($this->is_multipart($backup_name))
222
+		if ($this->is_multipart($backup_name))
223 223
 		{
224 224
 			$lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($backup_name));
225
-			foreach($lines as $line)
225
+			foreach ($lines as $line)
226 226
 			{
227
-				if($line)
227
+				if ($line)
228 228
 				{
229 229
 					$data = str_getcsv($line);
230 230
 					$files[] = $data[0];
@@ -237,12 +237,12 @@  discard block
 block discarded – undo
237 237
 	
238 238
 	public function delete_backup_by_name($backup_name)
239 239
 	{
240
-		if($this->is_multipart($backup_name))
240
+		if ($this->is_multipart($backup_name))
241 241
 		{
242 242
 			$lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($backup_name));
243
-			foreach($lines as $line)
243
+			foreach ($lines as $line)
244 244
 			{
245
-				if($line)
245
+				if ($line)
246 246
 				{
247 247
 					$data = str_getcsv($line);
248 248
 					$this->get_storage_filesystem()->delete($data[0]);
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 			}
251 251
 		}
252 252
 		
253
-		if($this->get_storage_filesystem()->delete($backup_name))
253
+		if ($this->get_storage_filesystem()->delete($backup_name))
254 254
 			$return = true;
255 255
 		else
256 256
 			$return = false;
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 		return $return;	
259 259
 	}
260 260
 	
261
-	public function getMetadataFull($adapter = "storage_adapter" , $path)
261
+	public function getMetadataFull($adapter = "storage_adapter", $path)
262 262
     {
263 263
         $location = $this->$adapter->applyPathPrefix($path);
264 264
         $spl_info = new SplFileInfo($location);
@@ -271,25 +271,25 @@  discard block
 block discarded – undo
271 271
 	{
272 272
 		$list = array();
273 273
 		
274
-		if(method_exists($this->get_storage_filesystem(), "listContents"))
274
+		if (method_exists($this->get_storage_filesystem(), "listContents"))
275 275
 			$list = $this->get_storage_filesystem()->listContents();
276 276
 
277 277
 		
278 278
 		$backup_files = array();
279 279
 		$parents = array();
280 280
 		
281
-		foreach($list as $file_info)
281
+		foreach ($list as $file_info)
282 282
 		{
283 283
 			$data = array();
284 284
 			
285
-			if(isset($file_info['extension']) and $file_info['extension'] == "csv")
285
+			if (isset($file_info['extension']) and $file_info['extension'] == "csv")
286 286
 			{
287 287
 				$lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($file_info['path']));
288
-				foreach($lines as $line)
289
-					if($line)
288
+				foreach ($lines as $line)
289
+					if ($line)
290 290
 					{
291 291
 						$data = str_getcsv($line);
292
-						if(is_array($data)){
292
+						if (is_array($data)) {
293 293
 							$parents[$data[0]] = $file_info['path'];
294 294
 							$file_info['childs'][] = $data;
295 295
 							$file_info['size'] += $data[2];
@@ -298,13 +298,13 @@  discard block
 block discarded – undo
298 298
 						
299 299
 			}
300 300
 			
301
-			if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions))
301
+			if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions))
302 302
 				$backup_files[$file_info['path']] = $file_info;
303 303
 		}
304 304
 		
305
-		foreach($backup_files as $key=>$file_info)
305
+		foreach ($backup_files as $key=>$file_info)
306 306
 		{
307
-			if(isset($parents[$file_info['path']]))
307
+			if (isset($parents[$file_info['path']]))
308 308
 				$backup_files[$key]['parent'] = $parents[$file_info['path']];
309 309
 		}
310 310
 		
@@ -313,40 +313,40 @@  discard block
 block discarded – undo
313 313
 	
314 314
 	public function start_file_recursion($init = 0)
315 315
 	{
316
-		if($init)
316
+		if ($init)
317 317
 		{
318 318
 			$this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"), $this->xcloner_settings->get_xcloner_start_path()));
319 319
 			$this->do_system_init();
320 320
 		}
321 321
 		
322
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler())){
322
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
323 323
 		//.dir exists, we presume we have files to iterate	
324 324
 			$content = $this->tmp_filesystem->read($this->get_temp_dir_handler());
325 325
 			$files = array_filter(explode("\n", $content));
326 326
 			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
327 327
 			
328 328
 			$counter = 0;
329
-			foreach($files as $file)
329
+			foreach ($files as $file)
330 330
 			{
331
-				if($counter < $this->folders_to_process_per_session){
331
+				if ($counter < $this->folders_to_process_per_session) {
332 332
 					$this->build_files_list($file);
333 333
 					$counter++;
334
-				}else{
334
+				} else {
335 335
 					$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n");
336 336
 				}
337 337
 			}
338
-		}else{
338
+		} else {
339 339
 			$this->build_files_list();
340 340
 		}
341 341
 		
342
-		if($this->scan_finished())
342
+		if ($this->scan_finished())
343 343
 		{
344 344
 			$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html");
345 345
 			$this->store_file($metadata_dumpfile, 'tmp_filesystem');
346 346
 			$this->files_counter++;
347 347
 		
348 348
 			//adding included dump file to the included files list
349
-			if($this->get_tmp_filesystem()->has($this->get_included_files_handler()))
349
+			if ($this->get_tmp_filesystem()->has($this->get_included_files_handler()))
350 350
 			{
351 351
 				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler());
352 352
 				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
@@ -354,13 +354,13 @@  discard block
 block discarded – undo
354 354
 			}
355 355
 		
356 356
 			//adding a default index.html to the temp xcloner folder
357
-			if(!$this->get_tmp_filesystem()->has("index.html"))
357
+			if (!$this->get_tmp_filesystem()->has("index.html"))
358 358
 			{
359
-				$this->get_tmp_filesystem()->write("index.html","");
359
+				$this->get_tmp_filesystem()->write("index.html", "");
360 360
 			}
361 361
 			
362 362
 			//adding the default log file
363
-			if($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1)))
363
+			if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1)))
364 364
 			{
365 365
 				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1));
366 366
 				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
 	{
378 378
 		$return = array();
379 379
 		$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler();
380
-		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log'))
380
+		if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log'))
381 381
 			$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
382 382
 		
383 383
 		return $return;
@@ -390,8 +390,8 @@  discard block
 block discarded – undo
390 390
 		
391 391
 		$contents = $this->get_tmp_filesystem()->listContents();
392 392
 	
393
-		if(is_array($contents))
394
-		foreach($contents as $file_info)
393
+		if (is_array($contents))
394
+		foreach ($contents as $file_info)
395 395
 			$this->get_tmp_filesystem()->delete($file_info['path']);
396 396
 			
397 397
 		@rmdir($this->xcloner_settings->get_xcloner_tmp_path());
@@ -403,16 +403,16 @@  discard block
 block discarded – undo
403 403
 	{
404 404
 		$this->files_counter = 0;
405 405
 		
406
-		if(!$this->storage_filesystem->has("index.html"))	
407
-			$this->storage_filesystem->write("index.html","");
406
+		if (!$this->storage_filesystem->has("index.html"))	
407
+			$this->storage_filesystem->write("index.html", "");
408 408
 		
409
-		if(!$this->tmp_filesystem->has("index.html"))	
410
-			$this->tmp_filesystem->write("index.html","");
409
+		if (!$this->tmp_filesystem->has("index.html"))	
410
+			$this->tmp_filesystem->write("index.html", "");
411 411
 			
412
-		if($this->tmp_filesystem->has($this->get_included_files_handler()))
412
+		if ($this->tmp_filesystem->has($this->get_included_files_handler()))
413 413
 			$this->tmp_filesystem->delete($this->get_included_files_handler());
414 414
 		
415
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler()))	
415
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler()))	
416 416
 			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
417 417
 	}
418 418
 	
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 	
434 434
 	public function set_excluded_files($excluded_files = array())
435 435
 	{
436
-		if(!is_array($excluded_files))
436
+		if (!is_array($excluded_files))
437 437
 			$excluded_files = array();
438 438
 			
439 439
 		$this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
@@ -456,33 +456,33 @@  discard block
 block discarded – undo
456 456
 		$this->logger->debug(sprintf(("Building the files system list")));
457 457
 		
458 458
 		//if we start with the root folder(empty value), we initializa the file system
459
-		if(!$folder){
459
+		if (!$folder) {
460 460
 			
461 461
 		}
462 462
 			
463
-		try{
463
+		try {
464 464
 			
465 465
 			$files = $this->start_filesystem->listContents($folder);
466
-			foreach($files as $file)
466
+			foreach ($files as $file)
467 467
 			{
468
-				if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path']))
468
+				if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path']))
469 469
 				{
470
-					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE"));
470
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN", "NOT READABLE"));
471 471
 				}
472
-				elseif(!$matching_pattern = $this->is_excluded($file) ){
473
-					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE"));
472
+				elseif (!$matching_pattern = $this->is_excluded($file)) {
473
+					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN", "INCLUDE"));
474 474
 					$file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
475 475
 					$this->store_file($file);
476 476
 					$this->files_counter++;
477
-					if(isset($file['size']))
477
+					if (isset($file['size']))
478 478
 						$this->files_size += $file['size'];
479 479
 					
480
-				}else{
481
-					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE"));
480
+				} else {
481
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN", "EXCLUDE"));
482 482
 					}
483 483
 			}
484 484
 			
485
-		}catch(Exception $e){
485
+		}catch (Exception $e) {
486 486
 			
487 487
 			$this->logger->error($e->getMessage());
488 488
 		
@@ -496,9 +496,9 @@  discard block
 block discarded – undo
496 496
 				
497 497
 		$start_time = microtime();
498 498
 		
499
-		$data = str_repeat(rand(0,9), 1024*1024); //write 1MB data
499
+		$data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data
500 500
 		
501
-		try{
501
+		try {
502 502
 			$this->tmp_filesystem->write($tmp_file, $data);
503 503
 			
504 504
 			$end_time = microtime() - $start_time;
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
 		
510 510
 			$this->tmp_filesystem->delete($tmp_file);
511 511
 		
512
-		}catch(Exception $e){
512
+		}catch (Exception $e) {
513 513
 			
514 514
 			$this->logger->error($e->getMessage());
515 515
 			
@@ -530,10 +530,10 @@  discard block
 block discarded – undo
530 530
 		
531 531
 		$files = $this->storage_filesystem->listContents();
532 532
 		
533
-		if(is_array($files))
534
-			foreach($files as $file)
533
+		if (is_array($files))
534
+			foreach ($files as $file)
535 535
 			{
536
-				if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions))
536
+				if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions))
537 537
 				{
538 538
 					$_storage_size += $file['size']; //bytes
539 539
 					$_backup_files_list[] = $file;
@@ -541,15 +541,15 @@  discard block
 block discarded – undo
541 541
 			}
542 542
 		
543 543
 		
544
-		$this->sort_by($_backup_files_list, "timestamp","asc");
544
+		$this->sort_by($_backup_files_list, "timestamp", "asc");
545 545
 		
546 546
 		$_backups_counter = sizeof($_backup_files_list);
547 547
 				
548
-		foreach($_backup_files_list as $file)
548
+		foreach ($_backup_files_list as $file)
549 549
 		{
550 550
 			//processing rule folder capacity
551
-			if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
552
-			$_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))	//bytes	
551
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
552
+			$_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))	//bytes	
553 553
 			{
554 554
 				$this->storage_filesystem->delete($file['path']);
555 555
 				$_storage_size -= $file['size'];
@@ -557,14 +557,14 @@  discard block
 block discarded – undo
557 557
 			}
558 558
 			
559 559
 			//processing rule days limit
560
-			if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp'])
560
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp'])
561 561
 			{
562 562
 				$this->storage_filesystem->delete($file['path']);
563 563
 				$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')));
564 564
 			}
565 565
 			
566 566
 			//processing backup countert limit
567
-			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'))
567
+			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'))
568 568
 			{
569 569
 				$this->storage_filesystem->delete($file['path']);
570 570
 				$_backups_counter--;
@@ -590,25 +590,25 @@  discard block
 block discarded – undo
590 590
 	
591 591
 	}
592 592
 	
593
-	public function process_backup_name($name = "", $max_length=100)
593
+	public function process_backup_name($name = "", $max_length = 100)
594 594
 	{
595
-		if(!$name)
595
+		if (!$name)
596 596
 			$name = $this->xcloner_settings->get_default_backup_name();
597 597
 		
598
-		foreach($this->backup_name_tags as $tag)
598
+		foreach ($this->backup_name_tags as $tag)
599 599
 		{
600
-			if($tag == '[time]')
601
-				$name = str_replace($tag, date("Y-m-d_H-i"),$name);
602
-			elseif($tag == '[hostname]')
603
-				$name = str_replace($tag, gethostname() ,$name);	
604
-			elseif($tag == '[domain]')
600
+			if ($tag == '[time]')
601
+				$name = str_replace($tag, date("Y-m-d_H-i"), $name);
602
+			elseif ($tag == '[hostname]')
603
+				$name = str_replace($tag, gethostname(), $name);	
604
+			elseif ($tag == '[domain]')
605 605
 			{
606 606
 				$domain = parse_url(admin_url(), PHP_URL_HOST);
607
-				$name = str_replace($tag, $domain ,$name);	
607
+				$name = str_replace($tag, $domain, $name);	
608 608
 			}
609 609
 		}
610 610
 		
611
-		if($max_length)
611
+		if ($max_length)
612 612
 			$name = substr($name, 0, $max_length);
613 613
 			
614 614
 		return $name;	
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
             return 0;
627 627
         }
628 628
 		
629
-		if(strlower($direction) == 'desc' )
629
+		if (strlower($direction) == 'desc')
630 630
 			return ($a > $b) ? -1 : 1;
631 631
 		else	
632 632
 			return ($a < $b) ? -1 : 1;
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
         //return ($a ($direction == 'desc' ? '>' : '<')  $b) ? -1 : 1;
635 635
 	}
636 636
 	
637
-	public function sort_by( &$array, $field, $direction = 'asc')
637
+	public function sort_by(&$array, $field, $direction = 'asc')
638 638
 	{
639 639
 		$direction = strtolower($direction);
640 640
 		
@@ -647,29 +647,29 @@  discard block
 block discarded – undo
647 647
 	{
648 648
 		$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
649 649
 		
650
-		if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb'))
650
+		if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb'))
651 651
 		{
652
-			if(isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb))
652
+			if (isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb))
653 653
 				return "> ".$xcloner_exclude_files_larger_than_mb."MB";
654 654
 		}
655 655
 		
656
-		if(!sizeof($this->excluded_files))
656
+		if (!sizeof($this->excluded_files))
657 657
 			$this->set_excluded_files();
658 658
 				
659
-		if(is_array($this->excluded_files))
660
-		foreach($this->excluded_files as $excluded_file_pattern)
659
+		if (is_array($this->excluded_files))
660
+		foreach ($this->excluded_files as $excluded_file_pattern)
661 661
 		{
662
-			if($excluded_file_pattern == "/")
662
+			if ($excluded_file_pattern == "/")
663 663
 				$needle = "$";
664 664
 			else
665 665
 				$needle = "$".$excluded_file_pattern;
666 666
 				
667
-			if(strstr("$".$file['path'], $needle)){
667
+			if (strstr("$".$file['path'], $needle)) {
668 668
 				return $excluded_file_pattern;
669 669
 			}
670 670
 		}
671 671
 		
672
-		if( $regex = $this->is_excluded_regex($file))
672
+		if ($regex = $this->is_excluded_regex($file))
673 673
 			return $regex;
674 674
 		
675 675
 		return false;
@@ -715,25 +715,25 @@  discard block
 block discarded – undo
715 715
 		
716 716
 		//print_r($regex_patterns);exit;
717 717
 		
718
-		if(is_array($regex_patterns))
718
+		if (is_array($regex_patterns))
719 719
 		{
720 720
 			//$this->excluded_files = array();
721 721
 			//$this->excluded_files[] ="(.*)\.(git)(.*)$";
722 722
 			//$this->excluded_files[] ="wp-content\/backups(.*)$";
723 723
 			
724
-			foreach($regex_patterns as $excluded_file_pattern)
724
+			foreach ($regex_patterns as $excluded_file_pattern)
725 725
 			{
726 726
 				
727
-				if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r")
728
-					$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1);
727
+				if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1, strlen($excluded_file_pattern)) == "\r")
728
+					$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1);
729 729
 					
730
-				if($file['path'] == "/")
730
+				if ($file['path'] == "/")
731 731
 					$needle = "/";
732 732
 				else
733 733
 					$needle = "/".$file['path'];
734 734
 				//echo $needle."---".$excluded_file_pattern."---\n";
735 735
 				
736
-				if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){
736
+				if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) {
737 737
 					return $excluded_file_pattern;
738 738
 				}
739 739
 			}
@@ -746,27 +746,27 @@  discard block
 block discarded – undo
746 746
 	{
747 747
 		$this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
748 748
 		
749
-		if(!isset($file['size']))
749
+		if (!isset($file['size']))
750 750
 			$file['size'] = 0;
751
-		if(!isset($file['visibility']))	
751
+		if (!isset($file['visibility']))	
752 752
 			$file['visibility'] = "private";
753 753
 		
754 754
 		$line = '"'.addslashes($file['path']).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL;
755 755
 		
756 756
 		$this->last_logged_file = $file['path'];
757 757
 		
758
-		try{
758
+		try {
759 759
 			$this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
760 760
 		
761
-		}catch(Exception $e){
761
+		}catch (Exception $e) {
762 762
 		
763 763
 			$this->logger->error($e->getMessage());	
764 764
 		}
765 765
 		
766
-		if($file['type'] == "dir"){
767
-			try{
766
+		if ($file['type'] == "dir") {
767
+			try {
768 768
 				$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n");
769
-			}catch(Exception $e){
769
+			}catch (Exception $e) {
770 770
 				$this->logger->error($e->getMessage());	
771 771
 			}
772 772
 		}
@@ -779,13 +779,13 @@  discard block
 block discarded – undo
779 779
 	
780 780
 	public function get_filesystem($system = "")
781 781
 	{
782
-		if($system == "storage_filesystem_append")
782
+		if ($system == "storage_filesystem_append")
783 783
 			return $this->storage_filesystem_append;
784
-		elseif($system == "tmp_filesystem_append")
784
+		elseif ($system == "tmp_filesystem_append")
785 785
 			return $this->tmp_filesystem_append;
786
-		elseif($system == "tmp_filesystem")
786
+		elseif ($system == "tmp_filesystem")
787 787
 			return $this->tmp_filesystem;
788
-		elseif($system == "storage_filesystem")
788
+		elseif ($system == "storage_filesystem")
789 789
 			return $this->storage_filesystem;
790 790
 		else
791 791
 			return $this->start_filesystem;	
@@ -793,9 +793,9 @@  discard block
 block discarded – undo
793 793
 	
794 794
 	public function get_adapter($system)
795 795
 	{
796
-		if($system == "tmp_filesystem")
796
+		if ($system == "tmp_filesystem")
797 797
 			return $this->tmp_adapter;
798
-		elseif($system == "storage_filesystem")
798
+		elseif ($system == "storage_filesystem")
799 799
 			return $this->storage_adapter;
800 800
 		else
801 801
 			return $this->start_adapter;	
@@ -803,10 +803,10 @@  discard block
 block discarded – undo
803 803
 	
804 804
 	private function scan_finished()
805 805
 	{
806
-		if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler()))
806
+		if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler()))
807 807
 			return false;
808 808
 		
809
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler()))
809
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler()))
810 810
 			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
811 811
 		
812 812
 		$this->logger->debug(sprintf(("File scan finished")));
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
 	
817 817
 	private function calc_to_bytes($mb_size)
818 818
 	{
819
-		return $mb_size*(1024*1024);
819
+		return $mb_size * (1024 * 1024);
820 820
 	}
821 821
 	
822 822
 }
Please login to merge, or discard this patch.