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 ( 1a6a13...b32b6e )
by Liuta
03:37
created
includes/class-xcloner-api.php 1 patch
Spacing   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 use splitbrain\PHPArchive\FileInfo;
12 12
 
13 13
 
14
-class Xcloner_Api{
14
+class Xcloner_Api {
15 15
 
16 16
 	private $xcloner_database;
17 17
 	private $xcloner_settings;
@@ -27,33 +27,33 @@  discard block
 block discarded – undo
27 27
 		global $wpdb;
28 28
 		
29 29
 		error_reporting(0);
30
-		if( ob_get_length() )
30
+		if (ob_get_length())
31 31
 			ob_end_clean();
32 32
 		ob_start();
33 33
 		
34
-		$wpdb->show_errors		= false;
34
+		$wpdb->show_errors = false;
35 35
 		
36
-		$this->xcloner_settings 		= new Xcloner_Settings();
36
+		$this->xcloner_settings = new Xcloner_Settings();
37 37
 		
38 38
 		//generating the hash suffix for tmp xcloner store folder
39
-		if(isset($_POST['hash'])){
39
+		if (isset($_POST['hash'])) {
40 40
 			
41
-			if($_POST['hash'] == "generate_hash")
41
+			if ($_POST['hash'] == "generate_hash")
42 42
 				$this->xcloner_settings->generate_new_hash();
43 43
 			else
44 44
 				$this->xcloner_settings->set_hash($_POST['hash']);
45 45
 		}
46 46
 
47
-		$this->logger 					= new XCloner_Logger("xcloner_api", $this->xcloner_settings->get_hash());
47
+		$this->logger = new XCloner_Logger("xcloner_api", $this->xcloner_settings->get_hash());
48 48
 		$this->xcloner_file_system 		= new Xcloner_File_System($this->xcloner_settings->get_hash());
49 49
 		$this->xcloner_sanitization 	= new Xcloner_Sanitization();
50 50
 		$this->xcloner_requirements 	= new XCloner_Requirements();
51
-		$this->archive_system 			= new Xcloner_Archive($this->xcloner_settings->get_hash());
52
-		$this->xcloner_database 		= new XCloner_Database($this->xcloner_settings->get_hash());
51
+		$this->archive_system = new Xcloner_Archive($this->xcloner_settings->get_hash());
52
+		$this->xcloner_database = new XCloner_Database($this->xcloner_settings->get_hash());
53 53
 		
54 54
 		
55
-		if(isset($_POST['API_ID'])){
56
-			$this->logger->info("Processing ajax request ID ".substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), 0 , 15));
55
+		if (isset($_POST['API_ID'])) {
56
+			$this->logger->info("Processing ajax request ID ".substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), 0, 15));
57 57
 		}
58 58
 		
59 59
 	}
@@ -69,16 +69,16 @@  discard block
 block discarded – undo
69 69
 		$data['dbDatabase'] = $this->xcloner_settings->get_db_database();
70 70
 		
71 71
 		
72
-		$data['recordsPerSession'] 		= $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
73
-		$data['TEMP_DBPROCESS_FILE'] 	= $this->xcloner_settings->get_xcloner_tmp_path().DS.".database";
74
-		$data['TEMP_DUMP_FILE'] 		= $this->xcloner_settings->get_xcloner_tmp_path().DS."database-sql.sql";
72
+		$data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request');
73
+		$data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS.".database";
74
+		$data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS."database-sql.sql";
75 75
 		
76 76
 		try
