From fc86e574cd2175ceca5fdc52392861dd24b5c9fc Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Wed, 24 Apr 2019 10:08:06 -0300 Subject: [PATCH] update action scheduler to version 2.2.5 --- .../action-scheduler/action-scheduler.php | 14 +++++------ .../classes/ActionScheduler_Logger.php | 6 ++++- .../classes/ActionScheduler_wpPostStore.php | 24 +++++++++++++++---- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/includes/libraries/action-scheduler/action-scheduler.php b/includes/libraries/action-scheduler/action-scheduler.php index 8c3117d92f5..4f69fbba869 100644 --- a/includes/libraries/action-scheduler/action-scheduler.php +++ b/includes/libraries/action-scheduler/action-scheduler.php @@ -4,8 +4,8 @@ * Plugin URI: https://actionscheduler.org * Description: A robust scheduling library for use in WordPress plugins. * Author: Prospress - * Author URI: http://prospress.com/ - * Version: 2.2.4 + * Author URI: https://prospress.com/ + * Version: 2.2.5 * License: GPLv3 * * Copyright 2019 Prospress, Inc. (email : freedoms@prospress.com) @@ -25,21 +25,21 @@ * */ -if ( ! function_exists( 'action_scheduler_register_2_dot_2_dot_4' ) ) { +if ( ! function_exists( 'action_scheduler_register_2_dot_2_dot_5' ) ) { if ( ! class_exists( 'ActionScheduler_Versions' ) ) { require_once( 'classes/ActionScheduler_Versions.php' ); add_action( 'plugins_loaded', array( 'ActionScheduler_Versions', 'initialize_latest_version' ), 1, 0 ); } - add_action( 'plugins_loaded', 'action_scheduler_register_2_dot_2_dot_4', 0, 0 ); + add_action( 'plugins_loaded', 'action_scheduler_register_2_dot_2_dot_5', 0, 0 ); - function action_scheduler_register_2_dot_2_dot_4() { + function action_scheduler_register_2_dot_2_dot_5() { $versions = ActionScheduler_Versions::instance(); - $versions->register( '2.2.4', 'action_scheduler_initialize_2_dot_2_dot_4' ); + $versions->register( '2.2.5', 'action_scheduler_initialize_2_dot_2_dot_5' ); } - function action_scheduler_initialize_2_dot_2_dot_4() { + function action_scheduler_initialize_2_dot_2_dot_5() { require_once( 'classes/ActionScheduler.php' ); ActionScheduler::init( __FILE__ ); } diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_Logger.php b/includes/libraries/action-scheduler/classes/ActionScheduler_Logger.php index 3da06ab48de..b87134cd6bb 100644 --- a/includes/libraries/action-scheduler/classes/ActionScheduler_Logger.php +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_Logger.php @@ -55,6 +55,7 @@ abstract class ActionScheduler_Logger { add_action( 'action_scheduler_unexpected_shutdown', array( $this, 'log_unexpected_shutdown' ), 10, 2 ); add_action( 'action_scheduler_reset_action', array( $this, 'log_reset_action' ), 10, 1 ); add_action( 'action_scheduler_execution_ignored', array( $this, 'log_ignored_action' ), 10, 1 ); + add_action( 'action_scheduler_failed_fetch_action', array( $this, 'log_failed_fetch_action' ), 10, 1 ); } public function log_stored_action( $action_id ) { @@ -94,5 +95,8 @@ abstract class ActionScheduler_Logger { public function log_ignored_action( $action_id ) { $this->log( $action_id, __( 'action ignored', 'action-scheduler' ) ); } + + public function log_failed_fetch_action( $action_id ) { + $this->log( $action_id, __( 'There was a failure fetching this action', 'action-scheduler' ) ); + } } - \ No newline at end of file diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_wpPostStore.php b/includes/libraries/action-scheduler/classes/ActionScheduler_wpPostStore.php index 59ee651522e..4d823414061 100644 --- a/includes/libraries/action-scheduler/classes/ActionScheduler_wpPostStore.php +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_wpPostStore.php @@ -19,7 +19,13 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { $this->validate_action( $action ); $post_array = $this->create_post_array( $action, $scheduled_date ); $post_id = $this->save_post_array( $post_array ); - $this->save_post_schedule( $post_id, $action->get_schedule() ); + $schedule = $action->get_schedule(); + + if ( ! is_null( $scheduled_date ) && $schedule->is_recurring() ) { + $schedule = new ActionScheduler_IntervalSchedule( $scheduled_date, $schedule->interval_in_seconds() ); + } + + $this->save_post_schedule( $post_id, $schedule ); $this->save_action_group( $post_id, $action->get_group() ); do_action( 'action_scheduler_stored_action', $post_id ); return $post_id; @@ -131,13 +137,21 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { protected function make_action_from_post( $post ) { $hook = $post->post_title; - $args = json_decode( $post->post_content, true ); - $this->validate_args( $args, $post->ID ); - $schedule = get_post_meta( $post->ID, self::SCHEDULE_META_KEY, true ); - if ( empty( $schedule ) || ! is_a( $schedule, 'ActionScheduler_Schedule' ) ) { + try { + $args = json_decode( $post->post_content, true ); + $this->validate_args( $args, $post->ID ); + + $schedule = get_post_meta( $post->ID, self::SCHEDULE_META_KEY, true ); + if ( empty( $schedule ) || ! is_a( $schedule, 'ActionScheduler_Schedule' ) ) { + throw ActionScheduler_InvalidActionException::from_decoding_args( $post->ID ); + } + } catch ( ActionScheduler_InvalidActionException $exception ) { $schedule = new ActionScheduler_NullSchedule(); + $args = array(); + do_action( 'action_scheduler_failed_fetch_action', $post->ID ); } + $group = wp_get_object_terms( $post->ID, self::GROUP_TAXONOMY, array('fields' => 'names') ); $group = empty( $group ) ? '' : reset($group);