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 ( 0a67c8...aec3a2 )
by Liuta
03:06
created
includes/class-xcloner-file-system.php 4 patches
Doc Comments   +9 added lines patch added patch discarded remove patch
@@ -187,6 +187,9 @@  discard block
 block discarded – undo
187 187
 		return $total;		
188 188
 	}
189 189
 	
190
+	/**
191
+	 * @param string $backup_name
192
+	 */
190 193
 	public function is_part($backup_name)
191 194
 	{
192 195
 		if(stristr($backup_name, "-part"))
@@ -577,6 +580,9 @@  discard block
 block discarded – undo
577 580
 		
578 581
 	}
579 582
 	
583
+	/**
584
+	 * @param string $tmp_file
585
+	 */
580 586
 	public function estimate_reading_time($tmp_file)
581 587
 	{
582 588
 		$this->logger->debug(sprintf(("Estimating file system reading time")));
@@ -615,6 +621,9 @@  discard block
 block discarded – undo
615 621
 		return $name;	
616 622
 	}
617 623
 	
624
+	/**
625
+	 * @param string $field
626
+	 */
618 627
 	public function sort_by( &$array, $field, $direction = 'asc')
619 628
 	{
620 629
 		if(strtolower($direction) == "desc" || $direction == SORT_DESC)
Please login to merge, or discard this patch.
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -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.
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;
@@ -33,39 +33,39 @@  discard block
 block discarded – undo
33 33
 		$this->logger = new XCloner_Logger('xcloner_file_system', $hash);
34 34
 		$this->xcloner_requirements = new Xcloner_Requirements();
35 35
 
36
-		$this->xcloner_settings 		= new Xcloner_Settings($hash);
36
+		$this->xcloner_settings = new Xcloner_Settings($hash);
37 37
 
38
-		try{
38
+		try {
39 39
 			
40
-			$this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(),LOCK_EX, 'SKIP_LINKS');
40
+			$this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS');
41 41
 			$this->start_filesystem = new Filesystem($this->start_adapter, new Config([
42 42
 					'disable_asserts' => true,
43 43
 				]));
44 44
 			
45
-			$this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX, 'SKIP_LINKS');
45
+			$this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS');
46 46
 			$this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([
47 47
 					'disable_asserts' => true,
48 48
 				]));
49
-			$adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX|FILE_APPEND, 'SKIP_LINKS');
49
+			$adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
50 50
 			$this->tmp_filesystem_append = new Filesystem($adapter, new Config([
51 51
 					'disable_asserts' => true,
52 52
 				]));
53 53
 
54
-			$adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),LOCK_EX, 'SKIP_LINKS');
54
+			$adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS');
55 55
 			$this->storage_filesystem = new Filesystem($adapter, new Config([
56 56
 					'disable_asserts' => true,
57 57
 				]));	
58 58
 			
59
-			$this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),FILE_APPEND, 'SKIP_LINKS');
59
+			$this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND, 'SKIP_LINKS');
60 60
 			$this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([
61 61
 					'disable_asserts' => true,
62 62
 				]));
63
-		}catch(Exception $e){
63
+		}catch (Exception $e) {
64 64
 			return false;
65 65
 		}
66 66
 		
67 67
 		
68
-		if($value = get_option('xcloner_directories_to_scan_per_request'))
68
+		if ($value = get_option('xcloner_directories_to_scan_per_request'))
69 69
 			$this->folders_to_process_per_session = $value;
70 70
 
71 71
 	}
@@ -126,10 +126,10 @@  discard block
 block discarded – undo
126 126
 		return $this->getMetadataFull('storage_adapter', $file);
127 127
 	}
128 128
 	
