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 ( ea440c...dcf4f4 )
by Liuta
03:18
created
includes/class-xcloner-archive.php 1 patch
Spacing   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -8,11 +8,11 @@  discard block
 block discarded – undo
8 8
 	/*
9 9
 	 * bytes
10 10
 	 */ 
11
-	private $file_size_per_request_limit	= 52428800 ; //50MB = 52428800; 1MB = 1048576
12
-	private $files_to_process_per_request 	= 250; //block of 512 bytes
13
-	private $compression_level 				= 0; //0-9 , 0 uncompressed
11
+	private $file_size_per_request_limit	= 52428800; //50MB = 52428800; 1MB = 1048576
12
+	private $files_to_process_per_request = 250; //block of 512 bytes
13
+	private $compression_level = 0; //0-9 , 0 uncompressed
14 14
 	private $xcloner_split_backup_limit		= 2048; //2048MB
15
-	private $processed_size_bytes			= 0 ;
15
+	private $processed_size_bytes = 0;
16 16
 	
17 17
 	private $archive_name;
18 18
 	private $backup_archive;
@@ -22,25 +22,25 @@  discard block
 block discarded – undo
22 22
 	
23 23
 	public function __construct($hash = "", $archive_name = "")
24 24
 	{
25
-		$this->filesystem 		= new Xcloner_File_System($hash);
26
-		$this->logger 			= new XCloner_Logger('xcloner_archive', $hash);
25
+		$this->filesystem = new Xcloner_File_System($hash);
26
+		$this->logger = new XCloner_Logger('xcloner_archive', $hash);
27 27
 		$this->xcloner_settings = new Xcloner_Settings($hash);
28 28
 		
29
-		if($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request'))
30
-			$this->file_size_per_request_limit = $value*1024*1024; //MB
29
+		if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request'))
30
+			$this->file_size_per_request_limit = $value * 1024 * 1024; //MB
31 31
 			
32
-		if($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request'))
32
+		if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request'))
33 33
 			$this->files_to_process_per_request = $value;
34 34
 		
35
-		if($value = get_option('xcloner_backup_compression_level'))
35
+		if ($value = get_option('xcloner_backup_compression_level'))
36 36
 			$this->compression_level = $value;
37 37
 		
38
-		if($value = get_option('xcloner_split_backup_limit'))
38
+		if ($value = get_option('xcloner_split_backup_limit'))
39 39
 			$this->xcloner_split_backup_limit = $value;
40 40
 		
41
-		$this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024*1024; //transform to bytes
41
+		$this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024 * 1024; //transform to bytes
42 42
 			
43
-		if(isset($archive_name))
43
+		if (isset($archive_name))
44 44
 			$this->set_archive_name($archive_name);
45 45
 	}
46 46
 	
@@ -65,11 +65,11 @@  discard block
 block discarded – undo
65 65
 	{
66 66
 		$this->archive_name = $this->filesystem->process_backup_name($name);
67 67
 		
68
-		if(isset($part) and $part)
68
+		if (isset($part) and $part)
69 69
 		{
70
-			$new_name =  preg_replace('/-part(\d*)/', "-part".$part, $this->archive_name);
71
-			if(!stristr($new_name, "-part"))
72
-				$new_name = $this->archive_name . "-part".$part;
70
+			$new_name = preg_replace('/-part(\d*)/', "-part".$part, $this->archive_name);
71
+			if (!stristr($new_name, "-part"))
72
+				$new_name = $this->archive_name."-part".$part;
73 73
 			
74 74
 			$this->archive_name = $new_name;	
75 75
 		}
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	 */ 
95 95
 	public function get_archive_name_multipart()
96 96
 	{
97
-		$new_name =  preg_replace('/-part(\d*)/', "", $this->archive_name);
97
+		$new_name = preg_replace('/-part(\d*)/', "", $this->archive_name);
98 98
 		return $new_name."-multipart".$this->xcloner_settings->get_backup_extension_name(".csv");
99 99
 	}
100 100
 	
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message)
117 117
 	{
118 118
 		
119
-		$body  = $error_message; 
119
+		$body = $error_message; 
120 120
 		
121 121
 		$this->logger->info(sprintf("Sending backup error notification to %s", $to));
122 122
 		
@@ -124,10 +124,10 @@  discard block
 block discarded – undo
124 124
 		
125 125
 		$headers = array('Content-Type: text/html; charset=UTF-8');
126 126
 		
127
-		if($admin_email and $from )
127
+		if ($admin_email and $from)
128 128
 			$headers[] = 'From: '.$from.' <'.$admin_email.'>';
129 129
 
130
-		$return = wp_mail( $to, $subject, $body, $headers );
130
+		$return = wp_mail($to, $subject, $body, $headers);
131 131
 		
132 132
 		return $return;
133 133
 	}
@@ -137,47 +137,47 @@  discard block
 block discarded – undo
137 137
 	 * Send backup archive notfication by E-Mail
138 138
 	 * 
139 139
 	 */ 
140
-	public function send_notification($to, $from, $subject, $backup_name, $params, $error_message="")
140
+	public function send_notification($to, $from, $subject, $backup_name, $params, $error_message = "")
141 141
 	{
142
-		if(!$from)
142
+		if (!$from)
143 143
 			$from = "XCloner Backup";
144 144
 			
145
-		if(($error_message))
145
+		if (($error_message))
146 146
 		{
147 147
 			return $this->send_notification_error($to, $from, $subject, $backup_name, $params, $error_message);
148 148
 		}
149 149
 		
150 150
 		$params = (array)$params;
151 151
 		
152
-		if(!$subject)
153
-			$subject = sprintf(__("New backup generated %s") ,$backup_name);
152
+		if (!$subject)
153
+			$subject = sprintf(__("New backup generated %s"), $backup_name);
154 154
 			
155 155
 		$body = sprintf(__("Generated Backup Size: %s"), size_format($this->filesystem->get_backup_size($backup_name)));
156 156
 		$body .= "<br /><br />";
157 157
 		
158 158
 		$backup_parts = $this->filesystem->get_multipart_files($backup_name);
159 159
 		
160
-		if(!$backups_counter = sizeof($backup_parts))
160
+		if (!$backups_counter = sizeof($backup_parts))
161 161
 			$backups_counter = 1;
162 162
 		
163 163
 		$body .= sprintf(__("Backup Parts: %s"), $backups_counter);
164 164
 		$body .= "<br />";
165 165
 		
166
-		if(sizeof($backup_parts))
166
+		if (sizeof($backup_parts))
167 167
 		{
168
-			$body .= implode("<br />",$backup_parts);
168
+			$body .= implode("<br />", $backup_parts);
169 169
 			$body .= "<br />";
170 170
 		}
171 171
 		
172
-		$body.= "<br />";
172
+		$body .= "<br />";
173 173
 		
174
-		if(isset($params['backup_params']->backup_comments))
174
+		if (isset($params['backup_params']->backup_comments))
175 175
 		{
176 176
 			$body .= __("Backup Comments: ").$params['backup_params']->backup_comments;
177 177
 			$body .= "<br /><br />";
178 178
 		}
179 179
 		
180
-		if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log'))
180
+		if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log'))
181 181
 			$body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n", $this->logger->getLastDebugLines(50));
182 182
 		
183 183
 		$attachments = $this->filesystem->get_backup_attachments();
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 		$tar = new Tar();
188 188
 		$tar->create($attachments_archive);
189 189
 			
190
-		foreach($attachments as $key => $file)
190
+		foreach ($attachments as $key => $file)
191 191
 		{
192 192
 			$tar->addFile($file, basename($file));
193 193
 		}
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 		
200 200
 		$headers = array('Content-Type: text/html; charset=UTF-8', 'From: '.$from.' <'.$admin_email.'>');
201 201
 		
202
-		$return = wp_mail( $to, $subject, $body, $headers, array($attachments_archive) );
202
+		$return = wp_mail($to, $subject, $body, $headers, array($attachments_archive));
203 203
 	
204 204
 		return $return;
205 205
 	}
@@ -213,17 +213,17 @@  discard block
 block discarded – undo
213 213
 	{
214 214
 		$return = array();
215 215
 		
216
-		if(!isset($extra_params['backup_part']))
216
+		if (!isset($extra_params['backup_part']))
217 217
 			$extra_params['backup_part'] = 0;
218 218
 		
219 219
 		$return['extra']['backup_part'] = $extra_params['backup_part'];
220 220
 					
221
-		if(isset( $extra_params['backup_archive_name']))
221
+		if (isset($extra_params['backup_archive_name']))
222 222
 			$this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']);
223 223
 		else
224 224
 			$this->set_archive_name($backup_params['backup_name']);
225 225
 			
226
-		if(!$this->get_archive_name())
226
+		if (!$this->get_archive_name())
227 227
 			$this->set_archive_name();
228 228
 		
229 229
 		$this->backup_archive = new Tar();
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 		
232 232
 		$archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension());
233 233
 		
234
-		if($init)
234
+		if ($init)
235 235
 		{
236 236
 			$this->logger->info(sprintf(__("Initializing the backup archive %s"), $this->get_archive_name()));
237 237
 		
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 			
240 240
 			$return['extra']['backup_init'] = 1;
241 241
 			
242
-		}else{
242
+		} else {
243 243
 			$this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name()));
244 244
 			
245 245
 			$this->backup_archive->openForAppend($archive_info->getPath().DS.$archive_info->getFilename());
@@ -251,13 +251,13 @@  discard block
 block discarded – undo
251 251
 		$return['extra']['backup_archive_name'] = $this->get_archive_name();
252 252
 		$return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension();
253 253
 		
254
-		if(!isset($extra_params['start_at_line']))
254
+		if (!isset($extra_params['start_at_line']))
255 255
 			$extra_params['start_at_line'] = 0;
256 256
 		
257
-		if(!isset($extra_params['start_at_byte']))
257
+		if (!isset($extra_params['start_at_byte']))
258 258
 			$extra_params['start_at_byte'] = 0;
259 259
 		
260
-		if(!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler()))
260
+		if (!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler()))
261 261
 		{
262 262
 			$this->logger->error(sprintf("Missing the includes file handler %s, aborting...", $this->filesystem->get_included_files_handler()));
263 263
 			
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 		
284 284
 		$byte_limit = 0;
285 285
 		
286
-		while(!$file->eof() and $counter<=$this->files_to_process_per_request)
286
+		while (!$file->eof() and $counter <= $this->files_to_process_per_request)
287 287
 		{
288 288
 			$line = str_getcsv($file->current());
289 289
 
@@ -291,13 +291,13 @@  discard block
 block discarded – undo
291 291
 			
292 292
 			$start_filesystem = "start_filesystem";
293 293
 			
294
-			if(isset($line[4])){
294
+			if (isset($line[4])) {
295 295
 				$start_filesystem = $line[4];
296 296
 			}
297 297
 			
298 298
 			//$adapter = $this->filesystem->get_adapter($start_filesystem);
299 299
 			
300
-			if(!$this->filesystem->get_filesystem($start_filesystem)->has($relative_path))
300
+			if (!$this->filesystem->get_filesystem($start_filesystem)->has($relative_path))
301 301
 			{
302 302
 				$extra_params['start_at_line']++;
303 303
 				$file->next();
@@ -306,35 +306,35 @@  discard block
 block discarded – undo
306 306
 			
307 307
 			$file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path);
308 308
 			
309
-			if(!isset($file_info['size']))
309
+			if (!isset($file_info['size']))
310 310
 				$file_info['size'] = 0;
311 311
 			
312
-			if($start_filesystem == "tmp_filesystem")	
312
+			if ($start_filesystem == "tmp_filesystem")	
313 313
 				$file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix();
314 314
 			
315
-			$byte_limit = (int)$this->file_size_per_request_limit/512;
315
+			$byte_limit = (int)$this->file_size_per_request_limit / 512;
316 316
 			
317 317
 			$append = 0;
318 318
 			
319
-			if($file_info['size'] > $byte_limit*512 or $start_byte)
319
+			if ($file_info['size'] > $byte_limit * 512 or $start_byte)
320 320
 				$append = 1;
321 321
 						
322
-			if(!isset($return['extra']['backup_size']))
323
-				$return['extra']['backup_size'] =0;
322
+			if (!isset($return['extra']['backup_size']))
323
+				$return['extra']['backup_size'] = 0;
324 324
 			
325 325
 			$return['extra']['backup_size'] = $archive_info->getSize();
326 326
 			
327 327
 			$estimated_new_size = $return['extra']['backup_size'] + $file_info['size'];
328 328
 			
329 329
 			//we create a new backup part if we reach the Split Achive Limit
330
-			if($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte))
330
+			if ($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte))
331 331
 			{
332
-				$this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ",$this->xcloner_split_backup_limit, $estimated_new_size));
332
+				$this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ", $this->xcloner_split_backup_limit, $estimated_new_size));
333 333
 				list($archive_info, $return['extra']['backup_part']) = $this->create_new_backup_part($return['extra']['backup_part']);
334 334
 				
335
-				if($file_info['size'] > $this->xcloner_split_backup_limit)
335
+				if ($file_info['size'] > $this->xcloner_split_backup_limit)
336 336
 				{
337
-					$this->logger->info(sprintf("Excluding %s file as it's size(%s) is bigger than the backup split limit of %s and it won't fit a single backup file",$file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit));
337
+					$this->logger->info(sprintf("Excluding %s file as it's size(%s) is bigger than the backup split limit of %s and it won't fit a single backup file", $file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit));
338 338
 					$extra_params['start_at_line']++;
339 339
 				}
340 340
 				
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 				return $return;
347 347
 			}
348 348
 			
349
-			list($bytes_wrote, $last_position) = $this->add_file_to_archive( $file_info, $start_byte, $byte_limit, $append, $start_filesystem);
349
+			list($bytes_wrote, $last_position) = $this->add_file_to_archive($file_info, $start_byte, $byte_limit, $append, $start_filesystem);
350 350
 			$this->processed_size_bytes += $bytes_wrote;
351 351
 			
352 352
 			//echo" - processed ".$this->processed_size_bytes." bytes ".$this->file_size_per_request_limit." last_position:".$last_position." \n";
@@ -354,17 +354,17 @@  discard block
 block discarded – undo
354 354
 			$return['extra']['processed_file_size'] = $file_info['size'];
355 355
 			$return['extra']['backup_size'] = $archive_info->getSize();
356 356
 			
357
-			if($last_position>0){	
357
+			if ($last_position > 0) {	
358 358
 				$start_byte = $last_position;
359 359
 			}
360
-			else{	
360
+			else {	
361 361
 				$extra_params['start_at_line']++;
362 362
 				$file->next();
363 363
 				$start_byte = 0;
364 364
 				$counter++;
365 365
 			}
366 366
 			
367
-			if($this->processed_size_bytes >= $this->file_size_per_request_limit)
367
+			if ($this->processed_size_bytes >= $this->file_size_per_request_limit)
368 368
 			{
369 369
 				clearstatcache();
370 370
 				$return['extra']['backup_size'] = $archive_info->getSize();
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
 			}
378 378
 		}
379 379
 		
380
-		if(!$file->eof())
380
+		if (!$file->eof())
381 381
 		{
382 382
 			clearstatcache();
383 383
 			$return['extra']['backup_size'] = $archive_info->getSize();
@@ -394,12 +394,12 @@  discard block
 block discarded – undo
394 394
 		$this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", $this->get_archive_name_with_extension()));
395 395
 		$this->backup_archive->close();
396 396
 				
397
-		if($return['extra']['backup_part'])
397
+		if ($return['extra']['backup_part'])
398 398
 			$this->write_multipart_file($this->get_archive_name_with_extension());
399 399
 		
400
-		$return['extra']['start_at_line'] = $extra_params['start_at_line']-1;
400
+		$return['extra']['start_at_line'] = $extra_params['start_at_line'] - 1;
401 401
 		
402
-		if(isset($file_info))
402
+		if (isset($file_info))
403 403
 		{
404 404
 			$return['extra']['processed_file'] = $file_info['path'];
405 405
 			$return['extra']['processed_file_size'] = $file_info['size'];
@@ -441,20 +441,20 @@  discard block
 block discarded – undo
441 441
 		$this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", $this->get_archive_name_with_extension()));
442 442
 		$this->backup_archive->close();		
443 443
 		
444
-		if(!$part)
444
+		if (!$part)
445 445
 		{
446 446
 			$old_name = $this->get_archive_name_with_extension();
447 447
 			$this->set_archive_name($this->get_archive_name(), ++$part);
448 448
 			$this->rename_archive($old_name, $this->get_archive_name_with_extension());
449 449
 			
450
-			if($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart()))
450
+			if ($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart()))
451 451
 				$this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart());
452 452
 				
453 453
 			$this->write_multipart_file($this->get_archive_name_with_extension());
454 454
 			
455
-		}else
455
+		} else
456 456
 		{
457
-			$this->logger->info(sprintf("Creating new multipart info file %s",$this->get_archive_name_with_extension()));
457
+			$this->logger->info(sprintf("Creating new multipart info file %s", $this->get_archive_name_with_extension()));
458 458
 			$this->write_multipart_file($this->get_archive_name_with_extension());
459 459
 		}
