From 4cf226f733b370dff84bce792fad5f640e5b8f20 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 10 Dec 2024 11:34:51 +0000 Subject: [PATCH] update project accessed at from router --- app/controllers/general.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/controllers/general.php b/app/controllers/general.php index 0bbfa2b694..af8f34ad40 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -25,6 +25,7 @@ use Utopia\App; use Utopia\CLI\Console; use Utopia\Config\Config; use Utopia\Database\Database; +use Utopia\Database\DateTime; use Utopia\Database\Document; use Utopia\Database\Helpers\ID; use Utopia\Database\Query; @@ -81,6 +82,15 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo $project = Authorization::skip( fn () => $dbForConsole->getDocument('projects', $projectId) ); + + if (!$project->isEmpty() && $project->getId() !== 'console') { + $accessedAt = $project->getAttribute('accessedAt', ''); + if (DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -APP_PROJECT_ACCESS)) > $accessedAt) { + $project->setAttribute('accessedAt', DateTime::now()); + Authorization::skip(fn () => $dbForConsole->updateDocument('projects', $project->getId(), $project)); + } + } + if (array_key_exists('proxy', $project->getAttribute('services', []))) { $status = $project->getAttribute('services', [])['proxy']; if (!$status) {