-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duplicating product copies product images couple of hundred times #9466
Comments
I am also experiencing this - but to a somewhat different level. This means that duplicating just a couple of products can create 100000s images. We are using Magento 2.1.15, PHP 7.0.18, mysql 5.0.12 , Apache/2.4.6, varnish Unfortunately because the products are not duplicated often, we don't know when this bug was introduced. We suspect it is something to do with products that were imported using the migration tool from 1.9 as the error does not seem to happen with products added to the catalog after the data migration |
Magento ver. 2.1.5 BUG "multiple image generation on product copy". this is down to a particularly bad piect of code in vendor\magento\module-catalog\Model\Product\Copier.php that loops infinately is the save fails due to an AlreadyExistsException. unfortunately data issues in the url rewrite table can cause this failure and as Magento devs failed to put in place a decent cleanup process to remove immages on save fail you get an ever increasing set untill php times out. public function copy(\Magento\Catalog\Model\Product $product) luckily there is code in vendor\magento\module-catalog-url-rewrite\observer\ProductProcessUrlRewriteSavingObserver.php that is a life saver public function execute(\Magento\Framework\Event\Observer $observer) so by inserting $duplicate->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE); into the object being saved the url rewrites will not be generated and the duplicate will save without the multiple image loop (though multiples will still occur if its been copied n times previously but only n copies) magento devs really need to sort this out, relying on the save excepting rather than first looking up a free rewrite is an error, The code should lookup a free url against the url_key attribute values in catalog_product_entity_varchar first then attempt the save once only and throw the exception if it fails, PLEASE stop putting empty catch staements in loops !!! my quick fix to correct this error is to insert $duplicate->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE); in the core copy function which then reads:- public function copy(\Magento\Catalog\Model\Product $product)
you will also note from the origional Magento code that if your URL keys / Sku convention is latter half numeric with a - in to ie AAAAA-00001 then prepare for a long wait on product copies or change the - in the logic to an _ if you dont use _ in your standard url keys. |
I think this is the same issue as #4096. |
Closed as a duplicate of #4096 |
As far as I can see this isn't a duplicate of #4096. When looking at the behaviour of #4096 there are some different things going on than in this issue. When duplicating a product on this issue the page doesn't go in a loop to reload the product page. Also, with this issue the website doesn't become unavailable. The website itself is still working, only the disk space of the server is filling up with duplicate product images. |
Confirmed this is still an issue on 2.1.8 for migrated products. The "setVisibility" fix from JasonScottM did work. |
Is there any way to safely and reliably delete all duplicates for all products? Thanks |
If you are asking is there a way to delete all unused duplicate images?
then yes, attached is a script I put together for that task,
if your database has a prefix set you may need to change the table name.
run the script and if you are happy the red results shown are the ones to delete,
uncomment the 2 unlink lines are re-run.
To be sure you can recover, I suggest backing up the pub/media/catalog
Folder first.
From: Valerio Versace [mailto:notifications@github.com]
Sent: 14 September 2017 17:45
To: magento/magento2 <magento2@noreply.github.com>
Cc: JasonScottM <jason.mummery@micommerce.com>; Comment <comment@noreply.github.com>
Subject: Re: [magento/magento2] Duplicating product copies product images couple of hundred times (#9466)
Is there any way to safely and reliably delete all duplicates for all products? Thanks
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#9466 (comment)> , or mute the thread <https://github.com/notifications/unsubscribe-auth/AOY7R-jzSKtkE6I3vx29lKr-IVYmZcC3ks5siVgVgaJpZM4NNQ8J> . <https://github.com/notifications/beacon/AOY7R2kofUTbkZwpqO_eqlJn38NFrGXmks5siVgVgaJpZM4NNQ8J.gif>
|
God damned, we just ran into this today on a Magento 2.1.9 installation. 12 GB of diskspace eaten away in a 40 minutes by duplicating some products until our server crashed with no space left. Would be great if this got fixed! |
@magento-engcom-team: can this ticket get re-opened? It has the label |
So the exact steps to reproduce are outlined below, because following the steps from @qbixx on a clean installation isn't going to trigger the problem: Steps to reproduce
... Expected resultAfter every duplication, only one new image file is being created Further discoveriesIt no longer seems to be reproducible in Magento 2.2.0 And I agree with @JasonScottM:
Trying to save a model and try to save it multiple times in a loop until an exception no longer is being thrown is a really bad idea. |
@JasonScottM - where is the script???? |
Hi Robert
I think that was stripped in my previous response
so please use this link http://www.keepandshare.com/doc18/view.php?id=16316 <http://www.keepandshare.com/doc18/view.php?id=16316&da=y> &da=y
Jason.
|
@JasonScottM - the link you provided requires login. |
The link should work now.
|
For other devs passing by, on the other related issue, a Magento CLI module has been developed in order to remove duplicated product media. |
we get this exception Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException |
http://www.autotechbook.com/magento-2-2-4-duplicate-product-image-issue/ |
Hi @engcom-backlog-nazar I'm re-opening this issue, since it hasn't been fixed in Although the worst issue is probably fixed by 50592b4, I can still reproduce this issue with the steps from my earlier report: #9466 (comment) This is still caused by that do while loop which tries to find a unique url key for a duplicated product by trying to save that product on and on until it finally finds a unique url key. You can very easily see this happening by adding something like this and monitoring the diff --git a/app/code/Magento/Catalog/Model/Product/Copier.php b/app/code/Magento/Catalog/Model/Product/Copier.php
index ce6b4d98bbc..357b5e510fb 100644
--- a/app/code/Magento/Catalog/Model/Product/Copier.php
+++ b/app/code/Magento/Catalog/Model/Product/Copier.php
@@ -82,6 +82,9 @@ class Copier
$urlKey = preg_match('/(.*)-(\d+)$/', $urlKey, $matches)
? $matches[1] . '-' . ($matches[2] + 1)
: $urlKey . '-1';
+
+ \Magento\Framework\App\ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class)->critical($urlKey);
+
$duplicate->setUrlKey($urlKey);
$duplicate->setData(Product::URL_PATH, null);
try { In my case, I had a product with the url key 'simple'. After duplicating that product 4 times, and then trying to duplicate it a few times more, this was the output:
And a whole bunch of extra images got created on the filesystem, even though I only needed 1 extra image per time I duplicated the product. |
Hi @hostep thanks for clear description of the issue, this issue still present on 2.2 and 2.3 branches. |
I was affected by this issue , the team depends on duplicate action , they filled up a disk of 440G completely with images cleaning up the extra images was very hard to do , the only way I've found is : I had to remember the items they duplicated and delete their images from disk you may need to delete them from I'm sharing my solution here to help the others , hopefully I could save someone's time |
@tawfekov |
@wget these won't work out for me since I had custom module generating custom images that aren't saved in media tables Thanks for willing to help 😀 P.s n98 has a similar addon that can clean it up too https://github.com/magento-hackathon/EAVCleaner#eav-cleaner-magerun-addon |
@tawfekov Didn't know this was also impacting custom modules; I only though |
Just ran into this. Is 50592b4 the best solution, or should it actually regenerate the url_path alongside the url_key? I was thinking load in |
@chickenland: The |
Ran into this on M2.2.6, @hostep is right: it happens with migrated M1 products that have url_path filled. I did a query for a test product: SELECT * FROM catalog_product_entity_varchar WHERE attribute_id IN ( SELECT attribute_id FROM eav_attribute WHERE attribute_code IN ('url_path') AND entity_type_id = 4 ) AND entity_id = 8 where my product id is 8 and found that it was filled. Emptied the url_path for this product and it duplicates fine without the hundreds of copied images as before. So time for a simple plugin that empties the url_path before duplicate is called. Thank you @hostep for pointing me in the right direction. |
For those that need a solution for products migrated from M1 that cannot be duplicated in M2 due to this bug, make your own module with an etc\di.xml and add these lines:
Create a Plugin folder and add the file with the following content:
Clear cache and di:compile and test. |
I followed the code when I save a product and it executes That function have a method called Simply replacing this line See completely function code here:
Function that adds _XX.jpg to images and duplicating them:
It works for me on Magento 2.1.8 💃 ! |
So after 2 years this is still an issue. A client of mine just got wrecked by this. What a joke. |
Hi @qbixx. Thank you for your report.
The fix will be available with the upcoming 2.4.0 release. |
i think this issue still there, we are move magento 1 to magento 2.3.4, we i am try to duplicate, its take too much time, finally request crashed but when i login back duplicate product created , log error see below..[2020-06-13 13:12:11] main.CRITICAL: We couldn't copy file catalog/product/b/a/bana-02_1.jpg. Please delete media with non-existing images and try again. {"exception":"[object] (Magento\Framework\Exception\LocalizedException(code: 0): We couldn't copy file catalog/product/b/a/bana-02_1.jpg. Please delete media with non-existing images and try again. at /data/web/magento2_staging/vendor/magento/module-catalog/Model/Product/Gallery/CreateHandler.php:473)"} [] |
Need Urgent Help, magento setup version is 2.3.4[upgraded m1], we have "29542 records found" products, i am facing duplicate product issue, try to fix using available patch but its not fix. Today i remove all products images in test environment, there no image for a single product, now i add product image for a single product, i save it, working cool, but when i try to do duplicate this product, its again went into infinite loop, within few mints it create huge[4.3GB] garbage of that image that recently add. now i am helpless. |
🙀🤯! Can anyone confirm if https://github.com/ThomasNegeli/M2CliTools works on magneto 2.3x? |
When duplicating a product to create a similar product all the required information is copied over. This also includes the product images. However when saving the new (duplicated) product, it takes quite a long time before the product get's saved. This is because the attached images are copied a few hundred times on the server.
The amount of copies is not always the same but ranges from about 200 to 2000 copies. The copies are all in the same folder that the original images resides and will have a format of e.g. [image]_100.jpg.
Preconditions
I've tested this both on Magento 2.1.4 and 2.1.6.
PHP 7.0.18 and MariaDB 10.1.22
Steps to reproduce
Expected result
The image(s) on the duplicated product should be copied once.
Actual result
The image(s) on the duplicated product are copied multiple times.
The text was updated successfully, but these errors were encountered: