purplespider/silverstripe-asset-delete-if-unused-extension
Composer 安装命令:
composer require purplespider/silverstripe-asset-delete-if-unused-extension
包简介
Provides a deleteIfUnused() method to the File class
关键字:
README 文档
README
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
- 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.
-
Perform a
dev/build?flush=1: -
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?
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.
purplespider/silverstripe-asset-delete-if-unused-extension 适用场景与选型建议
purplespider/silverstripe-asset-delete-if-unused-extension 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.45k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 11 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「assets」 「silverstripe」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 purplespider/silverstripe-asset-delete-if-unused-extension 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 purplespider/silverstripe-asset-delete-if-unused-extension 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 purplespider/silverstripe-asset-delete-if-unused-extension 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Asset Management for PHP
Caching and compression for Twig assets (JavaScript and CSS).
Analytics chooser extensions for site settings.
Tool for loading or deploying CSS and JS files into web pages
CitaNZ's SilverStripe picture object and field for SilverStripe 4
统计信息
- 总下载量: 4.45k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2021-11-04