From 593e5ab3163d588a07205a23ea2f1026cf4379bc Mon Sep 17 00:00:00 2001 From: shimon Date: Tue, 17 Oct 2023 22:08:01 +0300 Subject: [PATCH] some fixes --- app/controllers/api/account.php | 2 +- app/worker.php | 11 +++++++---- src/Appwrite/Event/Build.php | 2 -- src/Appwrite/Event/Database.php | 1 - src/Appwrite/Event/Delete.php | 2 -- src/Appwrite/Event/Event.php | 22 ++++++++++++++++++++++ src/Appwrite/Event/Func.php | 4 ++++ src/Appwrite/Event/Mail.php | 1 - src/Appwrite/Event/Migration.php | 3 --- src/Appwrite/Event/Phone.php | 2 -- 10 files changed, 34 insertions(+), 16 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 449420807..2bc775962 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -2854,7 +2854,7 @@ App::put('/v1/account/verification') $dbForProject->deleteCachedDocument('users', $profile->getId()); $queueForEvents - ->setParam('userId', $user->getId()) + ->setParam('userId', $userId) ->setParam('tokenId', $verificationDocument->getId()) ; diff --git a/app/worker.php b/app/worker.php index 4d11aba1b..8aa52ab93 100644 --- a/app/worker.php +++ b/app/worker.php @@ -44,7 +44,8 @@ Server::setResource('dbForConsole', function (Cache $cache, Registry $register) $database = $pools ->get('console') ->pop() - ->getResource(); + ->getResource() + ; $adapter = new Database($database, $cache); $adapter->setNamespace('_console'); @@ -64,9 +65,10 @@ Server::setResource('dbForProject', function (Cache $cache, Registry $register, $database = $pools ->get($project->getAttribute('database')) ->pop() - ->getResource(); + ->getResource() + ; - $adapter = new Database($database, $cache); + $adapter = new Database($database, $cache); $adapter->setNamespace('_' . $project->getInternalId()); return $adapter; }, ['cache', 'register', 'message', 'dbForConsole']); @@ -111,7 +113,8 @@ Server::setResource('cache', function (Registry $register) { $adapters[] = $pools ->get($value) ->pop() - ->getResource(); + ->getResource() + ; } return new Cache(new Sharding($adapters)); diff --git a/src/Appwrite/Event/Build.php b/src/Appwrite/Event/Build.php index 58667344a..496db87d6 100644 --- a/src/Appwrite/Event/Build.php +++ b/src/Appwrite/Event/Build.php @@ -114,8 +114,6 @@ class Build extends Event { $client = new Client($this->queue, $this->connection); - $events = $this->getEvent() ? Event::generateEvents($this->getEvent(), $this->getParams()) : null; - return $client->enqueue([ 'project' => $this->project, 'resource' => $this->resource, diff --git a/src/Appwrite/Event/Database.php b/src/Appwrite/Event/Database.php index eb22f8897..e5a86ef84 100644 --- a/src/Appwrite/Event/Database.php +++ b/src/Appwrite/Event/Database.php @@ -2,7 +2,6 @@ namespace Appwrite\Event; -use Utopia\App; use Utopia\Database\Document; use Utopia\Queue\Client; use Utopia\Queue\Connection; diff --git a/src/Appwrite/Event/Delete.php b/src/Appwrite/Event/Delete.php index d93dffaf4..57300feb7 100644 --- a/src/Appwrite/Event/Delete.php +++ b/src/Appwrite/Event/Delete.php @@ -128,8 +128,6 @@ class Delete extends Event { $client = new Client($this->queue, $this->connection); - $events = $this->getEvent() ? Event::generateEvents($this->getEvent(), $this->getParams()) : null; - return $client->enqueue([ 'project' => $this->project, 'type' => $this->type, diff --git a/src/Appwrite/Event/Event.php b/src/Appwrite/Event/Event.php index 07f496788..46b430d12 100644 --- a/src/Appwrite/Event/Event.php +++ b/src/Appwrite/Event/Event.php @@ -50,6 +50,7 @@ class Event protected array $context = []; protected ?Document $project = null; protected ?Document $user = null; + protected bool $paused = false; /** * @param Connection $connection @@ -264,6 +265,9 @@ class Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } $client = new Client($this->queue, $this->connection); @@ -472,4 +476,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 f211ec31b..11c9e980e 100644 --- a/src/Appwrite/Event/Func.php +++ b/src/Appwrite/Event/Func.php @@ -188,6 +188,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 393df3d97..c2de8023b 100644 --- a/src/Appwrite/Event/Mail.php +++ b/src/Appwrite/Event/Mail.php @@ -2,7 +2,6 @@ namespace Appwrite\Event; -use Utopia\Database\Document; use Utopia\Queue\Client; use Utopia\Queue\Connection; diff --git a/src/Appwrite/Event/Migration.php b/src/Appwrite/Event/Migration.php index 93126cb35..478291829 100644 --- a/src/Appwrite/Event/Migration.php +++ b/src/Appwrite/Event/Migration.php @@ -2,9 +2,6 @@ namespace Appwrite\Event; -use DateTime; -use Resque; -use ResqueScheduler; use Utopia\Database\Document; use Utopia\Queue\Client; use Utopia\Queue\Connection; diff --git a/src/Appwrite/Event/Phone.php b/src/Appwrite/Event/Phone.php index 9f27345a9..45f193a54 100644 --- a/src/Appwrite/Event/Phone.php +++ b/src/Appwrite/Event/Phone.php @@ -75,8 +75,6 @@ class Phone extends Event { $client = new Client($this->queue, $this->connection); - $events = $this->getEvent() ? Event::generateEvents($this->getEvent(), $this->getParams()) : null; - return $client->enqueue([ 'project' => $this->project, 'user' => $this->user,