Download the PHP package yannkost/craft-asset-cleaner without Composer

On this page you can find all versions of the php package yannkost/craft-asset-cleaner. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package craft-asset-cleaner

Asset Cleaner for Craft CMS

Identify and clean up unused assets in Craft CMS 5.

Features

Requirements

Installation

Via Composer

Manual / local path repository

  1. Copy the plugin to your plugins/ directory, for example to plugins/asset-cleaner
  2. Add a path repository to your project's composer.json:

  3. Require the package and install the plugin:

Usage

Control Panel

  1. Navigate to Utilities → Asset Cleaner
  2. Select the volumes you want to scan
  3. Choose whether to Include drafts in this scan and/or Include revisions in this scan
  4. Choose whether to Count all relational references as usage
  5. Click Scan Now
  6. Wait for the background scan to complete
  7. Review the results grouped by volume, showing:
    • Number of unused assets per volume
    • Total file size per volume
  8. Use bulk actions (global or per-volume):
    • Download CSV - Export a list of unused assets
    • Download ZIP - Download unused assets, optionally preserving folder structure
    • Put into Trash - Soft delete assets
    • Delete Permanently - Permanently remove assets with confirmation

The draft and revision toggles on the utility page override the plugin's default draft/revision handling settings for that individual scan. The relational fallback checkbox is scan-specific and is enabled by default for safer cleanup scans.

Scan stages

The utility page shows progress while the scan moves through these stages:

  1. Preparing asset snapshot - Builds the stored snapshot of assets in scope
  2. Scanning relations - Collects asset usage from Craft's relations table
  3. Scanning content - Scans relevant rich text fields and globals in batches
  4. Finalizing results - Merges usage data and writes the final unused asset results

ZIP Download Options

When downloading a ZIP file, you can choose:

Smart Filenames

Exported files include meaningful names with timestamps:

View Usage Button

On any asset edit page, click the View Usage button to see:

CLI Commands

How It Works

The plugin identifies unused assets by performing several checks across your Craft CMS site:

  1. Relations Table - Asset field references stored in Craft's relations table
  2. Content Fields - Scans Redactor and CKEditor fields for embedded asset references
  3. Global Sets - Checks supported global set content fields for asset references
  4. Nested Entries - Resolves nested entries to top-level entries for usage reporting

For large scans, the plugin uses a staged pipeline:

  1. Snapshot assets in scope into the active scan storage backend
  2. Build usage sets once from relations and content instead of rescanning all content for every asset
  3. Process entries in batches rather than loading the full content dataset into memory
  4. Persist final unused results so completed scans can be restored and exported

The matching strategy prefers stronger signals first:

The plugin can store transient scan state either on disk or in dedicated database tables, depending on your installation requirements.

Technical Details

Scan storage modes

Asset Cleaner supports two scan storage modes:

File-based storage

By default, scans are stored in a file-backed workspace under:

You can override the workspace base path with either:

Example plugin config:

Typical file-based scan artifacts include:

File-based storage is a good default on single-server installs or setups where web and queue workers share the same filesystem path.

Database-based storage

Database-based storage keeps scan state, asset snapshots, used asset IDs, and final results in dedicated database tables instead of the filesystem.

This mode is recommended for:

You can switch between file-based and database-based storage in the plugin settings, and config file values can override those settings when needed.

Draft and revision handling

Asset Cleaner lets you control whether assets referenced only in drafts or only in revisions should count as used.

There are three levels of control:

Example config override:

By default, draft-only and revision-only usage are excluded unless you enable them.

Relational fallback

Scans also provide a Count all relational references as usage checkbox.

When this option is enabled, any asset with a row in Craft’s relations table is treated as used. This is the safest mode for projects that rely on plugin-defined or unknown element types that may store asset relations outside normal entry content.

When this option is disabled, Asset Cleaner uses stricter relation resolution rules to identify more potentially unused assets, but that can undercount legitimate backend-only usage from third-party element types.

Scan performance tuning

The relation stage of a scan runs in resumable queue batches, and two settings control its footprint. Both are available in the plugin settings, and can be overridden via config or environment variables:

Note that the effective relation batch size is max(assetChunkSize, relationBatchSize) - the scan never loads fewer assets per relation batch than its asset chunk size, so very low relationBatchSize values are clamped up to the chunk size.

Example config:

Bulk relation resolution

Relation sources are resolved in bulk with set-based queries, which reduces scan queries by orders of magnitude on relation-heavy sites. If you suspect it misbehaves on your install, you can fall back to the original per-source resolution path with:

You can verify on your own install that both paths reach identical verdicts with:

The command compares bulk and per-source verdicts over sampled assets in both relation-counting modes and reports any mismatch.

Memory-efficient ZIP creation

ZIP exports are built in a memory-friendly way:

Permissions

The Asset Cleaner utility requires the utility:asset-cleaner permission. Assign this permission to user groups that should have access to the utility.

License

The Craft License. See LICENSE.md for details.

Support

Changelog

1.5.1

Fixed database scan storage setup for fresh installations and upgrades. New installations now create all scan storage tables, and an upgrade migration repairs missing tables while preserving existing tables and scan data. Apply Craft's pending migrations after updating.

See CHANGELOG.md for the full release history.


All versions of craft-asset-cleaner with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
craftcms/cms Version ^5.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package yannkost/craft-asset-cleaner contains the following files

Loading the files please wait ...