From 41beb8af9cc7e424c0965e1a1d470c78ffd56dfa Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 8 Aug 2024 15:14:43 +0300 Subject: [PATCH] credentials --- src/Appwrite/Platform/Workers/Migrations.php | 24 ++++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 250f82bcec..74bca22206 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -126,7 +126,7 @@ class Migrations extends Action ), SourceAppwrite::getName() => new SourceAppwrite( $credentials['projectId'], - str_starts_with($credentials['endpoint'], 'http://localhost/v1') ? 'http://appwrite/v1' : $credentials['endpoint'], + $credentials['endpoint'], $credentials['apiKey'] ), default => throw new \Exception('Invalid source type'), @@ -136,14 +136,15 @@ class Migrations extends Action /** * @throws Exception */ - protected function processDestination(Document $migration, array $credentials): Destination + protected function processDestination(Document $migration): Destination { $destination = $migration->getAttribute('destination'); + $credentials = $migration->getAttribute('credentials'); return match ($destination) { DestinationAppwrite::getName() => new DestinationAppwrite( $credentials['projectId'], - str_starts_with($credentials['endpoint'], 'http://localhost/v1') ? 'http://appwrite/v1' : $credentials['endpoint'], + $credentials['endpoint'], $credentials['apiKey'], $this->dbForProject, Config::getParam('collections', [])['databases']['collections'], @@ -277,16 +278,19 @@ class Migrations extends Action $log->addTag('type', $migration->getAttribute('source')); - $source = $this->processSource($migration); - - $destination = $this->processDestination( - $migration, - [ + if ( + $migration->getAttribute('source') === SourceAppwrite::getName() || + $migration->getAttribute('destination') === DestinationAppwrite::getName() + ) { + $migration->setAttribute('credentials', [ 'projectId' => $projectDocument->getId(), 'endpoint' => 'http://appwrite/v1', 'apiKey' => $tempAPIKey['secret'], - ] - ); + ]); + } + + $source = $this->processSource($migration); + $destination = $this->processDestination($migration); $source->report();