Add console command to force recalculation of scores
This commit is contained in:
parent
86ec4f4062
commit
fd3855a775
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Actions\Tabulation;
|
||||
|
||||
use App\Models\Entry;
|
||||
|
||||
class ForceRecalculateTotalScores
|
||||
{
|
||||
public function __invoke(): void
|
||||
{
|
||||
$calculator = app(TotalEntryScores::class);
|
||||
foreach (Entry::all() as $entry) {
|
||||
$calculator($entry, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -78,8 +78,11 @@ class TotalEntryScores
|
|||
$newTotaledScore->advancement_subscore_totals = $total_advancement_subscores;
|
||||
|
||||
// pull in bonus scores
|
||||
$bonusScores = BonusScore::where('entry_id', $entry->id)->sum('score');
|
||||
$newTotaledScore->bonus_score = $bonusScores;
|
||||
$bonusScores = BonusScore::where('entry_id', $entry->id)
|
||||
->selectRaw('SUM(score) as total')
|
||||
->value('total');
|
||||
|
||||
$newTotaledScore->bonus_total = $bonusScores;
|
||||
|
||||
$newTotaledScore->save();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Actions\Tabulation\ForceRecalculateTotalScores;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class RecalculateScores extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'audition:recalculate-scores';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Forces the recalculation of total scores for all entries';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(ForceRecalculateTotalScores $action): void
|
||||
{
|
||||
$this->info('Starting score recalculation...');
|
||||
|
||||
$action();
|
||||
|
||||
$this->info('Score recalculation completed successfully.');
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue