1
0
Fork 0
mirror of synced 2024-10-03 02:37:40 +13:00
This commit is contained in:
prateek banga 2023-08-17 19:04:41 +05:30
parent d6f4d76807
commit 860e9958c7

View file

@ -3252,7 +3252,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum
$data['$permissions'] = $permissions; $data['$permissions'] = $permissions;
$newDocument = new Document($data); $newDocument = new Document($data);
$setCollection = function (Document $collection, Document $document) use (&$setCollection, $dbForProject, $database) { $setCollection = (function (Document $collection, Document $document) use (&$setCollection, $dbForProject, $database) {
$relationships = \array_filter( $relationships = \array_filter(
$collection->getAttribute('attributes', []), $collection->getAttribute('attributes', []),
fn($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP fn($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP
@ -3316,26 +3316,26 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum
$document->setAttribute($relationship->getAttribute('key'), \reset($relations)); $document->setAttribute($relationship->getAttribute('key'), \reset($relations));
} }
} }
}; });
$setCollection($collection, $newDocument); $setCollection($collection, $newDocument);
try { try {
$document = $dbForProject->withRequestTimestamp( $document = $dbForProject->withRequestTimestamp(
$requestTimestamp, $requestTimestamp,
fn() => $dbForProject->updateDocument( fn() => $dbForProject->updateDocument(
'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(),
$document->getId(), $document->getId(),
$newDocument $newDocument
) )
); );
} catch (AuthorizationException) { } catch (AuthorizationException) {
throw new Exception(Exception::USER_UNAUTHORIZED); throw new Exception(Exception::USER_UNAUTHORIZED);
} catch (DuplicateException) { } catch (DuplicateException) {
throw new Exception(Exception::DOCUMENT_ALREADY_EXISTS); throw new Exception(Exception::DOCUMENT_ALREADY_EXISTS);
} catch (StructureException $exception) { } catch (StructureException $exception) {
throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, $exception->getMessage()); throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, $exception->getMessage());
} }
// Add $collectionId and $databaseId for all documents // Add $collectionId and $databaseId for all documents
$processDocument = function (Document $collection, Document $document) use (&$processDocument, $dbForProject, $database) { $processDocument = function (Document $collection, Document $document) use (&$processDocument, $dbForProject, $database) {