Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

How to delete created images? #31

Closed
OpenHaus opened this issue Sep 4, 2013 · 7 comments
Closed

How to delete created images? #31

OpenHaus opened this issue Sep 4, 2013 · 7 comments
Labels

Comments

@OpenHaus
Copy link

OpenHaus commented Sep 4, 2013

In the instructions you write that one should use

StorageManager::adapter($data['PdfFile']['adapter'])->delete($data['PdfFile']['path']);

to delete the file created before.

I am creating multiple sizes of my images. So I have one folder with a couple files. When I try to delete this folder as shown above ('path' points to the folder) I get a "Directory not empty" warning and nothing is deleted. Stepping through the code this is not surprising as the images itself are never removed.

How do I remove all images including the folder using your code? I could not find a suitable method or the parameters to clean up properly.

Thank you for any hints!

@burzum
Copy link
Owner

burzum commented Sep 9, 2013

StorageManager::adapter($data['PdfFile']['adapter'])->delete($data['PdfFile']['path']);

Calls the adapter directly - you have to make sure you build the correct path. If you used the same way to store images you won't even have any versions. You have to use the ImageStorage model. NOT the adapter directly. The adapter is a simple read/write Interface, it does not do the image processing magic, it just stores them. The model triggers events, look at the ImageStorage model and check Event/ImageProcessingListeiner.php for the actual implementation of image processing and deleting.

The readme.md also says to look at ImageProcessingListeiner.php and that you should use the model for storing images. Read the "Image Versioning" section of the readme.md.

If you extend or directly use the FileStorage model you don't even have to care of writing all the code yourself that is i the upper section of the readme.md, the model will do all the checking.

@burzum
Copy link
Owner

burzum commented Sep 16, 2013

Closing this now because no additional feedback was provided.

@burzum burzum closed this as completed Sep 16, 2013
@artnos
Copy link

artnos commented Aug 24, 2015

Hi I am trying to delete as well with my versioning,

In my ProductImagesTable I extends ImageStorageTable

This is where I have my upload method based on your tutorial.

I tried to create a delete method that removes the FileStorage row hoping the ImageStorageTable would run the ImageProcessingListener to listen for the delete which would remove the files like the upload did but that didn't work.

Can you offer some advice thank you.

@burzum
Copy link
Owner

burzum commented Aug 25, 2015

@artnos it is nearly impossible to understand the problem with the code without knowing the code. You need to come up with an easy and clear to reproduce scenario.

Please provide an unit test that demonstrates the problem.

@artnos
Copy link

artnos commented Aug 25, 2015

I don't know how to unit test but I made a stackoverflow and detailing my enviroment
http://stackoverflow.com/questions/32209075/cakephp-3-filestorage-plugin-triggering-the-imageprocessinglistener-to-delete-ve

I hope this helps.

@robertpustulka
Copy link
Contributor

@artnos Please read about deleting data in CakePHP: http://book.cakephp.org/3.0/en/orm/deleting-data.html
Now you're doing it wrong.

@artnos
Copy link

artnos commented Aug 25, 2015

ugh, thank you I changed my delete to, it works now
$entity = $this->get($fileStorageID);
$result = $this->delete($entity);

I knew about deleting this way i dont know why i choose the other way.
It doesn't remove the folders though, but that doesn't really matter. Thanks so much.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants