File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change 44
55use Illuminate \Console \Command ;
66use 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
911class 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
You can’t perform that action at this time.
0 commit comments