feed webhook

This commit is contained in:
aynsix
2019-09-20 18:04:05 +04:00
parent 5d8132b08d
commit c2524e50dc
4 changed files with 13 additions and 9 deletions

View File

@@ -31,7 +31,8 @@ class FeedEntrySubscriber extends AbstractNotificationSubscriber
$this->app['manipulator.webhook-event']->create( $this->app['manipulator.webhook-event']->create(
WebhookEvent::NEW_FEED_ENTRY, WebhookEvent::NEW_FEED_ENTRY,
WebhookEvent::FEED_ENTRY_TYPE, 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); $datas = json_encode($params);

View File

@@ -40,7 +40,7 @@ class WebhookEventManipulator implements ManipulatorInterface
$this->publisher = $publisher; $this->publisher = $publisher;
} }
public function create($eventName, $type, array $data) public function create($eventName, $type, array $data, array $collectionBaseIds = array())
{ {
$event = new WebhookEvent(); $event = new WebhookEvent();
@@ -48,6 +48,10 @@ class WebhookEventManipulator implements ManipulatorInterface
$event->setType($type); $event->setType($type);
$event->setData($data); $event->setData($data);
if (count($collectionBaseIds) > 0) {
$event->setCollectionBaseIds($collectionBaseIds);
}
$this->update($event); $this->update($event);
$this->publisher->publishWebhookEvent($event); $this->publisher->publishWebhookEvent($event);

View File

@@ -34,17 +34,16 @@ class FeedEntryProcessor implements ProcessorInterface
{ {
$data = $event->getData(); $data = $event->getData();
if (!isset($data->entry_id)) { if (!isset($data['entry_id'])) {
return null; return null;
} }
$entry = $this->entryRepository->find($data->entry_id); $entry = $this->entryRepository->find($data['entry_id']);
if (null === $entry) { if (null === $entry) {
return null; return null;
} }
$data = $event->getData();
$feed = $entry->getFeed(); $feed = $entry->getFeed();
$query = $this->userQuery; $query = $this->userQuery;
@@ -54,8 +53,8 @@ class FeedEntryProcessor implements ProcessorInterface
->include_templates(false) ->include_templates(false)
->email_not_null(true); ->email_not_null(true);
if ($feed->getCollection($this->app)) { if ($feed->getCollection($this->application)) {
$query->on_base_ids([$feed->getCollection($this->app)->get_base_id()]); $query->on_base_ids([$feed->getCollection($this->application)->get_base_id()]);
} }
$start = 0; $start = 0;
@@ -76,7 +75,7 @@ class FeedEntryProcessor implements ProcessorInterface
return [ return [
'event' => $event->getName(), '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' => [ 'feed' => [
'id' => $feed->getId(), 'id' => $feed->getId(),
'title' => $feed->getTitle(), 'title' => $feed->getTitle(),

View File

@@ -59,6 +59,6 @@ class FeedEntryProcessorTest extends \PhraseanetTestCase
self::$DI['app']['repo.feed-entries'], self::$DI['app']['repo.feed-entries'],
self::$DI['app']['phraseanet.user-query'] self::$DI['app']['phraseanet.user-query']
); );
$this->assertEquals($processor->process($event), null); $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $processor->process($event));
} }
} }