460 460
 				
@@ -482,10 +482,10 @@  discard block
 block discarded – undo
482 482
 		$start_adapter = $this->filesystem->get_adapter($filesystem);
483 483
 		$start_filesystem = $this->filesystem->get_adapter($filesystem);
484 484
 		
485
-		if(!$file_info['path'])
485
+		if (!$file_info['path'])
486 486
 			return;
487 487
 		
488
-		if(isset($file_info['archive_prefix_path']))	
488
+		if (isset($file_info['archive_prefix_path']))	
489 489
 			$file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path'];
490 490
 		else
491 491
 			$file_info['target_path'] = $file_info['path'];
@@ -494,36 +494,36 @@  discard block
 block discarded – undo
494 494
 		
495 495
 		//$start_adapter = $this->filesystem->get_start_adapter();
496 496
 
497
-		if(!$append){
497
+		if (!$append) {
498 498
 			$bytes_wrote = $file_info['size'];
499 499
 			$this->logger->info(sprintf("Adding %s bytes of file %s to archive %s ", $bytes_wrote, $file_info['target_path'], $this->get_archive_name_with_extension()));
500 500
 			$this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path']);
501 501
 		}
502
-		else{	
502
+		else {	
503 503
 			$tmp_file = md5($file_info['path']);
504 504
 			
505 505
 			//we isolate file to tmp if we are at byte 0, the starting point of file reading
506
-			if(!$start_at_byte)
506
+			if (!$start_at_byte)
507 507
 			{
508 508
 				$this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes", $file_info['path'], $tmp_file));
509 509
 				$file_stream = $start_filesystem->readStream($file_info['path']);
510 510
 				
511
-				if(is_resource($file_stream['stream']))
511
+				if (is_resource($file_stream['stream']))
512 512
 					$this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']);
513 513
 			}
514 514
 			
515
-			if($this->filesystem->get_tmp_filesystem()->has($tmp_file))
515
+			if ($this->filesystem->get_tmp_filesystem()->has($tmp_file))
516 516
 			{
517 517
 				$is_tmp = 1;
518 518
 				$last_position = $this->backup_archive->appendFileData($this->filesystem->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_file), $file_info['target_path'], $start_at_byte, $byte_limit);
519 519
 			}
520
-			else{
520
+			else {
521 521
 				$is_tmp = 0;
522 522
 				$last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path'], $start_at_byte, $byte_limit);
523 523
 			}
524 524
 				
525 525
 			
526
-			if($last_position == -1)
526
+			if ($last_position == -1)
527 527
 			{
528 528
 				$bytes_wrote = $file_info['size'] - $start_at_byte;
529 529
 			}
@@ -533,18 +533,18 @@  discard block
 block discarded – undo
533 533
 			}
534 534
 			
535 535
 			
536
-			if($is_tmp)
536
+			if ($is_tmp)
537 537
 			{
538 538
 				$this->logger->info(sprintf("Appended %s bytes, starting position %s, of tmp file %s (%s) to archive %s ", $bytes_wrote, $start_at_byte, $tmp_file, $file_info['target_path'], $this->get_archive_name()));
539 539
 			}
540
-			else{
540
+			else {
541 541
 				$this->logger->info(sprintf("Appended %s bytes, starting position %s, of original file %s to archive %s ", $bytes_wrote, $start_at_byte, $file_info['target_path'], $tmp_file, $this->get_archive_name()));
542 542
 			}
543 543
 			
544 544
 			//we delete here the isolated tmp file
545
-			if($last_position == -1)
545
+			if ($last_position == -1)
546 546
 			{
547
-				if($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file))
547
+				if ($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file))
548 548
 				{
549 549
 					$this->logger->info(sprintf("Deleting %s from the tmp filesystem", $tmp_file));
550 550
 					$this->filesystem->get_tmp_filesystem_adapter()->delete($tmp_file);
Please login to merge, or discard this patch.