@@ -1010,7 +1010,7 @@ public function setMaxQueryValues(int $max): self
10101010
10111011 public function getMaxQueryValues (): int
10121012 {
1013- return $ this ->maxQueryValues ;
1013+ return $ this ->maxQueryValues ;
10141014 }
10151015
10161016 /**
@@ -1395,8 +1395,7 @@ public function deleteCollection(string $id): bool
13951395
13961396 $ relationships = \array_filter (
13971397 $ collection ->getAttribute ('attributes ' ),
1398- fn ($ attribute ) =>
1399- $ attribute ->getAttribute ('type ' ) === Database::VAR_RELATIONSHIP
1398+ fn ($ attribute ) => $ attribute ->getAttribute ('type ' ) === Database::VAR_RELATIONSHIP
14001399 );
14011400
14021401 foreach ($ relationships as $ relationship ) {
@@ -1511,7 +1510,7 @@ public function createAttribute(string $collection, string $id, string $type, in
15111510 case self ::VAR_RELATIONSHIP :
15121511 break ;
15131512 default :
1514- throw new DatabaseException ('Unknown attribute type: ' . $ type . '. Must be one of ' . self ::VAR_STRING . ', ' . self ::VAR_INTEGER . ', ' . self ::VAR_FLOAT . ', ' . self ::VAR_BOOLEAN . ', ' . self ::VAR_DATETIME . ', ' . self ::VAR_RELATIONSHIP );
1513+ throw new DatabaseException ('Unknown attribute type: ' . $ type . '. Must be one of ' . self ::VAR_STRING . ', ' . self ::VAR_INTEGER . ', ' . self ::VAR_FLOAT . ', ' . self ::VAR_BOOLEAN . ', ' . self ::VAR_DATETIME . ', ' . self ::VAR_RELATIONSHIP );
15151514 }
15161515
15171516 // Only execute when $default is given
@@ -1569,8 +1568,8 @@ protected function getRequiredFilters(?string $type): array
15691568 * @param string $type Type of the attribute
15701569 * @param mixed $default Default value of the attribute
15711570 *
1572- * @throws DatabaseException
15731571 * @return void
1572+ * @throws DatabaseException
15741573 */
15751574 protected function validateDefaultTypes (string $ type , mixed $ default ): void
15761575 {
@@ -1603,7 +1602,7 @@ protected function validateDefaultTypes(string $type, mixed $default): void
16031602 }
16041603 break ;
16051604 default :
1606- throw new DatabaseException ('Unknown attribute type: ' . $ type . '. Must be one of ' . self ::VAR_STRING . ', ' . self ::VAR_INTEGER . ', ' . self ::VAR_FLOAT . ', ' . self ::VAR_BOOLEAN . ', ' . self ::VAR_DATETIME . ', ' . self ::VAR_RELATIONSHIP );
1605+ throw new DatabaseException ('Unknown attribute type: ' . $ type . '. Must be one of ' . self ::VAR_STRING . ', ' . self ::VAR_INTEGER . ', ' . self ::VAR_FLOAT . ', ' . self ::VAR_BOOLEAN . ', ' . self ::VAR_DATETIME . ', ' . self ::VAR_RELATIONSHIP );
16071606 }
16081607 }
16091608
@@ -1845,7 +1844,7 @@ public function updateAttribute(string $collection, string $id, ?string $type =
18451844 }
18461845 break ;
18471846 default :
1848- throw new DatabaseException ('Unknown attribute type: ' . $ type . '. Must be one of ' . self ::VAR_STRING . ', ' . self ::VAR_INTEGER . ', ' . self ::VAR_FLOAT . ', ' . self ::VAR_BOOLEAN . ', ' . self ::VAR_DATETIME . ', ' . self ::VAR_RELATIONSHIP );
1847+ throw new DatabaseException ('Unknown attribute type: ' . $ type . '. Must be one of ' . self ::VAR_STRING . ', ' . self ::VAR_INTEGER . ', ' . self ::VAR_FLOAT . ', ' . self ::VAR_BOOLEAN . ', ' . self ::VAR_DATETIME . ', ' . self ::VAR_RELATIONSHIP );
18491848 }
18501849
18511850 /** Ensure required filters for the attribute are passed */
@@ -1912,7 +1911,7 @@ public function updateAttribute(string $collection, string $id, ?string $type =
19121911 $ this ->adapter ->getSupportForCastIndexArray (),
19131912 );
19141913
1915- if (! $ validator ->isValid ($ attribute )) {
1914+ if (!$ validator ->isValid ($ attribute )) {
19161915 throw new DependencyException ($ validator ->getDescription ());
19171916 }
19181917 }
@@ -1955,8 +1954,8 @@ public function updateAttribute(string $collection, string $id, ?string $type =
19551954 * @param Document $collection
19561955 * @param Document $attribute
19571956 *
1958- * @throws LimitException
19591957 * @return bool
1958+ * @throws LimitException
19601959 */
19611960 public function checkAttribute (Document $ collection , Document $ attribute ): bool
19621961 {
@@ -2021,7 +2020,7 @@ public function deleteAttribute(string $collection, string $id): bool
20212020 $ this ->adapter ->getSupportForCastIndexArray (),
20222021 );
20232022
2024- if (! $ validator ->isValid ($ attribute )) {
2023+ if (!$ validator ->isValid ($ attribute )) {
20252024 throw new DependencyException ($ validator ->getDescription ());
20262025 }
20272026 }
@@ -2108,7 +2107,7 @@ public function renameAttribute(string $collection, string $old, string $new): b
21082107 $ this ->adapter ->getSupportForCastIndexArray (),
21092108 );
21102109
2111- if (! $ validator ->isValid ($ attribute )) {
2110+ if (!$ validator ->isValid ($ attribute )) {
21122111 throw new DependencyException ($ validator ->getDescription ());
21132112 }
21142113 }
@@ -2349,8 +2348,8 @@ public function createRelationship(
23492348 * @throws DatabaseException
23502349 */
23512350 public function updateRelationship (
2352- string $ collection ,
2353- string $ id ,
2351+ string $ collection ,
2352+ string $ id ,
23542353 ?string $ newKey = null ,
23552354 ?string $ newTwoWayKey = null ,
23562355 ?bool $ twoWay = null ,
@@ -2476,8 +2475,7 @@ function ($index) use ($newKey) {
24762475 }
24772476 );
24782477 $ this ->silent (
2479- fn () =>
2480- $ this ->renameIndex ($ collection , '_index_ ' . $ key , '_index_ ' . $ newKey )
2478+ fn () => $ this ->renameIndex ($ collection , '_index_ ' . $ key , '_index_ ' . $ newKey )
24812479 );
24822480 };
24832481
@@ -3050,8 +3048,7 @@ public function getDocument(string $collection, string $id, array $queries = [],
30503048
30513049 $ relationships = \array_filter (
30523050 $ collection ->getAttribute ('attributes ' , []),
3053- fn ($ attribute ) =>
3054- $ attribute ['type ' ] === Database::VAR_RELATIONSHIP
3051+ fn ($ attribute ) => $ attribute ['type ' ] === Database::VAR_RELATIONSHIP
30553052 );
30563053
30573054 // Don't save to cache if it's part of a relationship
@@ -3533,8 +3530,7 @@ private function createDocumentRelationships(Document $collection, Document $doc
35333530
35343531 $ relationships = \array_filter (
35353532 $ attributes ,
3536- fn ($ attribute ) =>
3537- $ attribute ['type ' ] === Database::VAR_RELATIONSHIP
3533+ fn ($ attribute ) => $ attribute ['type ' ] === Database::VAR_RELATIONSHIP
35383534 );
35393535
35403536 $ stackCount = count ($ this ->relationshipWriteStack );
@@ -3868,8 +3864,7 @@ public function updateDocument(string $collection, string $id, Document $documen
38683864 $ document = $ this ->withTransaction (function () use ($ collection , $ id , $ document ) {
38693865 $ time = DateTime::now ();
38703866 $ old = Authorization::skip (fn () => $ this ->silent (
3871- fn () =>
3872- $ this ->getDocument ($ collection ->getId (), $ id , forUpdate: true )
3867+ fn () => $ this ->getDocument ($ collection ->getId (), $ id , forUpdate: true )
38733868 ));
38743869
38753870 $ document = \array_merge ($ old ->getArrayCopy (), $ document ->getArrayCopy ());
@@ -4145,7 +4140,7 @@ public function updateDocuments(string $collection, Document $updates, array $qu
41454140 Query::limit ($ batchSize )
41464141 ];
41474142
4148- if (! empty ($ lastDocument )) {
4143+ if (!empty ($ lastDocument )) {
41494144 $ new [] = Query::cursorAfter ($ lastDocument );
41504145 }
41514146
@@ -4245,14 +4240,14 @@ private function updateDocumentRelationships(Document $collection, Document $old
42454240 $ value = $ document ->getAttribute ($ key );
42464241 $ oldValue = $ old ->getAttribute ($ key );
42474242 $ relatedCollection = $ this ->getCollection ($ relationship ['options ' ]['relatedCollection ' ]);
4248- $ relationType = (string ) $ relationship ['options ' ]['relationType ' ];
4249- $ twoWay = (bool ) $ relationship ['options ' ]['twoWay ' ];
4250- $ twoWayKey = (string ) $ relationship ['options ' ]['twoWayKey ' ];
4251- $ side = (string ) $ relationship ['options ' ]['side ' ];
4243+ $ relationType = (string )$ relationship ['options ' ]['relationType ' ];
4244+ $ twoWay = (bool )$ relationship ['options ' ]['twoWay ' ];
4245+ $ twoWayKey = (string )$ relationship ['options ' ]['twoWayKey ' ];
4246+ $ side = (string )$ relationship ['options ' ]['side ' ];
42524247
42534248 if ($ oldValue == $ value ) {
42544249 if (
4255- ($ relationType === Database::RELATION_ONE_TO_ONE ||
4250+ ($ relationType === Database::RELATION_ONE_TO_ONE ||
42564251 ($ relationType === Database::RELATION_MANY_TO_ONE && $ side === Database::RELATION_SIDE_PARENT )) &&
42574252 $ value instanceof Document
42584253 ) {
@@ -4374,8 +4369,7 @@ private function updateDocumentRelationships(Document $collection, Document $old
43744369 case 'NULL ' :
43754370 if (!\is_null ($ oldValue ?->getId())) {
43764371 $ oldRelated = $ this ->skipRelationships (
4377- fn () =>
4378- $ this ->getDocument ($ relatedCollection ->getId (), $ oldValue ->getId ())
4372+ fn () => $ this ->getDocument ($ relatedCollection ->getId (), $ oldValue ->getId ())
43794373 );
43804374 $ this ->skipRelationships (fn () => $ this ->updateDocument (
43814375 $ relatedCollection ->getId (),
@@ -4423,8 +4417,7 @@ private function updateDocumentRelationships(Document $collection, Document $old
44234417 foreach ($ value as $ relation ) {
44244418 if (\is_string ($ relation )) {
44254419 $ related = $ this ->skipRelationships (
4426- fn () =>
4427- $ this ->getDocument ($ relatedCollection ->getId (), $ relation , [Query::select (['$id ' ])])
4420+ fn () => $ this ->getDocument ($ relatedCollection ->getId (), $ relation , [Query::select (['$id ' ])])
44284421 );
44294422
44304423 if ($ related ->isEmpty ()) {
@@ -4438,8 +4431,7 @@ private function updateDocumentRelationships(Document $collection, Document $old
44384431 ));
44394432 } elseif ($ relation instanceof Document) {
44404433 $ related = $ this ->skipRelationships (
4441- fn () =>
4442- $ this ->getDocument ($ relatedCollection ->getId (), $ relation ->getId (), [Query::select (['$id ' ])])
4434+ fn () => $ this ->getDocument ($ relatedCollection ->getId (), $ relation ->getId (), [Query::select (['$id ' ])])
44434435 );
44444436
44454437 if ($ related ->isEmpty ()) {
@@ -4689,8 +4681,8 @@ public function createOrUpdateDocumentsWithIncrease(
46894681
46904682 $ validator = new Authorization (
46914683 $ old ->isEmpty () ?
4692- self ::PERMISSION_CREATE :
4693- self ::PERMISSION_UPDATE
4684+ self ::PERMISSION_CREATE :
4685+ self ::PERMISSION_UPDATE
46944686 );
46954687
46964688 if ($ old ->isEmpty ()) {
@@ -4748,28 +4740,23 @@ public function createOrUpdateDocumentsWithIncrease(
47484740 );
47494741 }
47504742
4751- /**
4752- * @var array<Change> $documents
4753- */
4754- $ documents = $ this ->withTransaction (function () use ($ collection , $ attribute , $ documents , $ batchSize ) {
4755- $ stack = [];
4743+ $ stack = [];
47564744
4757- foreach (\array_chunk ($ documents , $ batchSize ) as $ chunk ) {
4758- /**
4759- * @var array<Change> $chunk
4760- */
4761- \array_push (
4762- $ stack ,
4763- ...Authorization::skip (fn () => $ this ->adapter ->createOrUpdateDocuments (
4764- $ collection ->getId (),
4765- $ attribute ,
4766- $ chunk
4767- ))
4768- );
4769- }
4745+ foreach (\array_chunk ($ documents , $ batchSize ) as $ chunk ) {
4746+ /**
4747+ * @var array<Change> $chunk
4748+ */
4749+ \array_push (
4750+ $ stack ,
4751+ ...$ this -> withTransaction ( fn () => Authorization::skip (fn () => $ this ->adapter ->createOrUpdateDocuments (
4752+ $ collection ->getId (),
4753+ $ attribute ,
4754+ $ chunk
4755+ ) ))
4756+ );
4757+ }
47704758
4771- return $ stack ;
4772- });
4759+ $ documents = $ stack ;
47734760
47744761 /**
47754762 * @var array<Document> $documents
@@ -5002,8 +4989,7 @@ public function deleteDocument(string $collection, string $id): bool
50024989
50034990 $ deleted = $ this ->withTransaction (function () use ($ collection , $ id , &$ document ) {
50044991 $ document = Authorization::skip (fn () => $ this ->silent (
5005- fn () =>
5006- $ this ->getDocument ($ collection ->getId (), $ id , forUpdate: true )
4992+ fn () => $ this ->getDocument ($ collection ->getId (), $ id , forUpdate: true )
50074993 ));
50084994
50094995 if ($ document ->isEmpty ()) {
@@ -5508,7 +5494,7 @@ public function deleteDocuments(string $collection, array $queries = [], int $ba
55085494 Query::limit ($ batchSize )
55095495 ];
55105496
5511- if (! empty ($ lastDocument )) {
5497+ if (!empty ($ lastDocument )) {
55125498 $ new [] = Query::cursorAfter ($ lastDocument );
55135499 }
55145500
@@ -5628,7 +5614,7 @@ public function purgeCachedCollection(string $collectionId): bool
56285614 public function purgeCachedDocument (string $ collectionId , string $ id ): bool
56295615 {
56305616 $ collectionKey = $ this ->cacheName . '-cache- ' . $ this ->getNamespace () . ': ' . $ this ->adapter ->getTenant () . ':collection: ' . $ collectionId ;
5631- $ documentKey = $ collectionKey . ': ' . $ id ;
5617+ $ documentKey = $ collectionKey . ': ' . $ id ;
56325618
56335619 $ this ->cache ->purge ($ collectionKey , $ documentKey );
56345620 $ this ->cache ->purge ($ documentKey );
@@ -5814,8 +5800,8 @@ public function find(string $collection, array $queries = [], string $forPermiss
58145800 * @param callable $callback
58155801 * @param array<Query> $queries
58165802 * @param string $forPermission
5817- * @throws \Utopia\Database\Exception
58185803 * @return void
5804+ * @throws \Utopia\Database\Exception
58195805 */
58205806 public function foreach (string $ collection , callable $ callback , array $ queries = [], string $ forPermission = Database::PERMISSION_READ ): void
58215807 {
@@ -5866,6 +5852,7 @@ public function foreach(string $collection, callable $callback, array $queries =
58665852 $ latestDocument = $ results [array_key_last ($ results )];
58675853 }
58685854 }
5855+
58695856 /**
58705857 * @param string $collection
58715858 * @param array<Query> $queries
@@ -6066,14 +6053,12 @@ public function decode(Document $collection, Document $document, array $selectio
60666053 {
60676054 $ attributes = \array_filter (
60686055 $ collection ->getAttribute ('attributes ' , []),
6069- fn ($ attribute ) =>
6070- $ attribute ['type ' ] !== self ::VAR_RELATIONSHIP
6056+ fn ($ attribute ) => $ attribute ['type ' ] !== self ::VAR_RELATIONSHIP
60716057 );
60726058
60736059 $ relationships = \array_filter (
60746060 $ collection ->getAttribute ('attributes ' , []),
6075- fn ($ attribute ) =>
6076- $ attribute ['type ' ] === self ::VAR_RELATIONSHIP
6061+ fn ($ attribute ) => $ attribute ['type ' ] === self ::VAR_RELATIONSHIP
60776062 );
60786063
60796064 foreach ($ relationships as $ relationship ) {
0 commit comments