diff --git a/includes/class-sm-background-updater.php b/includes/class-sm-background-updater.php index ebe6189..d18e52a 100644 --- a/includes/class-sm-background-updater.php +++ b/includes/class-sm-background-updater.php @@ -19,46 +19,6 @@ class SM_Background_Updater extends WP_Background_Process { */ protected $action = 'sm_updater'; - /** - * Dispatch updater. - * - * Updater will still run via cron job if this fails for any reason. - */ - public function dispatch() { - parent::dispatch(); - } - - /** - * Handle cron healthcheck - * - * Restart the background process if not already running - * and data exists in the queue. - */ - public function handle_cron_healthcheck() { - if ( $this->is_process_running() ) { - // Background process already running. - return; - } - - if ( $this->is_queue_empty() ) { - // No data to process. - $this->clear_scheduled_event(); - - return; - } - - $this->handle(); - } - - /** - * Schedule fallback event. - */ - protected function schedule_event() { - if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) { - wp_schedule_event( time() + 10, $this->cron_interval_identifier, $this->cron_hook_identifier ); - } - } - /** * Is the updater running? * @@ -85,7 +45,7 @@ protected function task( $callback ) { define( 'SM_UPDATING', true ); } - include_once( dirname( __FILE__ ) . '/sm-update-functions.php' ); + include_once 'sm-update-functions.php'; if ( is_callable( $callback ) ) { call_user_func( $callback ); diff --git a/includes/class-sm-install.php b/includes/class-sm-install.php index 640ee5d..c2c5e7c 100644 --- a/includes/class-sm-install.php +++ b/includes/class-sm-install.php @@ -9,7 +9,7 @@ class SM_Install { /** @var array DB updates and callbacks that need to be run per version */ private static $db_updates = array( - '2.8' => array( + '2.8' => array( 'sm_update_28_revert_old_dates', 'sm_update_28_convert_dates_to_unix', 'sm_update_28_fill_out_empty_dates', @@ -17,8 +17,8 @@ class SM_Install { 'sm_update_28_save_sermon_render_into_post_content', 'sm_update_28_reset_recovery', ), - '2.8.3' => array( - 'sm_update_283_resave_sermons' + '2.8.4' => array( + 'sm_update_284_resave_sermons' ) ); @@ -98,12 +98,15 @@ private static function _install() { * Push all needed DB updates to the queue for processing. */ private static function _update() { - $current_db_version = get_option( 'sm_version' ); - $update_queued = false; + if ( self::$background_updater->is_updating() ) { + return; + } + + $update_queued = false; foreach ( self::_get_db_update_callbacks() as $version => $update_callbacks ) { - if ( version_compare( $current_db_version, $version, '<' ) ) { - foreach ( $update_callbacks as $update_callback ) { + foreach ( $update_callbacks as $update_callback ) { + if ( ! get_option( 'wp_sm_updater_' . $update_callback . '_done' ) ) { self::$background_updater->push_to_queue( $update_callback ); $update_queued = true; } @@ -124,14 +127,6 @@ private static function _get_db_update_callbacks() { return self::$db_updates; } - /** - * Init background updates - */ - public static function init_background_updater() { - include_once 'class-sm-background-updater.php'; - self::$background_updater = new SM_Background_Updater(); - } - /** * Update DB version to current. * @@ -142,6 +137,14 @@ public static function update_db_version( $version = null ) { add_option( 'sm_version', is_null( $version ) ? SM_VERSION : $version ); } + /** + * Init background updates + */ + public static function init_background_updater() { + include_once 'class-sm-background-updater.php'; + self::$background_updater = new SM_Background_Updater(); + } + /** * Add more cron schedules * diff --git a/includes/libraries/wp-background-process.php b/includes/libraries/wp-background-process.php index 1323ee5..f3f59a0 100644 --- a/includes/libraries/wp-background-process.php +++ b/includes/libraries/wp-background-process.php @@ -303,6 +303,7 @@ protected function handle() { $batch->data[ $key ] = $task; } else { unset( $batch->data[ $key ] ); + update_option('wp_sm_updater_' . $value . '_done', 1 ); } if ( $this->time_exceeded() || $this->memory_exceeded() ) { diff --git a/includes/options.php b/includes/options.php index f5b8cb1..a101275 100755 --- a/includes/options.php +++ b/includes/options.php @@ -26,11 +26,11 @@ static function wpfc_validate_options( $input ) { unset( $input['sm_do_not_catch'] ); } else { update_option( '_sm_recovery_do_not_catch', '0' ); - } + } - if ( SermonManager::getOption( 'archive_slug' ) != $input['archive_slug'] || - SermonManager::getOption( 'common_base_slug' ) != $input['common_base_slug'] || - SermonManager::getOption( 'preacher_label' ) != $input['preacher_label'] ) { + if ( SermonManager::getOption( 'archive_slug' ) != $input['archive_slug'] || + SermonManager::getOption( 'common_base_slug' ) != $input['common_base_slug'] || + SermonManager::getOption( 'preacher_label' ) != $input['preacher_label'] ) { update_option( 'sm_flush_rewrite_rules', '1' ); } @@ -43,7 +43,7 @@ static function wpfc_validate_options( $input ) { * @since 2.5.2 */ function maybe_flush_rewrite_rules() { - if ( boolval( get_option( 'sm_flush_rewrite_rules' ) ) ) { + if ( (bool) get_option( 'sm_flush_rewrite_rules' ) ) { flush_rewrite_rules(); update_option( 'sm_flush_rewrite_rules', '0' ); } @@ -167,17 +167,21 @@ function wpfc_sermon_options_render_form() {
+
+