From b2f903feb28ae95e1a9ca3961381ccc1f5011114 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Wed, 24 Apr 2019 16:30:45 -0300 Subject: [PATCH 1/7] mark actions with invsalid schedules as failures --- classes/ActionScheduler_Store.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/classes/ActionScheduler_Store.php b/classes/ActionScheduler_Store.php index 59ac236af..443ddf7bb 100644 --- a/classes/ActionScheduler_Store.php +++ b/classes/ActionScheduler_Store.php @@ -188,13 +188,36 @@ public function get_status_labels() { public function init() {} + public function mark_failed_fetch_action( $action_id ) { + self::$store->mark_failure( $action_id ); + } + + /** + * Add base hooks + * + * @since 2.2.6 + */ + protected static function hook() { + add_action( 'action_scheduler_failed_fetch_action', array( self::$store, 'mark_failed_fetch_action' ), 20 ); + } + + /** + * Remove base hooks + * + * @since 2.2.6 + */ + protected static function unhook() { + remove_action( 'action_scheduler_failed_fetch_action', array( self::$store, 'mark_failed_fetch_action' ), 20 ); + } + /** * @return ActionScheduler_Store */ public static function instance() { if ( empty(self::$store) ) { - $class = apply_filters('action_scheduler_store_class', 'ActionScheduler_wpPostStore'); + $class = apply_filters( 'action_scheduler_store_class', 'ActionScheduler_wpPostStore' ); self::$store = new $class(); + self::hook(); } return self::$store; } From 12da96a32b1f25b22fbcc5a7dc5f9917eef0d8ba Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Wed, 24 Apr 2019 16:37:05 -0300 Subject: [PATCH 2/7] phpdocs for mark_failed_fetch_action --- classes/ActionScheduler_Store.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/classes/ActionScheduler_Store.php b/classes/ActionScheduler_Store.php index 443ddf7bb..04628c56f 100644 --- a/classes/ActionScheduler_Store.php +++ b/classes/ActionScheduler_Store.php @@ -188,6 +188,13 @@ public function get_status_labels() { public function init() {} + /** + * Mark an action that failed to fetch correctly as failed. + * + * @since 2.2.6 + * + * @param int $action_id The ID of the action. + */ public function mark_failed_fetch_action( $action_id ) { self::$store->mark_failure( $action_id ); } From a00dee06c6c277070481ac6021fe549546bed32e Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Wed, 1 May 2019 16:41:51 -0300 Subject: [PATCH 3/7] add 1 second delta to unit tests comparing sequential generated timestamps --- tests/phpunit/jobstore/ActionScheduler_wpPostStore_Test.php | 2 +- tests/phpunit/runner/ActionScheduler_QueueRunner_Test.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/jobstore/ActionScheduler_wpPostStore_Test.php b/tests/phpunit/jobstore/ActionScheduler_wpPostStore_Test.php index d40fc9912..fb91a30f6 100644 --- a/tests/phpunit/jobstore/ActionScheduler_wpPostStore_Test.php +++ b/tests/phpunit/jobstore/ActionScheduler_wpPostStore_Test.php @@ -246,7 +246,7 @@ public function test_get_run_date() { $now = as_get_datetime_object(); $store->mark_complete( $action_id ); - $this->assertEquals( $store->get_date($action_id)->getTimestamp(), $now->getTimestamp() ); + $this->assertEquals( $store->get_date( $action_id )->getTimestamp(), $now->getTimestamp(), '', 1 ); $next = $action->get_schedule()->next( $now ); $new_action_id = $store->save_action( $action, $next ); diff --git a/tests/phpunit/runner/ActionScheduler_QueueRunner_Test.php b/tests/phpunit/runner/ActionScheduler_QueueRunner_Test.php index e68b3e06f..7b5a8e627 100644 --- a/tests/phpunit/runner/ActionScheduler_QueueRunner_Test.php +++ b/tests/phpunit/runner/ActionScheduler_QueueRunner_Test.php @@ -104,7 +104,7 @@ public function test_next_instance_of_action() { $this->assertEquals( $random, $new_action->get_hook() ); - $this->assertEquals( $schedule->next(as_get_datetime_object())->getTimestamp(), $new_action->get_schedule()->next(as_get_datetime_object())->getTimestamp() ); + $this->assertEquals( $schedule->next( as_get_datetime_object() )->getTimestamp(), $new_action->get_schedule()->next( as_get_datetime_object() )->getTimestamp(), '', 1 ); } public function test_hooked_into_wp_cron() { From 108b2a6104c04f4068c59391da266d6c6ba7270c Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Mon, 6 May 2019 15:44:26 -0300 Subject: [PATCH 4/7] phpcs fixes noted on PR #259 --- classes/ActionScheduler_wcSystemStatus.php | 4 ++-- docs/assets/css/style.scss | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/ActionScheduler_wcSystemStatus.php b/classes/ActionScheduler_wcSystemStatus.php index 3213d7cce..1fc7541da 100644 --- a/classes/ActionScheduler_wcSystemStatus.php +++ b/classes/ActionScheduler_wcSystemStatus.php @@ -129,8 +129,8 @@ protected function get_template( $status_labels, $action_counts, $oldest_and_new /** * is triggered when invoking inaccessible methods in an object context. * - * @param $name string - * @param $arguments array + * @param string $name + * @param array $arguments * * @return mixed * @link https://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods diff --git a/docs/assets/css/style.scss b/docs/assets/css/style.scss index ee1434cec..a13de0d06 100644 --- a/docs/assets/css/style.scss +++ b/docs/assets/css/style.scss @@ -35,7 +35,7 @@ footer { animation:octocat-wave 560ms ease-in-out } -@keyframes octocat-wave{ +@keyframes octocat-wave { 0%,100%{ transform:rotate(0) } @@ -51,7 +51,7 @@ footer { .github-corner:hover .octo-arm { animation:none } - .github-corner .octo-arm{ + .github-corner .octo-arm { animation:octocat-wave 560ms ease-in-out } } \ No newline at end of file From 6e93c1d1bf7a5ac6c59bcd7c8a6dd8b84f651e94 Mon Sep 17 00:00:00 2001 From: Sal Ferrarello Date: Wed, 8 May 2019 14:45:51 -0400 Subject: [PATCH 5/7] Add check that function add_action() exists By checking that the function add_action() exists, before we call it, we can avoid throwing a fatal error when a PHP tool is run (e.g. phpcs) even if we are loading `action-scheduler.php` via Composer's autoload. See #303 --- action-scheduler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action-scheduler.php b/action-scheduler.php index 4f69fbba8..4ff93d389 100644 --- a/action-scheduler.php +++ b/action-scheduler.php @@ -25,7 +25,7 @@ * */ -if ( ! function_exists( 'action_scheduler_register_2_dot_2_dot_5' ) ) { +if ( ! function_exists( 'action_scheduler_register_2_dot_2_dot_5' ) && function_exists( 'add_action' ) ) { if ( ! class_exists( 'ActionScheduler_Versions' ) ) { require_once( 'classes/ActionScheduler_Versions.php' ); From e24bf07375ee5976a9c5d06a3ea3b065fe2523d9 Mon Sep 17 00:00:00 2001 From: Dennis Nissle Date: Fri, 31 May 2019 09:28:16 +0200 Subject: [PATCH 6/7] Make sure wp_filter_post_kses does not corrupt JSON data in post_content --- classes/ActionScheduler_wpPostStore.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/classes/ActionScheduler_wpPostStore.php b/classes/ActionScheduler_wpPostStore.php index 4d8234140..4162fb89c 100644 --- a/classes/ActionScheduler_wpPostStore.php +++ b/classes/ActionScheduler_wpPostStore.php @@ -49,7 +49,20 @@ protected function create_post_array( ActionScheduler_Action $action, DateTime $ protected function save_post_array( $post_array ) { add_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10, 1 ); add_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10, 5 ); + + $has_kses = false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' ); + + if ( $has_kses ) { + // Prevent KSES from corrupting JSON in post_content. + kses_remove_filters(); + } + $post_id = wp_insert_post($post_array); + + if ( $has_kses ) { + kses_init_filters(); + } + remove_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10 ); remove_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10 ); From 73aa8a4655a579c4459d78bbb97d9e8c683a95b2 Mon Sep 17 00:00:00 2001 From: Brent Shepherd Date: Tue, 2 Jul 2019 16:35:56 +1000 Subject: [PATCH 7/7] Fix docblock --- classes/ActionScheduler_AdminView.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/ActionScheduler_AdminView.php b/classes/ActionScheduler_AdminView.php index d87861e78..52fc1dba7 100644 --- a/classes/ActionScheduler_AdminView.php +++ b/classes/ActionScheduler_AdminView.php @@ -9,7 +9,7 @@ class ActionScheduler_AdminView extends ActionScheduler_AdminView_Deprecated { private static $admin_view = NULL; /** - * @return ActionScheduler_QueueRunner + * @return ActionScheduler_AdminView * @codeCoverageIgnore */ public static function instance() {