From aacab8fcf107e72c4491be14f66502f943984ced Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 28 Jun 2026 06:27:02 +0000 Subject: [PATCH] feat(projects): track template & duplicate deployment onboarding via the API hook Add functions/sites createTemplateDeployment and createDuplicateDeployment to the onboarding config so the existing api.php shutdown hook marks them in the API request context (which reaches the central console DB), instead of the regional build worker. Reverts the build-worker write and the Onboarding helper. --- app/config/onboarding.php | 20 +++--- app/init/constants.php | 1 - .../Modules/Functions/Workers/Builds.php | 62 ------------------- 3 files changed, 10 insertions(+), 73 deletions(-) diff --git a/app/config/onboarding.php b/app/config/onboarding.php index 5b73328e25..6ac29b25ee 100644 --- a/app/config/onboarding.php +++ b/app/config/onboarding.php @@ -40,11 +40,11 @@ return [ // Functions 'functions.create' => true, - // One key per deployment creation type (deployment `type` attribute); - // OR them in the UI for a single "created a deployment" milestone. - 'functions.createManualDeployment' => true, - 'functions.createCliDeployment' => true, - 'functions.createVcsDeployment' => true, + // One key per deployment-creation SDK method; OR them in the UI for a + // single "created a deployment" milestone. + 'functions.createDeployment' => true, + 'functions.createTemplateDeployment' => true, + 'functions.createDuplicateDeployment' => true, 'functions.updateFunctionDeployment' => true, // Messaging @@ -67,10 +67,10 @@ return [ // Sites 'sites.create' => true, - // One key per deployment creation type (deployment `type` attribute); - // OR them in the UI for a single "created a deployment" milestone. - 'sites.createManualDeployment' => true, - 'sites.createCliDeployment' => true, - 'sites.createVcsDeployment' => true, + // One key per deployment-creation SDK method; OR them in the UI for a + // single "created a deployment" milestone. + 'sites.createDeployment' => true, + 'sites.createTemplateDeployment' => true, + 'sites.createDuplicateDeployment' => true, 'sites.updateSiteDeployment' => true, ]; diff --git a/app/init/constants.php b/app/init/constants.php index 62819d601b..9efb6e3222 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -171,7 +171,6 @@ const ACTOR_TYPE_GUEST = 'guest'; const ACTOR_TYPE_KEY_PROJECT = 'keyProject'; const ACTOR_TYPE_KEY_ACCOUNT = 'keyAccount'; const ACTOR_TYPE_KEY_ORGANIZATION = 'keyOrganization'; -const ACTOR_TYPE_SYSTEM = 'system'; /** * Project onboarding stage status (stored per SDK method key under project.onboarding JSON). diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 0ddb14aef1..d0806ccadf 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1039,68 +1039,6 @@ class Builds extends Action Span::add('build.activated', true); } - /** - * Mark deployment onboarding stages. Done here (not via the HTTP sdk - * label) so every creation path - manual upload, CLI, template, - * duplicate and VCS - and the worker-driven activation are covered. - * The create stage is keyed by the deployment `type` so each type - * has its own stage (OR them in the UI for a single milestone). - */ - $collection = $resource->getCollection(); - $createStage = match ($collection) { - 'functions' => match ($deployment->getAttribute('type')) { - 'manual' => 'functions.createManualDeployment', - 'cli' => 'functions.createCliDeployment', - 'vcs' => 'functions.createVcsDeployment', - default => null, - }, - 'sites' => match ($deployment->getAttribute('type')) { - 'manual' => 'sites.createManualDeployment', - 'cli' => 'sites.createCliDeployment', - 'vcs' => 'sites.createVcsDeployment', - default => null, - }, - default => null, - }; - $activateStage = match ($collection) { - 'functions' => 'functions.updateFunctionDeployment', - 'sites' => 'sites.updateSiteDeployment', - default => null, - }; - - $stages = []; - if ($createStage !== null) { - $stages[] = $createStage; - } - if ($activateBuild && $activateStage !== null) { - $stages[] = $activateStage; - } - - if ($stages !== []) { - // Fetch the project fresh and only set stages that aren't already - // recorded, so a stage skipped or completed via the API while the - // build was running is left untouched (??= respects it). - $onboarding = $dbForPlatform->getDocument('projects', $project->getId())->getAttribute('onboarding', []); - if (! \is_array($onboarding)) { - $onboarding = []; - } - - foreach ($stages as $stage) { - $onboarding[$stage] ??= [ - 'status' => ONBOARDING_STATUS_COMPLETED, - 'at' => DateTime::now(), - 'actorType' => ACTOR_TYPE_SYSTEM, - ]; - } - - try { - $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ - 'onboarding' => $onboarding, - ])); - } catch (\Throwable) { - } - } - $resource = $this->updateLatestDeployment($dbForProject, $resource); $this->afterDeploymentSuccess(