2022-04-19 13:13:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Appwrite\Event;
|
|
|
|
|
|
|
|
|
|
use Utopia\Database\Document;
|
2025-01-29 14:13:58 +00:00
|
|
|
use Utopia\Queue\Publisher;
|
2022-04-19 13:13:55 +00:00
|
|
|
|
|
|
|
|
class Build extends Event
|
|
|
|
|
{
|
|
|
|
|
protected string $type = '';
|
|
|
|
|
protected ?Document $resource = null;
|
|
|
|
|
protected ?Document $deployment = null;
|
2023-07-30 09:51:13 +00:00
|
|
|
protected ?Document $template = null;
|
2022-04-19 13:13:55 +00:00
|
|
|
|
2025-01-29 14:13:58 +00:00
|
|
|
public function __construct(protected Publisher $publisher)
|
2022-04-19 13:13:55 +00:00
|
|
|
{
|
2025-01-29 14:13:58 +00:00
|
|
|
parent::__construct($publisher);
|
2023-06-02 03:54:34 +00:00
|
|
|
|
|
|
|
|
$this
|
|
|
|
|
->setQueue(Event::BUILDS_QUEUE_NAME)
|
|
|
|
|
->setClass(Event::BUILDS_CLASS_NAME);
|
2022-04-19 13:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-17 12:12:21 +00:00
|
|
|
/**
|
|
|
|
|
* Sets template for the build event.
|
|
|
|
|
*
|
2023-07-30 09:51:13 +00:00
|
|
|
* @param Document $template
|
2023-06-17 12:12:21 +00:00
|
|
|
* @return self
|
|
|
|
|
*/
|
2023-07-30 09:51:13 +00:00
|
|
|
public function setTemplate(Document $template): self
|
2023-06-17 12:12:21 +00:00
|
|
|
{
|
2023-07-30 09:51:13 +00:00
|
|
|
$this->template = $template;
|
2023-06-17 12:12:21 +00:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 13:13:55 +00:00
|
|
|
/**
|
|
|
|
|
* Sets resource document for the build event.
|
|
|
|
|
*
|
2022-05-10 12:31:20 +00:00
|
|
|
* @param Document $resource
|
2022-04-19 13:13:55 +00:00
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setResource(Document $resource): self
|
|
|
|
|
{
|
|
|
|
|
$this->resource = $resource;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns set resource document for the build event.
|
|
|
|
|
*
|
2022-05-23 14:54:50 +00:00
|
|
|
* @return null|Document
|
2022-04-19 13:13:55 +00:00
|
|
|
*/
|
|
|
|
|
public function getResource(): ?Document
|
|
|
|
|
{
|
|
|
|
|
return $this->resource;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets deployment for the build event.
|
|
|
|
|
*
|
2022-05-10 12:31:20 +00:00
|
|
|
* @param Document $deployment
|
2022-04-19 13:13:55 +00:00
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setDeployment(Document $deployment): self
|
|
|
|
|
{
|
|
|
|
|
$this->deployment = $deployment;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns set deployment for the build event.
|
|
|
|
|
*
|
2022-05-10 12:31:20 +00:00
|
|
|
* @return null|Document
|
2022-04-19 13:13:55 +00:00
|
|
|
*/
|
|
|
|
|
public function getDeployment(): ?Document
|
|
|
|
|
{
|
|
|
|
|
return $this->deployment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets type for the build event.
|
|
|
|
|
*
|
|
|
|
|
* @param string $type Can be `BUILD_TYPE_DEPLOYMENT` or `BUILD_TYPE_RETRY`.
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setType(string $type): self
|
|
|
|
|
{
|
|
|
|
|
$this->type = $type;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns set type for the function event.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getType(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-01-17 05:08:39 +00:00
|
|
|
* Prepare payload for queue.
|
2022-04-19 13:13:55 +00:00
|
|
|
*
|
2025-01-17 05:08:39 +00:00
|
|
|
* @return array
|
2022-04-19 13:13:55 +00:00
|
|
|
*/
|
2025-01-17 05:08:39 +00:00
|
|
|
protected function preparePayload(): array
|
2022-04-19 13:13:55 +00:00
|
|
|
{
|
2025-01-17 05:08:39 +00:00
|
|
|
return [
|
2022-04-19 13:13:55 +00:00
|
|
|
'project' => $this->project,
|
|
|
|
|
'resource' => $this->resource,
|
|
|
|
|
'deployment' => $this->deployment,
|
2023-05-22 10:58:13 +00:00
|
|
|
'type' => $this->type,
|
2023-08-11 16:52:13 +00:00
|
|
|
'template' => $this->template
|
2025-01-17 05:08:39 +00:00
|
|
|
];
|
2022-04-19 13:13:55 +00:00
|
|
|
}
|
2024-03-11 10:17:40 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resets event.
|
|
|
|
|
*
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function reset(): self
|
|
|
|
|
{
|
|
|
|
|
$this->type = '';
|
|
|
|
|
$this->resource = null;
|
|
|
|
|
$this->deployment = null;
|
|
|
|
|
$this->template = null;
|
|
|
|
|
parent::reset();
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
2022-04-19 13:13:55 +00:00
|
|
|
}
|