Repository: appwrite/appwrite
File: src/Appwrite/Platform/Modules/Functions/Workers/Builds.php (PHP)

Code before:
                        ->trigger();
                } catch (\Throwable $th) {
                    Console::warning("Screenshot failed to generate:");
                    Console::warning($th->getMessage());
                    Console::warning($th->getTraceAsString());

                    $logs = $deployment->getAttribute('buildLogs', '');
                    $date = \date('H:i:s');
                    $logs .= "[90m[$date] [90m[[0mappwrite[90m][33m Screenshot capturing failed. Deployment will continue. [0m\n";

                    $deployment->setAttribute('buildLogs', $logs);
                    $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment);
                }
            }

            $logs = $deployment->getAttribute('buildLogs', '');
            $date = \date('H:i:s');
            $logs .= "[90m[$date] [90m[[0mappwrite[90m][32m Deployment finished. [0m\n";
            $deployment->setAttribute('buildLogs', $logs);

            /** Update the status */
            $deployment->setAttribute('status', 'ready');
            $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment);

            if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) {
                $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')]));
            }

            $queueForRealtime
                ->setPayload($deployment->getArrayCopy())
                ->trigger();

            if ($isVcsEnabled) {
                $this->runGitAction('ready', $github, $providerCommitHash, $owner, $repositoryName, $project, $resource, $deployment->getId(), $dbForProject, $dbForPlatform);
            }

            Console::success("Build id: $deploymentId created");

            /** Set auto deploy */
            $activateBuild = true;
            if ($deployment->getAttribute('activate') === 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->getAttribute('buildStartedAt', '');
                        $deploymentStartTime = $deployment->getAttribute('buildStartedAt', '');

                        // Skip auto-activation if current active deployment started later than deployment that is being activated

Review comment (suggestion):
```suggestion
                $resource = $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')]));
```

Code after:
                        ->trigger();
                } catch (\Throwable $th) {
                    Console::warning("Screenshot failed to generate:");
                    Console::warning($th->getMessage());
                    Console::warning($th->getTraceAsString());

                    $logs = $deployment->getAttribute('buildLogs', '');
                    $date = \date('H:i:s');
                    $logs .= "[90m[$date] [90m[[0mappwrite[90m][33m Screenshot capturing failed. Deployment will continue. [0m\n";

                    $deployment->setAttribute('buildLogs', $logs);
                    $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment);
                }
            }

            $logs = $deployment->getAttribute('buildLogs', '');
            $date = \date('H:i:s');
            $logs .= "[90m[$date] [90m[[0mappwrite[90m][32m Deployment finished. [0m\n";
            $deployment->setAttribute('buildLogs', $logs);

            /** Update the status */
            $deployment->setAttribute('status', 'ready');
            $deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment);

            if ($deployment->getSequence() === $resource->getAttribute('latestDeploymentInternalId', '')) {
                $resource = $dbForProject->updateDocument($resource->getCollection(), $resource->getId(), new Document(['latestDeploymentStatus' => $deployment->getAttribute('status', '')]));
            }

            $queueForRealtime
                ->setPayload($deployment->getArrayCopy())
                ->trigger();

            if ($isVcsEnabled) {
                $this->runGitAction('ready', $github, $providerCommitHash, $owner, $repositoryName, $project, $resource, $deployment->getId(), $dbForProject, $dbForPlatform);
            }

            Console::success("Build id: $deploymentId created");

            /** Set auto deploy */
            $activateBuild = false;
            if ($deployment->getAttribute('activate') === 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