Merge branch '1.4.x' into fix-rate-limit-error-on-large-uploads
This commit is contained in:
commit
a76efe7d4e
3 changed files with 30 additions and 19 deletions
|
@ -1231,7 +1231,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/enum')
|
||||||
->param('databaseId', '', new UID(), 'Database ID.')
|
->param('databaseId', '', new UID(), 'Database ID.')
|
||||||
->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).')
|
->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).')
|
||||||
->param('key', '', new Key(), 'Attribute Key.')
|
->param('key', '', new Key(), 'Attribute Key.')
|
||||||
->param('elements', [], new ArrayList(new Text(APP_LIMIT_ARRAY_ELEMENT_SIZE, min: 0), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of elements in enumerated type. Uses length of longest element to determine size. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' elements are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long.')
|
->param('elements', [], new ArrayList(new Text(DATABASE::LENGTH_KEY), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of elements in enumerated type. Uses length of longest element to determine size. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' elements are allowed, each ' . DATABASE::LENGTH_KEY . ' characters long.')
|
||||||
->param('required', null, new Boolean(), 'Is attribute required?')
|
->param('required', null, new Boolean(), 'Is attribute required?')
|
||||||
->param('default', null, new Text(0), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true)
|
->param('default', null, new Text(0), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true)
|
||||||
->param('array', false, new Boolean(), 'Is attribute an array?', true)
|
->param('array', false, new Boolean(), 'Is attribute an array?', true)
|
||||||
|
@ -1240,16 +1240,6 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/enum')
|
||||||
->inject('queueForDatabase')
|
->inject('queueForDatabase')
|
||||||
->inject('queueForEvents')
|
->inject('queueForEvents')
|
||||||
->action(function (string $databaseId, string $collectionId, string $key, array $elements, ?bool $required, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents) {
|
->action(function (string $databaseId, string $collectionId, string $key, array $elements, ?bool $required, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents) {
|
||||||
// use length of longest string as attribute size
|
|
||||||
$size = 0;
|
|
||||||
foreach ($elements as $element) {
|
|
||||||
$length = \strlen($element);
|
|
||||||
if ($length === 0) {
|
|
||||||
throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, 'Each enum element must not be empty');
|
|
||||||
}
|
|
||||||
$size = ($length > $size) ? $length : $size;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_null($default) && !in_array($default, $elements)) {
|
if (!is_null($default) && !in_array($default, $elements)) {
|
||||||
throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, 'Default value not found in elements');
|
throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, 'Default value not found in elements');
|
||||||
}
|
}
|
||||||
|
@ -1257,7 +1247,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/enum')
|
||||||
$attribute = createAttribute($databaseId, $collectionId, new Document([
|
$attribute = createAttribute($databaseId, $collectionId, new Document([
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
'type' => Database::VAR_STRING,
|
'type' => Database::VAR_STRING,
|
||||||
'size' => $size,
|
'size' => Database::LENGTH_KEY,
|
||||||
'required' => $required,
|
'required' => $required,
|
||||||
'default' => $default,
|
'default' => $default,
|
||||||
'array' => $array,
|
'array' => $array,
|
||||||
|
@ -1930,7 +1920,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/attributes/enum/
|
||||||
->param('databaseId', '', new UID(), 'Database ID.')
|
->param('databaseId', '', new UID(), 'Database ID.')
|
||||||
->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).')
|
->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).')
|
||||||
->param('key', '', new Key(), 'Attribute Key.')
|
->param('key', '', new Key(), 'Attribute Key.')
|
||||||
->param('elements', null, new ArrayList(new Text(APP_LIMIT_ARRAY_ELEMENT_SIZE), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of elements in enumerated type. Uses length of longest element to determine size. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' elements are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long.')
|
->param('elements', null, new ArrayList(new Text(DATABASE::LENGTH_KEY), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of elements in enumerated type. Uses length of longest element to determine size. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' elements are allowed, each ' . DATABASE::LENGTH_KEY . ' characters long.')
|
||||||
->param('required', null, new Boolean(), 'Is attribute required?')
|
->param('required', null, new Boolean(), 'Is attribute required?')
|
||||||
->param('default', null, new Nullable(new Text(0)), 'Default value for attribute when not provided. Cannot be set when attribute is required.')
|
->param('default', null, new Nullable(new Text(0)), 'Default value for attribute when not provided. Cannot be set when attribute is required.')
|
||||||
->inject('response')
|
->inject('response')
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Appwrite\Platform\Tasks;
|
||||||
|
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
use Utopia\Config\Config;
|
use Utopia\Config\Config;
|
||||||
|
use Utopia\Database\Helpers\ID;
|
||||||
use Utopia\Database\Query;
|
use Utopia\Database\Query;
|
||||||
use Utopia\Platform\Action;
|
use Utopia\Platform\Action;
|
||||||
use Utopia\Cache\Cache;
|
use Utopia\Cache\Cache;
|
||||||
|
@ -45,6 +46,17 @@ class DeleteOrphanedProjects extends Action
|
||||||
/** @var array $collections */
|
/** @var array $collections */
|
||||||
$collectionsConfig = Config::getParam('collections', [])['projects'] ?? [];
|
$collectionsConfig = Config::getParam('collections', [])['projects'] ?? [];
|
||||||
|
|
||||||
|
$collectionsConfig = array_merge([
|
||||||
|
'audit' => [
|
||||||
|
'$id' => ID::custom('audit'),
|
||||||
|
'$collection' => Database::METADATA
|
||||||
|
],
|
||||||
|
'abuse' => [
|
||||||
|
'$id' => ID::custom('abuse'),
|
||||||
|
'$collection' => Database::METADATA
|
||||||
|
]
|
||||||
|
], $collectionsConfig);
|
||||||
|
|
||||||
/* Initialise new Utopia app */
|
/* Initialise new Utopia app */
|
||||||
$app = new App('UTC');
|
$app = new App('UTC');
|
||||||
$console = $app->getResource('console');
|
$console = $app->getResource('console');
|
||||||
|
@ -80,6 +92,7 @@ class DeleteOrphanedProjects extends Action
|
||||||
$dbForProject = new Database($adapter, $cache);
|
$dbForProject = new Database($adapter, $cache);
|
||||||
$dbForProject->setDefaultDatabase('appwrite');
|
$dbForProject->setDefaultDatabase('appwrite');
|
||||||
$dbForProject->setNamespace('_' . $project->getInternalId());
|
$dbForProject->setNamespace('_' . $project->getInternalId());
|
||||||
|
|
||||||
$collectionsCreated = 0;
|
$collectionsCreated = 0;
|
||||||
$cnt++;
|
$cnt++;
|
||||||
if ($dbForProject->exists($dbForProject->getDefaultDatabase(), Database::METADATA)) {
|
if ($dbForProject->exists($dbForProject->getDefaultDatabase(), Database::METADATA)) {
|
||||||
|
@ -87,10 +100,8 @@ class DeleteOrphanedProjects extends Action
|
||||||
}
|
}
|
||||||
|
|
||||||
$msg = '(' . $cnt . ') found (' . $collectionsCreated . ') collections on project (' . $project->getInternalId() . ') , database (' . $project['database'] . ')';
|
$msg = '(' . $cnt . ') found (' . $collectionsCreated . ') collections on project (' . $project->getInternalId() . ') , database (' . $project['database'] . ')';
|
||||||
/**
|
|
||||||
* +2 = audit+abuse
|
if ($collectionsCreated >= count($collectionsConfig)) {
|
||||||
*/
|
|
||||||
if ($collectionsCreated === (count($collectionsConfig) + 2)) {
|
|
||||||
Console::log($msg . ' ignoring....');
|
Console::log($msg . ' ignoring....');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -107,16 +118,26 @@ class DeleteOrphanedProjects extends Action
|
||||||
Console::info('--Deleting collection (' . $collection->getId() . ') project no (' . $project->getInternalId() . ')');
|
Console::info('--Deleting collection (' . $collection->getId() . ') project no (' . $project->getInternalId() . ')');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($commit) {
|
if ($commit) {
|
||||||
$dbForConsole->deleteDocument('projects', $project->getId());
|
$dbForConsole->deleteDocument('projects', $project->getId());
|
||||||
$dbForConsole->deleteCachedDocument('projects', $project->getId());
|
$dbForConsole->deleteCachedDocument('projects', $project->getId());
|
||||||
|
|
||||||
|
if ($dbForProject->exists($dbForProject->getDefaultDatabase(), Database::METADATA)) {
|
||||||
|
try {
|
||||||
|
$dbForProject->deleteCollection(Database::METADATA);
|
||||||
|
$dbForProject->deleteCachedCollection(Database::METADATA);
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Console::warning('Metadata collection does not exist');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Console::info('--Deleting project no (' . $project->getInternalId() . ')');
|
Console::info('--Deleting project no (' . $project->getInternalId() . ')');
|
||||||
|
|
||||||
$orphans++;
|
$orphans++;
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
Console::error('Error: ' . $th->getMessage());
|
Console::error('Error: ' . $th->getMessage() . ' ' . $th->getTraceAsString());
|
||||||
} finally {
|
} finally {
|
||||||
$pools
|
$pools
|
||||||
->get($db)
|
->get($db)
|
||||||
|
|
|
@ -978,7 +978,7 @@ trait DatabasesBase
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(400, $badEnum['headers']['status-code']);
|
$this->assertEquals(400, $badEnum['headers']['status-code']);
|
||||||
$this->assertEquals('Each enum element must not be empty', $badEnum['body']['message']);
|
$this->assertEquals('Invalid `elements` param: Value must a valid array and Value must be a valid string and at least 1 chars and no longer than 255 chars', $badEnum['body']['message']);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue