I made a mistake and I need your help. I have a store based on Prestashop 1.6 and I was running out of space on the server so I decided to delete the images of disabled products.
I identified the IDs of disabled products with:
$sql_products = "SELECT id_product FROM ".DB_PREFIX."product WHERE active = 0";
I found out which images are related to these products with:
$sql_images = "SELECT id_image FROM ".DB_PREFIX."image WHERE id_product = ".$id_product;
I deleted the images/directories related to these images as well as the rows from the database with:
$sql_delete_image = "DELETE FROM ".DB_PREFIX."image WHERE id_image = ".$id_image;
Now, sometimes, I encounter an issue when adding an image to a product and I think it might be related to what I did.
Any tips on why this is happening and/or how to solve this problem?
Thank you in advance!
The cleaning operation you performed it's straightforward and shouldn't cause any issues when adding new images, I see that you have not deleted the rows from ps_image_shop, you must also consider that table in your work - probably the mistake is here.
I advise you in any case to use Prestashop's native object model to delete images to avoid problems :
$objImage = new Image($id_image)
$objImage->delete()
If the ps_image_shop table is aligned try enabling Prestashop's debug mode to see if you get any useful on-screen information about the error when adding new images.
I would also check the server's disk space (if you have many images/files, you might have run out of inodes).
Also consider checking the write permissions on /img/p (they might have changed if you ran your script from the command line and Prestashop can't save the new images).
Also, check that for some reason the auto-increment IDs in the various DB tables ps_image* haven't become misaligned.