From bd8032f2baa0e77cdf537093bd2fc7edf6f9a85d Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 5 Feb 2022 11:16:50 +0000 Subject: [PATCH 1/3] Issue 10365: Event updates are now processed --- src/Model/Item.php | 10 ++++++++ src/Protocol/ActivityPub/Processor.php | 32 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/Model/Item.php b/src/Model/Item.php index 29fe0ad8c..217e77fd5 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1428,6 +1428,16 @@ class Item private static function storeForUser(array $item, int $uid) { if (Post::exists(['uri-id' => $item['uri-id'], 'uid' => $uid])) { + if (!empty($item['event-id'])) { + $post = Post::selectFirst(['event-id'], ['uri-id' => $item['uri-id'], 'uid' => $uid]); + if (!empty($post['event-id'])) { + $event = DBA::selectFirst('event', ['edited', 'start', 'finish', 'summary', 'desc', 'location', 'nofinish', 'adjust'], ['id' => $item['event-id']]); + if (!empty($event)) { + $ret = DBA::update('event', $event, ['id' => $post['event-id']]); + Logger::info('Event updated', ['uid' => $uid, 'source-event' => $item['event-id'], 'target-event' => $post['event-id'], 'ret' => $ret]); + } + } + } Logger::info('Item already exists', ['uri-id' => $item['uri-id'], 'uid' => $uid]); return 0; } diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index bd198fb30..948a3983b 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -180,6 +180,38 @@ class Processor } Item::update($item, ['uri' => $activity['id']]); + + if ($activity['object_type'] == 'as:Event') { + $posts = Post::select(['event-id', 'uid'], ['uri' => $activity['id']]); + while ($post = DBA::fetch($posts)) { + if (empty($post['event-id'])) { + continue; + } + self::updateEvent($post['event-id'], $activity); + } + } + } + + /** + * Update an existing event + * + * @param int $event_id + * @param array $activity + */ + private static function updateEvent(int $event_id, array $activity) + { + $event = DBA::selectFirst('event', [], ['id' => $event_id]); + + $event['edited'] = DateTimeFormat::utc($activity['updated']); + $event['summary'] = HTML::toBBCode($activity['name']); + $event['desc'] = HTML::toBBCode($activity['content']); + $event['start'] = $activity['start-time']; + $event['finish'] = $activity['end-time']; + $event['nofinish'] = empty($event['finish']); + $event['location'] = $activity['location']; + + Logger::info('Updating event', ['uri' => $activity['id'], 'id' => $event_id]); + Event::store($event); } /** From 3e5130952559b507850c74f0659e68bb2d700d53 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 5 Feb 2022 16:22:21 +0000 Subject: [PATCH 2/3] Check for a filled "event-id" field --- src/Protocol/ActivityPub/Processor.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 948a3983b..76f8cdb85 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -182,11 +182,8 @@ class Processor Item::update($item, ['uri' => $activity['id']]); if ($activity['object_type'] == 'as:Event') { - $posts = Post::select(['event-id', 'uid'], ['uri' => $activity['id']]); + $posts = Post::select(['event-id', 'uid'], ["`uri` = ? AND `event-id` > ?", $activity['id'], 0]); while ($post = DBA::fetch($posts)) { - if (empty($post['event-id'])) { - continue; - } self::updateEvent($post['event-id'], $activity); } } From 69d7391f90a45f166ffff6379701d9c58b56c14d Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 5 Feb 2022 16:49:21 +0000 Subject: [PATCH 3/3] Added comment --- src/Model/Item.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Model/Item.php b/src/Model/Item.php index 217e77fd5..bf1f2585a 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1433,6 +1433,7 @@ class Item if (!empty($post['event-id'])) { $event = DBA::selectFirst('event', ['edited', 'start', 'finish', 'summary', 'desc', 'location', 'nofinish', 'adjust'], ['id' => $item['event-id']]); if (!empty($event)) { + // We aren't using "Event::store" here, since we don't want to trigger any further action $ret = DBA::update('event', $event, ['id' => $post['event-id']]); Logger::info('Event updated', ['uid' => $uid, 'source-event' => $item['event-id'], 'target-event' => $post['event-id'], 'ret' => $ret]); }