Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to update specific image if source has changed? #132

Closed
tburny opened this issue Jan 22, 2013 · 7 comments
Closed

How to update specific image if source has changed? #132

tburny opened this issue Jan 22, 2013 · 7 comments
Labels
Attn: Blocker This item blocks other issue(s) or PR(s) and therefore must be resolved prior. Level: Bug 🐞 This item involves a legitimate regression (bug) to existing functionality.
Milestone

Comments

@tburny
Copy link

tburny commented Jan 22, 2013

I'm using Liip to transform profile pictures to different sizes and I store them on the filesystem using the default configuration.

I cannot find a way to delete the old cached image, so it gets re-generated.
The goal is to have a filter name and a webpath of the original image file to delete the cached version(s) of that file.
I don't want to wipe the whole cache just because someone changed his profile picture.

My code so far:

                if (!empty($oldFile) && file_exists($oldFile)) {
                    unlink($oldFile);
                    $filter = 'profile_picture';
                    // Returns an image or a response, both unusable for me...
                    // $resolvedPath =  $cacheManager->resolve($this->getRequest(), $oldWebPath, $filter);
                    $cacheManager->remove($oldWebPath, $filter);
                }

How can I get this solved?

@havvg
Copy link
Contributor

havvg commented Jan 22, 2013

Your $cacheManager->remove($oldWebPath, $filter); should do the trick. At least that's what I'm doing and it works fine.

@tburny
Copy link
Author

tburny commented Jan 22, 2013

Hmm. I cannot get this to work :(
I tried to make the paths relative to the browser root or using relative paths, the cached files still are not deleted.
The original files are uploaded to /web/uploads/avatars. I defined a filter named 'user_profile' and the target path thus is /web/cache/profile_picture/uploads/avatars.

The filter configuration:

liip_imagine:
    filter_sets:
        profile_picture:
            quality: 85
            filters:
                thumbnail: { size: [120, 120], mode: inbound }

$oldWebPath is a relative url, namely e.g. 'uploads/avatars/16.jpeg'. In the template, I use
{{ user.avatar.webpath | imagine_filter('profile_picture',true)}}
to create a picture with the user_profile definition.

I use the current dev-master version of Liip..Bundle, Imagine 0.4.0 with composer and Symfony 2.1

@tburny
Copy link
Author

tburny commented Jan 23, 2013

I found the solution, we have a little bug/non-expected behaviour here.
If CacheManager::resolve() isn't called before CacheManager::remove(), the cached image is not removed at all.

Not working:

        /** @var $cacheManager CacheManager */
        $cacheManager = $this->get('liip_imagine.cache.manager');
        // $cacheManager->resolve($this->getRequest(),$pngPath,$filter);
        $cacheManager->remove($pngPath, $filter);

Now uncomment the resolve line, the file gets deleted.

        /** @var $cacheManager CacheManager */
        $cacheManager = $this->get('liip_imagine.cache.manager');
        $cacheManager->resolve($this->getRequest(),$pngPath,$filter);
        $cacheManager->remove($pngPath, $filter);

where $pngPath is the path of the original image relative to the webroot, e.g. 'uploads/avatars/16.png'

@lsmith77
Copy link
Contributor

lsmith77 commented Feb 8, 2013

sorry .. i do not have time to dig into this atm. would be great if you could look into figuring this out. not sure if we need to add a resolve() call in remove() ..

@havvg
Copy link
Contributor

havvg commented Feb 8, 2013

I planned to write tests for most parts of this bundle over this weekend, hopefully I will discover the missing pieces and/or verify existing stuff :)

@lsmith77
Copy link
Contributor

lsmith77 commented Feb 8, 2013

wow! that would be sooooo awesome.

@havvg
Copy link
Contributor

havvg commented Feb 8, 2013

The correct behavior is to work with the targetPath, which is the resolved one.

$cacheManager = $this->get('liip_imagine.cache.manager');
$cacheManager->resolve($this->getRequest(), $pngPath, $filter);
$cacheManager->remove($pngPath, $filter);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Attn: Blocker This item blocks other issue(s) or PR(s) and therefore must be resolved prior. Level: Bug 🐞 This item involves a legitimate regression (bug) to existing functionality.
Projects
None yet
Development

No branches or pull requests

3 participants