Liip Imagine generates wrong remove path on listener event in Symfony 5

I’m using Liip Imagine Bundle for Symfony 5. I’ve got it configured, the images are generated and show properly.

However, I have an issues on an event listener for postUpdate and preRemove where I want to delete the image.

The listener itself works fine, but Liip Imagine generates the wrong path for the storage, and thus I’m stuck with hundreds of images that never get deleted properly.

My config is fairly standard:

parameters:
  img_path: "/public/assets/img/uploaded"
  display_img_path: "/assets/img/uploaded/"
  google_secret_key: '%env(GOOGLE_KEY)%'
  site_name: '%env(SITE_NAME)%'
  liip_img_cache_path: '/media/cache'
liip_imagine:
  resolvers:
    default:
      web_path:
        web_root: "%kernel.project_dir%/public"
        cache_prefix: "%liip_img_cache_path%"
  filter_sets:
    cache: ~
    listing_show_thumbnails:
      quality: 60
      filters:
        thumbnail: { size: [ 450 ], mode: outbound, allow_upscale: true }
    user_profile_public_thumbnail:
      quality: 60
      filters:
        thumbnail: { size: [ 600 ], mode: outbound, allow_upscale: true }
    add_single_thumbnail:
      quality: 60
      filters:
        thumbnail: { size: [ 300 ], mode: outbound, allow_upscale: true }
    add_single_thumbnail_carousel:
      quality: 80
      filters:
        thumbnail: { size: [ 800 ], mode: outbound, allow_upscale: true }

And they way the listener is setup is also standard.

class CacheImageListener
{
    protected $cacheManager;
    protected $parameterBag;

    public function __construct(CacheManager $cacheManager, ParameterBagInterface $parameterBag)
    {
        $this->cacheManager = $cacheManager;
        $this->parameterBag = $parameterBag;
    }

    public function postUpdate(LifecycleEventArgs $args)
    {
        //... some other stuff here
    }

    public function preRemove(LifecycleEventArgs $args)
    {
        $entity = $args->getEntity();
        if ($entity instanceof UserImage) {
            if($this->cacheManager->isStored($entity->getPath(), 'user_profile_public_thumbnail')) {
                $this->cacheManager->remove($entity->getPath(), 'user_profile_public_thumbnail');
            }
        }
        // other functions bellow

The path generated by the fucntion

$this->cacheManager->isStored...

is

C:Bitnamiwampstack-7.4.9-0appscoleg/public/media/cache/user_profile_public_thumbnail/6012e6dbf4cad3416fb609e343470c27778f491dd1debc238fa2d9b3676fae007cc439bcb912feaca006db1bc23a6d17759e.jpeg

The first part is correct(C:Bitnamiwampstack-7.4.9-0appscoleg/public/media/cache/user_profile_public_thumbnail/) but the rest is not.

The folder structures is like so

Basically it’s missing the "suffix", I suppose you’d call it. Meaning the assets/img/uploaded which is where I store my original images.


I’m pretty sure I have something misconfigured somewhere but I can’t put my finger on it.

enter image description here

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *