diff --git a/app/config/collections.php b/app/config/collections.php index ac13bae12..5ce866703 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -30,28 +30,6 @@ $collections = [ 'array' => false, 'filters' => [], ], - [ - '$id' => 'dateCreated', - 'type' => Database::VAR_INTEGER, - 'format' => '', - 'size' => 0, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ], - [ - '$id' => 'dateUpdated', - 'type' => Database::VAR_INTEGER, - 'format' => '', - 'size' => 0, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ], [ '$id' => 'enabled', 'type' => Database::VAR_BOOLEAN, @@ -659,29 +637,7 @@ $collections = [ 'default' => null, 'array' => false, 'filters' => [], - ], - [ - '$id' => 'dateCreated', - 'type' => Database::VAR_INTEGER, - 'format' => '', - 'size' => 0, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ], - [ - '$id' => 'dateUpdated', - 'type' => Database::VAR_INTEGER, - 'format' => '', - 'size' => 0, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ], + ] ], 'indexes' => [ [ @@ -1508,17 +1464,6 @@ $collections = [ 'array' => false, 'filters' => [], ], - [ - '$id' => 'dateCreated', - 'type' => Database::VAR_INTEGER, - 'format' => '', - 'size' => 0, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ], [ '$id' => 'total', 'type' => Database::VAR_INTEGER, @@ -1706,28 +1651,6 @@ $collections = [ 'array' => false, 'filters' => [], ], - [ - '$id' => 'dateCreated', - 'type' => Database::VAR_INTEGER, - 'format' => '', - 'size' => 0, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ], - [ - '$id' => 'dateUpdated', - 'type' => Database::VAR_INTEGER, - 'format' => '', - 'size' => 0, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ], [ 'array' => false, '$id' => 'status', @@ -1856,17 +1779,6 @@ $collections = [ '$id' => 'deployments', 'name' => 'Deployments', 'attributes' => [ - [ - '$id' => 'dateCreated', - 'type' => Database::VAR_INTEGER, - 'format' => '', - 'size' => 0, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ], [ '$id' => 'resourceId', 'type' => Database::VAR_STRING, @@ -2158,17 +2070,6 @@ $collections = [ '$id' => 'executions', 'name' => 'Executions', 'attributes' => [ - [ - '$id' => 'dateCreated', - 'type' => Database::VAR_INTEGER, - 'format' => '', - 'size' => 0, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ], [ '$id' => 'functionId', 'type' => Database::VAR_STRING, @@ -2379,26 +2280,6 @@ $collections = [ '$id' => 'buckets', 'name' => 'Buckets', 'attributes' => [ - [ - '$id' => 'dateCreated', - 'type' => Database::VAR_INTEGER, - 'format' => '', - 'signed' => false, - 'size' => 0, - 'required' => false, - 'array' => false, - 'filters' => [], - ], - [ - '$id' => 'dateUpdated', - 'type' => Database::VAR_INTEGER, - 'size' => 0, - 'format' => '', - 'signed' => false, - 'required' => false, - 'array' => false, - 'filters' => [], - ], [ '$id' => 'enabled', 'type' => Database::VAR_BOOLEAN, @@ -2639,17 +2520,6 @@ $collections = [ '$id' => 'files', '$name' => 'Files', 'attributes' => [ - [ - '$id' => 'dateCreated', - 'type' => Database::VAR_INTEGER, - 'format' => '', - 'size' => 0, - 'signed' => false, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ], [ 'array' => false, '$id' => 'bucketId', diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index c039c2134..cc6294df2 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1530,8 +1530,7 @@ App::patch('/v1/account/sessions/:sessionId') $session ->setAttribute('providerAccessToken', $oauth2->getAccessToken('')) ->setAttribute('providerRefreshToken', $oauth2->getRefreshToken('')) - ->setAttribute('providerAccessTokenExpiry', \time() + (int) $oauth2->getAccessTokenExpiry('')) - ; + ->setAttribute('providerAccessTokenExpiry', \time() + (int) $oauth2->getAccessTokenExpiry('')); $dbForProject->updateDocument('sessions', $sessionId, $session); diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 358da9a52..5334ad186 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -166,8 +166,6 @@ App::post('/v1/database/collections') '$read' => $read ?? [], // Collection permissions for collection documents (based on permission model) '$write' => $write ?? [], // Collection permissions for collection documents (based on permission model) 'permission' => $permission, // Permissions model type (document vs collection) - 'dateCreated' => time(), - 'dateUpdated' => time(), 'enabled' => true, 'name' => $name, 'search' => implode(' ', [$collectionId, $name]), @@ -597,7 +595,6 @@ App::put('/v1/database/collections/:collectionId') ->setAttribute('$read', $read) ->setAttribute('name', $name) ->setAttribute('permission', $permission) - ->setAttribute('dateUpdated', time()) ->setAttribute('enabled', $enabled) ->setAttribute('search', implode(' ', [$collectionId, $name]))); } catch (AuthorizationException $exception) { diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 6b07c9704..7dfbe7142 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -66,8 +66,6 @@ App::post('/v1/functions') $function = $dbForProject->createDocument('functions', new Document([ '$id' => $functionId, 'execute' => $execute, - 'dateCreated' => time(), - 'dateUpdated' => time(), 'status' => 'disabled', 'name' => $name, 'runtime' => $runtime, @@ -315,7 +313,6 @@ App::put('/v1/functions/:functionId') $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ 'execute' => $execute, - 'dateUpdated' => time(), 'name' => $name, 'vars' => $vars, 'events' => $events, @@ -575,7 +572,6 @@ App::post('/v1/functions/:functionId/deployments') '$write' => ['role:all'], 'resourceId' => $function->getId(), 'resourceType' => 'functions', - 'dateCreated' => time(), 'entrypoint' => $entrypoint, 'path' => $path, 'size' => $fileSize, @@ -605,7 +601,6 @@ App::post('/v1/functions/:functionId/deployments') '$write' => ['role:all'], 'resourceId' => $function->getId(), 'resourceType' => 'functions', - 'dateCreated' => time(), 'entrypoint' => $entrypoint, 'path' => $path, 'size' => $fileSize, @@ -854,11 +849,11 @@ App::post('/v1/functions/:functionId/executions') $executionId = $dbForProject->getId(); + /** @var Document $execution */ $execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', new Document([ '$id' => $executionId, '$read' => (!$user->isEmpty()) ? ['user:' . $user->getId()] : [], '$write' => [], - 'dateCreated' => time(), 'functionId' => $function->getId(), 'deploymentId' => $deployment->getId(), 'trigger' => 'http', // http / schedule / event @@ -952,7 +947,7 @@ App::post('/v1/functions/:functionId/executions') $execution->setAttribute('time', $executionResponse['time']); } catch (\Throwable $th) { $endtime = \microtime(true); - $time = $endtime - $execution->getAttribute('dateCreated'); + $time = $endtime - $execution->getCreatedAt(); $execution->setAttribute('time', $time); $execution->setAttribute('status', 'failed'); $execution->setAttribute('statusCode', $th->getCode()); diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 2a7e7ad65..9613f821c 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -998,9 +998,7 @@ App::post('/v1/projects/:projectId/platforms') 'name' => $name, 'key' => $key, 'store' => $store, - 'hostname' => $hostname, - 'dateCreated' => \time(), - 'dateUpdated' => \time(), + 'hostname' => $hostname ]); $platform = $dbForConsole->createDocument('platforms', $platform); @@ -1112,7 +1110,6 @@ App::put('/v1/projects/:projectId/platforms/:platformId') $platform ->setAttribute('name', $name) - ->setAttribute('dateUpdated', \time()) ->setAttribute('key', $key) ->setAttribute('store', $store) ->setAttribute('hostname', $hostname) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 2f55d9720..e09cd7963 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -107,8 +107,6 @@ App::post('/v1/storage/buckets') $bucket = $dbForProject->createDocument('buckets', new Document([ '$id' => $bucketId, '$collection' => 'buckets', - 'dateCreated' => \time(), - 'dateUpdated' => \time(), 'name' => $name, 'permission' => $permission, 'maximumFileSize' => $maximumFileSize, @@ -546,7 +544,6 @@ App::post('/v1/storage/buckets/:bucketId/files') '$id' => $fileId, '$read' => $read, '$write' => $write, - 'dateCreated' => \time(), 'bucketId' => $bucket->getId(), 'name' => $fileName, 'path' => $path, @@ -613,7 +610,6 @@ App::post('/v1/storage/buckets/:bucketId/files') '$id' => $fileId, '$read' => $read, '$write' => $write, - 'dateCreated' => \time(), 'bucketId' => $bucket->getId(), 'name' => $fileName, 'path' => $path, diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index a983745a9..a32dc87bc 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -63,7 +63,6 @@ App::post('/v1/teams') '$write' => ['team:' . $teamId . '/owner'], 'name' => $name, 'total' => ($isPrivilegedUser || $isAppUser) ? 0 : 1, - 'dateCreated' => \time(), 'search' => implode(' ', [$teamId, $name]), ]))); diff --git a/app/controllers/general.php b/app/controllers/general.php index a67d9cfd7..bd05fea04 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -298,11 +298,10 @@ App::init(function (App $utopia, Request $request, Response $response, Document $service = $route->getLabel('sdk.namespace', ''); if (!empty($service)) { - $roles = Authorization::getRoles(); if ( array_key_exists($service, $project->getAttribute('services', [])) && !$project->getAttribute('services', [])[$service] - && !(Auth::isPrivilegedUser($roles) || Auth::isAppUser($roles)) + && !(Auth::isPrivilegedUser(Authorization::getRoles()) || Auth::isAppUser(Authorization::getRoles())) ) { throw new AppwriteException('Service is disabled', 503, AppwriteException::GENERAL_SERVICE_DISABLED); } diff --git a/app/http.php b/app/http.php index a7d10b9e0..d900947dc 100644 --- a/app/http.php +++ b/app/http.php @@ -155,8 +155,6 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { $dbForConsole->createDocument('buckets', new Document([ '$id' => 'default', '$collection' => 'buckets', - 'dateCreated' => \time(), - 'dateUpdated' => \time(), 'name' => 'Default', 'permission' => 'file', 'maximumFileSize' => (int) App::getEnv('_APP_STORAGE_LIMIT', 0), // 10MB diff --git a/app/init.php b/app/init.php index 4a456a4d1..308ec5438 100644 --- a/app/init.php +++ b/app/init.php @@ -461,6 +461,11 @@ $register->set('dbPool', function () { ->withPassword($dbPass) ->withOptions([ PDO::ATTR_ERRMODE => App::isDevelopment() ? PDO::ERRMODE_WARNING : PDO::ERRMODE_SILENT, // If in production mode, warnings are not displayed + PDO::ATTR_TIMEOUT => 3, // Seconds + PDO::ATTR_PERSISTENT => true, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => true, + PDO::ATTR_STRINGIFY_FETCHES => true, ]), 64 ); @@ -553,11 +558,12 @@ $register->set('db', function () { $dbScheme = App::getEnv('_APP_DB_SCHEMA', ''); $pdo = new PDO("mysql:host={$dbHost};port={$dbPort};dbname={$dbScheme};charset=utf8mb4", $dbUser, $dbPass, array( - PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4', PDO::ATTR_TIMEOUT => 3, // Seconds PDO::ATTR_PERSISTENT => true, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_EMULATE_PREPARES => true, + PDO::ATTR_STRINGIFY_FETCHES => true, )); return $pdo; diff --git a/app/views/console/database/collection.phtml b/app/views/console/database/collection.phtml index 48662ead1..fa782adb8 100644 --- a/app/views/console/database/collection.phtml +++ b/app/views/console/database/collection.phtml @@ -568,8 +568,8 @@ $logs = $this->getParam('logs', null);
- +