From 37707007a10ffb27919622ac5a595922144d8d7d Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Sat, 24 Feb 2024 14:18:55 +0000 Subject: [PATCH 01/14] Use new migration error handling --- composer.json | 8 ++- composer.lock | 62 ++++++++++++-------- src/Appwrite/Platform/Workers/Migrations.php | 37 ++++++++---- 3 files changed, 72 insertions(+), 35 deletions(-) diff --git a/composer.json b/composer.json index a53d47a3fa..c0afd636f7 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,7 @@ "utopia-php/locale": "0.4.*", "utopia-php/logger": "0.3.*", "utopia-php/messaging": "0.10.*", - "utopia-php/migration": "0.3.*", + "utopia-php/migration": "dev-dev", "utopia-php/orchestration": "0.9.*", "utopia-php/platform": "0.5.*", "utopia-php/pools": "0.4.*", @@ -77,6 +77,12 @@ "webonyx/graphql-php": "14.11.*", "league/csv": "9.14.*" }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/utopia-php/migration" + } + ], "require-dev": { "ext-fileinfo": "*", "appwrite/sdk-generator": "0.36.*", diff --git a/composer.lock b/composer.lock index bca3e557bc..447a047d30 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "37887fb414be6480280484aa41c0df9d", + "content-hash": "9e0e07159d27e4b86511aaab851532de", "packages": [ { "name": "adhocore/jwt", @@ -65,16 +65,16 @@ }, { "name": "appwrite/appwrite", - "version": "10.0.0", + "version": "10.1.0", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-for-php.git", - "reference": "461eedf4efd502dc905c3055f36f0e3583f67390" + "reference": "da579af70723cfc117b5af84375bdef117e27312" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-for-php/zipball/461eedf4efd502dc905c3055f36f0e3583f67390", - "reference": "461eedf4efd502dc905c3055f36f0e3583f67390", + "url": "https://api.github.com/repos/appwrite/sdk-for-php/zipball/da579af70723cfc117b5af84375bdef117e27312", + "reference": "da579af70723cfc117b5af84375bdef117e27312", "shasum": "" }, "require": { @@ -99,10 +99,10 @@ "support": { "email": "team@appwrite.io", "issues": "https://github.com/appwrite/sdk-for-php/issues", - "source": "https://github.com/appwrite/sdk-for-php/tree/10.0.0", + "source": "https://github.com/appwrite/sdk-for-php/tree/10.1.0", "url": "https://appwrite.io/support" }, - "time": "2023-09-07T23:28:31+00:00" + "time": "2023-11-20T09:56:12+00:00" }, { "name": "appwrite/php-clamav", @@ -1962,20 +1962,20 @@ }, { "name": "utopia-php/migration", - "version": "0.3.6", + "version": "dev-dev", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "f78273b38bade23db5866e5c7cb5f55427ba82af" + "reference": "0847fad35006c16f2aa572c4fa890cc8a0e7f8f2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/f78273b38bade23db5866e5c7cb5f55427ba82af", - "reference": "f78273b38bade23db5866e5c7cb5f55427ba82af", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/0847fad35006c16f2aa572c4fa890cc8a0e7f8f2", + "reference": "0847fad35006c16f2aa572c4fa890cc8a0e7f8f2", "shasum": "" }, "require": { - "appwrite/appwrite": "10.0.*", + "appwrite/appwrite": "10.1.0", "php": "8.*", "utopia-php/cli": "0.*" }, @@ -1990,7 +1990,19 @@ "Utopia\\Migration\\": "src/Migration" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-4": { + "Utopia\\Tests\\": "tests/Migration" + } + }, + "scripts": { + "lint": [ + "./vendor/bin/pint --test" + ], + "format": [ + "./vendor/bin/pint" + ] + }, "license": [ "MIT" ], @@ -2003,10 +2015,10 @@ "utopia" ], "support": { - "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/0.3.6" + "source": "https://github.com/utopia-php/migration/tree/dev", + "issues": "https://github.com/utopia-php/migration/issues" }, - "time": "2023-11-02T15:13:03+00:00" + "time": "2024-02-23T12:02:32+00:00" }, { "name": "utopia-php/mongo", @@ -3357,21 +3369,21 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.8.1", + "version": "1.8.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "bc3dc91a5e9b14aa06d1d9e90647c5c5a2cc5353" + "reference": "153ae662783729388a584b4361f2545e4d841e3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/bc3dc91a5e9b14aa06d1d9e90647c5c5a2cc5353", - "reference": "bc3dc91a5e9b14aa06d1d9e90647c5c5a2cc5353", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/153ae662783729388a584b4361f2545e4d841e3c", + "reference": "153ae662783729388a584b4361f2545e4d841e3c", "shasum": "" }, "require": { "doctrine/deprecations": "^1.0", - "php": "^7.4 || ^8.0", + "php": "^7.3 || ^8.0", "phpdocumentor/reflection-common": "^2.0", "phpstan/phpdoc-parser": "^1.13" }, @@ -3409,9 +3421,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.8.1" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.8.2" }, - "time": "2024-01-18T19:15:27+00:00" + "time": "2024-02-23T11:10:43+00:00" }, { "name": "phpspec/prophecy", @@ -5449,7 +5461,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/migration": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index d2a126f22b..9a37d4e6db 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -19,13 +19,13 @@ use Utopia\Database\Database; use Utopia\Database\Helpers\ID; use Utopia\Logger\Log; use Utopia\Migration\Destinations\Appwrite as DestinationsAppwrite; -use Utopia\Migration\Resource; use Utopia\Migration\Source; use Utopia\Migration\Sources\Appwrite; use Utopia\Migration\Sources\Firebase; use Utopia\Migration\Sources\NHost; use Utopia\Migration\Sources\Supabase; use Utopia\Migration\Transfer; +use Utopia\Migration\Exception as MigrationException; class Migrations extends Action { @@ -285,15 +285,21 @@ class Migrations extends Action $this->updateMigrationDocument($migrationDocument, $projectDocument); }); - $errors = $transfer->getReport(Resource::STATUS_ERROR); + $sourceErrors = $source->getErrors(); + $destinationErrors = $destination->getErrors(); - if (count($errors) > 0) { + if (!empty($sourceErrors) || !empty($destinationErrors)) { $migrationDocument->setAttribute('status', 'failed'); $migrationDocument->setAttribute('stage', 'finished'); $errorMessages = []; - foreach ($errors as $error) { - $errorMessages[] = "Failed to transfer resource '{$error['id']}:{$error['resource']}' with message '{$error['message']}'"; + foreach ($sourceErrors as $error) { + /** @var MigrationException $error */ + $errorMessages[] = "Error occured while fetching '{$error->getResourceType()}:{$error->getResourceId()}' from source with message '{$error->getMessage()}'"; + } + foreach ($destinationErrors as $error) { + /** @var MigrationException $error */ + $errorMessages[] = "Error occured while pushing '{$error->getResourceType()}:{$error->getResourceId()}' to destination with message '{$error->getMessage()}'"; } $migrationDocument->setAttribute('errors', $errorMessages); @@ -318,17 +324,28 @@ class Migrations extends Action } if ($transfer) { - $errors = $transfer->getReport(Resource::STATUS_ERROR); + $sourceErrors = $source->getErrors(); + $destinationErrors = $destination->getErrors(); - if (count($errors) > 0) { - $migrationDocument->setAttribute('status', 'failed'); - $migrationDocument->setAttribute('stage', 'finished'); - $migrationDocument->setAttribute('errors', $errors); + $errorMessages = []; + foreach ($sourceErrors as $error) { + /** @var MigrationException $error */ + $errorMessages[] = "Error occured while fetching '{$error->getResourceType()}:{$error->getResourceId()}' from source with message '{$error->getMessage()}'"; } + foreach ($destinationErrors as $error) { + /** @var MigrationException $error */ + $errorMessages[] = "Error occured while pushing '{$error->getResourceType()}:{$error->getResourceId()}' to destination with message '{$error->getMessage()}'"; + } + + $migrationDocument->setAttribute('errors', $errorMessages); } } finally { if ($migrationDocument) { $this->updateMigrationDocument($migrationDocument, $projectDocument); + + if ($migrationDocument->getAttribute('status', '') == 'failed') { + throw new Exception(implode("\n", $migrationDocument->getAttribute('errors', [])); + } } if ($tempAPIKey) { $this->removeAPIKey($tempAPIKey); From 3f603995f525e170ee30943670751af773029df1 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Sat, 24 Feb 2024 14:43:33 +0000 Subject: [PATCH 02/14] Make sure we're revoking API keys before throwing an exception --- src/Appwrite/Platform/Workers/Migrations.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 9a37d4e6db..45599f4be3 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -340,6 +340,9 @@ class Migrations extends Action $migrationDocument->setAttribute('errors', $errorMessages); } } finally { + if ($tempAPIKey) { + $this->removeAPIKey($tempAPIKey); + } if ($migrationDocument) { $this->updateMigrationDocument($migrationDocument, $projectDocument); @@ -347,9 +350,6 @@ class Migrations extends Action throw new Exception(implode("\n", $migrationDocument->getAttribute('errors', [])); } } - if ($tempAPIKey) { - $this->removeAPIKey($tempAPIKey); - } } } } From eaee61db2a7a82c39753abcfc1ce4042d6765d87 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Sat, 24 Feb 2024 15:19:50 +0000 Subject: [PATCH 03/14] Update src/Appwrite/Platform/Workers/Migrations.php Co-authored-by: Eldad A. Fux --- 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 45599f4be3..ecb3a09a97 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -295,7 +295,7 @@ class Migrations extends Action $errorMessages = []; foreach ($sourceErrors as $error) { /** @var MigrationException $error */ - $errorMessages[] = "Error occured while fetching '{$error->getResourceType()}:{$error->getResourceId()}' from source with message '{$error->getMessage()}'"; + $errorMessages[] = "Error occurred while fetching '{$error->getResourceType()}:{$error->getResourceId()}' from source with message: '{$error->getMessage()}'"; } foreach ($destinationErrors as $error) { /** @var MigrationException $error */ From 725dd479d2903b9658023429c185cd12b0f453a3 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Sat, 24 Feb 2024 15:21:21 +0000 Subject: [PATCH 04/14] Fix Typos --- src/Appwrite/Platform/Workers/Migrations.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 45599f4be3..3c68e546eb 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -295,11 +295,11 @@ class Migrations extends Action $errorMessages = []; foreach ($sourceErrors as $error) { /** @var MigrationException $error */ - $errorMessages[] = "Error occured while fetching '{$error->getResourceType()}:{$error->getResourceId()}' from source with message '{$error->getMessage()}'"; + $errorMessages[] = "Error occurred while fetching '{$error->getResourceType()}:{$error->getResourceId()}' from source with message '{$error->getMessage()}'"; } foreach ($destinationErrors as $error) { /** @var MigrationException $error */ - $errorMessages[] = "Error occured while pushing '{$error->getResourceType()}:{$error->getResourceId()}' to destination with message '{$error->getMessage()}'"; + $errorMessages[] = "Error occurred while pushing '{$error->getResourceType()}:{$error->getResourceId()}' to destination with message '{$error->getMessage()}'"; } $migrationDocument->setAttribute('errors', $errorMessages); @@ -330,11 +330,11 @@ class Migrations extends Action $errorMessages = []; foreach ($sourceErrors as $error) { /** @var MigrationException $error */ - $errorMessages[] = "Error occured while fetching '{$error->getResourceType()}:{$error->getResourceId()}' from source with message '{$error->getMessage()}'"; + $errorMessages[] = "Error occurred while fetching '{$error->getResourceType()}:{$error->getResourceId()}' from source with message '{$error->getMessage()}'"; } foreach ($destinationErrors as $error) { /** @var MigrationException $error */ - $errorMessages[] = "Error occured while pushing '{$error->getResourceType()}:{$error->getResourceId()}' to destination with message '{$error->getMessage()}'"; + $errorMessages[] = "Error occurred while pushing '{$error->getResourceType()}:{$error->getResourceId()}' to destination with message '{$error->getMessage()}'"; } $migrationDocument->setAttribute('errors', $errorMessages); From 77bb6b31a7d7ad2b265263f201baf5e38c54ecbf Mon Sep 17 00:00:00 2001 From: David <86196556+DH-555@users.noreply.github.com> Date: Sat, 24 Feb 2024 20:38:58 +0100 Subject: [PATCH 05/14] Fix es.json --- app/config/locale/translations/es.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/config/locale/translations/es.json b/app/config/locale/translations/es.json index 570b395ba7..4b9024c723 100644 --- a/app/config/locale/translations/es.json +++ b/app/config/locale/translations/es.json @@ -236,10 +236,10 @@ "emails.magicSession.securityPhrase": "La frase de seguridad para este correo electrónico es {{phrase}}. Puedes confiar en este correo electrónico si esta frase coincide con la frase que se muestra durante el inicio de sesión.", "emails.magicSession.optionUrl": "Si no puedes iniciar sesión utilizando el botón anterior, visita el siguiente enlace:", "emails.otpSession.subject": "Inicio de sesión en {{project}}", - "emails.otpSession.hello": "Hola,", + "emails.otpSession.hello": "Hola.", "emails.otpSession.description": "Ingrese el siguiente código de verificación cuando se le solicite para iniciar sesión de forma segura en su cuenta de {{project}}. Expirará en 15 minutos.", "emails.otpSession.clientInfo": "Este inicio de sesión fue solicitado usando {{agentClient}} en {{agentDevice}} {{agentOs}}. Si no solicitaste el inicio de sesión, puedes ignorar este correo electrónico de forma segura.", "emails.otpSession.securityPhrase": "La frase de seguridad para este correo electrónico es {{phrase}}. Puedes confiar en este correo si esta frase coincide con la frase mostrada durante el inicio de sesión.", - "emails.otpSession.thanks": "Gracias,", - "emails.otpSession.signature": "equipo {{project}}" -} \ No newline at end of file + "emails.otpSession.thanks": "Gracias.", + "emails.otpSession.signature": "El equipo de {{project}}" +} From a5779971cf974bbf5be4e1ff0f481b706c934e2a Mon Sep 17 00:00:00 2001 From: David <86196556+DH-555@users.noreply.github.com> Date: Sat, 24 Feb 2024 20:46:09 +0100 Subject: [PATCH 06/14] Update es.json Added missing dots --- app/config/locale/translations/es.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/config/locale/translations/es.json b/app/config/locale/translations/es.json index 4b9024c723..2199107eea 100644 --- a/app/config/locale/translations/es.json +++ b/app/config/locale/translations/es.json @@ -4,7 +4,7 @@ "settings.direction": "ltr", "emails.sender": "El equipo de %s", "emails.verification.subject": "Verificación de cuenta", - "emails.verification.hello": "Hola, {{name}}", + "emails.verification.hello": "Hola, {{name}}.", "emails.verification.body": "Haz clic en este enlace para verificar tu correo:", "emails.verification.footer": "Si no has solicitado verificar este correo, puedes ignorar este mensaje.", "emails.verification.thanks": "Gracias.", @@ -16,7 +16,7 @@ "emails.magicSession.thanks": "Gracias.", "emails.magicSession.signature": "El equipo de {{project}}", "emails.recovery.subject": "Restablecer contraseña", - "emails.recovery.hello": "Hola, {{name}}", + "emails.recovery.hello": "Hola, {{name}}.", "emails.recovery.body": "Haz clic en este enlace para restablecer la contraseña de {{project}}:", "emails.recovery.footer": "Si no has solicitado restablecer la contraseña, puedes ignorar este mensaje.", "emails.recovery.thanks": "Gracias.", @@ -236,7 +236,7 @@ "emails.magicSession.securityPhrase": "La frase de seguridad para este correo electrónico es {{phrase}}. Puedes confiar en este correo electrónico si esta frase coincide con la frase que se muestra durante el inicio de sesión.", "emails.magicSession.optionUrl": "Si no puedes iniciar sesión utilizando el botón anterior, visita el siguiente enlace:", "emails.otpSession.subject": "Inicio de sesión en {{project}}", - "emails.otpSession.hello": "Hola.", + "emails.otpSession.hello": "Hola", "emails.otpSession.description": "Ingrese el siguiente código de verificación cuando se le solicite para iniciar sesión de forma segura en su cuenta de {{project}}. Expirará en 15 minutos.", "emails.otpSession.clientInfo": "Este inicio de sesión fue solicitado usando {{agentClient}} en {{agentDevice}} {{agentOs}}. Si no solicitaste el inicio de sesión, puedes ignorar este correo electrónico de forma segura.", "emails.otpSession.securityPhrase": "La frase de seguridad para este correo electrónico es {{phrase}}. Puedes confiar en este correo si esta frase coincide con la frase mostrada durante el inicio de sesión.", From 450de95c57a15f0a9612723072ab1b5899612bba Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Sun, 25 Feb 2024 14:09:22 +0000 Subject: [PATCH 07/14] Update migration lib and fix typo --- composer.json | 8 +--- composer.lock | 40 ++++++++++---------- src/Appwrite/Platform/Workers/Migrations.php | 2 +- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index 90cf585739..40d8df92e4 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,7 @@ "utopia-php/locale": "0.4.*", "utopia-php/logger": "0.3.*", "utopia-php/messaging": "0.10.*", - "utopia-php/migration": "dev-dev", + "utopia-php/migration": "0.4.*", "utopia-php/orchestration": "0.9.*", "utopia-php/platform": "0.5.*", "utopia-php/pools": "0.4.*", @@ -77,12 +77,6 @@ "webonyx/graphql-php": "14.11.*", "league/csv": "9.14.*" }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/utopia-php/migration" - } - ], "require-dev": { "ext-fileinfo": "*", "appwrite/sdk-generator": "0.36.*", diff --git a/composer.lock b/composer.lock index b7bb031c3c..9eb8dd1fa7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f19c09e7e233fe0f767bf5255fb46b86", + "content-hash": "ed4d8b871471fe6a259742c4abe88184", "packages": [ { "name": "adhocore/jwt", @@ -65,16 +65,16 @@ }, { "name": "appwrite/appwrite", - "version": "10.0.0", + "version": "10.1.0", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-for-php.git", - "reference": "461eedf4efd502dc905c3055f36f0e3583f67390" + "reference": "da579af70723cfc117b5af84375bdef117e27312" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-for-php/zipball/461eedf4efd502dc905c3055f36f0e3583f67390", - "reference": "461eedf4efd502dc905c3055f36f0e3583f67390", + "url": "https://api.github.com/repos/appwrite/sdk-for-php/zipball/da579af70723cfc117b5af84375bdef117e27312", + "reference": "da579af70723cfc117b5af84375bdef117e27312", "shasum": "" }, "require": { @@ -99,10 +99,10 @@ "support": { "email": "team@appwrite.io", "issues": "https://github.com/appwrite/sdk-for-php/issues", - "source": "https://github.com/appwrite/sdk-for-php/tree/10.0.0", + "source": "https://github.com/appwrite/sdk-for-php/tree/10.1.0", "url": "https://appwrite.io/support" }, - "time": "2023-09-07T23:28:31+00:00" + "time": "2023-11-20T09:56:12+00:00" }, { "name": "appwrite/php-clamav", @@ -1962,20 +1962,20 @@ }, { "name": "utopia-php/migration", - "version": "0.3.6", + "version": "0.4.0", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "f78273b38bade23db5866e5c7cb5f55427ba82af" + "reference": "a72f27bd3dde68752fb185d306c4820e1b8d9657" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/f78273b38bade23db5866e5c7cb5f55427ba82af", - "reference": "f78273b38bade23db5866e5c7cb5f55427ba82af", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/a72f27bd3dde68752fb185d306c4820e1b8d9657", + "reference": "a72f27bd3dde68752fb185d306c4820e1b8d9657", "shasum": "" }, "require": { - "appwrite/appwrite": "10.0.*", + "appwrite/appwrite": "10.1.0", "php": "8.*", "utopia-php/cli": "0.*" }, @@ -2004,9 +2004,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/0.3.6" + "source": "https://github.com/utopia-php/migration/tree/0.4.0" }, - "time": "2023-11-02T15:13:03+00:00" + "time": "2024-02-25T12:35:21+00:00" }, { "name": "utopia-php/mongo", @@ -3484,16 +3484,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.25.0", + "version": "1.26.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240" + "reference": "231e3186624c03d7e7c890ec662b81e6b0405227" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bd84b629c8de41aa2ae82c067c955e06f1b00240", - "reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/231e3186624c03d7e7c890ec662b81e6b0405227", + "reference": "231e3186624c03d7e7c890ec662b81e6b0405227", "shasum": "" }, "require": { @@ -3525,9 +3525,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.25.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.26.0" }, - "time": "2024-01-04T17:06:16+00:00" + "time": "2024-02-23T16:05:55+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 43d0142c4e..f73eee7f36 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -347,7 +347,7 @@ class Migrations extends Action $this->updateMigrationDocument($migrationDocument, $projectDocument); if ($migrationDocument->getAttribute('status', '') == 'failed') { - throw new Exception(implode("\n", $migrationDocument->getAttribute('errors', [])); + throw new Exception(implode("\n", $migrationDocument->getAttribute('errors', []))); } } } From b3fc8eb5109120081ecfbdbdcc515489a98bb882 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Sun, 25 Feb 2024 16:37:31 +0000 Subject: [PATCH 08/14] feat: custom eventually assertion --- tests/extensions/Async.php | 14 +++++++ tests/extensions/Async/Eventually.php | 54 +++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/extensions/Async.php create mode 100644 tests/extensions/Async/Eventually.php diff --git a/tests/extensions/Async.php b/tests/extensions/Async.php new file mode 100644 index 0000000000..0fb9c8eea6 --- /dev/null +++ b/tests/extensions/Async.php @@ -0,0 +1,14 @@ +timeoutMs = $timeoutMs; + $this->waitMs = $waitMs; + } + + public function evaluate(mixed $probe, string $description = '', bool $returnResult = false): ?bool + { + if (!is_callable($probe)) { + throw new \Exception('Probe must be a callable'); + } + + $start = microtime(true); + $lastException = null; + + do { + try { + $probe(); + return true; + } catch (\Exception $exception) { + $lastException = $exception; + } + + usleep($this->waitMs * 1000); + } while (microtime(true) - $start < $this->timeoutMs / 1000); + + if ($returnResult) { + return false; + } + + throw $lastException; + } + + protected function failureDescription(mixed $other): string + { + return 'the given probe was satisfied within the provided timeout'; + } + + public function toString(): string + { + return 'Eventually'; + } +} \ No newline at end of file From c4657eadaf1232a325bb47a29dafcd9c82a72519 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Sun, 25 Feb 2024 16:41:37 +0000 Subject: [PATCH 09/14] fix: phone verification flaky test --- tests/e2e/Services/Account/AccountCustomClientTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index d3fc13bd17..84b740a988 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -2247,12 +2247,10 @@ class AccountCustomClientTest extends Scope $this->assertEmpty($response['body']['secret']); $this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['expire'])); - \sleep(10); - $smsRequest = $this->getLastRequest(); return \array_merge($data, [ - 'token' => $smsRequest['data']['secret'] + 'token' => \substr($smsRequest['data']['message'], 0, 6) ]); } From 4ba92e2591f85fc662e0bfa0f623d9befacfe174 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Sun, 25 Feb 2024 16:43:58 +0000 Subject: [PATCH 10/14] Revert "feat: custom eventually assertion" This reverts commit b3fc8eb5109120081ecfbdbdcc515489a98bb882. --- tests/extensions/Async.php | 14 ------- tests/extensions/Async/Eventually.php | 54 --------------------------- 2 files changed, 68 deletions(-) delete mode 100644 tests/extensions/Async.php delete mode 100644 tests/extensions/Async/Eventually.php diff --git a/tests/extensions/Async.php b/tests/extensions/Async.php deleted file mode 100644 index 0fb9c8eea6..0000000000 --- a/tests/extensions/Async.php +++ /dev/null @@ -1,14 +0,0 @@ -timeoutMs = $timeoutMs; - $this->waitMs = $waitMs; - } - - public function evaluate(mixed $probe, string $description = '', bool $returnResult = false): ?bool - { - if (!is_callable($probe)) { - throw new \Exception('Probe must be a callable'); - } - - $start = microtime(true); - $lastException = null; - - do { - try { - $probe(); - return true; - } catch (\Exception $exception) { - $lastException = $exception; - } - - usleep($this->waitMs * 1000); - } while (microtime(true) - $start < $this->timeoutMs / 1000); - - if ($returnResult) { - return false; - } - - throw $lastException; - } - - protected function failureDescription(mixed $other): string - { - return 'the given probe was satisfied within the provided timeout'; - } - - public function toString(): string - { - return 'Eventually'; - } -} \ No newline at end of file From 862cba1a5ba34d13a44177a4635accc32ce6bf24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sun, 25 Feb 2024 16:30:59 +0000 Subject: [PATCH 11/14] Check against false positive for MFA --- app/controllers/api/teams.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index c1fcb9d8c2..455542f546 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -756,8 +756,20 @@ App::get('/v1/teams/:teamId/memberships') $memberships = array_map(function ($membership) use ($dbForProject, $team) { $user = $dbForProject->getDocument('users', $membership->getAttribute('userId')); + $mfa = $user->getAttribute('mfa', false); + + if ($mfa) { + $totpEnabled = $user->getAttribute('totp', false) && $user->getAttribute('totpVerification', false); + $emailEnabled = $user->getAttribute('email', false) && $user->getAttribute('emailVerification', false); + $phoneEnabled = $user->getAttribute('phone', false) && $user->getAttribute('phoneVerification', false); + + if (!$totpEnabled && !$emailEnabled && !$phoneEnabled) { + $mfa = false; + } + } + $membership - ->setAttribute('mfa', $user->getAttribute('mfa')) + ->setAttribute('mfa', $mfa) ->setAttribute('teamName', $team->getAttribute('name')) ->setAttribute('userName', $user->getAttribute('name')) ->setAttribute('userEmail', $user->getAttribute('email')) From 5327c02870d82a32c8eae640c68e3b4df47c3f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sun, 25 Feb 2024 16:35:33 +0000 Subject: [PATCH 12/14] Improve tests --- app/controllers/api/teams.php | 13 +++++++++++++ tests/e2e/Services/Teams/TeamsBaseClient.php | 2 ++ tests/e2e/Services/Teams/TeamsBaseServer.php | 1 + 3 files changed, 16 insertions(+) diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 455542f546..b3507e35b4 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -817,7 +817,20 @@ App::get('/v1/teams/:teamId/memberships/:membershipId') $user = $dbForProject->getDocument('users', $membership->getAttribute('userId')); + $mfa = $user->getAttribute('mfa', false); + + if ($mfa) { + $totpEnabled = $user->getAttribute('totp', false) && $user->getAttribute('totpVerification', false); + $emailEnabled = $user->getAttribute('email', false) && $user->getAttribute('emailVerification', false); + $phoneEnabled = $user->getAttribute('phone', false) && $user->getAttribute('phoneVerification', false); + + if (!$totpEnabled && !$emailEnabled && !$phoneEnabled) { + $mfa = false; + } + } + $membership + ->setAttribute('mfa', $mfa) ->setAttribute('teamName', $team->getAttribute('name')) ->setAttribute('userName', $user->getAttribute('name')) ->setAttribute('userEmail', $user->getAttribute('email')) diff --git a/tests/e2e/Services/Teams/TeamsBaseClient.php b/tests/e2e/Services/Teams/TeamsBaseClient.php index 2213ae6d19..f586466cca 100644 --- a/tests/e2e/Services/Teams/TeamsBaseClient.php +++ b/tests/e2e/Services/Teams/TeamsBaseClient.php @@ -30,6 +30,7 @@ trait TeamsBaseClient $this->assertEquals(200, $response['headers']['status-code']); $this->assertIsInt($response['body']['total']); $this->assertNotEmpty($response['body']['memberships'][0]['$id']); + $this->assertNotEmpty($response['body']['memberships'][0]['mfa']); $this->assertEquals($this->getUser()['name'], $response['body']['memberships'][0]['userName']); $this->assertEquals($this->getUser()['email'], $response['body']['memberships'][0]['userEmail']); $this->assertEquals($teamName, $response['body']['memberships'][0]['teamName']); @@ -155,6 +156,7 @@ trait TeamsBaseClient $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); + $this->assertNotEmpty($response['body']['mfa']); $this->assertNotEmpty($response['body']['userId']); $this->assertNotEmpty($response['body']['userName']); $this->assertNotEmpty($response['body']['userEmail']); diff --git a/tests/e2e/Services/Teams/TeamsBaseServer.php b/tests/e2e/Services/Teams/TeamsBaseServer.php index f26d8857a4..19ac779beb 100644 --- a/tests/e2e/Services/Teams/TeamsBaseServer.php +++ b/tests/e2e/Services/Teams/TeamsBaseServer.php @@ -51,6 +51,7 @@ trait TeamsBaseServer $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); $this->assertNotEmpty($response['body']['userId']); + $this->assertNotEmpty($response['body']['mfa']); $this->assertNotEmpty($response['body']['userName']); $this->assertNotEmpty($response['body']['userEmail']); $this->assertNotEmpty($response['body']['teamId']); From 6da4a8282591bb067120a29c14c6c758dfdddb2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sun, 25 Feb 2024 16:47:26 +0000 Subject: [PATCH 13/14] Fix tests --- tests/e2e/Services/Teams/TeamsBaseClient.php | 4 ++-- tests/e2e/Services/Teams/TeamsBaseServer.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/e2e/Services/Teams/TeamsBaseClient.php b/tests/e2e/Services/Teams/TeamsBaseClient.php index f586466cca..dff1c85716 100644 --- a/tests/e2e/Services/Teams/TeamsBaseClient.php +++ b/tests/e2e/Services/Teams/TeamsBaseClient.php @@ -30,7 +30,7 @@ trait TeamsBaseClient $this->assertEquals(200, $response['headers']['status-code']); $this->assertIsInt($response['body']['total']); $this->assertNotEmpty($response['body']['memberships'][0]['$id']); - $this->assertNotEmpty($response['body']['memberships'][0]['mfa']); + $this->assertFalse($response['body']['memberships'][0]['mfa']); $this->assertEquals($this->getUser()['name'], $response['body']['memberships'][0]['userName']); $this->assertEquals($this->getUser()['email'], $response['body']['memberships'][0]['userEmail']); $this->assertEquals($teamName, $response['body']['memberships'][0]['teamName']); @@ -156,7 +156,7 @@ trait TeamsBaseClient $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertNotEmpty($response['body']['mfa']); + $this->assertFalse($response['body']['mfa']); $this->assertNotEmpty($response['body']['userId']); $this->assertNotEmpty($response['body']['userName']); $this->assertNotEmpty($response['body']['userEmail']); diff --git a/tests/e2e/Services/Teams/TeamsBaseServer.php b/tests/e2e/Services/Teams/TeamsBaseServer.php index 19ac779beb..4e9d0839ab 100644 --- a/tests/e2e/Services/Teams/TeamsBaseServer.php +++ b/tests/e2e/Services/Teams/TeamsBaseServer.php @@ -51,7 +51,7 @@ trait TeamsBaseServer $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); $this->assertNotEmpty($response['body']['userId']); - $this->assertNotEmpty($response['body']['mfa']); + $this->assertFalse($response['body']['mfa']); $this->assertNotEmpty($response['body']['userName']); $this->assertNotEmpty($response['body']['userEmail']); $this->assertNotEmpty($response['body']['teamId']); From 00c3bc0f8a50a8ae65afb2626054be3449ada5a3 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 26 Feb 2024 15:38:58 +1300 Subject: [PATCH 14/14] Remove invalid index type --- app/controllers/api/databases.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index f2925f8360..a1ce6c7d85 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -2404,7 +2404,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') ->param('key', null, new Key(), 'Index Key.') - ->param('type', null, new WhiteList([Database::INDEX_KEY, Database::INDEX_FULLTEXT, Database::INDEX_UNIQUE, Database::INDEX_SPATIAL]), 'Index type.') + ->param('type', null, new WhiteList([Database::INDEX_KEY, Database::INDEX_FULLTEXT, Database::INDEX_UNIQUE]), 'Index type.') ->param('attributes', null, new ArrayList(new Key(true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of attributes to index. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' attributes are allowed, each 32 characters long.') ->param('orders', [], new ArrayList(new WhiteList(['ASC', 'DESC'], false, Database::VAR_STRING), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of index orders. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' orders are allowed.', true) ->inject('response')