mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Fixed error caused by immutable datetime passed to mutable datetime doctrine type
This commit is contained in:
parent
4d927c5870
commit
777f6ba738
4 changed files with 11 additions and 11 deletions
|
@ -75,7 +75,7 @@ class APITokenFixtures extends Fixture implements DependentFixtureInterface
|
||||||
$expired_token->setUser($admin_user);
|
$expired_token->setUser($admin_user);
|
||||||
$expired_token->setLevel(ApiTokenLevel::FULL);
|
$expired_token->setLevel(ApiTokenLevel::FULL);
|
||||||
$expired_token->setName('expired');
|
$expired_token->setName('expired');
|
||||||
$expired_token->setValidUntil(new \DateTimeImmutable('-1 day'));
|
$expired_token->setValidUntil(new \DateTime('-1 day'));
|
||||||
$this->setTokenSecret($expired_token, self::TOKEN_EXPIRED);
|
$this->setTokenSecret($expired_token, self::TOKEN_EXPIRED);
|
||||||
$manager->persist($expired_token);
|
$manager->persist($expired_token);
|
||||||
|
|
||||||
|
|
|
@ -41,9 +41,9 @@ class OAuthToken extends AbstractNamedDBElement implements AccessTokenInterface
|
||||||
#[ORM\Column(type: 'text', nullable: true)]
|
#[ORM\Column(type: 'text', nullable: true)]
|
||||||
private ?string $token = null;
|
private ?string $token = null;
|
||||||
|
|
||||||
/** @var \DateTimeInterface The date when the token expires */
|
/** @var \DateTimeImmutable|null The date when the token expires */
|
||||||
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
|
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
|
||||||
private ?\DateTimeInterface $expires_at = null;
|
private ?\DateTimeImmutable $expires_at = null;
|
||||||
|
|
||||||
/** @var string|null The refresh token for the OAuth2 auth */
|
/** @var string|null The refresh token for the OAuth2 auth */
|
||||||
#[ORM\Column(type: 'text', nullable: true)]
|
#[ORM\Column(type: 'text', nullable: true)]
|
||||||
|
@ -54,7 +54,7 @@ class OAuthToken extends AbstractNamedDBElement implements AccessTokenInterface
|
||||||
*/
|
*/
|
||||||
private const DEFAULT_EXPIRATION_TIME = 3600;
|
private const DEFAULT_EXPIRATION_TIME = 3600;
|
||||||
|
|
||||||
public function __construct(string $name, ?string $refresh_token, ?string $token = null, \DateTimeInterface $expires_at = null)
|
public function __construct(string $name, ?string $refresh_token, ?string $token = null, \DateTimeImmutable $expires_at = null)
|
||||||
{
|
{
|
||||||
//If token is given, you also have to give the expires_at date
|
//If token is given, you also have to give the expires_at date
|
||||||
if ($token !== null && $expires_at === null) {
|
if ($token !== null && $expires_at === null) {
|
||||||
|
@ -82,7 +82,7 @@ class OAuthToken extends AbstractNamedDBElement implements AccessTokenInterface
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function unixTimestampToDatetime(int $timestamp): \DateTimeInterface
|
private static function unixTimestampToDatetime(int $timestamp): \DateTimeImmutable
|
||||||
{
|
{
|
||||||
return \DateTimeImmutable::createFromFormat('U', (string)$timestamp);
|
return \DateTimeImmutable::createFromFormat('U', (string)$timestamp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ class ApiToken implements TimeStampableInterface
|
||||||
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
|
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
|
||||||
#[Groups('token:read')]
|
#[Groups('token:read')]
|
||||||
#[Year2038BugWorkaround]
|
#[Year2038BugWorkaround]
|
||||||
private ?\DateTimeInterface $valid_until;
|
private ?\DateTime $valid_until;
|
||||||
|
|
||||||
#[ORM\Column(length: 68, unique: true)]
|
#[ORM\Column(length: 68, unique: true)]
|
||||||
private string $token;
|
private string $token;
|
||||||
|
@ -89,7 +89,7 @@ class ApiToken implements TimeStampableInterface
|
||||||
|
|
||||||
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
|
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
|
||||||
#[Groups('token:read')]
|
#[Groups('token:read')]
|
||||||
private ?\DateTimeInterface $last_time_used = null;
|
private ?\DateTime $last_time_used = null;
|
||||||
|
|
||||||
public function __construct(ApiTokenType $tokenType = ApiTokenType::PERSONAL_ACCESS_TOKEN)
|
public function __construct(ApiTokenType $tokenType = ApiTokenType::PERSONAL_ACCESS_TOKEN)
|
||||||
{
|
{
|
||||||
|
@ -130,7 +130,7 @@ class ApiToken implements TimeStampableInterface
|
||||||
return $this->valid_until === null || $this->valid_until > new \DateTime();
|
return $this->valid_until === null || $this->valid_until > new \DateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setValidUntil(?\DateTimeInterface $valid_until): ApiToken
|
public function setValidUntil(?\DateTime $valid_until): ApiToken
|
||||||
{
|
{
|
||||||
$this->valid_until = $valid_until;
|
$this->valid_until = $valid_until;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -168,10 +168,10 @@ class ApiToken implements TimeStampableInterface
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the last time the token was used to authenticate.
|
* Sets the last time the token was used to authenticate.
|
||||||
* @param \DateTimeInterface|null $last_time_used
|
* @param \DateTime|null $last_time_used
|
||||||
* @return ApiToken
|
* @return ApiToken
|
||||||
*/
|
*/
|
||||||
public function setLastTimeUsed(?\DateTimeInterface $last_time_used): ApiToken
|
public function setLastTimeUsed(?\DateTime $last_time_used): ApiToken
|
||||||
{
|
{
|
||||||
$this->last_time_used = $last_time_used;
|
$this->last_time_used = $last_time_used;
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
@ -75,7 +75,7 @@ class ApiTokenAuthenticator implements AuthenticatorInterface
|
||||||
|
|
||||||
$old_time = $token->getLastTimeUsed();
|
$old_time = $token->getLastTimeUsed();
|
||||||
//Set the last used date of the token
|
//Set the last used date of the token
|
||||||
$token->setLastTimeUsed(new \DateTimeImmutable());
|
$token->setLastTimeUsed(new \DateTime());
|
||||||
//Only flush the token if the last used date change is more than 10 minutes
|
//Only flush the token if the last used date change is more than 10 minutes
|
||||||
//For performance reasons we don't want to flush the token every time it is used, but only if it is used more than 10 minutes after the last time it was used
|
//For performance reasons we don't want to flush the token every time it is used, but only if it is used more than 10 minutes after the last time it was used
|
||||||
//If a flush is later in the code we don't want to flush the token again
|
//If a flush is later in the code we don't want to flush the token again
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue