mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-09 11:03:17 +00:00
54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
|
|
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)
|
|
{
|
|
$data = $event->getData();
|
|
$eventTime = $data['event_time'];
|
|
$url = $data['url'];
|
|
$instanceName = $data['instance_name'];
|
|
|
|
unset($data['event_time']);
|
|
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']) && $subdef->get_permalink() !== null) {
|
|
$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(),
|
|
'version' => WebhookEvent::WEBHOOK_VERSION,
|
|
'url' => $url,
|
|
'instance_name' => $instanceName,
|
|
'data' => $data,
|
|
'event_time' => $eventTime
|
|
];
|
|
}
|
|
}
|