From 4d1dabac66405b0c8de8d6333d0921408de37e94 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 15 May 2026 13:21:35 +0530 Subject: [PATCH 1/8] Update Utopia platform to rc2 --- composer.json | 2 +- composer.lock | 59 +++++++++++++++++++++++++-------------------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/composer.json b/composer.json index 7cd048726c..c04bc28f14 100644 --- a/composer.json +++ b/composer.json @@ -75,7 +75,7 @@ "utopia-php/logger": "0.8.*", "utopia-php/messaging": "0.22.*", "utopia-php/migration": "1.*", - "utopia-php/platform": "^1.0@RC", + "utopia-php/platform": "1.0.0-rc2", "utopia-php/pools": "1.*", "utopia-php/span": "1.1.*", "utopia-php/preloader": "0.2.*", diff --git a/composer.lock b/composer.lock index 3033d762e2..3e2e5e764b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9377e1b56bca8dbaf213ee3572ca15c0", + "content-hash": "6404f075ed03ef6651ce9cea63518fa0", "packages": [ { "name": "adhocore/jwt", @@ -4722,26 +4722,26 @@ }, { "name": "utopia-php/platform", - "version": "1.0.0-rc1", + "version": "1.0.0-rc2", "source": { "type": "git", "url": "https://github.com/utopia-php/platform.git", - "reference": "36c0a8b2f3d96ca056d724701a302a127111e933" + "reference": "a67e5037007ee7fdca5359ab4577b82917e55452" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/platform/zipball/36c0a8b2f3d96ca056d724701a302a127111e933", - "reference": "36c0a8b2f3d96ca056d724701a302a127111e933", + "url": "https://api.github.com/repos/utopia-php/platform/zipball/a67e5037007ee7fdca5359ab4577b82917e55452", + "reference": "a67e5037007ee7fdca5359ab4577b82917e55452", "shasum": "" }, "require": { "ext-json": "*", "ext-redis": "*", "php": ">=8.3", - "utopia-php/cli": "0.23.3", + "utopia-php/cli": "0.23.*", "utopia-php/http": "^2.0@RC", - "utopia-php/queue": "0.18.2", - "utopia-php/servers": "0.4.0" + "utopia-php/queue": "0.18.*", + "utopia-php/servers": "0.4.*" }, "require-dev": { "laravel/pint": "1.2.*", @@ -4767,9 +4767,9 @@ ], "support": { "issues": "https://github.com/utopia-php/platform/issues", - "source": "https://github.com/utopia-php/platform/tree/1.0.0-rc1" + "source": "https://github.com/utopia-php/platform/tree/1.0.0-rc2" }, - "time": "2026-05-05T15:09:27+00:00" + "time": "2026-05-15T06:19:20+00:00" }, { "name": "utopia-php/pools", @@ -4925,16 +4925,16 @@ }, { "name": "utopia-php/queue", - "version": "0.18.2", + "version": "0.18.3", "source": { "type": "git", "url": "https://github.com/utopia-php/queue.git", - "reference": "f85ca003c99ff475708c05466643d067403c0c22" + "reference": "141aad162b90728353f3aa834684b1f2affed045" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/queue/zipball/f85ca003c99ff475708c05466643d067403c0c22", - "reference": "f85ca003c99ff475708c05466643d067403c0c22", + "url": "https://api.github.com/repos/utopia-php/queue/zipball/141aad162b90728353f3aa834684b1f2affed045", + "reference": "141aad162b90728353f3aa834684b1f2affed045", "shasum": "" }, "require": { @@ -4985,9 +4985,9 @@ ], "support": { "issues": "https://github.com/utopia-php/queue/issues", - "source": "https://github.com/utopia-php/queue/tree/0.18.2" + "source": "https://github.com/utopia-php/queue/tree/0.18.3" }, - "time": "2026-05-05T04:38:59+00:00" + "time": "2026-05-14T08:53:35+00:00" }, { "name": "utopia-php/registry", @@ -5349,16 +5349,16 @@ }, { "name": "utopia-php/vcs", - "version": "4.0.0", + "version": "4.1.0", "source": { "type": "git", "url": "https://github.com/utopia-php/vcs.git", - "reference": "c14ec4d1188e6cc2e8f5256a4b26e531e4f9ac4e" + "reference": "2850dbe975ee69b9466ee6df385fe1679394ce78" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/vcs/zipball/c14ec4d1188e6cc2e8f5256a4b26e531e4f9ac4e", - "reference": "c14ec4d1188e6cc2e8f5256a4b26e531e4f9ac4e", + "url": "https://api.github.com/repos/utopia-php/vcs/zipball/2850dbe975ee69b9466ee6df385fe1679394ce78", + "reference": "2850dbe975ee69b9466ee6df385fe1679394ce78", "shasum": "" }, "require": { @@ -5392,9 +5392,9 @@ ], "support": { "issues": "https://github.com/utopia-php/vcs/issues", - "source": "https://github.com/utopia-php/vcs/tree/4.0.0" + "source": "https://github.com/utopia-php/vcs/tree/4.1.0" }, - "time": "2026-05-13T04:20:45+00:00" + "time": "2026-05-14T10:04:10+00:00" }, { "name": "utopia-php/websocket", @@ -5587,16 +5587,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "1.29.2", + "version": "1.29.5", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "31248a984a4d478d20a780dda8f5897984ee4e8f" + "reference": "e670edcdfb9ffcec36125b1eb3e4473dce30b620" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/31248a984a4d478d20a780dda8f5897984ee4e8f", - "reference": "31248a984a4d478d20a780dda8f5897984ee4e8f", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/e670edcdfb9ffcec36125b1eb3e4473dce30b620", + "reference": "e670edcdfb9ffcec36125b1eb3e4473dce30b620", "shasum": "" }, "require": { @@ -5632,9 +5632,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/1.29.2" + "source": "https://github.com/appwrite/sdk-generator/tree/1.29.5" }, - "time": "2026-05-13T04:47:38+00:00" + "time": "2026-05-15T06:49:05+00:00" }, { "name": "brianium/paratest", @@ -8567,8 +8567,7 @@ "aliases": [], "minimum-stability": "dev", "stability-flags": { - "utopia-php/http": 5, - "utopia-php/platform": 5 + "utopia-php/http": 5 }, "prefer-stable": true, "prefer-lowest": false, From ad88b827e60f0f813e4000299d3213b3b7b661cd Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 15 May 2026 13:22:35 +0530 Subject: [PATCH 2/8] Refactor database queue publisher --- app/cli.php | 5 ++ app/controllers/shared/api.php | 14 +---- app/init/resources.php | 5 ++ app/init/resources/request.php | 2 - app/init/worker/message.php | 5 -- src/Appwrite/Event/Message/Database.php | 51 +++++++++++++++++++ src/Appwrite/Event/Publisher/Database.php | 45 ++++++++++++++++ .../Collections/Attributes/Action.php | 31 ++++++----- .../Collections/Attributes/BigInt/Create.php | 8 +-- .../Collections/Attributes/Boolean/Create.php | 8 +-- .../Attributes/Datetime/Create.php | 8 +-- .../Collections/Attributes/Delete.php | 33 ++++++------ .../Collections/Attributes/Email/Create.php | 8 +-- .../Collections/Attributes/Enum/Create.php | 8 +-- .../Collections/Attributes/Float/Create.php | 8 +-- .../Collections/Attributes/IP/Create.php | 8 +-- .../Collections/Attributes/Integer/Create.php | 8 +-- .../Collections/Attributes/Line/Create.php | 8 +-- .../Attributes/Longtext/Create.php | 8 +-- .../Attributes/Mediumtext/Create.php | 8 +-- .../Collections/Attributes/Point/Create.php | 8 +-- .../Collections/Attributes/Polygon/Create.php | 8 +-- .../Attributes/Relationship/Create.php | 8 +-- .../Collections/Attributes/String/Create.php | 8 +-- .../Collections/Attributes/Text/Create.php | 8 +-- .../Collections/Attributes/URL/Create.php | 8 +-- .../Collections/Attributes/Varchar/Create.php | 8 +-- .../Http/Databases/Collections/Delete.php | 27 +++++----- .../Databases/Collections/Indexes/Create.php | 33 ++++++------ .../Databases/Collections/Indexes/Delete.php | 33 ++++++------ .../Databases/Http/Databases/Delete.php | 19 ++++--- .../Http/DocumentsDB/Collections/Delete.php | 2 +- .../Collections/Indexes/Create.php | 2 +- .../Collections/Indexes/Delete.php | 2 +- .../Databases/Http/DocumentsDB/Delete.php | 2 +- .../Databases/Http/TablesDB/Delete.php | 2 +- .../TablesDB/Tables/Columns/BigInt/Create.php | 2 +- .../Tables/Columns/Boolean/Create.php | 2 +- .../Tables/Columns/Datetime/Create.php | 2 +- .../Http/TablesDB/Tables/Columns/Delete.php | 2 +- .../TablesDB/Tables/Columns/Email/Create.php | 2 +- .../TablesDB/Tables/Columns/Enum/Create.php | 2 +- .../TablesDB/Tables/Columns/Float/Create.php | 2 +- .../TablesDB/Tables/Columns/IP/Create.php | 2 +- .../Tables/Columns/Integer/Create.php | 2 +- .../TablesDB/Tables/Columns/Line/Create.php | 2 +- .../Tables/Columns/Longtext/Create.php | 2 +- .../Tables/Columns/Mediumtext/Create.php | 2 +- .../TablesDB/Tables/Columns/Point/Create.php | 2 +- .../Tables/Columns/Polygon/Create.php | 2 +- .../Tables/Columns/Relationship/Create.php | 2 +- .../TablesDB/Tables/Columns/String/Create.php | 2 +- .../TablesDB/Tables/Columns/Text/Create.php | 2 +- .../TablesDB/Tables/Columns/URL/Create.php | 2 +- .../Tables/Columns/Varchar/Create.php | 2 +- .../Databases/Http/TablesDB/Tables/Delete.php | 2 +- .../Http/TablesDB/Tables/Indexes/Create.php | 2 +- .../Http/TablesDB/Tables/Indexes/Delete.php | 2 +- .../Http/VectorsDB/Collections/Delete.php | 2 +- .../VectorsDB/Collections/Indexes/Create.php | 2 +- .../VectorsDB/Collections/Indexes/Delete.php | 2 +- .../Databases/Http/VectorsDB/Delete.php | 2 +- .../Modules/Databases/Workers/Databases.php | 10 ++-- .../Http/Health/Queue/Databases/Get.php | 9 ++-- .../Health/Http/Health/Queue/Failed/Get.php | 8 +-- 65 files changed, 315 insertions(+), 221 deletions(-) create mode 100644 src/Appwrite/Event/Message/Database.php create mode 100644 src/Appwrite/Event/Publisher/Database.php diff --git a/app/cli.php b/app/cli.php index c5f436215e..9ad223a3ff 100644 --- a/app/cli.php +++ b/app/cli.php @@ -4,6 +4,7 @@ require_once __DIR__ . '/init.php'; use Appwrite\Event\Event; use Appwrite\Event\Publisher\Certificate as CertificatePublisher; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Event\Publisher\Delete as DeletePublisher; use Appwrite\Event\Publisher\Func as FunctionPublisher; use Appwrite\Event\Publisher\StatsResources as StatsResourcesPublisher; @@ -285,6 +286,10 @@ $container->set('publisherForFunctions', fn (Publisher $publisher) => new Functi $publisher, new Queue(System::getEnv('_APP_FUNCTIONS_QUEUE_NAME', Event::FUNCTIONS_QUEUE_NAME), 'utopia-queue', Event::FUNCTIONS_QUEUE_TTL) ), ['publisher']); +$container->set('publisherForDatabase', fn (Publisher $publisherDatabases) => new DatabasePublisher( + $publisherDatabases, + new Queue(System::getEnv('_APP_DATABASE_QUEUE_NAME', Event::DATABASE_QUEUE_NAME)) +), ['publisherDatabases']); $container->set('publisherForDeletes', fn (Publisher $publisher) => new DeletePublisher( $publisher, new Queue(System::getEnv('_APP_DELETE_QUEUE_NAME', Event::DELETE_QUEUE_NAME)) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index eb99a656c0..6e5167660a 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -4,7 +4,6 @@ use Appwrite\Auth\Key; use Appwrite\Auth\MFA\Type\TOTP; use Appwrite\Bus\Events\RequestCompleted; use Appwrite\Event\Context\Audit as AuditContext; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; use Appwrite\Event\Message\Audit as AuditMessage; use Appwrite\Event\Message\Func as FunctionMessage; @@ -564,7 +563,6 @@ Http::init() ->inject('user') ->inject('queueForEvents') ->inject('auditContext') - ->inject('queueForDatabase') ->inject('usage') ->inject('publisherForFunctions') ->inject('dbForProject') @@ -576,7 +574,7 @@ Http::init() ->inject('platform') ->inject('authorization') ->inject('cacheControlForStorage') - ->action(function (Http $utopia, Request $request, Response $response, Document $project, User $user, Event $queueForEvents, AuditContext $auditContext, EventDatabase $queueForDatabase, Context $usage, FunctionPublisher $publisherForFunctions, Database $dbForProject, Document $resourceToken, string $mode, ?Key $apiKey, array $plan, Telemetry $telemetry, array $platform, Authorization $authorization, callable $cacheControlForStorage) { + ->action(function (Http $utopia, Request $request, Response $response, Document $project, User $user, Event $queueForEvents, AuditContext $auditContext, Context $usage, FunctionPublisher $publisherForFunctions, Database $dbForProject, Document $resourceToken, string $mode, ?Key $apiKey, array $plan, Telemetry $telemetry, array $platform, Authorization $authorization, callable $cacheControlForStorage) { $response->setUser($user); $request->setUser($user); @@ -622,9 +620,6 @@ Http::init() $auditContext->user = $userClone; } - /* Auto-set projects */ - $queueForDatabase->setProject($project); - $useCache = $route->getLabel('cache', false); $storageCacheOperationsCounter = $telemetry->createCounter('storage.cache.operations.load'); if ($useCache) { @@ -815,7 +810,6 @@ Http::shutdown() ->inject('publisherForAudits') ->inject('usage') ->inject('publisherForUsage') - ->inject('queueForDatabase') ->inject('publisherForFunctions') ->inject('queueForWebhooks') ->inject('queueForRealtime') @@ -826,7 +820,7 @@ Http::shutdown() ->inject('bus') ->inject('apiKey') ->inject('mode') - ->action(function (Http $utopia, Request $request, Response $response, Document $project, User $user, Event $queueForEvents, AuditContext $auditContext, Audit $publisherForAudits, Context $usage, UsagePublisher $publisherForUsage, EventDatabase $queueForDatabase, FunctionPublisher $publisherForFunctions, Event $queueForWebhooks, Realtime $queueForRealtime, Database $dbForProject, Authorization $authorization, callable $timelimit, EventProcessor $eventProcessor, Bus $bus, ?Key $apiKey, string $mode) use ($parseLabel) { + ->action(function (Http $utopia, Request $request, Response $response, Document $project, User $user, Event $queueForEvents, AuditContext $auditContext, Audit $publisherForAudits, Context $usage, UsagePublisher $publisherForUsage, FunctionPublisher $publisherForFunctions, Event $queueForWebhooks, Realtime $queueForRealtime, Database $dbForProject, Authorization $authorization, callable $timelimit, EventProcessor $eventProcessor, Bus $bus, ?Key $apiKey, string $mode) use ($parseLabel) { $responsePayload = $response->getPayload(); @@ -973,10 +967,6 @@ Http::shutdown() $publisherForAudits->enqueue(AuditMessage::fromContext($auditContext)); } - if (! empty($queueForDatabase->getType())) { - $queueForDatabase->trigger(); - } - // Cache label $useCache = $route->getLabel('cache', false); if ($useCache) { diff --git a/app/init/resources.php b/app/init/resources.php index 64f16b4c05..92b581157f 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -4,6 +4,7 @@ use Appwrite\Event\Event; use Appwrite\Event\Publisher\Audit as AuditPublisher; use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Event\Publisher\Certificate as CertificatePublisher; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Event\Publisher\Delete as DeletePublisher; use Appwrite\Event\Publisher\Execution as ExecutionPublisher; use Appwrite\Event\Publisher\Func as FunctionPublisher; @@ -126,6 +127,10 @@ $container->set('publisherForBuilds', fn (Publisher $publisher) => new BuildPubl $publisher, new Queue(System::getEnv('_APP_BUILDS_QUEUE_NAME', Event::BUILDS_QUEUE_NAME)) ), ['publisher']); +$container->set('publisherForDatabase', fn (Publisher $publisherDatabases) => new DatabasePublisher( + $publisherDatabases, + new Queue(System::getEnv('_APP_DATABASE_QUEUE_NAME', Event::DATABASE_QUEUE_NAME)) +), ['publisherDatabases']); $container->set('publisherForDeletes', fn (Publisher $publisher) => new DeletePublisher( $publisher, new Queue(System::getEnv('_APP_DELETE_QUEUE_NAME', Event::DELETE_QUEUE_NAME)) diff --git a/app/init/resources/request.php b/app/init/resources/request.php index 2e303dcfaa..85d8db3698 100644 --- a/app/init/resources/request.php +++ b/app/init/resources/request.php @@ -5,7 +5,6 @@ use Ahc\Jwt\JWTException; use Appwrite\Auth\Key; use Appwrite\Databases\TransactionState; use Appwrite\Event\Context\Audit as AuditContext; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; use Appwrite\Event\Message\Func as FunctionMessage; use Appwrite\Event\Publisher\Func as FunctionPublisher; @@ -107,7 +106,6 @@ return function (Container $context): void { }); // Per-request queue resources (stateful, accumulate event data during request) - $context->set('queueForDatabase', fn (Publisher $publisher) => new EventDatabase($publisher), ['publisher']); $context->set('queueForEvents', fn (Publisher $publisher) => new Event($publisher), ['publisher']); $context->set('queueForWebhooks', fn (Publisher $publisher) => new Webhook($publisher), ['publisher']); $context->set('queueForRealtime', fn () => new Realtime(), []); diff --git a/app/init/worker/message.php b/app/init/worker/message.php index 2862d3ccdf..3585421a28 100644 --- a/app/init/worker/message.php +++ b/app/init/worker/message.php @@ -1,6 +1,5 @@ set('queueForDatabase', function (Publisher $publisher) { - return new EventDatabase($publisher); - }, ['publisher']); - $container->set('queueForEvents', function (Publisher $publisher) { return new Event($publisher); }, ['publisher']); diff --git a/src/Appwrite/Event/Message/Database.php b/src/Appwrite/Event/Message/Database.php new file mode 100644 index 0000000000..1178dcf5c7 --- /dev/null +++ b/src/Appwrite/Event/Message/Database.php @@ -0,0 +1,51 @@ + $this->project?->getArrayCopy(), + 'user' => $this->user?->getArrayCopy(), + 'type' => $this->type, + 'table' => $this->table?->getArrayCopy(), + 'row' => $this->row?->getArrayCopy(), + 'collection' => $this->collection?->getArrayCopy(), + 'document' => $this->document?->getArrayCopy(), + 'database' => $this->database?->getArrayCopy(), + 'events' => $this->events, + ]; + } + + public static function fromArray(array $data): static + { + return new self( + project: !empty($data['project']) ? new Document($data['project']) : null, + user: !empty($data['user']) ? new Document($data['user']) : null, + type: $data['type'] ?? '', + table: !empty($data['table']) ? new Document($data['table']) : null, + row: !empty($data['row']) ? new Document($data['row']) : null, + collection: !empty($data['collection']) ? new Document($data['collection']) : null, + document: !empty($data['document']) ? new Document($data['document']) : null, + database: !empty($data['database']) ? new Document($data['database']) : null, + events: $data['events'] ?? [], + ); + } +} diff --git a/src/Appwrite/Event/Publisher/Database.php b/src/Appwrite/Event/Publisher/Database.php new file mode 100644 index 0000000000..09d5c33f03 --- /dev/null +++ b/src/Appwrite/Event/Publisher/Database.php @@ -0,0 +1,45 @@ +publish($queue ?? $this->getQueueFromProject($message->project), $message); + } + + public function getSize(bool $failed = false, ?Queue $queue = null): int + { + return $this->getQueueSize($queue ?? $this->queue, $failed); + } + + private function getQueueFromProject(?Document $project): Queue + { + $database = $project?->getAttribute('database', ''); + if (empty($database)) { + return $this->queue; + } + + try { + $dsn = new DSN($database); + } catch (\InvalidArgumentException) { + $dsn = new DSN('mysql://' . $database); + } + + return new Queue($dsn->getHost()); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php index 4e5203b13f..a07a4be561 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php @@ -2,8 +2,9 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Message\Database as DatabaseMessage; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Utopia\Response; use Appwrite\Utopia\Response as UtopiaResponse; @@ -312,7 +313,7 @@ abstract class Action extends UtopiaAction }; } - protected function createAttribute(string $databaseId, string $collectionId, Document $attribute, Response $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): Document + protected function createAttribute(string $databaseId, string $collectionId, Document $attribute, Response $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): Document { $key = $attribute->getAttribute('key'); $type = $attribute->getAttribute('type', ''); @@ -464,20 +465,6 @@ abstract class Action extends UtopiaAction $dbForProject->purgeCachedCollection('database_' . $db->getSequence() . '_collection_' . $relatedCollection->getSequence()); } - $queueForDatabase - ->setType(DATABASE_TYPE_CREATE_ATTRIBUTE) - ->setDatabase($db); - - if ($this->isCollectionsAPI()) { - $queueForDatabase - ->setDocument($attribute) - ->setCollection($collection); - } else { - $queueForDatabase - ->setRow($attribute) - ->setTable($collection); - } - $queueForEvents ->setContext('database', $db) ->setParam('databaseId', $databaseId) @@ -487,6 +474,18 @@ abstract class Action extends UtopiaAction ->setParam('columnId', $attribute->getId()) ->setContext($this->getCollectionsEventsContext(), $collection); + $publisherForDatabase->enqueue(new DatabaseMessage( + project: $queueForEvents->getProject(), + user: $queueForEvents->getUser(), + type: DATABASE_TYPE_CREATE_ATTRIBUTE, + database: $db, + collection: $this->isCollectionsAPI() ? $collection : null, + document: $this->isCollectionsAPI() ? $attribute : null, + table: $this->isCollectionsAPI() ? null : $collection, + row: $this->isCollectionsAPI() ? null : $attribute, + events: Event::generateEvents($queueForEvents->getEvent(), $queueForEvents->getParams()), + )); + $response->setStatusCode(SwooleResponse::STATUS_CODE_CREATED); return $attribute; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php index 4ea85b71e6..11d3ada810 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/BigInt/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\BigInt; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; @@ -73,13 +73,13 @@ class Create extends Action ->param('array', false, new Boolean(), 'Is attribute an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?int $min, ?int $max, ?int $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): void + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?int $min, ?int $max, ?int $default, bool $array, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { $min ??= \PHP_INT_MIN; $max ??= \PHP_INT_MAX; @@ -102,7 +102,7 @@ class Create extends Action 'array' => $array, 'format' => APP_DATABASE_ATTRIBUTE_BIGINT_RANGE, 'formatOptions' => ['min' => $min, 'max' => $max], - ]), $response, $dbForProject, $queueForDatabase, $queueForEvents, $authorization); + ]), $response, $dbForProject, $publisherForDatabase, $queueForEvents, $authorization); $formatOptions = $attribute->getAttribute('formatOptions', []); if (!empty($formatOptions)) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Create.php index a19b1626c9..475b43f569 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Boolean; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\Deprecated; @@ -68,13 +68,13 @@ class Create extends Action ->param('array', false, new Boolean(), 'Is attribute an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?bool $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): void + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?bool $default, bool $array, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ 'key' => $key, @@ -83,7 +83,7 @@ class Create extends Action 'required' => $required, 'default' => $default, 'array' => $array, - ]), $response, $dbForProject, $queueForDatabase, $queueForEvents, $authorization); + ]), $response, $dbForProject, $publisherForDatabase, $queueForEvents, $authorization); $response ->setStatusCode(SwooleResponse::STATUS_CODE_ACCEPTED) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Create.php index 4162b50daf..7a0776751b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Datetime; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\Deprecated; @@ -69,13 +69,13 @@ class Create extends Action ->param('array', false, new Boolean(), 'Is attribute an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): void + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { $attribute = $this->createAttribute( $databaseId, @@ -91,7 +91,7 @@ class Create extends Action ]), $response, $dbForProject, - $queueForDatabase, + $publisherForDatabase, $queueForEvents, $authorization ); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php index 38b96e67bc..ff1636ae60 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php @@ -2,8 +2,9 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Message\Database as DatabaseMessage; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -66,13 +67,13 @@ class Delete extends Action ->param('key', '', fn (Database $dbForProject) => new Key(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Attribute Key.', false, ['dbForProject']) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $key, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): void + public function action(string $databaseId, string $collectionId, string $key, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { $db = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($db->isEmpty()) { @@ -129,20 +130,6 @@ class Delete extends Action } } - $queueForDatabase - ->setDatabase($db) - ->setType(DATABASE_TYPE_DELETE_ATTRIBUTE); - - if ($this->isCollectionsAPI()) { - $queueForDatabase - ->setRow($attribute) - ->setTable($collection); - } else { - $queueForDatabase - ->setDocument($attribute) - ->setCollection($collection); - } - $type = $attribute->getAttribute('type'); $format = $attribute->getAttribute('format'); @@ -158,6 +145,18 @@ class Delete extends Action ->setPayload($response->output($attribute, $model)) ->setContext($this->getCollectionsEventsContext(), $collection); + $publisherForDatabase->enqueue(new DatabaseMessage( + project: $queueForEvents->getProject(), + user: $queueForEvents->getUser(), + type: DATABASE_TYPE_DELETE_ATTRIBUTE, + database: $db, + collection: $this->isCollectionsAPI() ? null : $collection, + document: $this->isCollectionsAPI() ? null : $attribute, + table: $this->isCollectionsAPI() ? $collection : null, + row: $this->isCollectionsAPI() ? $attribute : null, + events: Event::generateEvents($queueForEvents->getEvent(), $queueForEvents->getParams()), + )); + $response->noContent(); } } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Create.php index 6530cdb1dd..098083bea6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Email; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\Deprecated; @@ -69,13 +69,13 @@ class Create extends Action ->param('array', false, new Boolean(), 'Is attribute an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): void + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { $attribute = $this->createAttribute( $databaseId, @@ -91,7 +91,7 @@ class Create extends Action ]), $response, $dbForProject, - $queueForDatabase, + $publisherForDatabase, $queueForEvents, $authorization ); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Create.php index fbc2d08cd1..602189e881 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Enum; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; @@ -72,13 +72,13 @@ class Create extends Action ->param('array', false, new Boolean(), 'Is attribute an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $key, array $elements, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): void + public function action(string $databaseId, string $collectionId, string $key, array $elements, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { if (!is_null($default) && !\in_array($default, $elements, true)) { throw new Exception($this->getInvalidValueException(), 'Default value not found in elements'); @@ -99,7 +99,7 @@ class Create extends Action ]), $response, $dbForProject, - $queueForDatabase, + $publisherForDatabase, $queueForEvents, $authorization ); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Create.php index e1585be169..a715b51b5a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Float; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; @@ -73,13 +73,13 @@ class Create extends Action ->param('array', false, new Boolean(), 'Is attribute an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?float $min, ?float $max, ?float $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): void + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?float $min, ?float $max, ?float $default, bool $array, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { $min ??= -PHP_FLOAT_MAX; $max ??= PHP_FLOAT_MAX; @@ -102,7 +102,7 @@ class Create extends Action 'array' => $array, 'format' => APP_DATABASE_ATTRIBUTE_FLOAT_RANGE, 'formatOptions' => ['min' => $min, 'max' => $max], - ]), $response, $dbForProject, $queueForDatabase, $queueForEvents, $authorization); + ]), $response, $dbForProject, $publisherForDatabase, $queueForEvents, $authorization); $formatOptions = $attribute->getAttribute('formatOptions', []); if (!empty($formatOptions)) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Create.php index 8b02339252..9a142b1a86 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\IP; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\Deprecated; @@ -69,13 +69,13 @@ class Create extends Action ->param('array', false, new Boolean(), 'Is attribute an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): void + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { $attribute = $this->createAttribute( $databaseId, @@ -91,7 +91,7 @@ class Create extends Action ]), $response, $dbForProject, - $queueForDatabase, + $publisherForDatabase, $queueForEvents, $authorization ); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Create.php index 3d2fa68797..89aefb87e6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Integer; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; @@ -73,13 +73,13 @@ class Create extends Action ->param('array', false, new Boolean(), 'Is attribute an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?int $min, ?int $max, ?int $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): void + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?int $min, ?int $max, ?int $default, bool $array, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { $min ??= \PHP_INT_MIN; $max ??= \PHP_INT_MAX; @@ -104,7 +104,7 @@ class Create extends Action 'array' => $array, 'format' => APP_DATABASE_ATTRIBUTE_INT_RANGE, 'formatOptions' => ['min' => $min, 'max' => $max], - ]), $response, $dbForProject, $queueForDatabase, $queueForEvents, $authorization); + ]), $response, $dbForProject, $publisherForDatabase, $queueForEvents, $authorization); $formatOptions = $attribute->getAttribute('formatOptions', []); if (!empty($formatOptions)) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php index d2578a963f..d3f82cd109 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Line/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Line; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; @@ -69,13 +69,13 @@ class Create extends Action ->param('default', null, new Nullable(new Spatial(Database::VAR_LINESTRING)), 'Default value for attribute when not provided, two-dimensional array of coordinate pairs, [[longitude, latitude], [longitude, latitude], …], listing the vertices of the line in order. Cannot be set when attribute is required.', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?array $default, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): void + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?array $default, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { if (!$dbForProject->getAdapter()->getSupportForSpatialAttributes()) { throw new Exception(Exception::GENERAL_FEATURE_UNSUPPORTED, 'Spatial columns are not supported by this database.'); @@ -86,7 +86,7 @@ class Create extends Action 'type' => Database::VAR_LINESTRING, 'required' => $required, 'default' => $default - ]), $response, $dbForProject, $queueForDatabase, $queueForEvents, $authorization); + ]), $response, $dbForProject, $publisherForDatabase, $queueForEvents, $authorization); $response ->setStatusCode(SwooleResponse::STATUS_CODE_ACCEPTED) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Create.php index 2fc9de8699..90591b43fb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Longtext; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; @@ -67,7 +67,7 @@ class Create extends Action ->param('encrypt', false, new Boolean(), 'Toggle encryption for the attribute. Encryption enhances security by not storing any plain text values in the database. However, encrypted attributes cannot be queried.', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('plan') ->inject('authorization') @@ -84,7 +84,7 @@ class Create extends Action bool $encrypt, UtopiaResponse $response, Database $dbForProject, - EventDatabase $queueForDatabase, + DatabasePublisher $publisherForDatabase, Event $queueForEvents, array $plan, Authorization $authorization @@ -112,7 +112,7 @@ class Create extends Action ]), $response, $dbForProject, - $queueForDatabase, + $publisherForDatabase, $queueForEvents, $authorization ); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Create.php index 5776e51917..0f7b386fd5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Mediumtext; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; @@ -67,7 +67,7 @@ class Create extends Action ->param('encrypt', false, new Boolean(), 'Toggle encryption for the attribute. Encryption enhances security by not storing any plain text values in the database. However, encrypted attributes cannot be queried.', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('plan') ->inject('authorization') @@ -84,7 +84,7 @@ class Create extends Action bool $encrypt, UtopiaResponse $response, Database $dbForProject, - EventDatabase $queueForDatabase, + DatabasePublisher $publisherForDatabase, Event $queueForEvents, array $plan, Authorization $authorization @@ -112,7 +112,7 @@ class Create extends Action ]), $response, $dbForProject, - $queueForDatabase, + $publisherForDatabase, $queueForEvents, $authorization ); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php index 527b4330b9..38082b46da 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Point/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Point; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; @@ -69,13 +69,13 @@ class Create extends Action ->param('default', null, new Nullable(new Spatial(Database::VAR_POINT)), 'Default value for attribute when not provided, array of two numbers [longitude, latitude], representing a single coordinate. Cannot be set when attribute is required.', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?array $default, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): void + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?array $default, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { if (!$dbForProject->getAdapter()->getSupportForSpatialAttributes()) { throw new Exception(Exception::GENERAL_FEATURE_UNSUPPORTED, 'Spatial columns are not supported by this database.'); @@ -86,7 +86,7 @@ class Create extends Action 'type' => Database::VAR_POINT, 'required' => $required, 'default' => $default, - ]), $response, $dbForProject, $queueForDatabase, $queueForEvents, $authorization); + ]), $response, $dbForProject, $publisherForDatabase, $queueForEvents, $authorization); $response ->setStatusCode(SwooleResponse::STATUS_CODE_ACCEPTED) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php index 4c3e725f3e..3063d1938a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Polygon/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Polygon; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; @@ -69,13 +69,13 @@ class Create extends Action ->param('default', null, new Nullable(new Spatial(Database::VAR_POLYGON)), 'Default value for attribute when not provided, three-dimensional array where the outer array holds one or more linear rings, [[[longitude, latitude], …], …], the first ring is the exterior boundary, any additional rings are interior holes, and each ring must start and end with the same coordinate pair. Cannot be set when attribute is required.', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?array $default, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): void + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?array $default, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { if (!$dbForProject->getAdapter()->getSupportForSpatialAttributes()) { throw new Exception(Exception::GENERAL_FEATURE_UNSUPPORTED, 'Spatial columns are not supported by this database.'); @@ -86,7 +86,7 @@ class Create extends Action 'type' => Database::VAR_POLYGON, 'required' => $required, 'default' => $default, - ]), $response, $dbForProject, $queueForDatabase, $queueForEvents, $authorization); + ]), $response, $dbForProject, $publisherForDatabase, $queueForEvents, $authorization); $response ->setStatusCode(SwooleResponse::STATUS_CODE_ACCEPTED) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php index fdd40aaa8f..ace48a5c56 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Relationship; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; @@ -81,13 +81,13 @@ class Create extends Action ], true), 'Constraints option', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $relatedCollectionId, string $type, bool $twoWay, ?string $key, ?string $twoWayKey, string $onDelete, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): void + public function action(string $databaseId, string $collectionId, string $relatedCollectionId, string $type, bool $twoWay, ?string $key, ?string $twoWayKey, string $onDelete, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { if (!$dbForProject->getAdapter()->getSupportForRelationships()) { throw new Exception(Exception::GENERAL_FEATURE_UNSUPPORTED, 'Relationships are not supported by this database.'); @@ -159,7 +159,7 @@ class Create extends Action 'twoWayKey' => $twoWayKey, 'onDelete' => $onDelete, ] - ]), $response, $dbForProject, $queueForDatabase, $queueForEvents, $authorization); + ]), $response, $dbForProject, $publisherForDatabase, $queueForEvents, $authorization); foreach ($attribute->getAttribute('options', []) as $k => $option) { $attribute->setAttribute($k, $option); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Create.php index c8917c3deb..a32a3083ab 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\String; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; @@ -75,7 +75,7 @@ class Create extends Action ->param('encrypt', false, new Boolean(), 'Toggle encryption for the attribute. Encryption enhances security by not storing any plain text values in the database. However, encrypted attributes cannot be queried.', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('plan') ->inject('authorization') @@ -93,7 +93,7 @@ class Create extends Action bool $encrypt, UtopiaResponse $response, Database $dbForProject, - EventDatabase $queueForDatabase, + DatabasePublisher $publisherForDatabase, Event $queueForEvents, array $plan, Authorization $authorization @@ -134,7 +134,7 @@ class Create extends Action ]), $response, $dbForProject, - $queueForDatabase, + $publisherForDatabase, $queueForEvents, $authorization ); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Create.php index eb6b2f9691..79968d0feb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Text; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; @@ -67,7 +67,7 @@ class Create extends Action ->param('encrypt', false, new Boolean(), 'Toggle encryption for the attribute. Encryption enhances security by not storing any plain text values in the database. However, encrypted attributes cannot be queried.', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('plan') ->inject('authorization') @@ -84,7 +84,7 @@ class Create extends Action bool $encrypt, UtopiaResponse $response, Database $dbForProject, - EventDatabase $queueForDatabase, + DatabasePublisher $publisherForDatabase, Event $queueForEvents, array $plan, Authorization $authorization @@ -112,7 +112,7 @@ class Create extends Action ]), $response, $dbForProject, - $queueForDatabase, + $publisherForDatabase, $queueForEvents, $authorization ); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Create.php index 7ada8c7f7d..7338bdbd1d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\URL; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\Deprecated; @@ -69,7 +69,7 @@ class Create extends Action ->param('array', false, new Boolean(), 'Is attribute an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); @@ -84,7 +84,7 @@ class Create extends Action bool $array, UtopiaResponse $response, Database $dbForProject, - EventDatabase $queueForDatabase, + DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization ): void { @@ -96,7 +96,7 @@ class Create extends Action 'default' => $default, 'array' => $array, 'format' => APP_DATABASE_ATTRIBUTE_URL, - ]), $response, $dbForProject, $queueForDatabase, $queueForEvents, $authorization); + ]), $response, $dbForProject, $publisherForDatabase, $queueForEvents, $authorization); $response ->setStatusCode(SwooleResponse::STATUS_CODE_ACCEPTED) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Create.php index 24a36725c8..89690de4e9 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Create.php @@ -2,8 +2,8 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Varchar; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; @@ -70,7 +70,7 @@ class Create extends Action ->param('encrypt', false, new Boolean(), 'Toggle encryption for the attribute. Encryption enhances security by not storing any plain text values in the database. However, encrypted attributes cannot be queried.', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('plan') ->inject('authorization') @@ -88,7 +88,7 @@ class Create extends Action bool $encrypt, UtopiaResponse $response, Database $dbForProject, - EventDatabase $queueForDatabase, + DatabasePublisher $publisherForDatabase, Event $queueForEvents, array $plan, Authorization $authorization @@ -129,7 +129,7 @@ class Create extends Action ]), $response, $dbForProject, - $queueForDatabase, + $publisherForDatabase, $queueForEvents, $authorization ); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php index 7a5b73f7db..87171fb2fe 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php @@ -2,8 +2,9 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Message\Database as DatabaseMessage; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -63,13 +64,13 @@ class Delete extends Action ->inject('response') ->inject('dbForProject') ->inject('getDatabasesDB') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, UtopiaResponse $response, Database $dbForProject, callable $getDatabasesDB, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): void + public function action(string $databaseId, string $collectionId, UtopiaResponse $response, Database $dbForProject, callable $getDatabasesDB, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { @@ -89,22 +90,22 @@ class Delete extends Action $dbForDatabases = $getDatabasesDB($database); $dbForDatabases->purgeCachedCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); - $queueForDatabase - ->setType(DATABASE_TYPE_DELETE_COLLECTION) - ->setDatabase($database); - - if ($this->isCollectionsAPI()) { - $queueForDatabase->setCollection($collection); - } else { - $queueForDatabase->setTable($collection); - } - $queueForEvents ->setParam('databaseId', $databaseId) ->setContext('database', $database) ->setParam($this->getEventsParamKey(), $collection->getId()) ->setPayload($response->output($collection, $this->getResponseModel())); + $publisherForDatabase->enqueue(new DatabaseMessage( + project: $queueForEvents->getProject(), + user: $queueForEvents->getUser(), + type: DATABASE_TYPE_DELETE_COLLECTION, + database: $database, + collection: $this->isCollectionsAPI() ? $collection : null, + table: $this->isCollectionsAPI() ? null : $collection, + events: Event::generateEvents($queueForEvents->getEvent(), $queueForEvents->getParams()), + )); + $response->noContent(); } } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php index 7e073c95d4..6c13a5c33c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php @@ -2,8 +2,9 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Indexes; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Message\Database as DatabaseMessage; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -78,13 +79,13 @@ class Create extends Action ->inject('response') ->inject('dbForProject') ->inject('getDatabasesDB') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $key, string $type, array $attributes, array $orders, array $lengths, UtopiaResponse $response, Database $dbForProject, callable $getDatabasesDB, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): void + public function action(string $databaseId, string $collectionId, string $key, string $type, array $attributes, array $orders, array $lengths, UtopiaResponse $response, Database $dbForProject, callable $getDatabasesDB, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { $db = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); @@ -228,20 +229,6 @@ class Create extends Action $dbForProject->purgeCachedDocument('database_' . $db->getSequence(), $collectionId); - $queueForDatabase - ->setType(DATABASE_TYPE_CREATE_INDEX) - ->setDatabase($db); - - if ($this->isCollectionsAPI()) { - $queueForDatabase - ->setCollection($collection) - ->setDocument($index); - } else { - $queueForDatabase - ->setTable($collection) - ->setRow($index); - } - $queueForEvents ->setContext('database', $db) ->setParam('databaseId', $databaseId) @@ -250,6 +237,18 @@ class Create extends Action ->setParam('tableId', $collection->getId()) ->setContext($this->getCollectionsEventsContext(), $collection); + $publisherForDatabase->enqueue(new DatabaseMessage( + project: $queueForEvents->getProject(), + user: $queueForEvents->getUser(), + type: DATABASE_TYPE_CREATE_INDEX, + database: $db, + collection: $this->isCollectionsAPI() ? $collection : null, + document: $this->isCollectionsAPI() ? $index : null, + table: $this->isCollectionsAPI() ? null : $collection, + row: $this->isCollectionsAPI() ? null : $index, + events: Event::generateEvents($queueForEvents->getEvent(), $queueForEvents->getParams()), + )); + $response ->setStatusCode(SwooleResponse::STATUS_CODE_ACCEPTED) ->dynamic($index, $this->getResponseModel()); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php index dea62bfc16..82cada6e0d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php @@ -2,8 +2,9 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Indexes; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Message\Database as DatabaseMessage; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -69,13 +70,13 @@ class Delete extends Action ->param('key', '', fn (Database $dbForProject) => new Key(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Index Key.', false, ['dbForProject']) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); } - public function action(string $databaseId, string $collectionId, string $key, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents, Authorization $authorization): void + public function action(string $databaseId, string $collectionId, string $key, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { $db = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); @@ -103,20 +104,6 @@ class Delete extends Action $dbForProject->purgeCachedDocument('database_' . $db->getSequence(), $collectionId); - $queueForDatabase - ->setType(DATABASE_TYPE_DELETE_INDEX) - ->setDatabase($db); - - if ($this->isCollectionsAPI()) { - $queueForDatabase - ->setCollection($collection) - ->setDocument($index); - } else { - $queueForDatabase - ->setTable($collection) - ->setRow($index); - } - $queueForEvents ->setContext('database', $db) ->setParam('databaseId', $databaseId) @@ -126,6 +113,18 @@ class Delete extends Action ->setContext($this->getCollectionsEventsContext(), $collection) ->setPayload($response->output($index, $this->getResponseModel())); + $publisherForDatabase->enqueue(new DatabaseMessage( + project: $queueForEvents->getProject(), + user: $queueForEvents->getUser(), + type: DATABASE_TYPE_DELETE_INDEX, + database: $db, + collection: $this->isCollectionsAPI() ? $collection : null, + document: $this->isCollectionsAPI() ? $index : null, + table: $this->isCollectionsAPI() ? null : $collection, + row: $this->isCollectionsAPI() ? null : $index, + events: Event::generateEvents($queueForEvents->getEvent(), $queueForEvents->getParams()), + )); + $response->noContent(); } } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php index 1046d7e566..058c48d68f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php @@ -2,8 +2,9 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases; -use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; +use Appwrite\Event\Message\Database as DatabaseMessage; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -58,12 +59,12 @@ class Delete extends Action ->param('databaseId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Database ID.', false, ['dbForProject']) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->callback($this->action(...)); } - public function action(string $databaseId, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void + public function action(string $databaseId, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents): void { $database = $dbForProject->getDocument('databases', $databaseId); @@ -78,14 +79,18 @@ class Delete extends Action $dbForProject->purgeCachedDocument('databases', $database->getId()); $dbForProject->purgeCachedCollection('databases_' . $database->getSequence()); - $queueForDatabase - ->setType(DATABASE_TYPE_DELETE_DATABASE) - ->setDatabase($database); - $queueForEvents ->setParam('databaseId', $database->getId()) ->setPayload($response->output($database, UtopiaResponse::MODEL_DATABASE)); + $publisherForDatabase->enqueue(new DatabaseMessage( + project: $queueForEvents->getProject(), + user: $queueForEvents->getUser(), + type: DATABASE_TYPE_DELETE_DATABASE, + database: $database, + events: Event::generateEvents($queueForEvents->getEvent(), $queueForEvents->getParams()), + )); + $response->noContent(); } } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Delete.php index d698b40203..043f74998d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Delete.php @@ -54,7 +54,7 @@ class Delete extends CollectionDelete ->inject('response') ->inject('dbForProject') ->inject('getDatabasesDB') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/Create.php index dc3ce34605..637255f16a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/Create.php @@ -65,7 +65,7 @@ class Create extends IndexCreate ->inject('response') ->inject('dbForProject') ->inject('getDatabasesDB') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/Delete.php index d4464f171d..1e3c012b4f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Collections/Indexes/Delete.php @@ -59,7 +59,7 @@ class Delete extends IndexDelete ->param('key', '', new Key(), 'Index Key.') ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Delete.php index 1708656c98..5e63ab8a7f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Delete.php @@ -48,7 +48,7 @@ class Delete extends DatabaseDelete ->param('databaseId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Database ID.', false, ['dbForProject']) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('usage') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Delete.php index 7873d369e6..70dc8430f2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Delete.php @@ -48,7 +48,7 @@ class Delete extends DatabaseDelete ->param('databaseId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Database ID.', false, ['dbForProject']) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->callback($this->action(...)); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php index 1d32c6bad9..9d882e09a6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/BigInt/Create.php @@ -62,7 +62,7 @@ class Create extends BigIntCreate ->param('array', false, new Boolean(), 'Is column an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Boolean/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Boolean/Create.php index 10cd65bc98..334c8b5124 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Boolean/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Boolean/Create.php @@ -59,7 +59,7 @@ class Create extends BooleanCreate ->param('array', false, new Boolean(), 'Is column an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Datetime/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Datetime/Create.php index 64e73e310e..922e071f35 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Datetime/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Datetime/Create.php @@ -60,7 +60,7 @@ class Create extends DatetimeCreate ->param('array', false, new Boolean(), 'Is column an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Delete.php index f4d606637d..8e0abf211f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Delete.php @@ -57,7 +57,7 @@ class Delete extends AttributesDelete ->param('key', '', fn (Database $dbForProject) => new Key(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Column Key.', false, ['dbForProject']) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Email/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Email/Create.php index d0b2ed3e4b..072e334b4b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Email/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Email/Create.php @@ -60,7 +60,7 @@ class Create extends EmailCreate ->param('array', false, new Boolean(), 'Is column an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Enum/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Enum/Create.php index e58ae115fc..9d24f310bd 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Enum/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Enum/Create.php @@ -62,7 +62,7 @@ class Create extends EnumCreate ->param('array', false, new Boolean(), 'Is column an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Float/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Float/Create.php index b8e81820aa..d68b3a4921 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Float/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Float/Create.php @@ -62,7 +62,7 @@ class Create extends FloatCreate ->param('array', false, new Boolean(), 'Is column an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/IP/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/IP/Create.php index c2faec9aeb..ff5828e749 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/IP/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/IP/Create.php @@ -60,7 +60,7 @@ class Create extends IPCreate ->param('array', false, new Boolean(), 'Is column an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Integer/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Integer/Create.php index 1a965c19dc..dec399cdb2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Integer/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Integer/Create.php @@ -62,7 +62,7 @@ class Create extends IntegerCreate ->param('array', false, new Boolean(), 'Is column an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php index c2f480d5d0..71548c74da 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Line/Create.php @@ -59,7 +59,7 @@ class Create extends LineCreate ->param('default', null, new Nullable(new Spatial(Database::VAR_LINESTRING)), 'Default value for column when not provided, two-dimensional array of coordinate pairs, [[longitude, latitude], [longitude, latitude], …], listing the vertices of the line in order. Cannot be set when column is required.', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Longtext/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Longtext/Create.php index 8e2dbd911d..ec0f633400 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Longtext/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Longtext/Create.php @@ -60,7 +60,7 @@ class Create extends LongtextCreate ->param('encrypt', false, new Boolean(), 'Toggle encryption for the column. Encryption enhances security by not storing any plain text values in the database. However, encrypted columns cannot be queried.', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('plan') ->inject('authorization') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Mediumtext/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Mediumtext/Create.php index f0b8099f02..2728caa58f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Mediumtext/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Mediumtext/Create.php @@ -60,7 +60,7 @@ class Create extends MediumtextCreate ->param('encrypt', false, new Boolean(), 'Toggle encryption for the column. Encryption enhances security by not storing any plain text values in the database. However, encrypted columns cannot be queried.', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('plan') ->inject('authorization') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php index 138ee482c3..601e19299b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Point/Create.php @@ -59,7 +59,7 @@ class Create extends PointCreate ->param('default', null, new Nullable(new Spatial(Database::VAR_POINT)), 'Default value for column when not provided, array of two numbers [longitude, latitude], representing a single coordinate. Cannot be set when column is required.', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php index a03a34f310..36972d5da2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Polygon/Create.php @@ -59,7 +59,7 @@ class Create extends PolygonCreate ->param('default', null, new Nullable(new Spatial(Database::VAR_POLYGON)), 'Default value for column when not provided, three-dimensional array where the outer array holds one or more linear rings, [[[longitude, latitude], …], …], the first ring is the exterior boundary, any additional rings are interior holes, and each ring must start and end with the same coordinate pair. Cannot be set when column is required.', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Relationship/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Relationship/Create.php index 87544926fe..414cf03b3d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Relationship/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Relationship/Create.php @@ -71,7 +71,7 @@ class Create extends RelationshipCreate ], true), 'Constraints option', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/String/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/String/Create.php index 17f60f61c1..8151b3e8da 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/String/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/String/Create.php @@ -69,7 +69,7 @@ class Create extends StringCreate ->param('encrypt', false, new Boolean(), 'Toggle encryption for the column. Encryption enhances security by not storing any plain text values in the database. However, encrypted columns cannot be queried.', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('plan') ->inject('authorization') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Text/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Text/Create.php index a8fde7d271..bffdc96001 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Text/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Text/Create.php @@ -60,7 +60,7 @@ class Create extends TextCreate ->param('encrypt', false, new Boolean(), 'Toggle encryption for the column. Encryption enhances security by not storing any plain text values in the database. However, encrypted columns cannot be queried.', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('plan') ->inject('authorization') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/URL/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/URL/Create.php index 19b33594b7..2edf4a62f6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/URL/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/URL/Create.php @@ -60,7 +60,7 @@ class Create extends URLCreate ->param('array', false, new Boolean(), 'Is column an array?', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Varchar/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Varchar/Create.php index 7595f16c45..307a1fd5e3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Varchar/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Columns/Varchar/Create.php @@ -63,7 +63,7 @@ class Create extends VarcharCreate ->param('encrypt', false, new Boolean(), 'Toggle encryption for the column. Encryption enhances security by not storing any plain text values in the database. However, encrypted columns cannot be queried.', true) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('plan') ->inject('authorization') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Delete.php index 97c5465fe3..3a6d6666f2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Delete.php @@ -55,7 +55,7 @@ class Delete extends CollectionDelete ->inject('response') ->inject('dbForProject') ->inject('getDatabasesDB') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Create.php index d377bed184..77496fea59 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Create.php @@ -65,7 +65,7 @@ class Create extends IndexCreate ->inject('response') ->inject('dbForProject') ->inject('getDatabasesDB') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Delete.php index ca7e4fc2da..6cd5cfe78f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Indexes/Delete.php @@ -60,7 +60,7 @@ class Delete extends IndexDelete ->param('key', '', fn (Database $dbForProject) => new Key(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Index Key.', false, ['dbForProject']) ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Delete.php index f1188868aa..6ee83b2530 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Delete.php @@ -54,7 +54,7 @@ class Delete extends CollectionDelete ->inject('response') ->inject('dbForProject') ->inject('getDatabasesDB') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/Create.php index a535dd5724..bba7ee0579 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/Create.php @@ -65,7 +65,7 @@ class Create extends IndexCreate ->inject('response') ->inject('dbForProject') ->inject('getDatabasesDB') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/Delete.php index 5c7fc47ee0..67e13dd26a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Indexes/Delete.php @@ -59,7 +59,7 @@ class Delete extends IndexDelete ->param('key', '', new Key(), 'Index Key.') ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('authorization') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Delete.php index c9d36904a9..a33eedccd5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Delete.php @@ -47,7 +47,7 @@ class Delete extends DatabaseDelete ->param('databaseId', '', new UID(), 'Database ID.') ->inject('response') ->inject('dbForProject') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('queueForEvents') ->inject('usage') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Workers/Databases.php b/src/Appwrite/Platform/Modules/Databases/Workers/Databases.php index 39902aea53..ee8494b382 100644 --- a/src/Appwrite/Platform/Modules/Databases/Workers/Databases.php +++ b/src/Appwrite/Platform/Modules/Databases/Workers/Databases.php @@ -2,6 +2,7 @@ namespace Appwrite\Platform\Modules\Databases\Workers; +use Appwrite\Event\Message\Database as DatabaseMessage; use Appwrite\Event\Realtime; use Exception; use Utopia\Console; @@ -60,10 +61,11 @@ class Databases extends Action throw new Exception('Missing payload'); } - $type = $payload['type']; - $document = new Document($payload['row'] ?? $payload['document'] ?? []); - $collection = new Document($payload['table'] ?? $payload['collection'] ?? []); - $database = new Document($payload['database'] ?? []); + $databaseMessage = DatabaseMessage::fromArray($payload); + $type = $databaseMessage->type; + $document = $databaseMessage->row ?? $databaseMessage->document ?? new Document(); + $collection = $databaseMessage->table ?? $databaseMessage->collection ?? new Document(); + $database = $databaseMessage->database ?? new Document(); /** * @var Database $dbForDatabases */ diff --git a/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Databases/Get.php b/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Databases/Get.php index 213bd8b36c..3bd42b64c6 100644 --- a/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Databases/Get.php +++ b/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Databases/Get.php @@ -2,7 +2,7 @@ namespace Appwrite\Platform\Modules\Health\Http\Health\Queue\Databases; -use Appwrite\Event\Database; +use Appwrite\Event\Publisher\Database; use Appwrite\Platform\Modules\Health\Http\Health\Queue\Base; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,6 +10,7 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response; use Utopia\Database\Document; +use Utopia\Queue\Queue; use Utopia\Validator\Integer; use Utopia\Validator\Text; @@ -44,15 +45,15 @@ class Get extends Base )) ->param('name', 'database_db_main', new Text(256), 'Queue name for which to check the queue size', true) ->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('response') ->callback($this->action(...)); } - public function action(string $name, int|string $threshold, Database $queueForDatabase, Response $response): void + public function action(string $name, int|string $threshold, Database $publisherForDatabase, Response $response): void { $threshold = (int) $threshold; - $size = $queueForDatabase->setQueue($name)->getSize(); + $size = $publisherForDatabase->getSize(queue: new Queue($name)); $this->assertQueueThreshold($size, $threshold); diff --git a/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Failed/Get.php b/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Failed/Get.php index 5aa29fcaba..d3b760d01b 100644 --- a/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Failed/Get.php +++ b/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Failed/Get.php @@ -2,11 +2,11 @@ namespace Appwrite\Platform\Modules\Health\Http\Health\Queue\Failed; -use Appwrite\Event\Database; use Appwrite\Event\Event; use Appwrite\Event\Publisher\Audit; use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Event\Publisher\Certificate; +use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Event\Publisher\Delete as DeletePublisher; use Appwrite\Event\Publisher\Func as FunctionPublisher; use Appwrite\Event\Publisher\Mail as MailPublisher; @@ -74,7 +74,7 @@ class Get extends Base ]), 'The name of the queue') ->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true) ->inject('response') - ->inject('queueForDatabase') + ->inject('publisherForDatabase') ->inject('publisherForDeletes') ->inject('publisherForAudits') ->inject('publisherForMails') @@ -94,7 +94,7 @@ class Get extends Base string $name, int|string $threshold, Response $response, - Database $queueForDatabase, + DatabasePublisher $publisherForDatabase, DeletePublisher $publisherForDeletes, Audit $publisherForAudits, MailPublisher $publisherForMails, @@ -111,7 +111,7 @@ class Get extends Base $threshold = (int) $threshold; $queue = match ($name) { - System::getEnv('_APP_DATABASE_QUEUE_NAME', Event::DATABASE_QUEUE_NAME) => $queueForDatabase, + System::getEnv('_APP_DATABASE_QUEUE_NAME', Event::DATABASE_QUEUE_NAME) => $publisherForDatabase, System::getEnv('_APP_DELETE_QUEUE_NAME', Event::DELETE_QUEUE_NAME) => $publisherForDeletes, System::getEnv('_APP_AUDITS_QUEUE_NAME', Event::AUDITS_QUEUE_NAME) => $publisherForAudits, System::getEnv('_APP_MAILS_QUEUE_NAME', Event::MAILS_QUEUE_NAME) => $publisherForMails, From 75587e629ee801c4a8088d715e26c58711635ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 15 May 2026 10:23:22 +0200 Subject: [PATCH 3/8] Improve quality of org scopes --- app/config/scopes/organization.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/config/scopes/organization.php b/app/config/scopes/organization.php index 228a1437f2..d74452f259 100644 --- a/app/config/scopes/organization.php +++ b/app/config/scopes/organization.php @@ -4,17 +4,23 @@ return [ "projects.read" => [ - "description" => 'Access to read organization\'s projects', + "description" => 'Access to read organization projects', + "category" => "Projects", ], "projects.write" => [ "description" => - "Access to create, update, and delete projects in organization", + "Access to create, update, and delete organization projects", + "category" => "Projects", ], "devKeys.read" => [ "description" => 'Access to read project\'s development keys', + "category" => "Other", + "deprecated" => true, ], "devKeys.write" => [ "description" => "Access to create, update, and delete project\'s development keys", + "category" => "Other", + "deprecated" => true, ], ]; From 8d8a0e883e2ff47451c8a0453849ddc06cd91ab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 15 May 2026 10:23:32 +0200 Subject: [PATCH 4/8] Add org scopes get console endpoint --- .../Http/Scopes/Organization/XList.php | 69 +++++++++++++++++++ .../Http/Scopes/{Key => Project}/XList.php | 2 +- .../Modules/Console/Services/Http.php | 4 +- 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 src/Appwrite/Platform/Modules/Console/Http/Scopes/Organization/XList.php rename src/Appwrite/Platform/Modules/Console/Http/Scopes/{Key => Project}/XList.php (96%) diff --git a/src/Appwrite/Platform/Modules/Console/Http/Scopes/Organization/XList.php b/src/Appwrite/Platform/Modules/Console/Http/Scopes/Organization/XList.php new file mode 100644 index 0000000000..4f88df6948 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Console/Http/Scopes/Organization/XList.php @@ -0,0 +1,69 @@ +setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) + ->setHttpPath('/v1/console/scopes/organization') + ->desc('List organization scopes') + ->groups(['api']) + ->label('scope', 'public') + ->label('sdk', new Method( + namespace: 'console', + group: 'console', + name: 'listOrganizationScopes', + description: 'List all scopes available for organization API keys, along with a description for each scope.', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: Response::STATUS_CODE_OK, + model: Response::MODEL_CONSOLE_KEY_SCOPE_LIST, + ) + ], + contentType: ContentType::JSON + )) + ->inject('response') + ->callback($this->action(...)); + } + + public function action(Response $response): void + { + $scopesConfig = Config::getParam('organizationScopes', []); + + $scopes = []; + foreach ($scopesConfig as $scopeId => $scope) { + $scopes[] = new Document([ + '$id' => $scopeId, + 'description' => $scope['description'] ?? '', + 'category' => $scope['category'] ?? '', + 'deprecated' => $scope['deprecated'] ?? false, + ]); + } + + $response->dynamic(new Document([ + 'total' => \count($scopes), + 'scopes' => $scopes, + ]), Response::MODEL_CONSOLE_KEY_SCOPE_LIST); + } +} diff --git a/src/Appwrite/Platform/Modules/Console/Http/Scopes/Key/XList.php b/src/Appwrite/Platform/Modules/Console/Http/Scopes/Project/XList.php similarity index 96% rename from src/Appwrite/Platform/Modules/Console/Http/Scopes/Key/XList.php rename to src/Appwrite/Platform/Modules/Console/Http/Scopes/Project/XList.php index d951e93886..3e6eceb26c 100644 --- a/src/Appwrite/Platform/Modules/Console/Http/Scopes/Key/XList.php +++ b/src/Appwrite/Platform/Modules/Console/Http/Scopes/Project/XList.php @@ -1,6 +1,6 @@ addAction(GetVariables::getName(), new GetVariables()); $this->addAction(ListOAuth2Providers::getName(), new ListOAuth2Providers()); $this->addAction(ListKeyScopes::getName(), new ListKeyScopes()); + $this->addAction(ListOrganizationScopes::getName(), new ListOrganizationScopes()); $this->addAction(CreateAssistantQuery::getName(), new CreateAssistantQuery()); $this->addAction(GetResourceAvailability::getName(), new GetResourceAvailability()); From e93a2c710105421e8b1d8be72b865baeddd0b841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 15 May 2026 10:23:40 +0200 Subject: [PATCH 5/8] Add tests for org scopes console get endpoint --- .../Console/ConsoleConsoleClientTest.php | 43 +++++++++++++++++++ .../Console/ConsoleCustomServerTest.php | 31 +++++++++++++ 2 files changed, 74 insertions(+) diff --git a/tests/e2e/Services/Console/ConsoleConsoleClientTest.php b/tests/e2e/Services/Console/ConsoleConsoleClientTest.php index c8f921f2ec..ccb7e8bdf7 100644 --- a/tests/e2e/Services/Console/ConsoleConsoleClientTest.php +++ b/tests/e2e/Services/Console/ConsoleConsoleClientTest.php @@ -175,4 +175,47 @@ class ConsoleConsoleClientTest extends Scope $this->assertNotNull($usersRead); $this->assertEquals('Access to read users', $usersRead['description']); } + + public function testListOrganizationScopes(): void + { + $response = $this->client->call(Client::METHOD_GET, '/console/scopes/organization', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertIsInt($response['body']['total']); + $this->assertIsArray($response['body']['scopes']); + $this->assertGreaterThan(0, $response['body']['total']); + $this->assertEquals($response['body']['total'], \count($response['body']['scopes'])); + + $scopeIds = \array_column($response['body']['scopes'], '$id'); + + // Well-known scopes must be present + $this->assertContains('projects.read', $scopeIds); + $this->assertContains('projects.write', $scopeIds); + + // Every scope has the expected shape + foreach ($response['body']['scopes'] as $scope) { + $this->assertArrayHasKey('$id', $scope); + $this->assertIsString($scope['$id']); + $this->assertNotEmpty($scope['$id']); + $this->assertArrayHasKey('description', $scope); + $this->assertIsString($scope['description']); + $this->assertNotEmpty($scope['description']); + $this->assertArrayHasKey('deprecated', $scope); + $this->assertIsBool($scope['deprecated']); + } + + // A specific scope has the expected description + $projectsRead = null; + foreach ($response['body']['scopes'] as $scope) { + if ($scope['$id'] === 'projects.read') { + $projectsRead = $scope; + break; + } + } + $this->assertNotNull($projectsRead); + $this->assertEquals('Access to read organization projects', $projectsRead['description']); + } } diff --git a/tests/e2e/Services/Console/ConsoleCustomServerTest.php b/tests/e2e/Services/Console/ConsoleCustomServerTest.php index f06011843f..e7a95fd357 100644 --- a/tests/e2e/Services/Console/ConsoleCustomServerTest.php +++ b/tests/e2e/Services/Console/ConsoleCustomServerTest.php @@ -74,4 +74,35 @@ class ConsoleCustomServerTest extends Scope $this->assertArrayHasKey('deprecated', $usersRead); $this->assertIsBool($usersRead['deprecated']); } + + public function testListOrganizationScopes(): void + { + // Public endpoint: must succeed without admin authentication. Drop the + // headers from getHeaders() and only pass project + content-type. + $response = $this->client->call(Client::METHOD_GET, '/console/scopes/organization', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertIsInt($response['body']['total']); + $this->assertIsArray($response['body']['scopes']); + $this->assertGreaterThan(0, $response['body']['total']); + + $scopeIds = \array_column($response['body']['scopes'], '$id'); + $this->assertContains('projects.read', $scopeIds); + + $projectsRead = null; + foreach ($response['body']['scopes'] as $scope) { + if ($scope['$id'] === 'projects.read') { + $projectsRead = $scope; + break; + } + } + $this->assertNotNull($projectsRead); + $this->assertIsString($projectsRead['description']); + $this->assertNotEmpty($projectsRead['description']); + $this->assertArrayHasKey('deprecated', $projectsRead); + $this->assertIsBool($projectsRead['deprecated']); + } } From e9b026647aef26ad5ebe3273a6d7108111b2fe2c Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 15 May 2026 13:57:10 +0530 Subject: [PATCH 6/8] chore: retrigger ci From bf3ac31157858d9f08f97d79974602bef61da7de Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 15 May 2026 13:59:10 +0530 Subject: [PATCH 7/8] chore: retrigger ci From 88e7fdbd9e9d7b4299c9c1e33152307d36b331fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 15 May 2026 10:55:13 +0200 Subject: [PATCH 8/8] Improve tests --- tests/e2e/Services/Console/ConsoleConsoleClientTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/e2e/Services/Console/ConsoleConsoleClientTest.php b/tests/e2e/Services/Console/ConsoleConsoleClientTest.php index ccb7e8bdf7..43daba470b 100644 --- a/tests/e2e/Services/Console/ConsoleConsoleClientTest.php +++ b/tests/e2e/Services/Console/ConsoleConsoleClientTest.php @@ -205,6 +205,8 @@ class ConsoleConsoleClientTest extends Scope $this->assertNotEmpty($scope['description']); $this->assertArrayHasKey('deprecated', $scope); $this->assertIsBool($scope['deprecated']); + $this->assertArrayHasKey('category', $scope); + $this->assertIsString($scope['category']); } // A specific scope has the expected description