mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 00:02:15 +00:00
- added it_delete_zips_older_than_one_day test
- refactored scheduler tasks into SchedulerService.php
This commit is contained in:
48
app/Services/SchedulerService.php
Normal file
48
app/Services/SchedulerService.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
use App\Models\Share;
|
||||
use App\Models\Zip;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class SchedulerService
|
||||
{
|
||||
/**
|
||||
* Delete old zips
|
||||
*/
|
||||
public function delete_old_zips(): void
|
||||
{
|
||||
Zip::where('created_at', '<=', Carbon::now()->subDay()->toDateTimeString())
|
||||
->get()
|
||||
->each(function ($zip) {
|
||||
|
||||
// Delete zip file
|
||||
\Storage::disk('local')->delete("zip/$zip->basename");
|
||||
|
||||
// Delete zip record
|
||||
$zip->delete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and delete expired shared links
|
||||
*/
|
||||
public function delete_expired_shared_links(): void
|
||||
{
|
||||
Share::whereNotNull('expire_in')
|
||||
->get()
|
||||
->each(function ($share) {
|
||||
|
||||
// Get dates
|
||||
$created_at = Carbon::parse($share->created_at);
|
||||
|
||||
// If time was over, then delete share record
|
||||
if ($created_at->diffInHours(Carbon::now()) >= $share->expire_in) {
|
||||
$share->delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user