diff --git a/composer.lock b/composer.lock index 72b460ec52..653d1841d5 100644 --- a/composer.lock +++ b/composer.lock @@ -5276,16 +5276,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.13.1", + "version": "1.13.3", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "1720ddd719e16cf0db4eb1c6eca108031636d46c" + "reference": "faed855a7b5f4d4637717c2b3863e277116beb36" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/1720ddd719e16cf0db4eb1c6eca108031636d46c", - "reference": "1720ddd719e16cf0db4eb1c6eca108031636d46c", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/faed855a7b5f4d4637717c2b3863e277116beb36", + "reference": "faed855a7b5f4d4637717c2b3863e277116beb36", "shasum": "" }, "require": { @@ -5324,7 +5324,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.13.1" + "source": "https://github.com/myclabs/DeepCopy/tree/1.13.3" }, "funding": [ { @@ -5332,7 +5332,7 @@ "type": "tidelift" } ], - "time": "2025-04-29T12:36:36+00:00" + "time": "2025-07-05T12:25:42+00:00" }, { "name": "nikic/php-parser", diff --git a/docker-compose.yml b/docker-compose.yml index a01165d949..af6610daf4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -214,7 +214,7 @@ services: appwrite-console: <<: *x-logging container_name: appwrite-console - image: appwrite/console:6.1.2 + image: appwrite/console:6.1.12 restart: unless-stopped networks: - appwrite diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 25b3473829..295acec885 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -275,8 +275,7 @@ class Builds extends Action $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { - $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); - $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); + $resource = $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')])); } $queueForRealtime @@ -525,8 +524,7 @@ class Builds extends Action $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { - $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); - $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); + $resource = $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')])); } $queueForRealtime @@ -858,9 +856,7 @@ class Builds extends Action $adapter = $resource->getAttribute('adapter', ''); if (empty($adapter)) { - $resource->setAttribute('adapter', $detection->getName()); - $resource->setAttribute('fallbackFile', $detection->getFallbackFile() ?? ''); - $resource = $dbForProject->updateDocument('sites', $resource->getId(), $resource); + $resource = $dbForProject->updateDocument('sites', $resource->getId(), new Document(['adapter' => $detection->getName(), 'fallbackFile' => $detection->getFallbackFile() ?? ''])); $deployment->setAttribute('adapter', $detection->getName()); $deployment->setAttribute('fallbackFile', $detection->getFallbackFile() ?? ''); @@ -1062,8 +1058,7 @@ class Builds extends Action $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment); if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { - $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); - $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); + $resource = $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')])); } $queueForRealtime @@ -1077,14 +1072,38 @@ class Builds extends Action Console::success("Build id: $deploymentId created"); /** Set auto deploy */ + $activateBuild = false; if ($deployment->getAttribute('activate') === true) { - $resource->setAttribute('live', true); + // Check if current active deployment started later than this deployment + $resource = $dbForProject->getDocument($resource->getCollection(), $resource->getId()); + $currentActiveDeploymentId = $resource->getAttribute('deploymentId', ''); + if (!empty($currentActiveDeploymentId)) { + $currentActiveDeployment = $dbForProject->getDocument('deployments', $currentActiveDeploymentId); + if (!$currentActiveDeployment->isEmpty()) { + $currentActiveStartTime = $currentActiveDeployment->getCreatedAt(); + $deploymentStartTime = $deployment->getCreatedAt(); + + // Skip auto-activation if current active deployment started later than deployment that is being activated + if ($currentActiveStartTime < $deploymentStartTime) { + $activateBuild = true; + } else { + Console::info('Skipping auto-activation as current deployment is more recent'); + } + } + } else { + $activateBuild = true; + } + } + + if ($activateBuild) { switch ($resource->getCollection()) { case 'functions': - $resource->setAttribute('deploymentId', $deployment->getId()); - $resource->setAttribute('deploymentInternalId', $deployment->getSequence()); - $resource->setAttribute('deploymentCreatedAt', $deployment->getCreatedAt()); - $resource = $dbForProject->updateDocument('functions', $resource->getId(), $resource); + $resource = $dbForProject->updateDocument('functions', $resource->getId(), new Document([ + 'live' => true, + 'deploymentId' => $deployment->getId(), + 'deploymentInternalId' => $deployment->getSequence(), + 'deploymentCreatedAt' => $deployment->getCreatedAt(), + ])); $queries = [ Query::equal('projectInternalId', [$project->getSequence()]), @@ -1098,19 +1117,21 @@ class Builds extends Action $rulesUpdated = false; $dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment, &$rulesUpdated) { $rulesUpdated = true; - $rule = $rule - ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getSequence()); - $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); + $rule = $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ + 'deploymentId' => $deployment->getId(), + 'deploymentInternalId' => $deployment->getSequence(), + ])); }, $queries); break; case 'sites': - $resource->setAttribute('deploymentId', $deployment->getId()); - $resource->setAttribute('deploymentInternalId', $deployment->getSequence()); - $resource->setAttribute('deploymentScreenshotDark', $deployment->getAttribute('screenshotDark', '')); - $resource->setAttribute('deploymentScreenshotLight', $deployment->getAttribute('screenshotLight', '')); - $resource->setAttribute('deploymentCreatedAt', $deployment->getCreatedAt()); - $resource = $dbForProject->updateDocument('sites', $resource->getId(), $resource); + $resource = $dbForProject->updateDocument('sites', $resource->getId(), new Document([ + 'live' => true, + 'deploymentId' => $deployment->getId(), + 'deploymentInternalId' => $deployment->getSequence(), + 'deploymentScreenshotDark' => $deployment->getAttribute('screenshotDark', ''), + 'deploymentScreenshotLight' => $deployment->getAttribute('screenshotLight', ''), + 'deploymentCreatedAt' => $deployment->getCreatedAt(), + ])); $queries = [ Query::equal('projectInternalId', [$project->getSequence()]), Query::equal('type', ['deployment']), @@ -1121,10 +1142,10 @@ class Builds extends Action ]; $dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment) { - $rule = $rule - ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getSequence()); - $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); + $rule = $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ + 'deploymentId' => $deployment->getId(), + 'deploymentInternalId' => $deployment->getSequence(), + ])); }, $queries); break; @@ -1166,11 +1187,10 @@ class Builds extends Action 'region' => $project->getAttribute('region') ])); } catch (Duplicate $err) { - $rule = $dbForPlatform->getDocument('rules', $ruleId); - $rule = $rule - ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getSequence()); - $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); + $rule = $dbForPlatform->updateDocument('rules', $ruleId, new Document([ + 'deploymentId' => $deployment->getId(), + 'deploymentInternalId' => $deployment->getSequence(), + ])); } $queries = [ @@ -1183,10 +1203,10 @@ class Builds extends Action ]; $dbForPlatform->foreach('rules', function (Document $rule) use ($dbForPlatform, $deployment) { - $rule = $rule - ->setAttribute('deploymentId', $deployment->getId()) - ->setAttribute('deploymentInternalId', $deployment->getSequence()); - $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); + $rule = $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([ + 'deploymentId' => $deployment->getId(), + 'deploymentInternalId' => $deployment->getSequence(), + ])); }, $queries); } } @@ -1256,8 +1276,7 @@ class Builds extends Action $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment); if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) { - $resource = $resource->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); - $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), $resource); + $resource = $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')])); } $queueForRealtime