From 17251b1973da7301134e13d7739190dea29c51c2 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 25 Oct 2022 17:37:07 +0000 Subject: [PATCH 01/16] initial implementation --- app/config/collections.php | 22 +++++++++++++++++++ app/controllers/api/databases.php | 2 ++ app/workers/databases.php | 1 + .../Database/Validator/Queries/Databases.php | 3 ++- .../Utopia/Response/Model/Attribute.php | 6 +++++ src/Appwrite/Utopia/Response/Model/Index.php | 6 +++++ 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/app/config/collections.php b/app/config/collections.php index d8f65da788..00d3be12cd 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -263,6 +263,17 @@ $collections = [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('error'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 255, + 'signed' => true, + 'required' => true, + 'default' => '', + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('size'), 'type' => Database::VAR_INTEGER, @@ -440,6 +451,17 @@ $collections = [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('error'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 16, + 'signed' => true, + 'required' => true, + 'default' => '', + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('attributes'), 'type' => Database::VAR_STRING, diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 19264454e0..bbe078be29 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -107,6 +107,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att 'collectionId' => $collectionId, 'type' => $type, 'status' => 'processing', // processing, available, failed, deleting, stuck + 'error' => '', 'size' => $size, 'required' => $required, 'signed' => $signed, @@ -1649,6 +1650,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') 'collectionInternalId' => $collection->getInternalId(), 'collectionId' => $collectionId, 'type' => $type, + 'error' => '', 'attributes' => $attributes, 'lengths' => $lengths, 'orders' => $orders, diff --git a/app/workers/databases.php b/app/workers/databases.php index 71e78b3777..79c79a69cb 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -96,6 +96,7 @@ class DatabaseV1 extends Worker throw new Exception('Failed to create Attribute'); } $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); + // $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('error', 'available')); } catch (\Throwable $th) { Console::error($th->getMessage()); $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'failed')); diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Databases.php b/src/Appwrite/Utopia/Database/Validator/Queries/Databases.php index 22f7ad9b82..2a33a2c7ab 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Databases.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Databases.php @@ -5,7 +5,8 @@ namespace Appwrite\Utopia\Database\Validator\Queries; class Databases extends Base { public const ALLOWED_ATTRIBUTES = [ - 'name' + 'name', + 'error' ]; /** diff --git a/src/Appwrite/Utopia/Response/Model/Attribute.php b/src/Appwrite/Utopia/Response/Model/Attribute.php index a05a40766e..bb9f05d1ee 100644 --- a/src/Appwrite/Utopia/Response/Model/Attribute.php +++ b/src/Appwrite/Utopia/Response/Model/Attribute.php @@ -28,6 +28,12 @@ class Attribute extends Model 'default' => '', 'example' => 'available', ]) + ->addRule('error', [ + 'type' => self::TYPE_STRING, + 'description' => 'Error message', + 'default' => '', + 'example' => 'string', + ]) ->addRule('required', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'Is attribute required?', diff --git a/src/Appwrite/Utopia/Response/Model/Index.php b/src/Appwrite/Utopia/Response/Model/Index.php index b7ac626be9..7145e17e6d 100644 --- a/src/Appwrite/Utopia/Response/Model/Index.php +++ b/src/Appwrite/Utopia/Response/Model/Index.php @@ -28,6 +28,12 @@ class Index extends Model 'default' => '', 'example' => 'available', ]) + ->addRule('error', [ + 'type' => self::TYPE_STRING, + 'description' => 'Error message', + 'default' => '', + 'example' => 'string', + ]) ->addRule('attributes', [ 'type' => self::TYPE_STRING, 'description' => 'Index attributes.', From de7fee6790dc0a52945bb27f85268a7905d46284 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 25 Oct 2022 17:46:28 +0000 Subject: [PATCH 02/16] implement error msg --- app/workers/databases.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/workers/databases.php b/app/workers/databases.php index 79c79a69cb..d3a8e17b1a 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -96,10 +96,10 @@ class DatabaseV1 extends Worker throw new Exception('Failed to create Attribute'); } $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); - // $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('error', 'available')); } catch (\Throwable $th) { Console::error($th->getMessage()); $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'failed')); + $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('error', $th->getMessage())); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern From f055e15031bdec0841371468c5288584d3667d64 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 25 Oct 2022 18:47:24 +0000 Subject: [PATCH 03/16] push changes --- app/workers/databases.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/app/workers/databases.php b/app/workers/databases.php index d3a8e17b1a..ef6371a5ca 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -98,8 +98,10 @@ class DatabaseV1 extends Worker $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'failed')); - $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('error', $th->getMessage())); + $dbForProject->updateDocument('attributes', $attribute->getId(), + $attribute + ->setAttribute('status', 'failed') + ->setAttribute('error', $th->getMessage())); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern @@ -159,7 +161,11 @@ class DatabaseV1 extends Worker $dbForProject->deleteDocument('attributes', $attribute->getId()); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'stuck')); + $dbForProject->updateDocument('attributes', $attribute->getId(), + $attribute + ->setAttribute('status', 'stuck') + ->setAttribute('error', $th->getMessage()) + ); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern @@ -269,7 +275,11 @@ class DatabaseV1 extends Worker $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'available')); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'failed')); + $dbForProject->updateDocument('indexes', $index->getId(), + $index + ->setAttribute('status', 'failed') + ->setAttribute('error', $th->getMessage()) + ); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern @@ -322,7 +332,12 @@ class DatabaseV1 extends Worker $dbForProject->deleteDocument('indexes', $index->getId()); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'stuck')); + $dbForProject->updateDocument('indexes', $index->getId(), + $index + ->setAttribute('status', 'stuck') + ->setAttribute('error',$th->getMessage()) + ); + } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern From cd0a5b73f87b6e17d003315437038220f82c99e7 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 25 Oct 2022 19:26:15 +0000 Subject: [PATCH 04/16] style:run linter --- app/workers/databases.php | 48 +++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/app/workers/databases.php b/app/workers/databases.php index ef6371a5ca..98d9c37e9e 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -98,10 +98,13 @@ class DatabaseV1 extends Worker $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForProject->updateDocument('attributes', $attribute->getId(), - $attribute - ->setAttribute('status', 'failed') - ->setAttribute('error', $th->getMessage())); + $dbForProject->updateDocument( + 'attributes', + $attribute->getId(), + $attribute + ->setAttribute('status', 'failed') + ->setAttribute('error', $th->getMessage()) + ); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern @@ -161,11 +164,13 @@ class DatabaseV1 extends Worker $dbForProject->deleteDocument('attributes', $attribute->getId()); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForProject->updateDocument('attributes', $attribute->getId(), - $attribute - ->setAttribute('status', 'stuck') - ->setAttribute('error', $th->getMessage()) - ); + $dbForProject->updateDocument( + 'attributes', + $attribute->getId(), + $attribute + ->setAttribute('status', 'stuck') + ->setAttribute('error', $th->getMessage()) + ); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern @@ -275,11 +280,13 @@ class DatabaseV1 extends Worker $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'available')); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForProject->updateDocument('indexes', $index->getId(), - $index - ->setAttribute('status', 'failed') - ->setAttribute('error', $th->getMessage()) - ); + $dbForProject->updateDocument( + 'indexes', + $index->getId(), + $index + ->setAttribute('status', 'failed') + ->setAttribute('error', $th->getMessage()) + ); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern @@ -332,12 +339,13 @@ class DatabaseV1 extends Worker $dbForProject->deleteDocument('indexes', $index->getId()); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForProject->updateDocument('indexes', $index->getId(), - $index - ->setAttribute('status', 'stuck') - ->setAttribute('error',$th->getMessage()) - ); - + $dbForProject->updateDocument( + 'indexes', + $index->getId(), + $index + ->setAttribute('status', 'stuck') + ->setAttribute('error', $th->getMessage()) + ); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern From afc1f50a877c6bff655358acea248875d96423d6 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 25 Oct 2022 19:27:33 +0000 Subject: [PATCH 05/16] clean up code --- src/Appwrite/Utopia/Database/Validator/Queries/Databases.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Databases.php b/src/Appwrite/Utopia/Database/Validator/Queries/Databases.php index 2a33a2c7ab..22f7ad9b82 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Databases.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Databases.php @@ -5,8 +5,7 @@ namespace Appwrite\Utopia\Database\Validator\Queries; class Databases extends Base { public const ALLOWED_ATTRIBUTES = [ - 'name', - 'error' + 'name' ]; /** From 3c8b74628db1d49ab772c095d17be5cc6819e33b Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 25 Oct 2022 19:42:19 +0000 Subject: [PATCH 06/16] revert unnecessary commit --- app/config/collections.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config/collections.php b/app/config/collections.php index 00d3be12cd..151f480cb3 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -455,7 +455,7 @@ $collections = [ '$id' => ID::custom('error'), 'type' => Database::VAR_STRING, 'format' => '', - 'size' => 16, + 'size' => 255, 'signed' => true, 'required' => true, 'default' => '', From 605ec8f10c851ed74882d7d88e5a058a47d3995d Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 25 Oct 2022 19:48:50 +0000 Subject: [PATCH 07/16] add PR to changelog --- CHANGES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 340aec16d4..764276390c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,9 @@ ## Bugs - Fix license detection for Flutter and Dart SDKs [#4435](https://github.com/appwrite/appwrite/pull/4435) +## Features +- Add error attribute to Collection Indexes and Attributes [#4575](https://github.com/appwrite/appwrite/pull/4575) + # Version 1.0.3 ## Bugs - Fix document audit deletion [#4429](https://github.com/appwrite/appwrite/pull/4429) From ddd747a084a4bdeb0339412787749fc89709d6bf Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 25 Oct 2022 19:51:08 +0000 Subject: [PATCH 08/16] add PR to changelog --- CHANGES.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 764276390c..2542fe3d14 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,11 +1,11 @@ -# Version 1.1.0 - -## Bugs -- Fix license detection for Flutter and Dart SDKs [#4435](https://github.com/appwrite/appwrite/pull/4435) - +# Unreleased Version ## Features - Add error attribute to Collection Indexes and Attributes [#4575](https://github.com/appwrite/appwrite/pull/4575) +# Version 1.1.0 +## Bugs +- Fix license detection for Flutter and Dart SDKs [#4435](https://github.com/appwrite/appwrite/pull/4435) + # Version 1.0.3 ## Bugs - Fix document audit deletion [#4429](https://github.com/appwrite/appwrite/pull/4429) From 943a334277235bfd89299603a2750d9e69359a23 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Wed, 26 Oct 2022 17:01:16 +0000 Subject: [PATCH 09/16] review comments --- app/config/collections.php | 4 ++-- src/Appwrite/Utopia/Response/Model/Attribute.php | 2 +- src/Appwrite/Utopia/Response/Model/Index.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index 151f480cb3..fe6738c32c 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -267,7 +267,7 @@ $collections = [ '$id' => ID::custom('error'), 'type' => Database::VAR_STRING, 'format' => '', - 'size' => 255, + 'size' => 2048, 'signed' => true, 'required' => true, 'default' => '', @@ -455,7 +455,7 @@ $collections = [ '$id' => ID::custom('error'), 'type' => Database::VAR_STRING, 'format' => '', - 'size' => 255, + 'size' => 2048, 'signed' => true, 'required' => true, 'default' => '', diff --git a/src/Appwrite/Utopia/Response/Model/Attribute.php b/src/Appwrite/Utopia/Response/Model/Attribute.php index bb9f05d1ee..0693e697be 100644 --- a/src/Appwrite/Utopia/Response/Model/Attribute.php +++ b/src/Appwrite/Utopia/Response/Model/Attribute.php @@ -30,7 +30,7 @@ class Attribute extends Model ]) ->addRule('error', [ 'type' => self::TYPE_STRING, - 'description' => 'Error message', + 'description' => 'Error message. Displays error generated when failure of creating or deleting an attribute.', 'default' => '', 'example' => 'string', ]) diff --git a/src/Appwrite/Utopia/Response/Model/Index.php b/src/Appwrite/Utopia/Response/Model/Index.php index 7145e17e6d..55f6a3c7c2 100644 --- a/src/Appwrite/Utopia/Response/Model/Index.php +++ b/src/Appwrite/Utopia/Response/Model/Index.php @@ -30,7 +30,7 @@ class Index extends Model ]) ->addRule('error', [ 'type' => self::TYPE_STRING, - 'description' => 'Error message', + 'description' => 'Error message. Displays error generated when failure of creating or deleting an index.', 'default' => '', 'example' => 'string', ]) From 9e8dddd70d5867b03839398d34c770525f5ed16d Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Thu, 3 Nov 2022 14:56:20 +0000 Subject: [PATCH 10/16] Push changes --- app/workers/databases.php | 64 +++++-- composer.json | 10 +- composer.lock | 382 +++++--------------------------------- 3 files changed, 105 insertions(+), 351 deletions(-) diff --git a/app/workers/databases.php b/app/workers/databases.php index 98d9c37e9e..5f0ebb08e6 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -5,6 +5,7 @@ use Appwrite\Messaging\Adapter\Realtime; use Appwrite\Resque\Worker; use Utopia\CLI\Console; use Utopia\Database\Document; +use Utopia\Database\Exception; require_once __DIR__ . '/../init.php'; @@ -96,15 +97,25 @@ class DatabaseV1 extends Worker throw new Exception('Failed to create Attribute'); } $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); - } catch (\Throwable $th) { - Console::error($th->getMessage()); + } catch (Exception $e) { + Console::error($e->getMessage()); $dbForProject->updateDocument( 'attributes', $attribute->getId(), $attribute ->setAttribute('status', 'failed') - ->setAttribute('error', $th->getMessage()) + ->setAttribute('error', $e->getMessage()) ); + } + catch(\Throwable $th){ + Console::error('Internal Error'); + $dbForProject->updateDocument( + 'attributes', + $attribute->getId(), + $attribute + ->setAttribute('status', 'failed') + ->setAttribute('error', 'Internal Error') + ); } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern @@ -162,14 +173,23 @@ class DatabaseV1 extends Worker throw new Exception('Failed to delete Attribute'); } $dbForProject->deleteDocument('attributes', $attribute->getId()); - } catch (\Throwable $th) { - Console::error($th->getMessage()); + } catch (Exception $e) { + Console::error($e->getMessage()); $dbForProject->updateDocument( 'attributes', $attribute->getId(), $attribute ->setAttribute('status', 'stuck') - ->setAttribute('error', $th->getMessage()) + ->setAttribute('error', $e->getMessage()) + ); + } catch (\Throwable $th) { + Console::error('Internal Error'); + $dbForProject->updateDocument( + 'attributes', + $attribute->getId(), + $attribute + ->setAttribute('status', 'stuck') + ->setAttribute('error', 'Internal Error') ); } finally { $target = Realtime::fromPayload( @@ -278,16 +298,25 @@ class DatabaseV1 extends Worker throw new Exception('Failed to create Index'); } $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'available')); - } catch (\Throwable $th) { - Console::error($th->getMessage()); + } catch (Exception $e) { + Console::error($e->getMessage()); $dbForProject->updateDocument( 'indexes', $index->getId(), $index ->setAttribute('status', 'failed') - ->setAttribute('error', $th->getMessage()) + ->setAttribute('error', $e->getMessage()) ); - } finally { + } catch (\Throwable $th) { + Console::Error('Internal Error'); + $dbForProject->updateDocument( + 'indexes', + $index->getId(), + $index + ->setAttribute('status', 'failed') + ->setAttribute('error', 'Internal Error') + ); + } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern event: $events[0], @@ -337,14 +366,23 @@ class DatabaseV1 extends Worker throw new Exception('Failed to delete index'); } $dbForProject->deleteDocument('indexes', $index->getId()); - } catch (\Throwable $th) { - Console::error($th->getMessage()); + } catch (Exception $e) { + Console::error($e->getMessage()); $dbForProject->updateDocument( 'indexes', $index->getId(), $index ->setAttribute('status', 'stuck') - ->setAttribute('error', $th->getMessage()) + ->setAttribute('error', $e->getMessage()) + ); + } catch (\Throwable $th) { + Console::error('Internal Error'); + $dbForProject->updateDocument( + 'indexes', + $index->getId(), + $index + ->setAttribute('status', 'stuck') + ->setAttribute('error', 'Internal Error') ); } finally { $target = Realtime::fromPayload( diff --git a/composer.json b/composer.json index 47317ed5e2..07006e2acc 100644 --- a/composer.json +++ b/composer.json @@ -48,13 +48,13 @@ "utopia-php/abuse": "0.14.*", "utopia-php/analytics": "0.2.*", "utopia-php/audit": "0.15.*", - "utopia-php/cache": "0.6.*", + "utopia-php/cache": "0.8.*", "utopia-php/cli": "0.13.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.26.*", "utopia-php/locale": "0.4.*", "utopia-php/registry": "0.5.*", "utopia-php/preloader": "0.2.*", + "utopia-php/database": "dev-add-exception-class as 0.26.0", "utopia-php/domains": "1.1.*", "utopia-php/swoole": "0.3.*", "utopia-php/storage": "0.11.*", @@ -74,7 +74,12 @@ { "url": "https://github.com/appwrite/runtimes.git", "type": "git" + }, + { + "url": "https://github.com/everly-gif/database.git", + "type": "git" } + ], "require-dev": { "appwrite/sdk-generator": "0.28.*", @@ -83,6 +88,7 @@ "squizlabs/php_codesniffer": "^3.6", "swoole/ide-helper": "4.8.9", "textalk/websocket": "1.5.7" + }, "provide": { "ext-phpiredis": "*" diff --git a/composer.lock b/composer.lock index f6f29452ad..921f8fe952 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": "08fdd139ad1285b02c4b4e555679e7de", + "content-hash": "6d24385bbb3207fa44866f955a805871", "packages": [ { "name": "adhocore/jwt", @@ -345,79 +345,6 @@ }, "time": "2022-06-20T22:56:59+00:00" }, - { - "name": "composer/package-versions-deprecated", - "version": "1.11.99.5", - "source": { - "type": "git", - "url": "https://github.com/composer/package-versions-deprecated.git", - "reference": "b4f54f74ef3453349c24a845d22392cd31e65f1d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/b4f54f74ef3453349c24a845d22392cd31e65f1d", - "reference": "b4f54f74ef3453349c24a845d22392cd31e65f1d", - "shasum": "" - }, - "require": { - "composer-plugin-api": "^1.1.0 || ^2.0", - "php": "^7 || ^8" - }, - "replace": { - "ocramius/package-versions": "1.11.99" - }, - "require-dev": { - "composer/composer": "^1.9.3 || ^2.0@dev", - "ext-zip": "^1.13", - "phpunit/phpunit": "^6.5 || ^7" - }, - "type": "composer-plugin", - "extra": { - "class": "PackageVersions\\Installer", - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "PackageVersions\\": "src/PackageVersions" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com" - }, - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be" - } - ], - "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", - "support": { - "issues": "https://github.com/composer/package-versions-deprecated/issues", - "source": "https://github.com/composer/package-versions-deprecated/tree/1.11.99.5" - }, - "funding": [ - { - "url": "https://packagist.com", - "type": "custom" - }, - { - "url": "https://github.com/composer", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" - } - ], - "time": "2022-01-17T14:14:24+00:00" - }, { "name": "dragonmantank/cron-expression", "version": "v3.3.1", @@ -693,16 +620,16 @@ }, { "name": "guzzlehttp/psr7", - "version": "2.4.1", + "version": "2.4.3", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "69568e4293f4fa993f3b0e51c9723e1e17c41379" + "reference": "67c26b443f348a51926030c83481b85718457d3d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/69568e4293f4fa993f3b0e51c9723e1e17c41379", - "reference": "69568e4293f4fa993f3b0e51c9723e1e17c41379", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/67c26b443f348a51926030c83481b85718457d3d", + "reference": "67c26b443f348a51926030c83481b85718457d3d", "shasum": "" }, "require": { @@ -792,7 +719,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.4.1" + "source": "https://github.com/guzzle/psr7/tree/2.4.3" }, "funding": [ { @@ -808,7 +735,7 @@ "type": "tidelift" } ], - "time": "2022-08-28T14:45:39+00:00" + "time": "2022-10-26T14:07:24+00:00" }, { "name": "influxdb/influxdb-php", @@ -876,61 +803,6 @@ }, "time": "2020-12-26T17:45:17+00:00" }, - { - "name": "jean85/pretty-package-versions", - "version": "1.6.0", - "source": { - "type": "git", - "url": "https://github.com/Jean85/pretty-package-versions.git", - "reference": "1e0104b46f045868f11942aea058cd7186d6c303" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Jean85/pretty-package-versions/zipball/1e0104b46f045868f11942aea058cd7186d6c303", - "reference": "1e0104b46f045868f11942aea058cd7186d6c303", - "shasum": "" - }, - "require": { - "composer/package-versions-deprecated": "^1.8.0", - "php": "^7.0|^8.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.0|^8.5|^9.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Jean85\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Alessandro Lai", - "email": "alessandro.lai85@gmail.com" - } - ], - "description": "A wrapper for ocramius/package-versions to get pretty versions strings", - "keywords": [ - "composer", - "package", - "release", - "versions" - ], - "support": { - "issues": "https://github.com/Jean85/pretty-package-versions/issues", - "source": "https://github.com/Jean85/pretty-package-versions/tree/1.6.0" - }, - "time": "2021-02-04T16:20:16+00:00" - }, { "name": "matomo/device-detector", "version": "6.0.0", @@ -1000,74 +872,6 @@ }, "time": "2022-04-11T09:58:17+00:00" }, - { - "name": "mongodb/mongodb", - "version": "1.8.0", - "source": { - "type": "git", - "url": "https://github.com/mongodb/mongo-php-library.git", - "reference": "953dbc19443aa9314c44b7217a16873347e6840d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/mongodb/mongo-php-library/zipball/953dbc19443aa9314c44b7217a16873347e6840d", - "reference": "953dbc19443aa9314c44b7217a16873347e6840d", - "shasum": "" - }, - "require": { - "ext-hash": "*", - "ext-json": "*", - "ext-mongodb": "^1.8.1", - "jean85/pretty-package-versions": "^1.2", - "php": "^7.0 || ^8.0", - "symfony/polyfill-php80": "^1.19" - }, - "require-dev": { - "squizlabs/php_codesniffer": "^3.5, <3.5.5", - "symfony/phpunit-bridge": "5.x-dev" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.8.x-dev" - } - }, - "autoload": { - "files": [ - "src/functions.php" - ], - "psr-4": { - "MongoDB\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Andreas Braun", - "email": "andreas.braun@mongodb.com" - }, - { - "name": "Jeremy Mikola", - "email": "jmikola@gmail.com" - } - ], - "description": "MongoDB driver library", - "homepage": "https://jira.mongodb.org/browse/PHPLIB", - "keywords": [ - "database", - "driver", - "mongodb", - "persistence" - ], - "support": { - "issues": "https://github.com/mongodb/mongo-php-library/issues", - "source": "https://github.com/mongodb/mongo-php-library/tree/1.8.0" - }, - "time": "2020-11-25T12:26:02+00:00" - }, { "name": "mustangostang/spyc", "version": "0.6.3", @@ -1656,89 +1460,6 @@ ], "time": "2022-02-25T11:15:52+00:00" }, - { - "name": "symfony/polyfill-php80", - "version": "v1.26.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "cfa0ae98841b9e461207c13ab093d76b0fa7bace" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/cfa0ae98841b9e461207c13ab093d76b0fa7bace", - "reference": "cfa0ae98841b9e461207c13ab093d76b0fa7bace", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.26-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Php80\\": "" - }, - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ion Bazan", - "email": "ion.bazan@gmail.com" - }, - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.26.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-05-10T07:21:04+00:00" - }, { "name": "utopia-php/abuse", "version": "0.14.0", @@ -1897,24 +1618,26 @@ }, { "name": "utopia-php/cache", - "version": "0.6.1", + "version": "0.8.0", "source": { "type": "git", "url": "https://github.com/utopia-php/cache.git", - "reference": "9889235a6d3da6cbb1f435201529da4d27c30e79" + "reference": "212e66100a1f32e674fca5d9bc317cc998303089" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cache/zipball/9889235a6d3da6cbb1f435201529da4d27c30e79", - "reference": "9889235a6d3da6cbb1f435201529da4d27c30e79", + "url": "https://api.github.com/repos/utopia-php/cache/zipball/212e66100a1f32e674fca5d9bc317cc998303089", + "reference": "212e66100a1f32e674fca5d9bc317cc998303089", "shasum": "" }, "require": { "ext-json": "*", + "ext-memcached": "*", "ext-redis": "*", "php": ">=8.0" }, "require-dev": { + "laravel/pint": "1.2.*", "phpunit/phpunit": "^9.3", "vimeo/psalm": "4.13.1" }, @@ -1928,12 +1651,6 @@ "license": [ "MIT" ], - "authors": [ - { - "name": "Eldad Fux", - "email": "eldad@appwrite.io" - } - ], "description": "A simple cache library to manage application cache storing, loading and purging", "keywords": [ "cache", @@ -1944,9 +1661,9 @@ ], "support": { "issues": "https://github.com/utopia-php/cache/issues", - "source": "https://github.com/utopia-php/cache/tree/0.6.1" + "source": "https://github.com/utopia-php/cache/tree/0.8.0" }, - "time": "2022-08-10T08:12:46+00:00" + "time": "2022-10-16T16:48:09+00:00" }, { "name": "utopia-php/cli", @@ -2054,29 +1771,23 @@ }, { "name": "utopia-php/database", - "version": "0.26.0", + "version": "dev-add-exception-class", "source": { "type": "git", - "url": "https://github.com/utopia-php/database.git", - "reference": "d172af2541137c83a86d066f82f48914b5a3a610" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/d172af2541137c83a86d066f82f48914b5a3a610", - "reference": "d172af2541137c83a86d066f82f48914b5a3a610", - "shasum": "" + "url": "https://github.com/everly-gif/database.git", + "reference": "e0b91278e8ce9644ec0504f466a90f59a75d2653" }, "require": { - "ext-mongodb": "*", - "ext-pdo": "*", - "ext-redis": "*", - "mongodb/mongodb": "1.8.0", "php": ">=8.0", - "utopia-php/cache": "0.6.*", + "utopia-php/cache": "0.8.*", "utopia-php/framework": "0.*.*" }, "require-dev": { + "ext-mongodb": "*", + "ext-pdo": "*", + "ext-redis": "*", "fakerphp/faker": "^1.14", + "mongodb/mongodb": "1.8.0", "phpunit/phpunit": "^9.4", "swoole/ide-helper": "4.8.0", "utopia-php/cli": "^0.11.0", @@ -2088,20 +1799,14 @@ "Utopia\\Database\\": "src/Database" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-4": { + "Utopia\\Tests\\": "tests/Database" + } + }, "license": [ "MIT" ], - "authors": [ - { - "name": "Eldad Fux", - "email": "eldad@appwrite.io" - }, - { - "name": "Brandon Leckemby", - "email": "brandon@appwrite.io" - } - ], "description": "A simple library to manage application persistency using multiple database adapters", "keywords": [ "database", @@ -2110,11 +1815,7 @@ "upf", "utopia" ], - "support": { - "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.26.0" - }, - "time": "2022-10-03T17:12:01+00:00" + "time": "2022-11-01T19:45:41+00:00" }, { "name": "utopia-php/domains", @@ -3535,16 +3236,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.17", + "version": "9.2.18", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "aa94dc41e8661fe90c7316849907cba3007b10d8" + "reference": "12fddc491826940cf9b7e88ad9664cf51f0f6d0a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aa94dc41e8661fe90c7316849907cba3007b10d8", - "reference": "aa94dc41e8661fe90c7316849907cba3007b10d8", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/12fddc491826940cf9b7e88ad9664cf51f0f6d0a", + "reference": "12fddc491826940cf9b7e88ad9664cf51f0f6d0a", "shasum": "" }, "require": { @@ -3600,7 +3301,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.17" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.18" }, "funding": [ { @@ -3608,7 +3309,7 @@ "type": "github" } ], - "time": "2022-08-30T12:24:04+00:00" + "time": "2022-10-27T13:35:33+00:00" }, { "name": "phpunit/php-file-iterator", @@ -5357,9 +5058,18 @@ "time": "2022-09-28T08:42:51+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-add-exception-class", + "alias": "0.26.0", + "alias_normalized": "0.26.0.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/database": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { From eece18c9f694efa0d8d35cce922c704afe626b01 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Thu, 3 Nov 2022 16:10:39 +0000 Subject: [PATCH 11/16] style:run linter --- app/workers/databases.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/workers/databases.php b/app/workers/databases.php index 5f0ebb08e6..e017855c57 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -106,8 +106,7 @@ class DatabaseV1 extends Worker ->setAttribute('status', 'failed') ->setAttribute('error', $e->getMessage()) ); - } - catch(\Throwable $th){ + } catch (\Throwable $th) { Console::error('Internal Error'); $dbForProject->updateDocument( 'attributes', @@ -316,7 +315,7 @@ class DatabaseV1 extends Worker ->setAttribute('status', 'failed') ->setAttribute('error', 'Internal Error') ); - } finally { + } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern event: $events[0], From b011f931c5f1a23773723bc2d550e150f50ae1c0 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Mon, 7 Nov 2022 19:38:06 +0000 Subject: [PATCH 12/16] change grammar --- src/Appwrite/Utopia/Response/Model/Attribute.php | 2 +- src/Appwrite/Utopia/Response/Model/Index.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Utopia/Response/Model/Attribute.php b/src/Appwrite/Utopia/Response/Model/Attribute.php index 0693e697be..9f9ceca317 100644 --- a/src/Appwrite/Utopia/Response/Model/Attribute.php +++ b/src/Appwrite/Utopia/Response/Model/Attribute.php @@ -30,7 +30,7 @@ class Attribute extends Model ]) ->addRule('error', [ 'type' => self::TYPE_STRING, - 'description' => 'Error message. Displays error generated when failure of creating or deleting an attribute.', + 'description' => 'Error message. Displays error generated on failure of creating or deleting an attribute.', 'default' => '', 'example' => 'string', ]) diff --git a/src/Appwrite/Utopia/Response/Model/Index.php b/src/Appwrite/Utopia/Response/Model/Index.php index 55f6a3c7c2..3d3d1a3b52 100644 --- a/src/Appwrite/Utopia/Response/Model/Index.php +++ b/src/Appwrite/Utopia/Response/Model/Index.php @@ -30,7 +30,7 @@ class Index extends Model ]) ->addRule('error', [ 'type' => self::TYPE_STRING, - 'description' => 'Error message. Displays error generated when failure of creating or deleting an index.', + 'description' => 'Error message. Displays error generated on failure of creating or deleting an index.', 'default' => '', 'example' => 'string', ]) From 13ea6a5e6928f2802d2c1887fcf08f80ce54d7cf Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Tue, 8 Nov 2022 17:06:50 +0000 Subject: [PATCH 13/16] update error attribute --- app/workers/databases.php | 43 ++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/app/workers/databases.php b/app/workers/databases.php index e017855c57..00b938d20a 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -5,7 +5,8 @@ use Appwrite\Messaging\Adapter\Realtime; use Appwrite\Resque\Worker; use Utopia\CLI\Console; use Utopia\Database\Document; -use Utopia\Database\Exception; +use Exception; +use Utopia\Database\Exception as DatabaseException; require_once __DIR__ . '/../init.php'; @@ -27,11 +28,11 @@ class DatabaseV1 extends Worker $database = new Document($this->args['database'] ?? []); if ($collection->isEmpty()) { - throw new Exception('Missing collection'); + throw new DatabaseException('Missing collection'); } if ($document->isEmpty()) { - throw new Exception('Missing document'); + throw new DatabaseException('Missing document'); } switch (strval($type)) { @@ -94,10 +95,10 @@ class DatabaseV1 extends Worker try { if (!$dbForProject->createAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key, $type, $size, $required, $default, $signed, $array, $format, $formatOptions, $filters)) { - throw new Exception('Failed to create Attribute'); + throw new DatabaseException('Failed to create Attribute'); } $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); - } catch (Exception $e) { + } catch (DatabaseException $e) { Console::error($e->getMessage()); $dbForProject->updateDocument( 'attributes', @@ -106,14 +107,13 @@ class DatabaseV1 extends Worker ->setAttribute('status', 'failed') ->setAttribute('error', $e->getMessage()) ); - } catch (\Throwable $th) { - Console::error('Internal Error'); + } catch (Exception $e) { $dbForProject->updateDocument( 'attributes', $attribute->getId(), $attribute ->setAttribute('status', 'failed') - ->setAttribute('error', 'Internal Error') + ->setAttribute('error', '') ); } finally { $target = Realtime::fromPayload( @@ -169,10 +169,10 @@ class DatabaseV1 extends Worker // - stuck: attribute was available but cannot be removed try { if ($status !== 'failed' && !$dbForProject->deleteAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { - throw new Exception('Failed to delete Attribute'); + throw new DatabaseException('Failed to delete Attribute'); } $dbForProject->deleteDocument('attributes', $attribute->getId()); - } catch (Exception $e) { + } catch (DatabaseException $e) { Console::error($e->getMessage()); $dbForProject->updateDocument( 'attributes', @@ -181,14 +181,13 @@ class DatabaseV1 extends Worker ->setAttribute('status', 'stuck') ->setAttribute('error', $e->getMessage()) ); - } catch (\Throwable $th) { - Console::error('Internal Error'); + } catch (Exception $e) { $dbForProject->updateDocument( 'attributes', $attribute->getId(), $attribute ->setAttribute('status', 'stuck') - ->setAttribute('error', 'Internal Error') + ->setAttribute('error', '') ); } finally { $target = Realtime::fromPayload( @@ -294,10 +293,10 @@ class DatabaseV1 extends Worker try { if (!$dbForProject->createIndex('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key, $type, $attributes, $lengths, $orders)) { - throw new Exception('Failed to create Index'); + throw new DatabaseException('Failed to create Index'); } $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'available')); - } catch (Exception $e) { + } catch (DatabaseException $e) { Console::error($e->getMessage()); $dbForProject->updateDocument( 'indexes', @@ -306,14 +305,13 @@ class DatabaseV1 extends Worker ->setAttribute('status', 'failed') ->setAttribute('error', $e->getMessage()) ); - } catch (\Throwable $th) { - Console::Error('Internal Error'); + } catch (Exception $e) { $dbForProject->updateDocument( 'indexes', $index->getId(), $index ->setAttribute('status', 'failed') - ->setAttribute('error', 'Internal Error') + ->setAttribute('error', '') ); } finally { $target = Realtime::fromPayload( @@ -362,10 +360,10 @@ class DatabaseV1 extends Worker try { if ($status !== 'failed' && !$dbForProject->deleteIndex('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { - throw new Exception('Failed to delete index'); + throw new DatabaseException('Failed to delete index'); } $dbForProject->deleteDocument('indexes', $index->getId()); - } catch (Exception $e) { + } catch (DatabaseException $e) { Console::error($e->getMessage()); $dbForProject->updateDocument( 'indexes', @@ -374,14 +372,13 @@ class DatabaseV1 extends Worker ->setAttribute('status', 'stuck') ->setAttribute('error', $e->getMessage()) ); - } catch (\Throwable $th) { - Console::error('Internal Error'); + } catch (Exception $e) { $dbForProject->updateDocument( 'indexes', $index->getId(), $index ->setAttribute('status', 'stuck') - ->setAttribute('error', 'Internal Error') + ->setAttribute('error', '') ); } finally { $target = Realtime::fromPayload( From 742736a479e8b81306fa7e30659631c2fa3c8d61 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 15 Jun 2023 13:00:24 +1200 Subject: [PATCH 14/16] Update dependencies --- composer.json | 6 ++-- composer.lock | 78 +++++++++++++++++++++++---------------------------- 2 files changed, 38 insertions(+), 46 deletions(-) diff --git a/composer.json b/composer.json index 0ba26540bd..792e757ff8 100644 --- a/composer.json +++ b/composer.json @@ -43,13 +43,13 @@ "ext-sockets": "*", "appwrite/php-clamav": "1.1.*", "appwrite/php-runtimes": "0.11.*", - "utopia-php/abuse": "0.25.*", + "utopia-php/abuse": "0.26.*", "utopia-php/analytics": "0.2.*", - "utopia-php/audit": "0.26.*", + "utopia-php/audit": "0.28.*", "utopia-php/cache": "0.8.*", "utopia-php/cli": "0.13.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.36.*", + "utopia-php/database": "0.37.*", "utopia-php/domains": "1.1.*", "utopia-php/framework": "0.28.*", "utopia-php/image": "0.5.*", diff --git a/composer.lock b/composer.lock index a9168dbbf4..3202cbdafd 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": "3eadbfe5543aafdf8682ea0465159e3c", + "content-hash": "0f20fb41e9b250b6763af1b734bb8d2d", "packages": [ { "name": "adhocore/jwt", @@ -1802,23 +1802,23 @@ }, { "name": "utopia-php/abuse", - "version": "0.25.0", + "version": "0.26.0", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "49a180cab5316cddec9676d900d5112d03e97ffc" + "reference": "fb73180f0588bc8826b85d433393b983bdc37cfa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/49a180cab5316cddec9676d900d5112d03e97ffc", - "reference": "49a180cab5316cddec9676d900d5112d03e97ffc", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/fb73180f0588bc8826b85d433393b983bdc37cfa", + "reference": "fb73180f0588bc8826b85d433393b983bdc37cfa", "shasum": "" }, "require": { "ext-curl": "*", "ext-pdo": "*", "php": ">=8.0", - "utopia-php/database": "0.36.*" + "utopia-php/database": "0.37.*" }, "require-dev": { "laravel/pint": "1.5.*", @@ -1845,9 +1845,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/0.25.0" + "source": "https://github.com/utopia-php/abuse/tree/0.26.0" }, - "time": "2023-04-27T15:43:47+00:00" + "time": "2023-06-15T00:53:36+00:00" }, { "name": "utopia-php/analytics", @@ -1906,21 +1906,21 @@ }, { "name": "utopia-php/audit", - "version": "0.26.0", + "version": "0.28.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "e7228080f14df28737fbb050c180c26d86ac0403" + "reference": "abf4124bec20b6ab3555869b64afe5b274e37165" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/e7228080f14df28737fbb050c180c26d86ac0403", - "reference": "e7228080f14df28737fbb050c180c26d86ac0403", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/abf4124bec20b6ab3555869b64afe5b274e37165", + "reference": "abf4124bec20b6ab3555869b64afe5b274e37165", "shasum": "" }, "require": { "php": ">=8.0", - "utopia-php/database": "0.36.*" + "utopia-php/database": "0.37.*" }, "require-dev": { "laravel/pint": "1.5.*", @@ -1947,9 +1947,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/0.26.0" + "source": "https://github.com/utopia-php/audit/tree/0.28.0" }, - "time": "2023-04-27T15:43:50+00:00" + "time": "2023-06-15T00:52:49+00:00" }, { "name": "utopia-php/cache", @@ -2106,16 +2106,16 @@ }, { "name": "utopia-php/database", - "version": "0.36.1", + "version": "0.37.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "f6ab65e59a199da5155c114564077b1ab8c4daef" + "reference": "698c5a44598bc263c58506d4fd526589ea392114" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/f6ab65e59a199da5155c114564077b1ab8c4daef", - "reference": "f6ab65e59a199da5155c114564077b1ab8c4daef", + "url": "https://api.github.com/repos/utopia-php/database/zipball/698c5a44598bc263c58506d4fd526589ea392114", + "reference": "698c5a44598bc263c58506d4fd526589ea392114", "shasum": "" }, "require": { @@ -2126,8 +2126,6 @@ "utopia-php/mongo": "0.2.*" }, "require-dev": { - "ext-mongodb": "*", - "ext-redis": "*", "fakerphp/faker": "^1.14", "laravel/pint": "1.4.*", "mongodb/mongodb": "1.8.0", @@ -2144,11 +2142,7 @@ "Utopia\\Database\\": "src/Database" } }, - "autoload-dev": { - "psr-4": { - "Utopia\\Tests\\": "tests/Database" - } - }, + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -2162,9 +2156,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.36.1" + "source": "https://github.com/utopia-php/database/tree/0.37.0" }, - "time": "2023-04-27T08:39:55+00:00" + "time": "2023-06-09T07:39:11+00:00" }, { "name": "utopia-php/domains", @@ -3204,16 +3198,16 @@ }, { "name": "matthiasmullie/minify", - "version": "1.3.70", + "version": "1.3.71", "source": { "type": "git", "url": "https://github.com/matthiasmullie/minify.git", - "reference": "2807d9f9bece6877577ad44acb5c801bb3ae536b" + "reference": "ae42a47d7fecc1fbb7277b2f2d84c37a33edc3b1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/matthiasmullie/minify/zipball/2807d9f9bece6877577ad44acb5c801bb3ae536b", - "reference": "2807d9f9bece6877577ad44acb5c801bb3ae536b", + "url": "https://api.github.com/repos/matthiasmullie/minify/zipball/ae42a47d7fecc1fbb7277b2f2d84c37a33edc3b1", + "reference": "ae42a47d7fecc1fbb7277b2f2d84c37a33edc3b1", "shasum": "" }, "require": { @@ -3263,7 +3257,7 @@ ], "support": { "issues": "https://github.com/matthiasmullie/minify/issues", - "source": "https://github.com/matthiasmullie/minify/tree/1.3.70" + "source": "https://github.com/matthiasmullie/minify/tree/1.3.71" }, "funding": [ { @@ -3271,7 +3265,7 @@ "type": "github" } ], - "time": "2022-12-09T12:56:44+00:00" + "time": "2023-04-25T20:33:03+00:00" }, { "name": "matthiasmullie/path-converter", @@ -5585,16 +5579,16 @@ }, { "name": "twig/twig", - "version": "v3.6.0", + "version": "v3.6.1", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "106c170d08e8415d78be2d16c3d057d0d108262b" + "reference": "7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/106c170d08e8415d78be2d16c3d057d0d108262b", - "reference": "106c170d08e8415d78be2d16c3d057d0d108262b", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd", + "reference": "7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd", "shasum": "" }, "require": { @@ -5640,7 +5634,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.6.0" + "source": "https://github.com/twigphp/Twig/tree/v3.6.1" }, "funding": [ { @@ -5652,14 +5646,12 @@ "type": "tidelift" } ], - "time": "2023-05-03T19:06:57+00:00" + "time": "2023-06-08T12:52:13+00:00" } ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "utopia-php/database": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { From 10f06226d3e77807831500f37822dc26f3cc9a3d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 15 Jun 2023 13:05:37 +1200 Subject: [PATCH 15/16] Make error optional --- app/config/collections.php | 8 ++++---- app/controllers/api/databases.php | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index dbc212e63c..b5c9daccc8 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -280,8 +280,8 @@ $collections = [ 'format' => '', 'size' => 2048, 'signed' => true, - 'required' => true, - 'default' => '', + 'required' => false, + 'default' => null, 'array' => false, 'filters' => [], ], @@ -478,8 +478,8 @@ $collections = [ 'format' => '', 'size' => 2048, 'signed' => true, - 'required' => true, - 'default' => '', + 'required' => false, + 'default' => null, 'array' => false, 'filters' => [], ], diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index e94c9adb7f..c4ff448ce4 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -118,7 +118,6 @@ function createAttribute(string $databaseId, string $collectionId, Document $att 'collectionId' => $collectionId, 'type' => $type, 'status' => 'processing', // processing, available, failed, deleting, stuck - 'error' => '', 'size' => $size, 'required' => $required, 'signed' => $signed, @@ -2437,7 +2436,6 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') 'collectionInternalId' => $collection->getInternalId(), 'collectionId' => $collectionId, 'type' => $type, - 'error' => '', 'attributes' => $attributes, 'lengths' => $lengths, 'orders' => $orders, From 44e7a822b18421e7ac3b4022754b00f47dc2361b Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 15 Jun 2023 13:25:25 +1200 Subject: [PATCH 16/16] Single catch with type check --- app/workers/databases.php | 126 ++++++++++++++------------------------ 1 file changed, 45 insertions(+), 81 deletions(-) diff --git a/app/workers/databases.php b/app/workers/databases.php index 2b16fb8f0b..6600fc2c01 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -102,7 +102,7 @@ class DatabaseV1 extends Worker case Database::VAR_RELATIONSHIP: $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection']); if ($relatedCollection->isEmpty()) { - throw new Exception('Collection not found'); + throw new DatabaseException('Collection not found'); } if ( @@ -116,7 +116,7 @@ class DatabaseV1 extends Worker onDelete: $options['onDelete'], ) ) { - throw new Exception('Failed to create Attribute'); + throw new DatabaseException('Failed to create Attribute'); } if ($options['twoWay']) { @@ -131,42 +131,27 @@ class DatabaseV1 extends Worker } $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); - } catch (DatabaseException $e) { - Console::error($e->getMessage()); - $dbForProject->updateDocument( - 'attributes', - $attribute->getId(), - $attribute - ->setAttribute('status', 'failed') - ->setAttribute('error', $e->getMessage()) - ); - - if ($type === Database::VAR_RELATIONSHIP && $options['twoWay']) { - $relatedAttribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $options['twoWayKey']); - $dbForProject->updateDocument( - 'attributes', - $relatedAttribute->getId(), - $relatedAttribute - ->setAttribute('status', 'failed') - ->setAttribute('error', $e->getMessage()); - } } catch (Exception $e) { + Console::error($e->getMessage()); + + if ($e instanceof DatabaseException) { + $attribute->setAttribute('error', $e->getMessage()); + if (isset($relatedAttribute)) { + $relatedAttribute->setAttribute('error', $e->getMessage()); + } + } + $dbForProject->updateDocument( 'attributes', $attribute->getId(), - $attribute - ->setAttribute('status', 'failed') - ->setAttribute('error', '') + $attribute->setAttribute('status', 'failed') ); - if ($type === Database::VAR_RELATIONSHIP && $options['twoWay']) { - $relatedAttribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $options['twoWayKey']); + if (isset($relatedAttribute)) { $dbForProject->updateDocument( 'attributes', $relatedAttribute->getId(), - $relatedAttribute - ->setAttribute('status', 'failed') - ->setAttribute('error', '') + $relatedAttribute->setAttribute('status', 'failed') ); } } finally { @@ -236,7 +221,7 @@ class DatabaseV1 extends Worker if ($options['twoWay']) { $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection']); if ($relatedCollection->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new DatabaseException('Collection not found'); } $relatedAttribute = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $options['twoWayKey']); } @@ -246,7 +231,7 @@ class DatabaseV1 extends Worker throw new DatabaseException('Failed to delete Relationship'); } } elseif (!$dbForProject->deleteAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { - throw new Exception('Failed to delete Attribute'); + throw new DatabaseException('Failed to delete Attribute'); } } @@ -255,37 +240,27 @@ class DatabaseV1 extends Worker if (!$relatedAttribute->isEmpty()) { $dbForProject->deleteDocument('attributes', $relatedAttribute->getId()); } - } catch (DatabaseException $e) { - Console::error($e->getMessage()); - $dbForProject->updateDocument( - 'attributes', - $attribute->getId(), - $attribute - ->setAttribute('status', 'stuck') - ->setAttribute('error', $e->getMessage()) - ); - $dbForProject->updateDocument( - 'attributes', - $relatedAttribute->getId(), - $relatedAttribute - ->setAttribute('status', 'stuck') - ->setAttribute('error', $e->getMessage()) - ); } catch (Exception $e) { + Console::error($e->getMessage()); + + if ($e instanceof DatabaseException) { + $attribute->setAttribute('error', $e->getMessage()); + if (!$relatedAttribute->isEmpty()) { + $relatedAttribute->setAttribute('error', $e->getMessage()); + } + } $dbForProject->updateDocument( 'attributes', $attribute->getId(), - $attribute - ->setAttribute('status', 'stuck') - ->setAttribute('error', '') - ); - $dbForProject->updateDocument( - 'attributes', - $relatedAttribute->getId(), - $relatedAttribute - ->setAttribute('status', 'stuck') - ->setAttribute('error', '') + $attribute->setAttribute('status', 'stuck') ); + if (!$relatedAttribute->isEmpty()) { + $dbForProject->updateDocument( + 'attributes', + $relatedAttribute->getId(), + $relatedAttribute->setAttribute('status', 'stuck') + ); + } } finally { $target = Realtime::fromPayload( // Pass first, most verbose event pattern @@ -398,22 +373,16 @@ class DatabaseV1 extends Worker throw new DatabaseException('Failed to create Index'); } $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'available')); - } catch (DatabaseException $e) { - Console::error($e->getMessage()); - $dbForProject->updateDocument( - 'indexes', - $index->getId(), - $index - ->setAttribute('status', 'failed') - ->setAttribute('error', $e->getMessage()) - ); } catch (Exception $e) { + Console::error($e->getMessage()); + + if ($e instanceof DatabaseException) { + $index->setAttribute('error', $e->getMessage()); + } $dbForProject->updateDocument( 'indexes', $index->getId(), - $index - ->setAttribute('status', 'failed') - ->setAttribute('error', '') + $index->setAttribute('status', 'failed') ); } finally { $target = Realtime::fromPayload( @@ -445,6 +414,7 @@ class DatabaseV1 extends Worker * @param Document $collection * @param Document $index * @param string $projectId + * @throws Exception */ protected function deleteIndex(Document $database, Document $collection, Document $index, string $projectId): void { @@ -465,22 +435,16 @@ class DatabaseV1 extends Worker throw new DatabaseException('Failed to delete index'); } $dbForProject->deleteDocument('indexes', $index->getId()); - } catch (DatabaseException $e) { - Console::error($e->getMessage()); - $dbForProject->updateDocument( - 'indexes', - $index->getId(), - $index - ->setAttribute('status', 'stuck') - ->setAttribute('error', $e->getMessage()) - ); } catch (Exception $e) { + Console::error($e->getMessage()); + + if ($e instanceof DatabaseException) { + $index->setAttribute('error', $e->getMessage()); + } $dbForProject->updateDocument( 'indexes', $index->getId(), - $index - ->setAttribute('status', 'stuck') - ->setAttribute('error', '') + $index->setAttribute('status', 'stuck') ); } finally { $target = Realtime::fromPayload(