tnegeli / m2clitools

tnegeli/m2clitools

Some nice commands to cleanup media files and tables on production systems

magento2-module Compatibility: 2.4.7-2.4.9 Code Quality: Fail Tests: N/A Security: Pass MIT

Are you the maintainer of tnegeli?

Packagento pulls tnegeli's Composer packages from the public registry so buyers can find them here.

Claim the namespace to take ownership, publish new releases directly, and start charging for premium versions.

Claim this namespace →

CLI Tools for Magento 2

Various CLI Tools for Magento 2

Available commands:

php bin/magento tnegeli:cleanup-unused-product-media

Use this command to backup (or delete) unused product media from filesystem.

You can use the --dry-run option to just test the result.

You can use the --delete option to remove files, instead of doing a backup.

php bin/magento tnegeli:cleanup-unused-category-media

Use this command to backup (or delete) unused category media from filesystem.

You can use the --dry-run option to just test the result.

You can use the --delete option to remove files, instead of doing a backup.

php bin/magento tnegeli:cleanup-unused-swatches-media

Use this command to backup (or delete) unused swatches media from filesystem.

You can use the --dry-run option to just test the result.

You can use the --delete option to remove files, instead of doing a backup.

php bin/magento tnegeli:cleanup-illegal-product-media

Use this command to identify and remove illegal entries in the media gallery database table, which might break catalog:
images:resize process.

You can use the --dry-run option to just test the result and give you a list of value_id entries from the media gallery
table which are illegal.

php bin/magento tnegeli:cleanup-illegal-product-media-non-existing-files

Use this command to identify and remove illegal entries in the media gallery database table that have no files on the
filesystem, which might break catalog:images:resize process.

You can use the --dry-run option to just test the result and give you a list of value_id entries from the media gallery
table which are illegal.

php bin/magento tnegeli:cleanup-illegal-product-image-markers-non-existing-files

Each product is checked for the attribute values of

  • image
  • small_image
  • thumbnail

If a product references a file that does not exist, the reference is removed.

You can use the --dry-run option to just test your database.

Safety checks

The commands tnegeli:cleanup-illegal-product-media-non-existing-files and
tnegeli:cleanup-illegal-product-image-markers-non-existing-files abort if the product media directory does not exist,
or if not a single referenced file exists. Both usually mean the media files are missing (e.g. an unmounted media
directory), not that the database entries are illegal. Use the --force option to remove the entries anyway.

Output verbosity

All commands print one line per affected file or database entry, plus a summary. More details are available via the
standard verbosity options:

  • -v: additionally list the image markers that are kept (image markers command)
  • -vv: additionally list every checked file
  • -vvv: additionally list every media value read from the database

Changelog

2.0.0

Breaking changes

  • Requires PHP 8.2 or newer and Magento 2.4.7 or newer.
  • Commands exit with code 1 if files could not be removed or a safety check aborts the run.
  • tnegeli:cleanup-illegal-product-media-non-existing-files and
    tnegeli:cleanup-illegal-product-image-markers-non-existing-files abort if the product media directory does not
    exist, or if not a single referenced file exists. Use the new --force option to remove the entries anyway.
  • Output is written line by line instead of a table and full array dumps. Details are available via -v, -vv
    and -vvv.

Added

  • --force option for the commands listed above.
  • Support for table prefixes.

Fixed

  • tnegeli:cleanup-unused-category-media treated almost all category images as unused, because newer Magento
    versions store the image path as /media/catalog/category/<file>.
  • tnegeli:cleanup-unused-swatches-media crashed with "Area code is not set" as soon as swatch files existed, and
    crashed on output because the removed table helper was used.
  • tnegeli:cleanup-unused-swatches-media listed the thumbnail instead of the swatch image variant.
  • Commands for unused media crashed if the media directory does not exist.
  • A failing file removal no longer aborts the whole run. The error is reported and the run continues.
  • tnegeli:cleanup-illegal-product-media-non-existing-files deletes in chunks of 50 entries.
  • Large amounts of media files no longer slow down the usage check or exhaust memory with output.
  • Declared the dependencies on Magento_Catalog, Magento_Indexer and Magento_Swatches.
