Fix context

This commit is contained in:
Jake Barnby 2025-08-19 01:19:34 +12:00
parent 6dd058d6e1
commit 1771934af6
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
3 changed files with 33 additions and 35 deletions

View file

@ -23,14 +23,13 @@ abstract class Action extends UtopiaAction
if (\str_contains($path, '/tablesdb')) {
$this->context = TABLES;
}
return parent::setHttpPath($path);
}
/**
* Get the current API context.
*/
final protected function getContext(): string
protected function getContext(): string
{
return $this->context;
}
@ -38,7 +37,7 @@ abstract class Action extends UtopiaAction
/**
* Get the key used in event parameters (e.g., 'collectionId' or 'tableId').
*/
final protected function getEventsParamKey(): string
protected function getEventsParamKey(): string
{
return $this->getContext() . 'Id';
}
@ -46,7 +45,7 @@ abstract class Action extends UtopiaAction
/**
* Determine if the current action is for the Collections API.
*/
final protected function isCollectionsAPI(): bool
protected function isCollectionsAPI(): bool
{
return $this->getContext() === COLLECTIONS;
}
@ -54,7 +53,7 @@ abstract class Action extends UtopiaAction
/**
* Get the SDK group name for the current action.
*/
final protected function getSdkGroup(): string
protected function getSdkGroup(): string
{
return $this->isCollectionsAPI() ? 'collections' : 'tables';
}
@ -62,7 +61,7 @@ abstract class Action extends UtopiaAction
/**
* Get the SDK namespace for the current action.
*/
final protected function getSdkNamespace(): string
protected function getSdkNamespace(): string
{
return $this->isCollectionsAPI() ? 'databases' : 'tablesdb';
}
@ -70,7 +69,7 @@ abstract class Action extends UtopiaAction
/**
* Get the exception to throw when the resource already exists.
*/
final protected function getDuplicateException(): string
protected function getDuplicateException(): string
{
return $this->isCollectionsAPI()
? Exception::COLLECTION_ALREADY_EXISTS
@ -80,7 +79,7 @@ abstract class Action extends UtopiaAction
/**
* Get the appropriate index invalid exception.
*/
final protected function getInvalidIndexException(): string
protected function getInvalidIndexException(): string
{
return $this->isCollectionsAPI()
? Exception::INDEX_INVALID
@ -90,7 +89,7 @@ abstract class Action extends UtopiaAction
/**
* Get the exception to throw when the resource is not found.
*/
final protected function getNotFoundException(): string
protected function getNotFoundException(): string
{
return $this->isCollectionsAPI()
? Exception::COLLECTION_NOT_FOUND
@ -100,7 +99,7 @@ abstract class Action extends UtopiaAction
/**
* Get the exception to throw when the resource limit is exceeded.
*/
final protected function getLimitException(): string
protected function getLimitException(): string
{
return $this->isCollectionsAPI()
? Exception::COLLECTION_LIMIT_EXCEEDED

View file

@ -37,15 +37,16 @@ abstract class Action extends UtopiaAction
public function setHttpPath(string $path): UtopiaAction
{
// Context is automatically set by Documents/Action.php setHttpPath for tablesdb paths
if (\str_contains($path, '/tablesdb')) {
$this->context = COLUMNS;
}
return parent::setHttpPath($path);
}
/**
* Get the current context.
*/
final protected function getContext(): string
protected function getContext(): string
{
return $this->context;
}
@ -53,7 +54,7 @@ abstract class Action extends UtopiaAction
/**
* Returns true if current context is Collections API.
*/
final protected function isCollectionsAPI(): bool
protected function isCollectionsAPI(): bool
{
// columns in tables context
// attributes in collections context
@ -65,7 +66,7 @@ abstract class Action extends UtopiaAction
*
* Can be used for XList operations as well!
*/
final protected function getSdkGroup(): string
protected function getSdkGroup(): string
{
return $this->isCollectionsAPI() ? 'attributes' : 'columns';
}
@ -73,7 +74,7 @@ abstract class Action extends UtopiaAction
/**
* Get the SDK namespace for the current action.
*/
final protected function getSdkNamespace(): string
protected function getSdkNamespace(): string
{
return $this->isCollectionsAPI() ? 'databases' : 'tablesdb';
}
@ -81,7 +82,7 @@ abstract class Action extends UtopiaAction
/**
* Get the appropriate parent level not found exception.
*/
final protected function getParentNotFoundException(): string
protected function getParentNotFoundException(): string
{
return $this->isCollectionsAPI()
? Exception::COLLECTION_NOT_FOUND
@ -91,7 +92,7 @@ abstract class Action extends UtopiaAction
/**
* Get the appropriate not found exception.
*/
final protected function getNotFoundException(): string
protected function getNotFoundException(): string
{
return $this->isCollectionsAPI()
? Exception::ATTRIBUTE_NOT_FOUND
@ -101,7 +102,7 @@ abstract class Action extends UtopiaAction
/**
* Get the appropriate not found exception.
*/
final protected function getIndexDependencyException(): string
protected function getIndexDependencyException(): string
{
return $this->isCollectionsAPI()
? Exception::INDEX_DEPENDENCY
@ -111,7 +112,7 @@ abstract class Action extends UtopiaAction
/**
* Get the appropriate already exists exception.
*/
final protected function getDuplicateException(): string
protected function getDuplicateException(): string
{
return $this->isCollectionsAPI()
? Exception::ATTRIBUTE_ALREADY_EXISTS
@ -121,7 +122,7 @@ abstract class Action extends UtopiaAction
/**
* Get the correct invalid structure message.
*/
final protected function getInvalidStructureException(): string
protected function getInvalidStructureException(): string
{
return $this->isCollectionsAPI()
? Exception::DOCUMENT_INVALID_STRUCTURE
@ -131,7 +132,7 @@ abstract class Action extends UtopiaAction
/**
* Get the appropriate limit exceeded exception.
*/
final protected function getLimitException(): string
protected function getLimitException(): string
{
return $this->isCollectionsAPI()
? Exception::ATTRIBUTE_LIMIT_EXCEEDED
@ -141,7 +142,7 @@ abstract class Action extends UtopiaAction
/**
* Get the appropriate index invalid exception.
*/
final protected function getInvalidIndexException(): string
protected function getInvalidIndexException(): string
{
return $this->isCollectionsAPI()
? Exception::INDEX_INVALID
@ -151,7 +152,7 @@ abstract class Action extends UtopiaAction
/**
* Get the correct default unsupported message.
*/
final protected function getDefaultUnsupportedException(): string
protected function getDefaultUnsupportedException(): string
{
return $this->isCollectionsAPI()
? Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED
@ -161,7 +162,7 @@ abstract class Action extends UtopiaAction
/**
* Get the correct format unsupported message.
*/
final protected function getFormatUnsupportedException(): string
protected function getFormatUnsupportedException(): string
{
return $this->isCollectionsAPI()
? Exception::ATTRIBUTE_FORMAT_UNSUPPORTED
@ -171,7 +172,7 @@ abstract class Action extends UtopiaAction
/**
* Get the exception for invalid type or format mismatch.
*/
final protected function getTypeInvalidException(): string
protected function getTypeInvalidException(): string
{
return $this->isCollectionsAPI()
? Exception::ATTRIBUTE_TYPE_INVALID
@ -181,7 +182,7 @@ abstract class Action extends UtopiaAction
/**
* Get the exception for resizing invalid attributes/columns.
*/
final protected function getInvalidResizeException(): string
protected function getInvalidResizeException(): string
{
return $this->isCollectionsAPI()
? Exception::ATTRIBUTE_INVALID_RESIZE
@ -191,7 +192,7 @@ abstract class Action extends UtopiaAction
/**
* Get the exception for invalid attributes/columns value.
*/
final protected function getInvalidValueException(): string
protected function getInvalidValueException(): string
{
return $this->isCollectionsAPI()
? Exception::ATTRIBUTE_VALUE_INVALID
@ -201,7 +202,7 @@ abstract class Action extends UtopiaAction
/**
* Get the exception for non-available column/attribute.
*/
final protected function getNotAvailableException(): string
protected function getNotAvailableException(): string
{
return $this->isCollectionsAPI()
? Exception::ATTRIBUTE_NOT_AVAILABLE
@ -211,7 +212,7 @@ abstract class Action extends UtopiaAction
/**
* Get the correct collections context for Events queue.
*/
final protected function getCollectionsEventsContext(): string
protected function getCollectionsEventsContext(): string
{
return $this->isCollectionsAPI() ? 'collection' : 'table';
}
@ -219,7 +220,7 @@ abstract class Action extends UtopiaAction
/**
* Get the proper column/attribute type based on set context.
*/
final protected function getModel(string $type, string $format): string
protected function getModel(string $type, string $format): string
{
$isCollections = $this->isCollectionsAPI();
@ -271,7 +272,7 @@ abstract class Action extends UtopiaAction
};
}
final protected function createAttribute(string $databaseId, string $collectionId, Document $attribute, Response $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): Document
protected function createAttribute(string $databaseId, string $collectionId, Document $attribute, Response $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): Document
{
$key = $attribute->getAttribute('key');
$type = $attribute->getAttribute('type', '');
@ -433,7 +434,7 @@ abstract class Action extends UtopiaAction
return $attribute;
}
final protected function updateAttribute(string $databaseId, string $collectionId, string $key, Database $dbForProject, Event $queueForEvents, string $type, int $size = null, string $filter = null, string|bool|int|float $default = null, bool $required = null, int|float|null $min = null, int|float|null $max = null, array $elements = null, array $options = [], string $newKey = null): Document
protected function updateAttribute(string $databaseId, string $collectionId, string $key, Database $dbForProject, Event $queueForEvents, string $type, int $size = null, string $filter = null, string|bool|int|float $default = null, bool $required = null, int|float|null $min = null, int|float|null $max = null, array $elements = null, array $options = [], string $newKey = null): Document
{
$db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));

View file

@ -25,10 +25,8 @@ abstract class Action extends AppwriteAction
{
if (str_contains($path, '/tablesdb/')) {
$this->context = ROWS;
// Set removable attributes for TablesDB API
$this->removableAttributes = ['$databaseId', '$tableId'];
} else {
// Set removable attributes for Collections API
$this->removableAttributes = ['$databaseId', '$collectionId'];
}