Spaces:
No application file
No application file
File size: 3,611 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
<?php
namespace Mautic\WebhookBundle\Entity;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
class WebhookQueue
{
/**
* @var int|null
*/
private $id;
/**
* @var Webhook
*/
private $webhook;
/**
* @var \DateTimeInterface|null
*/
private $dateAdded;
/**
* @var string|null
*/
private $payload; // @phpstan-ignore-line (BC: plain payload is fetched by ORM)
/**
* @var string|resource|null
*/
private $payloadCompressed;
/**
* @var Event
**/
private $event;
public static function loadMetadata(ORM\ClassMetadata $metadata): void
{
$builder = new ClassMetadataBuilder($metadata);
$builder->setTable('webhook_queue')
->setCustomRepositoryClass(WebhookQueueRepository::class);
$builder->addId();
$builder->createManyToOne('webhook', 'Webhook')
->addJoinColumn('webhook_id', 'id', false, false, 'CASCADE')
->build();
$builder->addNullableField('dateAdded', Types::DATETIME_MUTABLE, 'date_added');
$builder->addNullableField('payload', Types::TEXT);
$builder->createField('payloadCompressed', Types::BLOB)
->columnName('payload_compressed')
->nullable()
->length(MySQLPlatform::LENGTH_LIMIT_MEDIUMBLOB)
->build();
$builder->createManyToOne('event', 'Event')
->inversedBy('queues')
->addJoinColumn('event_id', 'id', false, false, 'CASCADE')
->build();
}
/**
* @return int|null
*/
public function getId()
{
return $this->id;
}
/**
* @return Webhook|null
*/
public function getWebhook()
{
return $this->webhook;
}
/**
* @param Webhook|null $webhook
*
* @return WebhookQueue
*/
public function setWebhook($webhook)
{
$this->webhook = $webhook;
return $this;
}
/**
* @return \DateTimeInterface|null
*/
public function getDateAdded()
{
return $this->dateAdded;
}
/**
* @param \DateTime|null $dateAdded
*
* @return WebhookQueue
*/
public function setDateAdded($dateAdded)
{
$this->dateAdded = $dateAdded;
return $this;
}
/**
* @return string|null
*/
public function getPayload()
{
if (null !== $this->payload) {
// BC: plain payload is fetched by ORM
return $this->payload;
}
if (null === $this->payloadCompressed) {
// no payload is set
return null;
}
$payloadCompressed = $this->payloadCompressed;
if (is_resource($payloadCompressed)) {
// compressed payload is fetched by ORM
$payloadCompressed = stream_get_contents($this->payloadCompressed);
}
return gzuncompress($payloadCompressed);
}
/**
* @param string $payload
*
* @return WebhookQueue
*/
public function setPayload($payload)
{
$this->payloadCompressed = gzcompress($payload, 9);
return $this;
}
/**
* @return Event|null
*/
public function getEvent()
{
return $this->event;
}
/**
* @param Event|null $event
*
* @return WebhookQueue
*/
public function setEvent($event)
{
$this->event = $event;
return $this;
}
}
|