129
-	public function get_included_files_handler($metadata  = 0)
129
+	public function get_included_files_handler($metadata = 0)
130 130
 	{
131 131
 		$path = $this->included_files_handler;
132
-		if(!$metadata)
132
+		if (!$metadata)
133 133
 			return $path;
134 134
 		
135 135
 		$spl_info = $this->getMetadataFull('tmp_adapter', $path);
@@ -146,16 +146,16 @@  discard block
 block discarded – undo
146 146
 	{
147 147
 		$files = $this->get_backup_archives_list();
148 148
 		
149
-		if(is_array($files))
150
-			$this->sort_by($files, "timestamp","desc");
149
+		if (is_array($files))
150
+			$this->sort_by($files, "timestamp", "desc");
151 151
 		
152 152
 		$new_list = array();
153 153
 		
154
-		foreach($files as $key=>$file)
155
-			if(!isset($file['parent']))
154
+		foreach ($files as $key=>$file)
155
+			if (!isset($file['parent']))
156 156
 				$new_list[] = ($files[$key]);
157 157
 
158
-		if(isset($new_list[0]))
158
+		if (isset($new_list[0]))
159 159
 			return $new_list[0];
160 160
 	}
161 161
 	
@@ -163,13 +163,13 @@  discard block
 block discarded – undo
163 163
 	{
164 164
 		$files = $this->get_backup_archives_list();
165 165
 
166
-		if(is_array($files))
167
-			$this->sort_by($files, "timestamp","desc");
166
+		if (is_array($files))
167
+			$this->sort_by($files, "timestamp", "desc");
168 168
 		
169 169
 		$new_list = array();
170 170
 		
171
-		foreach($files as $key=>$file)
172
-			if(!isset($file['parent']))
171
+		foreach ($files as $key=>$file)
172
+			if (!isset($file['parent']))
173 173
 				$new_list[] = ($files[$key]);
174 174
 
175 175
 		return $new_list;
@@ -180,8 +180,8 @@  discard block
 block discarded – undo
180 180
 		$files = $this->get_backup_archives_list();
181 181
 		$total = 0;
182 182
 		
183
-		if(is_array($files))
184
-			foreach($files as $file)
183
+		if (is_array($files))
184
+			foreach ($files as $file)
185 185
 				$total += $file['size'];
186 186
 				
187 187
 		return $total;		
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	
190 190
 	public function is_part($backup_name)
191 191
 	{
192
-		if(stristr($backup_name, "-part"))
192
+		if (stristr($backup_name, "-part"))
193 193
 			return true;
194 194
 		
195 195
 		return false;	
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	
198 198
 	public function is_multipart($backup_name)
199 199
 	{
200
-		if(stristr($backup_name, "-multipart"))
200
+		if (stristr($backup_name, "-multipart"))
201 201
 			return true;
202 202
 		
203 203
 		return false;	
@@ -206,10 +206,10 @@  discard block
 block discarded – undo
206 206
 	public function get_backup_size($backup_name)
207 207
 	{
208 208
 		$backup_size = $this->get_storage_filesystem()->getSize($backup_name);
209
-		if($this->is_multipart($backup_name))
209
+		if ($this->is_multipart($backup_name))
210 210
 		{
211 211
 			$backup_parts = $this->get_multipart_files($backup_name);
212
-			foreach($backup_parts as $part_file)
212
+			foreach ($backup_parts as $part_file)
213 213
 				$backup_size += $this->get_storage_filesystem()->getSize($part_file);
214 214
 		}
215 215
 		
@@ -220,12 +220,12 @@  discard block
 block discarded – undo
220 220
 	{
221 221
 		$files = array();
222 222
 		
223
-		if($this->is_multipart($backup_name))
223
+		if ($this->is_multipart($backup_name))
224 224
 		{
225 225
 			$lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($backup_name));
226
-			foreach($lines as $line)
226
+			foreach ($lines as $line)
227 227
 			{
228
-				if($line)
228
+				if ($line)
229 229
 				{
230 230
 					$data = str_getcsv($line);
231 231
 					$files[] = $data[0];
@@ -238,12 +238,12 @@  discard block
 block discarded – undo
238 238
 	
239 239
 	public function delete_backup_by_name($backup_name)
240 240
 	{
241
-		if($this->is_multipart($backup_name))
241
+		if ($this->is_multipart($backup_name))
242 242
 		{
243 243
 			$lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($backup_name));
244
-			foreach($lines as $line)
244
+			foreach ($lines as $line)
245 245
 			{
246
-				if($line)
246
+				if ($line)
247 247
 				{
248 248
 					$data = str_getcsv($line);
249 249
 					$this->get_storage_filesystem()->delete($data[0]);
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 			}
252 252
 		}
253 253
 		
254
-		if($this->get_storage_filesystem()->delete($backup_name))
254
+		if ($this->get_storage_filesystem()->delete($backup_name))
255 255
 			$return = true;
256 256
 		else
257 257
 			$return = false;
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 		return $return;	
260 260
 	}
261 261
 	
262
-	public function getMetadataFull($adapter = "storage_adapter" , $path)
262
+	public function getMetadataFull($adapter = "storage_adapter", $path)
263 263
     {
264 264
         $location = $this->$adapter->applyPathPrefix($path);
265 265
         $spl_info = new SplFileInfo($location);
@@ -272,25 +272,25 @@  discard block
 block discarded – undo
272 272
 	{
273 273
 		$list = array();
274 274
 		
275
-		if(method_exists($this->get_storage_filesystem(), "listContents"))
275
+		if (method_exists($this->get_storage_filesystem(), "listContents"))
276 276
 			$list = $this->get_storage_filesystem()->listContents();
277 277
 
278 278
 		
279 279
 		$backup_files = array();
280 280
 		$parents = array();
281 281
 		
282
-		foreach($list as $file_info)
282
+		foreach ($list as $file_info)
283 283
 		{
284 284
 			$data = array();
285 285
 			
286
-			if(isset($file_info['extension']) and $file_info['extension'] == "csv")
286
+			if (isset($file_info['extension']) and $file_info['extension'] == "csv")
287 287
 			{
288 288
 				$lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($file_info['path']));
289
-				foreach($lines as $line)
290
-					if($line)
289
+				foreach ($lines as $line)
290
+					if ($line)
291 291
 					{
292 292
 						$data = str_getcsv($line);
293
-						if(is_array($data)){
293
+						if (is_array($data)) {
294 294
 							$parents[$data[0]] = $file_info['path'];
295 295
 							$file_info['childs'][] = $data;
296 296
 							$file_info['size'] += $data[2];
@@ -299,13 +299,13 @@  discard block
 block discarded – undo
299 299
 						
300 300
 			}
301 301
 			
302
-			if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions))
302
+			if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions))
303 303
 				$backup_files[$file_info['path']] = $file_info;
304 304
 		}
305 305
 		
306
-		foreach($backup_files as $key=>$file_info)
306
+		foreach ($backup_files as $key=>$file_info)
307 307
 		{
308
-			if(isset($parents[$file_info['path']]))
308
+			if (isset($parents[$file_info['path']]))
309 309
 				$backup_files[$key]['parent'] = $parents[$file_info['path']];
310 310
 		}
311 311
 		
@@ -314,40 +314,40 @@  discard block
 block discarded – undo
314 314
 	
315 315
 	public function start_file_recursion($init = 0)
316 316
 	{
317
-		if($init)
317
+		if ($init)
318 318
 		{
319 319
 			$this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"), $this->xcloner_settings->get_xcloner_start_path()));
320 320
 			$this->do_system_init();
321 321
 		}
322 322
 		
323
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler())){
323
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
324 324
 		//.dir exists, we presume we have files to iterate	
325 325
 			$content = $this->tmp_filesystem->read($this->get_temp_dir_handler());
326 326
 			$files = array_filter(explode("\n", $content));
327 327
 			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
328 328
 			
329 329
 			$counter = 0;
330
-			foreach($files as $file)
330
+			foreach ($files as $file)
331 331
 			{
332
-				if($counter < $this->folders_to_process_per_session){
332
+				if ($counter < $this->folders_to_process_per_session) {
333 333
 					$this->build_files_list($file);
334 334
 					$counter++;
335
-				}else{
335
+				} else {
336 336
 					$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n");
337 337
 				}
338 338
 			}
339
-		}else{
339
+		} else {
340 340
 			$this->build_files_list();
341 341
 		}
342 342
 		
343
-		if($this->scan_finished())
343
+		if ($this->scan_finished())
344 344
 		{
345 345
 			$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html");
346 346
 			$this->store_file($metadata_dumpfile, 'tmp_filesystem');
347 347
 			$this->files_counter++;
348 348
 		
349 349
 			//adding included dump file to the included files list
350
-			if($this->get_tmp_filesystem()->has($this->get_included_files_handler()))
350
+			if ($this->get_tmp_filesystem()->has($this->get_included_files_handler()))
351 351
 			{
352 352
 				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler());
353 353
 				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
@@ -355,13 +355,13 @@  discard block
 block discarded – undo
355 355
 			}
356 356
 		
357 357
 			//adding a default index.html to the temp xcloner folder
358
-			if(!$this->get_tmp_filesystem()->has("index.html"))
358
+			if (!$this->get_tmp_filesystem()->has("index.html"))
359 359
 			{
360
-				$this->get_tmp_filesystem()->write("index.html","");
360
+				$this->get_tmp_filesystem()->write("index.html", "");
361 361
 			}
362 362
 			
363 363
 			//adding the default log file
364
-			if($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1)))
364
+			if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1)))
365 365
 			{
366 366
 				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1));
367 367
 				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 	{
379 379
 		$return = array();
380 380
 		$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler();
381
-		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log'))
381
+		if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log'))
382 382
 			$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
383 383
 		
384 384
 		return $return;
@@ -391,8 +391,8 @@  discard block
 block discarded – undo
391 391
 		
392 392
 		$contents = $this->get_tmp_filesystem()->listContents();
393 393
 	
394
-		if(is_array($contents))
395
-		foreach($contents as $file_info)
394
+		if (is_array($contents))
395
+		foreach ($contents as $file_info)
396 396
 			$this->get_tmp_filesystem()->delete($file_info['path']);
397 397
 			
398 398
 		@rmdir($this->xcloner_settings->get_xcloner_tmp_path());
@@ -404,16 +404,16 @@  discard block
 block discarded – undo
404 404
 	{
405 405
 		$this->files_counter = 0;
406 406
 		
407
-		if(!$this->storage_filesystem->has("index.html"))	
408
-			$this->storage_filesystem->write("index.html","");
407
+		if (!$this->storage_filesystem->has("index.html"))	
408
+			$this->storage_filesystem->write("index.html", "");
409 409
 		
410
-		if(!$this->tmp_filesystem->has("index.html"))	
411
-			$this->tmp_filesystem->write("index.html","");
410
+		if (!$this->tmp_filesystem->has("index.html"))	
411
+			$this->tmp_filesystem->write("index.html", "");
412 412
 			
413
-		if($this->tmp_filesystem->has($this->get_included_files_handler()))
413
+		if ($this->tmp_filesystem->has($this->get_included_files_handler()))
414 414
 			$this->tmp_filesystem->delete($this->get_included_files_handler());
415 415
 		
416
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler()))	
416
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler()))	
417 417
 			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
