Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions admin/class-boldgrid-backup-admin-cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public function add_all_crons( array $settings ) {
$scheduled = $this->add_cron_entry( $settings );
}

$jobs_scheduled = $this->schedule_jobs();
$jobs_scheduled = $this->schedule_jobs( $settings );
$site_check = $this->schedule_site_check( $settings );

$success = $scheduled && $jobs_scheduled;
Expand Down Expand Up @@ -313,17 +313,21 @@ public function read_cron_entry( $mode = 'backup' ) {
* @see BoldGrid_Backup_Admin_Core::get_backup_identifier()
* @see BoldGrid_Backup_Admin_Cron::get_cron_secret()
*
* @param array $settings Settings.
*
* @return bool Success.
*/
public function schedule_jobs() {
$entry = sprintf(
'*/5 * * * * %6$s "%1$s/%2$s" siteurl=%3$s id=%4$s secret=%5$s > /dev/null 2>&1',
public function schedule_jobs( $settings ) {
$cron_interval = isset( $settings['cron_interval'] ) ? $settings['cron_interval'] : '*/10 * * * *';
$entry = sprintf(
'%7$s %6$s "%1$s/%2$s" siteurl=%3$s id=%4$s secret=%5$s > /dev/null 2>&1',
dirname( dirname( __FILE__ ) ),
$this->run_jobs,
get_site_url(),
$this->core->get_backup_identifier(),
$this->get_cron_secret(),
$this->cron_command
$this->cron_command,
$cron_interval
);

return $this->update_cron( $entry );
Expand Down
27 changes: 25 additions & 2 deletions admin/class-boldgrid-backup-admin-jobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,31 @@ public function maybe_fix_stalled() {
public function run() {
$this->set_jobs();

// If there are no jobs or already running, then abort.
if ( empty( $this->jobs ) || $this->is_running() ) {
/*
* If there are no jobs in the job list, then delete this cron.
* Please note, that this method is called by the cron itself,
* so it will only delete if the cron list is empty when the cron starts.
* Sometimes, the job will have completed, but not have been removed from the list yet.
* In this case, the cron will not delete itself until the next scheduled cron run.
*
* The basic pattern is this:
* 1. Automatic backup is scheduled.
* 2. Automatic backup is run.
* 3. While automatic backup is running, if remote storage is enabled,
* the run-jobs.php cron is added.
* 4. When automatic backup is complete, the upload backup job is added to the cron list.
* 5. Next time the run-jobs.php cron runs, the upload backup job is run.
* 6. The next time the run-jobs.php cron runs, the upload backup job is deleted.
* 7. The next time the run-jobs.php cron runs, the run-jobs.php cron is deleted.
* 8. Repeat.
*/
if ( empty( $this->jobs ) ) {
$this->core->cron->delete_cron_entries( 'jobs' );
wp_die();
}

// If we have a job currently running, abort.
if ( $this->is_running() ) {
wp_die();
}

Expand Down
9 changes: 9 additions & 0 deletions admin/class-boldgrid-backup-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,15 @@ private function update_settings() {
$settings['scheduler'] = $_POST['scheduler'];
}

/*
* Save cron interval Settings.
*
* @since 1.16.0
*/
if ( isset( $_POST['cron_interval'] ) ) {
$settings['cron_interval'] = $_POST['cron_interval'];
}

/*
* Save WP Cron / Crons.
*
Expand Down
30 changes: 30 additions & 0 deletions admin/js/boldgrid-backup-admin-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,34 @@ BoldGrid.Settings = function( $ ) {
}
};

/**
* Toggle Cron Interval
*
* @summary Toggle the cron interval select element.
*
* @since 1.16.0
*/
self.toggleCronInterval = function() {
var $schedulerSelect = $( 'select[name="scheduler"]' ),
toggleInterval = function( val ) {
if ( 'cron' === val ) {
$( '#cron_interval' ).show();
} else {
$( '#cron_interval' ).hide();
}
};

toggleInterval( $schedulerSelect.find( 'option:selected' ).val() );

$schedulerSelect.on( 'change', function() {
toggleInterval(
$( this )
.find( 'option:selected' )
.val()
);
} );
};

// Onload event listener.
$( function() {

Expand All @@ -304,6 +332,8 @@ BoldGrid.Settings = function( $ ) {

self.toggleCompressionInfo();

self.toggleCronInterval();

$body.on( 'click', '#storage_locations input[type="checkbox"]', self.toggleNoStorage );

$backupDir.on( 'input', self.toggleMoveBackups );
Expand Down
26 changes: 25 additions & 1 deletion admin/partials/settings/scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,28 @@

$scheduler_select = sprintf( '<select name="scheduler" id="scheduler">%1$s</select>', $scheduler_options );

$intervals = array(
'*/5 * * * *' => esc_html__( 'Every 5 Minutes', 'boldgrid-backup' ),
'*/10 * * * *' => esc_html__( 'Every 10 Minutes', 'boldgrid-backup' ),
'*/30 * * * *' => esc_html__( 'Every 30 Minutes', 'boldgrid-backup' ),
'0 * * * *' => esc_html__( 'Once Every Hour', 'boldgrid-backup' ),
Comment thread
jamesros161 marked this conversation as resolved.
);

$selected_interval = ! empty( $settings['cron_interval'] ) ? $settings['cron_interval'] : '*/10 * * * *';

$cron_interval_options = '';

foreach ( $intervals as $key => $interval ) {
$cron_interval_options .= sprintf(
'<option value="%1$s" %3$s>%2$s</option>',
$key,
$interval,
$key === $selected_interval ? 'selected="selected"' : ''
);
}

$cron_interval_select = sprintf( '<select name="cron_interval" id="cron_interval">%1$s</select>', $cron_interval_options );

return sprintf(
'
<div class="bg-box">
Expand All @@ -54,10 +76,12 @@
<div class="bg-box-bottom">
%2$s
%3$s
%5$s
</div>
</div>',
__( 'Scheduler', 'boldgrid-backup' ),
$scheduler_select,
$wp_cron_warning,
__( 'Advanced', 'boldgrid-backup' )
__( 'Advanced', 'boldgrid-backup' ),
$cron_interval_select
);
2 changes: 1 addition & 1 deletion boldgrid-backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Plugin Name: Total Upkeep
* Plugin URI: https://www.boldgrid.com/boldgrid-backup/
* Description: Automated backups, remote backup to Amazon S3 and Google Drive, stop website crashes before they happen and more. Total Upkeep is the backup solution you need.
* Version: 1.15.10
* Version: 1.16.0
* Author: BoldGrid
* Author URI: https://www.boldgrid.com/
* License: GPL-2.0+
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: backup, cloud backup, database backup, restore, wordpress backup
Requires at least: 4.4
Tested up to: 6.4
Requires PHP: 5.4
Stable tag: 1.15.10
Stable tag: 1.16.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -132,6 +132,10 @@ Have a problem? First, take a look at our [Getting Started](https://www.boldgrid

== Changelog ==

= 1.16.0 =
Release Date: February 26, 2024
* New Feature: Add settings for cron interval for run-jobs.php [#584](https://github.com/BoldGrid/boldgrid-backup/issues/584)

= 1.15.10 =

Release date: February 7, 2024
Expand Down