77 77
 		{
78 78
 			//$xcloner_db = new XCloner_Database($data['dbUsername'], $data['dbPassword'], $data['dbDatabase'], $data['dbHostname']);
79 79
 			$this->xcloner_database->init($data);
80 80
 
81
-		}catch(Exception $e)
81
+		}catch (Exception $e)
82 82
 		{
83 83
 			$this->send_response($e->getMessage());
84 84
 			$this->logger->error($e->getMessage());
@@ -107,12 +107,12 @@  discard block
 block discarded – undo
107 107
 		$schedule = array();
108 108
 		$response = array();
109 109
 		
110
-		if(isset($_POST['data']))
110
+		if (isset($_POST['data']))
111 111
 			$params = json_decode(stripslashes($_POST['data']));
112 112
 		
113 113
 		$this->process_params($params);
114 114
 		
115
-		if(isset($_POST['id']))
115
+		if (isset($_POST['id']))
116 116
 		{
117 117
 			
118 118
 			$this->form_params['backup_params']['backup_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_name']);
@@ -127,11 +127,11 @@  discard block
 block discarded – undo
127 127
 			$tables = explode(PHP_EOL, $this->form_params['database']);
128 128
 			$return = array();
129 129
 			
130
-			foreach($tables as $table)
130
+			foreach ($tables as $table)
131 131
 			{
132
-					$table = str_replace("\r","", $table);
132
+					$table = str_replace("\r", "", $table);
133 133
 					$data = explode(".", $table);
134
-					if(isset($data[1]))
134
+					if (isset($data[1]))
135 135
 						$return[$data[0]][] = $data[1];
136 136
 			}
137 137
 			
@@ -140,29 +140,29 @@  discard block
 block discarded – undo
140 140
 			$excluded_files = explode(PHP_EOL, $this->form_params['excluded_files']);
141 141
 			$return = array();
142 142
 			
143
-			foreach($excluded_files as $file)
143
+			foreach ($excluded_files as $file)
144 144
 			{
145
-				$file = str_replace("\r","", $file);
146
-				if($file)
145
+				$file = str_replace("\r", "", $file);
146
+				if ($file)
147 147
 					$return[] = $file;
148 148
 			}
149 149
 			
150 150
 			$this->form_params['excluded_files'] = ($return);
151 151
 			
152
-			$schedule['start_at'] = $this->form_params['backup_params']['start_at'] ;
152
+			$schedule['start_at'] = $this->form_params['backup_params']['start_at'];
153 153
 			
154
-			if(!isset($_POST['status']))
154
+			if (!isset($_POST['status']))
155 155
 				$schedule['status'] = 0;
156 156
 			else	
157 157
 				$schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']);
158
-		}else{
158
+		} else {
159 159
 		
160 160
 			$schedule['status'] = 1;
161
-			$schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] .
161
+			$schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'].
162 162
 								" ".$this->form_params['backup_params']['schedule_start_time']);
163 163
 		}
164 164
 		
165
-		if(!$schedule['start_at'])						
165
+		if (!$schedule['start_at'])						
166 166
 			$schedule['start_at'] = time();
167 167
 		
168 168
 		$schedule['start_at'] = date('Y-m-d H:i:s', $schedule['start_at']);	
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 		
174 174
 		$schedule['params'] = json_encode($this->form_params);
175 175
 		
176
-		if(!isset($_POST['id']))
176
+		if (!isset($_POST['id']))
177 177
 		{
178 178
 			$wpdb->insert( 
179 179
 				$wpdb->prefix.'xcloner_scheduler', 
@@ -183,21 +183,21 @@  discard block
 block discarded – undo
183 183
 					'%s' 
184 184
 				) 
185 185
 			);
186
-		}else		{
186
+		} else {
187 187
 			$wpdb->update( 
188 188
 				$wpdb->prefix.'xcloner_scheduler', 
189 189
 				$schedule, 
190
-				array( 'id' => $_POST['id'] ), 
190
+				array('id' => $_POST['id']), 
191 191
 				array( 
192 192
 					'%s', 
193 193
 					'%s' 
194 194
 				) 
195 195
 			);
196 196
 		}
197
-		if(isset($_POST['id']))
197
+		if (isset($_POST['id']))
198 198
 			$scheduler->update_cron_hook($_POST['id']);
199 199
 			
