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.
Passed
Branch dev (4f6bab)
by Liuta
02:57
created
includes/class-xcloner-scheduler.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 		foreach ($list as $schedule) {
104 104
 			$hook = 'xcloner_scheduler_'.$schedule->id;
105 105
 
106
-			if($timestamp = wp_next_scheduled($hook, array($schedule->id))) {
106
+			if ($timestamp = wp_next_scheduled($hook, array($schedule->id))) {
107 107
                 wp_unschedule_event($timestamp, $hook, array($schedule->id));
108 108
             }
109 109
 		}
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 				}
128 128
 
129 129
 			} elseif (!$schedule->status) {
130
-				if($timestamp = wp_next_scheduled($hook, array($schedule->id))) {
130
+				if ($timestamp = wp_next_scheduled($hook, array($schedule->id))) {
131 131
                     wp_unschedule_event($timestamp, $hook, array($schedule->id));
132 132
                 }
133 133
 			}
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 		$schedule = $this->get_schedule_by_id_object($id);
140 140
 		$hook     = 'xcloner_scheduler_'.$schedule->id;
141 141
 
142
-		if( $timestamp = wp_next_scheduled($hook, array($schedule->id))) {
142
+		if ($timestamp = wp_next_scheduled($hook, array($schedule->id))) {
143 143
             wp_unschedule_event($timestamp, $hook, array($schedule->id));
144 144
         }
145 145
 
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
 
157 157
 	public function disable_single_cron($schedule_id) {
158 158
         $schedule = array();
159
-		$hook      = 'xcloner_scheduler_'.$schedule_id;
159
+		$hook = 'xcloner_scheduler_'.$schedule_id;
160 160
 
161
-		if($timestamp = wp_next_scheduled($hook, array($schedule_id))) {
161
+		if ($timestamp = wp_next_scheduled($hook, array($schedule_id))) {
162 162
             wp_unschedule_event($timestamp, $hook, array($schedule_id));
163 163
         }
164 164
 
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 		return $update;
178 178
 	}
179 179
 
180
-	public function update_hash( $schedule_id, $hash ) {
180
+	public function update_hash($schedule_id, $hash) {
181 181
 		$schedule = array();
182 182
 
183 183
 		$schedule['hash'] = $hash;
@@ -215,13 +215,13 @@  discard block
 block discarded – undo
215 215
 		return $update;
216 216
 	}
217 217
 
218
-	private function _xcloner_scheduler_callback( $id, $schedule ) {
219
-		set_time_limit( 0 );
218
+	private function _xcloner_scheduler_callback($id, $schedule) {
219
+		set_time_limit(0);
220 220
 
221 221
 
222 222
 		$xcloner = new XCloner();
223 223
 		$xcloner->init();
224
-		$this->set_xcloner_container( $xcloner );
224
+		$this->set_xcloner_container($xcloner);
225 225
         $return_encrypted = array();
226 226
         $return = array();
227 227
         $additional = array();
@@ -231,79 +231,79 @@  discard block
 block discarded – undo
231 231
 
232 232
 		//$this->xcloner_settings 		= $this->get_xcloner_container()->get_xcloner_settings();		
233 233
 		$this->xcloner_file_system    = $this->get_xcloner_container()->get_xcloner_filesystem();
234
-		$this->xcloner_encryption    = $this->get_xcloner_container()->get_xcloner_encryption();
234
+		$this->xcloner_encryption = $this->get_xcloner_container()->get_xcloner_encryption();
235 235
 		$this->xcloner_database       = $this->get_xcloner_container()->get_xcloner_database();
236 236
 		$this->archive_system         = $this->get_xcloner_container()->get_archive_system();
237
-		$this->logger                 = $this->get_xcloner_container()->get_xcloner_logger()->withName( "xcloner_scheduler" );
237
+		$this->logger                 = $this->get_xcloner_container()->get_xcloner_logger()->withName("xcloner_scheduler");
238 238
 		$this->xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
239 239
 
240
-		$this->logger->info( sprintf( "New schedule hash is %s", $this->xcloner_settings->get_hash() ) );
240
+		$this->logger->info(sprintf("New schedule hash is %s", $this->xcloner_settings->get_hash()));
241 241
 
242
-		if ( isset( $schedule['backup_params']->diff_start_date ) && $schedule['backup_params']->diff_start_date ) {
243
-			$this->xcloner_file_system->set_diff_timestamp_start( $schedule['backup_params']->diff_start_date );
242
+		if (isset($schedule['backup_params']->diff_start_date) && $schedule['backup_params']->diff_start_date) {
243
+			$this->xcloner_file_system->set_diff_timestamp_start($schedule['backup_params']->diff_start_date);
244 244
 		}
245 245
 
246
-		if ( $schedule['recurrence'] == "single" ) {
247
-			$this->disable_single_cron( $schedule['id'] );
246
+		if ($schedule['recurrence'] == "single") {
247
+			$this->disable_single_cron($schedule['id']);
248 248
 		}
249 249
 
250
-		if ( ! $schedule ) {
251
-			$this->logger->info( sprintf( "Could not load schedule with id'%s'", $id ), array( "CRON" ) );
250
+		if (!$schedule) {
251
+			$this->logger->info(sprintf("Could not load schedule with id'%s'", $id), array("CRON"));
252 252
 
253 253
 			return;
254 254
 		}
255 255
 
256 256
 		//echo $this->get_xcloner_container()->get_xcloner_settings()->get_hash(); exit;
257 257
 
258
-		$this->update_hash( $schedule['id'], $this->xcloner_settings->get_hash() );
258
+		$this->update_hash($schedule['id'], $this->xcloner_settings->get_hash());
259 259
 
260
-		$this->logger->info( sprintf( "Starting cron schedule '%s'", $schedule['name'] ), array( "CRON" ) );
260
+		$this->logger->info(sprintf("Starting cron schedule '%s'", $schedule['name']), array("CRON"));
261 261
 
262
-		$this->xcloner_file_system->set_excluded_files( json_decode( $schedule['excluded_files'] ) );
262
+		$this->xcloner_file_system->set_excluded_files(json_decode($schedule['excluded_files']));
263 263
 
264 264
 		$init     = 1;
265 265
 		$continue = 1;
266 266
 
267
-		while ( $continue ) {
268
-			$continue = $this->xcloner_file_system->start_file_recursion( $init );
267
+		while ($continue) {
268
+			$continue = $this->xcloner_file_system->start_file_recursion($init);
269 269
 
270 270
 			$init = 0;
271 271
 		}
272 272
 
273
-		$this->logger->info( sprintf( "File scan finished" ), array( "CRON" ) );
273
+		$this->logger->info(sprintf("File scan finished"), array("CRON"));
274 274
 
275
-		$this->logger->info( sprintf( "Starting the database backup" ), array( "CRON" ) );
275
+		$this->logger->info(sprintf("Starting the database backup"), array("CRON"));
276 276
 
277 277
 		$init               = 1;
278 278
 		$return['finished'] = 0;
279 279
 
280
-		while ( ! $return['finished'] ) {
281
-			$return = $this->xcloner_database->start_database_recursion( (array) json_decode( $schedule['table_params'] ), $return, $init );
280
+		while (!$return['finished']) {
281
+			$return = $this->xcloner_database->start_database_recursion((array)json_decode($schedule['table_params']), $return, $init);
282 282
 			$init   = 0;
283 283
 		}
284 284
 
285
-		$this->logger->info( sprintf( "Database backup done" ), array( "CRON" ) );
285
+		$this->logger->info(sprintf("Database backup done"), array("CRON"));
286 286
 
287
-		$this->logger->info( sprintf( "Starting file archive process" ), array( "CRON" ) );
287
+		$this->logger->info(sprintf("Starting file archive process"), array("CRON"));
288 288
 
289 289
 		$init               = 0;
290 290
 		$return['finished'] = 0;
291 291
 		$return['extra']    = array();
292 292
 
293
-		while ( ! $return['finished'] ) {
294
-			$return = $this->archive_system->start_incremental_backup( (array) $schedule['backup_params'], $return['extra'], $init );
293
+		while (!$return['finished']) {
294
+			$return = $this->archive_system->start_incremental_backup((array)$schedule['backup_params'], $return['extra'], $init);
295 295
 			$init   = 0;
296 296
 		}
297
-		$this->logger->info( sprintf( "File archive process FINISHED." ), array( "CRON" ) );
297
+		$this->logger->info(sprintf("File archive process FINISHED."), array("CRON"));
298 298
 
299 299
 		//getting the last backup archive file
300 300
 		$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension();
301
-		if ( $this->xcloner_file_system->is_part( $this->archive_system->get_archive_name_with_extension() ) ) {
301
+		if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) {
302 302
 			$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
303 303
 		}
304 304
 
305 305
 		//Updating schedule last backup archive
306
-		$this->update_last_backup( $schedule['id'], $return['extra']['backup_parent'] );
306
+		$this->update_last_backup($schedule['id'], $return['extra']['backup_parent']);
307 307
 
308 308
 		//Encrypting the backup archive
309 309
 		$return_encrypted['finished'] = 0;
@@ -313,8 +313,8 @@  discard block
 block discarded – undo
313 313
 		$part = 0;
314 314
 		$backup_parts = array();
315 315
 
316
-		if( $schedule['backup_params']->backup_encrypt){
317
-			$this->logger->info( sprintf( "Encrypting backup archive %s.", $return['extra']['backup_parent'] ), array( "CRON" ) );
316
+		if ($schedule['backup_params']->backup_encrypt) {
317
+			$this->logger->info(sprintf("Encrypting backup archive %s.", $return['extra']['backup_parent']), array("CRON"));
318 318
 
319 319
 			$backup_file = $return['extra']['backup_parent'];
320 320
 
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 				$backup_file = $backup_parts[$part];
324 324
 			}
325 325
 
326
-			while ( ! $return_encrypted['finished'] ) {
326
+			while (!$return_encrypted['finished']) {
327 327
 				$return_encrypted = $this->xcloner_encryption->encrypt_file(
328 328
 											$backup_file,
329 329
 											"",
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
 											true
335 335
 				);
336 336
 
337
-				if($return_encrypted['finished']) {
337
+				if ($return_encrypted['finished']) {
338 338
 					++$part;
339 339
 
340 340
 					if ($part < sizeof($backup_parts)) {
@@ -346,37 +346,37 @@  discard block
 block discarded – undo
346 346
 		}
347 347
 
348 348
 		//Sending backup to remote storage
349
-		if ( isset( $schedule['remote_storage'] ) && $schedule['remote_storage'] && array_key_exists( $schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages() ) ) {
349
+		if (isset($schedule['remote_storage']) && $schedule['remote_storage'] && array_key_exists($schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages())) {
350 350
 			$backup_file = $return['extra']['backup_parent'];
351 351
 
352
-			$this->logger->info( sprintf( "Transferring backup to remote storage %s", strtoupper( $schedule['remote_storage'] ) ), array( "CRON" ) );
352
+			$this->logger->info(sprintf("Transferring backup to remote storage %s", strtoupper($schedule['remote_storage'])), array("CRON"));
353 353
 
354
-			if ( method_exists( $this->xcloner_remote_storage, "upload_backup_to_storage" ) ) {
355
-				call_user_func_array( array(
354
+			if (method_exists($this->xcloner_remote_storage, "upload_backup_to_storage")) {
355
+				call_user_func_array(array(
356 356
 					$this->xcloner_remote_storage,
357 357
 					"upload_backup_to_storage"
358
-				), array( $backup_file, $schedule['remote_storage'] ) );
358
+				), array($backup_file, $schedule['remote_storage']));
359 359
 			}
360 360
 		}
361 361
 
362 362
 		//Sending email notification
363
-		if ( isset( $schedule['backup_params']->email_notification ) and $to = $schedule['backup_params']->email_notification ) {
363
+		if (isset($schedule['backup_params']->email_notification) and $to = $schedule['backup_params']->email_notification) {
364 364
 			try {
365 365
 				$from                      = "";
366 366
 				$additional['lines_total'] = $return['extra']['lines_total'];
367
-				$subject                   = sprintf( __( "%s - new backup generated %s" ), $schedule['name'], $return['extra']['backup_parent'] );
367
+				$subject                   = sprintf(__("%s - new backup generated %s"), $schedule['name'], $return['extra']['backup_parent']);
368 368
 
369
-				$this->archive_system->send_notification( $to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional );
369
+				$this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional);
370 370
 
371
-			} catch ( Exception $e ) {
372
-				$this->logger->error( $e->getMessage() );
371
+			}catch (Exception $e) {
372
+				$this->logger->error($e->getMessage());
373 373
 			}
374 374
 		}
375 375
 
376 376
 		//CHECK IF WE SHOULD DELETE BACKUP AFTER REMOTE TRANSFER IS DONE
377
-		if ( $schedule['remote_storage'] && $this->xcloner_settings->get_xcloner_option( 'xcloner_cleanup_delete_after_remote_transfer' ) ) {
378
-			$this->logger->info( sprintf( "Deleting %s from local storage matching rule xcloner_cleanup_delete_after_remote_transfer", $return['extra']['backup_parent'] ) );
379
-			$this->xcloner_file_system->delete_backup_by_name( $return['extra']['backup_parent'] );
377
+		if ($schedule['remote_storage'] && $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_delete_after_remote_transfer')) {
378
+			$this->logger->info(sprintf("Deleting %s from local storage matching rule xcloner_cleanup_delete_after_remote_transfer", $return['extra']['backup_parent']));
379
+			$this->xcloner_file_system->delete_backup_by_name($return['extra']['backup_parent']);
380 380
 
381 381
 		}
382 382
 
@@ -390,28 +390,28 @@  discard block
 block discarded – undo
390 390
 		$this->xcloner_file_system->cleanup_tmp_directories();
391 391
 	}
392 392
 
393
-	public function xcloner_scheduler_callback( $id, $schedule = "" ) {
394
-		if ( $id ) {
395
-			$schedule = $this->get_schedule_by_id( $id );
393
+	public function xcloner_scheduler_callback($id, $schedule = "") {
394
+		if ($id) {
395
+			$schedule = $this->get_schedule_by_id($id);
396 396
 		}
397 397
 
398 398
 		try {
399
-			if( get_option('xcloner_disable_email_notification') ) {
399
+			if (get_option('xcloner_disable_email_notification')) {
400 400
 				//we disable email notifications
401 401
 				$schedule['backup_params']->email_notification = "";
402 402
 			}
403
-			$this->_xcloner_scheduler_callback( $id, $schedule );
403
+			$this->_xcloner_scheduler_callback($id, $schedule);
404 404
 
405
-		} catch ( Exception $e ) {
405
+		}catch (Exception $e) {
406 406
 
407 407
 			//send email to site admin if email notification is not set in the scheduler
408
-			if ( ! isset( $schedule['backup_params']->email_notification ) || ! $schedule['backup_params']->email_notification ) {
409
-				$schedule['backup_params']->email_notification = get_option( 'admin_email' );
408
+			if (!isset($schedule['backup_params']->email_notification) || !$schedule['backup_params']->email_notification) {
409
+				$schedule['backup_params']->email_notification = get_option('admin_email');
410 410
 			}
411 411
 
412
-			if ( isset( $schedule['backup_params']->email_notification ) && $to = $schedule['backup_params']->email_notification ) {
412
+			if (isset($schedule['backup_params']->email_notification) && $to = $schedule['backup_params']->email_notification) {
413 413
 				$from = "";
414
-				$this->archive_system->send_notification( $to, $from, $schedule['name'] . " - backup error", "", "", $e->getMessage() );
414
+				$this->archive_system->send_notification($to, $from, $schedule['name']." - backup error", "", "", $e->getMessage());
415 415
 			}
416 416
 
417 417
 		}
Please login to merge, or discard this patch.