update: collections <> tables errors.

This commit is contained in:
Darshan
2025-05-06 16:44:19 +05:30
parent d70d001f5a
commit 59e5ce0664
25 changed files with 44 additions and 44 deletions
+3 -3
View File
@@ -192,9 +192,9 @@ class Exception extends \Exception
public const DATABASE_QUERY_ORDER_NULL = 'database_query_order_null';
/** Collections */
public const COLLECTION_NOT_FOUND = 'collection_not_found';
public const COLLECTION_ALREADY_EXISTS = 'collection_already_exists';
public const COLLECTION_LIMIT_EXCEEDED = 'collection_limit_exceeded';
public const TABLE_NOT_FOUND = 'table_not_found';
public const TABLE_ALREADY_EXISTS = 'table_already_exists';
public const TABLE_LIMIT_EXCEEDED = 'table_limit_exceeded';
/** Documents */
public const DOCUMENT_NOT_FOUND = 'document_not_found';
@@ -78,7 +78,7 @@ class Action extends UtopiaAction
$table = $dbForProject->getDocument('database_' . $db->getInternalId(), $tableId);
if ($table->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
if (!empty($format)) {
@@ -100,7 +100,7 @@ class Action extends UtopiaAction
$options['side'] = Database::RELATION_SIDE_PARENT;
$relatedTable = $dbForProject->getDocument('database_' . $db->getInternalId(), $options['relatedCollection'] ?? '');
if ($relatedTable->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND, 'The related table was not found.');
throw new Exception(Exception::TABLE_NOT_FOUND, 'The related table was not found.');
}
}
@@ -229,7 +229,7 @@ class Action extends UtopiaAction
$table = $dbForProject->getDocument('database_' . $db->getInternalId(), $tableId);
if ($table->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
$column = $dbForProject->getDocument('attributes', $db->getInternalId() . '_' . $table->getInternalId() . '_' . $key);
@@ -81,7 +81,7 @@ class Delete extends Action
$table = $dbForProject->getDocument('database_' . $db->getInternalId(), $tableId);
if ($table->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
$column = $dbForProject->getDocument('attributes', $db->getInternalId() . '_' . $table->getInternalId() . '_' . $key);
@@ -109,7 +109,7 @@ class Delete extends Action
if ($options['twoWay']) {
$relatedTable = $dbForProject->getDocument('database_' . $db->getInternalId(), $options['relatedCollection']);
if ($relatedTable->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
$relatedColumn = $dbForProject->getDocument('attributes', $db->getInternalId() . '_' . $relatedTable->getInternalId() . '_' . $options['twoWayKey']);
@@ -75,7 +75,7 @@ class Get extends Action
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
if ($table->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
$column = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $table->getInternalId() . '_' . $key);
@@ -105,13 +105,13 @@ class Create extends ColumnAction
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
$table = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $table->getInternalId());
if ($table->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
$relatedTableDocument = $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedTableId);
$relatedTable = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $relatedTableDocument->getInternalId());
if ($relatedTable->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
$columns = $table->getAttribute('attributes', []);
@@ -68,7 +68,7 @@ class XList extends Action
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
if ($table->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
$queries = Query::parseQueries($queries);
@@ -85,7 +85,7 @@ class Create extends Action
$table = $dbForProject->getDocument('database_' . $db->getInternalId(), $tableId);
if ($table->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
$count = $dbForProject->count('indexes', [
@@ -74,7 +74,7 @@ class Delete extends Action
$table = $dbForProject->getDocument('database_' . $db->getInternalId(), $tableId);
if ($table->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
$index = $dbForProject->getDocument('indexes', $db->getInternalId() . '_' . $table->getInternalId() . '_' . $key);
@@ -67,7 +67,7 @@ class Get extends Action
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
if ($table->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
$index = $table->find('key', $key, 'indexes');
@@ -73,7 +73,7 @@ class XList extends Action
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
if ($table->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
$queries = Query::parseQueries($queries);
@@ -106,7 +106,7 @@ class Create extends Action
$table = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId));
if ($table->isEmpty() || (!$table->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
$allowedPermissions = [
@@ -246,7 +246,7 @@ class Create extends Action
} catch (DuplicateException) {
throw new Exception(Exception::DOCUMENT_ALREADY_EXISTS);
} catch (NotFoundException) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
@@ -84,7 +84,7 @@ class Delete extends Action
$table = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId));
if ($table->isEmpty() || (!$table->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
// Read permission should not be required for delete
@@ -102,7 +102,7 @@ class Delete extends Action
);
});
} catch (NotFoundException) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
// Add $tableId and $databaseId for all rows
@@ -79,7 +79,7 @@ class Get extends Action
$table = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId));
if ($table->isEmpty() || (!$table->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
try {
@@ -81,7 +81,7 @@ class XList extends Action
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
if ($table->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
$row = $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $table->getInternalId(), $rowId);
@@ -101,7 +101,7 @@ class Update extends Action
$table = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId));
if ($table->isEmpty() || (!$table->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
// Read permission should not be required for update
@@ -243,7 +243,7 @@ class Update extends Action
} catch (StructureException $e) {
throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, $e->getMessage());
} catch (NotFoundException) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
// Add $tableId and $databaseId for all rows
@@ -79,7 +79,7 @@ class XList extends Action
$table = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId));
if ($table->isEmpty() || (!$table->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
try {
@@ -99,9 +99,9 @@ class Create extends Action
$dbForProject->createCollection('database_' . $database->getInternalId() . '_collection_' . $table->getInternalId(), permissions: $permissions, documentSecurity: $documentSecurity);
} catch (DuplicateException) {
throw new Exception(Exception::COLLECTION_ALREADY_EXISTS);
throw new Exception(Exception::TABLE_ALREADY_EXISTS);
} catch (LimitException) {
throw new Exception(Exception::COLLECTION_LIMIT_EXCEEDED);
throw new Exception(Exception::TABLE_LIMIT_EXCEEDED);
}
$queueForEvents
@@ -71,7 +71,7 @@ class Delete extends Action
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
if ($table->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
if (!$dbForProject->deleteDocument('database_' . $database->getInternalId(), $tableId)) {
@@ -66,7 +66,7 @@ class Get extends Action
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
if ($table->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
$response->dynamic($table, UtopiaResponse::MODEL_TABLE);
@@ -81,7 +81,7 @@ class XList extends Action
$table = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $tableDocument->getInternalId());
if ($table->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
try {
@@ -77,7 +77,7 @@ class Update extends Action
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
if ($table->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
$permissions ??= $table->getPermissions() ?? [];
@@ -68,7 +68,7 @@ class Get extends Action
$table = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $tableDocument->getInternalId());
if ($table->isEmpty()) {
throw new Exception(Exception::COLLECTION_NOT_FOUND);
throw new Exception(Exception::TABLE_NOT_FOUND);
}
$periods = Config::getParam('usage', []);