200
-		if( $wpdb->last_error ) {
200
+		if ($wpdb->last_error) {
201 201
             $response['error'] = 1;
202 202
             $response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/;
203 203
             
@@ -222,19 +222,19 @@  discard block
 block discarded – undo
222 222
 		
223 223
 		$params = json_decode(stripslashes($_POST['data']));
224 224
 		
225
-		$init 	= (int)$_POST['init'];
225
+		$init = (int)$_POST['init'];
226 226
 		
227
-		if($params === NULL)
228
-			 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
227
+		if ($params === NULL)
228
+			 die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
229 229
 			 
230 230
 		$this->process_params($params);
231 231
 		
232 232
 		$return['finished'] = 1;
233 233
 
234 234
 		//$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init);
235
-		try{
235
+		try {
236 236
 			$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init);
237
-		}catch(Exception $e)
237
+		}catch (Exception $e)
238 238
 		{
239 239
 			$return = array();
240 240
 			$return['error'] = true;
@@ -243,25 +243,25 @@  discard block
 block discarded – undo
243 243
 			return $this->send_response($return, $hash = 1);
244 244
 		}
245 245
 		
246
-		if($return['finished'])
246
+		if ($return['finished'])
247 247
 		{
248 248
 			$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension();
249
-			if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension()))
249
+			if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension()))
250 250
 				$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
251 251
 		}
252 252
 		
253 253
 		$data = $return;
254 254
 		
255 255
 		//check if backup is finished
256
-		if($return['finished'] )
256
+		if ($return['finished'])
257 257
 		{
258
-			if(isset($this->form_params['backup_params']['email_notification']) and $to=$this->form_params['backup_params']['email_notification'])
258
+			if (isset($this->form_params['backup_params']['email_notification']) and $to = $this->form_params['backup_params']['email_notification'])
259 259
 			{
260
-				try{
260
+				try {
261 261
 					$from = "";
262 262
 					$subject = "";
263 263
 					$this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $this->form_params);
264
-				}catch(Exception $e)
264
+				}catch (Exception $e)
265 265
 				{
266 266
 					$this->logger->error($e->getMessage());
267 267
 				}
@@ -285,17 +285,17 @@  discard block
 block discarded – undo
285 285
 		
286 286
 		$params = json_decode(stripslashes($_POST['data']));
287 287
 		
288
-		$init 	= (int)$_POST['init'];
288
+		$init = (int)$_POST['init'];
289 289
 		
290
-		if($params === NULL)
291
-			 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
290
+		if ($params === NULL)
291
+			 die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
292 292
 		
293 293
 		$this->process_params($params);
294 294
 			
295 295
 		//$xcloner_database = $this->init_db();	
296 296
 		$return = $this->xcloner_database->start_database_recursion($this->form_params['database'], $this->form_params['extra'], $init);
297 297
 		
298
-		if(isset($return['error']) and $return['error'])
298
+		if (isset($return['error']) and $return['error'])
299 299
 			$data['finished'] = 1;
300 300
 		else	
301 301
 			$data['finished'] = $return['finished'];
@@ -317,10 +317,10 @@  discard block
 block discarded – undo
317 317
 		}
318 318
 		
319 319
 		$params = json_decode(stripslashes($_POST['data']));
320
-		$init 	= (int)$_POST['init'];
320
+		$init = (int)$_POST['init'];
321 321
 		
322
-		if($params === NULL)
323
-			 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
322
+		if ($params === NULL)
323
+			 die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
324 324
 			 
325 325
 		$hash = $this->process_params($params);
326 326
 		
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 		$data["finished"] = !$return;
332 332
 		$data["total_files_num"] = $this->xcloner_file_system->get_scanned_files_num();
333 333
 		$data["last_logged_file"] = $this->xcloner_file_system->last_logged_file();
334
-		$data["total_files_size"] = sprintf("%.2f",$this->xcloner_file_system->get_scanned_files_total_size()/(1024*1024));
334
+		$data["total_files_size"] = sprintf("%.2f", $this->xcloner_file_system->get_scanned_files_total_size() / (1024 * 1024));
335 335
 		