418 418
 	}
419 419
 	
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 	
435 435
 	public function set_excluded_files($excluded_files = array())
436 436
 	{
437
-		if(!is_array($excluded_files))
437
+		if (!is_array($excluded_files))
438 438
 			$excluded_files = array();
439 439
 			
440 440
 		$this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
@@ -457,33 +457,33 @@  discard block
 block discarded – undo
457 457
 		$this->logger->debug(sprintf(("Building the files system list")));
458 458
 		
459 459
 		//if we start with the root folder(empty value), we initializa the file system
460
-		if(!$folder){
460
+		if (!$folder) {
461 461
 			
462 462
 		}
463 463
 			
464
-		try{
464
+		try {
465 465
 			
466 466
 			$files = $this->start_filesystem->listContents($folder);
467
-			foreach($files as $file)
467
+			foreach ($files as $file)
468 468
 			{
469
-				if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path']))
469
+				if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path']))
470 470
 				{
471
-					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE"));
471
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN", "NOT READABLE"));
472 472
 				}
473
-				elseif(!$matching_pattern = $this->is_excluded($file) ){
474
-					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE"));
473
+				elseif (!$matching_pattern = $this->is_excluded($file)) {
474
+					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN", "INCLUDE"));
475 475
 					$file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
476 476
 					$this->store_file($file);
477 477
 					$this->files_counter++;
478
-					if(isset($file['size']))
478
+					if (isset($file['size']))
479 479
 						$this->files_size += $file['size'];
480 480
 					
481
-				}else{
482
-					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE"));
481
+				} else {
482
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN", "EXCLUDE"));
483 483
 					}
484 484
 			}
485 485
 			
486
-		}catch(Exception $e){
486
+		}catch (Exception $e) {
487 487
 			
488 488
 			$this->logger->error($e->getMessage());
489 489
 		
@@ -497,9 +497,9 @@  discard block
 block discarded – undo
497 497
 				
498 498
 		$start_time = microtime();
499 499
 		
500
-		$data = str_repeat(rand(0,9), 1024*1024); //write 1MB data
500
+		$data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data
501 501
 		
502
-		try{
502
+		try {
503 503
 			$this->tmp_filesystem->write($tmp_file, $data);
504 504
 			
505 505
 			$end_time = microtime() - $start_time;
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 		
511 511
 			$this->tmp_filesystem->delete($tmp_file);
512 512
 		
513
-		}catch(Exception $e){
513
+		}catch (Exception $e) {
514 514
 			
515 515
 			$this->logger->error($e->getMessage());
516 516
 			
@@ -531,10 +531,10 @@  discard block
 block discarded – undo
531 531
 		
532 532
 		$files = $this->storage_filesystem->listContents();
533 533
 		
534
-		if(is_array($files))
535
-			foreach($files as $file)
534
+		if (is_array($files))
535
+			foreach ($files as $file)
536 536
 			{
537
-				if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions))
537
+				if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions))
538 538
 				{
539 539
 					$_storage_size += $file['size']; //bytes
540 540
 					$_backup_files_list[] = $file;
@@ -542,15 +542,15 @@  discard block
 block discarded – undo
542 542
 			}
543 543
 		
544 544
 		
545
-		$this->sort_by($_backup_files_list, "timestamp","asc");
545
+		$this->sort_by($_backup_files_list, "timestamp", "asc");
546 546
 		
547 547
 		$_backups_counter = sizeof($_backup_files_list);
548 548
 				
549
-		foreach($_backup_files_list as $file)
549
+		foreach ($_backup_files_list as $file)
550 550
 		{
551 551
 			//processing rule folder capacity
552
-			if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
553
-			$_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))	//bytes	
552
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
553
+			$_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))	//bytes	
554 554
 			{
555 555
 				$this->storage_filesystem->delete($file['path']);
556 556
 				$_storage_size -= $file['size'];
@@ -558,14 +558,14 @@  discard block
 block discarded – undo
558 558
 			}
559 559
 			
560 560
 			//processing rule days limit
561
-			if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp'])
561
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp'])
562 562
 			{
563 563
 				$this->storage_filesystem->delete($file['path']);
564 564
 				$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')));
565 565
 			}
566 566
 			
567 567
 			//processing backup countert limit
568
-			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
+			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'))
569 569
 			{
570 570
 				$this->storage_filesystem->delete($file['path']);
571 571
 				$_backups_counter--;
@@ -591,33 +591,33 @@  discard block
 block discarded – undo
591 591
 	
592 592
 	}
593 593
 	
594
-	public function process_backup_name($name = "", $max_length=100)
594
+	public function process_backup_name($name = "", $max_length = 100)
595 595
 	{
596
-		if(!$name)
596
+		if (!$name)
597 597
 			$name = $this->xcloner_settings->get_default_backup_name();
598 598
 		
599
-		foreach($this->backup_name_tags as $tag)
599
+		foreach ($this->backup_name_tags as $tag)
600 600
 		{
601
-			if($tag == '[time]')
602
-				$name = str_replace($tag, date("Y-m-d_H-i"),$name);
603
-			elseif($tag == '[hostname]')
604
-				$name = str_replace($tag, gethostname() ,$name);	
605
-			elseif($tag == '[domain]')
601
+			if ($tag == '[time]')
602
+				$name = str_replace($tag, date("Y-m-d_H-i"), $name);
603
+			elseif ($tag == '[hostname]')
604
+				$name = str_replace($tag, gethostname(), $name);	
605
+			elseif ($tag == '[domain]')
606 606
 			{
607 607
 				$domain = parse_url(admin_url(), PHP_URL_HOST);
608
-				$name = str_replace($tag, $domain ,$name);	
608
+				$name = str_replace($tag, $domain, $name);	
609 609
 			}
610 610
 		}
611 611
 		
612
-		if($max_length)
612
+		if ($max_length)
613 613
 			$name = substr($name, 0, $max_length);
614 614
 			
615 615
 		return $name;	
616 616
 	}
617 617
 	
618
-	public function sort_by( &$array, $field, $direction = 'asc')
618
+	public function sort_by(&$array, $field, $direction = 'asc')
619 619
 	{
620
-		if(strtolower($direction) == "desc" || $direction == SORT_DESC)
620
+		if (strtolower($direction) == "desc" || $direction == SORT_DESC)
621 621
 			$direction = SORT_DESC;
622 622
 		else
623 623
 			$direction = SORT_ASC;
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
 	            $tmp = array();
638 638
 	            foreach ($data as $key => $row)
639 639
 	            {
640
-					if(is_array($row))
640
+					if (is_array($row))
641 641
 						$tmp[$key] = $row[$field];
642 642
 					else
643 643
 						$tmp[$key] = $row->$field;
@@ -656,29 +656,29 @@  discard block
 block discarded – undo
656 656
 	{
657 657
 		$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
658 658
 		
659
-		if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb'))
659
+		if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb'))
660 660
 		{
661
-			if(isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb))
661
+			if (isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb))
662 662
 				return "> ".$xcloner_exclude_files_larger_than_mb."MB";
663 663
 		}
664 664
 		
665
-		if(!sizeof($this->excluded_files))
665
+		if (!sizeof($this->excluded_files))
666 666
 			$this->set_excluded_files();
667 667
 				
668
-		if(is_array($this->excluded_files))
669
-		foreach($this->excluded_files as $excluded_file_pattern)
668
+		if (is_array($this->excluded_files))
669
+		foreach ($this->excluded_files as $excluded_file_pattern)
670 670
 		{
671
-			if($excluded_file_pattern == "/")
671
+			if ($excluded_file_pattern == "/")
672 672
 				$needle = "$";
673 673
 			else
674 674
 				$needle = "$".$excluded_file_pattern;
675 675
 				
676
-			if(strstr("$".$file['path'], $needle)){
676
+			if (strstr("$".$file['path'], $needle)) {
677 677
 				return $excluded_file_pattern;
678 678
 			}
679 679
 		}
680 680
 		
681
-		if( $regex = $this->is_excluded_regex($file))
681
+		if ($regex = $this->is_excluded_regex($file))
682 682
 			return $regex;
683 683
 		
684 684
 		return false;
@@ -724,25 +724,25 @@  discard block
 block discarded – undo
724 724
 		
725 725
 		//print_r($regex_patterns);exit;
726 726
 		
727
-		if(is_array($regex_patterns))
727
+		if (is_array($regex_patterns))
728 728
 		{
729 729
 			//$this->excluded_files = array();
730 730
 			//$this->excluded_files[] ="(.*)\.(git)(.*)$";
731 731
 			//$this->excluded_files[] ="wp-content\/backups(.*)$";
732 732
 			
733
-			foreach($regex_patterns as $excluded_file_pattern)
733
+			foreach ($regex_patterns as $excluded_file_pattern)
734 734
 			{
735 735
 				
736
-				if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r")
737
-					$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1);
736
+				if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1, strlen($excluded_file_pattern)) == "\r")
737
+					$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1);
738 738
 					
739
-				if($file['path'] == "/")
739
+				if ($file['path'] == "/")
740 740
 					$needle = "/";
741 741
 				else
742 742
 					$needle = "/".$file['path'];
743 743
 				//echo $needle."---".$excluded_file_pattern."---\n";
744 744
 				
745
-				if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){
745
+				if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) {
746 746
 					return $excluded_file_pattern;
747 747
 				}
