/** * Gets the settings for a similar destination from the existing schedules * so that we can copy them into the form to avoid having to type them again */ protected function fetch_destination_settings() { $service = get_class($this); $schedules_obj = HMBKP_Schedules::get_instance(); $schedules = $schedules_obj->get_schedules(); foreach ($schedules as $schedule) { if ($schedule->get_id() != $this->schedule->get_id()) { $options = $schedule->get_service_options($service); if (!empty($options)) { return $options; } } } return array(); }
/** * Display the row of actions for a schedule * * @access public * @param HMBKP_Scheduled_Backup $schedule * @return void */ function hmbkp_schedule_actions(HMBKP_Scheduled_Backup $schedule) { // Start output buffering ob_start(); ?> <span class="hmbkp-status"><?php echo $schedule->get_status() ? wp_kses_data($schedule->get_status()) : __('Starting Backup', 'hmbkp'); ?> <a href="<?php echo esc_url(add_query_arg(array('action' => 'hmbkp_cancel', 'hmbkp_schedule_id' => $schedule->get_id()), HMBKP_ADMIN_URL)); ?> "><?php _e('cancel', 'hmbkp'); ?> </a></span> <div class="hmbkp-schedule-actions row-actions"> <a class="colorbox" href="<?php echo esc_url(add_query_arg(array('action' => 'hmbkp_edit_schedule_load', 'hmbkp_schedule_id' => $schedule->get_id()), admin_url('admin-ajax.php'))); ?> "><?php _e('Settings', 'hmbkp'); ?> </a> | <?php if ($schedule->get_type() !== 'database') { ?> <a class="colorbox" href="<?php echo esc_url(add_query_arg(array('action' => 'hmbkp_edit_schedule_excludes_load', 'hmbkp_schedule_id' => $schedule->get_id()), admin_url('admin-ajax.php'))); ?> "><?php _e('Excludes', 'hmbkp'); ?> </a> | <?php } ?> <?php // capture output $output = ob_get_clean(); echo apply_filters('hmbkp_schedule_actions_menu', $output, $schedule); ?> <a class="hmbkp-run" href="<?php echo esc_url(add_query_arg(array('action' => 'hmbkp_run_schedule', 'hmbkp_schedule_id' => $schedule->get_id()), admin_url('admin-ajax.php'))); ?> "><?php _e('Run now', 'hmbkp'); ?> </a> | <a class="delete-action" href="<?php echo wp_nonce_url(add_query_arg(array('action' => 'hmbkp_delete_schedule', 'hmbkp_schedule_id' => $schedule->get_id()), HMBKP_ADMIN_URL), 'hmbkp-delete_schedule'); ?> "><?php _e('Delete', 'hmbkp'); ?> </a> </div> <?php }
/** * Setup the default backup schedules */ function hmbkp_setup_default_schedules() { $schedules = HMBKP_Schedules::get_instance(); if ($schedules->get_schedules()) { return; } /** * Schedule a database backup daily and store backups * for the last 2 weeks */ $database_daily = new HMBKP_Scheduled_Backup('default-1'); $database_daily->set_type('database'); $database_daily->set_reoccurrence('hmbkp_daily'); $database_daily->set_max_backups(14); $database_daily->save(); /** * Schedule a complete backup to run weekly and store backups for * the last 3 months */ $complete_weekly = new HMBKP_Scheduled_Backup('default-2'); $complete_weekly->set_type('complete'); $complete_weekly->set_reoccurrence('hmbkp_weekly'); $complete_weekly->set_max_backups(12); $complete_weekly->save(); function hmbkp_default_schedules_setup_warning() { echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress has setup your default schedules.', 'hmbkp') . '</strong> ' . __('By default BackUpWordPress performs a daily backup of your database and a weekly backup of your database & files. You can modify these schedules.', 'hmbkp') . '</p></div>'; } add_action('admin_notices', 'hmbkp_default_schedules_setup_warning'); }
/** * Display the running status via ajax */ function hmbkp_ajax_is_backup_in_progress() { check_ajax_referer('hmbkp_nonce', 'nonce'); if (empty($_POST['hmbkp_schedule_id'])) { die; } $schedule = new HMBKP_Scheduled_Backup(sanitize_text_field(urldecode($_POST['hmbkp_schedule_id']))); if (!$schedule->get_status()) { echo 0; } else { hmbkp_schedule_status($schedule); } die; }
/** * Returns a formatted string containing the calculated total site size or a message * to indicate it is being calculated. * * @param HMBKP_Scheduled_Backup $schedule * * @return string */ function hmbkp_get_site_size_text(HMBKP_Scheduled_Backup $schedule) { if (isset($_GET['hmbkp_add_schedule'])) { return ''; } elseif ('database' === $schedule->get_type() || $schedule->is_site_size_cached()) { return sprintf('(<code title="' . __('Backups will be compressed and should be smaller than this.', 'backupwordpress') . '">%s</code>)', esc_attr($schedule->get_formatted_site_size())); } else { return sprintf('(<code class="calculating" title="' . __('this shouldn\'t take long…', 'backupwordpress') . '">' . __('calculating the size of your backup…', 'backupwordpress') . '</code>)'); } }
/** * Delete an exclude rule * * @access public * @return void */ function hmbkp_delete_exclude_rule() { if (empty($_GET['hmbkp_schedule_id'])) { die; } $schedule = new HMBKP_Scheduled_Backup(sanitize_text_field($_GET['hmbkp_schedule_id'])); $excludes = $schedule->get_excludes(); $schedule->set_excludes(array_diff($excludes, (array) stripslashes(sanitize_text_field($_GET['hmbkp_exclude_rule'])))); $schedule->save(); require HMBKP_PLUGIN_PATH . '/admin/schedule-form-excludes.php'; die; }
/** * Display the row of actions for a schedule * * @access public * @param HMBKP_Scheduled_Backup $schedule * @return void */ function hmbkp_schedule_status(HMBKP_Scheduled_Backup $schedule, $echo = true) { ob_start(); ?> <span class="hmbkp-status"<?php if ($schedule->get_status()) { ?> title="<?php printf(__('Started %s ago', 'hmbkp'), human_time_diff($schedule->get_schedule_running_start_time())); ?> "<?php } ?> > <?php echo $schedule->get_status() ? wp_kses_data($schedule->get_status()) : __('Starting Backup', 'hmbkp'); ?> <a href="<?php echo esc_url(wp_nonce_url(add_query_arg(array('action' => 'hmbkp_request_cancel_backup', 'hmbkp_schedule_id' => $schedule->get_id()), hmbkp_get_settings_url()), 'hmbkp_request_cancel_backup', 'hmbkp_request_cancel_backup_nonce')); ?> "><?php _e('cancel', 'hmbkp'); ?> </a> </span> <?php $output = ob_get_clean(); if (!$echo) { return $output; } echo $output; }
/** * @param string $type the type of the schedule * @param array $times { * An array of time arguments. Optional. * * @type int $minutes The minute to start the schedule on. Defaults to current time + 10 minutes. Accepts * any valid `date( 'i' )` output. * @type int $hours The hour to start the schedule on. Defaults to current time + 10 minutes. Accepts * any valid `date( 'G' )` output. * @type string $day_of_week The day of the week to start the schedule on. Defaults to current time + 10 minutes. Accepts * any valid `date( 'l' )` output. * @type int $day_of_month The day of the month to start the schedule on. Defaults to current time + 10 minutes. Accepts * any valid `date( 'j' )` output. * @type int $now The current time. Defaults to `time()`. Accepts any valid timestamp. * * } * @return int $timestamp Returns the resulting timestamp on success and Int 0 on failure */ function hmbkp_determine_start_time($type, $times = array()) { // Default to in 10 minutes if (!empty($times['now'])) { $default_timestamp = $times['now'] + 600; } else { $default_timestamp = time() + 600; } $default_times = array('minutes' => date('i', $default_timestamp), 'hours' => date('G', $default_timestamp), 'day_of_week' => date('l', $default_timestamp), 'day_of_month' => date('j', $default_timestamp), 'now' => time()); $args = wp_parse_args($times, $default_times); $schedule_start = ''; $intervals = HMBKP_Scheduled_Backup::get_cron_schedules(); // Allow the hours and minutes to be overwritten by a constant if (defined('HMBKP_SCHEDULE_TIME') && HMBKP_SCHEDULE_TIME) { $hm = HMBKP_SCHEDULE_TIME; } else { $hm = $args['hours'] . ':' . $args['minutes'] . ':00'; } switch ($type) { case 'hmbkp_hourly': case 'hmbkp_daily': case 'hmbkp_twicedaily': // The next occurance of the specified time $schedule_start = $hm; break; case 'hmbkp_weekly': case 'hmbkp_fortnightly': // The next day of the week at the specified time $schedule_start = $args['day_of_week'] . ' ' . $hm; break; case 'hmbkp_monthly': // The occurance of the time on the specified day of the month $schedule_start = date('F', $args['now']) . ' ' . $args['day_of_month'] . ' ' . $hm; // If we've already gone past that day this month then we'll need to start next month if (strtotime($schedule_start, $args['now']) <= $args['now']) { $schedule_start = date('F', strtotime('+ 1 month', $args['now'])) . ' ' . $args['day_of_month'] . ' ' . $hm; } // If that's still in the past then we'll need to jump to next year if (strtotime($schedule_start, $args['now']) <= $args['now']) { $schedule_start = date('F', strtotime('+ 1 month', $args['now'])) . ' ' . $args['day_of_month'] . ' ' . date('Y', strtotime('+ 1 year', $args['now'])) . ' ' . $hm; } break; default: return 0; break; } $timestamp = strtotime($schedule_start, $args['now']); // Convert to UTC $timestamp -= get_option('gmt_offset') * 3600; // If the scheduled time already passed then keep adding the interval until we get to a future date while ($timestamp <= $args['now']) { $timestamp += $intervals[$type]['interval']; } return $timestamp; }
public function setUp() { $this->schedule_intervals = HMBKP_Scheduled_Backup::get_cron_schedules(); }
/** * Display the row of actions for a schedule * * @access public * @param HMBKP_Scheduled_Backup $schedule * @return void */ function hmbkp_schedule_status(HMBKP_Scheduled_Backup $schedule, $echo = true) { ob_start(); ?> <span class="hmbkp-status"<?php if ($schedule->get_status()) { ?> title="<?php printf(__('Started %s ago', 'backupwordpress'), human_time_diff($schedule->get_schedule_running_start_time())); ?> "<?php } ?> > <?php echo $schedule->get_status() ? wp_kses_data($schedule->get_status()) : __('Starting Backup', 'backupwordpress'); ?> <a href="<?php echo hmbkp_admin_action_url('request_cancel_backup', array('hmbkp_schedule_id' => $schedule->get_id())); ?> "><?php _e('cancel', 'backupwordpress'); ?> </a> </span> <?php $output = ob_get_clean(); if (!$echo) { return $output; } echo $output; }
/** * Setup the schedule * * @access public */ public function setUp() { $this->schedule = new HMBKP_Scheduled_Backup('unit-test'); $this->recurrences = HMBKP_Scheduled_Backup::get_cron_schedules(); }
/** * @return string */ protected function test() { $schedule = new HMBKP_Scheduled_Backup('support'); return $schedule->get_formatted_file_size(); }