From c2524e50dce52b805b390b3d735d868dbefb38de Mon Sep 17 00:00:00 2001 From: aynsix Date: Fri, 20 Sep 2019 18:04:05 +0400 Subject: [PATCH] feed webhook --- .../Core/Event/Subscriber/FeedEntrySubscriber.php | 3 ++- .../Model/Manipulator/WebhookEventManipulator.php | 6 +++++- .../Phrasea/Webhook/Processor/FeedEntryProcessor.php | 11 +++++------ .../Webhook/Processor/FeedEntryProcessorTest.php | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/Alchemy/Phrasea/Core/Event/Subscriber/FeedEntrySubscriber.php b/lib/Alchemy/Phrasea/Core/Event/Subscriber/FeedEntrySubscriber.php index 03a72a95b4..6a8b0cdaf4 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Subscriber/FeedEntrySubscriber.php +++ b/lib/Alchemy/Phrasea/Core/Event/Subscriber/FeedEntrySubscriber.php @@ -31,7 +31,8 @@ class FeedEntrySubscriber extends AbstractNotificationSubscriber $this->app['manipulator.webhook-event']->create( WebhookEvent::NEW_FEED_ENTRY, WebhookEvent::FEED_ENTRY_TYPE, - array_merge(array('feed_id' => $entry->getFeed()->getId()), $params) + array_merge(array('feed_id' => $entry->getFeed()->getId()), $params), + $entry->getFeed()->getBaseId() ? [$entry->getFeed()->getBaseId()] : [] ); $datas = json_encode($params); diff --git a/lib/Alchemy/Phrasea/Model/Manipulator/WebhookEventManipulator.php b/lib/Alchemy/Phrasea/Model/Manipulator/WebhookEventManipulator.php index 40e7f812a7..63cf52c3f5 100644 --- a/lib/Alchemy/Phrasea/Model/Manipulator/WebhookEventManipulator.php +++ b/lib/Alchemy/Phrasea/Model/Manipulator/WebhookEventManipulator.php @@ -40,7 +40,7 @@ class WebhookEventManipulator implements ManipulatorInterface $this->publisher = $publisher; } - public function create($eventName, $type, array $data) + public function create($eventName, $type, array $data, array $collectionBaseIds = array()) { $event = new WebhookEvent(); @@ -48,6 +48,10 @@ class WebhookEventManipulator implements ManipulatorInterface $event->setType($type); $event->setData($data); + if (count($collectionBaseIds) > 0) { + $event->setCollectionBaseIds($collectionBaseIds); + } + $this->update($event); $this->publisher->publishWebhookEvent($event); diff --git a/lib/Alchemy/Phrasea/Webhook/Processor/FeedEntryProcessor.php b/lib/Alchemy/Phrasea/Webhook/Processor/FeedEntryProcessor.php index 7fd4500c49..c873bbb680 100644 --- a/lib/Alchemy/Phrasea/Webhook/Processor/FeedEntryProcessor.php +++ b/lib/Alchemy/Phrasea/Webhook/Processor/FeedEntryProcessor.php @@ -34,17 +34,16 @@ class FeedEntryProcessor implements ProcessorInterface { $data = $event->getData(); - if (!isset($data->entry_id)) { + if (!isset($data['entry_id'])) { return null; } - $entry = $this->entryRepository->find($data->entry_id); + $entry = $this->entryRepository->find($data['entry_id']); if (null === $entry) { return null; } - $data = $event->getData(); $feed = $entry->getFeed(); $query = $this->userQuery; @@ -54,8 +53,8 @@ class FeedEntryProcessor implements ProcessorInterface ->include_templates(false) ->email_not_null(true); - if ($feed->getCollection($this->app)) { - $query->on_base_ids([$feed->getCollection($this->app)->get_base_id()]); + if ($feed->getCollection($this->application)) { + $query->on_base_ids([$feed->getCollection($this->application)->get_base_id()]); } $start = 0; @@ -76,7 +75,7 @@ class FeedEntryProcessor implements ProcessorInterface return [ 'event' => $event->getName(), - 'users_were_notified' => isset($data->notify_email) ?: (bool) $data->notify_email, + 'users_were_notified' => isset($data['notify_email']) ? (bool) $data['notify_email'] : false, 'feed' => [ 'id' => $feed->getId(), 'title' => $feed->getTitle(), diff --git a/tests/Alchemy/Tests/Phrasea/Webhook/Processor/FeedEntryProcessorTest.php b/tests/Alchemy/Tests/Phrasea/Webhook/Processor/FeedEntryProcessorTest.php index 60b518e443..39c3ae57d4 100644 --- a/tests/Alchemy/Tests/Phrasea/Webhook/Processor/FeedEntryProcessorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Webhook/Processor/FeedEntryProcessorTest.php @@ -59,6 +59,6 @@ class FeedEntryProcessorTest extends \PhraseanetTestCase self::$DI['app']['repo.feed-entries'], self::$DI['app']['phraseanet.user-query'] ); - $this->assertEquals($processor->process($event), null); + $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $processor->process($event)); } }