Added a scheduled task for cleaning up database sessions
This commit is contained in:
43
src/Scheduler/Tasks/CleanupSessions.php
Normal file
43
src/Scheduler/Tasks/CleanupSessions.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* AVSDev UF Tweaks (https://avsdev.uk)
|
||||||
|
*
|
||||||
|
* @link https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks
|
||||||
|
* @license https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks/blob/master/LICENSE.md (LGPL-3.0 License)
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace UserFrosting\Sprinkle\UFTweaks\Scheduler\Tasks;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
|
use UserFrosting\Sprinkle\Scheduler\Scheduler\BaseTask;
|
||||||
|
use UserFrosting\Sprinkle\Core\Database\Models\Session;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Daily task to clean expired sessions from the database
|
||||||
|
*
|
||||||
|
* @author Craig Williams (https://avsdev.uk)
|
||||||
|
*/
|
||||||
|
class CleanupSessions extends BaseTask
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Function used to specify the schedule for the task.
|
||||||
|
*/
|
||||||
|
public function schedule()
|
||||||
|
{
|
||||||
|
$this->daily()->at("23:00");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function used to specify what the task does.
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
// Remove sessions over 2 days old
|
||||||
|
Session::where('last_activity', '<', time()-(60*60*48))->delete();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user