diff --git a/composer.lock b/composer.lock index 3076c39..33c0384 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", @@ -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", @@ -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", @@ -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", @@ -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.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 23e4505..ddc5986 100644 --- a/src/Audit/Adapter/Database.php +++ b/src/Audit/Adapter/Database.php @@ -81,26 +81,25 @@ 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): array + public function createBatch(array $logs): bool { - $created = []; - - $this->db->getAuthorization()->skip(function () use ($logs, &$created) { - foreach ($logs as $log) { + $this->db->getAuthorization()->skip(function () use ($logs) { + $documents = \array_map(function ($log) { $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; } /** @@ -152,7 +151,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 +207,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 +268,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 +332,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), ]; 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()); } 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); } 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..25b90cb 100644 --- a/tests/Audit/AuditBase.php +++ b/tests/Audit/AuditBase.php @@ -215,8 +215,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 +295,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');