Download the PHP package purplespider/silverstripe-asset-delete-if-unused-extension without Composer

On this page you can find all versions of the php package purplespider/silverstripe-asset-delete-if-unused-extension. 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 silverstripe-asset-delete-if-unused-extension

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?

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

  1. Install module via composer: `
  2. Perform a dev/build?flush=1:

  3. Make use of the new deleteIfUnused() method in your code: e.g. SlideshowSlide.php: `

How does it work out if an asset is/isn't 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?

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.


All versions of silverstripe-asset-delete-if-unused-extension with dependencies

PHP Build Version
Package Version
Requires silverstripe/cms Version ^4 || ^5
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 purplespider/silverstripe-asset-delete-if-unused-extension contains the following files

Loading the files please wait ....