mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
retrieve permalink if empty when sending webhook (#4251)
This commit is contained in:
@@ -34,8 +34,9 @@ class EventProcessorFactory
|
||||
$this->registerFactory(WebhookEvent::ORDER_TYPE, new OrderNotificationProcessorFactory($app));
|
||||
|
||||
$this->registerFactory(WebhookEvent::USER_TYPE, new UserProcessorFactory());
|
||||
$this->registerCallableFactory(WebhookEvent::RECORD_SUBDEF_TYPE, function () {
|
||||
return new SubdefEventProcessor();
|
||||
$this->registerCallableFactory(WebhookEvent::RECORD_SUBDEF_TYPE, function () use ($app) {
|
||||
return (new SubdefEventProcessor())
|
||||
->setApplicationBox($app['phraseanet.appbox']);
|
||||
});
|
||||
$this->registerCallableFactory(WebhookEvent::RECORD_TYPE, function () {
|
||||
return new RecordEventProcessor();
|
||||
|
@@ -2,10 +2,12 @@
|
||||
|
||||
namespace Alchemy\Phrasea\Webhook\Processor;
|
||||
|
||||
use Alchemy\Phrasea\Application\Helper\ApplicationBoxAware;
|
||||
use Alchemy\Phrasea\Model\Entities\WebhookEvent;
|
||||
|
||||
class SubdefEventProcessor implements ProcessorInterface
|
||||
{
|
||||
use ApplicationBoxAware;
|
||||
|
||||
public function process(WebhookEvent $event)
|
||||
{
|
||||
@@ -18,6 +20,26 @@ class SubdefEventProcessor implements ProcessorInterface
|
||||
unset($data['url']);
|
||||
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 [
|
||||
'event' => $event->getName(),
|
||||
'webhookId' => $event->getId(),
|
||||
|
Reference in New Issue
Block a user