jcergolj/filesystem-disk-cleanup-for-laravel

删除特定 Laravel 文件系统磁盘上的旧文件。

v1.0 2023-06-01 12:58 UTC

This package is auto-updated.

Last update: 2024-08-30 01:38:32 UTC


README

命令,可以计划删除指定时间之前的文件系统磁盘上的文件。

安装

    composer require jcergolj/filesystem-disk-cleanup-for-laravel

发布配置文件

    php artisan vendor:publish --provider="Jcergolj\FilesystemDiskCleanup\FilesystemDiskCleanupServiceProvider" --tag="config"

这是 config/filesystem-disk-cleanup.php 配置文件的内容

// filesystem-disk-cleanup.php
<?php

return [
    'disks' => [
        // jcergolj-test must match the name in filesystem.php disk config file
        'jcergolj-test' => [
            'delete_files_older_than_minutes' => 60 * 24 * 7,
        ],
    ],
];

以下是 config/filesystem.php 应该看起来像什么,其中已注册 jcergolj-test 磁盘。

// config/filesystem.php
<?php

return [
    'default' => env('FILESYSTEM_DISK', 'local'),

    'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
            'throw' => false,
        ],

        'jcergolj-test' [
            'driver' => 'local',
            'root' => storage_path('app/jceroglj-folder'),
            'throw' => false,
        ],

        // ...
    ],
];

这些命令可以像任何其他命令一样在 Laravel 的控制台内核中计划。

    // app/Console/Kernel.php
    $schedule->command('filesystem-disk:cleanup')->daily()->at('01:00');