Skip to content

Commit 106da41

Browse files
committed
Pull main
1 parent bf4219b commit 106da41

15 files changed

Lines changed: 550 additions & 106 deletions

File tree

composer.lock

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Database/Adapter/MariaDB.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function delete(string $name): bool
6161
$sql = "DROP DATABASE `{$name}`;";
6262

6363
$sql = $this->trigger(Database::EVENT_DATABASE_DELETE, $sql);
64-
64+
var_dump($sql);
6565
return $this->getPDO()
6666
->prepare($sql)
6767
->execute();

src/Database/Adapter/SQL.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public function exists(string $database, ?string $collection = null): bool
173173
$stmt->execute();
174174
$document = $stmt->fetchAll();
175175
$stmt->closeCursor();
176+
var_dump($document);
176177
} catch (PDOException $e) {
177178
$e = $this->processException($e);
178179

src/Database/Database.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6569,7 +6569,7 @@ public function getSchemaAttributes(string $collection): array
65696569
/**
65706570
* @param string $collectionId
65716571
* @param string|null $documentId
6572-
* @param array<string> $selects
6572+
* @param array<Query> $selects
65736573
* @return array{0: ?string, 1: ?string, 2: ?string}
65746574
*/
65756575
public function getCacheKeys(string $collectionId, ?string $documentId = null, array $selects = []): array
@@ -6597,7 +6597,7 @@ public function getCacheKeys(string $collectionId, ?string $documentId = null, a
65976597
$documentKey = $documentHashKey = "{$collectionKey}:{$documentId}";
65986598

65996599
if (!empty($selects)) {
6600-
$documentHashKey = $documentKey . ':' . \md5(\implode($selects));
6600+
$documentHashKey = $documentKey . ':' . \md5(\serialize($selects));
66016601
}
66026602
}
66036603

src/Database/Query.php

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,25 @@ class Query
8181
self::TYPE_OR,
8282
];
8383

84+
protected const FILTER_TYPES = [
85+
self::TYPE_EQUAL,
86+
self::TYPE_NOT_EQUAL,
87+
self::TYPE_LESSER,
88+
self::TYPE_LESSER_EQUAL,
89+
self::TYPE_GREATER,
90+
self::TYPE_GREATER_EQUAL,
91+
self::TYPE_CONTAINS,
92+
self::TYPE_SEARCH,
93+
self::TYPE_IS_NULL,
94+
self::TYPE_IS_NOT_NULL,
95+
self::TYPE_BETWEEN,
96+
self::TYPE_STARTS_WITH,
97+
self::TYPE_ENDS_WITH,
98+
self::TYPE_AND,
99+
self::TYPE_OR,
100+
self::TYPE_RELATION_EQUAL,
101+
];
102+
84103
protected string $method = '';
85104
protected string $collection = '';
86105
protected string $alias = '';
@@ -844,24 +863,7 @@ public function getCursorDocument(?Query $query): Document
844863
*/
845864
public static function getFilterQueries(array $queries): array
846865
{
847-
return self::getByType($queries, [
848-
self::TYPE_EQUAL,
849-
self::TYPE_NOT_EQUAL,
850-
self::TYPE_LESSER,
851-
self::TYPE_LESSER_EQUAL,
852-
self::TYPE_GREATER,
853-
self::TYPE_GREATER_EQUAL,
854-
self::TYPE_CONTAINS,
855-
self::TYPE_SEARCH,
856-
self::TYPE_IS_NULL,
857-
self::TYPE_IS_NOT_NULL,
858-
self::TYPE_BETWEEN,
859-
self::TYPE_STARTS_WITH,
860-
self::TYPE_ENDS_WITH,
861-
self::TYPE_AND,
862-
self::TYPE_OR,
863-
self::TYPE_RELATION_EQUAL,
864-
]);
866+
return self::getByType($queries, self::FILTER_TYPES);
865867
}
866868

