appwrite/src/Appwrite/Event/Migration.php

88 lines
1.8 KiB
PHP
Raw Normal View History

2023-08-04 16:21:41 +00:00
<?php
namespace Appwrite\Event;
use Utopia\Database\Document;
2023-10-01 17:39:26 +00:00
use Utopia\Queue\Client;
use Utopia\Queue\Connection;
2023-08-04 16:21:41 +00:00
class Migration extends Event
{
protected string $type = '';
protected ?Document $migration = null;
2023-10-01 17:39:26 +00:00
public function __construct(protected Connection $connection)
2023-08-04 16:21:41 +00:00
{
2023-10-01 17:39:26 +00:00
parent::__construct($connection);
$this
->setQueue(Event::MIGRATIONS_QUEUE_NAME)
->setClass(Event::MIGRATIONS_CLASS_NAME);
2023-08-04 16:21:41 +00:00
}
/**
* Sets migration document for the migration event.
*
* @param Document $migration
* @return self
*/
public function setMigration(Document $migration): self
{
$this->migration = $migration;
return $this;
}
/**
* Returns set migration document for the function event.
*
* @return null|Document
*/
public function getMigration(): ?Document
{
return $this->migration;
}
/**
* Sets migration type for the migration event.
*
* @param string $type
*
* @return self
*/
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
/**
* Returns set migration type for the migration event.
*
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* Executes the migration event and sends it to the migrations worker.
*
* @return string|bool
* @throws \InvalidArgumentException
*/
public function trigger(): string|bool
{
2023-10-01 17:39:26 +00:00
$client = new Client($this->queue, $this->connection);
return $client->enqueue([
2023-08-04 16:21:41 +00:00
'project' => $this->project,
'user' => $this->user,
2024-05-23 15:14:00 +00:00
'migration' => $this->migration,
2023-08-04 16:21:41 +00:00
]);
}
}