3

We would like to remove all product images from the database and the file-system in Magento 2.2.8 shop.

There is a solution for Magento 1

Magento Delete all Product Images

Can this easily be adapted to Magento 2?

I am thinking about

  • rm -r pub/media/catalog/product/? pub/media/catalog/product/cache # keeping placeholder folder
  • And deleting from some tables in the database (which one) ?
  • Reindex

is this safe or are complications to expect?

We rather would not like to iterate over each product and save it, because of performance reasons.

3

Apart from:

catalog_product_entity_media_gallery

and

catalog_product_entity_media_gallery_value

tables, now Magento 2 has one more table

catalog_product_entity_media_gallery_value_to_entity,

which keeps track of removal of product in catalog_product_entity table, and relates this table to catalog_product_entity_media_gallery.

You need to check this table also.

One more table (catalog_product_entity_media_gallery_value_video) has been introduced in Magento 2, which keeps entries related to product videos.

Please review this table if you have any videos for products.

After the database operation, you can remove the image files from:

  • pub/media/catalog/product/ folder
  • pub/media/catalog/product/cache # keeping placeholder folder

That's all.

Note: Keep a backup of the database before doing any exercise on the database.

0

Based on mohit's answer:

truncate catalog_product_entity_media_gallery_value;
truncate catalog_product_entity_media_gallery_value_to_entity;
delete from catalog_product_entity_media_gallery;  # 9 sec
delete from catalog_product_entity_varchar where attribute_id in ( select 
     attribute_id from eav_attribute where attribute_code like "%image" and 
     entity_type_id = 4 ); # 23 sec in our case (20000 Products)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.