From af448ac1831455c777e285073fdd0978f18cf17c Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 8 Nov 2024 21:55:53 +0100 Subject: [PATCH] feat: setpaused --- src/Appwrite/Event/Audit.php | 4 ++++ src/Appwrite/Event/Build.php | 4 ++++ src/Appwrite/Event/Certificate.php | 4 ++++ src/Appwrite/Event/Database.php | 4 ++++ src/Appwrite/Event/Delete.php | 4 ++++ src/Appwrite/Event/Event.php | 22 ++++++++++++++++++++++ src/Appwrite/Event/Func.php | 4 ++++ src/Appwrite/Event/Mail.php | 4 ++++ src/Appwrite/Event/Messaging.php | 4 ++++ src/Appwrite/Event/Migration.php | 3 +++ src/Appwrite/Event/Realtime.php | 2 +- src/Appwrite/Event/Usage.php | 4 ++++ src/Appwrite/Event/UsageDump.php | 4 ++++ 13 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Event/Audit.php b/src/Appwrite/Event/Audit.php index 4b02849970..17506bfe6c 100644 --- a/src/Appwrite/Event/Audit.php +++ b/src/Appwrite/Event/Audit.php @@ -121,6 +121,10 @@ class Audit extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Build.php b/src/Appwrite/Event/Build.php index b8cb62a6f8..1fbf20a9f9 100644 --- a/src/Appwrite/Event/Build.php +++ b/src/Appwrite/Event/Build.php @@ -112,6 +112,10 @@ class Build extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Certificate.php b/src/Appwrite/Event/Certificate.php index 85058c96fe..5d30c3d5ac 100644 --- a/src/Appwrite/Event/Certificate.php +++ b/src/Appwrite/Event/Certificate.php @@ -74,6 +74,10 @@ class Certificate extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Database.php b/src/Appwrite/Event/Database.php index f9eb7d9a7d..1b0ea6851c 100644 --- a/src/Appwrite/Event/Database.php +++ b/src/Appwrite/Event/Database.php @@ -108,6 +108,10 @@ class Database extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + try { $dsn = new DSN($this->getProject()->getAttribute('database')); } catch (\InvalidArgumentException) { diff --git a/src/Appwrite/Event/Delete.php b/src/Appwrite/Event/Delete.php index 064fbcefa9..1a4c9318e3 100644 --- a/src/Appwrite/Event/Delete.php +++ b/src/Appwrite/Event/Delete.php @@ -140,6 +140,10 @@ class Delete extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Event.php b/src/Appwrite/Event/Event.php index 3f166ad7a4..e3a2e394cf 100644 --- a/src/Appwrite/Event/Event.php +++ b/src/Appwrite/Event/Event.php @@ -65,6 +65,24 @@ class Event { } + /** + * Set paused state for this event. + */ + public function setPaused(bool $paused): self + { + $this->paused = $paused; + + return $this; + } + + /** + * Get paused state for this event. + */ + public function getPaused(): bool + { + return $this->paused; + } + /** * Set queue used for this event. * @@ -302,6 +320,10 @@ class Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Func.php b/src/Appwrite/Event/Func.php index 11a445d8ed..0ad639a9f5 100644 --- a/src/Appwrite/Event/Func.php +++ b/src/Appwrite/Event/Func.php @@ -213,6 +213,10 @@ class Func extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); $events = $this->getEvent() ? Event::generateEvents($this->getEvent(), $this->getParams()) : null; diff --git a/src/Appwrite/Event/Mail.php b/src/Appwrite/Event/Mail.php index 9bdbf6044d..a0fca75688 100644 --- a/src/Appwrite/Event/Mail.php +++ b/src/Appwrite/Event/Mail.php @@ -404,6 +404,10 @@ class Mail extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Messaging.php b/src/Appwrite/Event/Messaging.php index f97ff02d21..ab9b1bee6b 100644 --- a/src/Appwrite/Event/Messaging.php +++ b/src/Appwrite/Event/Messaging.php @@ -182,6 +182,10 @@ class Messaging extends Event */ public function trigger(): string | bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Migration.php b/src/Appwrite/Event/Migration.php index e57ac3c87c..789b8e2160 100644 --- a/src/Appwrite/Event/Migration.php +++ b/src/Appwrite/Event/Migration.php @@ -75,6 +75,9 @@ class Migration extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } $client = new Client($this->queue, $this->connection); diff --git a/src/Appwrite/Event/Realtime.php b/src/Appwrite/Event/Realtime.php index e158076f9b..f4f00b59d4 100644 --- a/src/Appwrite/Event/Realtime.php +++ b/src/Appwrite/Event/Realtime.php @@ -32,7 +32,7 @@ class Realtime extends Event */ public function trigger(): string|bool { - if (empty($this->event)) { + if ($this->paused || empty($this->event)) { return false; } diff --git a/src/Appwrite/Event/Usage.php b/src/Appwrite/Event/Usage.php index 4426f4ab1b..161c251c8e 100644 --- a/src/Appwrite/Event/Usage.php +++ b/src/Appwrite/Event/Usage.php @@ -57,6 +57,10 @@ class Usage extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ 'project' => $this->getProject(), diff --git a/src/Appwrite/Event/UsageDump.php b/src/Appwrite/Event/UsageDump.php index 8f87908849..2998e4e104 100644 --- a/src/Appwrite/Event/UsageDump.php +++ b/src/Appwrite/Event/UsageDump.php @@ -38,6 +38,10 @@ class UsageDump extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([