Skip to content

Commit 4471e0c

Browse files
committed
Use disk for purge
1 parent 3ae8fa9 commit 4471e0c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/Commands/DataTablesPurgeExportCommand.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Support\Facades\File;
7-
use Symfony\Component\Finder\SplFileInfo;
7+
use Illuminate\Support\Facades\Log;
8+
use Illuminate\Support\Facades\Storage;
9+
use Illuminate\Support\Str;
810

911
class DataTablesPurgeExportCommand extends Command
1012
{
@@ -29,13 +31,14 @@ class DataTablesPurgeExportCommand extends Command
2931
*/
3032
public function handle()
3133
{
32-
$exportPath = config('datatables-export.path', storage_path('app/exports'));
34+
$disk = config('datatables-export.disk', 'local');
3335
$timestamp = now()->subDay(config('datatables-export.purge.days'))->getTimestamp();
3436

35-
collect(File::allFiles($exportPath))
36-
->each(function (SplFileInfo $file) use ($timestamp) {
37-
if ($file->getMTime() < $timestamp && in_array(strtolower($file->getExtension()), ['xlsx', 'csv'])) {
38-
File::delete($file->getRealPath());
37+
collect(Storage::disk($disk)->files())
38+
->each(function ($file) use ($timestamp, $disk) {
39+
$path = Storage::disk($disk)->path($file);
40+
if (File::lastModified($path) < $timestamp && Str::endsWith(strtolower($file), ['xlsx', 'csv'])) {
41+
File::delete($path);
3942
}
4043
});
4144

0 commit comments

Comments
 (0)