mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-22 09:32:14 +00:00
- added it_delete_zips_older_than_one_day test
- refactored scheduler tasks into SchedulerService.php
This commit is contained in:
@@ -3,9 +3,7 @@
|
|||||||
namespace App\Console;
|
namespace App\Console;
|
||||||
|
|
||||||
use App\Console\Commands\SetupDevEnvironment;
|
use App\Console\Commands\SetupDevEnvironment;
|
||||||
use App\Share;
|
use App\Services\SchedulerService;
|
||||||
use App\Zip;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
|
|
||||||
@@ -28,12 +26,14 @@ class Kernel extends ConsoleKernel
|
|||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
$schedule->call(function () {
|
$scheduler = app()->make(SchedulerService::class);
|
||||||
$this->delete_expired_shared_links();
|
|
||||||
|
$schedule->call(function () use ($scheduler) {
|
||||||
|
$scheduler->delete_expired_shared_links();
|
||||||
})->everyMinute();
|
})->everyMinute();
|
||||||
|
|
||||||
$schedule->call(function () {
|
$schedule->call(function () use ($scheduler) {
|
||||||
$this->delete_old_zips();
|
$scheduler->delete_old_zips();
|
||||||
})->everySixHours();
|
})->everySixHours();
|
||||||
|
|
||||||
// Run queue jobs every minute
|
// Run queue jobs every minute
|
||||||
@@ -53,42 +53,4 @@ class Kernel extends ConsoleKernel
|
|||||||
|
|
||||||
require base_path('routes/console.php');
|
require base_path('routes/console.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete old zips
|
|
||||||
*/
|
|
||||||
protected function delete_old_zips(): void
|
|
||||||
{
|
|
||||||
// Get all zips
|
|
||||||
$zips = Zip::where('created_at', '<=', Carbon::now()->subDay()->toDateTimeString())->get();
|
|
||||||
|
|
||||||
$zips->each(function ($zip) {
|
|
||||||
|
|
||||||
// Delete zip file
|
|
||||||
\Storage::disk('local')->delete('zip/' . $zip->basename);
|
|
||||||
|
|
||||||
// Delete zip record
|
|
||||||
$zip->delete();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get and delete expired shared links
|
|
||||||
*/
|
|
||||||
protected function delete_expired_shared_links(): void
|
|
||||||
{
|
|
||||||
// Get all shares with expiration time
|
|
||||||
$shares = Share::whereNotNull('expire_in')->get();
|
|
||||||
|
|
||||||
$shares->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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,7 +50,9 @@
|
|||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"App\\": "app/"
|
"App\\": "app/",
|
||||||
|
"Database\\Factories\\": "database/factories/",
|
||||||
|
"Database\\Seeders\\": "database/seeders/"
|
||||||
},
|
},
|
||||||
"classmap": [
|
"classmap": [
|
||||||
"database/seeds",
|
"database/seeds",
|
||||||
|
|||||||
Reference in New Issue
Block a user