From d979c0c914c635633411b8585cd9b1ef3045241d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 21 Oct 2024 22:43:47 +1300 Subject: [PATCH] Create metadata document from outside if duplicate on shared tables V1 --- app/controllers/api/projects.php | 16 +++++++++++++++- composer.lock | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index e80e2888b2..7d8ddd8a79 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -234,7 +234,21 @@ App::post('/v1/projects') $attributes = \array_map(fn ($attribute) => new Document($attribute), $collection['attributes']); $indexes = \array_map(fn (array $index) => new Document($index), $collection['indexes']); - $dbForProject->createCollection($key, $attributes, $indexes); + + try { + $dbForProject->createCollection($key, $attributes, $indexes); + } catch (Duplicate) { + if (!$globalCollections) { + $dbForProject->createDocument(Database::METADATA, new Document([ + '$id' => ID::custom($key), + '$permissions' => [Permission::create(Role::any())], + 'name' => $key, + 'attributes' => $attributes, + 'indexes' => $indexes, + 'documentSecurity' => true + ])); + } + } } } diff --git a/composer.lock b/composer.lock index fdce5e2809..e0c0b534b4 100644 --- a/composer.lock +++ b/composer.lock @@ -7038,5 +7038,5 @@ "platform-overrides": { "php": "8.3" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" }