31 lines
856 B
PHP
31 lines
856 B
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Poll;
|
|
use App\Polls\Ledger;
|
|
use Illuminate\Console\Command;
|
|
|
|
class SealClosedPolls extends Command
|
|
{
|
|
protected $signature = 'polls:seal';
|
|
|
|
protected $description = 'Seal the ballot ledger of polls that have closed (status closed or past their closing time)';
|
|
|
|
public function handle(Ledger $ledger): int
|
|
{
|
|
$polls = Poll::whereNull('sealed_at')
|
|
->where(fn ($query) => $query->where('status', Poll::STATUS_CLOSED)
|
|
->orWhere(fn ($q) => $q->where('status', Poll::STATUS_OPEN)->where('closes_at', '<=', now())))
|
|
->get();
|
|
|
|
foreach ($polls as $poll) {
|
|
if ($entry = $ledger->seal($poll)) {
|
|
$this->info("Sealed poll {$poll->id}: {$entry->hash}");
|
|
}
|
|
}
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|