89 lines
2.5 KiB
PHP
89 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\YearEndProcedures;
|
|
|
|
use App\Exceptions\AuditionAdminException;
|
|
use App\Models\AuditionFlag;
|
|
use App\Models\AuditLogEntry;
|
|
use App\Models\BonusScore;
|
|
use App\Models\Doubler;
|
|
use App\Models\DoublerRequest;
|
|
use App\Models\EntryFlag;
|
|
use App\Models\EntryTotalScore;
|
|
use App\Models\JudgeAdvancementVote;
|
|
use App\Models\NominationEnsembleEntry;
|
|
use App\Models\ScoreSheet;
|
|
use App\Models\Seat;
|
|
use App\Models\Student;
|
|
use App\Models\UserFlag;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use function auth;
|
|
|
|
/**
|
|
* @codeCoverageIgnore
|
|
*/
|
|
// TODO: figure out how to test YearEndCleanup
|
|
class YearEndCleanup
|
|
{
|
|
public function __invoke(?array $options = []): void
|
|
{
|
|
$this->cleanup($options);
|
|
}
|
|
|
|
/**
|
|
* @param $options array array of reset options - possible values are deleteRooms
|
|
* removeAuditionsFromRoom unassignJudges
|
|
*
|
|
* @throws AuditionAdminException
|
|
*/
|
|
public function cleanup(?array $options = []): true
|
|
{
|
|
|
|
if (! auth()->user() or ! auth()->user()->is_admin) {
|
|
throw new AuditionAdminException('Only administrators may perform this action');
|
|
}
|
|
|
|
$historian = new RecordHistoricalSeats;
|
|
$historian();
|
|
|
|
// Delete all records in the audit_log_entries table
|
|
AuditLogEntry::truncate();
|
|
AuditionFlag::truncate();
|
|
BonusScore::truncate();
|
|
EntryTotalScore::truncate();
|
|
DoublerRequest::truncate();
|
|
Doubler::truncate();
|
|
EntryFlag::truncate();
|
|
ScoreSheet::truncate();
|
|
Seat::truncate();
|
|
JudgeAdvancementVote::truncate();
|
|
DB::table('entries')->delete();
|
|
NominationEnsembleEntry::truncate();
|
|
|
|
Student::query()->increment('grade');
|
|
|
|
if (is_array($options)) {
|
|
if (in_array('deleteRooms', $options)) {
|
|
DB::table('auditions')->update(['room_id' => null]);
|
|
DB::table('auditions')->update(['order_in_room' => '0']);
|
|
DB::table('room_user')->truncate();
|
|
DB::table('rooms')->delete();
|
|
}
|
|
|
|
if (in_array('removeAuditionsFromRoom', $options)) {
|
|
DB::table('auditions')->update(['room_id' => null]);
|
|
DB::table('auditions')->update(['order_in_room' => '0']);
|
|
}
|
|
|
|
if (in_array('unassignJudges', $options)) {
|
|
DB::table('room_user')->truncate();
|
|
UserFlag::where('flag', 'monitor')->delete();
|
|
}
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
}
|