748 748
 			}
@@ -755,27 +755,27 @@  discard block
 block discarded – undo
755 755
 	{
756 756
 		$this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
757 757
 		
758
-		if(!isset($file['size']))
758
+		if (!isset($file['size']))
759 759
 			$file['size'] = 0;
760
-		if(!isset($file['visibility']))	
760
+		if (!isset($file['visibility']))	
761 761
 			$file['visibility'] = "private";
762 762
 		
763 763
 		$line = '"'.addslashes($file['path']).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL;
764 764
 		
765 765
 		$this->last_logged_file = $file['path'];
766 766
 		
767
-		try{
767
+		try {
768 768
 			$this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
769 769
 		
770
-		}catch(Exception $e){
770
+		}catch (Exception $e) {
771 771
 		
772 772
 			$this->logger->error($e->getMessage());	
773 773
 		}
774 774
 		
775
-		if($file['type'] == "dir"){
776
-			try{
775
+		if ($file['type'] == "dir") {
776
+			try {
777 777
 				$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n");
778
-			}catch(Exception $e){
778
+			}catch (Exception $e) {
779 779
 				$this->logger->error($e->getMessage());	
780 780
 			}
781 781
 		}
@@ -788,13 +788,13 @@  discard block
 block discarded – undo
788 788
 	
789 789
 	public function get_filesystem($system = "")
790 790
 	{
791
-		if($system == "storage_filesystem_append")
791
+		if ($system == "storage_filesystem_append")
792 792
 			return $this->storage_filesystem_append;
793
-		elseif($system == "tmp_filesystem_append")
793
+		elseif ($system == "tmp_filesystem_append")
794 794
 			return $this->tmp_filesystem_append;
795
-		elseif($system == "tmp_filesystem")
795
+		elseif ($system == "tmp_filesystem")
796 796
 			return $this->tmp_filesystem;
797
-		elseif($system == "storage_filesystem")
797
+		elseif ($system == "storage_filesystem")
798 798
 			return $this->storage_filesystem;
799 799
 		else
800 800
 			return $this->start_filesystem;	
@@ -802,9 +802,9 @@  discard block
 block discarded – undo
802 802
 	
803 803
 	public function get_adapter($system)
804 804
 	{
805
-		if($system == "tmp_filesystem")
805
+		if ($system == "tmp_filesystem")
806 806
 			return $this->tmp_adapter;
807
-		elseif($system == "storage_filesystem")
807
+		elseif ($system == "storage_filesystem")
808 808
 			return $this->storage_adapter;
809 809
 		else
810 810
 			return $this->start_adapter;	
@@ -812,10 +812,10 @@  discard block
 block discarded – undo
812 812
 	
813 813
 	private function scan_finished()
814 814
 	{
815
-		if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler()))
815
+		if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler()))
816 816
 			return false;
817 817
 		
818
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler()))
818
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler()))
819 819
 			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
