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 ( e4dc90...7f6a9b )
by Liuta
03:01
created
includes/class-xcloner-file-system.php 3 patches
Doc Comments   +9 added lines patch added patch discarded remove patch
@@ -186,6 +186,9 @@  discard block
 block discarded – undo
186 186
 		return $total;		
187 187
 	}
188 188
 	
189
+	/**
190
+	 * @param string $backup_name
191
+	 */
189 192
 	public function is_part($backup_name)
190 193
 	{
191 194
 		if(stristr($backup_name, "-part"))
@@ -576,6 +579,9 @@  discard block
 block discarded – undo
576 579
 		
577 580
 	}
578 581
 	
582
+	/**
583
+	 * @param string $tmp_file
584
+	 */
579 585
 	public function estimate_reading_time($tmp_file)
580 586
 	{
581 587
 		$this->logger->debug(sprintf(("Estimating file system reading time")));
@@ -635,6 +641,9 @@  discard block
 block discarded – undo
635 641
         //return ($a ($direction == 'desc' ? '>' : '<')  $b) ? -1 : 1;
636 642
 	}
637 643
 	
644
+	/**
645
+	 * @param string $field
646
+	 */
638 647
 	public function sort_by( &$array, $field, $direction = 'asc')
639 648
 	{
640 649
 		$this->sort_direction = strtolower($direction);
Please login to merge, or discard this patch.
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -259,12 +259,12 @@  discard block
 block discarded – undo
259 259
 	}
260 260
 	
261 261
 	public function getMetadataFull($adapter = "storage_adapter" , $path)
262
-    {
263
-        $location = $this->$adapter->applyPathPrefix($path);
264
-        $spl_info = new SplFileInfo($location);
262
+	{
263
+		$location = $this->$adapter->applyPathPrefix($path);
264
+		$spl_info = new SplFileInfo($location);
265 265
         
266
-        return ($spl_info);
267
-    }
266
+		return ($spl_info);
267
+	}
268 268
 	
269 269
 	
270 270
 	public function get_backup_archives_list()
@@ -620,19 +620,19 @@  discard block
 block discarded – undo
620 620
 		$direction = $this->sort_direction;
621 621
 		
622 622
 		$a = $a["' . $field . '"];
623
-        $b = $b["' . $field . '"];
623
+		$b = $b["' . $field . '"];
624 624
 
625
-        if ($a == $b)
626
-        {
627
-            return 0;
628
-        }
625
+		if ($a == $b)
626
+		{
627
+			return 0;
628
+		}
629 629
 		
630 630
 		if(strlower($direction) == 'desc' )
631 631
 			return ($a > $b) ? -1 : 1;
632 632
 		else	
633 633
 			return ($a < $b) ? -1 : 1;
634 634
 			
635
-        //return ($a ($direction == 'desc' ? '>' : '<')  $b) ? -1 : 1;
635
+		//return ($a ($direction == 'desc' ? '>' : '<')  $b) ? -1 : 1;
636 636
 	}
637 637
 	
638 638
 	public function sort_by( &$array, $field, $direction = 'asc')
@@ -640,9 +640,9 @@  discard block
 block discarded – undo
640 640
 		$this->sort_direction = strtolower($direction);
641 641
 		$this->sort_field = $field;
642 642
 		
643
-	    usort($array, array($this, sort_by_usort));
643
+		usort($array, array($this, sort_by_usort));
644 644
 	
645
-	    return true;
645
+		return true;
646 646
 	}
647 647
 	
648 648
 	public function is_excluded($file)
Please login to merge, or discard this 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;	
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
             return 0;
628 628
         }
629 629
 		
630
-		if(strlower($direction) == 'desc' )
630
+		if (strlower($direction) == 'desc')
631 631
 			return ($a > $b) ? -1 : 1;
632 632
 		else	
633 633
 			return ($a < $b) ? -1 : 1;
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
         //return ($a ($direction == 'desc' ? '>' : '<')  $b) ? -1 : 1;
636 636
 	}
637 637
 	
638
-	public function sort_by( &$array, $field, $direction = 'asc')
638
+	public function sort_by(&$array, $field, $direction = 'asc')
639 639
 	{
640 640
 		$this->sort_direction = strtolower($direction);
641 641
 		$this->sort_field = $field;
@@ -649,29 +649,29 @@  discard block
 block discarded – undo
649 649
 	{
650 650
 		$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
651 651
 		
652
-		if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb'))
652
+		if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb'))
653 653
 		{
654
-			if(isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb))
654
+			if (isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb))
655 655
 				return "> ".$xcloner_exclude_files_larger_than_mb."MB";
656 656
 		}
657 657
 		
658
-		if(!sizeof($this->excluded_files))
658
+		if (!sizeof($this->excluded_files))
659 659
 			$this->set_excluded_files();
660 660
 				
