Implement ticket links and blocker state
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketLink;
|
||||
use App\Models\TicketLinkType;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class TicketLinkSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Project::query()
|
||||
->with(['tickets', 'ticketLinkTypes'])
|
||||
->orderBy('id')
|
||||
->get()
|
||||
->each(function (Project $project): void {
|
||||
/** @var Ticket|null $firstTicket */
|
||||
$firstTicket = $project->tickets->sortBy('sequence_number')->values()->get(0);
|
||||
/** @var Ticket|null $secondTicket */
|
||||
$secondTicket = $project->tickets->sortBy('sequence_number')->values()->get(1);
|
||||
/** @var TicketLinkType|null $ticketLinkType */
|
||||
$ticketLinkType = $project->ticketLinkTypes->sortBy('position')->first();
|
||||
|
||||
if ($firstTicket === null || $secondTicket === null || $ticketLinkType === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
TicketLink::factory()->create([
|
||||
'source_ticket_id' => min($firstTicket->id, $secondTicket->id),
|
||||
'target_ticket_id' => max($firstTicket->id, $secondTicket->id),
|
||||
'ticket_link_type_id' => $ticketLinkType->id,
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user