820 820
 		
821 821
 		$this->logger->debug(sprintf(("File scan finished")));
@@ -825,7 +825,7 @@  discard block
 block discarded – undo
825 825
 	
826 826
 	private function calc_to_bytes($mb_size)
827 827
 	{
828
-		return $mb_size*(1024*1024);
828
+		return $mb_size * (1024 * 1024);
829 829
 	}
830 830
 	
831 831
 }
Please login to merge, or discard this patch.
Braces   +164 added lines, -121 removed lines patch added patch discarded remove patch
@@ -60,13 +60,14 @@  discard block
 block discarded – undo
60 60
 			$this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([
61 61
 					'disable_asserts' => true,
62 62
 				]));
63
-		}catch(Exception $e){
63
+		} catch(Exception $e){
64 64
 			return false;
65 65
 		}
66 66
 		
67 67
 		
68
-		if($value = get_option('xcloner_directories_to_scan_per_request'))
69
-			$this->folders_to_process_per_session = $value;
68
+		if($value = get_option('xcloner_directories_to_scan_per_request')) {
69
+					$this->folders_to_process_per_session = $value;
70
+		}
70 71
 
71 72
 	}
72 73
 	
@@ -129,8 +130,9 @@  discard block
 block discarded – undo
129 130
 	public function get_included_files_handler($metadata  = 0)
130 131
 	{
131 132
 		$path = $this->included_files_handler;
132
-		if(!$metadata)
133
-			return $path;
133
+		if(!$metadata) {
134
+					return $path;
135
+		}
134 136
 		
135 137
 		$spl_info = $this->getMetadataFull('tmp_adapter', $path);
136 138
 		return $spl_info;
@@ -146,31 +148,36 @@  discard block
 block discarded – undo
146 148
 	{
147 149
 		$files = $this->get_backup_archives_list();
148 150
 		
149
-		if(is_array($files))
150
-			$this->sort_by($files, "timestamp","desc");
151
+		if(is_array($files)) {
152
+					$this->sort_by($files, "timestamp","desc");
153
+		}
151 154
 		
152 155
 		$new_list = array();
153 156
 		
154
-		foreach($files as $key=>$file)
155
-			if(!isset($file['parent']))
157
+		foreach($files as $key=>$file) {
158
+					if(!isset($file['parent']))
156 159
 				$new_list[] = ($files[$key]);
160
+		}
157 161
 
158
-		if(isset($new_list[0]))
159
-			return $new_list[0];
162
+		if(isset($new_list[0])) {
163
+					return $new_list[0];
164
+		}
160 165
 	}
161 166
 	
162 167
 	public function get_latest_backups()
163 168
 	{
164 169
 		$files = $this->get_backup_archives_list();
165 170
 
166
-		if(is_array($files))
167
-			$this->sort_by($files, "timestamp","desc");
171
+		if(is_array($files)) {
172
+					$this->sort_by($files, "timestamp","desc");
173
+		}
168 174
 		
169 175
 		$new_list = array();
170 176
 		
171
-		foreach($files as $key=>$file)
172
-			if(!isset($file['parent']))
177
+		foreach($files as $key=>$file) {
178
+					if(!isset($file['parent']))
173 179
 				$new_list[] = ($files[$key]);
180
+		}
174 181
 
175 182
 		return $new_list;
176 183
 	}
@@ -180,25 +187,28 @@  discard block
 block discarded – undo
180 187
 		$files = $this->get_backup_archives_list();
181 188
 		$total = 0;
182 189
 		
183
-		if(is_array($files))
184
-			foreach($files as $file)
190
+		if(is_array($files)) {
191
+					foreach($files as $file)
185 192
 				$total += $file['size'];
193
+		}
186 194
 				
187 195
 		return $total;		
188 196
 	}
