Merge pull request #8597 from appwrite/feat-string-attribute-resizing

Feat string attribute resizing
This commit is contained in:
Jake Barnby 2024-09-05 15:03:21 +12:00 committed by GitHub
commit 2a3ae69f1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 312 additions and 109 deletions

View file

@ -699,6 +699,11 @@ return [
'description' => 'The relationship value is invalid.',
'code' => 400,
],
Exception::ATTRIBUTE_INVALID_RESIZE => [
'name' => Exception::ATTRIBUTE_INVALID_RESIZE,
'description' => "Existing data is too large for new size, truncate your existing data then try again.",
'code' => 400,
],
/** Indexes */
Exception::INDEX_NOT_FOUND => [

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -392,7 +392,7 @@ App::post('/v1/account')
$existingTarget = $dbForProject->findOne('targets', [
Query::equal('identifier', [$email]),
]);
if($existingTarget) {
if ($existingTarget) {
$user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND);
}
}

View file

@ -26,6 +26,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;
@ -234,7 +235,8 @@ function updateAttribute(
int|float $min = null,
int|float $max = null,
array $elements = null,
array $options = []
array $options = [],
int $size = null
): Document {
$db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
@ -280,6 +282,10 @@ function updateAttribute(
->setAttribute('default', $default)
->setAttribute('required', $required);
if (!empty($size)) {
$attribute->setAttribute('size', $size);
}
$formatOptions = $attribute->getAttribute('formatOptions');
switch ($attribute->getAttribute('format')) {
@ -358,13 +364,18 @@ function updateAttribute(
$dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $relatedCollection->getId());
}
} else {
$dbForProject->updateAttribute(
collection: $collectionId,
id: $key,
required: $required,
default: $default,
formatOptions: $options ?? 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);
@ -1152,6 +1163,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string
'filters' => $filters,
]), $response, $dbForProject, $queueForDatabase, $queueForEvents);
$response
->setStatusCode(Response::STATUS_CODE_ACCEPTED)
->dynamic($attribute, Response::MODEL_ATTRIBUTE_STRING);
@ -1859,10 +1871,11 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/attributes/strin
->param('key', '', new Key(), 'Attribute Key.')
->param('required', null, new Boolean(), 'Is attribute required?')
->param('default', null, new Nullable(new Text(0, 0)), 'Default value for attribute when not provided. Cannot be set when attribute is required.')
->param('size', null, new Integer(), 'Maximum size of the string attribute.', true)
->inject('response')
->inject('dbForProject')
->inject('queueForEvents')
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, Response $response, Database $dbForProject, Event $queueForEvents) {
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?int $size, Response $response, Database $dbForProject, Event $queueForEvents) {
$attribute = updateAttribute(
databaseId: $databaseId,
@ -1872,7 +1885,8 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/attributes/strin
queueForEvents: $queueForEvents,
type: Database::VAR_STRING,
default: $default,
required: $required
required: $required,
size: $size
);
$response

View file

@ -296,7 +296,7 @@ App::post('/v1/functions')
if (!empty($providerRepositoryId)) {
// Deploy VCS
$redeployVcs($request, $function, $project, $installation, $dbForProject, $queueForBuilds, $template, $github);
} elseif(!$template->isEmpty()) {
} elseif (!$template->isEmpty()) {
// Deploy non-VCS from template
$deploymentId = ID::unique();
$deployment = $dbForProject->createDocument('deployments', new Document([
@ -1581,7 +1581,7 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/build')
}
$path = $deployment->getAttribute('path');
if(empty($path) || !$deviceForFunctions->exists($path)) {
if (empty($path) || !$deviceForFunctions->exists($path)) {
throw new Exception(Exception::DEPLOYMENT_NOT_FOUND);
}
@ -1735,7 +1735,7 @@ App::post('/v1/functions/:functionId/executions')
->inject('geodb')
->action(function (string $functionId, string $body, bool $async, string $path, string $method, mixed $headers, ?string $scheduledAt, Response $response, Request $request, Document $project, Database $dbForProject, Database $dbForConsole, Document $user, Event $queueForEvents, Usage $queueForUsage, Func $queueForFunctions, Reader $geodb) {
if(!$async && !is_null($scheduledAt)) {
if (!$async && !is_null($scheduledAt)) {
throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Scheduled executions must run asynchronously. Set scheduledAt to a future date, or set async to true.');
}
@ -1868,7 +1868,7 @@ App::post('/v1/functions/:functionId/executions')
$status = $async ? 'waiting' : 'processing';
if(!is_null($scheduledAt)) {
if (!is_null($scheduledAt)) {
$status = 'scheduled';
}
@ -1898,7 +1898,7 @@ App::post('/v1/functions/:functionId/executions')
->setContext('function', $function);
if ($async) {
if(is_null($scheduledAt)) {
if (is_null($scheduledAt)) {
$execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution));
$queueForFunctions
->setType('http')
@ -2077,7 +2077,7 @@ App::post('/v1/functions/:functionId/executions')
$acceptTypes = \explode(', ', $request->getHeader('accept'));
foreach ($acceptTypes as $acceptType) {
if(\str_starts_with($acceptType, 'application/json') || \str_starts_with($acceptType, 'application/*')) {
if (\str_starts_with($acceptType, 'application/json') || \str_starts_with($acceptType, 'application/*')) {
$response->setContentType(Response::CONTENT_TYPE_JSON);
break;
} elseif (\str_starts_with($acceptType, 'multipart/form-data') || \str_starts_with($acceptType, 'multipart/*')) {

View file

@ -140,7 +140,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e
$existingTarget = $dbForProject->findOne('targets', [
Query::equal('identifier', [$email]),
]);
if($existingTarget) {
if ($existingTarget) {
$user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND);
}
}
@ -164,7 +164,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e
$existingTarget = $dbForProject->findOne('targets', [
Query::equal('identifier', [$phone]),
]);
if($existingTarget) {
if ($existingTarget) {
$user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND);
}
}
@ -2124,7 +2124,7 @@ App::post('/v1/users/:userId/jwts')
$sessions = $user->getAttribute('sessions', []);
$session = new Document();
if($sessionId === 'recent') {
if ($sessionId === 'recent') {
// Get most recent
$session = \count($sessions) > 0 ? $sessions[\count($sessions) - 1] : new Document();
} else {

View file

@ -509,7 +509,7 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories/:pro
$vcsContents = [];
foreach ($contents as $content) {
$isDirectory = false;
if($content['type'] === GitHub::CONTENTS_DIRECTORY) {
if ($content['type'] === GitHub::CONTENTS_DIRECTORY) {
$isDirectory = true;
}

View file

@ -207,14 +207,14 @@ App::init()
}
// Remove after migration
if(!\str_contains($apiKey, '_')) {
if (!\str_contains($apiKey, '_')) {
$keyType = API_KEY_STANDARD;
$authKey = $apiKey;
} else {
[ $keyType, $authKey ] = \explode('_', $apiKey, 2);
}
if($keyType === API_KEY_DYNAMIC) {
if ($keyType === API_KEY_DYNAMIC) {
// Dynamic key
$jwtObj = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', 3600, 0);
@ -244,7 +244,7 @@ App::init()
Authorization::setRole(Auth::USER_ROLE_APPS);
Authorization::setDefaultStatus(false); // Cancel security segmentation for API keys.
}
} elseif($keyType === API_KEY_STANDARD) {
} elseif ($keyType === API_KEY_STANDARD) {
// No underline means no prefix. Backwards compatibility.
// Regular key

View file

@ -791,7 +791,7 @@ $register->set('logger', function () {
$adapter = null;
}
if($adapter === null) {
if ($adapter === null) {
Console::error("Logging provider not supported. Logging is disabled");
return;
}
@ -1267,7 +1267,7 @@ App::setResource('user', function ($mode, $project, $console, $request, $respons
}
$jwtSessionId = $payload['sessionId'] ?? '';
if(!empty($jwtSessionId)) {
if (!empty($jwtSessionId)) {
if (empty($user->find('$id', $jwtSessionId, 'sessions'))) { // Match JWT to active token
$user = new Document([]);
}

View file

@ -45,13 +45,13 @@
"ext-sockets": "*",
"appwrite/php-runtimes": "0.15.*",
"appwrite/php-clamav": "2.0.*",
"utopia-php/abuse": "0.42.0",
"utopia-php/abuse": "0.43.0",
"utopia-php/analytics": "0.10.*",
"utopia-php/audit": "0.42.0",
"utopia-php/audit": "0.43.0",
"utopia-php/cache": "0.10.*",
"utopia-php/cli": "0.15.*",
"utopia-php/config": "0.2.*",
"utopia-php/database": "0.52.*",
"utopia-php/database": "0.53.*",
"utopia-php/domains": "0.5.*",
"utopia-php/dsn": "0.2.1",
"utopia-php/framework": "0.33.*",

110
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "eba741eab8bb748ed684c32711d472df",
"content-hash": "b6820da26239716cf14a445697902a03",
"packages": [
{
"name": "adhocore/jwt",
@ -1429,16 +1429,16 @@
},
{
"name": "utopia-php/abuse",
"version": "0.42.0",
"version": "0.43.0",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/abuse.git",
"reference": "08cf17e7f4fd213966c8d8702e406f2269244f0f"
"reference": "6346a3b4c5177a43160035a7289e30fdfb0790d6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/abuse/zipball/08cf17e7f4fd213966c8d8702e406f2269244f0f",
"reference": "08cf17e7f4fd213966c8d8702e406f2269244f0f",
"url": "https://api.github.com/repos/utopia-php/abuse/zipball/6346a3b4c5177a43160035a7289e30fdfb0790d6",
"reference": "6346a3b4c5177a43160035a7289e30fdfb0790d6",
"shasum": ""
},
"require": {
@ -1446,7 +1446,7 @@
"ext-pdo": "*",
"ext-redis": "*",
"php": ">=8.0",
"utopia-php/database": "0.52.*"
"utopia-php/database": "0.53.*"
},
"require-dev": {
"laravel/pint": "1.5.*",
@ -1474,9 +1474,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/abuse/issues",
"source": "https://github.com/utopia-php/abuse/tree/0.42.0"
"source": "https://github.com/utopia-php/abuse/tree/0.43.0"
},
"time": "2024-08-21T08:24:01+00:00"
"time": "2024-08-30T05:17:23+00:00"
},
{
"name": "utopia-php/analytics",
@ -1526,21 +1526,21 @@
},
{
"name": "utopia-php/audit",
"version": "0.42.0",
"version": "0.43.0",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/audit.git",
"reference": "9dc168470625bcf11ff8cd9ab5660db09129f618"
"reference": "cef22b5dc6a6d28fcd522f41c7bf7ded4a4dfd3e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/audit/zipball/9dc168470625bcf11ff8cd9ab5660db09129f618",
"reference": "9dc168470625bcf11ff8cd9ab5660db09129f618",
"url": "https://api.github.com/repos/utopia-php/audit/zipball/cef22b5dc6a6d28fcd522f41c7bf7ded4a4dfd3e",
"reference": "cef22b5dc6a6d28fcd522f41c7bf7ded4a4dfd3e",
"shasum": ""
},
"require": {
"php": ">=8.0",
"utopia-php/database": "0.52.*"
"utopia-php/database": "0.53.*"
},
"require-dev": {
"laravel/pint": "1.5.*",
@ -1567,9 +1567,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/audit/issues",
"source": "https://github.com/utopia-php/audit/tree/0.42.0"
"source": "https://github.com/utopia-php/audit/tree/0.43.0"
},
"time": "2024-08-21T08:24:08+00:00"
"time": "2024-08-30T05:17:36+00:00"
},
{
"name": "utopia-php/cache",
@ -1723,7 +1723,7 @@
},
{
"name": "utopia-php/database",
"version": "0.52.2",
"version": "0.53.3",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/database.git",
@ -1773,7 +1773,7 @@
],
"support": {
"issues": "https://github.com/utopia-php/database/issues",
"source": "https://github.com/utopia-php/database/tree/0.52.2"
"source": "https://github.com/utopia-php/database/tree/0.53.3"
},
"time": "2024-09-02T06:28:50+00:00"
},
@ -2599,16 +2599,16 @@
},
{
"name": "utopia-php/storage",
"version": "0.18.4",
"version": "0.18.5",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/storage.git",
"reference": "94ab8758fabcefee5c5fa723616e45719833f922"
"reference": "7d355c5e3ccc8ecebc0266f8ddd30088a43be919"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/storage/zipball/94ab8758fabcefee5c5fa723616e45719833f922",
"reference": "94ab8758fabcefee5c5fa723616e45719833f922",
"url": "https://api.github.com/repos/utopia-php/storage/zipball/7d355c5e3ccc8ecebc0266f8ddd30088a43be919",
"reference": "7d355c5e3ccc8ecebc0266f8ddd30088a43be919",
"shasum": ""
},
"require": {
@ -2648,9 +2648,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/storage/issues",
"source": "https://github.com/utopia-php/storage/tree/0.18.4"
"source": "https://github.com/utopia-php/storage/tree/0.18.5"
},
"time": "2024-04-02T08:24:09+00:00"
"time": "2024-09-04T08:57:27+00:00"
},
{
"name": "utopia-php/swoole",
@ -3314,16 +3314,16 @@
},
{
"name": "laravel/pint",
"version": "v1.17.2",
"version": "v1.17.3",
"source": {
"type": "git",
"url": "https://github.com/laravel/pint.git",
"reference": "e8a88130a25e3f9d4d5785e6a1afca98268ab110"
"reference": "9d77be916e145864f10788bb94531d03e1f7b482"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/pint/zipball/e8a88130a25e3f9d4d5785e6a1afca98268ab110",
"reference": "e8a88130a25e3f9d4d5785e6a1afca98268ab110",
"url": "https://api.github.com/repos/laravel/pint/zipball/9d77be916e145864f10788bb94531d03e1f7b482",
"reference": "9d77be916e145864f10788bb94531d03e1f7b482",
"shasum": ""
},
"require": {
@ -3334,13 +3334,13 @@
"php": "^8.1.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.61.1",
"illuminate/view": "^10.48.18",
"friendsofphp/php-cs-fixer": "^3.64.0",
"illuminate/view": "^10.48.20",
"larastan/larastan": "^2.9.8",
"laravel-zero/framework": "^10.4.0",
"mockery/mockery": "^1.6.12",
"nunomaduro/termwind": "^1.15.1",
"pestphp/pest": "^2.35.0"
"pestphp/pest": "^2.35.1"
},
"bin": [
"builds/pint"
@ -3376,7 +3376,7 @@
"issues": "https://github.com/laravel/pint/issues",
"source": "https://github.com/laravel/pint"
},
"time": "2024-08-06T15:11:54+00:00"
"time": "2024-09-03T15:00:28+00:00"
},
{
"name": "matthiasmullie/minify",
@ -4185,16 +4185,16 @@
},
{
"name": "phpstan/phpdoc-parser",
"version": "1.29.1",
"version": "1.30.0",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpdoc-parser.git",
"reference": "fcaefacf2d5c417e928405b71b400d4ce10daaf4"
"reference": "5ceb0e384997db59f38774bf79c2a6134252c08f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/fcaefacf2d5c417e928405b71b400d4ce10daaf4",
"reference": "fcaefacf2d5c417e928405b71b400d4ce10daaf4",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/5ceb0e384997db59f38774bf79c2a6134252c08f",
"reference": "5ceb0e384997db59f38774bf79c2a6134252c08f",
"shasum": ""
},
"require": {
@ -4226,9 +4226,9 @@
"description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": {
"issues": "https://github.com/phpstan/phpdoc-parser/issues",
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.29.1"
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.30.0"
},
"time": "2024-05-31T08:52:43+00:00"
"time": "2024-08-29T09:54:52+00:00"
},
{
"name": "phpunit/php-code-coverage",
@ -5865,16 +5865,16 @@
},
{
"name": "symfony/console",
"version": "v7.1.3",
"version": "v7.1.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9"
"reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9",
"reference": "cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9",
"url": "https://api.github.com/repos/symfony/console/zipball/1eed7af6961d763e7832e874d7f9b21c3ea9c111",
"reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111",
"shasum": ""
},
"require": {
@ -5938,7 +5938,7 @@
"terminal"
],
"support": {
"source": "https://github.com/symfony/console/tree/v7.1.3"
"source": "https://github.com/symfony/console/tree/v7.1.4"
},
"funding": [
{
@ -5954,7 +5954,7 @@
"type": "tidelift"
}
],
"time": "2024-07-26T12:41:01+00:00"
"time": "2024-08-15T22:48:53+00:00"
},
{
"name": "symfony/deprecation-contracts",
@ -6091,16 +6091,16 @@
},
{
"name": "symfony/finder",
"version": "v7.1.3",
"version": "v7.1.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/finder.git",
"reference": "717c6329886f32dc65e27461f80f2a465412fdca"
"reference": "d95bbf319f7d052082fb7af147e0f835a695e823"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/717c6329886f32dc65e27461f80f2a465412fdca",
"reference": "717c6329886f32dc65e27461f80f2a465412fdca",
"url": "https://api.github.com/repos/symfony/finder/zipball/d95bbf319f7d052082fb7af147e0f835a695e823",
"reference": "d95bbf319f7d052082fb7af147e0f835a695e823",
"shasum": ""
},
"require": {
@ -6135,7 +6135,7 @@
"description": "Finds files and directories via an intuitive fluent interface",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/finder/tree/v7.1.3"
"source": "https://github.com/symfony/finder/tree/v7.1.4"
},
"funding": [
{
@ -6151,7 +6151,7 @@
"type": "tidelift"
}
],
"time": "2024-07-24T07:08:44+00:00"
"time": "2024-08-13T14:28:19+00:00"
},
{
"name": "symfony/options-resolver",
@ -6604,16 +6604,16 @@
},
{
"name": "symfony/string",
"version": "v7.1.3",
"version": "v7.1.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/string.git",
"reference": "ea272a882be7f20cad58d5d78c215001617b7f07"
"reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/string/zipball/ea272a882be7f20cad58d5d78c215001617b7f07",
"reference": "ea272a882be7f20cad58d5d78c215001617b7f07",
"url": "https://api.github.com/repos/symfony/string/zipball/6cd670a6d968eaeb1c77c2e76091c45c56bc367b",
"reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b",
"shasum": ""
},
"require": {
@ -6671,7 +6671,7 @@
"utf8"
],
"support": {
"source": "https://github.com/symfony/string/tree/v7.1.3"
"source": "https://github.com/symfony/string/tree/v7.1.4"
},
"funding": [
{
@ -6687,7 +6687,7 @@
"type": "tidelift"
}
],
"time": "2024-07-22T10:25:37+00:00"
"time": "2024-08-12T09:59:40+00:00"
},
{
"name": "textalk/websocket",

View file

@ -200,6 +200,7 @@ class Exception extends \Exception
public const ATTRIBUTE_LIMIT_EXCEEDED = 'attribute_limit_exceeded';
public const ATTRIBUTE_VALUE_INVALID = 'attribute_value_invalid';
public const ATTRIBUTE_TYPE_INVALID = 'attribute_type_invalid';
public const ATTRIBUTE_INVALID_RESIZE = 'attribute_invalid_resize';
/** Relationship */
public const RELATIONSHIP_VALUE_INVALID = 'relationship_value_invalid';
@ -313,7 +314,7 @@ class Exception extends \Exception
$this->code = $code ?? $this->errors[$type]['code'];
// Mark string errors like HY001 from PDO as 500 errors
if(\is_string($this->code)) {
if (\is_string($this->code)) {
if (\is_numeric($this->code)) {
$this->code = (int) $this->code;
} else {

View file

@ -44,7 +44,7 @@ class Headers extends Validator
return false;
}
if(\count($value) > $this->maxKeys) {
if (\count($value) > $this->maxKeys) {
return false;
}
@ -57,7 +57,7 @@ class Headers extends Validator
}
$size += $length + \strlen($val);
if($size >= $this->maxSize) {
if ($size >= $this->maxSize) {
return false;
}

View file

@ -208,7 +208,7 @@ class Builds extends Action
}
try {
if($isNewBuild && !$isVcsEnabled) {
if ($isNewBuild && !$isVcsEnabled) {
// Non-vcs+Template
$templateRepositoryName = $template->getAttribute('repositoryName', '');
@ -279,7 +279,7 @@ class Builds extends Action
$cloneVersion = $branchName;
$cloneType = GitHub::CLONE_TYPE_BRANCH;
if(!empty($commitHash)) {
if (!empty($commitHash)) {
$cloneVersion = $commitHash;
$cloneType = GitHub::CLONE_TYPE_COMMIT;
}
@ -543,7 +543,7 @@ class Builds extends Action
deploymentId: $deployment->getId(),
projectId: $project->getId(),
callback: function ($logs) use (&$response, &$err, &$build, $dbForProject, $allEvents, $project, &$isCanceled) {
if($isCanceled) {
if ($isCanceled) {
return;
}

View file

@ -669,7 +669,7 @@ class Messaging extends Action
private function getLocalDevice($project): Local
{
if($this->localDevice === null) {
if ($this->localDevice === null) {
$this->localDevice = new Local(APP_STORAGE_UPLOADS . '/app-' . $project->getId());
}

View file

@ -287,7 +287,7 @@ class Swagger2 extends Format
}
$validatorClass = (!empty($validator)) ? \get_class($validator) : '';
if($validatorClass === 'Utopia\Validator\AnyOf') {
if ($validatorClass === 'Utopia\Validator\AnyOf') {
$validator = $param['validator']->getValidators()[0];
$validatorClass = \get_class($validator);
}

View file

@ -33,13 +33,13 @@ class V16 extends Filter
protected function parseDeployment(array $content)
{
if(isset($content['buildLogs'])) {
if (isset($content['buildLogs'])) {
$content['buildStderr'] = '';
$content['buildStdout'] = $content['buildLogs'];
unset($content['buildLogs']);
}
if(isset($content['buildSize'])) {
if (isset($content['buildSize'])) {
$content['size'] += + $content['buildSize'] ?? 0;
unset($content['buildSize']);
}

View file

@ -25,8 +25,8 @@ class V18 extends Filter
protected function parseExecution(array $content)
{
if(!empty($content['status']) && !empty($content['statusCode'])) {
if($content['status'] === 'completed' && $content['statusCode'] >= 400 && $content['statusCode'] < 500) {
if (!empty($content['status']) && !empty($content['statusCode'])) {
if ($content['status'] === 'completed' && $content['statusCode'] >= 400 && $content['statusCode'] < 500) {
$content['status'] = 'failed';
}
}

View file

@ -217,7 +217,7 @@ class Executor
'restartPolicy' => 'always' // Once utopia/orchestration has it, use DockerAPI::ALWAYS (0.13+)
];
if(!empty($body)) {
if (!empty($body)) {
$params['body'] = $body;
}

View file

@ -3242,6 +3242,189 @@ class DatabasesCustomServerTest extends Scope
$this->assertEquals(AppwriteException::ATTRIBUTE_DEFAULT_UNSUPPORTED, $update['body']['type']);
}
/**
* @depends testAttributeUpdate
*/
public function testAttributeUpdateStringResize(array $data)
{
$key = 'string';
$databaseId = $data['databaseId'];
$collectionId = $data['collectionId'];
$document = $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' => 'string'
],
"permissions" => ["read(\"any\")"]
]
);
// Test Resize Up
$attribute = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/string/' . $key, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'size' => 2048,
'default' => '',
'required' => false
]);
$this->assertEquals(200, $attribute['headers']['status-code']);
$this->assertEquals(2048, $attribute['body']['size']);
// Test create new document with new size
$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', 2048)
],
"permissions" => ["read(\"any\")"]
]
);
$this->assertEquals(201, $newDoc['headers']['status-code']);
$this->assertEquals(2048, strlen($newDoc['body']['string']));
// Test update document with new size
$document = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $document['body']['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'data' => [
'string' => str_repeat('a', 2048)
]
]);
$this->assertEquals(200, $document['headers']['status-code']);
$this->assertEquals(2048, strlen($document['body']['string']));
// Test Exception on resize down with data that is too large
$attribute = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/string/' . $key, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'size' => 10,
'default' => '',
'required' => false
]);
$this->assertEquals(400, $attribute['headers']['status-code']);
$this->assertEquals(AppwriteException::ATTRIBUTE_INVALID_RESIZE, $attribute['body']['type']);
// original documents to original size, remove new document
$document = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $document['body']['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'data' => [
'string' => 'string'
]
]);
$this->assertEquals(200, $document['headers']['status-code']);
$this->assertEquals('string', $document['body']['string']);
$deleteDoc = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $newDoc['body']['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]));
$this->assertEquals(204, $deleteDoc['headers']['status-code']);
// Test Resize Down
$attribute = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/string/' . $key, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'size' => 10,
'default' => '',
'required' => false
]);
$this->assertEquals(200, $attribute['headers']['status-code']);
$this->assertEquals(10, $attribute['body']['size']);
// Test create new document with new size
$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', 10)
],
"permissions" => ["read(\"any\")"]
]
);
$this->assertEquals(201, $newDoc['headers']['status-code']);
$this->assertEquals(10, strlen($newDoc['body']['string']));
// Test update document with new size
$document = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $document['body']['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'data' => [
'string' => str_repeat('a', 10)
]
]);
$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']);
}
/**
* @depends testAttributeUpdate
*/

View file

@ -34,7 +34,7 @@ trait FunctionsBase
\sleep(1);
}
if($checkForSuccess) {
if ($checkForSuccess) {
$this->assertEquals(200, $deployment['headers']['status-code']);
$this->assertEquals('ready', $deployment['body']['status'], \json_encode($deployment['body']));
}

View file

@ -1072,7 +1072,7 @@ class FunctionsCustomServerTest extends Scope
$found = false;
foreach ($response['body']['deployments'] as $deployment) {
if($deployment['$id'] === $deploymentId) {
if ($deployment['$id'] === $deploymentId) {
$found = true;
$this->assertEquals($deploymentSize, $deployment['size']);
break;

View file

@ -31,7 +31,7 @@ trait WebhooksBase
\sleep(1);
}
if($checkForSuccess) {
if ($checkForSuccess) {
$this->assertEquals(200, $deployment['headers']['status-code']);
$this->assertEquals('ready', $deployment['body']['status'], \json_encode($deployment['body']));
}

View file

@ -27,19 +27,19 @@ final class HeadersBench
yield 'empty' => [ 'value' => [] ];
$value = [];
for($i = 0; $i < 10; $i++) {
for ($i = 0; $i < 10; $i++) {
$value[bin2hex(random_bytes(8))] = bin2hex(random_bytes(8));
}
yield 'items_10-size_320' => [ 'value' => $value ];
$value = [];
for($i = 0; $i < 100; $i++) {
for ($i = 0; $i < 100; $i++) {
$value[bin2hex(random_bytes(8))] = bin2hex(random_bytes(8));
}
yield 'items_100-size_3200' => [ 'value' => $value ];
$value = [];
for($i = 0; $i < 100; $i++) {
for ($i = 0; $i < 100; $i++) {
$value[bin2hex(random_bytes(32))] = bin2hex(random_bytes(32));
}
yield 'items_100-size_12800' => [ 'value' => $value ];
@ -53,7 +53,7 @@ final class HeadersBench
public function benchHeadersValidator(array $data): void
{
$assertion = $this->validator->isValid($data['value']);
if(!$assertion) {
if (!$assertion) {
exit(1);
}
}

View file

@ -109,7 +109,7 @@ class HeadersTest extends TestCase
$this->assertTrue($this->object->isValid($headers));
$headers = [];
for($i = 0; $i < 100; $i++) {
for ($i = 0; $i < 100; $i++) {
$headers['key-' . $i] = 'value_' . $i;
}
$this->assertTrue($this->object->isValid($headers));