Exemplo n.º 1
0
 /**
  * Cleanup on plugin deactivation
  *
  * Removes options and clears all cron schedules
  */
 public static function deactivate()
 {
     if (!current_user_can('activate_plugins')) {
         return;
     }
     // Determine if we need to do any cleanup
     if (!class_exists('HMBKP_Schedules')) {
         return;
     }
     $schedules = HMBKP_Schedules::get_instance();
     if (empty($schedules)) {
         return;
     }
     // Clear schedule crons
     foreach ($schedules->get_schedules() as $schedule) {
         $schedule->unschedule();
     }
     // Opt them out of support
     delete_option('hmbkp_enable_support');
     // Remove the directory filesize cache
     delete_transient('hmbkp_directory_filesizes');
 }
Exemplo n.º 2
0
 /**
  * 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();
 }
Exemplo n.º 3
0
/**
 * 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 &amp; files. You can modify these schedules.', 'hmbkp') . '</p></div>';
    }
    add_action('admin_notices', 'hmbkp_default_schedules_setup_warning');
}
<?php

if (HMBKP_Schedules::get_instance()->get_schedule($schedule->get_id())) {
    ?>

	<div class="hmbkp-schedule-actions row-actions">

		<a class="hmbkp-run" href="<?php 
    echo esc_url(add_query_arg(array('action' => 'hmbkp_run_schedule', 'hmbkp_schedule_id' => $schedule->get_id(), 'hmbkp-run-schedule-nonce' => wp_create_nonce('hmbkp-run-schedule')), hmbkp_get_settings_url()));
    ?>
"><?php 
    _e('Run now', 'hmbkp');
    ?>
</a>  |

		<a href="<?php 
    echo esc_url(wp_nonce_url(add_query_arg(array('action' => 'hmbkp_edit_schedule', 'hmbkp_panel' => 'hmbkp_edit_schedule_settings', 'hmbkp_schedule_id' => $schedule->get_id()), hmbkp_get_settings_url()), 'hmbkp-edit-schedule', 'hmbkp-edit-schedule-nonce'));
    ?>
"><?php 
    _e('Settings', 'hmbkp');
    ?>
</a> |

		<?php 
    // Only show excludes if we are backing up files
    if ($schedule->get_type() !== 'database') {
        ?>
			<a href="<?php 
        echo esc_url(add_query_arg(array('action' => 'hmbkp_edit_schedule', 'hmbkp_panel' => 'hmbkp_edit_schedule_excludes', 'hmbkp_schedule_id' => $schedule->get_id()), hmbkp_get_settings_url()));
        ?>
"><?php 
Exemplo n.º 5
0
function hmbkp_calculate_site_size()
{
    if (isset($_GET['hmbkp_schedule_id'])) {
        $current_schedule = new HMBKP_Scheduled_Backup(sanitize_text_field($_GET['hmbkp_schedule_id']));
    } else {
        // Refresh the schedules from the database to make sure we have the latest changes
        HMBKP_Schedules::get_instance()->refresh_schedules();
        $schedules = HMBKP_Schedules::get_instance()->get_schedules();
        $current_schedule = reset($schedules);
    }
    if (!$current_schedule->is_site_size_cached()) {
        // Start calculating
        $root = new SplFileInfo($current_schedule->get_root());
        $size = $current_schedule->filesize($root);
    }
}
Exemplo n.º 6
0
<?php

if (!defined('HMBKP_PLUGIN_PATH')) {
    define('HMBKP_PLUGIN_PATH', plugin_dir_path(__FILE__));
}
// Load the schedules
require_once HMBKP_PLUGIN_PATH . 'hm-backup/hm-backup.php';
require_once HMBKP_PLUGIN_PATH . 'classes/class-services.php';
require_once HMBKP_PLUGIN_PATH . 'classes/class-schedule.php';
require_once HMBKP_PLUGIN_PATH . 'classes/class-schedules.php';
require_once HMBKP_PLUGIN_PATH . 'functions/core.php';
$schedules = HMBKP_Schedules::get_instance();
// Cancel all the schedules and delete all the backups
foreach ($schedules->get_schedules() as $schedule) {
    $schedule->cancel(true);
}
// Remove the backups directory
hmbkp_rmdirtree(hmbkp_path());
// Remove all the options
foreach (array('hmbkp_enable_support', 'hmbkp_plugin_version', 'hmbkp_path', 'hmbkp_default_path', 'hmbkp_upsell') as $option) {
    delete_option($option);
}
Exemplo n.º 7
0
/**
 * Function to run when the schedule cron fires
 * @param $schedule_id
 */
function hmbkp_schedule_hook_run($schedule_id)
{
    $schedules = HMBKP_Schedules::get_instance();
    $schedule = $schedules->get_schedule($schedule_id);
    if (!$schedule) {
        return;
    }
    $schedule->run();
}
Exemplo n.º 8
0
/**
 * 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((string) time());
    $database_daily->set_type('database');
    $database_daily->set_schedule_start_time(hmbkp_determine_start_time('hmbkp_daily', array('hours' => '23', 'minutes' => '0')));
    $database_daily->set_reoccurrence('hmbkp_daily');
    $database_daily->set_max_backups(7);
    $database_daily->save();
    /**
     * Schedule a complete backup to run weekly and store backups for
     * the last 3 months
     */
    $complete_weekly = new HMBKP_Scheduled_Backup((string) (time() + 1));
    $complete_weekly->set_type('complete');
    $complete_weekly->set_schedule_start_time(hmbkp_determine_start_time('hmbkp_weekly', array('day_of_week' => 'sunday', 'hours' => '3', 'minutes' => '0')));
    $complete_weekly->set_reoccurrence('hmbkp_weekly');
    $complete_weekly->set_max_backups(3);
    $complete_weekly->save();
    $schedules->refresh_schedules();
    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 &amp; files. You can modify these schedules.', 'hmbkp') . '</p></div>';
    }
    add_action('admin_notices', 'hmbkp_default_schedules_setup_warning');
}
Exemplo n.º 9
0
    echo esc_url(add_query_arg('hmbkp_schedule_id', $schedule->get_id(), HMBKP_ADMIN_URL));
    ?>
 "><?php 
    echo esc_html(hmbkp_translated_schedule_title($schedule->get_slug(), $schedule->get_name()));
    ?>
 <span class="count">(<?php 
    echo esc_html(count($schedule->get_backups()));
    ?>
)</span></a>

	<?php 
}
?>

	<a class="nav-tab<?php 
if (!HMBKP_Schedules::get_instance()->get_schedule($current_schedule->get_id())) {
    ?>
 nav-tab-active<?php 
}
?>
" href="<?php 
echo esc_url(add_query_arg(array('hmbkp_add_schedule' => '1', 'action' => 'hmbkp_edit_schedule', 'hmbkp_schedule_id' => time(), 'hmbkp_panel' => 'hmbkp_edit_schedule_settings'), HMBKP_ADMIN_URL));
?>
"> + <?php 
_e('add schedule', 'backupwordpress');
?>
</a>

	<?php 
if (get_option('hmbkp_enable_support')) {
    ?>
Exemplo n.º 10
0
 /**
  * Retrieves the average backup duration for each schedule.
  *
  * @return array The average backup duration for all schedules.
  */
 public function test()
 {
     $schedule_average_durations = array();
     $schedules = HMBKP_Schedules::get_instance();
     foreach ($schedules->get_schedules() as $schedule) {
         $schedule_average_durations[sprintf(__('Schedule: %s', 'backupwordpress'), $schedule->get_id())] = sprintf(__('Duration: %s', 'backupwordpress'), $schedule->get_schedule_average_duration());
     }
     return array_filter($schedule_average_durations);
 }
Exemplo n.º 11
0
 /**
  * @return string
  */
 protected function test()
 {
     $backup_sizes = array();
     $schedules = HMBKP_Schedules::get_instance();
     foreach ($schedules->get_schedules() as $schedule) {
         if ($schedule->is_site_size_cached()) {
             $backup_sizes[$schedule->get_id()] = $schedule->get_formatted_site_size();
         }
     }
     return $backup_sizes;
 }
Exemplo n.º 12
0
 /**
  * Function to run when the schedule cron fires.
  *
  * @param $schedule_id
  */
 public function schedule_hook_run($schedule_id)
 {
     if (!hmbkp_possible()) {
         return;
     }
     $schedules = HMBKP_Schedules::get_instance();
     $schedule = $schedules->get_schedule($schedule_id);
     if (!$schedule) {
         return;
     }
     $schedule->run();
 }