@@ -13,13 +13,13 @@ discard block |
||
| 13 | 13 | private $xcloner_file_system; |
| 14 | 14 | private $xcloner_encryption; |
| 15 | 15 | |
| 16 | - private $allowed_schedules = array( "hourly", "twicedaily", "daily", "weekly", "monthly" ); |
|
| 16 | + private $allowed_schedules = array("hourly", "twicedaily", "daily", "weekly", "monthly"); |
|
| 17 | 17 | |
| 18 | 18 | /*public function __call($method, $args) { |
| 19 | 19 | echo "$method is not defined"; |
| 20 | 20 | }*/ |
| 21 | 21 | |
| 22 | - public function __construct( Xcloner $xcloner_container ) { |
|
| 22 | + public function __construct(Xcloner $xcloner_container) { |
|
| 23 | 23 | global $wpdb; |
| 24 | 24 | |
| 25 | 25 | $this->db = $wpdb; |
@@ -28,26 +28,26 @@ discard block |
||
| 28 | 28 | $this->xcloner_container = $xcloner_container; |
| 29 | 29 | $this->xcloner_settings = $this->xcloner_container->get_xcloner_settings(); |
| 30 | 30 | |
| 31 | - $this->scheduler_table = $this->db->prefix . $this->scheduler_table; |
|
| 31 | + $this->scheduler_table = $this->db->prefix.$this->scheduler_table; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | private function get_xcloner_container() { |
| 35 | 35 | return $this->xcloner_container; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - private function set_xcloner_container( Xcloner $container ) { |
|
| 38 | + private function set_xcloner_container(Xcloner $container) { |
|
| 39 | 39 | $this->xcloner_container = $container; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public function get_scheduler_list( $return_only_enabled = 0 ) { |
|
| 43 | - $list = $this->db->get_results( "SELECT * FROM " . $this->scheduler_table ); |
|
| 42 | + public function get_scheduler_list($return_only_enabled = 0) { |
|
| 43 | + $list = $this->db->get_results("SELECT * FROM ".$this->scheduler_table); |
|
| 44 | 44 | |
| 45 | - if ( $return_only_enabled ) { |
|
| 45 | + if ($return_only_enabled) { |
|
| 46 | 46 | $new_list = array(); |
| 47 | 47 | |
| 48 | - foreach ( $list as $res ) { |
|
| 49 | - if ( $res->status ) { |
|
| 50 | - $res->next_run_time = wp_next_scheduled( 'xcloner_scheduler_' . $res->id, array( $res->id ) ) + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
| 48 | + foreach ($list as $res) { |
|
| 49 | + if ($res->status) { |
|
| 50 | + $res->next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id)) + (get_option('gmt_offset') * HOUR_IN_SECONDS); |
|
| 51 | 51 | $new_list[] = $res; |
| 52 | 52 | } |
| 53 | 53 | } |
@@ -58,40 +58,40 @@ discard block |
||
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | public function get_next_run_schedule( ) { |
| 61 | - $list = $this->get_scheduler_list( $return_only_enabled = 1 ); |
|
| 61 | + $list = $this->get_scheduler_list($return_only_enabled = 1); |
|
| 62 | 62 | |
| 63 | 63 | return $list; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - public function get_schedule_by_id_object( $id ) { |
|
| 67 | - $data = $this->db->get_row( "SELECT * FROM " . $this->scheduler_table . " WHERE id=" . $id ); |
|
| 66 | + public function get_schedule_by_id_object($id) { |
|
| 67 | + $data = $this->db->get_row("SELECT * FROM ".$this->scheduler_table." WHERE id=".$id); |
|
| 68 | 68 | |
| 69 | 69 | return $data; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - public function get_schedule_by_id( $id ) { |
|
| 73 | - $data = $this->db->get_row( "SELECT * FROM " . $this->scheduler_table . " WHERE id=" . $id, ARRAY_A ); |
|
| 72 | + public function get_schedule_by_id($id) { |
|
| 73 | + $data = $this->db->get_row("SELECT * FROM ".$this->scheduler_table." WHERE id=".$id, ARRAY_A); |
|
| 74 | 74 | |
| 75 | - if ( ! $data ) { |
|
| 75 | + if (!$data) { |
|
| 76 | 76 | return false; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - $params = json_decode( $data['params'] ); |
|
| 79 | + $params = json_decode($data['params']); |
|
| 80 | 80 | |
| 81 | 81 | //print_r($params); |
| 82 | 82 | $data['params'] = ""; |
| 83 | 83 | $data['backup_params'] = $params->backup_params; |
| 84 | - $data['table_params'] = json_encode( $params->database ); |
|
| 85 | - $data['excluded_files'] = json_encode( $params->excluded_files ); |
|
| 84 | + $data['table_params'] = json_encode($params->database); |
|
| 85 | + $data['excluded_files'] = json_encode($params->excluded_files); |
|
| 86 | 86 | |
| 87 | 87 | return $data; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - public function delete_schedule_by_id( $id ) { |
|
| 91 | - $hook = 'xcloner_scheduler_' . $id; |
|
| 92 | - wp_clear_scheduled_hook( $hook, array( $id ) ); |
|
| 90 | + public function delete_schedule_by_id($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 | } |
@@ -99,68 +99,68 @@ discard block |
||
| 99 | 99 | public function deactivate_wp_cron_hooks() { |
| 100 | 100 | $list = $this->get_scheduler_list(); |
| 101 | 101 | |
| 102 | - foreach ( $list as $schedule ) { |
|
| 103 | - $hook = 'xcloner_scheduler_' . $schedule->id; |
|
| 102 | + foreach ($list as $schedule) { |
|
| 103 | + $hook = 'xcloner_scheduler_'.$schedule->id; |
|
| 104 | 104 | |
| 105 | - $timestamp = wp_next_scheduled( $hook, array( $schedule->id ) ); |
|
| 106 | - wp_unschedule_event( $timestamp, $hook, array( $schedule->id ) ); |
|
| 105 | + $timestamp = wp_next_scheduled($hook, array($schedule->id)); |
|
| 106 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | public function update_wp_cron_hooks() { |
| 111 | 111 | $list = $this->get_scheduler_list(); |
| 112 | 112 | |
| 113 | - foreach ( $list as $schedule ) { |
|
| 114 | - $hook = 'xcloner_scheduler_' . $schedule->id; |
|
| 113 | + foreach ($list as $schedule) { |
|
| 114 | + $hook = 'xcloner_scheduler_'.$schedule->id; |
|
| 115 | 115 | |
| 116 | 116 | //adding the xcloner_scheduler hook with xcloner_scheduler_callback callback |
| 117 | - add_action( $hook, array( $this, 'xcloner_scheduler_callback' ), 10, 1 ); |
|
| 117 | + add_action($hook, array($this, 'xcloner_scheduler_callback'), 10, 1); |
|
| 118 | 118 | |
| 119 | - if ( ! wp_next_scheduled( $hook, array( $schedule->id ) ) and $schedule->status ) { |
|
| 119 | + if (!wp_next_scheduled($hook, array($schedule->id)) and $schedule->status) { |
|
| 120 | 120 | |
| 121 | - if ( $schedule->recurrence == "single" ) { |
|
| 122 | - wp_schedule_single_event( strtotime( $schedule->start_at ), $hook, array( $schedule->id ) ); |
|
| 121 | + if ($schedule->recurrence == "single") { |
|
| 122 | + wp_schedule_single_event(strtotime($schedule->start_at), $hook, array($schedule->id)); |
|
| 123 | 123 | } else { |
| 124 | - wp_schedule_event( strtotime( $schedule->start_at ), $schedule->recurrence, $hook, array( $schedule->id ) ); |
|
| 124 | + wp_schedule_event(strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id)); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - } elseif ( ! $schedule->status ) { |
|
| 128 | - $timestamp = wp_next_scheduled( $hook, array( $schedule->id ) ); |
|
| 129 | - wp_unschedule_event( $timestamp, $hook, array( $schedule->id ) ); |
|
| 127 | + } elseif (!$schedule->status) { |
|
| 128 | + $timestamp = wp_next_scheduled($hook, array($schedule->id)); |
|
| 129 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - public function update_cron_hook( $id ) { |
|
| 136 | - $schedule = $this->get_schedule_by_id_object( $id ); |
|
| 137 | - $hook = 'xcloner_scheduler_' . $schedule->id; |
|
| 135 | + public function update_cron_hook($id) { |
|
| 136 | + $schedule = $this->get_schedule_by_id_object($id); |
|
| 137 | + $hook = 'xcloner_scheduler_'.$schedule->id; |
|
| 138 | 138 | |
| 139 | - $timestamp = wp_next_scheduled( $hook, array( $schedule->id ) ); |
|
| 140 | - wp_unschedule_event( $timestamp, $hook, array( $schedule->id ) ); |
|
| 139 | + $timestamp = wp_next_scheduled($hook, array($schedule->id)); |
|
| 140 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
| 141 | 141 | |
| 142 | - if ( $schedule->status ) { |
|
| 142 | + if ($schedule->status) { |
|
| 143 | 143 | |
| 144 | - if ( $schedule->recurrence == "single" ) { |
|
| 145 | - wp_schedule_single_event( strtotime( $schedule->start_at ), $hook, array( $schedule->id ) ); |
|
| 144 | + if ($schedule->recurrence == "single") { |
|
| 145 | + wp_schedule_single_event(strtotime($schedule->start_at), $hook, array($schedule->id)); |
|
| 146 | 146 | } else { |
| 147 | - wp_schedule_event( strtotime( $schedule->start_at ), $schedule->recurrence, $hook, array( $schedule->id ) ); |
|
| 147 | + wp_schedule_event(strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id)); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - public function disable_single_cron( $schedule_id ) { |
|
| 154 | - $hook = 'xcloner_scheduler_' . $schedule_id; |
|
| 155 | - $timestamp = wp_next_scheduled( $hook, array( $schedule_id ) ); |
|
| 156 | - wp_unschedule_event( $timestamp, $hook, array( $schedule_id ) ); |
|
| 153 | + public function disable_single_cron($schedule_id) { |
|
| 154 | + $hook = 'xcloner_scheduler_'.$schedule_id; |
|
| 155 | + $timestamp = wp_next_scheduled($hook, array($schedule_id)); |
|
| 156 | + wp_unschedule_event($timestamp, $hook, array($schedule_id)); |
|
| 157 | 157 | |
| 158 | 158 | $schedule['status'] = 0; |
| 159 | 159 | |
| 160 | 160 | $update = $this->db->update( |
| 161 | 161 | $this->scheduler_table, |
| 162 | 162 | $schedule, |
| 163 | - array( 'id' => $schedule_id ), |
|
| 163 | + array('id' => $schedule_id), |
|
| 164 | 164 | array( |
| 165 | 165 | '%s', |
| 166 | 166 | '%s' |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | return $update; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - public function update_hash( $schedule_id, $hash ) { |
|
| 173 | + public function update_hash($schedule_id, $hash) { |
|
| 174 | 174 | $schedule = array(); |
| 175 | 175 | |
| 176 | 176 | $schedule['hash'] = $hash; |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | $update = $this->db->update( |
| 179 | 179 | $this->scheduler_table, |
| 180 | 180 | $schedule, |
| 181 | - array( 'id' => $schedule_id ), |
|
| 181 | + array('id' => $schedule_id), |
|
| 182 | 182 | array( |
| 183 | 183 | '%s', |
| 184 | 184 | '%s' |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | return $update; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - public function update_last_backup( $schedule_id, $last_backup ) { |
|
| 191 | + public function update_last_backup($schedule_id, $last_backup) { |
|
| 192 | 192 | |
| 193 | 193 | $this->logger->info(sprintf('Updating last backup %s for schedule id #%s', $last_backup, $schedule_id)); |
| 194 | 194 | |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | $update = $this->db->update( |
| 198 | 198 | $this->scheduler_table, |
| 199 | 199 | $schedule, |
| 200 | - array( 'id' => $schedule_id ), |
|
| 200 | + array('id' => $schedule_id), |
|
| 201 | 201 | array( |
| 202 | 202 | '%s', |
| 203 | 203 | '%s' |
@@ -207,91 +207,91 @@ discard block |
||
| 207 | 207 | return $update; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - private function _xcloner_scheduler_callback( $id, $schedule ) { |
|
| 211 | - set_time_limit( 0 ); |
|
| 210 | + private function _xcloner_scheduler_callback($id, $schedule) { |
|
| 211 | + set_time_limit(0); |
|
| 212 | 212 | |
| 213 | 213 | $xcloner = new XCloner(); |
| 214 | 214 | $xcloner->init(); |
| 215 | - $this->set_xcloner_container( $xcloner ); |
|
| 215 | + $this->set_xcloner_container($xcloner); |
|
| 216 | 216 | |
| 217 | 217 | #$hash = $this->xcloner_settings->get_hash(); |
| 218 | 218 | #$this->get_xcloner_container()->get_xcloner_settings()->set_hash($hash); |
| 219 | 219 | |
| 220 | 220 | //$this->xcloner_settings = $this->get_xcloner_container()->get_xcloner_settings(); |
| 221 | 221 | $this->xcloner_file_system = $this->get_xcloner_container()->get_xcloner_filesystem(); |
| 222 | - $this->xcloner_encryption = $this->get_xcloner_container()->get_xcloner_encryption(); |
|
| 222 | + $this->xcloner_encryption = $this->get_xcloner_container()->get_xcloner_encryption(); |
|
| 223 | 223 | $this->xcloner_database = $this->get_xcloner_container()->get_xcloner_database(); |
| 224 | 224 | $this->archive_system = $this->get_xcloner_container()->get_archive_system(); |
| 225 | - $this->logger = $this->get_xcloner_container()->get_xcloner_logger()->withName( "xcloner_scheduler" ); |
|
| 225 | + $this->logger = $this->get_xcloner_container()->get_xcloner_logger()->withName("xcloner_scheduler"); |
|
| 226 | 226 | $this->xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
| 227 | 227 | |
| 228 | - $this->logger->info( sprintf( "New schedule hash is %s", $this->xcloner_settings->get_hash() ) ); |
|
| 228 | + $this->logger->info(sprintf("New schedule hash is %s", $this->xcloner_settings->get_hash())); |
|
| 229 | 229 | |
| 230 | - if ( isset( $schedule['backup_params']->diff_start_date ) && $schedule['backup_params']->diff_start_date ) { |
|
| 231 | - $this->xcloner_file_system->set_diff_timestamp_start( $schedule['backup_params']->diff_start_date ); |
|
| 230 | + if (isset($schedule['backup_params']->diff_start_date) && $schedule['backup_params']->diff_start_date) { |
|
| 231 | + $this->xcloner_file_system->set_diff_timestamp_start($schedule['backup_params']->diff_start_date); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - if ( $schedule['recurrence'] == "single" ) { |
|
| 235 | - $this->disable_single_cron( $schedule['id'] ); |
|
| 234 | + if ($schedule['recurrence'] == "single") { |
|
| 235 | + $this->disable_single_cron($schedule['id']); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - if ( ! $schedule ) { |
|
| 239 | - $this->logger->info( sprintf( "Could not load schedule with id'%s'", $id ), array( "CRON" ) ); |
|
| 238 | + if (!$schedule) { |
|
| 239 | + $this->logger->info(sprintf("Could not load schedule with id'%s'", $id), array("CRON")); |
|
| 240 | 240 | |
| 241 | 241 | return; |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | //echo $this->get_xcloner_container()->get_xcloner_settings()->get_hash(); exit; |
| 245 | 245 | |
| 246 | - $this->update_hash( $schedule['id'], $this->xcloner_settings->get_hash() ); |
|
| 246 | + $this->update_hash($schedule['id'], $this->xcloner_settings->get_hash()); |
|
| 247 | 247 | |
| 248 | - $this->logger->info( sprintf( "Starting cron schedule '%s'", $schedule['name'] ), array( "CRON" ) ); |
|
| 248 | + $this->logger->info(sprintf("Starting cron schedule '%s'", $schedule['name']), array("CRON")); |
|
| 249 | 249 | |
| 250 | - $this->xcloner_file_system->set_excluded_files( json_decode( $schedule['excluded_files'] ) ); |
|
| 250 | + $this->xcloner_file_system->set_excluded_files(json_decode($schedule['excluded_files'])); |
|
| 251 | 251 | |
| 252 | 252 | $init = 1; |
| 253 | 253 | $continue = 1; |
| 254 | 254 | |
| 255 | - while ( $continue ) { |
|
| 256 | - $continue = $this->xcloner_file_system->start_file_recursion( $init ); |
|
| 255 | + while ($continue) { |
|
| 256 | + $continue = $this->xcloner_file_system->start_file_recursion($init); |
|
| 257 | 257 | |
| 258 | 258 | $init = 0; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - $this->logger->info( sprintf( "File scan finished" ), array( "CRON" ) ); |
|
| 261 | + $this->logger->info(sprintf("File scan finished"), array("CRON")); |
|
| 262 | 262 | |
| 263 | - $this->logger->info( sprintf( "Starting the database backup" ), array( "CRON" ) ); |
|
| 263 | + $this->logger->info(sprintf("Starting the database backup"), array("CRON")); |
|
| 264 | 264 | |
| 265 | 265 | $init = 1; |
| 266 | 266 | $return['finished'] = 0; |
| 267 | 267 | |
| 268 | - while ( ! $return['finished'] ) { |
|
| 269 | - $return = $this->xcloner_database->start_database_recursion( (array) json_decode( $schedule['table_params'] ), $return, $init ); |
|
| 268 | + while (!$return['finished']) { |
|
| 269 | + $return = $this->xcloner_database->start_database_recursion((array)json_decode($schedule['table_params']), $return, $init); |
|
| 270 | 270 | $init = 0; |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - $this->logger->info( sprintf( "Database backup done" ), array( "CRON" ) ); |
|
| 273 | + $this->logger->info(sprintf("Database backup done"), array("CRON")); |
|
| 274 | 274 | |
| 275 | - $this->logger->info( sprintf( "Starting file archive process" ), array( "CRON" ) ); |
|
| 275 | + $this->logger->info(sprintf("Starting file archive process"), array("CRON")); |
|
| 276 | 276 | |
| 277 | 277 | $init = 0; |
| 278 | 278 | $return['finished'] = 0; |
| 279 | 279 | $return['extra'] = array(); |
| 280 | 280 | |
| 281 | - while ( ! $return['finished'] ) { |
|
| 282 | - $return = $this->archive_system->start_incremental_backup( (array) $schedule['backup_params'], $return['extra'], $init ); |
|
| 281 | + while (!$return['finished']) { |
|
| 282 | + $return = $this->archive_system->start_incremental_backup((array)$schedule['backup_params'], $return['extra'], $init); |
|
| 283 | 283 | $init = 0; |
| 284 | 284 | } |
| 285 | - $this->logger->info( sprintf( "File archive process FINISHED." ), array( "CRON" ) ); |
|
| 285 | + $this->logger->info(sprintf("File archive process FINISHED."), array("CRON")); |
|
| 286 | 286 | |
| 287 | 287 | //getting the last backup archive file |
| 288 | 288 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); |
| 289 | - if ( $this->xcloner_file_system->is_part( $this->archive_system->get_archive_name_with_extension() ) ) { |
|
| 289 | + if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) { |
|
| 290 | 290 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | //Updating schedule last backup archive |
| 294 | - $this->update_last_backup( $schedule['id'], $return['extra']['backup_parent'] ); |
|
| 294 | + $this->update_last_backup($schedule['id'], $return['extra']['backup_parent']); |
|
| 295 | 295 | |
| 296 | 296 | //Encrypting the backup archive |
| 297 | 297 | $return_encrypted['finished'] = 0; |
@@ -301,8 +301,8 @@ discard block |
||
| 301 | 301 | $part = 0; |
| 302 | 302 | $backup_parts = array(); |
| 303 | 303 | |
| 304 | - if( $schedule['backup_params']->backup_encrypt){ |
|
| 305 | - $this->logger->info( sprintf( "Encrypting backup archive %s.", $return['extra']['backup_parent'] ), array( "CRON" ) ); |
|
| 304 | + if ($schedule['backup_params']->backup_encrypt) { |
|
| 305 | + $this->logger->info(sprintf("Encrypting backup archive %s.", $return['extra']['backup_parent']), array("CRON")); |
|
| 306 | 306 | |
| 307 | 307 | $backup_file = $return['extra']['backup_parent']; |
| 308 | 308 | |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | $backup_file = $backup_parts[$part]; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - while ( ! $return_encrypted['finished'] ) { |
|
| 314 | + while (!$return_encrypted['finished']) { |
|
| 315 | 315 | $return_encrypted = $this->xcloner_encryption->encrypt_file( |
| 316 | 316 | $backup_file, |
| 317 | 317 | "", |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | true |
| 323 | 323 | ); |
| 324 | 324 | |
| 325 | - if($return_encrypted['finished']) { |
|
| 325 | + if ($return_encrypted['finished']) { |
|
| 326 | 326 | ++$part; |
| 327 | 327 | |
| 328 | 328 | if ($part < sizeof($backup_parts)) { |
@@ -334,37 +334,37 @@ discard block |
||
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | //Sending backup to remote storage |
| 337 | - if ( isset( $schedule['remote_storage'] ) && $schedule['remote_storage'] && array_key_exists( $schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages() ) ) { |
|
| 337 | + if (isset($schedule['remote_storage']) && $schedule['remote_storage'] && array_key_exists($schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages())) { |
|
| 338 | 338 | $backup_file = $return['extra']['backup_parent']; |
| 339 | 339 | |
| 340 | - $this->logger->info( sprintf( "Transferring backup to remote storage %s", strtoupper( $schedule['remote_storage'] ) ), array( "CRON" ) ); |
|
| 340 | + $this->logger->info(sprintf("Transferring backup to remote storage %s", strtoupper($schedule['remote_storage'])), array("CRON")); |
|
| 341 | 341 | |
| 342 | - if ( method_exists( $this->xcloner_remote_storage, "upload_backup_to_storage" ) ) { |
|
| 343 | - call_user_func_array( array( |
|
| 342 | + if (method_exists($this->xcloner_remote_storage, "upload_backup_to_storage")) { |
|
| 343 | + call_user_func_array(array( |
|
| 344 | 344 | $this->xcloner_remote_storage, |
| 345 | 345 | "upload_backup_to_storage" |
| 346 | - ), array( $backup_file, $schedule['remote_storage'] ) ); |
|
| 346 | + ), array($backup_file, $schedule['remote_storage'])); |
|
| 347 | 347 | } |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | //Sending email notification |
| 351 | - if ( isset( $schedule['backup_params']->email_notification ) and $to = $schedule['backup_params']->email_notification ) { |
|
| 351 | + if (isset($schedule['backup_params']->email_notification) and $to = $schedule['backup_params']->email_notification) { |
|
| 352 | 352 | try { |
| 353 | 353 | $from = ""; |
| 354 | 354 | $additional['lines_total'] = $return['extra']['lines_total']; |
| 355 | - $subject = sprintf( __( "%s - new backup generated %s" ), $schedule['name'], $return['extra']['backup_parent'] ); |
|
| 355 | + $subject = sprintf(__("%s - new backup generated %s"), $schedule['name'], $return['extra']['backup_parent']); |
|
| 356 | 356 | |
| 357 | - $this->archive_system->send_notification( $to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional ); |
|
| 357 | + $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional); |
|
| 358 | 358 | |
| 359 | - } catch ( Exception $e ) { |
|
| 360 | - $this->logger->error( $e->getMessage() ); |
|
| 359 | + }catch (Exception $e) { |
|
| 360 | + $this->logger->error($e->getMessage()); |
|
| 361 | 361 | } |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | //CHECK IF WE SHOULD DELETE BACKUP AFTER REMOTE TRANSFER IS DONE |
| 365 | - if ( $schedule['remote_storage'] && $this->xcloner_settings->get_xcloner_option( 'xcloner_cleanup_delete_after_remote_transfer' ) ) { |
|
| 366 | - $this->logger->info( sprintf( "Deleting %s from local storage matching rule xcloner_cleanup_delete_after_remote_transfer", $return['extra']['backup_parent'] ) ); |
|
| 367 | - $this->xcloner_file_system->delete_backup_by_name( $return['extra']['backup_parent'] ); |
|
| 365 | + if ($schedule['remote_storage'] && $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_delete_after_remote_transfer')) { |
|
| 366 | + $this->logger->info(sprintf("Deleting %s from local storage matching rule xcloner_cleanup_delete_after_remote_transfer", $return['extra']['backup_parent'])); |
|
| 367 | + $this->xcloner_file_system->delete_backup_by_name($return['extra']['backup_parent']); |
|
| 368 | 368 | |
| 369 | 369 | } |
| 370 | 370 | |
@@ -378,28 +378,28 @@ discard block |
||
| 378 | 378 | $this->xcloner_file_system->cleanup_tmp_directories(); |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - public function xcloner_scheduler_callback( $id, $schedule = "" ) { |
|
| 382 | - if ( $id ) { |
|
| 383 | - $schedule = $this->get_schedule_by_id( $id ); |
|
| 381 | + public function xcloner_scheduler_callback($id, $schedule = "") { |
|
| 382 | + if ($id) { |
|
| 383 | + $schedule = $this->get_schedule_by_id($id); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | try { |
| 387 | - if( get_option('xcloner_disable_email_notification') ) { |
|
| 387 | + if (get_option('xcloner_disable_email_notification')) { |
|
| 388 | 388 | //we disable email notifications |
| 389 | 389 | $schedule['backup_params']->email_notification = ""; |
| 390 | 390 | } |
| 391 | - $this->_xcloner_scheduler_callback( $id, $schedule ); |
|
| 391 | + $this->_xcloner_scheduler_callback($id, $schedule); |
|
| 392 | 392 | |
| 393 | - } catch ( Exception $e ) { |
|
| 393 | + }catch (Exception $e) { |
|
| 394 | 394 | |
| 395 | 395 | //send email to site admin if email notification is not set in the scheduler |
| 396 | - if ( ! isset( $schedule['backup_params']->email_notification ) || ! $schedule['backup_params']->email_notification ) { |
|
| 397 | - $schedule['backup_params']->email_notification = get_option( 'admin_email' ); |
|
| 396 | + if (!isset($schedule['backup_params']->email_notification) || !$schedule['backup_params']->email_notification) { |
|
| 397 | + $schedule['backup_params']->email_notification = get_option('admin_email'); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | - if ( isset( $schedule['backup_params']->email_notification ) && $to = $schedule['backup_params']->email_notification ) { |
|
| 400 | + if (isset($schedule['backup_params']->email_notification) && $to = $schedule['backup_params']->email_notification) { |
|
| 401 | 401 | $from = ""; |
| 402 | - $this->archive_system->send_notification( $to, $from, $schedule['name'] . " - backup error", "", "", $e->getMessage() ); |
|
| 402 | + $this->archive_system->send_notification($to, $from, $schedule['name']." - backup error", "", "", $e->getMessage()); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | } |
@@ -410,14 +410,14 @@ discard block |
||
| 410 | 410 | $schedules = wp_get_schedules(); |
| 411 | 411 | $new_schedules = array(); |
| 412 | 412 | |
| 413 | - foreach ( $schedules as $key => $row ) { |
|
| 414 | - if ( in_array( $key, $this->allowed_schedules ) ) { |
|
| 415 | - $new_schedules[ $key ] = $row; |
|
| 416 | - $intervals[ $key ] = $row['interval']; |
|
| 413 | + foreach ($schedules as $key => $row) { |
|
| 414 | + if (in_array($key, $this->allowed_schedules)) { |
|
| 415 | + $new_schedules[$key] = $row; |
|
| 416 | + $intervals[$key] = $row['interval']; |
|
| 417 | 417 | } |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | - array_multisort( $intervals, SORT_ASC, $new_schedules ); |
|
| 420 | + array_multisort($intervals, SORT_ASC, $new_schedules); |
|
| 421 | 421 | |
| 422 | 422 | return $new_schedules; |
| 423 | 423 | } |