From 52a1d0bfb68a35e95b182319c12d79ec1f5a6cf9 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 15 Sep 2026 09:58:45 +0000 Subject: [PATCH] fix(executions): localize query attributes Co-authored-by: Torsten Dittmann --- .../Database/Validator/Queries/Base.php | 22 +++--- .../Database/Validator/Queries/Executions.php | 72 ++++++++++++++++--- .../Database/Validator/Queries/Logs.php | 4 +- 3 files changed, 73 insertions(+), 25 deletions(-) diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php index 056eb467b4..688a67a20d 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php @@ -18,24 +18,22 @@ class Base extends Queries /** * Expression constructor * - * @param string|array $collection + * @param string $collection * @param string[] $allowedAttributes * @throws \Exception */ - public function __construct(string|array $collection, array $allowedAttributes) + public function __construct(string $collection, array $allowedAttributes) { - if (\is_string($collection)) { - $config = Config::getParam('collections', []); + $config = Config::getParam('collections', []); - $collections = \array_merge( - $config['projects'], - $config['buckets'], - $config['databases'], - $config['console'] - ); + $collections = \array_merge( + $config['projects'], + $config['buckets'], + $config['databases'], + $config['console'] + ); - $collection = $collections[$collection]; - } + $collection = $collections[$collection]; $allowedAttributesLookup = []; foreach ($allowedAttributes as $attribute) { diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Executions.php b/src/Appwrite/Utopia/Database/Validator/Queries/Executions.php index 92b915daf8..36fefa010b 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Executions.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Executions.php @@ -3,17 +3,24 @@ namespace Appwrite\Utopia\Database\Validator\Queries; use Utopia\Database\Database; +use Utopia\Database\Document; +use Utopia\Database\Validator\Queries; +use Utopia\Database\Validator\Query\Cursor; +use Utopia\Database\Validator\Query\Filter; +use Utopia\Database\Validator\Query\Limit; +use Utopia\Database\Validator\Query\Offset; +use Utopia\Database\Validator\Query\Order; -class Executions extends Base +class Executions extends Queries { - public const ATTRIBUTES = [ - ['$id' => 'trigger', 'type' => Database::VAR_STRING, 'array' => false], - ['$id' => 'status', 'type' => Database::VAR_STRING, 'array' => false], - ['$id' => 'responseStatusCode', 'type' => Database::VAR_INTEGER, 'array' => false], - ['$id' => 'duration', 'type' => Database::VAR_FLOAT, 'array' => false], - ['$id' => 'requestMethod', 'type' => Database::VAR_STRING, 'array' => false], - ['$id' => 'requestPath', 'type' => Database::VAR_STRING, 'array' => false], - ['$id' => 'deploymentId', 'type' => Database::VAR_STRING, 'array' => false], + protected const ATTRIBUTE_TYPES = [ + 'trigger' => Database::VAR_STRING, + 'status' => Database::VAR_STRING, + 'responseStatusCode' => Database::VAR_INTEGER, + 'duration' => Database::VAR_FLOAT, + 'requestMethod' => Database::VAR_STRING, + 'requestPath' => Database::VAR_STRING, + 'deploymentId' => Database::VAR_STRING, ]; public const ALLOWED_ATTRIBUTES = [ @@ -30,8 +37,51 @@ class Executions extends Base * Expression constructor * */ - public function __construct() + public function __construct(array $allowedAttributes = self::ALLOWED_ATTRIBUTES) { - parent::__construct(['attributes' => self::ATTRIBUTES], self::ALLOWED_ATTRIBUTES); + $attributes = []; + foreach ($allowedAttributes as $attribute) { + $attributes[] = new Document([ + 'key' => $attribute, + 'type' => self::ATTRIBUTE_TYPES[$attribute], + 'array' => false, + ]); + } + + $attributes = [ + ...$attributes, + new Document([ + 'key' => '$id', + 'type' => Database::VAR_STRING, + 'array' => false, + ]), + new Document([ + 'key' => '$createdAt', + 'type' => Database::VAR_DATETIME, + 'array' => false, + ]), + new Document([ + 'key' => '$updatedAt', + 'type' => Database::VAR_DATETIME, + 'array' => false, + ]), + new Document([ + 'key' => '$sequence', + 'type' => Database::VAR_INTEGER, + 'array' => false, + ]), + ]; + + parent::__construct([ + new Limit(), + new Offset(), + new Cursor(), + new Filter( + attributes: $attributes, + idAttributeType: Database::VAR_INTEGER, + maxValuesCount: APP_DATABASE_QUERY_MAX_VALUES + ), + new Order($attributes), + ]); } } diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Logs.php b/src/Appwrite/Utopia/Database/Validator/Queries/Logs.php index ab1982c29f..302fe672a7 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Logs.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Logs.php @@ -2,7 +2,7 @@ namespace Appwrite\Utopia\Database\Validator\Queries; -class Logs extends Base +class Logs extends Executions { public const ALLOWED_ATTRIBUTES = [ 'status', @@ -19,6 +19,6 @@ class Logs extends Base */ public function __construct() { - parent::__construct(['attributes' => Executions::ATTRIBUTES], self::ALLOWED_ATTRIBUTES); + parent::__construct(self::ALLOWED_ATTRIBUTES); } }