diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 33b37bb1b6..aad072c50a 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -2895,11 +2895,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId)); - var_dump('database_' . $database->getInternalId()); - var_dump($collectionId); - var_dump($collection); - var_dump($isAPIKey); - var_dump($isPrivilegedUser); + if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 69a76d9da4..a373c77b10 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -128,7 +128,6 @@ App::post('/v1/projects') $databases = Config::getParam('pools-database', []); - if ($region !== 'default') { $databaseKeys = System::getEnv('_APP_DATABASE_KEYS', ''); $keys = explode(',', $databaseKeys); @@ -235,8 +234,6 @@ App::post('/v1/projects') $create = false; } - - if ($create || $projectTables) { $audit = new Audit($dbForProject); $audit->setup(); diff --git a/app/http.php b/app/http.php index 7c37680c1e..07f1bbabe7 100644 --- a/app/http.php +++ b/app/http.php @@ -265,7 +265,7 @@ $http->on(Constant::EVENT_START, function (Server $http) use ($payloadSize, $reg $sharedTablesV1 = \explode(',', System::getEnv('_APP_DATABASE_SHARED_TABLES_V1', '')); $sharedTablesV2 = \array_diff($sharedTables, $sharedTablesV1); - $region = System::getEnv('_APP_REGION', 'fra'); + $region = System::getEnv('_APP_REGION', 'default'); $cache = $app->getResource('cache'); $regionDatabases = \array_filter( @@ -292,6 +292,16 @@ $http->on(Constant::EVENT_START, function (Server $http) use ($payloadSize, $reg Console::success('[Setup] - Skip: metadata table already exists'); } + if ($dbForProject->getCollection(Audit::COLLECTION)->isEmpty()) { + $audit = new Audit($dbForProject); + $audit->setup(); + } + + if ($dbForProject->getCollection(TimeLimit::COLLECTION)->isEmpty()) { + $adapter = new TimeLimit("", 0, 1, $dbForProject); + $adapter->setup(); + } + foreach ($projectCollections as $key => $collection) { if (($collection['$collection'] ?? '') !== Database::METADATA) { continue; diff --git a/app/init.php b/app/init.php index b4a689bfaa..4a35374143 100644 --- a/app/init.php +++ b/app/init.php @@ -1334,7 +1334,7 @@ App::setResource('project', function ($dbForPlatform, $request, $console) { $project = Authorization::skip(fn () => $dbForPlatform->getDocument('projects', $projectId)); - if ($project->getAttribute('region') !== System::getEnv('_APP_REGION')) { + if ($project->getAttribute('region') !== System::getEnv('_APP_REGION', 'default')) { var_dump(System::getEnv('_APP_REGION')); var_dump($project->getAttribute('region')); throw new Exception(Exception::GENERAL_ACCESS_FORBIDDEN, 'Project is not accessible in this region. Please make sure you are using the correct endpoint'); diff --git a/composer.json b/composer.json index 512e203a5e..afd870b3d6 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "utopia-php/cache": "0.11.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.53.200", + "utopia-php/database": "0.53.27", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", diff --git a/composer.lock b/composer.lock index c56ec65402..6cab92d581 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": "fae350df93342992edd8f639948e1570", + "content-hash": "cfa976b029b0e8f53ef617056d04face", "packages": [ { "name": "adhocore/jwt", @@ -3476,16 +3476,16 @@ }, { "name": "utopia-php/database", - "version": "0.53.200", + "version": "0.53.27", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "570c63a3760d0e1404679ddfacd9484af40bd9fc" + "reference": "d3a8cae6e743a6a1a5719b860762a03aabce678a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/570c63a3760d0e1404679ddfacd9484af40bd9fc", - "reference": "570c63a3760d0e1404679ddfacd9484af40bd9fc", + "url": "https://api.github.com/repos/utopia-php/database/zipball/d3a8cae6e743a6a1a5719b860762a03aabce678a", + "reference": "d3a8cae6e743a6a1a5719b860762a03aabce678a", "shasum": "" }, "require": { @@ -3526,9 +3526,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.53.200" + "source": "https://github.com/utopia-php/database/tree/0.53.27" }, - "time": "2024-12-01T07:59:15+00:00" + "time": "2024-12-02T08:53:55+00:00" }, { "name": "utopia-php/domains", @@ -8556,7 +8556,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -8580,5 +8580,5 @@ "platform-overrides": { "php": "8.3" }, - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.6.0" }