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 ( 476136...1f2497 )
by Liuta
02:37
created
includes/class-xcloner-scheduler.php 2 patches
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-class Xcloner_Scheduler{
3
+class Xcloner_Scheduler {
4 4
 	
5 5
 	private $db;
6 6
 	private $scheduler_table = "xcloner_scheduler";
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
 	{
21 21
 		global $wpdb;
22 22
 		
23
-		$this->db 					= $wpdb;
24
-		$wpdb->show_errors			= false;
23
+		$this->db = $wpdb;
24
+		$wpdb->show_errors = false;
25 25
 		
26 26
 		$this->xcloner_container	= $xcloner_container;
27 27
 		$this->xcloner_settings 	= $xcloner_container->get_xcloner_settings();
@@ -34,18 +34,18 @@  discard block
 block discarded – undo
34 34
 		return $this->xcloner_container;
35 35
 	}
36 36
 	
37
-	public function get_scheduler_list($return_only_enabled = 0 )
37
+	public function get_scheduler_list($return_only_enabled = 0)
38 38
 	{
39 39
 		$list = $this->db->get_results("SELECT * FROM ".$this->scheduler_table);
40 40
 		
41
-		if($return_only_enabled)
41
+		if ($return_only_enabled)
42 42
 		{
43
-			$new_list= array();
43
+			$new_list = array();
44 44
 			
45
-			foreach($list as $res)
46
-				if($res->status)
45
+			foreach ($list as $res)
46
+				if ($res->status)
47 47
 				{
48
-					$res->next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id))+(get_option( 'gmt_offset' ) * HOUR_IN_SECONDS);
48
+					$res->next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id)) + (get_option('gmt_offset') * HOUR_IN_SECONDS);
49 49
 					$new_list[] = $res;
50 50
 				}
51 51
 			$list = $new_list;	
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	{
72 72
 		$data = $this->db->get_row("SELECT * FROM ".$this->scheduler_table." WHERE id=".$id, ARRAY_A);
73 73
 		
74
-		if(!$data)
74
+		if (!$data)
75 75
 			return false;
76 76
 		
77 77
 		$params = json_decode($data['params']);
@@ -88,10 +88,10 @@  discard block
 block discarded – undo
88 88
 	
89 89
 	public function delete_schedule_by_id($id)
90 90
 	{
91
-		$hook =  'xcloner_scheduler_'.$id;
92
-		wp_clear_scheduled_hook( $hook, array($id) );
91
+		$hook = 'xcloner_scheduler_'.$id;
92
+		wp_clear_scheduled_hook($hook, array($id));
93 93
 		
94
-		$data = $this->db->delete( $this->scheduler_table , array( 'id' => $id ) );
94
+		$data = $this->db->delete($this->scheduler_table, array('id' => $id));
95 95
 		
96 96
 		return $data;
97 97
 	}
@@ -100,12 +100,12 @@  discard block
 block discarded – undo
100 100
 	{
101 101
 		$list = $this->get_scheduler_list();
102 102
 		
103
-		foreach($list as $schedule)
103
+		foreach ($list as $schedule)
104 104
 		{
105
-			$hook =  'xcloner_scheduler_'.$schedule->id;
105
+			$hook = 'xcloner_scheduler_'.$schedule->id;
106 106
 			
107
-			$timestamp = wp_next_scheduled( $hook , array($schedule->id) );
108
-			wp_unschedule_event( $timestamp, $hook, array($schedule->id) );
107
+			$timestamp = wp_next_scheduled($hook, array($schedule->id));
108
+			wp_unschedule_event($timestamp, $hook, array($schedule->id));
109 109
 		}
110 110
 	}
111 111
 	
@@ -113,24 +113,24 @@  discard block
 block discarded – undo
113 113
 	{
114 114
 		$list = $this->get_scheduler_list();
115 115
 		
116
-		foreach($list as $schedule)
116
+		foreach ($list as $schedule)
117 117
 		{
118
-			$hook =  'xcloner_scheduler_'.$schedule->id;
118
+			$hook = 'xcloner_scheduler_'.$schedule->id;
119 119
 			
120 120
 			//adding the xcloner_scheduler hook with xcloner_scheduler_callback callback
121
-			add_action( $hook, array($this, 'xcloner_scheduler_callback'), 10,  1 );
121
+			add_action($hook, array($this, 'xcloner_scheduler_callback'), 10, 1);
122 122
 			
123
-			if ( ! wp_next_scheduled( $hook, array($schedule->id) ) and $schedule->status) {
123
+			if (!wp_next_scheduled($hook, array($schedule->id)) and $schedule->status) {
124 124
 				
125
-				if($schedule->recurrence == "single")
126
-					wp_schedule_single_event( strtotime($schedule->start_at), $hook, array($schedule->id));
125
+				if ($schedule->recurrence == "single")
126
+					wp_schedule_single_event(strtotime($schedule->start_at), $hook, array($schedule->id));
127 127
 				else	
128
-					wp_schedule_event( strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id) );
128
+					wp_schedule_event(strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id));
129 129
 					
130
-			}elseif(!$schedule->status)
130
+			}elseif (!$schedule->status)
131 131
 			{
132
-				$timestamp = wp_next_scheduled( $hook , array($schedule->id) );
133
-				wp_unschedule_event( $timestamp, $hook, array($schedule->id) );
132
+				$timestamp = wp_next_scheduled($hook, array($schedule->id));
133
+				wp_unschedule_event($timestamp, $hook, array($schedule->id));
134 134
 			}
135 135
 		}
