diff --git a/bin/MigrationCLI.php b/bin/MigrationCLI.php index def3634..0c74a58 100644 --- a/bin/MigrationCLI.php +++ b/bin/MigrationCLI.php @@ -14,6 +14,10 @@ class MigrationCLI { protected Transfer $transfer; + protected Appwrite $source; + + protected DestinationsAppwrite $destination; + /** * Prints the current status of migrations as a table after wiping the screen */ @@ -24,10 +28,29 @@ public function drawFrame() $statusCounters = $this->transfer->getStatusCounters(); $mask = "| %15.15s | %-7.7s | %10.10s | %7.7s | %7.7s | %8.8s |\n"; - printf($mask, 'Resource', 'Pending', 'Processing', 'Skipped', 'Warning', 'Success'); - printf($mask, '-------------', '-------------', '-------------', '-------------', '-------------', '-------------'); + printf($mask, 'Resource', 'Pending', 'Processing', 'Skipped', 'Warning', 'Error', 'Success'); + printf($mask, '-------------', '-------------', '-------------', '-------------', '-------------', '-------------', '-------------'); foreach ($statusCounters as $resource => $data) { - printf($mask, $resource, $data['pending'], $data['processing'], $data['skip'], $data['warning'], $data['success']); + printf($mask, $resource, $data['pending'], $data['processing'], $data['skip'], $data['warning'], $data['error'], $data['success']); + } + + // Render Errors + $destErrors = $this->destination->getErrors(); + if (! empty($destErrors)) { + echo "\n\nDestination Errors:\n"; + foreach ($destErrors as $error) { + /** @var Utopia\Migration\Exception $error */ + echo $error->getResourceName().'['.$error->getResourceId().'] - '.$error->getMessage()."\n"; + } + } + + $sourceErrors = $this->source->getErrors(); + if (! empty($sourceErrors)) { + echo "\n\nSource Errors:\n"; + foreach ($sourceErrors as $error) { + /** @var Utopia\Migration\Exception $error */ + echo $error->getResourceType().'['.$error->getResourceId().'] - '.$error->getMessage()."\n"; + } } } @@ -39,7 +62,7 @@ public function start() /** * Initialise All Source Adapters */ - $source = new Appwrite( + $this->source = new Appwrite( $_ENV['SOURCE_APPWRITE_TEST_PROJECT'], $_ENV['SOURCE_APPWRITE_TEST_ENDPOINT'], $_ENV['SOURCE_APPWRITE_TEST_KEY'] @@ -47,7 +70,7 @@ public function start() // $source->report(); - $destination = new DestinationsAppwrite( + $this->destination = new DestinationsAppwrite( $_ENV['DESTINATION_APPWRITE_TEST_PROJECT'], $_ENV['DESTINATION_APPWRITE_TEST_ENDPOINT'], $_ENV['DESTINATION_APPWRITE_TEST_KEY'] @@ -57,15 +80,15 @@ public function start() * Initialise Transfer Class */ $this->transfer = new Transfer( - $source, - $destination + $this->source, + $this->destination ); /** * Run Transfer */ $this->transfer->run( - $source->getSupportedResources(), + $this->source->getSupportedResources(), function (array $resources) { $this->drawFrame(); } diff --git a/src/Migration/Destinations/Appwrite.php b/src/Migration/Destinations/Appwrite.php index 7db57d1..452cc36 100644 --- a/src/Migration/Destinations/Appwrite.php +++ b/src/Migration/Destinations/Appwrite.php @@ -238,10 +238,12 @@ protected function import(array $resources, callable $callback): void } else { $resource->setStatus(Resource::STATUS_ERROR, $e->getMessage()); $this->addError(new Exception( - resourceType: $resource->getGroup(), + resourceName: $resource->getName(), + resourceGroup: $resource->getGroup(), resourceId: $resource->getId(), message: $e->getMessage(), - code: $e->getCode() + code: $e->getCode(), + previous: $e )); } diff --git a/src/Migration/Exception.php b/src/Migration/Exception.php index d90f50c..46ecf52 100644 --- a/src/Migration/Exception.php +++ b/src/Migration/Exception.php @@ -4,21 +4,29 @@ class Exception extends \Exception { - public string $resourceType; + public string $resourceName; + + public string $resourceGroup; public string $resourceId; - public function __construct(string $resourceType, string $message, int $code = 0, ?\Throwable $previous = null, string $resourceId = '') + public function __construct(string $resourceName, string $resourceGroup, string $message, int $code = 0, ?\Throwable $previous = null, string $resourceId = '') { + $this->resourceName = $resourceName; $this->resourceId = $resourceId; - $this->resourceType = $resourceType; + $this->resourceGroup = $resourceGroup; parent::__construct($message, $code, $previous); } - public function getResourceType(): string + public function getResourceName(): string + { + return $this->resourceName; + } + + public function getResourceGroup(): string { - return $this->resourceType; + return $this->resourceGroup; } public function getResourceId(): string diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index 75a7bbb..00abd19 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -281,7 +281,10 @@ protected function exportGroupAuth(int $batchSize, array $resources) } catch (\Throwable $e) { $this->addError(new Exception( Resource::TYPE_USER, - $e->getMessage() + Transfer::GROUP_AUTH, + $e->getMessage(), + $e->getCode(), + $e )); } @@ -292,7 +295,10 @@ protected function exportGroupAuth(int $batchSize, array $resources) } catch (\Throwable $e) { $this->addError(new Exception( Resource::TYPE_TEAM, - $e->getMessage() + Transfer::GROUP_AUTH, + $e->getMessage(), + $e->getCode(), + $e )); } @@ -303,7 +309,10 @@ protected function exportGroupAuth(int $batchSize, array $resources) } catch (\Throwable $e) { $this->addError(new Exception( Resource::TYPE_MEMBERSHIP, - $e->getMessage() + Transfer::GROUP_AUTH, + $e->getMessage(), + $e->getCode(), + $e )); } } @@ -459,7 +468,10 @@ protected function exportGroupDatabases(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_DATABASE, - $e->getMessage() + Transfer::GROUP_DATABASES, + $e->getMessage(), + $e->getCode(), + $e ) ); } @@ -472,7 +484,10 @@ protected function exportGroupDatabases(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_COLLECTION, - $e->getMessage() + Transfer::GROUP_DATABASES, + $e->getMessage(), + $e->getCode(), + $e ) ); } @@ -485,7 +500,10 @@ protected function exportGroupDatabases(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_ATTRIBUTE, - $e->getMessage() + Transfer::GROUP_DATABASES, + $e->getMessage(), + $e->getCode(), + $e ) ); } @@ -498,7 +516,10 @@ protected function exportGroupDatabases(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_INDEX, - $e->getMessage() + Transfer::GROUP_DATABASES, + $e->getMessage(), + $e->getCode(), + $e ) ); } @@ -511,7 +532,10 @@ protected function exportGroupDatabases(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_DOCUMENT, - $e->getMessage() + Transfer::GROUP_DATABASES, + $e->getMessage(), + $e->getCode(), + $e ) ); } @@ -952,7 +976,10 @@ protected function exportGroupStorage(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_BUCKET, - $e->getMessage() + Transfer::GROUP_STORAGE, + $e->getMessage(), + $e->getCode(), + $e ) ); } @@ -965,7 +992,10 @@ protected function exportGroupStorage(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_FILE, - $e->getMessage() + Transfer::GROUP_STORAGE, + $e->getMessage(), + $e->getCode(), + $e ) ); } @@ -978,7 +1008,10 @@ protected function exportGroupStorage(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_BUCKET, - $e->getMessage() + Transfer::GROUP_STORAGE, + $e->getMessage(), + $e->getCode(), + $e ) ); } @@ -1052,7 +1085,8 @@ private function exportFiles(int $batchSize) )); } catch (\Throwable $e) { $this->addError(new Exception( - resourceType: Resource::TYPE_FILE, + resourceName: Resource::TYPE_FILE, + resourceGroup: Transfer::GROUP_STORAGE, message: $e->getMessage(), code: $e->getCode(), resourceId: $file['$id'] @@ -1116,7 +1150,10 @@ protected function exportGroupFunctions(int $batchSize, array $resources) } catch (\Throwable $e) { $this->addError(new Exception( Resource::TYPE_FUNCTION, - $e->getMessage() + Transfer::GROUP_FUNCTIONS, + $e->getMessage(), + $e->getCode(), + $e )); } @@ -1127,7 +1164,10 @@ protected function exportGroupFunctions(int $batchSize, array $resources) } catch (\Throwable $e) { $this->addError(new Exception( Resource::TYPE_DEPLOYMENT, - $e->getMessage() + Transfer::GROUP_FUNCTIONS, + $e->getMessage(), + $e->getCode(), + $e )); } } diff --git a/src/Migration/Sources/Firebase.php b/src/Migration/Sources/Firebase.php index 18536ff..97ef3e9 100644 --- a/src/Migration/Sources/Firebase.php +++ b/src/Migration/Sources/Firebase.php @@ -172,7 +172,10 @@ protected function exportGroupAuth(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_USER, - $e->getMessage() + Transfer::GROUP_AUTH, + $e->getMessage(), + $e->getCode(), + $e ) ); } @@ -258,7 +261,10 @@ protected function exportGroupDatabases(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_DATABASE, - $e->getMessage() + Transfer::GROUP_DATABASES, + $e->getMessage(), + $e->getCode(), + $e ) ); } @@ -271,7 +277,10 @@ protected function exportGroupDatabases(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_COLLECTION, - $e->getMessage() + Transfer::GROUP_DATABASES, + $e->getMessage(), + $e->getCode(), + $e ) ); } @@ -529,7 +538,10 @@ protected function exportGroupStorage(int $batchSize, array $resources) } catch (\Throwable $e) { $this->addError(new Exception( Resource::TYPE_BUCKET, - $e->getMessage() + Transfer::GROUP_STORAGE, + $e->getMessage(), + $e->getCode(), + $e )); } @@ -540,7 +552,10 @@ protected function exportGroupStorage(int $batchSize, array $resources) } catch (\Throwable $e) { $this->addError(new Exception( Resource::TYPE_FILE, - $e->getMessage() + Transfer::GROUP_STORAGE, + $e->getMessage(), + $e->getCode(), + $e )); } diff --git a/src/Migration/Sources/NHost.php b/src/Migration/Sources/NHost.php index 0b87f55..b1e6cf3 100644 --- a/src/Migration/Sources/NHost.php +++ b/src/Migration/Sources/NHost.php @@ -219,7 +219,10 @@ protected function exportGroupAuth(int $batchSize, array $resources) } catch (\Throwable $e) { $this->addError(new Exception( Resource::TYPE_USER, - $e->getMessage() + Transfer::GROUP_AUTH, + $e->getMessage(), + $e->getCode(), + $e )); } } @@ -274,7 +277,10 @@ protected function exportGroupDatabases(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_DATABASE, - $e->getMessage() + Transfer::GROUP_DATABASES, + $e->getMessage(), + $e->getCode(), + $e ) ); } @@ -287,7 +293,10 @@ protected function exportGroupDatabases(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_COLLECTION, - $e->getMessage() + Transfer::GROUP_DATABASES, + $e->getMessage(), + $e->getCode(), + $e ) ); } @@ -300,7 +309,10 @@ protected function exportGroupDatabases(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_ATTRIBUTE, - $e->getMessage() + Transfer::GROUP_DATABASES, + $e->getMessage(), + $e->getCode(), + $e ) ); } @@ -313,7 +325,10 @@ protected function exportGroupDatabases(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_DOCUMENT, - $e->getMessage() + Transfer::GROUP_DATABASES, + $e->getMessage(), + $e->getCode(), + $e ) ); } @@ -326,7 +341,10 @@ protected function exportGroupDatabases(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_INDEX, - $e->getMessage() + Transfer::GROUP_DATABASES, + $e->getMessage(), + $e->getCode(), + $e ) ); } @@ -599,7 +617,10 @@ protected function exportGroupStorage(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_BUCKET, - $e->getMessage() + Transfer::GROUP_STORAGE, + $e->getMessage(), + $e->getCode(), + $e ) ); } @@ -612,7 +633,10 @@ protected function exportGroupStorage(int $batchSize, array $resources) $this->addError( new Exception( Resource::TYPE_FILE, - $e->getMessage() + Transfer::GROUP_STORAGE, + $e->getMessage(), + $e->getCode(), + $e ) ); } diff --git a/src/Migration/Sources/Supabase.php b/src/Migration/Sources/Supabase.php index 375c3c6..14b23ec 100644 --- a/src/Migration/Sources/Supabase.php +++ b/src/Migration/Sources/Supabase.php @@ -355,7 +355,10 @@ protected function exportGroupAuth(int $batchSize, array $resources) } catch (\Throwable $e) { $this->addError(new Exception( Resource::TYPE_BUCKET, - $e->getMessage() + Transfer::GROUP_STORAGE, + $e->getMessage(), + $e->getCode(), + $e )); } } @@ -418,7 +421,10 @@ protected function exportGroupStorage(int $batchSize, array $resources) } catch (\Throwable $e) { $this->addError(new Exception( Resource::TYPE_BUCKET, - $e->getMessage() + Transfer::GROUP_STORAGE, + $e->getMessage(), + $e->getCode(), + $e )); } @@ -429,7 +435,10 @@ protected function exportGroupStorage(int $batchSize, array $resources) } catch (\Throwable $e) { $this->addError(new Exception( Resource::TYPE_BUCKET, - $e->getMessage() + Transfer::GROUP_STORAGE, + $e->getMessage(), + $e->getCode(), + $e )); } }