phpsymfonysonata-adminliipimaginebundle

Deleting Thumbnails from media/cache in liip imagine bundle


I have the bundle installed and configured with Sonata Admin Bundle, when I try to remove an Image, the image is properly deleted from the folder but not the thumbnail stored in media/cache.

this is my liip_imagine yml:

liip_imagine:

loaders:
    loader_s3_thumbnail:
        stream:
            wrapper: gaufrette://questions_image_fs/

filter_sets:
    question_thumb:
        cache: default
        data_loader: loader_s3_thumbnail
        # list of transformations to apply (the "filters")
        filters:
            thumbnail: { size: [120, 120], mode: outbound }

    provider_thumb:
        cache: default
        data_loader: loader_s3_thumbnail
        # list of transformations to apply (the "filters")
        filters:
            thumbnail: { size: [200, 200], mode: inset }

Any Idea why or how to delete this thumbnails?


Solution

  • Workmate managed to solve it using Liip cachemanager. Here is the code:

    Service:

      question.admin_bundle.event_listener.delete_thumbnails:
        class: QuestionAdminBundle\EventListener\DeleteThumbnails
        arguments: [ "@liip_imagine.cache.manager" ]
        tags:
            - { name: kernel.event_listener, event: vich_uploader.pre_remove, method: postRemove}  
    

    Php:

    use Liip\ImagineBundle\Imagine\Cache\CacheManager;
    [...]
    public function __construct(CacheManager $cacheManager)
    {
         Add a comment to this line
         $this->cacheManager = $cacheManager;
    }
    [...]
    public function postRemove(Event $event)
    {
        $image = $event->getObject();
        if ($image instanceof Image){
            $this->cacheManager->remove($image->getName());
        }
     }