| Conditions | 23 |
| Paths | 5764 |
| Total Lines | 173 |
| Code Lines | 97 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 2 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 218 | private function _xcloner_scheduler_callback($id, $schedule) { |
||
| 219 | set_time_limit(0); |
||
| 220 | |||
| 221 | |||
| 222 | $xcloner = new XCloner(); |
||
| 223 | $xcloner->init(); |
||
| 224 | $this->set_xcloner_container($xcloner); |
||
| 225 | $return_encrypted = array(); |
||
| 226 | $return = array(); |
||
| 227 | $additional = array(); |
||
| 228 | |||
| 229 | #$hash = $this->xcloner_settings->get_hash(); |
||
| 230 | #$this->get_xcloner_container()->get_xcloner_settings()->set_hash($hash); |
||
| 231 | |||
| 232 | //$this->xcloner_settings = $this->get_xcloner_container()->get_xcloner_settings(); |
||
| 233 | $this->xcloner_file_system = $this->get_xcloner_container()->get_xcloner_filesystem(); |
||
| 234 | $this->xcloner_encryption = $this->get_xcloner_container()->get_xcloner_encryption(); |
||
| 235 | $this->xcloner_database = $this->get_xcloner_container()->get_xcloner_database(); |
||
| 236 | $this->archive_system = $this->get_xcloner_container()->get_archive_system(); |
||
| 237 | $this->logger = $this->get_xcloner_container()->get_xcloner_logger()->withName("xcloner_scheduler"); |
||
| 238 | $this->xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
||
| 239 | |||
| 240 | $this->logger->info(sprintf("New schedule hash is %s", $this->xcloner_settings->get_hash())); |
||
|
|
|||
| 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); |
||
| 244 | } |
||
| 245 | |||
| 246 | if ($schedule['recurrence'] == "single") { |
||
| 247 | $this->disable_single_cron($schedule['id']); |
||
| 248 | } |
||
| 249 | |||
| 250 | if (!$schedule) { |
||
| 251 | $this->logger->info(sprintf("Could not load schedule with id'%s'", $id), array("CRON")); |
||
| 252 | |||
| 253 | return; |
||
| 254 | } |
||
| 255 | |||
| 256 | //echo $this->get_xcloner_container()->get_xcloner_settings()->get_hash(); exit; |
||
| 257 | |||
| 258 | $this->update_hash($schedule['id'], $this->xcloner_settings->get_hash()); |
||
| 259 | |||
| 260 | $this->logger->info(sprintf("Starting cron schedule '%s'", $schedule['name']), array("CRON")); |
||
| 261 | |||
| 262 | $this->xcloner_file_system->set_excluded_files(json_decode($schedule['excluded_files'])); |
||
| 263 | |||
| 264 | $init = 1; |
||
| 265 | $continue = 1; |
||
| 266 | |||
| 267 | while ($continue) { |
||
| 268 | $continue = $this->xcloner_file_system->start_file_recursion($init); |
||
| 269 | |||
| 270 | $init = 0; |
||
| 271 | } |
||
| 272 | |||
| 273 | $this->logger->info(sprintf("File scan finished"), array("CRON")); |
||
| 274 | |||
| 275 | $this->logger->info(sprintf("Starting the database backup"), array("CRON")); |
||
| 276 | |||
| 277 | $init = 1; |
||
| 278 | $return['finished'] = 0; |
||
| 279 | |||
| 280 | while (!$return['finished']) { |
||
| 281 | $return = $this->xcloner_database->start_database_recursion((array)json_decode($schedule['table_params']), $return, $init); |
||
| 282 | $init = 0; |
||
| 283 | } |
||
| 284 | |||
| 285 | $this->logger->info(sprintf("Database backup done"), array("CRON")); |
||
| 286 | |||
| 287 | $this->logger->info(sprintf("Starting file archive process"), array("CRON")); |
||
| 288 | |||
| 289 | $init = 0; |
||
| 290 | $return['finished'] = 0; |
||
| 291 | $return['extra'] = array(); |
||
| 292 | |||
| 293 | while (!$return['finished']) { |
||
| 294 | $return = $this->archive_system->start_incremental_backup((array)$schedule['backup_params'], $return['extra'], $init); |
||
| 295 | $init = 0; |
||
| 296 | } |
||
| 297 | $this->logger->info(sprintf("File archive process FINISHED."), array("CRON")); |
||
| 298 | |||
| 299 | //getting the last backup archive file |
||
| 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())) { |
||
| 302 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
||
| 303 | } |
||
| 304 | |||
| 305 | //Updating schedule last backup archive |
||
| 306 | $this->update_last_backup($schedule['id'], $return['extra']['backup_parent']); |
||
| 307 | |||
| 308 | //Encrypting the backup archive |
||
| 309 | $return_encrypted['finished'] = 0; |
||
| 310 | $return_encrypted['start'] = 0; |
||
| 311 | $return_encrypted['iv'] = ''; |
||
| 312 | $return_encrypted['target_file'] = ''; |
||
| 313 | $part = 0; |
||
| 314 | $backup_parts = array(); |
||
| 315 | |||
| 316 | if ($schedule['backup_params']->backup_encrypt) { |
||
| 317 | $this->logger->info(sprintf("Encrypting backup archive %s.", $return['extra']['backup_parent']), array("CRON")); |
||
| 318 | |||
| 319 | $backup_file = $return['extra']['backup_parent']; |
||
| 320 | |||
| 321 | if ($this->xcloner_file_system->is_multipart($return['extra']['backup_parent'])) { |
||
| 322 | $backup_parts = $this->xcloner_file_system->get_multipart_files($return['extra']['backup_parent']); |
||
| 323 | $backup_file = $backup_parts[$part]; |
||
| 324 | } |
||
| 325 | |||
| 326 | while (!$return_encrypted['finished']) { |
||
| 327 | $return_encrypted = $this->xcloner_encryption->encrypt_file( |
||
| 328 | $backup_file, |
||
| 329 | "", |
||
| 330 | "", |
||
| 331 | "", |
||
| 332 | "", |
||
| 333 | true, |
||
| 334 | true |
||
| 335 | ); |
||
| 336 | |||
| 337 | if ($return_encrypted['finished']) { |
||
| 338 | ++$part; |
||
| 339 | |||
| 340 | if ($part < sizeof($backup_parts)) { |
||
| 341 | $return_encrypted['finished'] = 0; |
||
| 342 | $backup_file = $backup_parts[$part]; |
||
| 343 | } |
||
| 344 | } |
||
| 345 | } |
||
| 346 | } |
||
| 347 | |||
| 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())) { |
||
| 350 | $backup_file = $return['extra']['backup_parent']; |
||
| 351 | |||
| 352 | $this->logger->info(sprintf("Transferring backup to remote storage %s", strtoupper($schedule['remote_storage'])), array("CRON")); |
||
| 353 | |||
| 354 | if (method_exists($this->xcloner_remote_storage, "upload_backup_to_storage")) { |
||
| 355 | call_user_func_array(array( |
||
| 356 | $this->xcloner_remote_storage, |
||
| 357 | "upload_backup_to_storage" |
||
| 358 | ), array($backup_file, $schedule['remote_storage'])); |
||
| 359 | } |
||
| 360 | } |
||
| 361 | |||
| 362 | //Sending email notification |
||
| 363 | if (isset($schedule['backup_params']->email_notification) and $to = $schedule['backup_params']->email_notification) { |
||
| 364 | try { |
||
| 365 | $from = ""; |
||
| 366 | $additional['lines_total'] = $return['extra']['lines_total']; |
||
| 367 | $subject = sprintf(__("%s - new backup generated %s"), $schedule['name'], $return['extra']['backup_parent']); |
||
| 368 | |||
| 369 | $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional); |
||
| 370 | |||
| 371 | }catch (Exception $e) { |
||
| 372 | $this->logger->error($e->getMessage()); |
||
| 373 | } |
||
| 374 | } |
||
| 375 | |||
| 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']); |
||
| 380 | |||
| 381 | } |
||
| 382 | |||
| 383 | //Removing the tmp filesystem used for backup |
||
| 384 | $this->xcloner_file_system->remove_tmp_filesystem(); |
||
| 385 | |||
| 386 | //Backup Storage Cleanup |
||
| 387 | $this->xcloner_file_system->backup_storage_cleanup(); |
||
| 388 | |||
| 389 | //Filesystem Cleanup |
||
| 390 | $this->xcloner_file_system->cleanup_tmp_directories(); |
||
| 391 | } |
||
| 439 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.