From 5d6aff8d902dc01626bab5299d79e032642d3a8c Mon Sep 17 00:00:00 2001 From: Lang <7system7@gmail.com> Date: Tue, 14 Apr 2026 16:53:16 +0200 Subject: [PATCH] chg: dev: the user's avatar will be saved as a uuid.extension #4 --- src/Controller/ProfileController.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Controller/ProfileController.php b/src/Controller/ProfileController.php index e5af715..bfec582 100644 --- a/src/Controller/ProfileController.php +++ b/src/Controller/ProfileController.php @@ -19,6 +19,7 @@ use Liip\ImagineBundle\Imagine\Cache\CacheManager; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\File\UploadedFile; +use Symfony\Component\Uid\Uuid; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -228,16 +229,14 @@ class ProfileController extends AbstractController } $ext = $file->guessExtension() ?? 'jpg'; - $newPath = sprintf('avatar/%d.%s', $user->getId(), $ext); + $newPath = sprintf('avatar/%s.%s', Uuid::v4()->toRfc4122(), $ext); $oldPath = $user->getAvatarPath(); // Remove old file and any cached thumbnails if ($oldPath) { - if ($oldPath !== $newPath) { - try { - $mediaStorage->delete($oldPath); - } catch (\Throwable) { - } + try { + $mediaStorage->delete($oldPath); + } catch (\Throwable) { } $cacheManager->remove($oldPath, 'avatar_thumb'); }