mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
add statusbefore and newstatus data
This commit is contained in:
@@ -13,4 +13,26 @@ namespace Alchemy\Phrasea\Core\Event\Record;
|
|||||||
|
|
||||||
class StatusChangedEvent extends RecordEvent
|
class StatusChangedEvent extends RecordEvent
|
||||||
{
|
{
|
||||||
|
/** @var array */
|
||||||
|
private $statusBefore;
|
||||||
|
|
||||||
|
/** @var array */
|
||||||
|
private $statusAfter;
|
||||||
|
|
||||||
|
public function __construct(\record_adapter $record, array $statusBefore, array $statusAfter)
|
||||||
|
{
|
||||||
|
parent::__construct($record);
|
||||||
|
$this->statusBefore = $statusBefore;
|
||||||
|
$this->statusAfter = $statusAfter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatusBefore()
|
||||||
|
{
|
||||||
|
return $this->statusBefore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatusAfter()
|
||||||
|
{
|
||||||
|
return $this->statusAfter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,7 @@ use Alchemy\Phrasea\Application;
|
|||||||
use Alchemy\Phrasea\Core\Event\Record\CollectionChangedEvent;
|
use Alchemy\Phrasea\Core\Event\Record\CollectionChangedEvent;
|
||||||
use Alchemy\Phrasea\Core\Event\Record\RecordEvent;
|
use Alchemy\Phrasea\Core\Event\Record\RecordEvent;
|
||||||
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
|
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
|
||||||
|
use Alchemy\Phrasea\Core\Event\Record\StatusChangedEvent;
|
||||||
use Alchemy\Phrasea\Core\LazyLocator;
|
use Alchemy\Phrasea\Core\LazyLocator;
|
||||||
use Alchemy\Phrasea\Core\PhraseaEvents;
|
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||||
use Alchemy\Phrasea\Model\Entities\WebhookEvent;
|
use Alchemy\Phrasea\Model\Entities\WebhookEvent;
|
||||||
@@ -78,12 +79,31 @@ class WebhookRecordEventSubscriber implements EventSubscriberInterface
|
|||||||
} else {
|
} else {
|
||||||
$this->app['logger']->error("Record not found when wanting to create webhook data!");
|
$this->app['logger']->error("Record not found when wanting to create webhook data!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onRecordStatusChanged(RecordEvent $event)
|
public function onRecordStatusChanged(StatusChangedEvent $event)
|
||||||
{
|
{
|
||||||
$this->createWebhookEvent($event, WebhookEvent::RECORD_STATUS_CHANGED);
|
$record = $this->convertToRecordAdapter($event->getRecord());
|
||||||
|
|
||||||
|
if ($record !== null) {
|
||||||
|
$eventData = [
|
||||||
|
'databox_id' => $event->getRecord()->getDataboxId(),
|
||||||
|
'record_id' => $event->getRecord()->getRecordId(),
|
||||||
|
'collection_name' => $record->getCollection()->get_name(),
|
||||||
|
'record_type' => $event->getRecord()->isStory() ? "story" : "record",
|
||||||
|
'before' => $event->getStatusBefore(),
|
||||||
|
'after' => $event->getStatusAfter()
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->app['manipulator.webhook-event']->create(
|
||||||
|
WebhookEvent::RECORD_STATUS_CHANGED,
|
||||||
|
WebhookEvent::RECORD_TYPE,
|
||||||
|
$eventData,
|
||||||
|
[$event->getRecord()->getBaseId()]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->app['logger']->error("Record not found when wanting to create webhook data!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -2362,6 +2362,14 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
*/
|
*/
|
||||||
public function setStatus($status)
|
public function setStatus($status)
|
||||||
{
|
{
|
||||||
|
$statusBefore['status'] = [];
|
||||||
|
foreach ($this->getStatusStructure() as $bit => $st) {
|
||||||
|
$statusBefore['status'][] = [
|
||||||
|
'bit' => $bit,
|
||||||
|
'state' => \databox_status::bitIsSet($this->getStatusBitField(), $bit),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
$this->getDataboxConnection()->executeUpdate(
|
$this->getDataboxConnection()->executeUpdate(
|
||||||
'UPDATE record SET moddate = NOW(), status = :status WHERE record_id=:record_id',
|
'UPDATE record SET moddate = NOW(), status = :status WHERE record_id=:record_id',
|
||||||
['status' => bindec($status), 'record_id' => $this->getRecordId()]
|
['status' => bindec($status), 'record_id' => $this->getRecordId()]
|
||||||
@@ -2371,7 +2379,15 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
// modification date is now unknown, delete from cache to reload on another record
|
// modification date is now unknown, delete from cache to reload on another record
|
||||||
$this->delete_data_from_cache();
|
$this->delete_data_from_cache();
|
||||||
|
|
||||||
$this->dispatch(RecordEvents::STATUS_CHANGED, new StatusChangedEvent($this));
|
$newStatus['status'] = [];
|
||||||
|
foreach ($this->getStatusStructure() as $bit => $st) {
|
||||||
|
$newStatus['status'][] = [
|
||||||
|
'bit' => $bit,
|
||||||
|
'state' => \databox_status::bitIsSet($this->getStatusBitField(), $bit),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->dispatch(RecordEvents::STATUS_CHANGED, new StatusChangedEvent($this, $statusBefore, $newStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -53,7 +53,7 @@ class FeedEntryProcessorTest extends \PhraseanetTestCase
|
|||||||
'entry_id' => self::$DI['feed_public_entry']->getId(),
|
'entry_id' => self::$DI['feed_public_entry']->getId(),
|
||||||
'url' => 'server_name',
|
'url' => 'server_name',
|
||||||
'instance_name' => 'instance_name',
|
'instance_name' => 'instance_name',
|
||||||
'time' => new \DateTime()
|
'event_time' => new \DateTime()
|
||||||
]);
|
]);
|
||||||
$event->setName(WebhookEvent::NEW_FEED_ENTRY);
|
$event->setName(WebhookEvent::NEW_FEED_ENTRY);
|
||||||
$event->setType(WebhookEvent::FEED_ENTRY_TYPE);
|
$event->setType(WebhookEvent::FEED_ENTRY_TYPE);
|
||||||
|
Reference in New Issue
Block a user