136 136
 	
@@ -139,17 +139,17 @@  discard block
 block discarded – undo
139 139
 	public function update_cron_hook($id)
140 140
 	{
141 141
 		$schedule = $this->get_schedule_by_id_object($id);
142
-		$hook =  'xcloner_scheduler_'.$schedule->id;
142
+		$hook = 'xcloner_scheduler_'.$schedule->id;
143 143
 		
144
-		$timestamp = wp_next_scheduled( $hook , array($schedule->id) );
145
-		wp_unschedule_event( $timestamp, $hook, array($schedule->id) );
144
+		$timestamp = wp_next_scheduled($hook, array($schedule->id));
145
+		wp_unschedule_event($timestamp, $hook, array($schedule->id));
146 146
 		
147 147
 		if ($schedule->status) {
148 148
 			
149
-			if($schedule->recurrence == "single")
150
-				wp_schedule_single_event( strtotime($schedule->start_at), $hook, array($schedule->id));
151
-			else{	
152
-				wp_schedule_event( strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id) );
149
+			if ($schedule->recurrence == "single")
150
+				wp_schedule_single_event(strtotime($schedule->start_at), $hook, array($schedule->id));
151
+			else {	
152
+				wp_schedule_event(strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id));
153 153
 			}
154 154
 				
155 155
 		}
@@ -157,16 +157,16 @@  discard block
 block discarded – undo
157 157
 	
158 158
 	public function disable_single_cron($schedule_id)
