fix: remove redundant db column

Signed-off-by: Jana Peper <jana.peper@nextcloud.com>
pull/55790/head
Jana Peper 2025-11-20 13:18:44 +07:00 committed by janepie
parent 4dab6217a2
commit b02966a481
4 changed files with 7 additions and 21 deletions

@ -13,22 +13,16 @@ use OCP\AppFramework\Db\Entity;
/**
* @method int getTokenId()
* @method string getToken()
* @method ?string getUserId()
* @method int getCreatedAt()
* @psalm-suppress PropertyNotSetInConstructor
*/
class EphemeralToken extends Entity implements \JsonSerializable {
/**
* @var int id of the token that was created for a webhook
* @var int id of the token in the oc_authtoken db table
*/
protected $tokenId;
/**
* @var string the token
*/
protected $token;
/**
* @var ?string id of the user wich the token belongs to
* @psalm-suppress PropertyNotSetInConstructor
@ -36,14 +30,13 @@ class EphemeralToken extends Entity implements \JsonSerializable {
protected $userId = null;
/**
* @var int
* @var int token creation timestamp
* @psalm-suppress PropertyNotSetInConstructor
*/
protected $createdAt;
public function __construct() {
$this->addType('tokenId', 'integer');
$this->addType('token', 'string');
$this->addType('userId', 'string');
$this->addType('createdAt', 'integer');
}

@ -39,7 +39,7 @@ class EphemeralTokenMapper extends QBMapper {
/**
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
* @throws Exception
* @throws \Exception
*/
public function getById(int $id): EphemeralToken {
$qb = $this->db->getQueryBuilder();
@ -52,7 +52,7 @@ class EphemeralTokenMapper extends QBMapper {
}
/**
* @throws Exception
* @throws \Exception
* @return EphemeralToken[]
*/
public function getAll(): array {
@ -75,18 +75,16 @@ class EphemeralTokenMapper extends QBMapper {
}
/**
* @throws Exception
* @throws \Exception
*/
public function addEphemeralToken(
int $tokenId,
string $token,
?string $userId,
int $createdAt,
): EphemeralToken {
$tempToken = EphemeralToken::fromParams(
[
'tokenId' => $tokenId,
'token' => $token,
'userId' => $userId,
'createdAt' => $createdAt,
]
@ -95,7 +93,7 @@ class EphemeralTokenMapper extends QBMapper {
}
/**
* @throws Exception
* @throws \Exception
*/
public function deleteByTokenId(int $tokenId): bool {
$qb = $this->db->getQueryBuilder();
@ -112,7 +110,7 @@ class EphemeralTokenMapper extends QBMapper {
$this->logger->debug('Invalidating ephemeral webhook tokens older than ' . date('c', $olderThan), ['app' => 'webhook_listeners']);
foreach ($tokensToDelete as $token) {
$this->tokenMapper->invalidate($token->getToken()); // delete token itself
$this->tokenMapper->invalidate($this->tokenMapper->getTokenById($token->getTokenId())->getToken()); // delete token itself
$this->deleteByTokenId($token->getTokenId()); // delete db row in webhook_tokens
}
}

@ -51,10 +51,6 @@ class Version1500Date20251007130000 extends SimpleMigrationStep {
'length' => 4,
'unsigned' => true,
]);
$table->addColumn('token', Types::STRING, [
'notnull' => false,
'length' => 200,
]);
$table->addColumn('user_id', Types::STRING, [
'notnull' => false,
'length' => 64,

@ -104,7 +104,6 @@ class TokenService {
}
$this->tokenMapper->addEphemeralToken(
$deviceToken->getId(),
$deviceToken->getToken(),
$userId,
$this->time->getTime());
return $token;