Merge pull request #10961 from appwrite/refactor-messaging-and-queue

chore: lazy init sms adapter + late static binding
This commit is contained in:
Jake Barnby 2025-12-16 06:25:15 +00:00 committed by GitHub
commit e3e7f56bb8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 31 deletions

View file

@ -161,7 +161,7 @@ class Database extends Event
return $this->document; return $this->document;
} }
public function setProject(Document $project): self public function setProject(Document $project): static
{ {
$database = $project->getAttribute('database'); $database = $project->getAttribute('database');
if (!empty($database)) { if (!empty($database)) {

View file

@ -92,9 +92,9 @@ class Event
* Set queue used for this event. * Set queue used for this event.
* *
* @param string $queue * @param string $queue
* @return Event * @return static
*/ */
public function setQueue(string $queue): self public function setQueue(string $queue): static
{ {
$this->queue = $queue; $this->queue = $queue;
@ -114,9 +114,9 @@ class Event
/** /**
* Set event name used for this event. * Set event name used for this event.
* @param string $event * @param string $event
* @return Event * @return static
*/ */
public function setEvent(string $event): self public function setEvent(string $event): static
{ {
$this->event = $event; $this->event = $event;
@ -137,9 +137,9 @@ class Event
* Set project for this event. * Set project for this event.
* *
* @param Document $project * @param Document $project
* @return self * @return static
*/ */
public function setProject(Document $project): self public function setProject(Document $project): static
{ {
$this->project = $project; $this->project = $project;
return $this; return $this;
@ -159,9 +159,9 @@ class Event
* Set platform for this event. * Set platform for this event.
* *
* @param array $platform * @param array $platform
* @return self * @return static
*/ */
public function setPlatform(array $platform): self public function setPlatform(array $platform): static
{ {
$this->platform = $platform; $this->platform = $platform;
return $this; return $this;
@ -181,9 +181,9 @@ class Event
* Set user for this event. * Set user for this event.
* *
* @param Document $user * @param Document $user
* @return self * @return static
*/ */
public function setUser(Document $user): self public function setUser(Document $user): static
{ {
$this->user = $user; $this->user = $user;
@ -193,9 +193,9 @@ class Event
/** /**
* Set user ID for this event. * Set user ID for this event.
* *
* @return self * @return static
*/ */
public function setUserId(string $userId): self public function setUserId(string $userId): static
{ {
$this->userId = $userId; $this->userId = $userId;
@ -225,9 +225,9 @@ class Event
* *
* @param array $payload * @param array $payload
* @param array $sensitive * @param array $sensitive
* @return self * @return static
*/ */
public function setPayload(array $payload, array $sensitive = []): self public function setPayload(array $payload, array $sensitive = []): static
{ {
$this->payload = $payload; $this->payload = $payload;

View file

@ -161,19 +161,6 @@ class Messaging extends Event
return $this->scheduledAt; return $this->scheduledAt;
} }
/**
* Set project for this event.
*
* @param Document $project
* @return self
*/
public function setProject(Document $project): self
{
$this->project = $project;
return $this;
}
/** /**
* Prepare the payload for the event * Prepare the payload for the event
* *

View file

@ -62,9 +62,6 @@ class Messaging extends Action
*/ */
public function __construct() public function __construct()
{ {
$this->adapter = $this->createInternalSMSAdapter();
$this $this
->desc('Messaging worker') ->desc('Messaging worker')
->inject('message') ->inject('message')
@ -390,6 +387,10 @@ class Messaging extends Action
private function sendInternalSMSMessage(Document $message, Document $project, array $recipients, Log $log): void private function sendInternalSMSMessage(Document $message, Document $project, array $recipients, Log $log): void
{ {
if ($this->adapter === null) {
$this->adapter = $this->createInternalSMSAdapter();
}
if ($this->adapter === null) { if ($this->adapter === null) {
Console::warning('Skipped SMS processing. SMS adapter is not set.'); Console::warning('Skipped SMS processing. SMS adapter is not set.');
return; return;