From acfd6633a22ec2f30df33aa6efd95611d4800cd0 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 28 Mar 2024 14:36:44 +0200 Subject: [PATCH 1/9] non integer errors --- src/Appwrite/Extend/Exception.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 7d56f5a384..f96057bc5b 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -296,11 +296,17 @@ class Exception extends \Exception protected array $errors = []; protected bool $publish; - public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $message = null, int $code = null, \Throwable $previous = null) + public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $message = null, $code = null, \Throwable $previous = null) { $this->errors = Config::getParam('errors'); $this->type = $type; $this->code = $code ?? $this->errors[$type]['code']; + + // todo: Handle better PDOExceptions or string errors + if(is_string($this->code)) { + $this->code = 500; + } + $this->message = $message ?? $this->errors[$type]['description']; $this->publish = $this->errors[$type]['publish'] ?? ($this->code >= 500); From c7f2de6500b83a2a89633e229fb702190157bdd1 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 30 Apr 2024 12:25:12 +1200 Subject: [PATCH 2/9] Update src/Appwrite/Extend/Exception.php --- src/Appwrite/Extend/Exception.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index f96057bc5b..458a89dece 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -303,7 +303,7 @@ class Exception extends \Exception $this->code = $code ?? $this->errors[$type]['code']; // todo: Handle better PDOExceptions or string errors - if(is_string($this->code)) { + if(\is_string($this->code) && !\is_numeric($this->code)) { $this->code = 500; } From e6b6e4e54e7b3ef3fbd9b9580d978ce1d7318b9a Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 30 Apr 2024 12:25:29 +1200 Subject: [PATCH 3/9] Update src/Appwrite/Extend/Exception.php --- src/Appwrite/Extend/Exception.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 458a89dece..6f89a1d65d 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -302,7 +302,6 @@ class Exception extends \Exception $this->type = $type; $this->code = $code ?? $this->errors[$type]['code']; - // todo: Handle better PDOExceptions or string errors if(\is_string($this->code) && !\is_numeric($this->code)) { $this->code = 500; } From 9bf13a24005402b7f8c3d43393a06f19c4c9f595 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 30 Apr 2024 12:28:29 +1200 Subject: [PATCH 4/9] Update src/Appwrite/Extend/Exception.php --- src/Appwrite/Extend/Exception.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 6f89a1d65d..b5e338f1b0 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -302,8 +302,12 @@ class Exception extends \Exception $this->type = $type; $this->code = $code ?? $this->errors[$type]['code']; - if(\is_string($this->code) && !\is_numeric($this->code)) { - $this->code = 500; + if(\is_string($this->code)) { + if (\is_numeric($this->code)) { + $this->code = (int) $this->code; + } else { + $this->code = 500; + } } $this->message = $message ?? $this->errors[$type]['description']; From 3c3e066bce4549622a62f7caa415784e2e9b4548 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 30 Apr 2024 12:30:35 +1200 Subject: [PATCH 5/9] Update src/Appwrite/Extend/Exception.php --- src/Appwrite/Extend/Exception.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index b5e338f1b0..851c19a944 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -296,7 +296,7 @@ class Exception extends \Exception protected array $errors = []; protected bool $publish; - public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $message = null, $code = null, \Throwable $previous = null) + public function __construct(string $type = Exception::GENERAL_UNKNOWN, string $message = null, int|string $code = null, \Throwable $previous = null) { $this->errors = Config::getParam('errors'); $this->type = $type; From 77e3dec6ed093860b21a8da429d3aba621c5d53f Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Thu, 2 May 2024 01:31:31 +0900 Subject: [PATCH 6/9] Update Migrations.php --- src/Appwrite/Platform/Workers/Migrations.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 7bbfcfbce2..6959406cc0 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -85,6 +85,7 @@ class Migrations extends Action return; } + $log->addTag('migrationId', $migration->getId()); $log->addTag('projectId', $project->getId()); $this->processMigration($project, $migration, $log); @@ -256,6 +257,7 @@ class Migrations extends Action $migrationDocument = $this->dbForProject->getDocument('migrations', $migration->getId()); $migrationDocument->setAttribute('stage', 'processing'); $migrationDocument->setAttribute('status', 'processing'); + $log->addTag('stage', 'processing'); $this->updateMigrationDocument($migrationDocument, $projectDocument); $log->addTag('type', $migrationDocument->getAttribute('source')); @@ -277,6 +279,7 @@ class Migrations extends Action /** Start Transfer */ $migrationDocument->setAttribute('stage', 'migrating'); + $log->addTag('stage', 'migrating'); $this->updateMigrationDocument($migrationDocument, $projectDocument); $transfer->run($migrationDocument->getAttribute('resources'), function () use ($migrationDocument, $transfer, $projectDocument) { $migrationDocument->setAttribute('resourceData', json_encode($transfer->getCache())); @@ -291,6 +294,7 @@ class Migrations extends Action if (!empty($sourceErrors) || !empty($destinationErrors)) { $migrationDocument->setAttribute('status', 'failed'); $migrationDocument->setAttribute('stage', 'finished'); + $log->addTag('stage', 'finished'); $errorMessages = []; foreach ($sourceErrors as $error) { @@ -303,9 +307,8 @@ class Migrations extends Action } $migrationDocument->setAttribute('errors', $errorMessages); + $log->addExtra('migrationErrors', json_encode($errorMessages)); $this->updateMigrationDocument($migrationDocument, $projectDocument); - - return; } $migrationDocument->setAttribute('status', 'completed'); @@ -338,6 +341,7 @@ class Migrations extends Action } $migrationDocument->setAttribute('errors', $errorMessages); + $log->addTag('migrationErrors', json_encode($errorMessages)); } } finally { if ($tempAPIKey) { @@ -347,9 +351,9 @@ class Migrations extends Action $this->updateMigrationDocument($migrationDocument, $projectDocument); if ($migrationDocument->getAttribute('status', '') == 'failed') { - throw new Exception(implode("\n", $migrationDocument->getAttribute('errors', []))); + throw new Exception("Migration failed"); } } } } -} +} \ No newline at end of file From 234e2e020b026a9f4d0b1eae7af19f605d57987e Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Thu, 2 May 2024 01:32:47 +0900 Subject: [PATCH 7/9] Update lock file --- composer.lock | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.lock b/composer.lock index 9dbcd5c5ec..9d4300f0a4 100644 --- a/composer.lock +++ b/composer.lock @@ -2005,16 +2005,16 @@ }, { "name": "utopia-php/migration", - "version": "0.4.0", + "version": "0.4.1", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "a72f27bd3dde68752fb185d306c4820e1b8d9657" + "reference": "ae3cfe93f6d313105d226aeb68806660c806a925" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/a72f27bd3dde68752fb185d306c4820e1b8d9657", - "reference": "a72f27bd3dde68752fb185d306c4820e1b8d9657", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/ae3cfe93f6d313105d226aeb68806660c806a925", + "reference": "ae3cfe93f6d313105d226aeb68806660c806a925", "shasum": "" }, "require": { @@ -2047,9 +2047,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/0.4.0" + "source": "https://github.com/utopia-php/migration/tree/0.4.1" }, - "time": "2024-02-25T12:35:21+00:00" + "time": "2024-05-01T13:19:18+00:00" }, { "name": "utopia-php/mongo", @@ -2991,16 +2991,16 @@ }, { "name": "laravel/pint", - "version": "v1.15.2", + "version": "v1.15.3", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "2c9f8004899815f3f0ee3cb28ef7281e2b589134" + "reference": "3600b5d17aff52f6100ea4921849deacbbeb8656" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/2c9f8004899815f3f0ee3cb28ef7281e2b589134", - "reference": "2c9f8004899815f3f0ee3cb28ef7281e2b589134", + "url": "https://api.github.com/repos/laravel/pint/zipball/3600b5d17aff52f6100ea4921849deacbbeb8656", + "reference": "3600b5d17aff52f6100ea4921849deacbbeb8656", "shasum": "" }, "require": { @@ -3053,7 +3053,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2024-04-23T15:42:34+00:00" + "time": "2024-04-30T15:02:26+00:00" }, { "name": "matthiasmullie/minify", From 26d4d6589591cbbe766280231138091c6b9e26e3 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Thu, 2 May 2024 01:46:19 +0900 Subject: [PATCH 8/9] Run Linter --- src/Appwrite/Platform/Workers/Migrations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 6959406cc0..e9762fc060 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -356,4 +356,4 @@ class Migrations extends Action } } } -} \ No newline at end of file +} From 8a055dacc7a3cc6252ef48be798a573377ddd86c Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Thu, 2 May 2024 02:15:16 +0900 Subject: [PATCH 9/9] Use breadcrumbs for tracking migration stages --- src/Appwrite/Platform/Workers/Migrations.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index e9762fc060..8e4aa5216d 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -16,6 +16,7 @@ use Utopia\Database\Exception\Restricted; use Utopia\Database\Exception\Structure; use Utopia\Database\Helpers\ID; use Utopia\Logger\Log; +use Utopia\Logger\Log\Breadcrumb; use Utopia\Migration\Destinations\Appwrite as DestinationsAppwrite; use Utopia\Migration\Exception as MigrationException; use Utopia\Migration\Source; @@ -257,7 +258,7 @@ class Migrations extends Action $migrationDocument = $this->dbForProject->getDocument('migrations', $migration->getId()); $migrationDocument->setAttribute('stage', 'processing'); $migrationDocument->setAttribute('status', 'processing'); - $log->addTag('stage', 'processing'); + $log->addBreadcrumb(new Breadcrumb("debug", "migration", "Migration hit stage 'processing'", \microtime(true))); $this->updateMigrationDocument($migrationDocument, $projectDocument); $log->addTag('type', $migrationDocument->getAttribute('source')); @@ -279,7 +280,7 @@ class Migrations extends Action /** Start Transfer */ $migrationDocument->setAttribute('stage', 'migrating'); - $log->addTag('stage', 'migrating'); + $log->addBreadcrumb(new Breadcrumb("debug", "migration", "Migration hit stage 'migrating'", \microtime(true))); $this->updateMigrationDocument($migrationDocument, $projectDocument); $transfer->run($migrationDocument->getAttribute('resources'), function () use ($migrationDocument, $transfer, $projectDocument) { $migrationDocument->setAttribute('resourceData', json_encode($transfer->getCache())); @@ -294,7 +295,7 @@ class Migrations extends Action if (!empty($sourceErrors) || !empty($destinationErrors)) { $migrationDocument->setAttribute('status', 'failed'); $migrationDocument->setAttribute('stage', 'finished'); - $log->addTag('stage', 'finished'); + $log->addBreadcrumb(new Breadcrumb("debug", "migration", "Migration hit stage 'finished' and failed", \microtime(true))); $errorMessages = []; foreach ($sourceErrors as $error) { @@ -309,10 +310,13 @@ class Migrations extends Action $migrationDocument->setAttribute('errors', $errorMessages); $log->addExtra('migrationErrors', json_encode($errorMessages)); $this->updateMigrationDocument($migrationDocument, $projectDocument); + + return; } $migrationDocument->setAttribute('status', 'completed'); $migrationDocument->setAttribute('stage', 'finished'); + $log->addBreadcrumb(new Breadcrumb("debug", "migration", "Migration hit stage 'finished' and succeeded", \microtime(true))); } catch (\Throwable $th) { Console::error($th->getMessage());