@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | $hook = 'xcloner_scheduler_'.$schedule->id; |
105 | 105 | |
106 | 106 | if($timestamp = wp_next_scheduled($hook, array($schedule->id))) { |
107 | - wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
108 | - } |
|
107 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
108 | + } |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
@@ -128,8 +128,8 @@ discard block |
||
128 | 128 | |
129 | 129 | } elseif (!$schedule->status) { |
130 | 130 | if($timestamp = wp_next_scheduled($hook, array($schedule->id))) { |
131 | - wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
132 | - } |
|
131 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
132 | + } |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | $hook = 'xcloner_scheduler_'.$schedule->id; |
141 | 141 | |
142 | 142 | if( $timestamp = wp_next_scheduled($hook, array($schedule->id))) { |
143 | - wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
144 | - } |
|
143 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
144 | + } |
|
145 | 145 | |
146 | 146 | if ($schedule->status) { |
147 | 147 | |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | public function disable_single_cron($schedule_id) { |
158 | 158 | $hook = 'xcloner_scheduler_'.$schedule_id; |
159 | 159 | if($timestamp = wp_next_scheduled($hook, array($schedule_id))) { |
160 | - wp_unschedule_event($timestamp, $hook, array($schedule_id)); |
|
161 | - } |
|
160 | + wp_unschedule_event($timestamp, $hook, array($schedule_id)); |
|
161 | + } |
|
162 | 162 | |
163 | 163 | $schedule['status'] = 0; |
164 | 164 |
@@ -103,7 +103,7 @@ discard block |
||
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 |
||
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 |
||
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 | |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | public function disable_single_cron($schedule_id) { |
158 | - $hook = 'xcloner_scheduler_'.$schedule_id; |
|
159 | - if($timestamp = wp_next_scheduled($hook, array($schedule_id))) { |
|
158 | + $hook = 'xcloner_scheduler_'.$schedule_id; |
|
159 | + if ($timestamp = wp_next_scheduled($hook, array($schedule_id))) { |
|
160 | 160 | wp_unschedule_event($timestamp, $hook, array($schedule_id)); |
161 | 161 | } |
162 | 162 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | return $update; |
176 | 176 | } |
177 | 177 | |
178 | - public function update_hash( $schedule_id, $hash ) { |
|
178 | + public function update_hash($schedule_id, $hash) { |
|
179 | 179 | $schedule = array(); |
180 | 180 | |
181 | 181 | $schedule['hash'] = $hash; |
@@ -212,91 +212,91 @@ discard block |
||
212 | 212 | return $update; |
213 | 213 | } |
214 | 214 | |
215 | - private function _xcloner_scheduler_callback( $id, $schedule ) { |
|
216 | - set_time_limit( 0 ); |
|
215 | + private function _xcloner_scheduler_callback($id, $schedule) { |
|
216 | + set_time_limit(0); |
|
217 | 217 | |
218 | 218 | $xcloner = new XCloner(); |
219 | 219 | $xcloner->init(); |
220 | - $this->set_xcloner_container( $xcloner ); |
|
220 | + $this->set_xcloner_container($xcloner); |
|
221 | 221 | |
222 | 222 | #$hash = $this->xcloner_settings->get_hash(); |
223 | 223 | #$this->get_xcloner_container()->get_xcloner_settings()->set_hash($hash); |
224 | 224 | |
225 | 225 | //$this->xcloner_settings = $this->get_xcloner_container()->get_xcloner_settings(); |
226 | 226 | $this->xcloner_file_system = $this->get_xcloner_container()->get_xcloner_filesystem(); |
227 | - $this->xcloner_encryption = $this->get_xcloner_container()->get_xcloner_encryption(); |
|
227 | + $this->xcloner_encryption = $this->get_xcloner_container()->get_xcloner_encryption(); |
|
228 | 228 | $this->xcloner_database = $this->get_xcloner_container()->get_xcloner_database(); |
229 | 229 | $this->archive_system = $this->get_xcloner_container()->get_archive_system(); |
230 | - $this->logger = $this->get_xcloner_container()->get_xcloner_logger()->withName( "xcloner_scheduler" ); |
|
230 | + $this->logger = $this->get_xcloner_container()->get_xcloner_logger()->withName("xcloner_scheduler"); |
|
231 | 231 | $this->xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
232 | 232 | |
233 | - $this->logger->info( sprintf( "New schedule hash is %s", $this->xcloner_settings->get_hash() ) ); |
|
233 | + $this->logger->info(sprintf("New schedule hash is %s", $this->xcloner_settings->get_hash())); |
|
234 | 234 | |
235 | - if ( isset( $schedule['backup_params']->diff_start_date ) && $schedule['backup_params']->diff_start_date ) { |
|
236 | - $this->xcloner_file_system->set_diff_timestamp_start( $schedule['backup_params']->diff_start_date ); |
|
235 | + if (isset($schedule['backup_params']->diff_start_date) && $schedule['backup_params']->diff_start_date) { |
|
236 | + $this->xcloner_file_system->set_diff_timestamp_start($schedule['backup_params']->diff_start_date); |
|
237 | 237 | } |
238 | 238 | |
239 | - if ( $schedule['recurrence'] == "single" ) { |
|
240 | - $this->disable_single_cron( $schedule['id'] ); |
|
239 | + if ($schedule['recurrence'] == "single") { |
|
240 | + $this->disable_single_cron($schedule['id']); |
|
241 | 241 | } |
242 | 242 | |
243 | - if ( ! $schedule ) { |
|
244 | - $this->logger->info( sprintf( "Could not load schedule with id'%s'", $id ), array( "CRON" ) ); |
|
243 | + if (!$schedule) { |
|
244 | + $this->logger->info(sprintf("Could not load schedule with id'%s'", $id), array("CRON")); |
|
245 | 245 | |
246 | 246 | return; |
247 | 247 | } |
248 | 248 | |
249 | 249 | //echo $this->get_xcloner_container()->get_xcloner_settings()->get_hash(); exit; |
250 | 250 | |
251 | - $this->update_hash( $schedule['id'], $this->xcloner_settings->get_hash() ); |
|
251 | + $this->update_hash($schedule['id'], $this->xcloner_settings->get_hash()); |
|
252 | 252 | |
253 | - $this->logger->info( sprintf( "Starting cron schedule '%s'", $schedule['name'] ), array( "CRON" ) ); |
|
253 | + $this->logger->info(sprintf("Starting cron schedule '%s'", $schedule['name']), array("CRON")); |
|
254 | 254 | |
255 | - $this->xcloner_file_system->set_excluded_files( json_decode( $schedule['excluded_files'] ) ); |
|
255 | + $this->xcloner_file_system->set_excluded_files(json_decode($schedule['excluded_files'])); |
|
256 | 256 | |
257 | 257 | $init = 1; |
258 | 258 | $continue = 1; |
259 | 259 | |
260 | - while ( $continue ) { |
|
261 | - $continue = $this->xcloner_file_system->start_file_recursion( $init ); |
|
260 | + while ($continue) { |
|
261 | + $continue = $this->xcloner_file_system->start_file_recursion($init); |
|
262 | 262 | |
263 | 263 | $init = 0; |
264 | 264 | } |
265 | 265 | |
266 | - $this->logger->info( sprintf( "File scan finished" ), array( "CRON" ) ); |
|
266 | + $this->logger->info(sprintf("File scan finished"), array("CRON")); |
|
267 | 267 | |
268 | - $this->logger->info( sprintf( "Starting the database backup" ), array( "CRON" ) ); |
|
268 | + $this->logger->info(sprintf("Starting the database backup"), array("CRON")); |
|
269 | 269 | |
270 | 270 | $init = 1; |
271 | 271 | $return['finished'] = 0; |
272 | 272 | |
273 | - while ( ! $return['finished'] ) { |
|
274 | - $return = $this->xcloner_database->start_database_recursion( (array) json_decode( $schedule['table_params'] ), $return, $init ); |
|
273 | + while (!$return['finished']) { |
|
274 | + $return = $this->xcloner_database->start_database_recursion((array)json_decode($schedule['table_params']), $return, $init); |
|
275 | 275 | $init = 0; |
276 | 276 | } |
277 | 277 | |
278 | - $this->logger->info( sprintf( "Database backup done" ), array( "CRON" ) ); |
|
278 | + $this->logger->info(sprintf("Database backup done"), array("CRON")); |
|
279 | 279 | |
280 | - $this->logger->info( sprintf( "Starting file archive process" ), array( "CRON" ) ); |
|
280 | + $this->logger->info(sprintf("Starting file archive process"), array("CRON")); |
|
281 | 281 | |
282 | 282 | $init = 0; |
283 | 283 | $return['finished'] = 0; |
284 | 284 | $return['extra'] = array(); |
285 | 285 | |
286 | - while ( ! $return['finished'] ) { |
|
287 | - $return = $this->archive_system->start_incremental_backup( (array) $schedule['backup_params'], $return['extra'], $init ); |
|
286 | + while (!$return['finished']) { |
|
287 | + $return = $this->archive_system->start_incremental_backup((array)$schedule['backup_params'], $return['extra'], $init); |
|
288 | 288 | $init = 0; |
289 | 289 | } |
290 | - $this->logger->info( sprintf( "File archive process FINISHED." ), array( "CRON" ) ); |
|
290 | + $this->logger->info(sprintf("File archive process FINISHED."), array("CRON")); |
|
291 | 291 | |
292 | 292 | //getting the last backup archive file |
293 | 293 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); |
294 | - if ( $this->xcloner_file_system->is_part( $this->archive_system->get_archive_name_with_extension() ) ) { |
|
294 | + if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) { |
|
295 | 295 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
296 | 296 | } |
297 | 297 | |
298 | 298 | //Updating schedule last backup archive |
299 | - $this->update_last_backup( $schedule['id'], $return['extra']['backup_parent'] ); |
|
299 | + $this->update_last_backup($schedule['id'], $return['extra']['backup_parent']); |
|
300 | 300 | |
301 | 301 | //Encrypting the backup archive |
302 | 302 | $return_encrypted['finished'] = 0; |
@@ -306,8 +306,8 @@ discard block |
||
306 | 306 | $part = 0; |
307 | 307 | $backup_parts = array(); |
308 | 308 | |
309 | - if( $schedule['backup_params']->backup_encrypt){ |
|
310 | - $this->logger->info( sprintf( "Encrypting backup archive %s.", $return['extra']['backup_parent'] ), array( "CRON" ) ); |
|
309 | + if ($schedule['backup_params']->backup_encrypt) { |
|
310 | + $this->logger->info(sprintf("Encrypting backup archive %s.", $return['extra']['backup_parent']), array("CRON")); |
|
311 | 311 | |
312 | 312 | $backup_file = $return['extra']['backup_parent']; |
313 | 313 | |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | $backup_file = $backup_parts[$part]; |
317 | 317 | } |
318 | 318 | |
319 | - while ( ! $return_encrypted['finished'] ) { |
|
319 | + while (!$return_encrypted['finished']) { |
|
320 | 320 | $return_encrypted = $this->xcloner_encryption->encrypt_file( |
321 | 321 | $backup_file, |
322 | 322 | "", |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | true |
328 | 328 | ); |
329 | 329 | |
330 | - if($return_encrypted['finished']) { |
|
330 | + if ($return_encrypted['finished']) { |
|
331 | 331 | ++$part; |
332 | 332 | |
333 | 333 | if ($part < sizeof($backup_parts)) { |
@@ -339,37 +339,37 @@ discard block |
||
339 | 339 | } |
340 | 340 | |
341 | 341 | //Sending backup to remote storage |
342 | - if ( isset( $schedule['remote_storage'] ) && $schedule['remote_storage'] && array_key_exists( $schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages() ) ) { |
|
342 | + if (isset($schedule['remote_storage']) && $schedule['remote_storage'] && array_key_exists($schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages())) { |
|
343 | 343 | $backup_file = $return['extra']['backup_parent']; |
344 | 344 | |
345 | - $this->logger->info( sprintf( "Transferring backup to remote storage %s", strtoupper( $schedule['remote_storage'] ) ), array( "CRON" ) ); |
|
345 | + $this->logger->info(sprintf("Transferring backup to remote storage %s", strtoupper($schedule['remote_storage'])), array("CRON")); |
|
346 | 346 | |
347 | - if ( method_exists( $this->xcloner_remote_storage, "upload_backup_to_storage" ) ) { |
|
348 | - call_user_func_array( array( |
|
347 | + if (method_exists($this->xcloner_remote_storage, "upload_backup_to_storage")) { |
|
348 | + call_user_func_array(array( |
|
349 | 349 | $this->xcloner_remote_storage, |
350 | 350 | "upload_backup_to_storage" |
351 | - ), array( $backup_file, $schedule['remote_storage'] ) ); |
|
351 | + ), array($backup_file, $schedule['remote_storage'])); |
|
352 | 352 | } |
353 | 353 | } |
354 | 354 | |
355 | 355 | //Sending email notification |
356 | - if ( isset( $schedule['backup_params']->email_notification ) and $to = $schedule['backup_params']->email_notification ) { |
|
356 | + if (isset($schedule['backup_params']->email_notification) and $to = $schedule['backup_params']->email_notification) { |
|
357 | 357 | try { |
358 | 358 | $from = ""; |
359 | 359 | $additional['lines_total'] = $return['extra']['lines_total']; |
360 | - $subject = sprintf( __( "%s - new backup generated %s" ), $schedule['name'], $return['extra']['backup_parent'] ); |
|
360 | + $subject = sprintf(__("%s - new backup generated %s"), $schedule['name'], $return['extra']['backup_parent']); |
|
361 | 361 | |
362 | - $this->archive_system->send_notification( $to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional ); |
|
362 | + $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional); |
|
363 | 363 | |
364 | - } catch ( Exception $e ) { |
|
365 | - $this->logger->error( $e->getMessage() ); |
|
364 | + }catch (Exception $e) { |
|
365 | + $this->logger->error($e->getMessage()); |
|
366 | 366 | } |
367 | 367 | } |
368 | 368 | |
369 | 369 | //CHECK IF WE SHOULD DELETE BACKUP AFTER REMOTE TRANSFER IS DONE |
370 | - if ( $schedule['remote_storage'] && $this->xcloner_settings->get_xcloner_option( 'xcloner_cleanup_delete_after_remote_transfer' ) ) { |
|
371 | - $this->logger->info( sprintf( "Deleting %s from local storage matching rule xcloner_cleanup_delete_after_remote_transfer", $return['extra']['backup_parent'] ) ); |
|
372 | - $this->xcloner_file_system->delete_backup_by_name( $return['extra']['backup_parent'] ); |
|
370 | + if ($schedule['remote_storage'] && $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_delete_after_remote_transfer')) { |
|
371 | + $this->logger->info(sprintf("Deleting %s from local storage matching rule xcloner_cleanup_delete_after_remote_transfer", $return['extra']['backup_parent'])); |
|
372 | + $this->xcloner_file_system->delete_backup_by_name($return['extra']['backup_parent']); |
|
373 | 373 | |
374 | 374 | } |
375 | 375 | |
@@ -383,28 +383,28 @@ discard block |
||
383 | 383 | $this->xcloner_file_system->cleanup_tmp_directories(); |
384 | 384 | } |
385 | 385 | |
386 | - public function xcloner_scheduler_callback( $id, $schedule = "" ) { |
|
387 | - if ( $id ) { |
|
388 | - $schedule = $this->get_schedule_by_id( $id ); |
|
386 | + public function xcloner_scheduler_callback($id, $schedule = "") { |
|
387 | + if ($id) { |
|
388 | + $schedule = $this->get_schedule_by_id($id); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | try { |
392 | - if( get_option('xcloner_disable_email_notification') ) { |
|
392 | + if (get_option('xcloner_disable_email_notification')) { |
|
393 | 393 | //we disable email notifications |
394 | 394 | $schedule['backup_params']->email_notification = ""; |
395 | 395 | } |
396 | - $this->_xcloner_scheduler_callback( $id, $schedule ); |
|
396 | + $this->_xcloner_scheduler_callback($id, $schedule); |
|
397 | 397 | |
398 | - } catch ( Exception $e ) { |
|
398 | + }catch (Exception $e) { |
|
399 | 399 | |
400 | 400 | //send email to site admin if email notification is not set in the scheduler |
401 | - if ( ! isset( $schedule['backup_params']->email_notification ) || ! $schedule['backup_params']->email_notification ) { |
|
402 | - $schedule['backup_params']->email_notification = get_option( 'admin_email' ); |
|
401 | + if (!isset($schedule['backup_params']->email_notification) || !$schedule['backup_params']->email_notification) { |
|
402 | + $schedule['backup_params']->email_notification = get_option('admin_email'); |
|
403 | 403 | } |
404 | 404 | |
405 | - if ( isset( $schedule['backup_params']->email_notification ) && $to = $schedule['backup_params']->email_notification ) { |
|
405 | + if (isset($schedule['backup_params']->email_notification) && $to = $schedule['backup_params']->email_notification) { |
|
406 | 406 | $from = ""; |
407 | - $this->archive_system->send_notification( $to, $from, $schedule['name'] . " - backup error", "", "", $e->getMessage() ); |
|
407 | + $this->archive_system->send_notification($to, $from, $schedule['name']." - backup error", "", "", $e->getMessage()); |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | } |