moNTeZIon Posted July 9, 2015 Share Posted July 9, 2015 Hi, When downloading my prestashop to my local machine, just for backup it, I noticed that the IMG folder size is 12GB. This is a lot of space. Every day, or every two days, i delete all the products related to one Manufacturer, and import them again with the "Import CSV" process. By this way seems that the IMG folder grows up too much. What can i do to solve this problem? Thanks a lot. Link to comment Share on other sites More sharing options...
gabdara Posted July 10, 2015 Share Posted July 10, 2015 Try to regenerate thumbnails from Back Office > Preferences > Images and see if this decreases the size. If you are sure that only the manufacturers images are the problem you could regenerate thumbnails only for manufacturers, it will take less time. Link to comment Share on other sites More sharing options...
moNTeZIon Posted July 10, 2015 Author Share Posted July 10, 2015 Thanks gabdara, The problem is that every time we import, before the import process we delete all the products related to a manufacturer. We make this delete througt the database directly. Thats the problem, every time we delete products the images remain in the folder, and every time we have more images. Regenerate thumbnails don't resolve the problem. Regards, Link to comment Share on other sites More sharing options...
gabdara Posted July 10, 2015 Share Posted July 10, 2015 It's not indicated to delete the products directly from the database. Those products have related data in other tables than ps_product and it will remain in your database as junk data. You should create a module in which you get the id of the products associated with the manufacturers you want to delete, then instantiate the products with the Product class and use method delete. The same thing you should do with the manufacturers, instantiate with Manufacturer class and use method delete. In this way you will make sure that all the associated data in the database and associated files are erased. Now to remove the junk images you could look into database in ps_product and see from what id does your current products start. Then look in YOUR_PRESTASHOP/img/p, all the images of the products are in corresponding id folder. You could delete all the folders that are below the first id in the database. As for the junk data in your database you'll need some custom SQL queries. Link to comment Share on other sites More sharing options...
moNTeZIon Posted July 13, 2015 Author Share Posted July 13, 2015 (edited) Hi gabdara, I don't delete the products related to a manufacturer, only deleting from product table. I make all this delete statements: DELETE FROM prefix_product WHERE id_manufacturer=".$current_manufacturer; DELETE FROM prefix_product_attribute WHERE id_product NOT IN (SELECT p.id_product FROM prefix_product p) DELETE FROM prefix_product_sale WHERE id_product NOT IN (SELECT p.id_product FROM prefix_product p) DELETE FROM prefix_product_lang WHERE id_product NOT IN (SELECT p.id_product FROM prefix_product p) DELETE FROM prefix_category_product WHERE id_product NOT IN (SELECT p.id_product FROM prefix_product p) DELETE FROM prefix_image WHERE id_product NOT IN (SELECT p.id_product FROM prefix_product p) DELETE FROM prefix_image_lang WHERE id_image NOT IN (SELECT p.id_image FROM prefix_image p) DELETE FROM prefix_product_attribute_combination WHERE id_product_attribute NOT IN (SELECT p.id_product_attribute FROM prefix_product_attribute p) DELETE FROM prefix_attribute_impact WHERE id_product NOT IN (SELECT p.id_product FROM prefix_product p) DELETE FROM prefix_product_tag WHERE id_product NOT IN (SELECT p.id_product FROM prefix_product p) DELETE FROM prefix_tag WHERE id_tag NOT IN (SELECT p.id_tag FROM prefix_product_tag p) DELETE FROM prefix_feature_product WHERE id_product NOT IN (SELECT p.id_product FROM prefix_product p) DELETE FROM prefix_feature_value WHERE id_feature NOT IN (SELECT p.id_feature FROM prefix_feature_product p) DELETE FROM prefix_feature_value_lang WHERE id_feature_value NOT IN (SELECT p.id_feature_value FROM prefix_feature_value p) Then, in the last days i've found a module that you can use to delete all the existing images in the IMG/P folder that are not related to any existing product. I think that module will help me a lot with my problem. If that resolves my problem, i will have a last problem, and is the identity/autoincrement columns... I would like, after the deleting statements, to reset the identity/autoincrement columns, just next to the bigest ID of the remaining products. For example, if the biggest ID in the product table is 5 after the deleting process, reset the identity value to 6. I think that would solve a big part of my problems. I would like to hear from you experts! Thanks for your replies/sugestions. Edited July 13, 2015 by moNTeZIon (see edit history) Link to comment Share on other sites More sharing options...
gabdara Posted July 14, 2015 Share Posted July 14, 2015 Your delete statements seem to do the job. Please share the module you've found if it removes all the images of products that don't exist anymore for others that might have similar problem to try it. Regarding the autoincrement, if you're using phpmyadmin after you select a table go to Operations tab. From there you can change the AUTO_INCREMENT value. Or use a sql statement similar to this: SELECT MAX(id_product) + 1 FROM `ps_product`; Take the resulting value and add it to the alter statement: ALTER TABLE `ps_product` AUTO_INCREMENT = <PUT MAX RESULT>; You'll have to do this for all the tables from your delete statements. Link to comment Share on other sites More sharing options...
moNTeZIon Posted July 15, 2015 Author Share Posted July 15, 2015 Thanks for your replies Gabdara, You have helped me. This is the module i found to delete de images not related to any product. And I can say that works fine! http://addons.prestashop.com/es/administracion-prestashop-modulo/19192-delete-useless-images.html Regards, Link to comment Share on other sites More sharing options...
Recommended Posts