appwrite/src/Appwrite/Event/Delete.php

151 lines
3.2 KiB
PHP
Raw Normal View History

<?php
namespace Appwrite\Event;
use Utopia\Database\Document;
2025-01-29 14:13:58 +00:00
use Utopia\Queue\Publisher;
class Delete extends Event
{
protected string $type = '';
protected ?Document $document = null;
protected ?string $resourceType = null;
2022-08-15 09:05:41 +00:00
protected ?string $resource = null;
2022-07-11 15:12:41 +00:00
protected ?string $datetime = null;
2022-10-28 08:40:04 +00:00
protected ?string $hourlyUsageRetentionDatetime = null;
2025-01-29 14:13:58 +00:00
public function __construct(protected Publisher $publisher)
{
2025-01-29 14:13:58 +00:00
parent::__construct($publisher);
2023-06-02 03:54:34 +00:00
$this
->setQueue(Event::DELETE_QUEUE_NAME)
->setClass(Event::DELETE_CLASS_NAME);
}
2022-04-18 16:21:45 +00:00
/**
* Sets the type for the delete event (use the constants starting with DELETE_TYPE_*).
*
* @param string $type
* @return self
*/
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
2022-04-18 16:21:45 +00:00
/**
* Returns the set type for the delete event.
*
2022-05-23 14:54:50 +00:00
* @return string
2022-04-18 16:21:45 +00:00
*/
public function getType(): string
{
return $this->type;
}
2022-05-10 12:33:31 +00:00
/**
2022-07-11 15:12:41 +00:00
* set Datetime.
2022-05-10 12:33:31 +00:00
*
2022-07-11 15:12:41 +00:00
* @param string $datetime
2022-05-10 12:33:31 +00:00
* @return self
*/
2022-07-11 15:12:41 +00:00
public function setDatetime(string $datetime): self
2022-04-19 13:13:55 +00:00
{
2022-07-11 15:12:41 +00:00
$this->datetime = $datetime;
2022-04-19 13:13:55 +00:00
return $this;
}
2022-05-10 12:33:31 +00:00
/**
2022-10-23 04:46:23 +00:00
* Sets datetime for 1h interval.
2022-05-10 12:33:31 +00:00
*
2022-07-11 15:12:41 +00:00
* @param string $datetime
2022-05-10 12:33:31 +00:00
* @return self
*/
2022-10-28 09:54:56 +00:00
public function setUsageRetentionHourlyDateTime(string $datetime): self
2022-04-19 13:13:55 +00:00
{
2022-10-28 08:40:04 +00:00
$this->hourlyUsageRetentionDatetime = $datetime;
2022-04-19 13:13:55 +00:00
return $this;
}
2022-04-18 16:21:45 +00:00
/**
* Sets the document for the delete event.
*
2022-05-10 12:31:20 +00:00
* @param Document $document
2022-04-18 16:21:45 +00:00
* @return self
*/
public function setDocument(Document $document): self
{
$this->document = $document;
return $this;
}
2022-08-15 09:05:41 +00: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;
}
/**
* Sets the resource type for the delete event.
*
* @param string $resourceType
* @return self
*/
public function setResourceType(string $resourceType): self
{
$this->resourceType = $resourceType;
return $this;
}
2022-04-18 16:21:45 +00:00
/**
* Returns the set document for the delete event.
*
2022-05-10 12:31:20 +00:00
* @return null|Document
2022-04-18 16:21:45 +00:00
*/
public function getDocument(): ?Document
{
return $this->document;
}
2022-04-18 16:21:45 +00:00
/**
2025-01-17 05:08:39 +00:00
* Prepare the payload for the event
2022-04-18 16:21:45 +00:00
*
2025-01-17 05:08:39 +00:00
* @return array
2022-04-18 16:21:45 +00:00
*/
2025-01-17 05:08:39 +00:00
protected function preparePayload(): array
{
2025-01-17 05:08:39 +00:00
return [
'project' => $this->project,
'type' => $this->type,
'document' => $this->document,
2022-08-15 09:05:41 +00:00
'resource' => $this->resource,
'resourceType' => $this->resourceType,
2022-07-11 15:12:41 +00:00
'datetime' => $this->datetime,
2023-08-12 19:08:44 +00:00
'hourlyUsageRetentionDatetime' => $this->hourlyUsageRetentionDatetime
2025-01-17 05:08:39 +00:00
];
}
2022-04-18 16:21:45 +00:00
}