diff --git a/src/Appwrite/Event/Event.php b/src/Appwrite/Event/Event.php index 0fecbe0304..0cf90eb3d3 100644 --- a/src/Appwrite/Event/Event.php +++ b/src/Appwrite/Event/Event.php @@ -46,6 +46,7 @@ class Event protected array $context = []; protected ?Document $project = null; protected ?Document $user = null; + protected bool $paused = false; /** * @param string $queue @@ -263,6 +264,10 @@ class Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + return Resque::enqueue($this->queue, $this->class, [ 'project' => $this->project, 'user' => $this->user, @@ -468,4 +473,22 @@ class Event */ return \array_values($events); } + + /** + * Get the value of paused + */ + public function isPaused(): bool + { + return $this->paused; + } + + /** + * Set the value of paused + */ + public function setPaused(bool $paused): self + { + $this->paused = $paused; + + return $this; + } } diff --git a/src/Appwrite/Event/Func.php b/src/Appwrite/Event/Func.php index 5f8b4c80c6..d121b47a4a 100644 --- a/src/Appwrite/Event/Func.php +++ b/src/Appwrite/Event/Func.php @@ -142,6 +142,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/tests/unit/Event/EventTest.php b/tests/unit/Event/EventTest.php index dee905638f..a328c8d599 100644 --- a/tests/unit/Event/EventTest.php +++ b/tests/unit/Event/EventTest.php @@ -58,6 +58,14 @@ class EventTest extends TestCase $this->assertEquals(\Resque::size($this->queue), 1); } + public function testPause(): void + { + $this->object->setPaused(true); + $this->assertTrue($this->object->isPaused()); + $this->object->setPaused(false); + $this->assertNotTrue($this->object->isPaused()); + } + public function testReset(): void { $this->object