I get pretty particular about things and thus it led me to stumble upon this nifty tool. Use it with caution and check the results, but it can help cleanup the M2 database after doing a migration. As usual, makes backups and make sure they work.
Cleans up database and images:
Magento 2 EAV Cleaner Console Command
Purpose of this project is to check for different flaws that can occur due to EAV and provide cleanup functions.
Use --dry-run to check result without modifying data.
eav:config:restore-use-default-valueCheck if config admin value and storeview value are the same, so “use default” doesn’t work anymore. Delete the storeview values.
eav:attributes:restore-use-default-valueCheck if product attribute admin value and storeview value are the same, so “use default” doesn’t work anymore. Delete the storeview values.
eav:attributes:remove-unusedRemove attributes with no values set in products and attributes that are not present in any attribute sets.
eav:media:remove-unusedRemove unused product images.
bin/magento in the Magento 2 root and look for the
Installation with composer:
composer require hackathon/magento2-eavcleaner
Then the usual magento cache clear, upgrade etc…
rm -rf var/cache/* var/page_cache/* generated/code/* && bin/magento setup:upgrade && bin/magento setup:di:compile && bin/magento setup:static-content:deploy -f && bin/magento indexer:reindex && bin/magento cache:clean && bin/magento cache:flush
- Nikita Zhavoronkova
- Anastasiia Sukhorukova
- Peter Jaap Blaakmeer
Special thanks to
- Benno Lippert
- Damian Luszczymak
- Joke Puts
- Ralf Siepker
I have used this and didn’t notice any ill effects. I did not use:
eav:attributes:remove-unused as there were only a few unused attributes in my installation and it wasn’t worth risking them being tied to something necessary. It is unlikely, but removing 5 unused attributes for me wasn’t going to make a difference.
I think I removed around 800MB in images from my previous installation. It may remove the watermark folder. I copied the outputs so I can view the results in its entirety, if necessary. Simply append > output.txt to your command and it will create a file with the output. If you append >>output.txt then you can append to your output file from the previous command. It is a handy feature as your terminal may not go back as far as needed to view all the outputs.
I copied all the media for a backup before running the image removal command.