Create year end cleanup action
This commit is contained in:
parent
92c8de0cf2
commit
3a9f5ab123
|
|
@ -0,0 +1,76 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\YearEndProcedures;
|
||||||
|
|
||||||
|
use App\Exceptions\AuditionAdminException;
|
||||||
|
use App\Models\AuditionFlag;
|
||||||
|
use App\Models\AuditLogEntry;
|
||||||
|
use App\Models\BonusScore;
|
||||||
|
use App\Models\CalculatedScore;
|
||||||
|
use App\Models\DoublerRequest;
|
||||||
|
use App\Models\EntryFlag;
|
||||||
|
use App\Models\JudgeAdvancementVote;
|
||||||
|
use App\Models\NominationEnsembleEntry;
|
||||||
|
use App\Models\ScoreSheet;
|
||||||
|
use App\Models\Seat;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
use function auth;
|
||||||
|
|
||||||
|
class YearEndCleanup
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __invoke(): void
|
||||||
|
{
|
||||||
|
$this->cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $options array array of reset options - possible values are deleteRooms
|
||||||
|
* removeAuditionsFromRoom unassignJudges
|
||||||
|
|
||||||
|
*
|
||||||
|
* @throws AuditionAdminException
|
||||||
|
*/
|
||||||
|
public function cleanup($options = []): true
|
||||||
|
{
|
||||||
|
if (! auth()->user() or ! auth()->user()->is_admin) {
|
||||||
|
throw new AuditionAdminException('Only administrators may perform this action');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete all records in the audit_log_entries table
|
||||||
|
AuditLogEntry::truncate();
|
||||||
|
AuditionFlag::truncate();
|
||||||
|
BonusScore::truncate();
|
||||||
|
CalculatedScore::truncate();
|
||||||
|
DoublerRequest::truncate();
|
||||||
|
EntryFlag::truncate();
|
||||||
|
ScoreSheet::truncate();
|
||||||
|
Seat::truncate();
|
||||||
|
JudgeAdvancementVote::truncate();
|
||||||
|
DB::table('entries')->delete();
|
||||||
|
NominationEnsembleEntry::truncate();
|
||||||
|
|
||||||
|
if (in_array('deleteRooms', $options)) {
|
||||||
|
DB::table('auditions')->update(['room_id' => null]);
|
||||||
|
DB::table('auditions')->update(['order_in_room' => null]);
|
||||||
|
DB::table('room_judges')->truncate();
|
||||||
|
DB::table('rooms')->truncate();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array('removeAuditionsFromRoom', $options)) {
|
||||||
|
DB::table('auditions')->update(['room_id' => null]);
|
||||||
|
DB::table('auditions')->update(['order_in_room' => null]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array('unassignJudges', $options)) {
|
||||||
|
DB::table('room_judges')->truncate();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue