retrieve permalink if empty when sending webhook (#4251)

This commit is contained in:
Aina Sitraka
2023-02-22 11:26:29 +03:00
committed by GitHub
parent 8f8631ee31
commit be5c5a2e4a
2 changed files with 25 additions and 2 deletions

View File

@@ -34,8 +34,9 @@ class EventProcessorFactory
$this->registerFactory(WebhookEvent::ORDER_TYPE, new OrderNotificationProcessorFactory($app)); $this->registerFactory(WebhookEvent::ORDER_TYPE, new OrderNotificationProcessorFactory($app));
$this->registerFactory(WebhookEvent::USER_TYPE, new UserProcessorFactory()); $this->registerFactory(WebhookEvent::USER_TYPE, new UserProcessorFactory());
$this->registerCallableFactory(WebhookEvent::RECORD_SUBDEF_TYPE, function () { $this->registerCallableFactory(WebhookEvent::RECORD_SUBDEF_TYPE, function () use ($app) {
return new SubdefEventProcessor(); return (new SubdefEventProcessor())
->setApplicationBox($app['phraseanet.appbox']);
}); });
$this->registerCallableFactory(WebhookEvent::RECORD_TYPE, function () { $this->registerCallableFactory(WebhookEvent::RECORD_TYPE, function () {
return new RecordEventProcessor(); return new RecordEventProcessor();

View File

@@ -2,10 +2,12 @@
namespace Alchemy\Phrasea\Webhook\Processor; namespace Alchemy\Phrasea\Webhook\Processor;
use Alchemy\Phrasea\Application\Helper\ApplicationBoxAware;
use Alchemy\Phrasea\Model\Entities\WebhookEvent; use Alchemy\Phrasea\Model\Entities\WebhookEvent;
class SubdefEventProcessor implements ProcessorInterface class SubdefEventProcessor implements ProcessorInterface
{ {
use ApplicationBoxAware;
public function process(WebhookEvent $event) public function process(WebhookEvent $event)
{ {
@@ -18,6 +20,26 @@ class SubdefEventProcessor implements ProcessorInterface
unset($data['url']); unset($data['url']);
unset($data['instance_name']); unset($data['instance_name']);
try {
$record = $this->findDataboxById($data['databox_id'])->get_record($data['record_id']);
$subdef = $record->get_subdef($data['subdef_name']);
if (empty($data['permalink'])) {
$data['permalink'] = $subdef->get_permalink()->get_url()->__toString();
}
if (empty($data['size'])) {
$data['size'] = $subdef->get_size();
}
if (empty($data['type'])) {
$data['type'] = $subdef->get_mime();
}
} catch (\Exception $e) {
// if some error, we use the initial webhook data
}
return [ return [
'event' => $event->getName(), 'event' => $event->getName(),
'webhookId' => $event->getId(), 'webhookId' => $event->getId(),