661
-		if(is_array($this->excluded_files))
662
-		foreach($this->excluded_files as $excluded_file_pattern)
661
+		if (is_array($this->excluded_files))
662
+		foreach ($this->excluded_files as $excluded_file_pattern)
663 663
 		{
664
-			if($excluded_file_pattern == "/")
664
+			if ($excluded_file_pattern == "/")
665 665
 				$needle = "$";
666 666
 			else
667 667
 				$needle = "$".$excluded_file_pattern;
668 668
 				
669
-			if(strstr("$".$file['path'], $needle)){
669
+			if (strstr("$".$file['path'], $needle)) {
670 670
 				return $excluded_file_pattern;
671 671
 			}
672 672
 		}
673 673
 		
674
-		if( $regex = $this->is_excluded_regex($file))
674
+		if ($regex = $this->is_excluded_regex($file))
675 675
 			return $regex;
676 676
 		
677 677
 		return false;
@@ -717,25 +717,25 @@  discard block
 block discarded – undo
717 717
 		
718 718
 		//print_r($regex_patterns);exit;
719 719
 		
720
-		if(is_array($regex_patterns))
720
+		if (is_array($regex_patterns))
721 721
 		{
722 722
 			//$this->excluded_files = array();
723 723
 			//$this->excluded_files[] ="(.*)\.(git)(.*)$";
724 724
 			//$this->excluded_files[] ="wp-content\/backups(.*)$";
725 725
 			
726
-			foreach($regex_patterns as $excluded_file_pattern)
726
+			foreach ($regex_patterns as $excluded_file_pattern)
727 727
 			{
728 728
 				
729
-				if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r")
730
-					$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1);
729
+				if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1, strlen($excluded_file_pattern)) == "\r")
730
+					$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1);
731 731
 					
732
-				if($file['path'] == "/")
732
+				if ($file['path'] == "/")
733 733
 					$needle = "/";
734 734
 				else
735 735
 					$needle = "/".$file['path'];
736 736
 				//echo $needle."---".$excluded_file_pattern."---\n";
737 737
 				
738
-				if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){
738
+				if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) {
739 739
 					return $excluded_file_pattern;
740 740
 				}
741 741
 			}
@@ -748,27 +748,27 @@  discard block
 block discarded – undo
748 748
 	{
749 749
 		$this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
750 750
 		
751
-		if(!isset($file['size']))
751
+		if (!isset($file['size']))
752 752
 			$file['size'] = 0;
753
-		if(!isset($file['visibility']))	
753
+		if (!isset($file['visibility']))	
754 754
 			$file['visibility'] = "private";
755 755
 		
756 756
 		$line = '"'.addslashes($file['path']).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL;
757 757
 		
758 758
 		$this->last_logged_file = $file['path'];
759 759
 		
760
-		try{
760
+		try {
761 761
 			$this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
762 762
 		
763
-		}catch(Exception $e){
763
+		}catch (Exception $e) {
764 764
 		
765 765
 			$this->logger->error($e->getMessage());	
766 766
 		}
767 767
 		
768
-		if($file['type'] == "dir"){
769
-			try{
768
+		if ($file['type'] == "dir") {
769
+			try {
770 770
 				$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n");
771
-			}catch(Exception $e){
771
+			}catch (Exception $e) {
772 772
 				$this->logger->error($e->getMessage());	
773 773
 			}
774 774
 		}
@@ -781,13 +781,13 @@  discard block
 block discarded – undo
781 781
 	
782 782
 	public function get_filesystem($system = "")
783 783
 	{
784
-		if($system == "storage_filesystem_append")
784
+		if ($system == "storage_filesystem_append")
785 785
 			return $this->storage_filesystem_append;
786
-		elseif($system == "tmp_filesystem_append")
786
+		elseif ($system == "tmp_filesystem_append")
787 787
 			return $this->tmp_filesystem_append;
788
-		elseif($system == "tmp_filesystem")
788
+		elseif ($system == "tmp_filesystem")
789 789
 			return $this->tmp_filesystem;
790
-		elseif($system == "storage_filesystem")
790
+		elseif ($system == "storage_filesystem")
791 791
 			return $this->storage_filesystem;
792 792
 		else
793 793
 			return $this->start_filesystem;	
@@ -795,9 +795,9 @@  discard block
 block discarded – undo
795 795
 	
796 796
 	public function get_adapter($system)
797 797
 	{
798
-		if($system == "tmp_filesystem")
798
+		if ($system == "tmp_filesystem")
799 799
 			return $this->tmp_adapter;
800
-		elseif($system == "storage_filesystem")
800
+		elseif ($system == "storage_filesystem")
801 801
 			return $this->storage_adapter;
802 802
 		else
803 803
 			return $this->start_adapter;	
@@ -805,10 +805,10 @@  discard block
 block discarded – undo
805 805
 	
806 806
 	private function scan_finished()
807 807
 	{
808
-		if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler()))
808
+		if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler()))
809 809
 			return false;
810 810
 		
811
-		if($this->tmp_filesystem->has($this->get_temp_dir_handler()))
811
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler()))
812 812
 			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
813 813
 		
814 814
 		$this->logger->debug(sprintf(("File scan finished")));
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 	
819 819
 	private function calc_to_bytes($mb_size)
820 820
 	{
821
-		return $mb_size*(1024*1024);
821
+		return $mb_size * (1024 * 1024);
822 822
 	}
823 823
 	
824 824
 }
Please login to merge, or discard this patch.