336 336
 		return $this->send_response($data, $hash = 1);
337 337
 	}
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 	 */ 
344 344
 	private function process_params($params)
345 345
 	{
346
-		if(isset($params->hash))
346
+		if (isset($params->hash))
347 347
 			$this->xcloner_settings->set_hash($params->hash);
348 348
 			
349 349
 		$this->form_params['extra'] = array();
@@ -351,9 +351,9 @@  discard block
 block discarded – undo
351 351
 		
352 352
 		$this->form_params['database'] = array();
353 353
 		
354
-		if(isset($params->backup_params))
354
+		if (isset($params->backup_params))
355 355
 		{
356
-			foreach($params->backup_params as $param)
356
+			foreach ($params->backup_params as $param)
357 357
 			{
358 358
 				$this->form_params['backup_params'][$param->name] = $this->xcloner_sanitization->sanitize_input_as_string($param->value);
359 359
 				$this->logger->debug("Adding form parameter ".$param->name.".".$param->value."\n", array('POST', 'fields filter'));
@@ -362,28 +362,28 @@  discard block
 block discarded – undo
362 362
 		
363 363
 		$this->form_params['database'] = array();
364 364
 		
365
-		if(isset($params->table_params))
365
+		if (isset($params->table_params))
366 366
 		{
367
-			foreach($params->table_params as $param)
367
+			foreach ($params->table_params as $param)
368 368
 			{
369 369
 				$this->form_params['database'][$param->parent][] = $this->xcloner_sanitization->sanitize_input_as_raw($param->id);
370 370
 				$this->logger->debug("Adding database filter ".$param->parent.".".$param->id."\n", array('POST', 'database filter'));
371 371
 			}
372 372
 		}
373 373
 		
374
-		$this->form_params['excluded_files'] =  array();
375
-		if(isset($params->files_params))
374
+		$this->form_params['excluded_files'] = array();
375
+		if (isset($params->files_params))
376 376
 		{
377
-			foreach($params->files_params as $param)
377
+			foreach ($params->files_params as $param)
378 378
 			{
379 379
 				$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
380 380
 			}
381 381
 			
382 382
 			$unique_exclude_files = array();
383 383
 			
384
-			foreach($params->files_params as $key=>$param)
384
+			foreach ($params->files_params as $key=>$param)
385 385
 			{
386
-				if(!in_array($param->parent, $this->form_params['excluded_files'])){
386
+				if (!in_array($param->parent, $this->form_params['excluded_files'])) {
387 387
 				//$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
388 388
 					$unique_exclude_files[] = $param->id;
389 389
 					$this->logger->debug("Adding file filter ".$param->id."\n", array('POST', 'exclude files filter'));
@@ -395,9 +395,9 @@  discard block
 block discarded – undo
395 395
 		
396 396
 		//$this->form_params['excluded_files'] =  array_merge($this->form_params['excluded_files'], $this->exclude_files_by_default);
397 397
 		
398
-		if(isset($params->extra))
398
+		if (isset($params->extra))
399 399
 		{
400
-			foreach($params->extra as $key=>$value)
400
+			foreach ($params->extra as $key=>$value)
401 401
 				$this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value);
402 402
 		}
403 403
 			
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 		
420 420
 		$data = array();
421 421
 		
422
-		if($folder == "#"){
422
+		if ($folder == "#") {
423 423
 			
424 424
 			$folder = "/";
425 425
 			//$list_directory = $this->xcloner_settings->get_xcloner_start_path();
@@ -433,9 +433,9 @@  discard block
 block discarded – undo
433 433
 						);
434 434
 		}
435 435
 			
436
-			try{
436
+			try {
437 437
 				$files = $this->xcloner_file_system->list_directory($folder);
438
-			}catch(Exception $e){
438
+			}catch (Exception $e) {
439 439
 				
440 440
 				print $e->getMessage();
441 441
 				$this->logger->error($e->getMessage());
@@ -450,19 +450,19 @@  discard block
 block discarded – undo
450 450
 			}
451 451
 			array_multisort($type, SORT_ASC, $files);
452 452
 			
453
-			foreach($files as $file)
453
+			foreach ($files as $file)
454 454
 			{
455 455
 				$children = false;
456 456
 				$text = $file['basename'];
457 457
 				
458
-				if($file['type'] == "dir")
458
+				if ($file['type'] == "dir")
459 459
 					$children = true;
460 460
 				else
461
-					 $text .= " (". $this->xcloner_requirements->file_format_size($file['size']).")";
461
+					 $text .= " (".$this->xcloner_requirements->file_format_size($file['size']).")";
462 462
 				
463 463
 				//if(in_array($file['path'], $this->xcloner_file_system->get_excluded_files()))
464 464
 				//echo $file['path']."--".$this->xcloner_file_system->is_excluded($file);
465
-				if($this->xcloner_file_system->is_excluded($file))
465
+				if ($this->xcloner_file_system->is_excluded($file))
466 466
 					$selected = true;
467 467
 				else
468 468
 					$selected = false;
@@ -499,25 +499,25 @@  discard block
 block discarded – undo
499 499
 		
500 500
 		$xcloner_backup_only_wp_tables = $this->xcloner_settings->get_xcloner_option('xcloner_backup_only_wp_tables');
501 501
 	
502
-		if($database == "#")
502
+		if ($database == "#")
503 503
 		{
504
-			try{
504
+			try {
505 505
 				$return = $this->xcloner_database->get_all_databases();
506
-			}catch(Exception $e){
506
+			}catch (Exception $e) {
507 507
 				$this->logger->error($e->getMessage());
508 508
 			}
509 509
 			
510
-			foreach($return as $database)
510
+			foreach ($return as $database)
511 511
 			{
512
-				if($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database())
512
+				if ($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database())
513 513
 					continue;
514 514
 					
515 515
 				$state = array();
516 516
 				
517
-				if($database['name'] == $this->xcloner_settings->get_db_database())
517
+				if ($database['name'] == $this->xcloner_settings->get_db_database())
518 518
 				{
519 519
 					$state['selected'] = true;
520
-					if($database['num_tables'] < 25)
520
+					if ($database['num_tables'] < 25)
521 521
 						$state['opened'] = false;
522 522
 				}
523 523
 					
@@ -533,22 +533,22 @@  discard block
 block discarded – undo
533 533
 			
534 534
 		}
535 535
 		
536
-		else{
536
+		else {
537 537
 			
538
-			try{
538
+			try {
539 539
 				$return = $this->xcloner_database->list_tables($database, "", 1);
540
-			}catch(Exception $e){
540
+			}catch (Exception $e) {
541 541
 				$this->logger->error($e->getMessage());
542 542
 			}
543 543
 			
544
-			foreach($return as $table)
544
+			foreach ($return as $table)
545 545
 			{
546 546
 				$state = array();
547 547
 				
548
-				if($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix()))
548
+				if ($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix()))
549 549
 					continue;
550 550
 				
551
-				if(isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database())
551
+				if (isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database())
552 552
 					$state = array('selected' => true);
553 553
 					
554 554
 				$data[] = array(
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
 		
579 579
 		$schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']);
580 580
 		$scheduler = new Xcloner_Scheduler();
581
-		$data  = $scheduler->get_schedule_by_id($schedule_id);
581
+		$data = $scheduler->get_schedule_by_id($schedule_id);
582 582
 		
583 583
 		return $this->send_response($data);
584 584
 	}
@@ -595,14 +595,14 @@  discard block
 block discarded – undo
595 595
 		}
596 596
 		
597 597
 		$scheduler = new Xcloner_Scheduler();
598
-		$data  = $scheduler->get_scheduler_list();
598
+		$data = $scheduler->get_scheduler_list();
599 599
 		$return['data'] = array();
600 600
 		
601
-		foreach($data as $res)
601
+		foreach ($data as $res)
602 602
 		{
603 603
 			$action = "<a href=\"#".$res->id."\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> 
604 604
 					<a href=\"#".$res->id."\" class=\"delete\" title='Delete'><i class=\"material-icons  \">delete</i></a>";
605
-			if($res->status)
605
+			if ($res->status)
606 606
 				$status = '<i class="material-icons active status">timer</i>';
607 607
 			else
608 608
 				$status = '<i class="material-icons status inactive">timer_off</i>';
@@ -613,14 +613,14 @@  discard block
 block discarded – undo
613 613
 			
614 614
 			$remote_storage = $res->remote_storage;
615 615
 			
616
-			if(!$next_run_time >= time())
616
+			if (!$next_run_time >= time())
617 617
 				$next_run = " ";
618 618
 			
619
-			if(trim($next_run))
619
+			if (trim($next_run))
620 620
 			{
621 621
 				$date_text = $next_run;
622 622
 				
623
-				if($next_run_time >= time())
623
+				if ($next_run_time >= time())
624 624
 					$next_run = "in ".human_time_diff($next_run_time, time());
625 625
 				else
626 626
 					$next_run = __("executed", 'xcloner-backup-and-restore');
@@ -633,9 +633,9 @@  discard block
 block discarded – undo
633 633
 			$backup_size = "";
634 634
 			$backup_time = "";
635 635
 			
636
-			if($res->last_backup)
636
+			if ($res->last_backup)
637 637
 			{
638
-				if( $this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup))
638
+				if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup))
639 639
 				{
640 640
 					$metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup);
641 641
 					$backup_size  = size_format($metadata['size']);
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
 				$backup_text = "<span title='".$backup_time."' class='shorten_string'>".$res->last_backup." (".$backup_size.")</span>";
646 646
 			}
647 647
 				
648
-			$return['data'][] = array($res->id, $res->name, $res->recurrence,/*$res->start_at,*/ $next_run, $remote_storage, $backup_text, $status, $action);
648
+			$return['data'][] = array($res->id, $res->name, $res->recurrence, /*$res->start_at,*/ $next_run, $remote_storage, $backup_text, $status, $action);
649 649
 		}
650 650
 		
651 651
 		return $this->send_response($return, 0);
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
 		
665 665
 		$schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']);
666 666
 		$scheduler = new Xcloner_Scheduler();
667
-		$data['finished']  = $scheduler->delete_schedule_by_id($schedule_id);
667
+		$data['finished'] = $scheduler->delete_schedule_by_id($schedule_id);
668 668
 		
669 669
 		return $this->send_response($data);
670 670
 	}
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
 		
683 683
 		$backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_POST['name']);
684 684
 		
685
-		$data['finished']  = $this->xcloner_file_system->delete_backup_by_name($backup_name);
685
+		$data['finished'] = $this->xcloner_file_system->delete_backup_by_name($backup_name);
686 686
 		
687 687
 		return $this->send_response($data);
688 688
 	}
@@ -701,32 +701,32 @@  discard block
 block discarded – undo
701 701
 		
702 702
 		$backup_file = $source_backup_file;
703 703
 		
704
-		if($this->xcloner_file_system->is_multipart($backup_file))
704
+		if ($this->xcloner_file_system->is_multipart($backup_file))
705 705
 		{
706 706
 			$backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file);
707 707
 			$backup_file = $backup_parts[$return['part']];
708 708
 		}
709 709
 		
710
-		try{
710
+		try {
711 711
 			$tar = new Tar();
712 712
 			$tar->open($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file, $start);
713 713
 		
714 714
 			$data = $tar->contents(get_option('xcloner_files_to_process_per_request'));
715
-		}catch(Exception $e)
715
+		}catch (Exception $e)
716 716
 		{
717 717
 			$return['error'] = true;
718 718
 			$return['message'] = $e->getMessage();
719 719
 			$this->send_response($return, 0);
720 720
 		}
721 721
 		
722
-		$return['files'] 		= array();
723
-		$return['finished'] 	= 1;
724
-		$return['total_size'] 	= filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file);
722
+		$return['files'] = array();
723
+		$return['finished'] = 1;
724
+		$return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file);
725 725
 		$i = 0;
726 726
 		
727
-		if(isset($data['extracted_files']) and is_array($data['extracted_files']))
727
+		if (isset($data['extracted_files']) and is_array($data['extracted_files']))
728 728
 		{
729
-			foreach($data['extracted_files'] as $file)
729
+			foreach ($data['extracted_files'] as $file)
730 730
 			{
731 731
 				$return['files'][$i]['path'] = $file->getPath();
732 732
 				$return['files'][$i]['size'] = $file->getSize();
@@ -736,18 +736,18 @@  discard block
 block discarded – undo
736 736
 			}
737 737
 		}
738 738
 		
739
-		if(isset($data['start']))
739
+		if (isset($data['start']))
740 740
 		{
741 741
 			$return['start'] = $data['start'];
742 742
 			$return['finished'] = 0;	
743
-		}else{
744
-			if($this->xcloner_file_system->is_multipart($source_backup_file))
743
+		} else {
744
+			if ($this->xcloner_file_system->is_multipart($source_backup_file))
745 745
 			{
746 746
 				$return['start'] = 0;
747 747
 				
748 748
 				++$return['part'];
749 749
 			
750
-				if($return['part'] < sizeof($backup_parts))	
750
+				if ($return['part'] < sizeof($backup_parts))	
751 751
 					$return['finished'] = 0;
752 752
 				
753 753
 			}
@@ -776,17 +776,17 @@  discard block
 block discarded – undo
776 776
 		
777 777
 		try
778 778
 		{
779
-			if(method_exists($xcloner_remote_storage, "upload_backup_to_storage"))
779
+			if (method_exists($xcloner_remote_storage, "upload_backup_to_storage"))
780 780
 			{
781 781
 				$return = call_user_func_array(array($xcloner_remote_storage, "upload_backup_to_storage"), array($backup_file, $storage_type));
782 782
 			}
783
-		}catch(Exception $e){
783
+		}catch (Exception $e) {
784 784
 		
785 785
 			$return['error'] = 1;
786 786
 			$return['message'] = $e->getMessage();
787 787
 		}
788 788
 		
789
-		if(!$return)
789
+		if (!$return)
790 790
 		{
791 791
 			$return['error'] = 1;
792 792
 			$return['message'] = "Upload failed, please check the error log for more information!";
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 		
825 825
 		@ob_end_clean();
826 826
 		
827
-		$adapter = new Local(dirname(__DIR__) ,LOCK_EX, 'SKIP_LINKS');
827
+		$adapter = new Local(dirname(__DIR__), LOCK_EX, 'SKIP_LINKS');
828 828
 		$xcloner_plugin_filesystem = new Filesystem($adapter, new Config([
829 829
 				'disable_asserts' => true,
830 830
 			]));
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
 		//$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz");
839 839
 		
840 840
 		$files = $xcloner_plugin_filesystem->listContents("vendor/", true);
841
-		foreach($files as $file)
841
+		foreach ($files as $file)
842 842
 		{
843 843
 			$tar->addFile(dirname(__DIR__).DS.$file['path'], $file['path']);
844 844
 		}
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
 		    header('Expires: 0');
858 858
 		    header('Cache-Control: must-revalidate');
859 859
 		    header('Pragma: public');
860
-		    header('Content-Length: ' . filesize($tmp_file));
860
+		    header('Content-Length: '.filesize($tmp_file));
861 861
 		    readfile($tmp_file);
862 862
 		    
863 863
 		}
@@ -882,9 +882,9 @@  discard block
 block discarded – undo
882 882
 		$backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_GET['name']);
883 883
 		
884 884
 		
885
-		$metadata  = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name);
885
+		$metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name);
886 886
 		//$mimetype  = $this->xcloner_file_system->get_storage_filesystem()->getMimetype($backup_name);
887
-		$read_stream  = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name);
887
+		$read_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name);
888 888
 		
