diff --git a/app/config/collections.php b/app/config/collections.php index 7c947cb08..0c0cef253 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -2183,7 +2183,7 @@ $collections = [ 'name' => 'Builds', 'attributes' => [ [ - '$id' => 'startTime', // todo: change to datetime in motion + '$id' => 'startTime', 'type' => Database::VAR_DATETIME, 'format' => '', 'size' => 0, @@ -2194,7 +2194,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'endTime', // todo: change to datetime in motion + '$id' => 'endTime', 'type' => Database::VAR_DATETIME, 'format' => '', 'size' => 0, @@ -2658,7 +2658,7 @@ $collections = [ ], [ '$id' => 'time', - 'type' => Database::VAR_DATETIME,// todo: change to datetime in motion + 'type' => Database::VAR_DATETIME, 'format' => '', 'size' => 0, 'signed' => false, @@ -2732,11 +2732,11 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'timestamp', // todo: change to datetime??? - 'type' => Database::VAR_INTEGER, + '$id' => 'timestamp', + 'type' => Database::VAR_DATETIME, 'format' => '', 'size' => 0, - 'signed' => true, + 'signed' => false, 'required' => false, 'default' => null, 'array' => false, diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index ab2de460e..15cfc06b8 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -26,6 +26,7 @@ use Utopia\Audit\Audit as EventAudit; use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\DateTime; use Utopia\Database\Exception\Duplicate; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; @@ -102,8 +103,8 @@ App::post('/v1/account') 'emailVerification' => false, 'status' => true, 'password' => Auth::passwordHash($password), - 'passwordUpdate' => Database::getCurrentDateTime(), - 'registration' => Database::getCurrentDateTime(), + 'passwordUpdate' => DateTime::getCurrentDateTime(), + 'registration' => DateTime::getCurrentDateTime(), 'reset' => false, 'name' => $name, 'prefs' => new \stdClass(), @@ -175,7 +176,7 @@ App::post('/v1/account/sessions/email') $detector = new Detector($request->getUserAgent('UNKNOWN')); $record = $geodb->get($request->getIP()); - $expire = Database::dateAddSeconds(new DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG); + $expire = DateTime::dateAddSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG); $secret = Auth::tokenGenerator(); $session = new Document(array_merge( [ @@ -215,8 +216,8 @@ App::post('/v1/account/sessions/email') } $response - ->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($profile->getId(), $secret), (new DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null) - ->addCookie(Auth::$cookieName, Auth::encodeSession($profile->getId(), $secret), (new DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite')) + ->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($profile->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null) + ->addCookie(Auth::$cookieName, Auth::encodeSession($profile->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite')) ->setStatusCode(Response::STATUS_CODE_CREATED) ; @@ -484,7 +485,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') 'status' => true, // Email should already be authenticated by OAuth2 provider 'password' => Auth::passwordHash(Auth::passwordGenerator()), 'passwordUpdate' => null, - 'registration' => Database::getCurrentDateTime(), + 'registration' => DateTime::getCurrentDateTime(), 'reset' => false, 'name' => $name, 'prefs' => new \stdClass(), @@ -507,7 +508,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $detector = new Detector($request->getUserAgent('UNKNOWN')); $record = $geodb->get($request->getIP()); $secret = Auth::tokenGenerator(); - $expire = Database::dateAddSeconds(new DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG); + $expire = DateTime::dateAddSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG); $session = new Document(array_merge([ '$id' => $dbForProject->getId(), @@ -517,7 +518,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') 'providerUid' => $oauth2ID, 'providerAccessToken' => $accessToken, 'providerRefreshToken' => $refreshToken, - 'providerAccessTokenExpiry' => Database::dateAddSeconds(new DateTime(), (int)$accessTokenExpiry), + 'providerAccessTokenExpiry' => DateTime::dateAddSeconds(new \DateTime(), (int)$accessTokenExpiry), 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak 'expire' => $expire, 'userAgent' => $request->getUserAgent('UNKNOWN'), @@ -584,8 +585,8 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $response ->addHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0') ->addHeader('Pragma', 'no-cache') - ->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), (new DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null) - ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), (new DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite')) + ->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null) + ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite')) ->redirect($state['success']) ; }); @@ -650,7 +651,7 @@ App::post('/v1/account/sessions/magic-url') 'status' => true, 'password' => null, 'passwordUpdate' => null, - 'registration' => Database::getCurrentDateTime(), + 'registration' => DateTime::getCurrentDateTime(), 'reset' => false, 'prefs' => new \stdClass(), 'sessions' => null, @@ -661,7 +662,7 @@ App::post('/v1/account/sessions/magic-url') } $loginSecret = Auth::tokenGenerator(); - $expire = Database::dateAddSeconds(new DateTime(), Auth::TOKEN_EXPIRATION_CONFIRM); + $expire = DateTime::dateAddSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_CONFIRM); $token = new Document([ '$id' => $dbForProject->getId(), @@ -761,7 +762,7 @@ App::put('/v1/account/sessions/magic-url') $detector = new Detector($request->getUserAgent('UNKNOWN')); $record = $geodb->get($request->getIP()); $secret = Auth::tokenGenerator(); - $expire = Database::dateAddSeconds(new DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG); + $expire = DateTime::dateAddSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG); $session = new Document(array_merge( [ @@ -819,8 +820,8 @@ App::put('/v1/account/sessions/magic-url') $protocol = $request->getProtocol(); $response - ->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), (new DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null) - ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), (new DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite')) + ->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null) + ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite')) ->setStatusCode(Response::STATUS_CODE_CREATED) ; @@ -893,7 +894,7 @@ App::post('/v1/account/sessions/phone') 'status' => true, 'password' => null, 'passwordUpdate' => null, - 'registration' => Database::getCurrentDateTime(), + 'registration' => DateTime::getCurrentDateTime(), 'reset' => false, 'prefs' => new \stdClass(), 'sessions' => null, @@ -904,7 +905,7 @@ App::post('/v1/account/sessions/phone') } $secret = $phone->generateSecretDigits(); - $expire = Database::dateAddSeconds(new DateTime(), Auth::TOKEN_EXPIRATION_PHONE); + $expire = DateTime::dateAddSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_PHONE); $token = new Document([ '$id' => $dbForProject->getId(), @@ -991,7 +992,7 @@ App::put('/v1/account/sessions/phone') $detector = new Detector($request->getUserAgent('UNKNOWN')); $record = $geodb->get($request->getIP()); $secret = Auth::tokenGenerator(); - $expire = Database::dateAddSeconds(new DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG); + $expire = DateTime::dateAddSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG); $session = new Document(array_merge( [ @@ -1047,8 +1048,8 @@ App::put('/v1/account/sessions/phone') $protocol = $request->getProtocol(); $response - ->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), (new DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null) - ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), (new DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite')) + ->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null) + ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite')) ->setStatusCode(Response::STATUS_CODE_CREATED) ; @@ -1119,7 +1120,7 @@ App::post('/v1/account/sessions/anonymous') 'status' => true, 'password' => null, 'passwordUpdate' => null, - 'registration' => Database::getCurrentDateTime(), + 'registration' => DateTime::getCurrentDateTime(), 'reset' => false, 'name' => null, 'prefs' => new \stdClass(), @@ -1134,7 +1135,7 @@ App::post('/v1/account/sessions/anonymous') $detector = new Detector($request->getUserAgent('UNKNOWN')); $record = $geodb->get($request->getIP()); $secret = Auth::tokenGenerator(); - $expire = Database::dateAddSeconds(new DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG); + $expire = DateTime::dateAddSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG); $session = new Document(array_merge( [ @@ -1178,8 +1179,8 @@ App::post('/v1/account/sessions/anonymous') } $response - ->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), (new DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null) - ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), (new DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite')) + ->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null) + ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite')) ->setStatusCode(Response::STATUS_CODE_CREATED) ; @@ -1489,7 +1490,7 @@ App::patch('/v1/account/password') $user->getId(), $user ->setAttribute('password', Auth::passwordHash($password)) - ->setAttribute('passwordUpdate', Database::getCurrentDateTime()) + ->setAttribute('passwordUpdate', DateTime::getCurrentDateTime()) ); $audits @@ -1820,7 +1821,7 @@ App::patch('/v1/account/sessions/:sessionId') $session ->setAttribute('providerAccessToken', $oauth2->getAccessToken('')) ->setAttribute('providerRefreshToken', $oauth2->getRefreshToken('')) - ->setAttribute('providerAccessTokenExpiry', Database::dateAddSeconds(new DateTime(), (int)$oauth2->getAccessTokenExpiry(''))); + ->setAttribute('providerAccessTokenExpiry', DateTime::dateAddSeconds(new \DateTime(), (int)$oauth2->getAccessTokenExpiry(''))); $dbForProject->updateDocument('sessions', $sessionId, $session); @@ -1963,7 +1964,7 @@ App::post('/v1/account/recovery') throw new Exception('Invalid credentials. User is blocked', 401, Exception::USER_BLOCKED); } - $expire = Database::dateAddSeconds(new DateTime(), Auth::TOKEN_EXPIRATION_RECOVERY); + $expire = DateTime::dateAddSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_RECOVERY); $secret = Auth::tokenGenerator(); $recovery = new Document([ @@ -2064,7 +2065,7 @@ App::put('/v1/account/recovery') $profile = $dbForProject->updateDocument('users', $profile->getId(), $profile ->setAttribute('password', Auth::passwordHash($password)) - ->setAttribute('passwordUpdate', Database::getCurrentDateTime()) + ->setAttribute('passwordUpdate', DateTime::getCurrentDateTime()) ->setAttribute('emailVerification', true)); $recoveryDocument = $dbForProject->getDocument('tokens', $recovery); @@ -2123,7 +2124,7 @@ App::post('/v1/account/verification') $isPrivilegedUser = Auth::isPrivilegedUser($roles); $isAppUser = Auth::isAppUser($roles); $verificationSecret = Auth::tokenGenerator(); - $expire = Database::dateAddSeconds(new DateTime(), Auth::TOKEN_EXPIRATION_CONFIRM); + $expire = DateTime::dateAddSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_CONFIRM); $verification = new Document([ '$id' => $dbForProject->getId(), @@ -2276,7 +2277,7 @@ App::post('/v1/account/verification/phone') $isAppUser = Auth::isAppUser($roles); $verificationSecret = Auth::tokenGenerator(); $secret = $phone->generateSecretDigits(); - $expire = Database::dateAddSeconds(new DateTime(), Auth::TOKEN_EXPIRATION_CONFIRM); + $expire = DateTime::dateAddSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_CONFIRM); $verification = new Document([ '$id' => $dbForProject->getId(), diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 7c1b77e4b..26958d9e3 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -14,6 +14,7 @@ use Utopia\Validator\ArrayList; use Utopia\Validator\JSON; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\DateTime; use Utopia\Database\Query; use Utopia\Database\Adapter\MariaDB; use Utopia\Database\Validator\Authorization; @@ -2529,7 +2530,7 @@ App::get('/v1/databases/usage') }; $stats[$metric][] = [ 'value' => 0, - 'date' => Database::dateAddSeconds(new DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff), + 'date' => DateTime::dateAddSeconds(new \DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff), ]; $backfill--; } @@ -2641,7 +2642,7 @@ App::get('/v1/databases/:databaseId/usage') }; $stats[$metric][] = [ 'value' => 0, - 'date' => Database::dateAddSeconds(new DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff), + 'date' => DateTime::dateAddSeconds(new \DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff), ]; $backfill--; } @@ -2754,7 +2755,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/usage') }; $stats[$metric][] = [ 'value' => 0, - 'date' => Database::dateAddSeconds(new DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff), + 'date' => DateTime::dateAddSeconds(new \DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff), ]; $backfill--; } diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 0077f311e..7b3f5f8a7 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -22,6 +22,7 @@ use Appwrite\Task\Validator\Cron; use Utopia\App; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\DateTime; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Validator\ArrayList; @@ -256,7 +257,7 @@ App::get('/v1/functions/:functionId/usage') }; $stats[$metric][] = [ 'value' => 0, - 'date' => Database::dateAddSeconds(new DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff), + 'date' => DateTime::dateAddSeconds(new \DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff), ]; $backfill--; } @@ -309,7 +310,7 @@ App::put('/v1/functions/:functionId') $original = $function->getAttribute('schedule', ''); $cron = (!empty($function->getAttribute('deployment')) && !empty($schedule)) ? new CronExpression($schedule) : null; - $next = (!empty($function->getAttribute('deployment')) && !empty($schedule)) ? Database::dateFormat($cron->getNextRunDate()) : null; + $next = (!empty($function->getAttribute('deployment')) && !empty($schedule)) ? DateTime::dateFormat($cron->getNextRunDate()) : null; $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ 'execute' => $execute, @@ -330,7 +331,7 @@ App::put('/v1/functions/:functionId') ->setType('schedule') ->setUser($user) ->setProject($project) - ->schedule(new DateTime($next)); + ->schedule(new \DateTime($next)); } $eventsInstance->setParam('functionId', $function->getId()); @@ -380,7 +381,7 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId') $schedule = $function->getAttribute('schedule', ''); $cron = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? new CronExpression($schedule) : null; - $next = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? Database::dateFormat($cron->getNextRunDate()) : null; + $next = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? DateTime::dateFormat($cron->getNextRunDate()) : null; $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ 'deployment' => $deployment->getId(), @@ -393,7 +394,7 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId') ->setType('schedule') ->setFunction($function) ->setProject($project) - ->schedule(new DateTime($next)); + ->schedule(new \DateTime($next)); } $events @@ -944,7 +945,7 @@ App::post('/v1/functions/:functionId/executions') $execution->setAttribute('stderr', $executionResponse['stderr']); $execution->setAttribute('time', $executionResponse['time']); } catch (\Throwable $th) { - $interval = (new DateTime())->diff(new DateTime($execution->getCreatedAt())); + $interval = (new \DateTime())->diff(new \DateTime($execution->getCreatedAt())); $execution ->setAttribute('time', (float)$interval->format('%s.%f')) ->setAttribute('status', 'failed') diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 8200cca2a..7ab8d1af7 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -17,6 +17,7 @@ use Utopia\Audit\Audit; use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\DateTime; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\DatetimeValidation; @@ -314,7 +315,7 @@ App::get('/v1/projects/:projectId/usage') }; $stats[$metric][] = [ 'value' => 0, - 'date' => Database::dateAddSeconds(new DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff), + 'date' => DateTime::dateAddSeconds(new \DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff), ]; $backfill--; } @@ -820,7 +821,7 @@ App::post('/v1/projects/:projectId/keys') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('name', null, new Text(128), 'Key name. Max length: 128 chars.') ->param('scopes', null, new ArrayList(new WhiteList(array_keys(Config::getParam('scopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.') - ->param('expire', null, new DatetimeValidation(), 'Expiration time in DateTime. Use null for unlimited expiration.', true) + ->param('expire', null, new DateTimeValidation(), 'Expiration time in DateTime. Use null for unlimited expiration.', true) ->inject('response') ->inject('dbForConsole') ->action(function (string $projectId, string $name, array $scopes, string|null $expire, Response $response, Database $dbForConsole) { @@ -1245,7 +1246,7 @@ App::post('/v1/projects/:projectId/domains') '$write' => ['role:all'], 'projectInternalId' => $project->getInternalId(), 'projectId' => $project->getId(), - 'updated' => Database::getCurrentDateTime(), + 'updated' => DateTime::getCurrentDateTime(), 'domain' => $domain->get(), 'tld' => $domain->getSuffix(), 'registerable' => $domain->getRegisterable(), diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 41f04992a..db3428db0 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -15,6 +15,7 @@ use Utopia\Cache\Cache; use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\DateTime; use Utopia\Database\Exception\Duplicate; use Utopia\Database\Exception\Duplicate as DuplicateException; use Utopia\Database\Exception\Structure as StructureException; @@ -1547,7 +1548,7 @@ App::get('/v1/storage/usage') }; $stats[$metric][] = [ 'value' => 0, - 'date' => Database::dateAddSeconds(new DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff), + 'date' => DateTime::dateAddSeconds(new \DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff), ]; $backfill--; } @@ -1656,7 +1657,7 @@ App::get('/v1/storage/:bucketId/usage') }; $stats[$metric][] = [ 'value' => 0, - 'date' => Database::dateAddSeconds(new DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff), + 'date' => DateTime::dateAddSeconds(new \DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff), ]; $backfill--; } diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 4ad0e0dc3..08078d7c0 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -22,6 +22,7 @@ use Utopia\Database\Document; use Utopia\Database\Exception\Authorization as AuthorizationException; use Utopia\Database\Exception\Duplicate; use Utopia\Database\Query; +use Utopia\Database\DateTime; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; @@ -77,8 +78,8 @@ App::post('/v1/teams') 'teamId' => $team->getId(), 'teamInternalId' => $team->getInternalId(), 'roles' => $roles, - 'invited' => Database::getCurrentDateTime(), - 'joined' => Database::getCurrentDateTime(), + 'invited' => DateTime::getCurrentDateTime(), + 'joined' => DateTime::getCurrentDateTime(), 'confirm' => true, 'secret' => '', 'search' => implode(' ', [$membershipId, $user->getId()]) @@ -340,7 +341,7 @@ App::post('/v1/teams/:teamId/memberships') * old password */ 'passwordUpdate' => null, - 'registration' => Database::getCurrentDateTime(), + 'registration' => DateTime::getCurrentDateTime(), 'reset' => false, 'name' => $name, 'prefs' => new \stdClass(), @@ -372,8 +373,8 @@ App::post('/v1/teams/:teamId/memberships') 'teamId' => $team->getId(), 'teamInternalId' => $team->getInternalId(), 'roles' => $roles, - 'invited' => Database::getCurrentDateTime(), - 'joined' => ($isPrivilegedUser || $isAppUser) ? Database::getCurrentDateTime() : null, + 'invited' => DateTime::getCurrentDateTime(), + 'joined' => ($isPrivilegedUser || $isAppUser) ? DateTime::getCurrentDateTime() : null, 'confirm' => ($isPrivilegedUser || $isAppUser), 'secret' => Auth::hash($secret), 'search' => implode(' ', [$membershipId, $invitee->getId()]) @@ -686,7 +687,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') } $membership // Attach user to team - ->setAttribute('joined', Database::getCurrentDateTime()) + ->setAttribute('joined', DateTime::getCurrentDateTime()) ->setAttribute('confirm', true) ; @@ -700,7 +701,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') $detector = new Detector($request->getUserAgent('UNKNOWN')); $record = $geodb->get($request->getIP()); - $expire = Database::dateAddSeconds(new DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG); + $expire = DateTime::dateAddSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG); $secret = Auth::tokenGenerator(); $session = new Document(array_merge([ '$id' => $dbForProject->getId(), @@ -743,8 +744,8 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') } $response - ->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), (new DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null) - ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), (new DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite')) + ->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null) + ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite')) ; $response->dynamic( diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 9ada18396..f6bf39cf3 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -17,6 +17,7 @@ use Utopia\Config\Config; use Utopia\Locale\Locale; use Appwrite\Extend\Exception; use Utopia\Database\Document; +use Utopia\Database\DateTime; use Utopia\Database\Exception\Duplicate; use Utopia\Database\Validator\UID; use Utopia\Database\Database; @@ -63,8 +64,8 @@ App::post('/v1/users') 'emailVerification' => false, 'status' => true, 'password' => Auth::passwordHash($password), - 'passwordUpdate' => Database::getCurrentDateTime(), - 'registration' => Database::getCurrentDateTime(), + 'passwordUpdate' => DateTime::getCurrentDateTime(), + 'registration' => DateTime::getCurrentDateTime(), 'reset' => false, 'name' => $name, 'prefs' => new \stdClass(), @@ -550,7 +551,7 @@ App::patch('/v1/users/:userId/password') $user ->setAttribute('password', Auth::passwordHash($password)) - ->setAttribute('passwordUpdate', Database::getCurrentDateTime()); + ->setAttribute('passwordUpdate', DateTime::getCurrentDateTime()); $user = $dbForProject->updateDocument('users', $user->getId(), $user); @@ -925,7 +926,7 @@ App::get('/v1/users/usage') }; $stats[$metric][] = [ 'value' => 0, - 'date' => Database::dateAddSeconds(new DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff), + 'date' => DateTime::dateAddSeconds(new \DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff), ]; $backfill--; } diff --git a/app/controllers/general.php b/app/controllers/general.php index f8c0517a1..5232a854d 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -23,6 +23,7 @@ use Appwrite\Utopia\Response\Filters\V14 as ResponseV14; use Utopia\CLI\Console; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\DateTime; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Validator\Hostname; @@ -285,7 +286,7 @@ App::init(function (App $utopia, Request $request, Response $response, Document $expire = $key->getAttribute('expire'); - if (!empty($expire) && $expire < Database::getCurrentDateTime()) { + if (!empty($expire) && $expire < DateTime::getCurrentDateTime()) { throw new AppwriteException('Project key expired', 401, AppwriteException:: PROJECT_KEY_EXPIRED); } diff --git a/app/executor.php b/app/executor.php index 891995871..e2e06a0a6 100644 --- a/app/executor.php +++ b/app/executor.php @@ -12,7 +12,7 @@ use Swoole\Runtime; use Swoole\Timer; use Utopia\App; use Utopia\CLI\Console; -use Utopia\Database\Database; +use Utopia\Database\DateTime; use Utopia\Logger\Log; use Utopia\Logger\Logger; use Utopia\Orchestration\Adapter\DockerCLI; @@ -189,8 +189,8 @@ App::post('/v1/runtimes') $containerId = ''; $stdout = ''; $stderr = ''; - $startTime = Database::getCurrentDateTime(); - $startTimeUnix = (new DateTime($startTime))->getTimestamp(); + $startTime = DateTime::getCurrentDateTime(); + $startTimeUnix = (new \DateTime($startTime))->getTimestamp(); $endTimeUnix = 0; $orchestration = $orchestrationPool->get(); @@ -321,8 +321,8 @@ App::post('/v1/runtimes') $stdout = 'Build Successful!'; } - $endTime = Database::getCurrentDateTime(); - $endTimeUnix = (new DateTime($endTime))->getTimestamp(); + $endTime = DateTime::getCurrentDateTime(); + $endTimeUnix = (new \DateTime($endTime))->getTimestamp(); $duration = $endTimeUnix - $startTimeUnix; $container = array_merge($container, [ diff --git a/app/tasks/maintenance.php b/app/tasks/maintenance.php index ecd7197a6..96586e203 100644 --- a/app/tasks/maintenance.php +++ b/app/tasks/maintenance.php @@ -11,6 +11,7 @@ use Utopia\Cache\Cache; use Utopia\CLI\Console; use Utopia\Database\Adapter\MariaDB; use Utopia\Database\Database; +use Utopia\Database\DateTime; use Utopia\Cache\Adapter\Redis as RedisCache; use Utopia\Database\Document; use Utopia\Database\Query; @@ -57,7 +58,7 @@ $cli { (new Delete()) ->setType(DELETE_TYPE_EXECUTIONS) - ->setDatetime(Database::dateAddSeconds(new DateTime(), -1 * $interval)) + ->setDatetime(DateTime::dateAddSeconds(new \DateTime(), -1 * $interval)) ->trigger(); } @@ -65,7 +66,7 @@ $cli { (new Delete()) ->setType(DELETE_TYPE_ABUSE) - ->setDatetime(Database::dateAddSeconds(new DateTime(), -1 * $interval)) + ->setDatetime(DateTime::dateAddSeconds(new \DateTime(), -1 * $interval)) ->trigger(); } @@ -73,7 +74,7 @@ $cli { (new Delete()) ->setType(DELETE_TYPE_AUDIT) - ->setDatetime(Database::dateAddSeconds(new DateTime(), -1 * $interval)) + ->setDatetime(DateTime::dateAddSeconds(new \DateTime(), -1 * $interval)) ->trigger(); } @@ -81,8 +82,8 @@ $cli { (new Delete()) ->setType(DELETE_TYPE_USAGE) - ->setDateTime1d(Database::dateAddSeconds(new DateTime(), -1 * $interval1d)) - ->setDateTime30m(Database::dateAddSeconds(new DateTime(), -1 * $interval30m)) + ->setDateTime1d(DateTime::dateAddSeconds(new \DateTime(), -1 * $interval1d)) + ->setDateTime30m(DateTime::dateAddSeconds(new \DateTime(), -1 * $interval30m)) ->trigger(); } @@ -90,7 +91,7 @@ $cli { (new Delete()) ->setType(DELETE_TYPE_REALTIME) - ->setDatetime(Database::dateAddSeconds(new DateTime(), -60)) + ->setDatetime(DateTime::dateAddSeconds(new \DateTime(), -60)) ->trigger(); } @@ -98,13 +99,13 @@ $cli { (new Delete()) ->setType(DELETE_TYPE_SESSIONS) - ->setDatetime(Database::dateAddSeconds(new DateTime(), -1 * Auth::TOKEN_EXPIRATION_LOGIN_LONG)) + ->setDatetime(DateTime::dateAddSeconds(new \DateTime(), -1 * Auth::TOKEN_EXPIRATION_LOGIN_LONG)) ->trigger(); } function renewCertificates($dbForConsole) { - $time = Database::getCurrentDateTime(); + $time = DateTime::getCurrentDateTime(); $certificates = $dbForConsole->find('certificates', [ new Query('attempts', Query::TYPE_LESSEREQUAL, [5]), // Maximum 5 attempts @@ -139,7 +140,7 @@ $cli Console::loop(function () use ($interval, $executionLogsRetention, $abuseLogsRetention, $auditLogRetention, $usageStatsRetention30m, $usageStatsRetention1d) { $database = getConsoleDB(); - $time = Database::getCurrentDateTime(); + $time = DateTime::getCurrentDateTime(); Console::info("[{$time}] Notifying workers with maintenance tasks every {$interval} seconds"); notifyDeleteExecutionLogs($executionLogsRetention); diff --git a/app/workers/builds.php b/app/workers/builds.php index 19d9f35ea..c0a3e7093 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -7,6 +7,7 @@ use Appwrite\Utopia\Response\Model\Deployment; use Cron\CronExpression; use Executor\Executor; use Utopia\Database\Database; +use Utopia\Database\DateTime; use Utopia\App; use Utopia\CLI\Console; use Utopia\Storage\Storage; @@ -75,7 +76,7 @@ class BuildsV1 extends Worker } $buildId = $deployment->getAttribute('buildId', ''); - $startTime = Database::getCurrentDateTime(); + $startTime = DateTime::getCurrentDateTime(); if (empty($buildId)) { $buildId = $dbForProject->getId(); $build = $dbForProject->createDocument('builds', new Document([ @@ -166,7 +167,7 @@ class BuildsV1 extends Worker /** Update the build document */ - //$response['endTime'] = Database::dateFormat((new DateTime())->setTimestamp($response['endTime'])); //todo: fix to datetime + //$response['endTime'] = DateTime::dateFormat((new \DateTime())->setTimestamp($response['endTime'])); //todo: fix to datetime $build->setAttribute('endTime', $response['endTime']); $build->setAttribute('duration', $response['duration']); @@ -186,12 +187,12 @@ class BuildsV1 extends Worker /** Update function schedule */ $schedule = $function->getAttribute('schedule', ''); $cron = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? new CronExpression($schedule) : null; - $next = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? Database::dateFormat($cron->getNextRunDate()) : null; + $next = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? DateTime::dateFormat($cron->getNextRunDate()) : null; $function->setAttribute('scheduleNext', $next); $function = $dbForProject->updateDocument('functions', $function->getId(), $function); } catch (\Throwable $th) { - $endtime = Database::getCurrentDateTime(); - $interval = (new DateTime($endtime))->diff(new DateTime($startTime)); + $endtime = DateTime::getCurrentDateTime(); + $interval = (new \DateTime($endtime))->diff(new \DateTime($startTime)); $build->setAttribute('endTime', $endtime); $build->setAttribute('duration', $interval->format('%s')); $build->setAttribute('status', 'failed'); diff --git a/app/workers/certificates.php b/app/workers/certificates.php index 06317fbb4..445f5d11f 100644 --- a/app/workers/certificates.php +++ b/app/workers/certificates.php @@ -7,8 +7,8 @@ use Utopia\App; use Utopia\CLI\Console; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\DateTime; use Utopia\Database\Query; -use Utopia\Database\Validator\Authorization; use Utopia\Domains\Domain; require_once __DIR__ . '/../init.php'; @@ -116,7 +116,7 @@ class CertificatesV1 extends Worker // Update certificate info stored in database $certificate->setAttribute('renewDate', $this->getRenewDate($domain->get())); $certificate->setAttribute('attempts', 0); - $certificate->setAttribute('issueDate', Database::getCurrentDateTime()); + $certificate->setAttribute('issueDate', DateTime::getCurrentDateTime()); } catch (Throwable $e) { // Set exception as log in certificate document $certificate->setAttribute('log', $e->getMessage()); @@ -129,7 +129,7 @@ class CertificatesV1 extends Worker $this->notifyError($domain->get(), $e->getMessage(), $attempts); } finally { // All actions result in new updatedAt date - $certificate->setAttribute('updated', Database::getCurrentDateTime()); + $certificate->setAttribute('updated', DateTime::getCurrentDateTime()); // Save all changes we made to certificate document into database $this->saveCertificateDocument($domain->get(), $certificate); @@ -298,7 +298,7 @@ class CertificatesV1 extends Worker $certData = openssl_x509_parse(file_get_contents($certPath)); $validTo = $certData['validTo_time_t'] ?? null; $dt = (new \DateTime())->setTimestamp($validTo); - return Database::dateAddSeconds($dt, -60 * 60 * 24 * 30); // -30 days + return DateTime::dateAddSeconds($dt, -60 * 60 * 24 * 30); // -30 days } /** @@ -398,7 +398,7 @@ class CertificatesV1 extends Worker ], 1000); foreach ($domains as $domainDocument) { - $domainDocument->setAttribute('updated', Database::getCurrentDateTime()); + $domainDocument->setAttribute('updated', DateTime::getCurrentDateTime()); $domainDocument->setAttribute('certificateId', $certificateId); $this->dbForConsole->updateDocument('domains', $domainDocument->getId(), $domainDocument); diff --git a/app/workers/deletes.php b/app/workers/deletes.php index d605e7b44..234e8afb5 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -315,7 +315,7 @@ class DeletesV1 extends Worker $dbForProject = $this->getProjectDB($projectId); $timeLimit = new TimeLimit("", 0, 1, $dbForProject); $abuse = new Abuse($timeLimit); - $timestamp = (new DateTime($datetime))->getTimestamp(); //todo:make abuse get datetime + $timestamp = (new \DateTime($datetime))->getTimestamp(); //todo:make abuse get datetime $status = $abuse->cleanup($timestamp); if (!$status) { throw new Exception('Failed to delete Abuse logs for project ' . $projectId); @@ -336,7 +336,7 @@ class DeletesV1 extends Worker $this->deleteForProjectIds(function (string $projectId) use ($datetime) { $dbForProject = $this->getProjectDB($projectId); $audit = new Audit($dbForProject); - $timestamp = (new DateTime($datetime))->getTimestamp(); //todo:make audit get datetime + $timestamp = (new \DateTime($datetime))->getTimestamp(); //todo:make audit get datetime $status = $audit->cleanup($timestamp); if (!$status) { throw new Exception('Failed to delete Audit logs for project' . $projectId); diff --git a/app/workers/functions.php b/app/workers/functions.php index 39ef134ca..9bcbe97fb 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -12,8 +12,8 @@ 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\Validator\Authorization; require_once __DIR__ . '/../init.php'; @@ -147,11 +147,11 @@ class FunctionsV1 extends Worker } $cron = new CronExpression($function->getAttribute('schedule')); - $next = Database::dateFormat($cron->getNextRunDate()); + $next = DateTime::dateFormat($cron->getNextRunDate()); $function ->setAttribute('scheduleNext', $next) - ->setAttribute('schedulePrevious', Database::getCurrentDateTime()); + ->setAttribute('schedulePrevious', DateTime::getCurrentDateTime()); $function = $database->updateDocument( 'functions', @@ -165,7 +165,7 @@ class FunctionsV1 extends Worker ->setType('schedule') ->setUser($user) ->setProject($project) - ->schedule(new DateTime($next)); + ->schedule(new \DateTime($next)); ; $this->execute( @@ -291,7 +291,7 @@ class FunctionsV1 extends Worker ->setAttribute('stderr', $executionResponse['stderr']) ->setAttribute('time', $executionResponse['time']); } catch (\Throwable $th) { - $interval = (new DateTime())->diff(new DateTime($execution->getCreatedAt())); + $interval = (new \DateTime())->diff(new \DateTime($execution->getCreatedAt())); $execution ->setAttribute('time', (float)$interval->format('%s.%f')) ->setAttribute('status', 'failed') diff --git a/composer.lock b/composer.lock index d310fcf64..58a126304 100644 --- a/composer.lock +++ b/composer.lock @@ -236,16 +236,16 @@ }, { "name": "chillerlan/php-settings-container", - "version": "2.1.3", + "version": "2.1.4", "source": { "type": "git", "url": "https://github.com/chillerlan/php-settings-container.git", - "reference": "125dd573b45ffc7cabecf385986a356ba2c6f602" + "reference": "1beb7df3c14346d4344b0b2e12f6f9a74feabd4a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/chillerlan/php-settings-container/zipball/125dd573b45ffc7cabecf385986a356ba2c6f602", - "reference": "125dd573b45ffc7cabecf385986a356ba2c6f602", + "url": "https://api.github.com/repos/chillerlan/php-settings-container/zipball/1beb7df3c14346d4344b0b2e12f6f9a74feabd4a", + "reference": "1beb7df3c14346d4344b0b2e12f6f9a74feabd4a", "shasum": "" }, "require": { @@ -296,7 +296,7 @@ "type": "ko_fi" } ], - "time": "2022-03-09T13:18:58+00:00" + "time": "2022-07-05T22:32:14+00:00" }, { "name": "colinmollenhour/credis", @@ -2055,12 +2055,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "9f9d143fade3911a5b4d4844ccb803152e6a8399" + "reference": "677c30a6497e4d994946ab79d532e3a2568b8f24" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/9f9d143fade3911a5b4d4844ccb803152e6a8399", - "reference": "9f9d143fade3911a5b4d4844ccb803152e6a8399", + "url": "https://api.github.com/repos/utopia-php/database/zipball/677c30a6497e4d994946ab79d532e3a2568b8f24", + "reference": "677c30a6497e4d994946ab79d532e3a2568b8f24", "shasum": "" }, "require": { @@ -2111,7 +2111,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/feat-attr-datetime" }, - "time": "2022-07-05T07:56:19+00:00" + "time": "2022-07-12T12:34:04+00:00" }, { "name": "utopia-php/domains", diff --git a/src/Appwrite/Auth/Auth.php b/src/Appwrite/Auth/Auth.php index e45a03c6f..379d8dabd 100644 --- a/src/Appwrite/Auth/Auth.php +++ b/src/Appwrite/Auth/Auth.php @@ -3,7 +3,7 @@ namespace Appwrite\Auth; use Utopia\Database\Document; -use Utopia\Database\Database; +use Utopia\Database\DateTime; use Utopia\Database\Validator\Authorization; class Auth @@ -207,7 +207,7 @@ class Auth $token->isSet('expire') && $token->getAttribute('type') == $type && $token->getAttribute('secret') === self::hash($secret) && - $token->getAttribute('expire') >= Database::getCurrentDateTime() + $token->getAttribute('expire') >= DateTime::getCurrentDateTime() ) { return (string)$token->getId(); } @@ -226,7 +226,7 @@ class Auth $token->isSet('expire') && $token->getAttribute('type') == Auth::TOKEN_TYPE_PHONE && $token->getAttribute('secret') === $secret && - $token->getAttribute('expire') >= Database::getCurrentDateTime() + $token->getAttribute('expire') >= DateTime::getCurrentDateTime() ) { return (string) $token->getId(); } @@ -252,7 +252,7 @@ class Auth $session->isSet('expire') && $session->isSet('provider') && $session->getAttribute('secret') === self::hash($secret) && - $session->getAttribute('expire') >= Database::getCurrentDateTime() + $session->getAttribute('expire') >= DateTime::getCurrentDateTime() ) { return $session->getId(); } diff --git a/src/Appwrite/Stats/Usage.php b/src/Appwrite/Stats/Usage.php index 2e0b283f1..f08b48da2 100644 --- a/src/Appwrite/Stats/Usage.php +++ b/src/Appwrite/Stats/Usage.php @@ -247,7 +247,7 @@ class Usage ); } - $time = (new DateTime($time))->getTimestamp(); //todo: What about this timestamp? + $time = (new \DateTime($time))->getTimestamp(); //todo: What about this timestamp? $this->latestTime[$metric][$period] = $time; } catch (\Exception $e) { // if projects are deleted this might fail diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index 8130b7f62..b60cb0a6f 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -539,7 +539,7 @@ class AccountCustomClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals('123456', $response['body']['providerAccessToken']); $this->assertEquals('tuvwxyz', $response['body']['providerRefreshToken']); - $this->assertGreaterThan(Database::dateAddSeconds(new \DateTime(), 14400 - 5), $response['body']['providerAccessTokenExpiry']); // 5 seconds allowed networking delay + $this->assertGreaterThan(DateTime::dateAddSeconds(new \DateTime(), 14400 - 5), $response['body']['providerAccessTokenExpiry']); // 5 seconds allowed networking delay $initialExpiry = $response['body']['providerAccessTokenExpiry']; diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index bece78fb6..3d9f5e129 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -9,6 +9,7 @@ use Tests\E2E\Scopes\SideClient; use Tests\E2E\Services\Projects\ProjectsBase; use Tests\E2E\Client; use Utopia\Database\Database; +use Utopia\Database\DateTime; class ProjectsConsoleClientTest extends Scope { @@ -1280,7 +1281,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'name' => 'Key Test', 'scopes' => ['health.read'], - 'expire' => Database::dateAddSeconds(new \DateTime(), 3600), + 'expire' => DateTime::dateAddSeconds(new \DateTime(), 3600), ]); $response = $this->client->call(Client::METHOD_GET, '/health', [ @@ -1320,7 +1321,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'name' => 'Key Test', 'scopes' => ['health.read'], - 'expire' => Database::dateAddSeconds(new \DateTime(), -3600), + 'expire' => DateTime::dateAddSeconds(new \DateTime(), -3600), ]); $response = $this->client->call(Client::METHOD_GET, '/health', [ @@ -1347,7 +1348,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'name' => 'Key Test Update', 'scopes' => ['users.read', 'users.write', 'collections.read'], - 'expire' => Database::dateAddSeconds(new \DateTime(), 360), + 'expire' => DateTime::dateAddSeconds(new \DateTime(), 360), ]); $this->assertEquals(200, $response['headers']['status-code']); diff --git a/tests/e2e/Services/Teams/TeamsBaseServer.php b/tests/e2e/Services/Teams/TeamsBaseServer.php index ceb1506c9..a5db88358 100644 --- a/tests/e2e/Services/Teams/TeamsBaseServer.php +++ b/tests/e2e/Services/Teams/TeamsBaseServer.php @@ -4,6 +4,7 @@ namespace Tests\E2E\Services\Teams; use Tests\E2E\Client; use Utopia\Database\Database; +use Utopia\Database\DateTime; trait TeamsBaseServer { @@ -61,7 +62,7 @@ trait TeamsBaseServer $this->assertNotEmpty($response['body']['teamId']); $this->assertCount(2, $response['body']['roles']); $this->assertIsString($response['body']['joined']); - $this->assertGreaterThan('2020-07-07 07:58:44', Database::getCurrentDateTime()); + $this->assertGreaterThan('2020-07-07 07:58:44', DateTime::getCurrentDateTime()); $this->assertEquals(true, $response['body']['confirm']); $userUid = $response['body']['userId']; diff --git a/tests/unit/Auth/AuthTest.php b/tests/unit/Auth/AuthTest.php index 660def6f0..1b76c4d38 100644 --- a/tests/unit/Auth/AuthTest.php +++ b/tests/unit/Auth/AuthTest.php @@ -3,6 +3,7 @@ namespace Appwrite\Tests; use Appwrite\Auth\Auth; +use Utopia\Database\DateTime; use Utopia\Database\Document; use Utopia\Database\Validator\Authorization; use PHPUnit\Framework\TestCase; @@ -76,14 +77,14 @@ class AuthTest extends TestCase $tokens1 = [ new Document([ '$id' => 'token1', - 'expire' => Database::dateAddSeconds(new \DateTime(), 60 * 60 * 24), + 'expire' => DateTime::dateAddSeconds(new \DateTime(), 60 * 60 * 24), 'secret' => $hash, 'provider' => Auth::SESSION_PROVIDER_EMAIL, 'providerUid' => 'test@example.com', ]), new Document([ '$id' => 'token2', - 'expire' => Database::dateAddSeconds(new \DateTime(), -60 * 60 * 24), + 'expire' => DateTime::dateAddSeconds(new \DateTime(), -60 * 60 * 24), 'secret' => 'secret2', 'provider' => Auth::SESSION_PROVIDER_EMAIL, 'providerUid' => 'test@example.com', @@ -93,14 +94,14 @@ class AuthTest extends TestCase $tokens2 = [ new Document([ // Correct secret and type time, wrong expire time '$id' => 'token1', - 'expire' => Database::dateAddSeconds(new \DateTime(), -60 * 60 * 24), + 'expire' => DateTime::dateAddSeconds(new \DateTime(), -60 * 60 * 24), 'secret' => $hash, 'provider' => Auth::SESSION_PROVIDER_EMAIL, 'providerUid' => 'test@example.com', ]), new Document([ '$id' => 'token2', - 'expire' => Database::dateAddSeconds(new \DateTime(), -60 * 60 * 24), + 'expire' => DateTime::dateAddSeconds(new \DateTime(), -60 * 60 * 24), 'secret' => 'secret2', 'provider' => Auth::SESSION_PROVIDER_EMAIL, 'providerUid' => 'test@example.com', @@ -121,13 +122,13 @@ class AuthTest extends TestCase new Document([ '$id' => 'token1', 'type' => Auth::TOKEN_TYPE_RECOVERY, - 'expire' => Database::dateAddSeconds(new \DateTime(), 60 * 60 * 24), + 'expire' => DateTime::dateAddSeconds(new \DateTime(), 60 * 60 * 24), 'secret' => $hash, ]), new Document([ '$id' => 'token2', 'type' => Auth::TOKEN_TYPE_RECOVERY, - 'expire' => Database::dateAddSeconds(new \DateTime(), -60 * 60 * 24), + 'expire' => DateTime::dateAddSeconds(new \DateTime(), -60 * 60 * 24), 'secret' => 'secret2', ]), ]; @@ -136,13 +137,13 @@ class AuthTest extends TestCase new Document([ // Correct secret and type time, wrong expire time '$id' => 'token1', 'type' => Auth::TOKEN_TYPE_RECOVERY, - 'expire' => Database::dateAddSeconds(new \DateTime(), -60 * 60 * 24), + 'expire' => DateTime::dateAddSeconds(new \DateTime(), -60 * 60 * 24), 'secret' => $hash, ]), new Document([ '$id' => 'token2', 'type' => Auth::TOKEN_TYPE_RECOVERY, - 'expire' => Database::dateAddSeconds(new \DateTime(), -60 * 60 * 24), + 'expire' => DateTime::dateAddSeconds(new \DateTime(), -60 * 60 * 24), 'secret' => 'secret2', ]), ]; @@ -151,13 +152,13 @@ class AuthTest extends TestCase new Document([ '$id' => 'token1', 'type' => Auth::TOKEN_TYPE_INVITE, - 'expire' => Database::dateAddSeconds(new \DateTime(), 60 * 60 * 24), + 'expire' => DateTime::dateAddSeconds(new \DateTime(), 60 * 60 * 24), 'secret' => $hash, ]), new Document([ '$id' => 'token2', 'type' => Auth::TOKEN_TYPE_RECOVERY, - 'expire' => Database::dateAddSeconds(new \DateTime(), -60 * 60 * 24), + 'expire' => DateTime::dateAddSeconds(new \DateTime(), -60 * 60 * 24), 'secret' => 'secret2', ]), ];