mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-19 16:32:15 +00:00
added delete_failed_files into SchedulerService.php
This commit is contained in:
@@ -7,6 +7,8 @@ namespace App\Services;
|
||||
use App\Models\Share;
|
||||
use App\Models\Zip;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class SchedulerService
|
||||
{
|
||||
@@ -45,4 +47,38 @@ class SchedulerService
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and delete failed files older than 24 hours
|
||||
*/
|
||||
public function delete_failed_files(): void
|
||||
{
|
||||
$local_disk = Storage::disk('local');
|
||||
|
||||
// Get all files from storage
|
||||
$files = collect([
|
||||
//$local_disk->allFiles('files'),
|
||||
$local_disk->allFiles('chunks')
|
||||
])->collapse();
|
||||
|
||||
$files->each(function ($file) use ($local_disk) {
|
||||
|
||||
// Get the file's last modification time.
|
||||
$last_modified = $local_disk
|
||||
->lastModified($file);
|
||||
|
||||
// Get diffInHours
|
||||
$diff = Carbon::parse($last_modified)
|
||||
->diffInHours(Carbon::now());
|
||||
|
||||
// Delete if file is in local storage more than 24 hours
|
||||
if ($diff >= 24) {
|
||||
|
||||
Log::info("Failed file or chunk $file deleted.");
|
||||
|
||||
// Delete file from local storage
|
||||
$local_disk->delete($file);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user