So... I believe I have figured out the problem that causes the "image bloat", whereby the image files for deleted products are not ALSO being deleted.
It's so astoundingly simple, that I wish I had tried to find and fix the problem sooner.
Based on my old 4.07 version of ISC... here's what I found:
In "admin/classes/class.product.php" locate "public function DoDeleteProducts($ids)" --- This is the function that is supposed to deleted products from the database and any associated image files and downloadable files.
Within this function, scroll down until you locate:
Code: Select all
while($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
@unlink(APP_ROOT."/../".GetConfig('ImageDirectory')."/".$row['imagefile']);
}
In any case, I wanted to see exactly what was going on, so for testing purposes, I added the following bit of debugging code inside the "while" loop.
Code: Select all
while($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
@unlink(APP_ROOT."/../".GetConfig('ImageDirectory')."/".$row['imagefile']);
echo APP_ROOT."/../".GetConfig('ImageDirectory')."/".$row['imagefile'] . "<br/>"; // TEMP DEBUG STATEMENT
}
WHAT A MESS!! THERE'S F*CKING THE PROBLEM!! It's looking in the WRONG PLACE when trying to delete product images... AND any error messages are being suppressed with the "@" prefix./home/myaccount/public_html/store/admin/../product_images/y/mainImage.jpg
/home/myaccount/public_html/store/admin/../product_images/c/additionalImage1.jpg
/home/myaccount/public_html/store/admin/../product_images/t/additionalImage2.jpg
/home/myaccount/public_html/store/admin/../product_images/p/additionalImage3.jpg
/home/myaccount/public_html/store/admin/../product_images/p/mainImage_tiny.jpg
Let's try again... change the "while" loop to be:
Code: Select all
while($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
// Notes: Original ISC code used the wrong location. Corrected code follows.
//@unlink(APP_ROOT."/../".GetConfig('ImageDirectory')."/".$row['imagefile']);
unlink(ISC_BASE_PATH."/".GetConfig('ImageDirectory')."/".$row['imagefile']); // CORRECTED UNLINK PATH
echo ISC_BASE_PATH."/".GetConfig('ImageDirectory')."/".$row['imagefile'] . "<br/>"; // TEMP DEBUG STATEMENT
}
Very nice... the "unlink" command is pointed at the CORRECT location of the files... and they are NOW DELETED as they are supposed to be./home/myaccount/public_html/store/product_images/s/mainImage.jpg
/home/myaccount/public_html/store/product_images/f/additionalImage1.jpg
/home/myaccount/public_html/store/product_images/o/additionalImage2.jpg
/home/myaccount/public_html/store/product_images/k/additionalImage3.jpg
/home/myaccount/public_html/store/product_images/m/mainImage_tiny.jpg
After I confirmed that all was performing as intended, I deleted the echo command ("TEMP DEBUG STATEMENT") and re-uploaded, then tested again.
FINAL NOTES: Elsewhere in this script, the erroneous "@unlink(APP_ROOT..." statement appears MULTIPLE TIMES (ie: deleting product downloads, deleting variation images, etc.) ~~ They ALL need to be changed to be "unlink(ISC_BASE_PATH..."
MORE NOTES: These changes were made to an earlier version of ISC. More recent versions may have been fixed already (doubtful) or the current code may vary from the examples I've indicated here (probably).
AS ALWAYS: Take normal precautions. Review changes carefully. Leave comments in your php code so you'll know what you changed. Comment-out the original code instead of deleting it (so that you can easily restore it if needed). Keep backups of your original php and your database in case something goes wrong. Test before going live.
DID YOU SPOT ANY ERRORS? ...
ANY CORRECTIONS? ...
ANY IMPROVEMENTS? ...
Please post them here!