VichUploaderBundle Removing an image asynchronously using message queue

48 Views Asked by At

Would anyone be able to help me delete a file using VichUploaderBundle asynchronously?

The images are being uploaded to S3 and being cached by LiipImagineBUndle. When I was deleting the enitity straight from the database the image would remove fine.

For performance I want to put the file deletion in a message queue.

The message queue is working fine as setup here: https://github.com/dustin10/VichUploaderBundle/blob/master/docs/events/howto/remove_files_asynchronously.md

The problem is a I don't know how to actually delete the original file. I don't quite understand what needs to be done below.

All that is returned from the message is the filename.

$filename = $message->getFilename();

// delete your file according to your mapping configuration

I have managed to delete the cache files fine but I cannot delete the orginal file.

namespace App\MessageHandler;

use App\Message\RemoveProductImageMessage;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;

class RemoveProductImageMessageHandler implements MessageHandlerInterface
    {
    
        private $cacheManager;
    
        public function __construct(CacheManager $cacheManager)
        {         
            $this->cacheManager = $cacheManager;
        }   
    
        public function __invoke(RemoveProductImageMessage $message): void
        {
            $filename = $message->getFilename();
    
            // delete your file according to your mapping configuration. What does this mean?
    
            // Need to delete original image here but don't understand how
            
            $this->cacheManager->remove($filename, 'large');
            $this->cacheManager->remove($filename, 'header');
            $this->cacheManager->remove($filename, 'medium');
            $this->cacheManager->remove($filename, 'profile');
            $this->cacheManager->remove($filename, 'thumb');                
    
        }
    }
0

There are 0 best solutions below