misc: fixes.

This commit is contained in:
Darshan 2025-05-08 19:36:59 +05:30
parent 44a5fef345
commit 8006c9d60b
4 changed files with 23 additions and 23 deletions

View file

@ -308,8 +308,8 @@ abstract class Action extends UtopiaAction
if ($type === Database::VAR_RELATIONSHIP) {
$options['side'] = Database::RELATION_SIDE_PARENT;
$relatedTable = $dbForProject->getDocument('database_' . $db->getInternalId(), $options['relatedCollection'] ?? '');
if ($relatedTable->isEmpty()) {
$relatedCollection = $dbForProject->getDocument('database_' . $db->getInternalId(), $options['relatedCollection'] ?? '');
if ($relatedCollection->isEmpty()) {
$parent = $this->isCollectionsAPI() ? 'collection' : 'table';
throw new Exception($this->getParentNotFoundException(), "The related $parent was not found.");
}
@ -359,12 +359,12 @@ abstract class Action extends UtopiaAction
try {
$twoWayAttribute = new Document([
'$id' => ID::custom($db->getInternalId() . '_' . $relatedTable->getInternalId() . '_' . $twoWayKey),
'$id' => ID::custom($db->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $twoWayKey),
'key' => $twoWayKey,
'databaseInternalId' => $db->getInternalId(),
'databaseId' => $db->getId(),
'collectionInternalId' => $relatedTable->getInternalId(),
'collectionId' => $relatedTable->getId(),
'collectionInternalId' => $relatedCollection->getInternalId(),
'collectionId' => $relatedCollection->getId(),
'type' => $type,
'status' => 'processing', // processing, available, failed, deleting, stuck
'size' => $size,
@ -378,7 +378,7 @@ abstract class Action extends UtopiaAction
'options' => $options,
]);
$dbForProject->checkAttribute($relatedTable, $twoWayAttribute);
$dbForProject->checkAttribute($relatedCollection, $twoWayAttribute);
$dbForProject->createDocument('attributes', $twoWayAttribute);
} catch (DuplicateException) {
$dbForProject->deleteDocument('attributes', $attribute->getId());
@ -387,13 +387,13 @@ abstract class Action extends UtopiaAction
$dbForProject->deleteDocument('attributes', $attribute->getId());
throw new Exception($this->getLimitException());
} catch (Throwable $e) {
$dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $relatedTable->getId());
$dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $relatedTable->getInternalId());
$dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $relatedCollection->getId());
$dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $relatedCollection->getInternalId());
throw $e;
}
$dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $relatedTable->getId());
$dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $relatedTable->getInternalId());
$dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $relatedCollection->getId());
$dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $relatedCollection->getInternalId());
}
$queueForDatabase
@ -447,11 +447,11 @@ abstract class Action extends UtopiaAction
throw new Exception($this->getNotAvailableException());
}
if ($attribute->getAttribute('type') !== $type) {
if ($attribute->getAttribute(('type') !== $type)) {
throw new Exception($this->getTypeInvalidException());
}
if ($attribute->getAttribute('type') === Database::VAR_STRING && $attribute->getAttribute('filter') !== $filter) {
if ($attribute->getAttribute('type') === Database::VAR_STRING && $attribute->getAttribute(('filter') !== $filter)) {
throw new Exception($this->getTypeInvalidException());
}

View file

@ -62,21 +62,21 @@ class Get extends Action
]
))
->param('databaseId', '', new UID(), 'Database ID.')
->param('tableId', '', new UID(), 'Table ID.')
->param('collectionId', '', new UID(), 'Collection ID.')
->param('key', '', new Key(), 'Attribute Key.')
->inject('response')
->inject('dbForProject')
->callback([$this, 'action']);
}
public function action(string $databaseId, string $tableId, string $key, UtopiaResponse $response, Database $dbForProject): void
public function action(string $databaseId, string $collectionId, string $key, UtopiaResponse $response, Database $dbForProject): void
{
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
throw new Exception(Exception::DATABASE_NOT_FOUND);
}
$collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
$collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId);
if ($collection->isEmpty()) {
throw new Exception($this->getParentNotFoundException());
}

View file

@ -62,14 +62,14 @@ class XList extends Action
->callback([$this, 'action']);
}
public function action(string $databaseId, string $tableId, array $queries, UtopiaResponse $response, Database $dbForProject): void
public function action(string $databaseId, string $collectionId, array $queries, UtopiaResponse $response, Database $dbForProject): void
{
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
throw new Exception(Exception::DATABASE_NOT_FOUND);
}
$collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
$collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId);
if ($collection->isEmpty()) {
throw new Exception($this->getParentNotFoundException());
}

View file

@ -197,9 +197,9 @@ class Create extends Action
$relations = [$related];
}
$relatedTableId = $relationship->getAttribute('relatedCollection');
$relatedTable = Authorization::skip(
fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedTableId)
$relatedCollectionId = $relationship->getAttribute('relatedCollection');
$relatedCollection = Authorization::skip(
fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedCollectionId)
);
foreach ($relations as &$relation) {
@ -213,7 +213,7 @@ class Create extends Action
}
if ($relation instanceof Document) {
$current = Authorization::skip(
fn () => $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $relatedTable->getInternalId(), $relation->getId())
fn () => $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId(), $relation->getId())
);
if ($current->isEmpty()) {
@ -225,11 +225,11 @@ class Create extends Action
} else {
$relation->removeAttribute('$collectionId');
$relation->removeAttribute('$databaseId');
$relation->setAttribute('$collection', $relatedTable->getId());
$relation->setAttribute('$collection', $relatedCollection->getId());
$type = Database::PERMISSION_UPDATE;
}
$checkPermissions($relatedTable, $relation, $type);
$checkPermissions($relatedCollection, $relation, $type);
}
}