Jump to content

Delete unused/orphanned images


Veronica

Recommended Posts

Looking for a way to delete images along with products - my shop is mostly one-off artworks, so when a piece is gone, it's gone.

I found this one for Cube Cart 3:

Image Utilities CC3

I haven't tried it in CC6 - not sure if it would break something.  I can manually delete images if I remember before deleting the product, but tricky to do in the other order - the image filename being pretty much only recorded in the product listing (the other place being in the artist signature on the actual jpg - so I can go over to his tumblr blog and try find the piece, then zoom in for the signature and hope it's readable, then hop back over to the shop admin and find the jpg to delete... - would be good if said artist could include product id in text in the tumblr blog, but that's another story...)

My budget is minimal :) I'm guessing this feature would appeal most to those with cheaper limited hosting, so I understand if not really worth the hassle.

But I post here just in case and will try remember to delete the image first next time :)

 

Link to comment
Share on other sites

I've always thought it would be very helpful for me if I could delete photos that are not being used by any current product listing. I don't have a clue how this could be done, but hopefully someone will be along who can suggest a solution for you (and I might be able to use that solution to help me, too).

There are way too many differences between the database tables in CC3 and 6 for that extension to work. But maybe it will kickstart a solution in v6??

Link to comment
Share on other sites

It's ironic that this would be asked since it wasn't too long ago that a situation was fixed: after FTP'ing a bunch of images into the /images/source/ folder, clicking the FileManager, Update File List tab, would disassociate all already associated images from their products.

The Update File List tab is meant to find all new images (not uploaded via CubeCart) and get them logged into the FileManager.

There is (or was) a means to delete all images that are not logged in the Filemanager.

There is no means to delete all images not associated with any product or category.

Even the cheapest of hosting plans should provide for enough hard drive space to hold thousands of image files.

But unused images do make for a longer than necessary Image Picker listing.

Link to comment
Share on other sites

In some scenarios, the FileManager Update File List tab will delete from the FileManager's logs references to images that no longer exist in /images/source/ (or subfolders) that were removed other than via CubeCart's control.

It helps to first unassign the images that are due to disappear from the product.

Link to comment
Share on other sites

  • 2 weeks later...

I don't know if this helps but here is my 2 cents.  I create an image folder for each item I list and like Veronica I have a lot of one and gone products.  When the item sells and I have proof it has been delivered, it is no problem to go into admin and delete the product and the image folder associated with it.  That way you have no orphan images.

Claudia

Link to comment
Share on other sites

22 hours ago, Claudia M said:

I create an image folder for each item I list and like Veronica I have a lot of one and gone products.  When the item sells and I have proof it has been delivered, it is no problem to go into admin and delete the product and the image folder associated with it.

Having a directory per product may seem a little extreme but ALL store owners should really sub-divide images by category or some other logical sub-division, as it just makes many things so much easier - the number of times we have taken on clients that had 20,000 plus images all in one directory which is unwieldy in so many ways.

Ian

 

Link to comment
Share on other sites

  • 2 weeks later...

It's quite simple to put together a script to delete orphaned images, I've done it before although don't have anything to hand. I can produce this if required.
 I've used it in the past to clean up several thousand unused images.

Link to comment
Share on other sites

  • 3 weeks later...

I have an idea for a crude method.

FTP the images folder to a PC.

Export the database table 'Cubecart_filemanager' as a csv file and modify this table to include dos commands, (the dos commands would copy the images listed in filemanager to another location)

clean it up and convert it to a batch file.

When the copy has completed, upload the images folder back.

The new images folder should now only contain those images which are referenced in the filemanager table.

Rather than deleting any unused images, your'e copying the used one.

 

It's extremely crude, but simple and should work.

Link to comment
Share on other sites

  • 3 weeks later...
On 1/27/2017 at 11:52 AM, Noodleman said:

I am going to release a module to handle this, I just haven't had time to write it yet due to have some commitments to custom projects for people.

Hi @Noodleman , Any progress on this yet? I have a client who has several years worth of redundant images in the source folder and it would be a nightmare to try and sort them manually. 

T

 

 

Link to comment
Share on other sites

no progress yet. I've got two active customer projects I need to complete before I can spend time on the module.  I've already got the designed confirmed, I just need to put aside the time to make it.

