Files
Phraseanet/lib/Alchemy/Phrasea/Webhook/Processor/SubdefEventProcessor.php
Aina Sitraka df780d993e PHRAS-4060 webhook - error - stay in running status (#4506)
* fix webhook stay running

* add databox_id and record_id in workerRunningJob
2024-04-29 16:41:33 +02:00

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
];
}
}