189 197
 	
190 198
 	public function is_part($backup_name)
191 199
 	{
192
-		if(stristr($backup_name, "-part"))
193
-			return true;
200
+		if(stristr($backup_name, "-part")) {
201
+					return true;
202
+		}
194 203
 		
195 204
 		return false;	
196 205
 	}
197 206
 	
198 207
 	public function is_multipart($backup_name)
199 208
 	{
200
-		if(stristr($backup_name, "-multipart"))
201
-			return true;
209
+		if(stristr($backup_name, "-multipart")) {
210
+					return true;
211
+		}
202 212
 		
203 213
 		return false;	
204 214
 	}
@@ -209,8 +219,9 @@  discard block
 block discarded – undo
209 219
 		if($this->is_multipart($backup_name))
210 220
 		{
211 221
 			$backup_parts = $this->get_multipart_files($backup_name);
212
-			foreach($backup_parts as $part_file)
213
-				$backup_size += $this->get_storage_filesystem()->getSize($part_file);
222
+			foreach($backup_parts as $part_file) {
223
+							$backup_size += $this->get_storage_filesystem()->getSize($part_file);
224
+			}
214 225
 		}
215 226
 		
216 227
 		return $backup_size;
@@ -251,10 +262,11 @@  discard block
 block discarded – undo
251 262
 			}
252 263
 		}
253 264
 		
254
-		if($this->get_storage_filesystem()->delete($backup_name))
255
-			$return = true;
256
-		else
257
-			$return = false;
265
+		if($this->get_storage_filesystem()->delete($backup_name)) {
266
+					$return = true;
267
+		} else {
268
+					$return = false;
269
+		}
258 270
 			
259 271
 		return $return;	
260 272
 	}
@@ -272,8 +284,9 @@  discard block
 block discarded – undo
272 284
 	{
273 285
 		$list = array();
274 286
 		
275
-		if(method_exists($this->get_storage_filesystem(), "listContents"))
276
-			$list = $this->get_storage_filesystem()->listContents();
287
+		if(method_exists($this->get_storage_filesystem(), "listContents")) {
288
+					$list = $this->get_storage_filesystem()->listContents();
289
+		}
277 290
 
278 291
 		
279 292
 		$backup_files = array();
@@ -286,10 +299,11 @@  discard block
 block discarded – undo
286 299
 			if(isset($file_info['extension']) and $file_info['extension'] == "csv")
287 300
 			{
288 301
 				$lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($file_info['path']));
289
-				foreach($lines as $line)
290
-					if($line)
302
+				foreach($lines as $line) {
303
+									if($line)
291 304
 					{
292 305
 						$data = str_getcsv($line);
306
+				}
293 307
 						if(is_array($data)){
294 308
 							$parents[$data[0]] = $file_info['path'];
295 309
 							$file_info['childs'][] = $data;
@@ -299,14 +313,16 @@  discard block
 block discarded – undo
299 313
 						
300 314
 			}
301 315
 			
302
-			if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions))
303
-				$backup_files[$file_info['path']] = $file_info;
316
+			if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) {
317
+							$backup_files[$file_info['path']] = $file_info;
318
+			}
304 319
 		}
305 320
 		
306 321
 		foreach($backup_files as $key=>$file_info)
307 322
 		{
308
-			if(isset($parents[$file_info['path']]))
309
-				$backup_files[$key]['parent'] = $parents[$file_info['path']];
323
+			if(isset($parents[$file_info['path']])) {
324
+							$backup_files[$key]['parent'] = $parents[$file_info['path']];
325
+			}
310 326
 		}
311 327
 		
312 328
 		return $backup_files;
@@ -332,11 +348,11 @@  discard block
 block discarded – undo
332 348
 				if($counter < $this->folders_to_process_per_session){
333 349
 					$this->build_files_list($file);
334 350
 					$counter++;
335
-				}else{
351
+				} else{
336 352
 					$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n");
337 353
 				}
338 354
 			}
339
-		}else{
355
+		} else{
340 356
 			$this->build_files_list();
341 357
 		}
342 358
 		
@@ -378,8 +394,9 @@  discard block
 block discarded – undo
378 394
 	{
379 395
 		$return = array();
380 396
 		$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler();
381
-		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log'))
382
-			$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
397
+		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
398
+					$return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
399
+		}
383 400
 		
384 401
 		return $return;
385 402
 	}
@@ -391,9 +408,10 @@  discard block
 block discarded – undo
391 408
 		
392 409
 		$contents = $this->get_tmp_filesystem()->listContents();
393 410
 	
394
-		if(is_array($contents))
395
-		foreach($contents as $file_info)
411
+		if(is_array($contents)) {
412
+				foreach($contents as $file_info)
396 413
 			$this->get_tmp_filesystem()->delete($file_info['path']);
414
+		}
397 415
 			
398 416
 		@rmdir($this->xcloner_settings->get_xcloner_tmp_path());
399 417
 		
@@ -404,17 +422,21 @@  discard block
 block discarded – undo