unless I get ahead of schedule over this week, which is unlikely, it's probably going to be sometime in March.

Link to comment
Share on other sites

  • 2 weeks later...

I just tried this using my cheat method and it worked as I expected it would, whilst not the tidiest of methods, it did only take about 10 minutes to write the batch file, and duplicate the used images.

I guess the time contraints would be the FTP.

 

For me, it's not worth messing around as I only found 33 orphaned images

 

I'm more than happy to share step by step instructions if you get desperate.

 

Link to comment
Share on other sites

It's good to know it works.  Your description above is pretty clear I think.

For me I think even just having a comparison between used images and images in the source directory would be enough.  I think I have all the product images separate from other images used in the website, but would need to double check.

Link to comment
Share on other sites

I wouldn't recommend using that method. It won't consider images being referenced in either category/document or product descriptions. Those images will likely be considered orphaned and get removed. The module I will put together, hopefully in March will address embeded images as well as those directly associated with products/categories etc.

In theory, filemanager contains all images found in the /images/source directory regardless of if it's in use in the store, so your process isn't really removing orphaned files. It's likely removing images which are not in sync with the store DB. you can run the filemanager / scan/update process and it will re-scan the images directory and add/remove records as required to the filemanager table.

The trick is to find images/data that isn't in use elsewhere in the store, and exists in both filemanager and the /images/source directory. Those are the true opphaned/unused images.  I've some crude code which does this already but needs to be polished and published via a module.

 

Link to comment
Share on other sites

  • 1 year later...

Unfortunately not, I've been super busy recently as well as moving house/offices. It is still on my R&D roadmap, but I've got more urgent customer projects to complete first before I can get to this. At this time, I can't give an estimate of when I would be able to carve out enough time to fit this module in, but it WILL get done...

Link to comment
Share on other sites

  • 3 months later...

Adding new products is currently taking over 12 minutes per product as the Image Picker listing taking an age to load due to there being an excess of images.

I have compiled a list of several thousand unassigned / orphaned images using the Store Health Check plugin. After much searching for a solution I'm guessing that the only way to bulk delete these orphaned images is with SSH ???

However, I must admit that I have never used SSH so I know nothing of the process. Can somebody tell me if there is another way or perhaps give me a clue as to how to go about it and can I use a text file list of the orphaned images?

Any help or advice will be very gratefully received.

T

 

Link to comment
Share on other sites

If you don't want to delete the images, then this may help.

Inside images/source create a sub folder with a name of your choice.

I called mine 'pictures'

Move all the images from the source folder to source/pictures.


In PHP MyAdmin, Make a backup copy of the table Cubecart_filemanager, then run the following sql script.

UPDATE `CubeCart_filemanager` SET `filepath` = 'pictures/' WHERE `CubeCart_filemanager`.`file_id` >0

This will update the file locations for all the images you moved earlier.

Now when you add a new product, there will be no images inside the source folder to get in the way.

If you do want to delete the images, then my method of writing a dos script will work, but it would involve the need to ftp the folder off the server and back on again afterwards.

Link to comment
Share on other sites

Thanks @keat that's a great solution. 

It took over an hour to move the images into the 'pictures' directory but now the Image Picker is working at normal speed again which has solved the main issue 🙂

I would still like to delete the orphaned images but don't fancy FTPing them all off the server and back again as it would take an eternity. However, I believe a similar script would work directly on the server using SSH ????

Anyway, thanks again.

Link to comment
Share on other sites

I compiled my list of file names, and imported these in to a seperate column in excell.

I then created new colums containing the dos scripts either side of the file name column.

Exported the whole lot as a txt file.

Used find and replace to take out the delimitation marks, and saved this a a dos batch file.

 

I've no doubt the same would work through SSH, but I'm not sure how to create and run a script in SSH.

I could pose the question on the CPanel forum if you like ?

Maybe this could be automated through FileZilla FTP app ??

Link to comment
Share on other sites

20 hours ago, TDLWebs said:

It took over an hour to move the images into the 'pictures' directory

Update: I got to grips with SSH and wish I had done it sooner. Moving the orphaned images from the 'pictures' folder into a temp folder ready for deleting took about a minute; and there were thousands of them!

My process in future will be to identify the orphaned images using Store Health Check, then use SSH to get rid of them. Simples 🙂

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...