Address Comments
This commit is contained in:
parent
38bc2bb925
commit
627cbe285f
3 changed files with 60 additions and 46 deletions
|
@ -27,6 +27,7 @@ use Utopia\Database\Exception\Duplicate as DuplicateException;
|
|||
use Utopia\Database\Exception\Limit as LimitException;
|
||||
use Utopia\Database\Exception\Restricted as RestrictedException;
|
||||
use Utopia\Database\Exception\Structure as StructureException;
|
||||
use Utopia\Database\Exception\Truncate as TruncateException;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\Database\Helpers\Permission;
|
||||
use Utopia\Database\Helpers\Role;
|
||||
|
@ -364,14 +365,18 @@ function updateAttribute(
|
|||
$dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $relatedCollection->getId());
|
||||
}
|
||||
} else {
|
||||
$dbForProject->updateAttribute(
|
||||
collection: $collectionId,
|
||||
id: $key,
|
||||
required: $required,
|
||||
default: $default,
|
||||
formatOptions: $options ?? null,
|
||||
size: $size ?? null,
|
||||
);
|
||||
try {
|
||||
$dbForProject->updateAttribute(
|
||||
collection: $collectionId,
|
||||
id: $key,
|
||||
required: $required,
|
||||
default: $default,
|
||||
formatOptions: $options ?? null,
|
||||
size: $size ?? null,
|
||||
);
|
||||
} catch (TruncateException $e) {
|
||||
throw new Exception(Exception::ATTRIBUTE_INVALID_RESIZE);
|
||||
}
|
||||
}
|
||||
|
||||
$attribute = $dbForProject->updateDocument('attributes', $db->getInternalId() . '_' . $collection->getInternalId() . '_' . $key, $attribute);
|
||||
|
@ -1149,19 +1154,15 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string
|
|||
$filters[] = 'encrypt';
|
||||
}
|
||||
|
||||
try {
|
||||
$attribute = createAttribute($databaseId, $collectionId, new Document([
|
||||
'key' => $key,
|
||||
'type' => Database::VAR_STRING,
|
||||
'size' => $size,
|
||||
'required' => $required,
|
||||
'default' => $default,
|
||||
'array' => $array,
|
||||
'filters' => $filters,
|
||||
]), $response, $dbForProject, $queueForDatabase, $queueForEvents);
|
||||
} catch (DatabaseException $e) {
|
||||
var_dump($e);
|
||||
}
|
||||
$attribute = createAttribute($databaseId, $collectionId, new Document([
|
||||
'key' => $key,
|
||||
'type' => Database::VAR_STRING,
|
||||
'size' => $size,
|
||||
'required' => $required,
|
||||
'default' => $default,
|
||||
'array' => $array,
|
||||
'filters' => $filters,
|
||||
]), $response, $dbForProject, $queueForDatabase, $queueForEvents);
|
||||
|
||||
|
||||
$response
|
||||
|
@ -1877,25 +1878,17 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/attributes/strin
|
|||
->inject('queueForEvents')
|
||||
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?int $size, Response $response, Database $dbForProject, Event $queueForEvents) {
|
||||
|
||||
try {
|
||||
$attribute = updateAttribute(
|
||||
databaseId: $databaseId,
|
||||
collectionId: $collectionId,
|
||||
key: $key,
|
||||
dbForProject: $dbForProject,
|
||||
queueForEvents: $queueForEvents,
|
||||
type: Database::VAR_STRING,
|
||||
default: $default,
|
||||
required: $required,
|
||||
size: $size
|
||||
);
|
||||
} catch (DatabaseException $e) {
|
||||
if ($e->getMessage() === "Resize would result in data truncation") {
|
||||
throw new Exception(Exception::ATTRIBUTE_INVALID_RESIZE);
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
$attribute = updateAttribute(
|
||||
databaseId: $databaseId,
|
||||
collectionId: $collectionId,
|
||||
key: $key,
|
||||
dbForProject: $dbForProject,
|
||||
queueForEvents: $queueForEvents,
|
||||
type: Database::VAR_STRING,
|
||||
default: $default,
|
||||
required: $required,
|
||||
size: $size
|
||||
);
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_OK)
|
||||
|
|
12
composer.lock
generated
12
composer.lock
generated
|
@ -1723,16 +1723,16 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/database",
|
||||
"version": "0.53.1",
|
||||
"version": "0.53.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/database.git",
|
||||
"reference": "3f17072a33649a3451122bfeb630d57330c0a6df"
|
||||
"reference": "87fa42f15e9ff43bcb6523f5f8be4b53ad4bbb78"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/3f17072a33649a3451122bfeb630d57330c0a6df",
|
||||
"reference": "3f17072a33649a3451122bfeb630d57330c0a6df",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/87fa42f15e9ff43bcb6523f5f8be4b53ad4bbb78",
|
||||
"reference": "87fa42f15e9ff43bcb6523f5f8be4b53ad4bbb78",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1773,9 +1773,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/database/issues",
|
||||
"source": "https://github.com/utopia-php/database/tree/0.53.1"
|
||||
"source": "https://github.com/utopia-php/database/tree/0.53.2"
|
||||
},
|
||||
"time": "2024-08-30T09:02:45+00:00"
|
||||
"time": "2024-08-30T10:14:51+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/domains",
|
||||
|
|
|
@ -3402,6 +3402,27 @@ class DatabasesCustomServerTest extends Scope
|
|||
|
||||
$this->assertEquals(200, $document['headers']['status-code']);
|
||||
$this->assertEquals(10, strlen($document['body']['string']));
|
||||
|
||||
// Try create document with string that is too large
|
||||
$newDoc = $this->client->call(
|
||||
Client::METHOD_POST,
|
||||
'/databases/' . $databaseId . '/collections/' . $collectionId . '/documents',
|
||||
array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]),
|
||||
[
|
||||
'documentId' => 'unique()',
|
||||
'data' => [
|
||||
'string' => str_repeat('a', 11)
|
||||
],
|
||||
"permissions" => ["read(\"any\")"]
|
||||
]
|
||||
);
|
||||
|
||||
$this->assertEquals(400, $newDoc['headers']['status-code']);
|
||||
$this->assertEquals(AppwriteException::DOCUMENT_INVALID_STRUCTURE, $newDoc['body']['type']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue