diff --git a/app/config/collections2.php b/app/config/collections2.php index e1ab45dac5..33295b7e0d 100644 --- a/app/config/collections2.php +++ b/app/config/collections2.php @@ -8,13 +8,13 @@ $auth = Config::getParam('auth', []); $collections = [ 'collections' => [ - '$collection' => Database::COLLECTIONS, + '$collection' => Database::METADATA, '$id' => 'collections', 'name' => 'Collections', 'attributes' => [ [ '$id' => 'name', - 'type' => self::VAR_STRING, + 'type' => Database::VAR_STRING, 'size' => 256, 'required' => true, 'signed' => true, @@ -45,7 +45,7 @@ $collections = [ ], [ '$id' => 'attributes', - 'type' => self::VAR_STRING, + 'type' => Database::VAR_STRING, 'size' => 1000000, 'required' => false, 'signed' => true, @@ -54,7 +54,7 @@ $collections = [ ], [ '$id' => 'indexes', - 'type' => self::VAR_STRING, + 'type' => Database::VAR_STRING, 'size' => 1000000, 'required' => false, 'signed' => true, @@ -85,7 +85,7 @@ $collections = [ ], 'projects' => [ - '$collection' => Database::COLLECTIONS, + '$collection' => Database::METADATA, '$id' => 'projects', 'name' => 'Projects', 'attributes' => [ @@ -311,7 +311,7 @@ $collections = [ ], 'users' => [ - '$collection' => Database::COLLECTIONS, + '$collection' => Database::METADATA, '$id' => 'users', 'name' => 'Users', 'attributes' => [ @@ -460,7 +460,7 @@ $collections = [ ], 'sessions' => [ - '$collection' => Database::COLLECTIONS, + '$collection' => Database::METADATA, '$id' => 'sessions', 'name' => 'Sessions', 'attributes' => [ @@ -708,7 +708,7 @@ $collections = [ ], 'teams' => [ - '$collection' => Database::COLLECTIONS, + '$collection' => Database::METADATA, '$id' => 'teams', 'name' => 'Teams', 'attributes' => [ @@ -758,7 +758,7 @@ $collections = [ ], 'memberships' => [ - '$collection' => Database::COLLECTIONS, + '$collection' => Database::METADATA, '$id' => 'memberships', 'name' => 'Memberships', 'attributes' => [ @@ -866,7 +866,7 @@ $collections = [ ], 'files' => [ - '$collection' => Database::COLLECTIONS, + '$collection' => Database::METADATA, '$id' => 'files', 'name' => 'Files', 'attributes' => [ @@ -1045,7 +1045,7 @@ $collections = [ ], 'functions' => [ - '$collection' => Database::COLLECTIONS, + '$collection' => Database::METADATA, '$id' => 'functions', 'name' => 'Functions', 'attributes' => [ @@ -1206,7 +1206,7 @@ $collections = [ ], 'tags' => [ - '$collection' => Database::COLLECTIONS, + '$collection' => Database::METADATA, '$id' => 'tags', 'name' => 'Tags', 'attributes' => [ @@ -1279,7 +1279,7 @@ $collections = [ ], 'executions' => [ - '$collection' => Database::COLLECTIONS, + '$collection' => Database::METADATA, '$id' => 'executions', 'name' => 'Executions', 'attributes' => [ @@ -1396,7 +1396,7 @@ $collections = [ ], 'certificates' => [ - '$collection' => Database::COLLECTIONS, + '$collection' => Database::METADATA, '$id' => 'certificates', 'name' => 'Certificates', 'attributes' => [ diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index dd2dd3cf8c..d2a760e683 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -1,12 +1,10 @@ getAttribute('format', null); $filters = $attribute->getAttribute('filters', []); // filters are hidden from the endpoint - $collection = $dbForExternal->getCollection($collectionId); + $collection = $dbForInternal->getDocument('collections', $collectionId); if ($collection->isEmpty()) { throw new Exception('Collection not found', 404); @@ -85,7 +84,7 @@ $attributesCallback = function ($attribute, $response, $dbForExternal, $database } } - $success = $dbForExternal->addAttributeInQueue($collectionId, $attributeId, $type, $size, $required, $default, $signed, $array, $format, $filters); + $dbForExternal->addAttributeInQueue($collectionId, $attributeId, $type, $size, $required, $default, $signed, $array, $format, $filters); // Database->addAttributeInQueue() does not return a document // So we need to create one for the response @@ -204,8 +203,8 @@ App::get('/v1/database/collections') } $response->dynamic(new Document([ - 'collections' => $dbForInternal->find(Database::COLLECTIONS, $queries, $limit, $offset, ['_id'], [$orderType]), - 'sum' => $dbForInternal->count(Database::COLLECTIONS, $queries, APP_LIMIT_COUNT), + 'collections' => $dbForInternal->find('collections', $queries, $limit, $offset, ['_id'], [$orderType]), + 'sum' => $dbForInternal->count('collections', $queries, APP_LIMIT_COUNT), ]), Response::MODEL_COLLECTION_LIST); }); @@ -360,11 +359,13 @@ App::post('/v1/database/collections/:collectionId/attributes/string') ->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) ->inject('response') + ->inject('dbForInternal') ->inject('dbForExternal') ->inject('database') ->inject('audits') - ->action(function ($collectionId, $attributeId, $size, $required, $default, $array, $response, $dbForExternal, $database, $audits) use ($attributesCallback) { + ->action(function ($collectionId, $attributeId, $size, $required, $default, $array, $response, $dbForInternal, $dbForExternal, $database, $audits) use ($attributesCallback) { /** @var Appwrite\Utopia\Response $response */ + /** @var Utopia\Database\Database $dbForInternal*/ /** @var Utopia\Database\Database $dbForExternal*/ /** @var Appwrite\Event\Event $database */ /** @var Appwrite\Event\Event $audits */ @@ -377,7 +378,7 @@ App::post('/v1/database/collections/:collectionId/attributes/string') 'required' => $required, 'default' => $default, 'array' => $array, - ]), $response, $dbForExternal, $database, $audits); + ]), $response, $dbForInternal, $dbForExternal, $database, $audits); }); App::post('/v1/database/collections/:collectionId/attributes/email') @@ -398,11 +399,13 @@ App::post('/v1/database/collections/:collectionId/attributes/email') ->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) ->inject('response') + ->inject('dbForInternal') ->inject('dbForExternal') ->inject('database') ->inject('audits') - ->action(function ($collectionId, $attributeId, $required, $default, $array, $response, $dbForExternal, $database, $audits) use ($attributesCallback) { + ->action(function ($collectionId, $attributeId, $required, $default, $array, $response, $dbForInternal, $dbForExternal, $database, $audits) use ($attributesCallback) { /** @var Appwrite\Utopia\Response $response */ + /** @var Utopia\Database\Database $dbForInternal*/ /** @var Utopia\Database\Database $dbForExternal*/ /** @var Appwrite\Event\Event $database */ /** @var Appwrite\Event\Event $audits */ @@ -416,7 +419,7 @@ App::post('/v1/database/collections/:collectionId/attributes/email') 'default' => $default, 'array' => $array, 'format' => \json_encode(['name'=>'email']), - ]), $response, $dbForExternal, $database, $audits); + ]), $response, $dbForInternal, $dbForExternal, $database, $audits); }); App::post('/v1/database/collections/:collectionId/attributes/ip') @@ -437,11 +440,13 @@ App::post('/v1/database/collections/:collectionId/attributes/ip') ->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) ->inject('response') + ->inject('dbForInternal') ->inject('dbForExternal') ->inject('database') ->inject('audits') - ->action(function ($collectionId, $attributeId, $required, $default, $array, $response, $dbForExternal, $database, $audits) use ($attributesCallback) { + ->action(function ($collectionId, $attributeId, $required, $default, $array, $response, $dbForInternal, $dbForExternal, $database, $audits) use ($attributesCallback) { /** @var Appwrite\Utopia\Response $response */ + /** @var Utopia\Database\Database $dbForInternal*/ /** @var Utopia\Database\Database $dbForExternal*/ /** @var Appwrite\Event\Event $database */ /** @var Appwrite\Event\Event $audits */ @@ -455,7 +460,7 @@ App::post('/v1/database/collections/:collectionId/attributes/ip') 'default' => $default, 'array' => $array, 'format' => \json_encode(['name'=>'ip']), - ]), $response, $dbForExternal, $database, $audits); + ]), $response, $dbForInternal, $dbForExternal, $database, $audits); }); App::post('/v1/database/collections/:collectionId/attributes/url') @@ -477,11 +482,13 @@ App::post('/v1/database/collections/:collectionId/attributes/url') ->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) ->inject('response') + ->inject('dbForInternal') ->inject('dbForExternal') ->inject('database') ->inject('audits') - ->action(function ($collectionId, $attributeId, $size, $required, $default, $array, $response, $dbForExternal, $database, $audits) use ($attributesCallback) { + ->action(function ($collectionId, $attributeId, $size, $required, $default, $array, $response, $dbForInternal, $dbForExternal, $database, $audits) use ($attributesCallback) { /** @var Appwrite\Utopia\Response $response */ + /** @var Utopia\Database\Database $dbForInternal*/ /** @var Utopia\Database\Database $dbForExternal*/ /** @var Appwrite\Event\Event $database */ /** @var Appwrite\Event\Event $audits */ @@ -495,7 +502,7 @@ App::post('/v1/database/collections/:collectionId/attributes/url') 'default' => $default, 'array' => $array, 'format' => \json_encode(['name'=>'url']), - ]), $response, $dbForExternal, $database, $audits); + ]), $response, $dbForInternal, $dbForExternal, $database, $audits); }); App::post('/v1/database/collections/:collectionId/attributes/integer') @@ -518,11 +525,13 @@ App::post('/v1/database/collections/:collectionId/attributes/integer') ->param('default', null, new Integer(), '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) ->inject('response') + ->inject('dbForInternal') ->inject('dbForExternal') ->inject('database') ->inject('audits') - ->action(function ($collectionId, $attributeId, $required, $min, $max, $default, $array, $response, $dbForExternal, $database, $audits) use ($attributesCallback) { + ->action(function ($collectionId, $attributeId, $required, $min, $max, $default, $array, $response, $dbForInternal, $dbForExternal, $database, $audits) use ($attributesCallback) { /** @var Appwrite\Utopia\Response $response */ + /** @var Utopia\Database\Database $dbForInternal*/ /** @var Utopia\Database\Database $dbForExternal*/ /** @var Appwrite\Event\Event $database */ /** @var Appwrite\Event\Event $audits */ @@ -540,7 +549,7 @@ App::post('/v1/database/collections/:collectionId/attributes/integer') 'min' => $min, 'max' => $max, ]), - ]), $response, $dbForExternal, $database, $audits); + ]), $response, $dbForInternal, $dbForExternal, $database, $audits); }); App::post('/v1/database/collections/:collectionId/attributes/float') @@ -563,11 +572,13 @@ App::post('/v1/database/collections/:collectionId/attributes/float') ->param('default', null, new FloatValidator(), '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) ->inject('response') + ->inject('dbForInternal') ->inject('dbForExternal') ->inject('database') ->inject('audits') - ->action(function ($collectionId, $attributeId, $required, $min, $max, $default, $array, $response, $dbForExternal, $database, $audits) use ($attributesCallback) { + ->action(function ($collectionId, $attributeId, $required, $min, $max, $default, $array, $response, $dbForInternal, $dbForExternal, $database, $audits) use ($attributesCallback) { /** @var Appwrite\Utopia\Response $response */ + /** @var Utopia\Database\Database $dbForInternal*/ /** @var Utopia\Database\Database $dbForExternal*/ /** @var Appwrite\Event\Event $database */ /** @var Appwrite\Event\Event $audits */ @@ -585,7 +596,7 @@ App::post('/v1/database/collections/:collectionId/attributes/float') 'min' => $min, 'max' => $max, ]), - ]), $response, $dbForExternal, $database, $audits); + ]), $response, $dbForInternal, $dbForExternal, $database, $audits); }); App::post('/v1/database/collections/:collectionId/attributes/boolean') @@ -606,11 +617,13 @@ App::post('/v1/database/collections/:collectionId/attributes/boolean') ->param('default', null, new Boolean(), '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) ->inject('response') + ->inject('dbForInternal') ->inject('dbForExternal') ->inject('database') ->inject('audits') - ->action(function ($collectionId, $attributeId, $required, $default, $array, $response, $dbForExternal, $database, $audits) use ($attributesCallback) { + ->action(function ($collectionId, $attributeId, $required, $default, $array, $response, $dbForInternal, $dbForExternal, $database, $audits) use ($attributesCallback) { /** @var Appwrite\Utopia\Response $response */ + /** @var Utopia\Database\Database $dbForInternal*/ /** @var Utopia\Database\Database $dbForExternal*/ /** @var Appwrite\Event\Event $database */ /** @var Appwrite\Event\Event $audits */ @@ -623,7 +636,7 @@ App::post('/v1/database/collections/:collectionId/attributes/boolean') 'required' => $required, 'default' => $default, 'array' => $array, - ]), $response, $dbForExternal, $database, $audits); + ]), $response, $dbForInternal, $dbForExternal, $database, $audits); }); App::get('/v1/database/collections/:collectionId/attributes') @@ -639,12 +652,12 @@ App::get('/v1/database/collections/:collectionId/attributes') ->label('sdk.response.model', Response::MODEL_ATTRIBUTE_LIST) ->param('collectionId', '', new UID(), 'Collection unique ID. You can create a new collection using the Database service [server integration](/docs/server/database#createCollection).') ->inject('response') - ->inject('dbForExternal') - ->action(function ($collectionId, $response, $dbForExternal) { + ->inject('dbForInternal') + ->action(function ($collectionId, $response, $dbForInternal) { /** @var Appwrite\Utopia\Response $response */ - /** @var Utopia\Database\Database $dbForExternal */ + /** @var Utopia\Database\Database $dbForInternal */ - $collection = $dbForExternal->getCollection($collectionId); + $collection = $dbForInternal->getDocument('collections', $collectionId); if ($collection->isEmpty()) { throw new Exception('Collection not found', 404); @@ -678,12 +691,12 @@ App::get('/v1/database/collections/:collectionId/attributes/:attributeId') ->param('collectionId', '', new UID(), 'Collection unique ID. You can create a new collection using the Database service [server integration](/docs/server/database#createCollection).') ->param('attributeId', '', new Key(), 'Attribute ID.') ->inject('response') - ->inject('dbForExternal') - ->action(function ($collectionId, $attributeId, $response, $dbForExternal) { + ->inject('dbForInternal') + ->action(function ($collectionId, $attributeId, $response, $dbForInternal) { /** @var Appwrite\Utopia\Response $response */ - /** @var Utopia\Database\Database $dbForExternal */ + /** @var Utopia\Database\Database $dbForInternal */ - $collection = $dbForExternal->getCollection($collectionId); + $collection = $dbForInternal->getDocument('collections', $collectionId); if (empty($collection)) { throw new Exception('Collection not found', 404); @@ -719,18 +732,18 @@ App::delete('/v1/database/collections/:collectionId/attributes/:attributeId') ->param('collectionId', '', new UID(), 'Collection unique ID. You can create a new collection using the Database service [server integration](/docs/server/database#createCollection).') ->param('attributeId', '', new Key(), 'Attribute ID.') ->inject('response') - ->inject('dbForExternal') + ->inject('dbForInternal') ->inject('database') ->inject('events') ->inject('audits') - ->action(function ($collectionId, $attributeId, $response, $dbForExternal, $database, $events, $audits) { + ->action(function ($collectionId, $attributeId, $response, $dbForInternal, $database, $events, $audits) { /** @var Appwrite\Utopia\Response $response */ - /** @var Utopia\Database\Database $dbForExternal */ + /** @var Utopia\Database\Database $dbForInternal */ /** @var Appwrite\Event\Event $database */ /** @var Appwrite\Event\Event $events */ /** @var Appwrite\Event\Event $audits */ - $collection = $dbForExternal->getCollection($collectionId); + $collection = $dbForInternal->getDocument('collections', $collectionId); if ($collection->isEmpty()) { throw new Exception('Collection not found', 404); @@ -788,16 +801,16 @@ App::post('/v1/database/collections/:collectionId/indexes') ->param('attributes', null, new ArrayList(new Key()), 'Array of attributes to index.') ->param('orders', [], new ArrayList(new WhiteList(['ASC', 'DESC'], false, Database::VAR_STRING)), 'Array of index orders.', true) ->inject('response') - ->inject('dbForExternal') + ->inject('dbForInternal') ->inject('database') ->inject('audits') - ->action(function ($collectionId, $id, $type, $attributes, $orders, $response, $dbForExternal, $database, $audits) { + ->action(function ($collectionId, $id, $type, $attributes, $orders, $response, $dbForInternal, $database, $audits) { /** @var Appwrite\Utopia\Response $response */ - /** @var Utopia\Database\Database $dbForExternal */ + /** @var Utopia\Database\Database $dbForInternal */ /** @var Appwrite\Event\Event $database */ /** @var Appwrite\Event\Event $audits */ - $collection = $dbForExternal->getCollection($collectionId); + $collection = $dbForInternal->getDocument('collections', $collectionId); if ($collection->isEmpty()) { throw new Exception('Collection not found', 404); @@ -827,7 +840,7 @@ App::post('/v1/database/collections/:collectionId/indexes') $lengths[$key] = ($attributeType === Database::VAR_STRING) ? $attributeSize : null; } - $success = $dbForExternal->addIndexInQueue($collectionId, $id, $type, $attributes, $lengths, $orders); + $dbForInternal->addIndexInQueue($collectionId, $id, $type, $attributes, $lengths, $orders); // Database->createIndex() does not return a document // So we need to create one for the response @@ -871,12 +884,12 @@ App::get('/v1/database/collections/:collectionId/indexes') ->label('sdk.response.model', Response::MODEL_INDEX_LIST) ->param('collectionId', '', new UID(), 'Collection unique ID. You can create a new collection using the Database service [server integration](/docs/server/database#createCollection).') ->inject('response') - ->inject('dbForExternal') - ->action(function ($collectionId, $response, $dbForExternal) { + ->inject('dbForInternal') + ->action(function ($collectionId, $response, $dbForInternal) { /** @var Appwrite\Utopia\Response $response */ - /** @var Utopia\Database\Database $dbForExternal */ + /** @var Utopia\Database\Database $dbForInternal */ - $collection = $dbForExternal->getCollection($collectionId); + $collection = $dbForInternal->getDocument('collections', $collectionId); if ($collection->isEmpty()) { throw new Exception('Collection not found', 404); @@ -910,12 +923,12 @@ App::get('/v1/database/collections/:collectionId/indexes/:indexId') ->param('collectionId', '', new UID(), 'Collection unique ID. You can create a new collection using the Database service [server integration](/docs/server/database#createCollection).') ->param('indexId', null, new Key(), 'Index ID.') ->inject('response') - ->inject('dbForExternal') - ->action(function ($collectionId, $indexId, $response, $dbForExternal) { + ->inject('dbForInternal') + ->action(function ($collectionId, $indexId, $response, $dbForInternal) { /** @var Appwrite\Utopia\Response $response */ - /** @var Utopia\Database\Database $dbForExternal */ + /** @var Utopia\Database\Database $dbForInternal */ - $collection = $dbForExternal->getCollection($collectionId); + $collection = $dbForInternal->getDocument('collections', $collectionId); if ($collection->isEmpty()) { throw new Exception('Collection not found', 404); @@ -923,7 +936,7 @@ App::get('/v1/database/collections/:collectionId/indexes/:indexId') $indexes = $collection->getAttribute('indexes'); - // // Search for index + // Search for index $indexIndex = array_search($indexId, array_column($indexes, '$id')); if ($indexIndex === false) { @@ -951,18 +964,18 @@ App::delete('/v1/database/collections/:collectionId/indexes/:indexId') ->param('collectionId', null, new UID(), 'Collection unique ID. You can create a new collection using the Database service [server integration](/docs/server/database#createCollection).') ->param('indexId', '', new Key(), 'Index ID.') ->inject('response') - ->inject('dbForExternal') + ->inject('dbForInternal') ->inject('database') ->inject('events') ->inject('audits') - ->action(function ($collectionId, $indexId, $response, $dbForExternal, $database, $events, $audits) { + ->action(function ($collectionId, $indexId, $response, $dbForInternal, $database, $events, $audits) { /** @var Appwrite\Utopia\Response $response */ - /** @var Utopia\Database\Database $dbForExternal */ + /** @var Utopia\Database\Database $dbForInternal */ /** @var Appwrite\Event\Event $database */ /** @var Appwrite\Event\Event $events */ /** @var Appwrite\Event\Event $audits */ - $collection = $dbForExternal->getCollection($collectionId); + $collection = $dbForInternal->getDocument('collections', $collectionId); if ($collection->isEmpty()) { throw new Exception('Collection not found', 404); @@ -1017,11 +1030,13 @@ App::post('/v1/database/collections/:collectionId/documents') ->param('read', null, new Permissions(), 'An array of strings with read permissions. By default only the current user is granted with read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true) ->param('write', null, new Permissions(), 'An array of strings with write permissions. By default only the current user is granted with write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true) ->inject('response') + ->inject('dbForInternal') ->inject('dbForExternal') ->inject('user') ->inject('audits') - ->action(function ($documentId, $collectionId, $data, $read, $write, $response, $dbForExternal, $user, $audits) { + ->action(function ($documentId, $collectionId, $data, $read, $write, $response, $dbForInternal, $dbForExternal, $user, $audits) { /** @var Appwrite\Utopia\Response $response */ + /** @var Utopia\Database\Database $dbForInternal */ /** @var Utopia\Database\Database $dbForExternal */ /** @var Utopia\Database\Document $user */ /** @var Appwrite\Event\Event $audits */ @@ -1036,7 +1051,7 @@ App::post('/v1/database/collections/:collectionId/documents') throw new Exception('$id is not allowed for creating new documents, try update instead', 400); } - $collection = $dbForExternal->getCollection($collectionId); + $collection = $dbForInternal->getDocument('collections', $collectionId); if ($collection->isEmpty()) { throw new Exception('Collection not found', 404); @@ -1082,12 +1097,13 @@ App::get('/v1/database/collections/:collectionId/documents') ->param('orderAttributes', [], new ArrayList(new Text(128)), 'Array of attributes used to sort results.', true) ->param('orderTypes', [], new ArrayList(new WhiteList(['DESC', 'ASC'], true)), 'Array of order directions for sorting attribtues. Possible values are DESC for descending order, or ASC for ascending order.', true) ->inject('response') + ->inject('dbForInternal') ->inject('dbForExternal') - ->action(function ($collectionId, $queries, $limit, $offset, $orderAttributes, $orderTypes, $response, $dbForExternal) { + ->action(function ($collectionId, $queries, $limit, $offset, $orderAttributes, $orderTypes, $response, $dbForInternal, $dbForExternal) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForExternal */ - $collection = $dbForExternal->getCollection($collectionId); + $collection = $dbForInternal->getDocument('collections', $collectionId); if ($collection->isEmpty()) { throw new Exception('Collection not found', 404); @@ -1109,11 +1125,9 @@ App::get('/v1/database/collections/:collectionId/documents') throw new Exception($validator->getDescription(), 400); } - $documents = $dbForExternal->find($collectionId, $queries, $limit, $offset, $orderAttributes, $orderTypes); - $response->dynamic(new Document([ - 'sum' => \count($documents), - 'documents' => $documents, + 'sum' => $dbForInternal->find($collectionId, $queries, $limit, $offset, ['_id'], $orderTypes), + 'documents' => $dbForExternal->find($collectionId, $queries, $limit, $offset, $orderAttributes, $orderTypes), ]), Response::MODEL_DOCUMENT_LIST); }); @@ -1131,12 +1145,14 @@ App::get('/v1/database/collections/:collectionId/documents/:documentId') ->param('collectionId', null, new UID(), 'Collection unique ID. You can create a new collection using the Database service [server integration](/docs/server/database#createCollection).') ->param('documentId', null, new UID(), 'Document unique ID.') ->inject('response') + ->inject('$dbForInternal') ->inject('dbForExternal') - ->action(function ($collectionId, $documentId, $response, $dbForExternal) { + ->action(function ($collectionId, $documentId, $response, $dbForInternal, $dbForExternal) { /** @var Appwrite\Utopia\Response $response */ + /** @var Utopia\Database\Database $$dbForInternal */ /** @var Utopia\Database\Database $dbForExternal */ - $collection = $dbForExternal->getCollection($collectionId); + $collection = $dbForInternal->getDocument('collections', $collectionId); if ($collection->isEmpty()) { throw new Exception('Collection not found', 404); @@ -1169,14 +1185,16 @@ App::patch('/v1/database/collections/:collectionId/documents/:documentId') ->param('read', null, new Permissions(), 'An array of strings with read permissions. By default inherits the existing read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true) ->param('write', null, new Permissions(), 'An array of strings with write permissions. By default inherits the existing write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true) ->inject('response') + ->inject('dbForInternal') ->inject('dbForExternal') ->inject('audits') - ->action(function ($collectionId, $documentId, $data, $read, $write, $response, $dbForExternal, $audits) { + ->action(function ($collectionId, $documentId, $data, $read, $write, $response, $dbForInternal, $dbForExternal, $audits) { /** @var Appwrite\Utopia\Response $response */ + /** @var Utopia\Database\Database $dbForInternal */ /** @var Utopia\Database\Database $dbForExternal */ /** @var Appwrite\Event\Event $audits */ - $collection = $dbForExternal->getCollection($collectionId); + $collection = $dbForInternal->getDocument('collections', $collectionId); if ($collection->isEmpty()) { throw new Exception('Collection not found', 404); @@ -1236,16 +1254,17 @@ App::delete('/v1/database/collections/:collectionId/documents/:documentId') ->param('collectionId', null, new UID(), 'Collection unique ID. You can create a new collection using the Database service [server integration](/docs/server/database#createCollection).') ->param('documentId', null, new UID(), 'Document unique ID.') ->inject('response') + ->inject('dbForInternal') ->inject('dbForExternal') ->inject('events') ->inject('audits') - ->action(function ($collectionId, $documentId, $response, $dbForExternal, $events, $audits) { + ->action(function ($collectionId, $documentId, $response, $dbForInternal, $dbForExternal, $events, $audits) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForExternal */ /** @var Appwrite\Event\Event $events */ /** @var Appwrite\Event\Event $audits */ - $collection = $dbForExternal->getCollection($collectionId); + $collection = $dbForInternal->getDocument('collections', $collectionId); if ($collection->isEmpty()) { throw new Exception('Collection not found', 404); @@ -1257,7 +1276,7 @@ App::delete('/v1/database/collections/:collectionId/documents/:documentId') throw new Exception('No document found', 404); } - $success = $dbForExternal->deleteDocument($collectionId, $documentId); + $dbForExternal->deleteDocument($collectionId, $documentId); $events ->setParam('eventData', $response->output($document, Response::MODEL_DOCUMENT)) @@ -1270,4 +1289,4 @@ App::delete('/v1/database/collections/:collectionId/documents/:documentId') ; $response->noContent(); - }); + }); \ No newline at end of file diff --git a/composer.json b/composer.json index b3593e34d9..38e3669b0d 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ "utopia-php/cache": "0.4.*", "utopia-php/cli": "0.11.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.6.*", + "utopia-php/database": "0.8.*", "utopia-php/locale": "0.4.*", "utopia-php/registry": "0.5.*", "utopia-php/preloader": "0.2.*", @@ -53,6 +53,7 @@ "utopia-php/swoole": "0.2.*", "utopia-php/storage": "0.5.*", "utopia-php/image": "0.5.*", + "resque/php-resque": "1.3.6", "matomo/device-detector": "4.2.3", "dragonmantank/cron-expression": "3.1.0", diff --git a/composer.lock b/composer.lock index c528f39540..77f53238c2 100644 --- a/composer.lock +++ b/composer.lock @@ -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": "c2bda60e7b774a0c813f52033a268c6c", + "content-hash": "c43b186a794c614272806e6530ada496", "packages": [ { "name": "adhocore/jwt", @@ -1666,22 +1666,22 @@ }, { "name": "utopia-php/abuse", - "version": "0.6.1", + "version": "0.6.3", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "c9078aa3a87750d66060f0ed7642e03e5815da17" + "reference": "d63e928c2c50b367495a499a85ba9806ee274c5e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/c9078aa3a87750d66060f0ed7642e03e5815da17", - "reference": "c9078aa3a87750d66060f0ed7642e03e5815da17", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/d63e928c2c50b367495a499a85ba9806ee274c5e", + "reference": "d63e928c2c50b367495a499a85ba9806ee274c5e", "shasum": "" }, "require": { "ext-pdo": "*", "php": ">=7.4", - "utopia-php/database": "0.6.*" + "utopia-php/database": ">=0.6 <1.0" }, "require-dev": { "phpunit/phpunit": "^9.4", @@ -1713,9 +1713,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/0.6.1" + "source": "https://github.com/utopia-php/abuse/tree/0.6.3" }, - "time": "2021-08-03T19:31:07+00:00" + "time": "2021-08-16T18:38:31+00:00" }, { "name": "utopia-php/analytics", @@ -1774,22 +1774,22 @@ }, { "name": "utopia-php/audit", - "version": "0.6.1", + "version": "0.6.3", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "971dcd5c88309656df31ac20f326d3ac8b555594" + "reference": "d79b467fbc7d03e5e02f12cdeb08761507a60ca0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/971dcd5c88309656df31ac20f326d3ac8b555594", - "reference": "971dcd5c88309656df31ac20f326d3ac8b555594", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/d79b467fbc7d03e5e02f12cdeb08761507a60ca0", + "reference": "d79b467fbc7d03e5e02f12cdeb08761507a60ca0", "shasum": "" }, "require": { "ext-pdo": "*", "php": ">=7.4", - "utopia-php/database": "0.6.*" + "utopia-php/database": ">=0.6 <1.0" }, "require-dev": { "phpunit/phpunit": "^9.3", @@ -1821,9 +1821,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/0.6.1" + "source": "https://github.com/utopia-php/audit/tree/0.6.3" }, - "time": "2021-08-03T19:29:34+00:00" + "time": "2021-08-16T18:49:55+00:00" }, { "name": "utopia-php/cache", @@ -1984,16 +1984,16 @@ }, { "name": "utopia-php/database", - "version": "0.6.1", + "version": "0.8.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "59d9d34164b6fb896bc43085a9a82a292b43473a" + "reference": "2645c150267aaf73c70fb8a8d1a74430c9e6f336" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/59d9d34164b6fb896bc43085a9a82a292b43473a", - "reference": "59d9d34164b6fb896bc43085a9a82a292b43473a", + "url": "https://api.github.com/repos/utopia-php/database/zipball/2645c150267aaf73c70fb8a8d1a74430c9e6f336", + "reference": "2645c150267aaf73c70fb8a8d1a74430c9e6f336", "shasum": "" }, "require": { @@ -2041,9 +2041,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.6.1" + "source": "https://github.com/utopia-php/database/tree/0.8.0" }, - "time": "2021-08-05T17:19:16+00:00" + "time": "2021-08-16T17:19:07+00:00" }, { "name": "utopia-php/domains", @@ -6278,5 +6278,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.0.0" }