2022-04-14 00:39:31 +12:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Appwrite\Event;
|
|
|
|
|
|
|
|
use Resque;
|
|
|
|
use Utopia\Database\Document;
|
|
|
|
|
|
|
|
class Database extends Event
|
|
|
|
{
|
|
|
|
protected string $type = '';
|
|
|
|
protected ?Document $collection = null;
|
|
|
|
protected ?Document $document = null;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct(Event::DATABASE_QUEUE_NAME, Event::DATABASE_CLASS_NAME);
|
|
|
|
}
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
/**
|
|
|
|
* Sets the type for this database event (use the constants starting with DATABASE_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 database 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-04-19 04:21:45 +12:00
|
|
|
/**
|
|
|
|
* Set the collection for this database event.
|
|
|
|
*
|
2022-05-11 00:31:20 +12:00
|
|
|
* @param Document $collection
|
2022-04-19 04:21:45 +12:00
|
|
|
* @return self
|
|
|
|
*/
|
2022-04-14 00:39:31 +12:00
|
|
|
public function setCollection(Document $collection): self
|
|
|
|
{
|
|
|
|
$this->collection = $collection;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
/**
|
|
|
|
* Returns set collection for this event.
|
|
|
|
*
|
2022-05-11 00:31:20 +12:00
|
|
|
* @return null|Document
|
2022-04-19 04:21:45 +12:00
|
|
|
*/
|
|
|
|
public function getCollection(): ?Document
|
2022-04-14 00:39:31 +12:00
|
|
|
{
|
|
|
|
return $this->collection;
|
|
|
|
}
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
/**
|
|
|
|
* Set the document for this database 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-04-19 04:21:45 +12:00
|
|
|
/**
|
|
|
|
* Returns set document for this database 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-04-19 04:21:45 +12:00
|
|
|
/**
|
|
|
|
* Executes the event and send it to the database worker.
|
|
|
|
*
|
|
|
|
* @return string|bool
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
*/
|
2022-04-14 00:39:31 +12:00
|
|
|
public function trigger(): string|bool
|
|
|
|
{
|
|
|
|
return Resque::enqueue($this->queue, $this->class, [
|
|
|
|
'project' => $this->project,
|
|
|
|
'user' => $this->user,
|
|
|
|
'type' => $this->type,
|
|
|
|
'collection' => $this->collection,
|
|
|
|
'document' => $this->document,
|
|
|
|
'events' => Event::generateEvents($this->getEvent(), $this->getParams())
|
|
|
|
]);
|
|
|
|
}
|
2022-05-24 02:54:50 +12:00
|
|
|
}
|