2022-04-13 12:39:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Appwrite\Event;
|
|
|
|
|
|
|
|
|
|
use Resque;
|
|
|
|
|
use Utopia\Database\Document;
|
|
|
|
|
|
|
|
|
|
class Mail extends Event
|
|
|
|
|
{
|
|
|
|
|
protected string $recipient = '';
|
2022-12-14 06:23:14 +00:00
|
|
|
protected string $from = '';
|
2022-04-13 12:39:31 +00:00
|
|
|
protected string $name = '';
|
2022-12-14 06:23:14 +00:00
|
|
|
protected string $subject = '';
|
|
|
|
|
protected string $body = '';
|
2023-03-12 02:12:09 +00:00
|
|
|
protected array $smtp = [];
|
2022-04-13 12:39:31 +00:00
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
parent::__construct(Event::MAILS_QUEUE_NAME, Event::MAILS_CLASS_NAME);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
2022-12-14 06:23:14 +00:00
|
|
|
* Sets subject for the mail event.
|
2022-04-18 16:21:45 +00:00
|
|
|
*
|
2022-12-14 06:23:14 +00:00
|
|
|
* @param string $subject
|
2022-04-18 16:21:45 +00:00
|
|
|
* @return self
|
|
|
|
|
*/
|
2022-12-14 06:23:14 +00:00
|
|
|
public function setSubject(string $subject): self
|
2022-04-13 12:39:31 +00:00
|
|
|
{
|
2022-12-14 06:23:14 +00:00
|
|
|
$this->subject = $subject;
|
2022-04-13 12:39:31 +00:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
|
|
|
|
* Returns set team for the mail event.
|
|
|
|
|
*
|
2022-12-14 06:23:14 +00:00
|
|
|
* @return string
|
2022-04-18 16:21:45 +00:00
|
|
|
*/
|
2022-12-14 06:23:14 +00:00
|
|
|
public function getSubject(): string
|
2022-04-13 12:39:31 +00:00
|
|
|
{
|
2022-12-14 06:23:14 +00:00
|
|
|
return $this->subject;
|
2022-04-13 12:39:31 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
|
|
|
|
* Sets recipient for the mail event.
|
|
|
|
|
*
|
|
|
|
|
* @param string $recipient
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
2022-04-13 12:39:31 +00:00
|
|
|
public function setRecipient(string $recipient): self
|
|
|
|
|
{
|
|
|
|
|
$this->recipient = $recipient;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
|
|
|
|
* Returns set recipient for mail event.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2022-04-13 12:39:31 +00:00
|
|
|
public function getRecipient(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->recipient;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
2022-12-14 06:23:14 +00:00
|
|
|
* Sets from for the mail event.
|
2022-04-18 16:21:45 +00:00
|
|
|
*
|
2022-12-14 06:23:14 +00:00
|
|
|
* @param string $from
|
2022-04-18 16:21:45 +00:00
|
|
|
* @return self
|
|
|
|
|
*/
|
2022-12-14 06:23:14 +00:00
|
|
|
public function setFrom(string $from): self
|
2022-04-13 12:39:31 +00:00
|
|
|
{
|
2022-12-14 06:23:14 +00:00
|
|
|
$this->from = $from;
|
2022-04-13 12:39:31 +00:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
2022-12-14 06:23:14 +00:00
|
|
|
* Returns from for mail event.
|
2022-04-18 16:21:45 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2022-12-14 06:23:14 +00:00
|
|
|
public function getFrom(): string
|
2022-04-13 12:39:31 +00:00
|
|
|
{
|
2022-12-14 06:23:14 +00:00
|
|
|
return $this->from;
|
2022-04-13 12:39:31 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
2022-12-14 06:23:14 +00:00
|
|
|
* Sets body for the mail event.
|
2022-04-18 16:21:45 +00:00
|
|
|
*
|
2022-12-14 06:23:14 +00:00
|
|
|
* @param string $body
|
2022-04-18 16:21:45 +00:00
|
|
|
* @return self
|
|
|
|
|
*/
|
2022-12-14 06:23:14 +00:00
|
|
|
public function setBody(string $body): self
|
2022-04-13 12:39:31 +00:00
|
|
|
{
|
2022-12-14 06:23:14 +00:00
|
|
|
$this->body = $body;
|
2022-04-13 12:39:31 +00:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
2022-12-14 06:23:14 +00:00
|
|
|
* Returns body for the mail event.
|
2022-04-18 16:21:45 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2022-12-14 06:23:14 +00:00
|
|
|
public function getBody(): string
|
2022-04-13 12:39:31 +00:00
|
|
|
{
|
2022-12-14 06:23:14 +00:00
|
|
|
return $this->body;
|
2022-04-13 12:39:31 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
|
|
|
|
* Sets name for the mail event.
|
|
|
|
|
*
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
2022-04-13 12:39:31 +00:00
|
|
|
public function setName(string $name): self
|
|
|
|
|
{
|
|
|
|
|
$this->name = $name;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
|
|
|
|
* Returns set name for the mail event.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2022-04-13 12:39:31 +00:00
|
|
|
public function getName(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->name;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-12 02:12:09 +00:00
|
|
|
/**
|
|
|
|
|
* Set SMTP
|
|
|
|
|
*
|
|
|
|
|
* @param array $smtp
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setSmtp(array $smtp): self
|
|
|
|
|
{
|
|
|
|
|
$this->smtp = $smtp;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get SMTP
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getSmtp(): array
|
|
|
|
|
{
|
|
|
|
|
return $this->smtp;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 16:21:45 +00:00
|
|
|
/**
|
|
|
|
|
* Executes the event and sends it to the mails worker.
|
|
|
|
|
*
|
|
|
|
|
* @return string|bool
|
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
|
*/
|
2022-04-13 12:39:31 +00:00
|
|
|
public function trigger(): string|bool
|
|
|
|
|
{
|
|
|
|
|
return Resque::enqueue($this->queue, $this->class, [
|
2022-12-14 06:23:14 +00:00
|
|
|
'from' => $this->from,
|
2022-04-13 12:39:31 +00:00
|
|
|
'recipient' => $this->recipient,
|
|
|
|
|
'name' => $this->name,
|
2022-12-14 06:23:14 +00:00
|
|
|
'subject' => $this->subject,
|
|
|
|
|
'body' => $this->body,
|
2022-04-13 12:39:31 +00:00
|
|
|
'events' => Event::generateEvents($this->getEvent(), $this->getParams())
|
|
|
|
|
]);
|
|
|
|
|
}
|
2022-04-18 16:21:45 +00:00
|
|
|
}
|