masterro/laravel-file-cleaner 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

masterro/laravel-file-cleaner

Composer 安装命令:

composer require masterro/laravel-file-cleaner

包简介

Laravel console command for deleting temp files and associated model instances.

README 文档

README

Latest Stable Version Total Downloads Build Status License

StandWithUkraine

File Cleaner for Laravel

File Cleaner is a package for Laravel 5+ that provides deleting files and associated model instances.

Installation

Step 1: Composer

From the command line, run:

composer require masterro/laravel-file-cleaner

Step 2: Service Provider (For Laravel < 5.5)

For your Laravel app, open config/app.php and, within the providers array, append:

MasterRO\LaravelFileCleaner\FileCleanerServiceProvider::class

This will bootstrap the package into Laravel.

Step 3: Publish Configs

First from the command line, run:

php artisan vendor:publish --provider="MasterRO\LaravelFileCleaner\FileCleanerServiceProvider"

After that you will see file-cleaner.php file in config directory

For this package you may set such configurations:

  • paths - Paths where temp files are storing (or will be storing), relative to root directory
  • excluded_paths - Excluded directory paths where nothing would be deleted, relative to root directory
  • excluded_files - Excluded files path that would not be deleted, relative to root directory
  • time_before_remove - Time after which the files will be deleted | default 60 minutes
  • model - Model which instances will be deleted with associated files | optional
  • file_field_name - Field name that contains the name of the removing file | optional, only if model set
  • remove_directories - Remove directories flag, if set to true all nested directories would be removed | default true
  • relation - Relation, remove files and model instances only if model instance does not have a set relation

Voter callback

Additionally, you can set a static voter callback or invokable object to have more power on controlling deletion logic.
You can register it in one of yours Service providers. The callback will be called after time_before_remove and excluded_* checks.

FileCleaner::voteDeleteUsing(function($path, $entity) {
    if (isset($entity) && !$entity->user->isActive()) {
        return true;
    }

    return false;
});

If callback return true file and optionally associated record in db will be removed.
If callback return false file and record won't be removed.
Otherwise relation check will be performed.

Usage

Scheduling

Add new command call to schedule function:

Have a look at Laravel's task scheduling documentation, if you need any help.

protected function schedule(Schedule $schedule)
{
    $schedule->command('file-cleaner:clean')->everyMinute();
}

And that's all. If your cron set up everything will work.

Manual, using artisan console

You can run deleting manually, just run from the command line:

php artisan file-cleaner:clean

And see the output.

Or if you want to delete files without checking time (just delete all files from all set directories) use the --force flag (or -f shortcut):

php artisan file-cleaner:clean -f

You can even override config directories paths, excluded_paths and excluded_files values with --directories, --excluded-paths and --excluded-files options (separate by comma):

php artisan file-cleaner:clean -f --directories=storage/temp/images,public/uploads/test
php artisan file-cleaner:clean -f --excluded-paths=public/uploads/images/default,public/uploads/test
php artisan file-cleaner:clean -f --excluded-files=public/uploads/images/default.png,public/uploads/test/01.png

Also you can even override remove_directories config value with --remove-directories option:

php artisan file-cleaner:clean -f --directories=storage/temp/images,public/uploads/test --remove-directories=false

I will be grateful if you star this project :)

masterro/laravel-file-cleaner 适用场景与选型建议

masterro/laravel-file-cleaner 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.08k 次下载、GitHub Stars 达 19, 最近一次更新时间为 2016 年 04 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「files」 「laravel」 「delete」 「clean」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 masterro/laravel-file-cleaner 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 masterro/laravel-file-cleaner 我们能提供哪些服务?
定制开发 / 二次开发

基于 masterro/laravel-file-cleaner 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 19
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 19
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-04