867869
/**
@@ -879,7 +881,7 @@ public static function getFilterQueries(array $queries): array
879881
* cursorDirection: string|null
880882
* }
881883
*/
882-
public static function groupByType(array $queries): array
884+
public static function groupByType_deprecated(array $queries): array
883885
{
884886
$filters = [];
885887
$joins = [];
@@ -996,6 +998,11 @@ public function isJoin(): bool
996998
return false;
997999
}
9981000

1001+
public static function isFilter(string $method): bool
1002+
{
1003+
return in_array($method, self::FILTER_TYPES);
1004+
}
1005+
9991006
public function onArray(): bool
10001007
{
10011008
return $this->onArray;

src/Database/Validator/Queries/V2.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,6 @@ public function isValid($value, string $scope = ''): bool
247247
case Query::TYPE_SELECT:
248248
$this->validateSelect($query);
249249

250-
break;
251-
// case Query::TYPE_SELECTION:
252-
// $this->validateSelections($query);
253-
254250
break;
255251
case Query::TYPE_ORDER_ASC:
256252
case Query::TYPE_ORDER_DESC:
@@ -404,6 +400,9 @@ protected function validateValues(string $attributeId, string $alias, array $val
404400

405401
$attribute = $this->schema[$collection->getId()][$attributeId];
406402

403+
$array = $attribute['array'] ?? false;
404+
$filters = $attribute['filters'] ?? [];
405+
407406
foreach ($values as $value) {
408407

409408
$validator = null;
@@ -466,8 +465,6 @@ protected function validateValues(string $attributeId, string $alias, array $val
466465
}
467466
}
468467

469-
$array = $attribute['array'] ?? false;
470-
471468
if (
472469
! $array &&
473470
$method === Query::TYPE_CONTAINS &&
@@ -482,6 +479,10 @@ protected function validateValues(string $attributeId, string $alias, array $val
482479
) {
483480
throw new \Exception('Invalid query: Cannot query '.$method.' on attribute "'.$attributeId.'" because it is an array.');
484481
}
482+
483+
if (Query::isFilter($method) && \in_array('encrypt', $filters)) {
484+
throw new \Exception('Cannot query encrypted attribute: ' . $attributeId);
485+
}
485486
}
486487

487488
/**

tests/e2e/Adapter/Base.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Tests\E2E\Adapter\Scopes\CollectionTests;
88
use Tests\E2E\Adapter\Scopes\DocumentTests;
99
use Tests\E2E\Adapter\Scopes\GeneralTests;
10+
use Tests\E2E\Adapter\Scopes\JoinsTests;
1011
use Tests\E2E\Adapter\Scopes\IndexTests;
1112
use Tests\E2E\Adapter\Scopes\PermissionTests;
1213
use Tests\E2E\Adapter\Scopes\RelationshipTests;
@@ -21,6 +22,7 @@ abstract class Base extends TestCase
2122
use DocumentTests;
2223
use AttributeTests;
2324
use IndexTests;
25+
use JoinsTests;
2426
use PermissionTests;
2527
use RelationshipTests;
2628
use GeneralTests;

tests/e2e/Adapter/Scopes/AttributeTests.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public function testAttributeNamesWithDots(): void
219219
));
220220

221221
$document = static::getDatabase()->find('dots.parent', [
222-
Query::select(['dots.name']),
222+
Query::select('dots.name'),
223223
]);
224224
$this->assertEmpty($document);
225225

@@ -260,7 +260,7 @@ public function testAttributeNamesWithDots(): void
260260
]));
261261

262262
$documents = static::getDatabase()->find('dots.parent', [
263-
Query::select(['*']),
263+
Query::select('*'),
264264
]);
265265

266266
$this->assertEquals('Bill clinton', $documents[0]['dots.name']);
@@ -1598,6 +1598,9 @@ public function testCreateDatetime(): void
15981598
'Tue Dec 31 2024',
15991599
];
16001600

1601+
/**
1602+
* ConvertQueries method will fix the dates
1603+
*/
16011604
foreach ($validDates as $date) {
16021605
$docs = static::getDatabase()->find('datetime', [
16031606
Query::equal('$createdAt', [$date])

0 commit comments

Comments
 (0)