PHPackages                             purplespider/silverstripe-asset-delete-if-unused-extension - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. purplespider/silverstripe-asset-delete-if-unused-extension

ActiveSilverstripe-vendormodule[File &amp; Storage](/categories/file-storage)

purplespider/silverstripe-asset-delete-if-unused-extension
==========================================================

Provides a deleteIfUnused() method to the File class

2.0.0(1y ago)04.1k↓19%11BSD-3-ClausePHP

Since Nov 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/purplespider/asset-delete-if-unused-extension)[ Packagist](https://packagist.org/packages/purplespider/silverstripe-asset-delete-if-unused-extension)[ Docs](http://github.com/purplespider/silverstripe-asset-delete-if-unused-extension)[ RSS](/packages/purplespider-silverstripe-asset-delete-if-unused-extension/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (4)Used By (1)

Delete Asset If Unused Extension for Silverstripe
=================================================

[](#delete-asset-if-unused-extension-for-silverstripe)

This Silverstripe module provides a new `deleteIfUnused()` method to `SilverStripe\Assets\File` objects, which when called will delete the File, but *only* if it isn't being used anywhere, e.g. by another `Page` or `DataObject`.

When would I want to use this?
==============================

[](#when-would-i-want-to-use-this)

Say you have a homepage slideshow, and each slide can have an image.

If a CMS user deletes a slide, it should also ideally delete any image that had been uploaded for that slide (to avoid orphaned images wasting disk space), but there is a risk that this image has been used elsewhere, e.g. perhaps a CMS user added the same image to a page via the WYSIWYG editor, or they selected the same image for another slide, without re-uploading it.

This module allows you to tell the image to be deleted (e.g. from your slide's `onAfterDelete` method), but *only* if it isn't associated with any other Pages or DataObjects.

If it is associted with another object, it won't get deleted, unless, of course, you go and delete the other object, at which point it *will* delete the image as it will no longer be associated with anything.

Installation
------------

[](#installation)

1. Install module via composer:

```
composer require purplespider/silverstripe-asset-delete-if-unused-extension "^2"

```

For SilverStripe 4 or 5 use version 1 of this module.

2. Perform a `dev/build?flush=1`:
3. Make use of the new `deleteIfUnused()` method in your code: e.g. `SlideshowSlide.php`:

```
protected function onAfterDelete()
{
    $this->MyImage()->deleteIfUnused();

    parent::onAfterDelete();
}

```

How does it work out if an asset is/isn't being used?
-----------------------------------------------------

[](#how-does-it-work-out-if-an-asset-isisnt-being-used)

It uses the existing `findAllRelatedData()` method, which is what populates the **Used on** tab in the Files section of the CMS.

It also excludes the same classes that the **Used on** tab does from counting the asset as "used", e.g. `ChangeSetItem`, `Member` `FileLink`, `Folder`.

Anything else I should be aware of?
-----------------------------------

[](#anything-else-i-should-be-aware-of)

Always keep backups! I provide no guarantee that this module won't delete used assets, it's up to you to test it fully in your desired scenareo.

Warning, if you use this on a site that has been upgraded from Silverstripe 3, it is likely that images in WYSIWIG fields don't have the `ImageID` attribute on the `img` tag, so it won't detect that the image is being used on that page, potentially resulting in a `used` image being deleted.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance47

Moderate activity, may be stable

Popularity24

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~633 days

Total

3

Last Release

391d ago

Major Versions

1.0.1 → 2.0.02025-04-22

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/329880?v=4)[James Cocker](/maintainers/purplespider)[@purplespider](https://github.com/purplespider)

---

Top Contributors

[![purplespider](https://avatars.githubusercontent.com/u/329880?v=4)](https://github.com/purplespider "purplespider (6 commits)")[![wernerkrauss](https://avatars.githubusercontent.com/u/1043925?v=4)](https://github.com/wernerkrauss "wernerkrauss (2 commits)")

---

Tags

silverstripeassets

### Embed Badge

![Health badge](/badges/purplespider-silverstripe-asset-delete-if-unused-extension/health.svg)

```
[![Health](https://phpackages.com/badges/purplespider-silverstripe-asset-delete-if-unused-extension/health.svg)](https://phpackages.com/packages/purplespider-silverstripe-asset-delete-if-unused-extension)
```

###  Alternatives

[unclecheese/silverstripe-kickassets

Provides an alternative file management interface for SilverStripe CMS with drag-and-drop, multi-selection, and several other desktop-like UI conventions.

4728.3k1](/packages/unclecheese-silverstripe-kickassets)[unclecheese/kickassets

Provides an alternative file management interface for SilverStripe CMS with drag-and-drop, multi-selection, and several other desktop-like UI conventions.

464.0k](/packages/unclecheese-kickassets)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