159 159
 	{
160
-		$hook =  'xcloner_scheduler_'.$schedule_id;
161
-		$timestamp = wp_next_scheduled( $hook , array($schedule_id) );
162
-		wp_unschedule_event( $timestamp, $hook, array($schedule_id) );
160
+		$hook = 'xcloner_scheduler_'.$schedule_id;
161
+		$timestamp = wp_next_scheduled($hook, array($schedule_id));
162
+		wp_unschedule_event($timestamp, $hook, array($schedule_id));
163 163
 		
164 164
 		$schedule['status'] = 0;
165 165
 		
166 166
 		$update = $this->db->update( 
167 167
 				$this->scheduler_table, 
168 168
 				$schedule, 
169
-				array( 'id' => $schedule_id ), 
169
+				array('id' => $schedule_id), 
170 170
 				array( 
171 171
 					'%s', 
172 172
 					'%s' 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 		$update = $this->db->update( 
183 183
 				$this->scheduler_table, 
184 184
 				$schedule, 
185
-				array( 'id' => $schedule_id ), 
185
+				array('id' => $schedule_id), 
186 186
 				array( 
187 187
 					'%s', 
188 188
 					'%s' 
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 		$update = $this->db->update( 
199 199
 				$this->scheduler_table, 
200 200
 				$schedule, 
201
-				array( 'id' => $schedule_id ), 
201
+				array('id' => $schedule_id), 
202 202
 				array( 
203 203
 					'%s', 
204 204
 					'%s' 
@@ -211,18 +211,18 @@  discard block
 block discarded – undo
211 211
 	{
212 212
 		set_time_limit(0);
213 213
 		
214
-		$this->xcloner_file_system 		= $this->get_xcloner_container()->get_xcloner_filesystem();
215
-		$this->xcloner_database 		= $this->get_xcloner_container()->get_xcloner_database();
216
-		$this->archive_system 			= $this->get_xcloner_container()->get_archive_system();
217
-		$this->logger 					= $this->get_xcloner_container()->get_xcloner_logger()->withName("xcloner_scheduler");
218
-		$this->xcloner_remote_storage 	= $this->get_xcloner_container()->get_xcloner_remote_storage();
214
+		$this->xcloner_file_system = $this->get_xcloner_container()->get_xcloner_filesystem();
215
+		$this->xcloner_database = $this->get_xcloner_container()->get_xcloner_database();
216
+		$this->archive_system = $this->get_xcloner_container()->get_archive_system();
217
+		$this->logger = $this->get_xcloner_container()->get_xcloner_logger()->withName("xcloner_scheduler");
218
+		$this->xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
219 219
 				
220
-		if($schedule['recurrence'] == "single")
220
+		if ($schedule['recurrence'] == "single")
221 221
 		{
222 222
 			$this->disable_single_cron($schedule['id']);
223 223
 		}
224 224
 		
225
-		if(!$schedule)
225
+		if (!$schedule)
226 226
 		{
227 227
 			$this->logger->info(sprintf("Could not load schedule with id'%s'", $id), array("CRON"));
228 228
 			return;
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 		$init = 1;
238 238
 		$continue = 1;
239 239
 
240
-		while($continue)
240
+		while ($continue)
241 241
 		{
242 242
 			$continue = $this->xcloner_file_system->start_file_recursion($init);
243 243
 			
@@ -251,9 +251,9 @@  discard block
 block discarded – undo
251 251
 		$init = 1;
252 252
 		$return['finished'] = 0;
253 253
 		
254
-		while(!$return['finished'])
254
+		while (!$return['finished'])
255 255
 		{
256
-			$return  = $this->xcloner_database->start_database_recursion((array)json_decode($schedule['table_params']), $return, $init);
256
+			$return = $this->xcloner_database->start_database_recursion((array)json_decode($schedule['table_params']), $return, $init);
257 257
 			$init = 0;
258 258
 		}
259 259
 		
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 		$return['finished'] = 0;
266 266
 		$return['extra'] = array();
267 267
 		
268
-		while(!$return['finished'])
268
+		while (!$return['finished'])
269 269
 		{
270 270
 			$return = $this->archive_system->start_incremental_backup((array)$schedule['backup_params'], $return['extra'], $init);
271 271
 			$init = 0;
@@ -274,29 +274,29 @@  discard block
 block discarded – undo
274 274
 		
275 275
 		//getting the last backup archive file
276 276
 		$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension();
277
-		if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension()))
277
+		if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension()))
278 278
 				$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
279 279
 		
280 280
 		$this->update_last_backup($schedule['id'], $return['extra']['backup_parent']);
281 281
 		
282
-		if($schedule['remote_storage'] and array_key_exists($schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages()))
282
+		if ($schedule['remote_storage'] and array_key_exists($schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages()))
283 283
 		{
284 284
 			$backup_file = $return['extra']['backup_parent'];
285 285
 			
286 286
 			$this->logger->info(sprintf("Transferring backup to remote storage %s", strtoupper($schedule['remote_storage'])), array("CRON"));
287 287
 			
288
-			if(method_exists($this->xcloner_remote_storage, "upload_backup_to_storage"))
288
+			if (method_exists($this->xcloner_remote_storage, "upload_backup_to_storage"))
289 289
 				call_user_func_array(array($this->xcloner_remote_storage, "upload_backup_to_storage"), array($backup_file, $schedule['remote_storage']));
290 290
 		}
291 291
 		
292 292
 		
293
-		if(isset($schedule['backup_params']->email_notification) and $to=$schedule['backup_params']->email_notification)
293
+		if (isset($schedule['backup_params']->email_notification) and $to = $schedule['backup_params']->email_notification)
294 294
 		{	
295
-			try{
295
+			try {
296 296
 				$from = "XCloner Schedule - ".$schedule['name'];
297 297
 				$additional['lines_total'] = $return['extra']['lines_total'];
298 298
 				$this->archive_system->send_notification($to, $from, "", $return['extra']['backup_parent'], $schedule, "", $additional);
299
-			}catch(Exception $e)
299
+			}catch (Exception $e)
300 300
 			{
301 301
 				$this->logger->error($e->getMessage());
302 302
 			}
@@ -311,22 +311,22 @@  discard block
 block discarded – undo
311 311
 	{
312 312
 		$schedule = $this->get_schedule_by_id($id);
313 313
 		
314
-		try{
314
+		try {
315 315
 
316 316
 			$this->__xcloner_scheduler_callback($id, $schedule);
317 317
 			
318
-		}catch(Exception $e){
318
+		}catch (Exception $e) {
319 319
 			
320 320
 			//send email to site admin if email notification is not set in the scheduler
321
-			if(!isset($schedule['backup_params']->email_notification) || !$schedule['backup_params']->email_notification)
321
+			if (!isset($schedule['backup_params']->email_notification) || !$schedule['backup_params']->email_notification)
322 322
 			{
323 323
 				$schedule['backup_params']->email_notification = get_option('admin_email');
324 324
 			}
325 325
 				
326
-			if(isset($schedule['backup_params']->email_notification) && $to=$schedule['backup_params']->email_notification)
326
+			if (isset($schedule['backup_params']->email_notification) && $to = $schedule['backup_params']->email_notification)
327 327
 			{
328 328
 				$from = "XCloner Schedule - ".$schedule['name'];
329
-				$this->archive_system->send_notification($to, $from, "Scheduled backup error","", "", $e->getMessage());
329
+				$this->archive_system->send_notification($to, $from, "Scheduled backup error", "", "", $e->getMessage());
330 330
 			}
331 331
 			
332 332
 		}
Please login to merge, or discard this patch.
Braces   +23 added lines, -18 removed lines patch added patch discarded remove patch
@@ -42,10 +42,11 @@  discard block
 block discarded – undo
42 42
 		{
43 43
 			$new_list= array();
44 44
 			
45
-			foreach($list as $res)
46
-				if($res->status)
45
+			foreach($list as $res) {
46
+							if($res->status)
47 47
 				{
48 48
 					$res->next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id))+(get_option( 'gmt_offset' ) * HOUR_IN_SECONDS);
49
+			}
49 50
 					$new_list[] = $res;
50 51
 				}
51 52
 			$list = $new_list;	
@@ -71,8 +72,9 @@  discard block
 block discarded – undo
71 72
 	{
72 73
 		$data = $this->db->get_row("SELECT * FROM ".$this->scheduler_table." WHERE id=".$id, ARRAY_A);
73 74
 		
74
-		if(!$data)
75
-			return false;
75
+		if(!$data) {
76
+					return false;
77
+		}
76 78
 		
77 79
 		$params = json_decode($data['params']);
78 80
 		
@@ -122,12 +124,13 @@  discard block
 block discarded – undo
122 124
 			
123 125
 			if ( ! wp_next_scheduled( $hook, array($schedule->id) ) and $schedule->status) {
124 126
 				
125
-				if($schedule->recurrence == "single")
126
-					wp_schedule_single_event( strtotime($schedule->start_at), $hook, array($schedule->id));
127
-				else	
128
-					wp_schedule_event( strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id) );
127
+				if($schedule->recurrence == "single") {
128
+									wp_schedule_single_event( strtotime($schedule->start_at), $hook, array($schedule->id));
129
+				} else {
130
+									wp_schedule_event( strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id) );
131
+				}
129 132
 					
130
-			}elseif(!$schedule->status)
133
+			} elseif(!$schedule->status)
131 134
 			{
132 135
 				$timestamp = wp_next_scheduled( $hook , array($schedule->id) );
133 136
 				wp_unschedule_event( $timestamp, $hook, array($schedule->id) );
@@ -146,9 +149,9 @@  discard block
 block discarded – undo
146 149
 		
147 150
 		if ($schedule->status) {
148 151
 			
149
-			if($schedule->recurrence == "single")
150
-				wp_schedule_single_event( strtotime($schedule->start_at), $hook, array($schedule->id));
151
-			else{	
152
+			if($schedule->recurrence == "single") {
153
+							wp_schedule_single_event( strtotime($schedule->start_at), $hook, array($schedule->id));
154
+			} else{	
152 155
 				wp_schedule_event( strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id) );
153 156
 			}
154 157
 				
@@ -274,8 +277,9 @@  discard block
 block discarded – undo
274 277
 		
275 278
 		//getting the last backup archive file
276 279
 		$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension();
277
-		if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension()))
278
-				$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
280
+		if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) {
281
+						$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
282
+		}
279 283
 		
280 284
 		$this->update_last_backup($schedule['id'], $return['extra']['backup_parent']);
281 285
 		
@@ -285,8 +289,9 @@  discard block
 block discarded – undo
285 289
 			
286 290
 			$this->logger->info(sprintf("Transferring backup to remote storage %s", strtoupper($schedule['remote_storage'])), array("CRON"));
287 291
 			
288
-			if(method_exists($this->xcloner_remote_storage, "upload_backup_to_storage"))
289
-				call_user_func_array(array($this->xcloner_remote_storage, "upload_backup_to_storage"), array($backup_file, $schedule['remote_storage']));
292
+			if(method_exists($this->xcloner_remote_storage, "upload_backup_to_storage")) {
293
+							call_user_func_array(array($this->xcloner_remote_storage, "upload_backup_to_storage"), array($backup_file, $schedule['remote_storage']));
294
+			}
290 295
 		}
291 296
 		
292 297
 		
@@ -296,7 +301,7 @@  discard block
 block discarded – undo
296 301
 				$from = "XCloner Schedule - ".$schedule['name'];
297 302
 				$additional['lines_total'] = $return['extra']['lines_total'];
298 303
 				$this->archive_system->send_notification($to, $from, "", $return['extra']['backup_parent'], $schedule, "", $additional);
299
-			}catch(Exception $e)
304
+			} catch(Exception $e)
300 305
 			{
301 306
 				$this->logger->error($e->getMessage());
302 307
 			}
@@ -315,7 +320,7 @@  discard block
 block discarded – undo
315 320
 
316 321
 			$this->__xcloner_scheduler_callback($id, $schedule);
317 322
 			
318
-		}catch(Exception $e){
323
+		} catch(Exception $e){
319 324
 			
320 325
 			//send email to site admin if email notification is not set in the scheduler
321 326
 			if(!isset($schedule['backup_params']->email_notification) || !$schedule['backup_params']->email_notification)
Please login to merge, or discard this patch.