2022-04-14 00:39:31 +12:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Appwrite\Event;
|
|
|
|
|
|
|
|
use Utopia\Database\Document;
|
2022-12-21 01:22:58 +13:00
|
|
|
use Utopia\Queue\Client;
|
2022-12-21 00:07:49 +13:00
|
|
|
use Utopia\Queue\Connection;
|
2022-04-14 00:39:31 +12:00
|
|
|
|
|
|
|
class Delete extends Event
|
|
|
|
{
|
|
|
|
protected string $type = '';
|
|
|
|
protected ?Document $document = null;
|
2022-08-15 21:05:41 +12:00
|
|
|
protected ?string $resource = null;
|
2022-07-12 03:12:41 +12:00
|
|
|
protected ?string $datetime = null;
|
2022-10-28 21:40:04 +13:00
|
|
|
protected ?string $hourlyUsageRetentionDatetime = null;
|
2022-09-01 01:07:27 +12:00
|
|
|
|
2022-04-14 00:39:31 +12:00
|
|
|
|
2022-12-21 00:07:49 +13:00
|
|
|
public function __construct(protected Connection $connection)
|
2022-04-14 00:39:31 +12:00
|
|
|
{
|
2023-06-02 15:54:34 +12:00
|
|
|
parent::__construct($connection);
|
|
|
|
|
|
|
|
$this
|
|
|
|
->setQueue(Event::DELETE_QUEUE_NAME)
|
|
|
|
->setClass(Event::DELETE_CLASS_NAME);
|
2022-04-14 00:39:31 +12:00
|
|
|
}
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
/**
|
|
|
|
* Sets the type for the delete event (use the constants starting with DELETE_TYPE_*).
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
* @return self
|
|
|
|
*/
|
2022-04-14 00:39:31 +12:00
|
|
|
public function setType(string $type): self
|
|
|
|
{
|
|
|
|
$this->type = $type;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
/**
|
|
|
|
* Returns the set type for the delete event.
|
|
|
|
*
|
2022-05-24 02:54:50 +12:00
|
|
|
* @return string
|
2022-04-19 04:21:45 +12:00
|
|
|
*/
|
2022-04-14 00:39:31 +12:00
|
|
|
public function getType(): string
|
|
|
|
{
|
|
|
|
return $this->type;
|
|
|
|
}
|
|
|
|
|
2022-05-11 00:33:31 +12:00
|
|
|
/**
|
2022-07-12 03:12:41 +12:00
|
|
|
* set Datetime.
|
2022-05-11 00:33:31 +12:00
|
|
|
*
|
2022-07-12 03:12:41 +12:00
|
|
|
* @param string $datetime
|
2022-05-11 00:33:31 +12:00
|
|
|
* @return self
|
|
|
|
*/
|
2022-07-12 03:12:41 +12:00
|
|
|
public function setDatetime(string $datetime): self
|
2022-04-20 01:13:55 +12:00
|
|
|
{
|
2022-07-12 03:12:41 +12:00
|
|
|
$this->datetime = $datetime;
|
2022-04-20 01:13:55 +12:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-05-11 00:33:31 +12:00
|
|
|
/**
|
2022-10-23 17:46:23 +13:00
|
|
|
* Sets datetime for 1h interval.
|
2022-05-11 00:33:31 +12:00
|
|
|
*
|
2022-07-12 03:12:41 +12:00
|
|
|
* @param string $datetime
|
2022-05-11 00:33:31 +12:00
|
|
|
* @return self
|
|
|
|
*/
|
2022-10-28 22:54:56 +13:00
|
|
|
public function setUsageRetentionHourlyDateTime(string $datetime): self
|
2022-04-20 01:13:55 +12:00
|
|
|
{
|
2022-10-28 21:40:04 +13:00
|
|
|
$this->hourlyUsageRetentionDatetime = $datetime;
|
2022-04-20 01:13:55 +12:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
/**
|
|
|
|
* Sets the document for the delete event.
|
|
|
|
*
|
2022-05-11 00:31:20 +12:00
|
|
|
* @param Document $document
|
2022-04-19 04:21:45 +12:00
|
|
|
* @return self
|
|
|
|
*/
|
2022-04-14 00:39:31 +12:00
|
|
|
public function setDocument(Document $document): self
|
|
|
|
{
|
|
|
|
$this->document = $document;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-08-15 21:05:41 +12:00
|
|
|
/**
|
|
|
|
* Returns the resource for the delete event.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getResource(): string
|
|
|
|
{
|
|
|
|
return $this->resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the resource for the delete event.
|
|
|
|
*
|
|
|
|
* @param string $resource
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public function setResource(string $resource): self
|
|
|
|
{
|
|
|
|
$this->resource = $resource;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
/**
|
|
|
|
* Returns the set document for the delete event.
|
|
|
|
*
|
2022-05-11 00:31:20 +12:00
|
|
|
* @return null|Document
|
2022-04-19 04:21:45 +12:00
|
|
|
*/
|
|
|
|
public function getDocument(): ?Document
|
2022-04-14 00:39:31 +12:00
|
|
|
{
|
|
|
|
return $this->document;
|
|
|
|
}
|
|
|
|
|
2022-08-15 21:05:41 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
/**
|
|
|
|
* Executes this event and sends it to the deletes worker.
|
|
|
|
*
|
|
|
|
* @return string|bool
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
*/
|
2022-04-14 00:39:31 +12:00
|
|
|
public function trigger(): string|bool
|
|
|
|
{
|
2022-12-21 01:22:58 +13:00
|
|
|
$client = new Client($this->queue, $this->connection);
|
|
|
|
|
|
|
|
return $client->enqueue([
|
2022-04-14 00:39:31 +12:00
|
|
|
'project' => $this->project,
|
|
|
|
'type' => $this->type,
|
|
|
|
'document' => $this->document,
|
2022-08-15 21:05:41 +12:00
|
|
|
'resource' => $this->resource,
|
2022-07-12 03:12:41 +12:00
|
|
|
'datetime' => $this->datetime,
|
2023-08-13 07:08:44 +12:00
|
|
|
'hourlyUsageRetentionDatetime' => $this->hourlyUsageRetentionDatetime
|
2022-04-14 00:39:31 +12:00
|
|
|
]);
|
|
|
|
}
|
2022-04-19 04:21:45 +12:00
|
|
|
}
|