404 422
 	{
405 423
 		$this->files_counter = 0;
406 424
 		
407
-		if(!$this->storage_filesystem->has("index.html"))	
408
-			$this->storage_filesystem->write("index.html","");
425
+		if(!$this->storage_filesystem->has("index.html")) {
426
+					$this->storage_filesystem->write("index.html","");
427
+		}
409 428
 		
410
-		if(!$this->tmp_filesystem->has("index.html"))	
411
-			$this->tmp_filesystem->write("index.html","");
429
+		if(!$this->tmp_filesystem->has("index.html")) {
430
+					$this->tmp_filesystem->write("index.html","");
431
+		}
412 432
 			
413
-		if($this->tmp_filesystem->has($this->get_included_files_handler()))
414
-			$this->tmp_filesystem->delete($this->get_included_files_handler());
433
+		if($this->tmp_filesystem->has($this->get_included_files_handler())) {
434
+					$this->tmp_filesystem->delete($this->get_included_files_handler());
435
+		}
415 436
 		
416
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler()))	
417
-			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
437
+		if($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
438
+					$this->tmp_filesystem->delete($this->get_temp_dir_handler());
439
+		}
418 440
 	}
419 441
 	
420 442
 	public function get_scanned_files_num()
@@ -434,8 +456,9 @@  discard block
 block discarded – undo
434 456
 	
435 457
 	public function set_excluded_files($excluded_files = array())
436 458
 	{
437
-		if(!is_array($excluded_files))
438
-			$excluded_files = array();
459
+		if(!is_array($excluded_files)) {
460
+					$excluded_files = array();
461
+		}
439 462
 			
440 463
 		$this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
441 464
 		
@@ -469,21 +492,21 @@  discard block
 block discarded – undo
469 492
 				if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path']))
470 493
 				{
471 494
 					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE"));
472
-				}
473
-				elseif(!$matching_pattern = $this->is_excluded($file) ){
495
+				} elseif(!$matching_pattern = $this->is_excluded($file) ){
474 496
 					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE"));
475 497
 					$file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
476 498
 					$this->store_file($file);
477 499
 					$this->files_counter++;
478
-					if(isset($file['size']))
479
-						$this->files_size += $file['size'];
500
+					if(isset($file['size'])) {
501
+											$this->files_size += $file['size'];
502
+					}
480 503
 					
481
-				}else{
504
+				} else{
482 505
 					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE"));
483 506
 					}
484 507
 			}
485 508
 			
486
-		}catch(Exception $e){
509
+		} catch(Exception $e){
487 510
 			
488 511
 			$this->logger->error($e->getMessage());
489 512
 		
@@ -510,7 +533,7 @@  discard block
 block discarded – undo
510 533
 		
511 534
 			$this->tmp_filesystem->delete($tmp_file);
512 535
 		
513
-		}catch(Exception $e){
536
+		} catch(Exception $e){
514 537
 			
515 538
 			$this->logger->error($e->getMessage());
516 539
 			
@@ -531,12 +554,14 @@  discard block
 block discarded – undo
531 554
 		
532 555
 		$files = $this->storage_filesystem->listContents();
533 556
 		
534
-		if(is_array($files))
535
-			foreach($files as $file)
557
+		if(is_array($files)) {
558
+					foreach($files as $file)
536 559
 			{
537 560
 				if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions))
538 561
 				{
539
-					$_storage_size += $file['size']; //bytes
562
+					$_storage_size += $file['size'];
563
+		}
564
+		//bytes
540 565
 					$_backup_files_list[] = $file;
541 566
 				}
542 567
 			}
@@ -550,9 +575,11 @@  discard block
 block discarded – undo
550 575
 		{
551 576
 			//processing rule folder capacity
552 577
 			if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
553
-			$_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))	//bytes	
578
+			$_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) {
579
+				//bytes	
554 580
 			{
555 581
 				$this->storage_filesystem->delete($file['path']);
582
+			}
556 583
 				$_storage_size -= $file['size'];
557 584
 				$this->logger->info("Deleting backup ".$file['path']." matching rule", array("STORAGE SIZE LIMIT", $_storage_size." >= ".$set_storage_limit));
558 585
 			}
@@ -593,34 +620,37 @@  discard block
 block discarded – undo
593 620
 	
594 621
 	public function process_backup_name($name = "", $max_length=100)
595 622
 	{
596
-		if(!$name)
597
-			$name = $this->xcloner_settings->get_default_backup_name();
623
+		if(!$name) {
624
+					$name = $this->xcloner_settings->get_default_backup_name();
625
+		}
598 626
 		
599 627
 		foreach($this->backup_name_tags as $tag)
600 628
 		{
601
-			if($tag == '[time]')
602
-				$name = str_replace($tag, date("Y-m-d_H-i"),$name);
603
-			elseif($tag == '[hostname]')
604
-				$name = str_replace($tag, gethostname() ,$name);	
605
-			elseif($tag == '[domain]')
629
+			if($tag == '[time]') {
630
+							$name = str_replace($tag, date("Y-m-d_H-i"),$name);
631
+			} elseif($tag == '[hostname]') {
632
+							$name = str_replace($tag, gethostname() ,$name);
633
+			} elseif($tag == '[domain]')
606 634
 			{
607 635
 				$domain = parse_url(admin_url(), PHP_URL_HOST);
608 636
 				$name = str_replace($tag, $domain ,$name);	
609 637
 			}
610 638
 		}
611 639
 		
612
-		if($max_length)
613
-			$name = substr($name, 0, $max_length);
640
+		if($max_length) {
641
+					$name = substr($name, 0, $max_length);
642
+		}
614 643
 			
615 644
 		return $name;	
616 645
 	}
617 646
 	
618 647
 	public function sort_by( &$array, $field, $direction = 'asc')
619 648
 	{
620
-		if(strtolower($direction) == "desc" || $direction == SORT_DESC)
621
-			$direction = SORT_DESC;
622
-		else
623
-			$direction = SORT_ASC;
649
+		if(strtolower($direction) == "desc" || $direction == SORT_DESC) {
650
+					$direction = SORT_DESC;
651
+		} else {
652
+					$direction = SORT_ASC;
653
+		}
624 654
 					
625 655
 	   $array = $this->array_orderby($array, $field, $direction);
626 656
 	    
@@ -637,10 +667,11 @@  discard block
 block discarded – undo
637 667
 	            $tmp = array();
638 668
 	            foreach ($data as $key => $row)
639 669
 	            {
640
-					if(is_array($row))
641
-						$tmp[$key] = $row[$field];
642
-					else
643
-						$tmp[$key] = $row->$field;
670
+					if(is_array($row)) {
671
+											$tmp[$key] = $row[$field];
672
+					} else {
673
+											$tmp[$key] = $row->$field;
674
+					}
644 675
 				}
645 676
 	            $args[$n] = $tmp;
646 677
 	            }
