From f1572798a8c88de9cb8d3fe95cbe23c450956555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 4 Jan 2025 18:26:39 +0100 Subject: [PATCH] Drop meta key _event_bridge_for_activitypub_is_remote_cached always use _event_bridge_for_activitypub_event_source instead --- .../activitypub/transmogrifier/class-base.php | 12 ++++-- .../class-the-events-calendar.php | 4 +- includes/class-event-sources.php | 43 +++++++------------ includes/integrations/class-gatherpress.php | 4 +- .../class-the-events-calendar.php | 2 +- includes/integrations/class-vs-event-list.php | 2 +- 6 files changed, 31 insertions(+), 36 deletions(-) diff --git a/includes/activitypub/transmogrifier/class-base.php b/includes/activitypub/transmogrifier/class-base.php index b0e63ee..195c800 100644 --- a/includes/activitypub/transmogrifier/class-base.php +++ b/includes/activitypub/transmogrifier/class-base.php @@ -10,9 +10,8 @@ namespace Event_Bridge_For_ActivityPub\ActivityPub\Transmogrifier; use Activitypub\Activity\Extended_Object\Event; -use DateTime; +use Event_Bridge_For_ActivityPub\ActivityPub\Model\Event_Source; use Event_Bridge_For_ActivityPub\ActivityPub\Collection\Event_Sources; -use Exception; use WP_Error; use function Activitypub\sanitize_url; @@ -33,6 +32,13 @@ abstract class Base { */ protected $activitypub_event; + /** + * The current Event object. + * + * @var Event_Source + */ + protected $event_source; + /** * Internal function to actually save the event. * @@ -54,6 +60,7 @@ abstract class Base { } $this->activitypub_event = $activitypub_event; + $this->event_source = $event_source; $post_id = $this->save_event(); @@ -67,7 +74,6 @@ abstract class Base { 'event_bridge_for_activitypub_write_log', array( "[ACTIVITYPUB] Processed incoming event {$event_id} from {$event_source_activitypub_id}" ) ); - update_post_meta( $post_id, '_event_bridge_for_activitypub_is_remote_cached', true ); update_post_meta( $post_id, '_event_bridge_for_activitypub_event_source', absint( $event_source_post_id ) ); update_post_meta( $post_id, 'activitypub_content_visibility', constant( 'ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL' ) ?? '' ); } else { diff --git a/includes/activitypub/transmogrifier/class-the-events-calendar.php b/includes/activitypub/transmogrifier/class-the-events-calendar.php index 399e1b7..4806650 100644 --- a/includes/activitypub/transmogrifier/class-the-events-calendar.php +++ b/includes/activitypub/transmogrifier/class-the-events-calendar.php @@ -96,7 +96,7 @@ class The_Events_Calendar extends Base { } } - if ( $post_id && get_post_meta( $post_id, '_event_bridge_for_activitypub_is_remote_cached', true ) ) { + if ( $post_id && get_post_meta( $post_id, '_event_bridge_for_activitypub_event_source', true ) ) { $result = tribe_venues()->where( 'id', $post_id )->set_args( $this->get_venue_args( $location ) )->save(); if ( array_key_exists( $post_id, $result ) && $result[ $post_id ] ) { return $post_id; @@ -105,7 +105,7 @@ class The_Events_Calendar extends Base { $post = tribe_venues()->set_args( $this->get_venue_args( $location ) )->create(); if ( $post ) { $post_id = $post->ID; - update_post_meta( $post_id, '_event_bridge_for_activitypub_is_remote_cached', true ); + update_post_meta( $post_id, '_event_bridge_for_activitypub_event_source', $this->event_source->get__id() ); } } diff --git a/includes/class-event-sources.php b/includes/class-event-sources.php index af76806..9d2bb59 100644 --- a/includes/class-event-sources.php +++ b/includes/class-event-sources.php @@ -90,32 +90,6 @@ class Event_Sources { if ( ! $event_plugin_integration instanceof Feature_Event_Sources && $event_plugin_integration instanceof Event_Plugin_Integration ) { continue; } - \register_post_meta( - $event_plugin_integration::get_post_type(), - '_event_bridge_for_activitypub_is_remote_cached', - array( - 'type' => 'string', - 'single' => false, - 'sanitize_callback' => function ( $value ) { - return sanitize_url( $value ); - }, - ) - ); - - $location_post_type = $event_plugin_integration::get_location_post_type(); - if ( $location_post_type ) { - \register_post_meta( - $location_post_type, - '_event_bridge_for_activitypub_is_remote_cached', - array( - 'type' => 'string', - 'single' => false, - 'sanitize_callback' => function ( $value ) { - return sanitize_url( $value ); - }, - ) - ); - } \register_post_meta( $event_plugin_integration::get_post_type(), @@ -126,6 +100,21 @@ class Event_Sources { 'sanitize_callback' => 'absint', ) ); + + $location_post_type = $event_plugin_integration::get_location_post_type(); + if ( $location_post_type ) { + \register_post_meta( + $location_post_type, + '_event_bridge_for_activitypub_event_source', + array( + 'type' => 'string', + 'single' => false, + 'sanitize_callback' => function ( $value ) { + return sanitize_url( $value ); + }, + ) + ); + } } } @@ -205,7 +194,7 @@ class Event_Sources { * @return bool */ public static function is_cached_external_event_post( $post ): bool { - if ( get_post_meta( $post->ID, '_event_bridge_for_activitypub_is_remote_cached', true ) ) { + if ( get_post_meta( $post->ID, '_event_bridge_for_activitypub_event_source', true ) ) { return true; } diff --git a/includes/integrations/class-gatherpress.php b/includes/integrations/class-gatherpress.php index 3a5c5ed..c754852 100644 --- a/includes/integrations/class-gatherpress.php +++ b/includes/integrations/class-gatherpress.php @@ -103,7 +103,7 @@ final class GatherPress extends Event_Plugin_Integration implements Feature_Even WHERE {$wpdb->prefix}posts.post_type = 'gatherpress_event' AND {$wpdb->prefix}posts.post_status = 'publish' AND {$wpdb->prefix}gatherpress_events.datetime_end_gmt <= %s - AND {$wpdb->prefix}postmeta.meta_key = '_event_bridge_for_activitypub_is_remote_cached' + AND {$wpdb->prefix}postmeta.meta_key = '_event_bridge_for_activitypub_event_source' ", $ends_before_time_string ), @@ -129,7 +129,7 @@ final class GatherPress extends Event_Plugin_Integration implements Feature_Even if ( $post && 'gatherpress_event' === $post->post_type ) { // Add your custom logic here to decide whether to force the link. // For example, force it only if a specific meta field exists. - if ( get_post_meta( $post->ID, '_event_bridge_for_activitypub_is_remote_cached', true ) ) { + if ( get_post_meta( $post->ID, '_event_bridge_for_activitypub_event_source', true ) ) { return true; // Force the online event link. } } diff --git a/includes/integrations/class-the-events-calendar.php b/includes/integrations/class-the-events-calendar.php index 23cbbef..789c27b 100644 --- a/includes/integrations/class-the-events-calendar.php +++ b/includes/integrations/class-the-events-calendar.php @@ -127,7 +127,7 @@ final class The_Events_Calendar extends Event_plugin_Integration implements Feat */ public static function add_is_activitypub_remote_cached_to_query( $schema_entry ) { $schema_entry['meta_query']['is-remote-cached'] = array( - 'key' => '_event_bridge_for_activitypub_is_remote_cached', + 'key' => '_event_bridge_for_activitypub_event_source', 'compare' => 'EXISTS', ); return $schema_entry; diff --git a/includes/integrations/class-vs-event-list.php b/includes/integrations/class-vs-event-list.php index f00b54c..4ed01f2 100644 --- a/includes/integrations/class-vs-event-list.php +++ b/includes/integrations/class-vs-event-list.php @@ -96,7 +96,7 @@ final class VS_Event_List extends Event_Plugin_Integration implements Feature_Ev 'meta_query' => array( 'relation' => 'AND', array( - 'key' => '_event_bridge_for_activitypub_is_remote_cached', + 'key' => '_event_bridge_for_activitypub_event_source', 'compare' => 'EXISTS', ), array(