1
0
Fork 0
mirror of synced 2024-06-02 10:54:44 +12:00
appwrite/src/Appwrite/Event/Database.php

103 lines
2.3 KiB
PHP
Raw Normal View History

<?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
*/
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.
* @return string
*/
public function getType(): string
{
return $this->type;
}
2022-04-19 04:21:45 +12:00
/**
* Set the collection for this database event.
*
* @param \Utopia\Database\Document $collection
* @return self
*/
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.
*
* @return null|\Utopia\Database\Document
*/
public function getCollection(): ?Document
{
return $this->collection;
}
2022-04-19 04:21:45 +12:00
/**
* Set the document for this database event.
*
* @param \Utopia\Database\Document $document
* @return self
*/
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.
* @return null|\Utopia\Database\Document
*/
public function getDocument(): ?Document
{
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
*/
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())
]);
}
}