Fix broken suspension cleaner
This commit rewrites the previously broken auto ban cleaner. It's now much more efficient and compact, and it removes bans correctly and on the right date. Fixes #1
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Ban;
|
||||
use App\Services\AccountSuspensionService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@@ -34,8 +35,6 @@ class ProcessDueSuspensions implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $bans;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@@ -50,20 +49,10 @@ class ProcessDueSuspensions implements ShouldQueue
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(AccountSuspensionService $service)
|
||||
{
|
||||
Log::debug('Running automatic suspension cleaner...');
|
||||
$bans = Ban::all();
|
||||
Log::info('(suspension cleaner) Purging all expired suspension records.');
|
||||
|
||||
if (! is_null($bans)) {
|
||||
foreach ($this->bans as $ban) {
|
||||
$bannedUntil = Carbon::parse($ban->bannedUntil);
|
||||
|
||||
if ($bannedUntil->isToday()) {
|
||||
Log::debug('Lifted expired suspension ID '.$ban->id.' for '.$ban->user->name);
|
||||
$ban->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
$service->purgeExpired();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user