889 889
 		
890 890
 		header('Pragma: public');
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
 	    header('Content-Disposition: attachment; filename="'.$metadata['path'].'";');
896 896
 	    //header('Content-Type: ' . $mimetype);
897 897
 	    header('Content-Type: application/octet-stream');
898
-	    header('Content-Length: ' . $metadata['size']);
898
+	    header('Content-Length: '.$metadata['size']);
899 899
 	    
900 900
 	    @ob_end_clean();
901 901
 	    
@@ -925,10 +925,10 @@  discard block
 block discarded – undo
925 925
 		$file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
926 926
 		$hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']);
927 927
 		
928
-		if(isset($_POST['part']))
928
+		if (isset($_POST['part']))
929 929
 			$return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
930 930
 		
931
-		if(isset($_POST['uploaded_size']))
931
+		if (isset($_POST['uploaded_size']))
932 932
 			$return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']);
933 933
 		
934 934
 		$start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']);
@@ -936,46 +936,46 @@  discard block
 block discarded – undo
936 936
 		
937 937
 		$return['total_size'] = $this->xcloner_file_system->get_backup_size($file);
938 938
 		
939
-		if($this->xcloner_file_system->is_multipart($file))
939
+		if ($this->xcloner_file_system->is_multipart($file))
940 940
 		{
941 941
 			$backup_parts = $this->xcloner_file_system->get_multipart_files($file);
942 942
 			
943
-			$return['total_parts'] = sizeof($backup_parts)+1;
943
+			$return['total_parts'] = sizeof($backup_parts) + 1;
944 944
 			
945
-			if($return['part'] and isset($backup_parts[$return['part']-1]))
945
+			if ($return['part'] and isset($backup_parts[$return['part'] - 1]))
946 946
 			{
947
-				$file = $backup_parts[$return['part']-1];
947
+				$file = $backup_parts[$return['part'] - 1];
948 948
 			}
949 949
 			
950 950
 			$is_multipart = 1;	
951 951
 		}
