Skip to content

Commit

Permalink
updated anonymization
Browse files Browse the repository at this point in the history
Signed-off-by: bidi <bidi@apidemia.com>
  • Loading branch information
bidi47 committed Sep 12, 2024
1 parent a2e8eda commit 16e2c68
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 3 additions & 9 deletions src/User/src/Repository/UserAvatarRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,16 @@
use Doctrine\ORM\EntityRepository;
use Dot\DependencyInjection\Attribute\Entity;
use Frontend\User\Entity\UserAvatar;
use Ramsey\Uuid\Uuid;

/**
* @extends EntityRepository<object>
*/
#[Entity(name: UserAvatar::class)]
class UserAvatarRepository extends EntityRepository
{
public function deleteAvatar(string $uuid): mixed
public function deleteAvatar(UserAvatar $avatar): void
{
$uuid = Uuid::fromString($uuid)->getBytes();
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->delete(UserAvatar::class, 'user_avatar')
->where('user_avatar.uuid = :uuid')
->setParameter('uuid', $uuid);

return $qb->getQuery()->useQueryCache(true)->execute();
$this->getEntityManager()->remove($avatar);
$this->getEntityManager()->flush();
}
}
11 changes: 9 additions & 2 deletions src/User/src/Service/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use function is_readable;
use function mkdir;
use function password_hash;
use function rmdir;
use function sprintf;
use function time;
use function unlink;
Expand Down Expand Up @@ -222,10 +223,16 @@ protected function createAvatar(User $user, UploadedFile $uploadedFile): UserAva

public function deleteAvatar(User $user): void
{
$path = sprintf('%s/%s/', $this->config['uploads']['user']['path'], $user->getUuid()->toString());
$avatar = $user->getAvatar();
if (! $avatar instanceof UserAvatar) {
return;
}

$path = sprintf('%s/%s/', $this->config['uploads']['user']['path'], $user->getUuid()->toString());
$this->deleteAvatarFile($path . $avatar->getName());
$this->userAvatarRepository->deleteAvatar($user->getAvatar()->getUuid()->toString());
rmdir($path);

$this->userAvatarRepository->deleteAvatar($avatar);
}

public function deleteAvatarFile(string $path): bool
Expand Down

0 comments on commit 16e2c68

Please sign in to comment.