Versions
Version Stability QA Status Compatibility Released
2.0.0 stable Fail Magento 2.4.7-2.4.9 Details 2026-11-02 16:23:20
1.5.5 stable Fail Not yet tested Details 2025-11-07 10:55:27
1.5.4 stable Not tested Not yet tested Details 2025-11-07 10:34:15
1.5.3 stable Not tested Not yet tested Details 2023-08-28 08:00:02
1.5.2 stable Not tested Not yet tested Details 2020-09-16 12:27:53
1.5.0 stable Not tested Not yet tested Details 2020-08-27 10:18:08
1.4.2 stable Not tested Not yet tested Details 2020-06-04 05:38:57
1.4.1 stable Not tested Not yet tested Details 2019-06-05 14:08:28
1.4.0 stable Not tested Not yet tested Details 2019-06-05 13:24:52
1.3.0 stable Not tested Not yet tested Details 2019-05-24 10:07:34
1.2.3 stable Not tested Not yet tested Details 2017-08-02 09:37:14
1.2.2 stable Not tested Not yet tested Details 2017-07-18 12:38:02
1.2.1 stable Not tested Not yet tested Details 2017-07-18 12:26:56
1.2.0 stable Not tested Not yet tested Details 2017-07-18 12:18:05
1.1.0 stable Not tested Not yet tested Details 2017-07-14 06:12:56
1.0.0 stable Not tested Not yet tested Details 2017-07-12 14:15:01

Requires 5

Package Constraint
magento/framework ^103.0.7
magento/module-catalog ^104.0.7
magento/module-indexer ^100.4.7
magento/module-swatches ^100.4.7
php ~8.2.0||~8.3.0||~8.4.0||~8.5.0

Compatibility

Each Magento release line is installed on its supported PHP versions, then the module is built (DI compilation + static-content deploy) and its unit and integration suites are run. The matrix shows the lines and PHP versions the module is confirmed to install and run on. Code-quality results further down (phpstan, phpcs, …) are reported separately and never affect compatibility.

Compatibility matrix (Magento × PHP)
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Pass Pass
2.4.8 Pass Pass
2.4.9 Pass Pass

Code Quality

Advisory checks against the module's source. Static analysis runs once across the whole module; PHPStan re-runs per Magento + PHP version because resolvable symbols differ between releases. These NEVER affect the Compatibility badge. A phpcs finding can't make a module incompatible.

Static analysis

Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.

Static analysis results
Tool Status Findings Summary
PHPCS Fail 134 2 errors, 132 warnings (ruleset: Magento2), 31 auto-fixable with phpcbf
PHPMD Warning 12 12 rule violations (CyclomaticComplexity:5, NPathComplexity:5, UnusedFormalParameter:1, ExcessiveMethodLength:1)
Cpd Warning 5 5 duplicated chunks spanning 146 total lines (min-lines=5, min-tokens=70)
Composer validate Pass 0

PHPStan

Type-checks the module's PHP against a real Magento install at the configured gate level. Re-runs per Magento and PHP version because resolvable symbols differ between releases.

PHPStan results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 Error Error
2.4.8 10 10
2.4.9 10 10

Tests

Unit and integration suites, run for each applicable Magento and PHP version. A test failure speaks to the module's behaviour, not its compatibility with a Magento line, so it is reported here separately and never reddens the compatibility matrix.

Unit tests

Unit tests results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 N/A N/A
2.4.8 N/A N/A
2.4.9 N/A N/A

Integration tests

Integration tests results by Magento and PHP version
Magento PHP 8.2 PHP 8.3 PHP 8.4 PHP 8.5
2.4.7 N/A N/A
2.4.8 N/A N/A
2.4.9 N/A N/A

Security

Security checks run directly against the module: an audit of its declared dependencies for known vulnerabilities (composer audit) and a scan of its source for malware and web-shell signatures. Each runs once. A malware detection fails the version outright.

Security results
Tool Status Findings Summary
Composer audit Pass 0
Malware scan Pass 0
License
MIT
Make it pay

Turn an existing module into recurring revenue.

If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.