952 952
 		
953
-		try{
953
+		try {
954 954
 		
955 955
 			$xcloner_file_transfer = new Xcloner_File_Transfer();
956 956
 			$xcloner_file_transfer->set_target($target_url);
957 957
 			$return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash);
958 958
 		
959
-		}catch(Exception $e){
959
+		}catch (Exception $e) {
960 960
 		
961 961
 			$return = array();
962 962
 			$return['error'] = true;
963 963
 			$return['status'] = 500;
964 964
 			$return['message'] = "CURL communication error with the restore host. ".$e->getMessage();
965
-			$this->send_response( $return, 0);
965
+			$this->send_response($return, 0);
966 966
 		
967 967
 		}
968 968
 		
969 969
 		$return['status'] = 200;
970 970
 		
971 971
 		//we have finished the upload
972
-		if(!$return['start'] and $is_multipart)
972
+		if (!$return['start'] and $is_multipart)
973 973
 		{
974 974
 			$return['part']++;
975 975
 			$return['uploaded_size'] += $this->xcloner_file_system->get_storage_filesystem()->getSize($file);
976 976
 		}
977 977
 		
978
-		$this->send_response( $return, 0);
978
+		$this->send_response($return, 0);
979 979
 	}
980 980
 	/*
981 981
 	 * 
@@ -985,12 +985,12 @@  discard block
 block discarded – undo
985 985
 	private function send_response($data, $attach_hash = 1)
986 986
 	{
987 987
 		
988
-		if($attach_hash and null !== $this->xcloner_settings->get_hash())
988
+		if ($attach_hash and null !== $this->xcloner_settings->get_hash())
989 989
 		{
990 990
 			$data['hash'] = $this->xcloner_settings->get_hash();
991 991
 		}
992 992
 			
993
-		if( ob_get_length() )
993
+		if (ob_get_length())
994 994
 			ob_clean();
995 995
 		wp_send_json($data);
996 996
 		
Please login to merge, or discard this patch.