Try our conversational search powered by Generative AI!

Delete all assets(images) of a specific type



We need to delete about 60000 imageassets (imported from inriver) for a specific type from the web and cm database.

Anyone have any code or sql script for a this operation?

Commerce version: 9.24.1

CMS: 9.12.2

(yeah, I know we should upgrade, but thats another story...)

Edited, Jan 25, 2019 15:59

hi, do you care about database only or filesystem as well?

Jan 26, 2019 19:50

Just the easiest way of getting rid of all the inriver assets, so that I can re import everything from inriver.

My issue is that some months ago we deleted alle product and items, and as we see now, the linked assets were not deleted, just unlinked in the database. When we now try to import pictures for some of the products, with the same filename, the importcontroller gives an exeception of some kind that the image seo url is already occupied by some other content, so it can't import and link the image. And when I look in the database I see that the old assets existst in the content tables, version tabels and so on. 

So instead of writing a rather complex sql to delete alle the assets, I live in hope that there are an easier and less risky way of deleting all the resources. If not, maybe someone already have written a sql for a similar purpose.

Jan 28, 2019 10:11

You would have to write code to delete them, probably by iterating over all products and then delete each asset in their CommerceMediaCollection (assets are basically content so just use IContentRepository as usual)

It's not fast, but it is the safest way to go 

Jan 28, 2019 13:57

Ok, I built something that will iterate through all assets of a specific type in the blockfolders and delete them. Pretty slow though, but a one-time job, so I guess its ok for now.

Edited, Jan 30, 2019 12:07
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.