chg: dev: the user's avatar will be saved as a uuid.extension #4
All checks were successful
Deploy to Production / deploy (push) Successful in 10s
All checks were successful
Deploy to Production / deploy (push) Successful in 10s
This commit is contained in:
@@ -19,6 +19,7 @@ use Liip\ImagineBundle\Imagine\Cache\CacheManager;
|
|||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||||
|
use Symfony\Component\Uid\Uuid;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
@@ -228,16 +229,14 @@ class ProfileController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$ext = $file->guessExtension() ?? 'jpg';
|
$ext = $file->guessExtension() ?? 'jpg';
|
||||||
$newPath = sprintf('avatar/%d.%s', $user->getId(), $ext);
|
$newPath = sprintf('avatar/%s.%s', Uuid::v4()->toRfc4122(), $ext);
|
||||||
$oldPath = $user->getAvatarPath();
|
$oldPath = $user->getAvatarPath();
|
||||||
|
|
||||||
// Remove old file and any cached thumbnails
|
// Remove old file and any cached thumbnails
|
||||||
if ($oldPath) {
|
if ($oldPath) {
|
||||||
if ($oldPath !== $newPath) {
|
try {
|
||||||
try {
|
$mediaStorage->delete($oldPath);
|
||||||
$mediaStorage->delete($oldPath);
|
} catch (\Throwable) {
|
||||||
} catch (\Throwable) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$cacheManager->remove($oldPath, 'avatar_thumb');
|
$cacheManager->remove($oldPath, 'avatar_thumb');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user