From 70395cfaccc2f633074f247315c522e82eb33c67 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Sat, 13 Dec 2025 23:43:51 +0530 Subject: [PATCH 1/5] added tableid and collectionid in increment and decrement --- .../Databases/Collections/Documents/Attribute/Decrement.php | 1 + .../Databases/Collections/Documents/Attribute/Increment.php | 1 + src/Appwrite/Utopia/Response/Model/Document.php | 2 +- tests/e2e/Services/Databases/Legacy/DatabasesBase.php | 2 ++ tests/e2e/Services/Databases/TablesDB/DatabasesBase.php | 2 ++ 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php index 38e7f8f231..a3a1ea6ce8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php @@ -177,6 +177,7 @@ class Decrement extends Action value: $value, min: $min ); + $document->setAttribute('$' . $this->getCollectionsEventsContext() . 'Id', $collectionId); } catch (ConflictException) { throw new Exception($this->getConflictException()); } catch (NotFoundException) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php index 10dadae824..157c5ef2af 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php @@ -177,6 +177,7 @@ class Increment extends Action value: $value, max: $max ); + $document->setAttribute('$' . $this->getCollectionsEventsContext() . 'Id', $collectionId); } catch (ConflictException) { throw new Exception($this->getConflictException()); } catch (NotFoundException) { diff --git a/src/Appwrite/Utopia/Response/Model/Document.php b/src/Appwrite/Utopia/Response/Model/Document.php index f9766c895c..c04cf817b7 100644 --- a/src/Appwrite/Utopia/Response/Model/Document.php +++ b/src/Appwrite/Utopia/Response/Model/Document.php @@ -82,7 +82,7 @@ class Document extends Any { $document->removeAttribute('$collection'); $document->removeAttribute('$tenant'); - + var_dump($document->getArrayCopy()); if (!$document->isEmpty()) { $document->setAttribute('$sequence', (int)$document->getAttribute('$sequence', 0)); } diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php index d43d183e5a..d1d2c9687d 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php @@ -6118,6 +6118,7 @@ trait DatabasesBase ])); $this->assertEquals(200, $inc['headers']['status-code']); $this->assertEquals(6, $inc['body']['count']); + $this->assertEquals($collectionId, $inc['body']['$collectionId']); // Verify count = 6 $get = $this->client->call(Client::METHOD_GET, "/databases/$databaseId/collections/$collectionId/documents/$docId", array_merge([ @@ -6229,6 +6230,7 @@ trait DatabasesBase ])); $this->assertEquals(200, $dec['headers']['status-code']); $this->assertEquals(9, $dec['body']['count']); + $this->assertEquals($collectionId, $dec['body']['$collectionId']); $get = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $documentId, array_merge([ 'content-type' => 'application/json', diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php index e74431c779..ba111e5923 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php @@ -7760,6 +7760,7 @@ trait DatabasesBase 'x-appwrite-project' => $this->getProject()['$id'], ])); $this->assertEquals(200, $inc['headers']['status-code']); + $this->assertEquals($tableId, $inc['body']['$tableId']); $this->assertEquals(6, $inc['body']['count']); // Verify count = 6 @@ -7872,6 +7873,7 @@ trait DatabasesBase ])); $this->assertEquals(200, $dec['headers']['status-code']); $this->assertEquals(9, $dec['body']['count']); + $this->assertEquals($tableId, $dec['body']['$tableId']); $get = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows/' . $rowId, array_merge([ 'content-type' => 'application/json', From e4e6c84362a8fd76123c3ea249fc18cf6a562dea Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Sat, 13 Dec 2025 23:45:57 +0530 Subject: [PATCH 2/5] linting --- src/Appwrite/Utopia/Response/Model/Document.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Response/Model/Document.php b/src/Appwrite/Utopia/Response/Model/Document.php index c04cf817b7..f9766c895c 100644 --- a/src/Appwrite/Utopia/Response/Model/Document.php +++ b/src/Appwrite/Utopia/Response/Model/Document.php @@ -82,7 +82,7 @@ class Document extends Any { $document->removeAttribute('$collection'); $document->removeAttribute('$tenant'); - var_dump($document->getArrayCopy()); + if (!$document->isEmpty()) { $document->setAttribute('$sequence', (int)$document->getAttribute('$sequence', 0)); } From 4b58e1a85e86278386084d6aa4e671beec25c650 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Mon, 15 Dec 2025 16:55:48 +0000 Subject: [PATCH 3/5] revert: backups endpoints --- app/controllers/shared/api.php | 1 - src/Appwrite/Platform/Workers/Migrations.php | 10 +++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 8467468ed6..83b56f626a 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -628,7 +628,6 @@ App::init() $queueForFunctions->setPlatform($platform); $queueForBuilds->setPlatform($platform); $queueForMails->setPlatform($platform); - $queueForMigrations->setPlatform($platform); // Clone the queues, to prevent events triggered by the database listener // from overwriting the events that are supposed to be triggered in the shutdown hook. diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index a10ddc4904..e7b12c5d9d 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -52,8 +52,6 @@ class Migrations extends Action protected array $plan; - protected array $platform; - /** * @var array */ @@ -108,7 +106,6 @@ class Migrations extends Action $this->deviceForMigrations = $deviceForMigrations; $this->deviceForFiles = $deviceForFiles; $this->plan = $plan; - $this->platform = $payload['platform'] ?? []; if (empty($payload)) { throw new Exception('Missing payload'); @@ -144,7 +141,6 @@ class Migrations extends Action $credentials = $migration->getAttribute('credentials'); $migrationOptions = $migration->getAttribute('options'); $dataSource = Appwrite::SOURCE_API; - $endpoint = $this->platform['endpoint'] ?: ($credentials['endpoint'] ?? 'http://appwrite.test/v1'); $database = null; $queries = []; @@ -178,7 +174,7 @@ class Migrations extends Action ), SourceAppwrite::getName() => new SourceAppwrite( $credentials['projectId'], - $endpoint, + $credentials['endpoint'] === 'http://localhost/v1' ? 'http://appwrite/v1' : $credentials['endpoint'], $credentials['apiKey'], $dataSource, $database, @@ -209,7 +205,7 @@ class Migrations extends Action return match ($destination) { DestinationAppwrite::getName() => new DestinationAppwrite( $this->project->getId(), - $this->platform['endpoint'], + 'http://appwrite/v1', $apiKey, $this->dbForProject, Config::getParam('collections', [])['databases']['collections'], @@ -313,7 +309,7 @@ class Migrations extends Action ) { $credentials = $migration->getAttribute('credentials', []); $credentials['projectId'] = $credentials['projectId'] ?? $project->getId(); - $credentials['endpoint'] = $credentials['endpoint'] ?? $this->platform['endpoint']; + $credentials['endpoint'] = $credentials['endpoint'] ?? 'http://appwrite/v1'; $credentials['apiKey'] = $credentials['apiKey'] ?? $tempAPIKey; $migration->setAttribute('credentials', $credentials); } From e931938b7855d59d8d24704f7d457b17aeb432ea Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Mon, 15 Dec 2025 18:01:30 +0000 Subject: [PATCH 4/5] revert: backups endpoints --- docker-compose.yml | 1 + src/Appwrite/Platform/Workers/Migrations.php | 22 +++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 80fb99c0fd..f18bb747b8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -737,6 +737,7 @@ services: - _APP_MIGRATIONS_FIREBASE_CLIENT_ID - _APP_MIGRATIONS_FIREBASE_CLIENT_SECRET - _APP_DATABASE_SHARED_TABLES + - _APP_OPTIONS_FORCE_HTTPS appwrite-task-maintenance: entrypoint: maintenance diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index e7b12c5d9d..69c78d9620 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -144,6 +144,12 @@ class Migrations extends Action $database = null; $queries = []; + if ($credentials['endpoint'] === 'http://localhost/v1') { + $platform = Config::getParam('platform', []); + $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https'; + $credentials['endpoint'] = $protocol . '://' . $platform['apiHostname'] . '/v1'; + } + if ($source === Appwrite::getName() && $destination === DestinationCSV::getName()) { $dataSource = Appwrite::SOURCE_DATABASE; $database = $this->dbForProject; @@ -174,7 +180,7 @@ class Migrations extends Action ), SourceAppwrite::getName() => new SourceAppwrite( $credentials['projectId'], - $credentials['endpoint'] === 'http://localhost/v1' ? 'http://appwrite/v1' : $credentials['endpoint'], + $credentials['endpoint'], $credentials['apiKey'], $dataSource, $database, @@ -202,10 +208,13 @@ class Migrations extends Action $destination = $migration->getAttribute('destination'); $options = $migration->getAttribute('options', []); + $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https'; + $platform = Config::getParam('platform', []); + return match ($destination) { DestinationAppwrite::getName() => new DestinationAppwrite( $this->project->getId(), - 'http://appwrite/v1', + $protocol . '://' . $platform['apiHostname'] . '/v1', $apiKey, $this->dbForProject, Config::getParam('collections', [])['databases']['collections'], @@ -302,6 +311,8 @@ class Migrations extends Action $transfer = $source = $destination = null; + + try { if ( $migration->getAttribute('source') === SourceAppwrite::getName() && @@ -309,8 +320,13 @@ class Migrations extends Action ) { $credentials = $migration->getAttribute('credentials', []); $credentials['projectId'] = $credentials['projectId'] ?? $project->getId(); - $credentials['endpoint'] = $credentials['endpoint'] ?? 'http://appwrite/v1'; $credentials['apiKey'] = $credentials['apiKey'] ?? $tempAPIKey; + + if (empty($credentials['endpoint'])) { + $platform = Config::getParam('platform', []); + $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https'; + $credentials['endpoint'] = $protocol . '://' . $platform['apiHostname'] . '/v1'; + } $migration->setAttribute('credentials', $credentials); } From c7fd31285d0f9eba27f416c5afe739bfd85c2c41 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 16 Dec 2025 10:36:45 +0530 Subject: [PATCH 5/5] chore: lazy init sms adapter + late static binding --- src/Appwrite/Event/Database.php | 2 +- src/Appwrite/Event/Event.php | 28 ++++++++++----------- src/Appwrite/Event/Messaging.php | 13 ---------- src/Appwrite/Platform/Workers/Messaging.php | 7 +++--- 4 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/Appwrite/Event/Database.php b/src/Appwrite/Event/Database.php index 8e7f6b7625..eac30ac07e 100644 --- a/src/Appwrite/Event/Database.php +++ b/src/Appwrite/Event/Database.php @@ -161,7 +161,7 @@ class Database extends Event return $this->document; } - public function setProject(Document $project): self + public function setProject(Document $project): static { $database = $project->getAttribute('database'); if (!empty($database)) { diff --git a/src/Appwrite/Event/Event.php b/src/Appwrite/Event/Event.php index f8fb012075..c7bb22f715 100644 --- a/src/Appwrite/Event/Event.php +++ b/src/Appwrite/Event/Event.php @@ -92,9 +92,9 @@ class Event * Set queue used for this event. * * @param string $queue - * @return Event + * @return static */ - public function setQueue(string $queue): self + public function setQueue(string $queue): static { $this->queue = $queue; @@ -114,9 +114,9 @@ class Event /** * Set event name used for this event. * @param string $event - * @return Event + * @return static */ - public function setEvent(string $event): self + public function setEvent(string $event): static { $this->event = $event; @@ -137,9 +137,9 @@ class Event * Set project for this event. * * @param Document $project - * @return self + * @return static */ - public function setProject(Document $project): self + public function setProject(Document $project): static { $this->project = $project; return $this; @@ -159,9 +159,9 @@ class Event * Set platform for this event. * * @param array $platform - * @return self + * @return static */ - public function setPlatform(array $platform): self + public function setPlatform(array $platform): static { $this->platform = $platform; return $this; @@ -181,9 +181,9 @@ class Event * Set user for this event. * * @param Document $user - * @return self + * @return static */ - public function setUser(Document $user): self + public function setUser(Document $user): static { $this->user = $user; @@ -193,9 +193,9 @@ class Event /** * Set user ID for this event. * - * @return self + * @return static */ - public function setUserId(string $userId): self + public function setUserId(string $userId): static { $this->userId = $userId; @@ -225,9 +225,9 @@ class Event * * @param array $payload * @param array $sensitive - * @return self + * @return static */ - public function setPayload(array $payload, array $sensitive = []): self + public function setPayload(array $payload, array $sensitive = []): static { $this->payload = $payload; diff --git a/src/Appwrite/Event/Messaging.php b/src/Appwrite/Event/Messaging.php index 3ddbac1040..f4c72c7d72 100644 --- a/src/Appwrite/Event/Messaging.php +++ b/src/Appwrite/Event/Messaging.php @@ -161,19 +161,6 @@ class Messaging extends Event return $this->scheduledAt; } - /** - * Set project for this event. - * - * @param Document $project - * @return self - */ - public function setProject(Document $project): self - { - $this->project = $project; - - return $this; - } - /** * Prepare the payload for the event * diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index 64224a9770..ae94c7580d 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -62,9 +62,6 @@ class Messaging extends Action */ public function __construct() { - - $this->adapter = $this->createInternalSMSAdapter(); - $this ->desc('Messaging worker') ->inject('message') @@ -390,6 +387,10 @@ class Messaging extends Action private function sendInternalSMSMessage(Document $message, Document $project, array $recipients, Log $log): void { + if ($this->adapter === null) { + $this->adapter = $this->createInternalSMSAdapter(); + } + if ($this->adapter === null) { Console::warning('Skipped SMS processing. SMS adapter is not set.'); return;