httpClient = $httpClient ?: new GuzzleClient(); $version = new Version(); $this->httpClient->setUserAgent(sprintf('Phraseanet/%s (%s)', $version->getNumber(), $version->getName())); } /** * {@inheritdoc} */ public function getName() { return $this->translator->trans("API Webhook"); } /** * {@inheritdoc} */ public function getJobId() { return 'Webhook'; } /** * {@inheritdoc} */ public function getDescription() { return $this->translator->trans("Notify third party application when an event occurs in Phraseanet"); } /** * {@inheritdoc} */ public function getEditor() { return new DefaultEditor($this->translator); } /** * {@inheritdoc} */ protected function doJob(JobData $data) { $app = $data->getApplication(); $thirdPartyApplications = $app['repo.api-applications']->findWithDefinedWebhookCallback(); /** @var EventProcessorFactory $eventFactory */ $eventFactory = $app['webhook.processor_factory']; foreach ($app['repo.webhook-event']->getUnprocessedEventIterator() as $row) { $event = $row[0]; // set event as processed $app['manipulator.webhook-event']->processed($event); $this->log('info', sprintf('Processing event "%s" with id %d', $event->getName(), $event->getId())); // send requests $this->deliverEvent($eventFactory, $app, $thirdPartyApplications, $event); } } }