From cd5a3169780213c5751dbfbfe436d34c208c4030 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 14 Dec 2025 02:28:58 +0000 Subject: [PATCH 01/12] Feat: Database 3.x.x --- composer.json | 2 +- composer.lock | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/composer.json b/composer.json index 4d00dad..6cba96e 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ }, "require": { "php": ">=8.0", - "utopia-php/database": "4.*", + "utopia-php/database": "3.*", "utopia-php/fetch": "^0.4.2", "utopia-php/validators": "^0.1.0" }, diff --git a/composer.lock b/composer.lock index 3076c39..aee4be3 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": "7e7770e1778658a1376fdd3c1ffd73c3", + "content-hash": "56a7dbb2d6f7f217b842a1785df2f5d2", "packages": [ { "name": "brick/math", @@ -1383,16 +1383,16 @@ }, { "name": "symfony/http-client", - "version": "v7.4.0", + "version": "v7.4.1", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "ee5e0e0139ab506f6063a230e631bed677c650a4" + "reference": "26cc224ea7103dda90e9694d9e139a389092d007" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/ee5e0e0139ab506f6063a230e631bed677c650a4", - "reference": "ee5e0e0139ab506f6063a230e631bed677c650a4", + "url": "https://api.github.com/repos/symfony/http-client/zipball/26cc224ea7103dda90e9694d9e139a389092d007", + "reference": "26cc224ea7103dda90e9694d9e139a389092d007", "shasum": "" }, "require": { @@ -1460,7 +1460,7 @@ "http" ], "support": { - "source": "https://github.com/symfony/http-client/tree/v7.4.0" + "source": "https://github.com/symfony/http-client/tree/v7.4.1" }, "funding": [ { @@ -1480,7 +1480,7 @@ "type": "tidelift" } ], - "time": "2025-11-20T12:32:50+00:00" + "time": "2025-12-04T21:12:57+00:00" }, { "name": "symfony/http-client-contracts", @@ -2124,16 +2124,16 @@ }, { "name": "utopia-php/database", - "version": "4.3.0", + "version": "3.6.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "fe7a1326ad623609e65587fe8c01a630a7075fee" + "reference": "af15066255a5fd7bd2926de37bcbf3d8500fc155" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/fe7a1326ad623609e65587fe8c01a630a7075fee", - "reference": "fe7a1326ad623609e65587fe8c01a630a7075fee", + "url": "https://api.github.com/repos/utopia-php/database/zipball/af15066255a5fd7bd2926de37bcbf3d8500fc155", + "reference": "af15066255a5fd7bd2926de37bcbf3d8500fc155", "shasum": "" }, "require": { @@ -2176,9 +2176,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/4.3.0" + "source": "https://github.com/utopia-php/database/tree/3.6.0" }, - "time": "2025-11-14T03:43:10+00:00" + "time": "2025-12-08T05:23:04+00:00" }, { "name": "utopia-php/fetch", @@ -2221,29 +2221,29 @@ }, { "name": "utopia-php/framework", - "version": "0.33.33", + "version": "0.33.35", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "838e3a28276e73187bc34a314f014096dc92191b" + "reference": "82b139fb04f30045db51b0d322224f222da32313" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/838e3a28276e73187bc34a314f014096dc92191b", - "reference": "838e3a28276e73187bc34a314f014096dc92191b", + "url": "https://api.github.com/repos/utopia-php/http/zipball/82b139fb04f30045db51b0d322224f222da32313", + "reference": "82b139fb04f30045db51b0d322224f222da32313", "shasum": "" }, "require": { - "php": ">=8.1", + "php": ">=8.3", "utopia-php/compression": "0.1.*", "utopia-php/telemetry": "0.1.*", "utopia-php/validators": "0.1.*" }, "require-dev": { - "laravel/pint": "^1.2", - "phpbench/phpbench": "^1.2", - "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9.5.25" + "laravel/pint": "1.*", + "phpbench/phpbench": "1.*", + "phpstan/phpstan": "1.*", + "phpunit/phpunit": "9.*" }, "type": "library", "autoload": { @@ -2263,9 +2263,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.33.33" + "source": "https://github.com/utopia-php/http/tree/0.33.35" }, - "time": "2025-11-25T10:21:13+00:00" + "time": "2025-12-12T08:33:52+00:00" }, { "name": "utopia-php/mongo", From 5b5a5440eb37ee6c6b7fc717868e6965b19c003f Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 14 Dec 2025 02:29:51 +0000 Subject: [PATCH 02/12] Fix authorization --- src/Audit/Adapter/Database.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Audit/Adapter/Database.php b/src/Audit/Adapter/Database.php index 23e4505..3e42a4d 100644 --- a/src/Audit/Adapter/Database.php +++ b/src/Audit/Adapter/Database.php @@ -10,6 +10,7 @@ use Utopia\Database\Exception\Duplicate as DuplicateException; use Utopia\Database\Exception\Timeout; use Utopia\Database\Query; +use Utopia\Database\Validator\Authorization; use Utopia\Exception; /** @@ -70,7 +71,7 @@ public function setup(): void public function create(array $log): Log { $log['time'] = $log['time'] ?? DateTime::now(); - $document = $this->db->getAuthorization()->skip(function () use ($log) { + $document = Authorization::skip(function () use ($log) { return $this->db->createDocument($this->getCollectionName(), new Document($log)); }); @@ -88,7 +89,7 @@ public function createBatch(array $logs): array { $created = []; - $this->db->getAuthorization()->skip(function () use ($logs, &$created) { + Authorization::skip(function () use ($logs, &$created) { foreach ($logs as $log) { $time = $log['time'] ?? new \DateTime(); if (is_string($time)) { @@ -148,7 +149,7 @@ public function getByUser( bool $ascending = false, ): array { $timeQueries = $this->buildTimeQueries($after, $before); - $documents = $this->db->getAuthorization()->skip(function () use ($userId, $timeQueries, $limit, $offset, $ascending) { + $documents = Authorization::skip(function () use ($userId, $timeQueries, $limit, $offset, $ascending) { $queries = [ Query::equal('userId', [$userId]), ...$timeQueries, @@ -177,7 +178,7 @@ public function countByUser( ?\DateTime $before = null, ): int { $timeQueries = $this->buildTimeQueries($after, $before); - return $this->db->getAuthorization()->skip(function () use ($userId, $timeQueries) { + return Authorization::skip(function () use ($userId, $timeQueries) { return $this->db->count( collection: $this->getCollectionName(), queries: [ @@ -204,7 +205,7 @@ public function getByResource( bool $ascending = false, ): array { $timeQueries = $this->buildTimeQueries($after, $before); - $documents = $this->db->getAuthorization()->skip(function () use ($resource, $timeQueries, $limit, $offset, $ascending) { + $documents = Authorization::skip(function () use ($resource, $timeQueries, $limit, $offset, $ascending) { $queries = [ Query::equal('resource', [$resource]), ...$timeQueries, @@ -235,7 +236,7 @@ public function countByResource( ?\DateTime $before = null, ): int { $timeQueries = $this->buildTimeQueries($after, $before); - return $this->db->getAuthorization()->skip(function () use ($resource, $timeQueries) { + return Authorization::skip(function () use ($resource, $timeQueries) { return $this->db->count( collection: $this->getCollectionName(), queries: [ @@ -264,7 +265,7 @@ public function getByUserAndEvents( bool $ascending = false, ): array { $timeQueries = $this->buildTimeQueries($after, $before); - $documents = $this->db->getAuthorization()->skip(function () use ($userId, $events, $timeQueries, $limit, $offset, $ascending) { + $documents = Authorization::skip(function () use ($userId, $events, $timeQueries, $limit, $offset, $ascending) { $queries = [ Query::equal('userId', [$userId]), Query::equal('event', $events), @@ -298,7 +299,7 @@ public function countByUserAndEvents( ?\DateTime $before = null, ): int { $timeQueries = $this->buildTimeQueries($after, $before); - return $this->db->getAuthorization()->skip(function () use ($userId, $events, $timeQueries) { + return Authorization::skip(function () use ($userId, $events, $timeQueries) { return $this->db->count( collection: $this->getCollectionName(), queries: [ @@ -328,7 +329,7 @@ public function getByResourceAndEvents( bool $ascending = false, ): array { $timeQueries = $this->buildTimeQueries($after, $before); - $documents = $this->db->getAuthorization()->skip(function () use ($resource, $events, $timeQueries, $limit, $offset, $ascending) { + $documents = Authorization::skip(function () use ($resource, $events, $timeQueries, $limit, $offset, $ascending) { $queries = [ Query::equal('resource', [$resource]), Query::equal('event', $events), @@ -362,7 +363,7 @@ public function countByResourceAndEvents( ?\DateTime $before = null, ): int { $timeQueries = $this->buildTimeQueries($after, $before); - return $this->db->getAuthorization()->skip(function () use ($resource, $events, $timeQueries) { + return Authorization::skip(function () use ($resource, $events, $timeQueries) { return $this->db->count( collection: $this->getCollectionName(), queries: [ @@ -384,7 +385,7 @@ public function countByResourceAndEvents( public function cleanup(\DateTime $datetime): bool { $datetimeString = DateTime::format($datetime); - $this->db->getAuthorization()->skip(function () use ($datetimeString) { + Authorization::skip(function () use ($datetimeString) { do { $removed = $this->db->deleteDocuments($this->getCollectionName(), [ Query::lessThan('time', $datetimeString), From bea15e59f63d1b0fceabf53bf73bed3962d176d5 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 14 Dec 2025 06:56:09 +0000 Subject: [PATCH 03/12] expose attributes and indexes --- src/Audit/Adapter/SQL.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Audit/Adapter/SQL.php b/src/Audit/Adapter/SQL.php index 3b196f2..2c59ffa 100644 --- a/src/Audit/Adapter/SQL.php +++ b/src/Audit/Adapter/SQL.php @@ -21,7 +21,7 @@ abstract class SQL extends Adapter * * @return string */ - protected function getCollectionName(): string + public function getCollectionName(): string { return self::COLLECTION; } @@ -40,7 +40,7 @@ protected function getCollectionName(): string * * @return array> */ - protected function getAttributes(): array + public function getAttributes(): array { return [ [ @@ -124,7 +124,7 @@ protected function getAttributes(): array * * @return array */ - protected function getAttributeDocuments(): array + public function getAttributeDocuments(): array { return array_map(static fn (array $attribute) => new Document($attribute), $this->getAttributes()); } @@ -139,7 +139,7 @@ protected function getAttributeDocuments(): array * * @return array> */ - protected function getIndexes(): array + public function getIndexes(): array { return [ [ @@ -170,7 +170,7 @@ protected function getIndexes(): array * * @return array */ - protected function getIndexDocuments(): array + public function getIndexDocuments(): array { return array_map(static fn (array $index) => new Document($index), $this->getIndexes()); } From f2bb0469ef39346cca97c504db858660b1fc4d94 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 14 Dec 2025 07:00:37 +0000 Subject: [PATCH 04/12] composer update --- composer.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index aee4be3..9746cd9 100644 --- a/composer.lock +++ b/composer.lock @@ -1238,20 +1238,20 @@ }, { "name": "ramsey/uuid", - "version": "4.9.1", + "version": "4.9.2", "source": { "type": "git", "url": "https://github.com/ramsey/uuid.git", - "reference": "81f941f6f729b1e3ceea61d9d014f8b6c6800440" + "reference": "8429c78ca35a09f27565311b98101e2826affde0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/uuid/zipball/81f941f6f729b1e3ceea61d9d014f8b6c6800440", - "reference": "81f941f6f729b1e3ceea61d9d014f8b6c6800440", + "url": "https://api.github.com/repos/ramsey/uuid/zipball/8429c78ca35a09f27565311b98101e2826affde0", + "reference": "8429c78ca35a09f27565311b98101e2826affde0", "shasum": "" }, "require": { - "brick/math": "^0.8.8 || ^0.9 || ^0.10 || ^0.11 || ^0.12 || ^0.13 || ^0.14", + "brick/math": "^0.8.16 || ^0.9 || ^0.10 || ^0.11 || ^0.12 || ^0.13 || ^0.14", "php": "^8.0", "ramsey/collection": "^1.2 || ^2.0" }, @@ -1310,9 +1310,9 @@ ], "support": { "issues": "https://github.com/ramsey/uuid/issues", - "source": "https://github.com/ramsey/uuid/tree/4.9.1" + "source": "https://github.com/ramsey/uuid/tree/4.9.2" }, - "time": "2025-09-04T20:59:21+00:00" + "time": "2025-12-14T04:43:48+00:00" }, { "name": "symfony/deprecation-contracts", From a83dec21b3b9b7fc85fd8cf92563b2fd174a39cb Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 14 Dec 2025 08:29:40 +0000 Subject: [PATCH 05/12] Fix log batch --- src/Audit/Adapter.php | 4 ++-- src/Audit/Adapter/ClickHouse.php | 29 +++-------------------------- src/Audit/Adapter/Database.php | 15 +++++++-------- 3 files changed, 12 insertions(+), 36 deletions(-) diff --git a/src/Audit/Adapter.php b/src/Audit/Adapter.php index a8fea58..1a39d9c 100644 --- a/src/Audit/Adapter.php +++ b/src/Audit/Adapter.php @@ -55,11 +55,11 @@ abstract public function create(array $log): Log; * time: \DateTime|string|null, * data?: array * }> $logs - * @return array + * @return bool * * @throws \Exception */ - abstract public function createBatch(array $logs): array; + abstract public function createBatch(array $logs): bool; /** * Get logs by user ID. diff --git a/src/Audit/Adapter/ClickHouse.php b/src/Audit/Adapter/ClickHouse.php index fb60616..7265adb 100644 --- a/src/Audit/Adapter/ClickHouse.php +++ b/src/Audit/Adapter/ClickHouse.php @@ -500,10 +500,10 @@ public function create(array $log): Log * * @throws Exception */ - public function createBatch(array $logs): array + public function createBatch(array $logs): bool { if (empty($logs)) { - return []; + return true; } $tableName = $this->getTableName(); @@ -579,30 +579,7 @@ public function createBatch(array $logs): array VALUES " . implode(', ', $valueClauses); $this->query($insertSql, $params); - - // Return documents using the same IDs that were inserted - $documents = []; - foreach ($logs as $index => $log) { - $result = [ - '$id' => $ids[$index], - 'userId' => $log['userId'] ?? null, - 'event' => $log['event'], - 'resource' => $log['resource'], - 'userAgent' => $log['userAgent'], - 'ip' => $log['ip'], - 'location' => $log['location'] ?? null, - 'time' => $log['time'], - 'data' => $log['data'] ?? [], - ]; - - if ($this->sharedTables) { - $result['tenant'] = $this->tenant; - } - - $documents[] = new Log($result); - } - - return $documents; + return true; } /** diff --git a/src/Audit/Adapter/Database.php b/src/Audit/Adapter/Database.php index 3e42a4d..b7ee679 100644 --- a/src/Audit/Adapter/Database.php +++ b/src/Audit/Adapter/Database.php @@ -85,23 +85,22 @@ public function create(array $log): Log * @return array * @throws AuthorizationException|\Exception */ - public function createBatch(array $logs): array + public function createBatch(array $logs): bool { - $created = []; - - Authorization::skip(function () use ($logs, &$created) { - foreach ($logs as $log) { + Authorization::skip(function () use ($logs) { + $documents = \array_map(function ($event) { $time = $log['time'] ?? new \DateTime(); if (is_string($time)) { $time = new \DateTime($time); } assert($time instanceof \DateTime); $log['time'] = DateTime::format($time); - $created[] = $this->db->createDocument($this->getCollectionName(), new Document($log)); - } + return new Document($log); + }, $logs); + $this->db->createDocuments($this->getCollectionName(), $documents); }); - return array_map(fn ($doc) => new Log($doc->getArrayCopy()), $created); + return true; } /** From 0191ec161c19cd939a15bf7cf1cf56cb15043919 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 14 Dec 2025 08:32:25 +0000 Subject: [PATCH 06/12] Fix typo --- src/Audit/Adapter/Database.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Audit/Adapter/Database.php b/src/Audit/Adapter/Database.php index b7ee679..01d8e1e 100644 --- a/src/Audit/Adapter/Database.php +++ b/src/Audit/Adapter/Database.php @@ -88,7 +88,7 @@ public function create(array $log): Log public function createBatch(array $logs): bool { Authorization::skip(function () use ($logs) { - $documents = \array_map(function ($event) { + $documents = \array_map(function ($log) { $time = $log['time'] ?? new \DateTime(); if (is_string($time)) { $time = new \DateTime($time); From c0a0d1679231c4c979f950458c273b04971b5f08 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 14 Dec 2025 08:34:27 +0000 Subject: [PATCH 07/12] fix return type --- src/Audit/Audit.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Audit/Audit.php b/src/Audit/Audit.php index 2873edc..f4c0f33 100644 --- a/src/Audit/Audit.php +++ b/src/Audit/Audit.php @@ -75,11 +75,11 @@ public function log(?string $userId, string $event, string $resource, string $us * Add multiple event logs in batch. * * @param array}> $events - * @return array + * @return bool * * @throws \Exception */ - public function logBatch(array $events): array + public function logBatch(array $events): bool { return $this->adapter->createBatch($events); } From 4f77e217c86f0cb27d2b51b5e462411ae3579f80 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 14 Dec 2025 08:49:56 +0000 Subject: [PATCH 08/12] Fix ordering in adatabase adapter --- src/Audit/Adapter/Database.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Audit/Adapter/Database.php b/src/Audit/Adapter/Database.php index 01d8e1e..d52e4af 100644 --- a/src/Audit/Adapter/Database.php +++ b/src/Audit/Adapter/Database.php @@ -152,7 +152,7 @@ public function getByUser( $queries = [ Query::equal('userId', [$userId]), ...$timeQueries, - $ascending ? Query::orderAsc('time') : Query::orderDesc('time'), + $ascending ? Query::orderAsc() : Query::orderDesc(), Query::limit($limit), Query::offset($offset), ]; @@ -208,7 +208,7 @@ public function getByResource( $queries = [ Query::equal('resource', [$resource]), ...$timeQueries, - $ascending ? Query::orderAsc('time') : Query::orderDesc('time'), + $ascending ? Query::orderAsc() : Query::orderDesc(), Query::limit($limit), Query::offset($offset), ]; @@ -269,7 +269,7 @@ public function getByUserAndEvents( Query::equal('userId', [$userId]), Query::equal('event', $events), ...$timeQueries, - $ascending ? Query::orderAsc('time') : Query::orderDesc('time'), + $ascending ? Query::orderAsc() : Query::orderDesc(), Query::limit($limit), Query::offset($offset), ]; @@ -333,7 +333,7 @@ public function getByResourceAndEvents( Query::equal('resource', [$resource]), Query::equal('event', $events), ...$timeQueries, - $ascending ? Query::orderAsc('time') : Query::orderDesc('time'), + $ascending ? Query::orderAsc() : Query::orderDesc(), Query::limit($limit), Query::offset($offset), ]; From e29129bc0741747449087055c3ef69dcd80da355 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 19 Dec 2025 09:29:30 +0000 Subject: [PATCH 09/12] Update database version --- composer.json | 2 +- composer.lock | 44 +++++++++++++++++----------------- src/Audit/Adapter/Database.php | 30 +++++++++++------------ 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/composer.json b/composer.json index 6cba96e..4d00dad 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ }, "require": { "php": ">=8.0", - "utopia-php/database": "3.*", + "utopia-php/database": "4.*", "utopia-php/fetch": "^0.4.2", "utopia-php/validators": "^0.1.0" }, diff --git a/composer.lock b/composer.lock index 9746cd9..33c0384 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": "56a7dbb2d6f7f217b842a1785df2f5d2", + "content-hash": "7e7770e1778658a1376fdd3c1ffd73c3", "packages": [ { "name": "brick/math", @@ -2026,16 +2026,16 @@ }, { "name": "utopia-php/cache", - "version": "0.13.1", + "version": "0.13.2", "source": { "type": "git", "url": "https://github.com/utopia-php/cache.git", - "reference": "97220cb3b3822b166ee016d1646e2ae2815dc540" + "reference": "5768498c9f451482f0bf3eede4d6452ddcd4a0f6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cache/zipball/97220cb3b3822b166ee016d1646e2ae2815dc540", - "reference": "97220cb3b3822b166ee016d1646e2ae2815dc540", + "url": "https://api.github.com/repos/utopia-php/cache/zipball/5768498c9f451482f0bf3eede4d6452ddcd4a0f6", + "reference": "5768498c9f451482f0bf3eede4d6452ddcd4a0f6", "shasum": "" }, "require": { @@ -2044,7 +2044,7 @@ "ext-redis": "*", "php": ">=8.0", "utopia-php/pools": "0.8.*", - "utopia-php/telemetry": "0.1.*" + "utopia-php/telemetry": "*" }, "require-dev": { "laravel/pint": "1.2.*", @@ -2072,9 +2072,9 @@ ], "support": { "issues": "https://github.com/utopia-php/cache/issues", - "source": "https://github.com/utopia-php/cache/tree/0.13.1" + "source": "https://github.com/utopia-php/cache/tree/0.13.2" }, - "time": "2025-05-09T14:43:52+00:00" + "time": "2025-12-17T08:55:43+00:00" }, { "name": "utopia-php/compression", @@ -2124,16 +2124,16 @@ }, { "name": "utopia-php/database", - "version": "3.6.0", + "version": "4.3.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "af15066255a5fd7bd2926de37bcbf3d8500fc155" + "reference": "fe7a1326ad623609e65587fe8c01a630a7075fee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/af15066255a5fd7bd2926de37bcbf3d8500fc155", - "reference": "af15066255a5fd7bd2926de37bcbf3d8500fc155", + "url": "https://api.github.com/repos/utopia-php/database/zipball/fe7a1326ad623609e65587fe8c01a630a7075fee", + "reference": "fe7a1326ad623609e65587fe8c01a630a7075fee", "shasum": "" }, "require": { @@ -2176,9 +2176,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/3.6.0" + "source": "https://github.com/utopia-php/database/tree/4.3.0" }, - "time": "2025-12-08T05:23:04+00:00" + "time": "2025-11-14T03:43:10+00:00" }, { "name": "utopia-php/fetch", @@ -2330,21 +2330,21 @@ }, { "name": "utopia-php/pools", - "version": "0.8.2", + "version": "0.8.3", "source": { "type": "git", "url": "https://github.com/utopia-php/pools.git", - "reference": "05c67aba42eb68ac65489cc1e7fc5db83db2dd4d" + "reference": "ad7d6ba946376e81c603204285ce9a674b6502b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/pools/zipball/05c67aba42eb68ac65489cc1e7fc5db83db2dd4d", - "reference": "05c67aba42eb68ac65489cc1e7fc5db83db2dd4d", + "url": "https://api.github.com/repos/utopia-php/pools/zipball/ad7d6ba946376e81c603204285ce9a674b6502b8", + "reference": "ad7d6ba946376e81c603204285ce9a674b6502b8", "shasum": "" }, "require": { - "php": ">=8.3", - "utopia-php/telemetry": "0.1.*" + "php": ">=8.4", + "utopia-php/telemetry": "*" }, "require-dev": { "laravel/pint": "1.*", @@ -2376,9 +2376,9 @@ ], "support": { "issues": "https://github.com/utopia-php/pools/issues", - "source": "https://github.com/utopia-php/pools/tree/0.8.2" + "source": "https://github.com/utopia-php/pools/tree/0.8.3" }, - "time": "2025-04-17T02:04:54+00:00" + "time": "2025-12-17T09:35:18+00:00" }, { "name": "utopia-php/telemetry", diff --git a/src/Audit/Adapter/Database.php b/src/Audit/Adapter/Database.php index d52e4af..2963e9e 100644 --- a/src/Audit/Adapter/Database.php +++ b/src/Audit/Adapter/Database.php @@ -71,7 +71,7 @@ public function setup(): void public function create(array $log): Log { $log['time'] = $log['time'] ?? DateTime::now(); - $document = Authorization::skip(function () use ($log) { + $document = $this->db->getAuthorization()->skip(function () use ($log) { return $this->db->createDocument($this->getCollectionName(), new Document($log)); }); @@ -87,7 +87,7 @@ public function create(array $log): Log */ public function createBatch(array $logs): bool { - Authorization::skip(function () use ($logs) { + $this->db->getAuthorization()->skip(function () use ($logs) { $documents = \array_map(function ($log) { $time = $log['time'] ?? new \DateTime(); if (is_string($time)) { @@ -148,7 +148,7 @@ public function getByUser( bool $ascending = false, ): array { $timeQueries = $this->buildTimeQueries($after, $before); - $documents = Authorization::skip(function () use ($userId, $timeQueries, $limit, $offset, $ascending) { + $documents = $this->db->getAuthorization()->skip(function () use ($userId, $timeQueries, $limit, $offset, $ascending) { $queries = [ Query::equal('userId', [$userId]), ...$timeQueries, @@ -163,7 +163,7 @@ public function getByUser( ); }); - return array_map(fn ($doc) => new Log($doc->getArrayCopy()), $documents); + return array_map(fn($doc) => new Log($doc->getArrayCopy()), $documents); } /** @@ -177,7 +177,7 @@ public function countByUser( ?\DateTime $before = null, ): int { $timeQueries = $this->buildTimeQueries($after, $before); - return Authorization::skip(function () use ($userId, $timeQueries) { + return $this->db->getAuthorization()->skip(function () use ($userId, $timeQueries) { return $this->db->count( collection: $this->getCollectionName(), queries: [ @@ -204,7 +204,7 @@ public function getByResource( bool $ascending = false, ): array { $timeQueries = $this->buildTimeQueries($after, $before); - $documents = Authorization::skip(function () use ($resource, $timeQueries, $limit, $offset, $ascending) { + $documents = $this->db->getAuthorization()->skip(function () use ($resource, $timeQueries, $limit, $offset, $ascending) { $queries = [ Query::equal('resource', [$resource]), ...$timeQueries, @@ -219,7 +219,7 @@ public function getByResource( ); }); - return array_map(fn ($doc) => new Log($doc->getArrayCopy()), $documents); + return array_map(fn($doc) => new Log($doc->getArrayCopy()), $documents); } /** @@ -235,7 +235,7 @@ public function countByResource( ?\DateTime $before = null, ): int { $timeQueries = $this->buildTimeQueries($after, $before); - return Authorization::skip(function () use ($resource, $timeQueries) { + return $this->db->getAuthorization()->skip(function () use ($resource, $timeQueries) { return $this->db->count( collection: $this->getCollectionName(), queries: [ @@ -264,7 +264,7 @@ public function getByUserAndEvents( bool $ascending = false, ): array { $timeQueries = $this->buildTimeQueries($after, $before); - $documents = Authorization::skip(function () use ($userId, $events, $timeQueries, $limit, $offset, $ascending) { + $documents = $this->db->getAuthorization()->skip(function () use ($userId, $events, $timeQueries, $limit, $offset, $ascending) { $queries = [ Query::equal('userId', [$userId]), Query::equal('event', $events), @@ -280,7 +280,7 @@ public function getByUserAndEvents( ); }); - return array_map(fn ($doc) => new Log($doc->getArrayCopy()), $documents); + return array_map(fn($doc) => new Log($doc->getArrayCopy()), $documents); } /** @@ -298,7 +298,7 @@ public function countByUserAndEvents( ?\DateTime $before = null, ): int { $timeQueries = $this->buildTimeQueries($after, $before); - return Authorization::skip(function () use ($userId, $events, $timeQueries) { + return $this->db->getAuthorization()->skip(function () use ($userId, $events, $timeQueries) { return $this->db->count( collection: $this->getCollectionName(), queries: [ @@ -328,7 +328,7 @@ public function getByResourceAndEvents( bool $ascending = false, ): array { $timeQueries = $this->buildTimeQueries($after, $before); - $documents = Authorization::skip(function () use ($resource, $events, $timeQueries, $limit, $offset, $ascending) { + $documents = $this->db->getAuthorization()->skip(function () use ($resource, $events, $timeQueries, $limit, $offset, $ascending) { $queries = [ Query::equal('resource', [$resource]), Query::equal('event', $events), @@ -344,7 +344,7 @@ public function getByResourceAndEvents( ); }); - return array_map(fn ($doc) => new Log($doc->getArrayCopy()), $documents); + return array_map(fn($doc) => new Log($doc->getArrayCopy()), $documents); } /** @@ -362,7 +362,7 @@ public function countByResourceAndEvents( ?\DateTime $before = null, ): int { $timeQueries = $this->buildTimeQueries($after, $before); - return Authorization::skip(function () use ($resource, $events, $timeQueries) { + return $this->db->getAuthorization()->skip(function () use ($resource, $events, $timeQueries) { return $this->db->count( collection: $this->getCollectionName(), queries: [ @@ -384,7 +384,7 @@ public function countByResourceAndEvents( public function cleanup(\DateTime $datetime): bool { $datetimeString = DateTime::format($datetime); - Authorization::skip(function () use ($datetimeString) { + $this->db->getAuthorization()->skip(function () use ($datetimeString) { do { $removed = $this->db->deleteDocuments($this->getCollectionName(), [ Query::lessThan('time', $datetimeString), From 5254d12edc66207db14e528604e4be4c98e89a78 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 19 Dec 2025 09:31:10 +0000 Subject: [PATCH 10/12] Format --- src/Audit/Adapter/Database.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Audit/Adapter/Database.php b/src/Audit/Adapter/Database.php index 2963e9e..ffbad7f 100644 --- a/src/Audit/Adapter/Database.php +++ b/src/Audit/Adapter/Database.php @@ -10,7 +10,6 @@ use Utopia\Database\Exception\Duplicate as DuplicateException; use Utopia\Database\Exception\Timeout; use Utopia\Database\Query; -use Utopia\Database\Validator\Authorization; use Utopia\Exception; /** @@ -163,7 +162,7 @@ public function getByUser( ); }); - return array_map(fn($doc) => new Log($doc->getArrayCopy()), $documents); + return array_map(fn ($doc) => new Log($doc->getArrayCopy()), $documents); } /** @@ -219,7 +218,7 @@ public function getByResource( ); }); - return array_map(fn($doc) => new Log($doc->getArrayCopy()), $documents); + return array_map(fn ($doc) => new Log($doc->getArrayCopy()), $documents); } /** @@ -280,7 +279,7 @@ public function getByUserAndEvents( ); }); - return array_map(fn($doc) => new Log($doc->getArrayCopy()), $documents); + return array_map(fn ($doc) => new Log($doc->getArrayCopy()), $documents); } /** @@ -344,7 +343,7 @@ public function getByResourceAndEvents( ); }); - return array_map(fn($doc) => new Log($doc->getArrayCopy()), $documents); + return array_map(fn ($doc) => new Log($doc->getArrayCopy()), $documents); } /** From 1c7ff3a4ec238efeb6e30f60e0b83c6bacec4718 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 19 Dec 2025 09:34:00 +0000 Subject: [PATCH 11/12] Fix codeql --- src/Audit/Adapter/Database.php | 2 +- tests/Audit/Adapter/ClickHouseTest.php | 2 +- tests/Audit/AuditBase.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Audit/Adapter/Database.php b/src/Audit/Adapter/Database.php index ffbad7f..ddc5986 100644 --- a/src/Audit/Adapter/Database.php +++ b/src/Audit/Adapter/Database.php @@ -81,7 +81,7 @@ public function create(array $log): Log * Create multiple audit log entries in batch. * * @param array> $logs - * @return array + * @return bool * @throws AuthorizationException|\Exception */ public function createBatch(array $logs): bool diff --git a/tests/Audit/Adapter/ClickHouseTest.php b/tests/Audit/Adapter/ClickHouseTest.php index 947ec8a..2872fbd 100644 --- a/tests/Audit/Adapter/ClickHouseTest.php +++ b/tests/Audit/Adapter/ClickHouseTest.php @@ -310,7 +310,7 @@ public function testBatchOperationsWithSpecialCharacters(): void ]; $result = $this->audit->logBatch($batchEvents); - $this->assertEquals(1, count($result)); + $this->assertTrue($result); // Verify retrieval $logs = $this->audit->getLogsByUser('user`with`backticks'); diff --git a/tests/Audit/AuditBase.php b/tests/Audit/AuditBase.php index 301a7c8..bac8fa5 100644 --- a/tests/Audit/AuditBase.php +++ b/tests/Audit/AuditBase.php @@ -216,7 +216,7 @@ public function testLogByBatch(): void // Test batch insertion $result = $this->audit->logBatch($batchEvents); $this->assertIsArray($result); - $this->assertEquals(4, count($result)); + $this->assertTrue($result); // Verify the number of logs inserted $logs = $this->audit->getLogsByUser($userId); @@ -296,7 +296,7 @@ public function testLargeBatchInsert(): void // Insert batch $result = $this->audit->logBatch($batchEvents); - $this->assertEquals(50, \count($result)); + $this->assertTrue($result); // Verify all were inserted $count = $this->audit->countLogsByUser('largebatchuser'); From 4e69f0b541da1673f9ca6fdcdff24ef22b2c7a61 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 19 Dec 2025 09:42:10 +0000 Subject: [PATCH 12/12] Fix assertion --- tests/Audit/AuditBase.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Audit/AuditBase.php b/tests/Audit/AuditBase.php index bac8fa5..25b90cb 100644 --- a/tests/Audit/AuditBase.php +++ b/tests/Audit/AuditBase.php @@ -215,7 +215,6 @@ public function testLogByBatch(): void // Test batch insertion $result = $this->audit->logBatch($batchEvents); - $this->assertIsArray($result); $this->assertTrue($result); // Verify the number of logs inserted