From 137bb7ad71114d375abee262495b9fa6cda75c50 Mon Sep 17 00:00:00 2001 From: Hans Morbach <6433480+hansmorb@users.noreply.github.com> Date: Thu, 18 Apr 2024 17:04:04 +0200 Subject: [PATCH 1/2] fix #1576 --- src/Wordpress/CustomPostType/Timeframe.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Wordpress/CustomPostType/Timeframe.php b/src/Wordpress/CustomPostType/Timeframe.php index 0978b3827..b69cf5aac 100644 --- a/src/Wordpress/CustomPostType/Timeframe.php +++ b/src/Wordpress/CustomPostType/Timeframe.php @@ -944,6 +944,7 @@ protected static function validateTimeFrame( $timeframe ): bool { /** * Will update the dynamic item / location assignment for all timeframes. + * Only valid for timeframes which can have a dynamic selection type (so far only holidays and repair timeframes) * * @return void */ @@ -953,7 +954,6 @@ public static function updateAllTimeframes() { [], [ Timeframe::HOLIDAYS_ID, - Timeframe::BOOKABLE_ID, Timeframe::REPAIR_ID ] ); From 5c3daec2db93de3c2278b8c1a09f9aaade6ed980 Mon Sep 17 00:00:00 2001 From: Hans Morbach <6433480+hansmorb@users.noreply.github.com> Date: Thu, 18 Apr 2024 19:03:39 +0200 Subject: [PATCH 2/2] fix schedule clearing cache as async action --- src/Plugin.php | 3 ++- src/Service/AsyncJob.php | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/Service/AsyncJob.php diff --git a/src/Plugin.php b/src/Plugin.php index fed25e77e..43bdf0bb8 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -10,6 +10,7 @@ use CommonsBooking\Map\SearchShortcode; use CommonsBooking\Model\Booking; use CommonsBooking\Model\BookingCode; +use CommonsBooking\Service\AsyncJob; use CommonsBooking\Service\BookingRuleApplied; use CommonsBooking\Service\Cache; use CommonsBooking\Service\Scheduler; @@ -803,7 +804,7 @@ public function savePostActions( $post_id, $post, $update ) { if ( ! in_array( $post->post_status, $ignoredStates ) || $update ) { $tags = Wordpress::getRelatedPostIds( $post_id ); $tags[] = 'misc'; - self::clearCache( $tags ); + new AsyncJob( array( self::class, 'clearCache' ), [ $tags ] ); } } diff --git a/src/Service/AsyncJob.php b/src/Service/AsyncJob.php new file mode 100644 index 000000000..eeb6f6dd5 --- /dev/null +++ b/src/Service/AsyncJob.php @@ -0,0 +1,41 @@ +addAsync( $jobhook, $args ); + if ( is_wp_error( $success ) ) { + $callback( $args ); + } + } + + /** + * Enqueue an action to run one time, as soon as possible + * + * @param string $hook The hook to trigger. + * @param array $args Arguments to pass when the hook triggers. + * + * @return bool|\WP_Error True if the action was successfully scheduled, WP_Error on failure. + */ + private function addAsync( string $hook, array $args = [] ): string { + return wp_schedule_single_event( time(), $hook, $args ); + } + +} \ No newline at end of file