@@ -658,28 +689,32 @@  discard block
 block discarded – undo
658 689
 		
659 690
 		if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb'))
660 691
 		{
661
-			if(isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb))
662
-				return "> ".$xcloner_exclude_files_larger_than_mb."MB";
692
+			if(isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) {
693
+							return "> ".$xcloner_exclude_files_larger_than_mb."MB";
694
+			}
663 695
 		}
664 696
 		
665
-		if(!sizeof($this->excluded_files))
666
-			$this->set_excluded_files();
697
+		if(!sizeof($this->excluded_files)) {
698
+					$this->set_excluded_files();
699
+		}
667 700
 				
668
-		if(is_array($this->excluded_files))
669
-		foreach($this->excluded_files as $excluded_file_pattern)
701
+		if(is_array($this->excluded_files)) {
702
+				foreach($this->excluded_files as $excluded_file_pattern)
670 703
 		{
671 704
 			if($excluded_file_pattern == "/")
672 705
 				$needle = "$";
673
-			else
674
-				$needle = "$".$excluded_file_pattern;
706
+		} else {
707
+							$needle = "$".$excluded_file_pattern;
708
+			}
675 709
 				
676 710
 			if(strstr("$".$file['path'], $needle)){
677 711
 				return $excluded_file_pattern;
678 712
 			}
679 713
 		}
680 714
 		
681
-		if( $regex = $this->is_excluded_regex($file))
682
-			return $regex;
715
+		if( $regex = $this->is_excluded_regex($file)) {
716
+					return $regex;
717
+		}
683 718
 		
684 719
 		return false;
685 720
 	}
@@ -733,13 +768,15 @@  discard block
 block discarded – undo
733 768
 			foreach($regex_patterns as $excluded_file_pattern)
734 769
 			{
735 770
 				
736
-				if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r")
737
-					$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1);
771
+				if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") {
772
+									$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1);
773
+				}
738 774
 					
739
-				if($file['path'] == "/")
740
-					$needle = "/";
741
-				else
742
-					$needle = "/".$file['path'];
775
+				if($file['path'] == "/") {
776
+									$needle = "/";
777
+				} else {
778
+									$needle = "/".$file['path'];
779
+				}
743 780
 				//echo $needle."---".$excluded_file_pattern."---\n";
744 781
 				
745 782
 				if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){
@@ -755,10 +792,12 @@  discard block
 block discarded – undo
755 792
 	{
756 793
 		$this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
757 794
 		
758
-		if(!isset($file['size']))
759
-			$file['size'] = 0;
760
-		if(!isset($file['visibility']))	
761
-			$file['visibility'] = "private";
795
+		if(!isset($file['size'])) {
796
+					$file['size'] = 0;
797
+		}
798
+		if(!isset($file['visibility'])) {
799
+					$file['visibility'] = "private";
800
+		}
762 801
 		
763 802
 		$line = '"'.addslashes($file['path']).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL;
764 803
 		
@@ -767,7 +806,7 @@  discard block
 block discarded – undo
767 806
 		try{
768 807
 			$this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
769 808
 		
770
-		}catch(Exception $e){
809
+		} catch(Exception $e){
771 810
 		
772 811
 			$this->logger->error($e->getMessage());	
773 812
 		}
@@ -775,7 +814,7 @@  discard block
 block discarded – undo
775 814
 		if($file['type'] == "dir"){
776 815
 			try{
777 816
 				$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n");
778
-			}catch(Exception $e){
817
+			} catch(Exception $e){
779 818
 				$this->logger->error($e->getMessage());	
780 819
 			}
781 820
 		}
@@ -788,35 +827,39 @@  discard block
 block discarded – undo
788 827
 	
789 828
 	public function get_filesystem($system = "")
790 829
 	{
791
-		if($system == "storage_filesystem_append")
792
-			return $this->storage_filesystem_append;
793
-		elseif($system == "tmp_filesystem_append")
794
-			return $this->tmp_filesystem_append;
795
-		elseif($system == "tmp_filesystem")
796
-			return $this->tmp_filesystem;
797
-		elseif($system == "storage_filesystem")
798
-			return $this->storage_filesystem;
799
-		else
800
-			return $this->start_filesystem;	
830
+		if($system == "storage_filesystem_append") {
831
+					return $this->storage_filesystem_append;
832
+		} elseif($system == "tmp_filesystem_append") {
833
+					return $this->tmp_filesystem_append;
834
+		} elseif($system == "tmp_filesystem") {
835
+					return $this->tmp_filesystem;
836
+		} elseif($system == "storage_filesystem") {
837
+					return $this->storage_filesystem;
838
+		} else {
839
+					return $this->start_filesystem;
840
+		}
801 841
 	}
802 842
 	
803 843
 	public function get_adapter($system)
804 844
 	{
805
-		if($system == "tmp_filesystem")
806
-			return $this->tmp_adapter;
807
-		elseif($system == "storage_filesystem")
808
-			return $this->storage_adapter;
809
-		else
810
-			return $this->start_adapter;	
845
+		if($system == "tmp_filesystem") {
846
+					return $this->tmp_adapter;
847
+		} elseif($system == "storage_filesystem") {
848
+					return $this->storage_adapter;
849
+		} else {
850
+					return $this->start_adapter;
851
+		}
811 852
 	}
812 853
 	
813 854
 	private function scan_finished()
814 855
 	{
815
-		if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler()))
816
-			return false;
856
+		if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) {
857
+					return false;
858
+		}
817 859
 		
818
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler()))
819
-			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
860
+		if($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
861
+					$this->tmp_filesystem->delete($this->get_temp_dir_handler());
862
+		}
820 863
 		
821 864
 		$this->logger->debug(sprintf(("File scan finished")));
822 865
 			
Please login to merge, or discard this patch.