From a3722f53a578905d20b5b5c207d33217d8f44a81 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Sat, 17 May 2025 01:39:25 +1200 Subject: [PATCH] Fix getting function for rule --- src/Appwrite/Migration/Migration.php | 13 ++++++++++++- src/Appwrite/Migration/Version/V23.php | 17 ++++++++--------- src/Appwrite/Platform/Tasks/Migrate.php | 4 ++-- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index 5199368376..ffd2707097 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -28,6 +28,11 @@ abstract class Migration protected Database $dbForPlatform; + /** + * @var callable(Document): Database + */ + protected mixed $getProjectDB; + protected PDO $pdo; /** @@ -115,11 +120,17 @@ abstract class Migration * @param Database $dbForPlatform * @return self */ - public function setProject(Document $project, Database $dbForProject, Database $dbForPlatform): self + public function setProject( + Document $project, + Database $dbForProject, + Database $dbForPlatform, + ?callable $getProjectDB = null + ): self { $this->project = $project; $this->dbForProject = $dbForProject; $this->dbForPlatform = $dbForPlatform; + $this->getProjectDB = $getProjectDB; return $this; } diff --git a/src/Appwrite/Migration/Version/V23.php b/src/Appwrite/Migration/Version/V23.php index f3b5746c89..582b5fc36b 100644 --- a/src/Appwrite/Migration/Version/V23.php +++ b/src/Appwrite/Migration/Version/V23.php @@ -348,16 +348,15 @@ class V23 extends Migration ->setAttribute('search', \implode(' ', [$document->getId(), $document->getAttribute('domain', '')])); if ($deploymentResourceType === 'function') { - if ($this->project->getInternalId() !== 'console') { - $function = $this->dbForProject->getDocument('functions', $resourceId); + $project = $this->dbForProject->getDocument('projects', $document->getAttribute('projectId')); + $dbForOwnerProject = ($this->getProjectDB)($project); + $function = $dbForOwnerProject->getDocument('functions', $resourceId); + $deploymentId = $function->getAttribute('deployment', $function->getAttribute('deploymentId', $document->getAttribute('deploymentId'))); + $deploymentInternalId = $function->getAttribute('deploymentInternalId', $document->getAttribute('deploymentInternalId', '')); - $deploymentId = $function->getAttribute('deployment', $document->getAttribute('deploymentId', '')); - $deploymentInternalId = $function->getAttribute('deploymentInternalId', $document->getAttribute('deploymentInternalId', '')); - - $document - ->setAttribute('deploymentId', $deploymentId) - ->setAttribute('deploymentInternalId', $deploymentInternalId); - } + $document + ->setAttribute('deploymentId', $deploymentId) + ->setAttribute('deploymentInternalId', $deploymentInternalId); } break; case 'variables': diff --git a/src/Appwrite/Platform/Tasks/Migrate.php b/src/Appwrite/Platform/Tasks/Migrate.php index 6aa1f0da00..5d5cb2a407 100644 --- a/src/Appwrite/Platform/Tasks/Migrate.php +++ b/src/Appwrite/Platform/Tasks/Migrate.php @@ -74,7 +74,7 @@ class Migrate extends Action try { $migration - ->setProject($project, $dbForProject, $dbForPlatform) + ->setProject($project, $dbForProject, $dbForPlatform, $getProjectDB) ->setPDO($register->get('db', true)) ->execute(); } catch (\Throwable $th) { @@ -89,7 +89,7 @@ class Migrate extends Action try { $migration - ->setProject($console, $getProjectDB($console), $dbForPlatform) + ->setProject($console, $getProjectDB($console), $dbForPlatform, $getProjectDB) ->setPDO($register->get('db', true)) ->execute(); } catch (\Throwable $th) {