allow inserting username with UserDeletedRepository

This commit is contained in:
Art4 2025-04-15 14:08:45 +00:00
parent 23d052c7fe
commit 00b4bd19d8
2 changed files with 52 additions and 0 deletions

View file

@ -9,8 +9,13 @@ declare(strict_types=1);
namespace Friendica\Database\Repository;
use Exception;
use Friendica\Database\Database;
use Friendica\Database\DatabaseException;
/**
* Repository for deleted users
*/
final class UserDeletedRepository
{
private Database $database;
@ -20,6 +25,25 @@ final class UserDeletedRepository
$this->database = $database;
}
/**
* Insert a deleted user by username.
*
* @throws \Exception If the username could not be inserted
*/
public function insertByUsername(string $username): void
{
$result = $this->database->insert('userd', ['username' => $username]);
if ($result === false) {
throw new Exception(sprintf('Error while inserting username `%s` as deleted user.', $username));
}
}
/**
* Check if a deleted username exists.
*
* @throws \Exception
*/
public function existsByUsername(string $username): bool
{
return $this->database->exists('userd', ['username' => $username]);