Skip to content

Commit

Permalink
Merge pull request #676 from nextcloud/backport/671/stable19
Browse files Browse the repository at this point in the history
[stable19] Delete duplicates of the same push token hash
  • Loading branch information
nickvergessen authored Jul 2, 2020
2 parents b2d2a42 + 59fd0f7 commit b4ece9d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/Controller/PushController.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ protected function savePushToken(IUser $user, IToken $token, string $deviceIdent
$result->closeCursor();

if (!$row) {
// In case the auth token is new, delete potentially old entries for the same device (push token) by this user
$this->deletePushTokenByHash($user, $pushTokenHash);

return $this->insertPushToken($user, $token, $deviceIdentifier, $devicePublicKey, $pushTokenHash, $proxyServer, $appType);
}

Expand Down Expand Up @@ -261,4 +264,18 @@ protected function deletePushToken(IUser $user, IToken $token): bool {

return $query->execute() !== 0;
}

/**
* @param IUser $user
* @param string $pushTokenHash
* @return bool If the entry was deleted
*/
protected function deletePushTokenByHash(IUser $user, string $pushTokenHash): bool {
$query = $this->db->getQueryBuilder();
$query->delete('notifications_pushtokens')
->where($query->expr()->eq('uid', $query->createNamedParameter($user->getUID())))
->andWhere($query->expr()->eq('pushtokenhash', $query->createNamedParameter($pushTokenHash)));

return $query->execute() !== 0;
}
}

0 comments on commit b4ece9d

Please sign in to comment.