From 1f093f3349bf66be2d9aac35a35ae2a68d8f248e Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 18 Sep 2025 16:12:15 +0300 Subject: [PATCH 1/4] Move out of rollback --- src/Database/Adapter.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Database/Adapter.php b/src/Database/Adapter.php index bac76fc73..707ae35ea 100644 --- a/src/Database/Adapter.php +++ b/src/Database/Adapter.php @@ -3,6 +3,7 @@ namespace Utopia\Database; use Exception; +use Utopia\CLI\Console; use Utopia\Database\Exception as DatabaseException; use Utopia\Database\Exception\Authorization as AuthorizationException; use Utopia\Database\Exception\Conflict as ConflictException; @@ -388,19 +389,6 @@ public function withTransaction(callable $callback): mixed } catch (\Throwable $action) { try { $this->rollbackTransaction(); - - if ( - $action instanceof DuplicateException || - $action instanceof RestrictedException || - $action instanceof AuthorizationException || - $action instanceof RelationshipException || - $action instanceof ConflictException || - $action instanceof LimitException - ) { - $this->inTransaction = 0; - throw $action; - } - } catch (\Throwable $rollback) { if ($attempts < $retries) { \usleep($sleep * ($attempts + 1)); @@ -411,6 +399,21 @@ public function withTransaction(callable $callback): mixed throw $rollback; } + if ( + $action instanceof DuplicateException || + $action instanceof RestrictedException || + $action instanceof AuthorizationException || + $action instanceof RelationshipException || + $action instanceof ConflictException || + $action instanceof LimitException + ) { + Console::error($action->getMessage()); + Console::error($action->getFile()); + Console::error($action->getLine()); + $this->inTransaction = 0; + throw $action; + } + if ($attempts < $retries) { \usleep($sleep * ($attempts + 1)); continue; From 871ca582b7e91b3bae8bf5dc830efc76e15640ab Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 18 Sep 2025 16:12:32 +0300 Subject: [PATCH 2/4] Move dbg --- src/Database/Adapter.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Database/Adapter.php b/src/Database/Adapter.php index 707ae35ea..e209720f0 100644 --- a/src/Database/Adapter.php +++ b/src/Database/Adapter.php @@ -407,9 +407,6 @@ public function withTransaction(callable $callback): mixed $action instanceof ConflictException || $action instanceof LimitException ) { - Console::error($action->getMessage()); - Console::error($action->getFile()); - Console::error($action->getLine()); $this->inTransaction = 0; throw $action; } From d773995046bc6661f1a78a034d54c7ad609c9a30 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 18 Sep 2025 16:13:52 +0300 Subject: [PATCH 3/4] Remove use --- src/Database/Adapter.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Database/Adapter.php b/src/Database/Adapter.php index e209720f0..715cab030 100644 --- a/src/Database/Adapter.php +++ b/src/Database/Adapter.php @@ -3,7 +3,6 @@ namespace Utopia\Database; use Exception; -use Utopia\CLI\Console; use Utopia\Database\Exception as DatabaseException; use Utopia\Database\Exception\Authorization as AuthorizationException; use Utopia\Database\Exception\Conflict as ConflictException; From 0d1570fdfecd87ebb3269fddd0d868789a8987e3 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 18 Sep 2025 16:34:46 +0300 Subject: [PATCH 4/4] Remove use --- phpunit.xml | 3 +-- tests/e2e/Adapter/Scopes/CollectionTests.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 2a0531cfd..7469c5341 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,8 +7,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" -> + stopOnFailure="true"> ./tests/unit diff --git a/tests/e2e/Adapter/Scopes/CollectionTests.php b/tests/e2e/Adapter/Scopes/CollectionTests.php index 5178a414d..44c82191d 100644 --- a/tests/e2e/Adapter/Scopes/CollectionTests.php +++ b/tests/e2e/Adapter/Scopes/CollectionTests.php @@ -44,6 +44,23 @@ public function testCreateListExistsDeleteCollection(): void /** @var Database $database */ $database = static::getDatabase(); + + $database->createCollection('shmuel', permissions: [ + Permission::create(Role::any()), + Permission::read(Role::any()), + ]); + + $database->createDocument('shmuel', new Document([ + '$id' => 'doc1', + ])); + + $database->createDocument('shmuel', new Document([ + '$id' => 'doc1', + ])); + + $this->assertEquals(1,222); + + $this->assertInstanceOf('Utopia\Database\Document', $database->createCollection('actors', permissions: [ Permission::create(Role::any()), Permission::read(Role::any()),