Implement ticket links and blocker state
This commit is contained in:
@@ -23,7 +23,9 @@ class TicketFactory extends Factory
|
||||
return [
|
||||
'acceptance_criteria' => fake()->paragraph(),
|
||||
'board_column_id' => null,
|
||||
'blocked_comment' => null,
|
||||
'description' => fake()->paragraphs(2, true),
|
||||
'is_blocked' => false,
|
||||
'parent_ticket_id' => null,
|
||||
'sequence_number' => 1,
|
||||
'ticket_key' => 'TEST-1',
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketLink;
|
||||
use App\Models\TicketLinkType;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<TicketLink>
|
||||
*/
|
||||
class TicketLinkFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'source_ticket_id' => null,
|
||||
'target_ticket_id' => null,
|
||||
'ticket_link_type_id' => null,
|
||||
];
|
||||
}
|
||||
|
||||
public function configure(): static
|
||||
{
|
||||
return $this->afterMaking(function (TicketLink $ticketLink): void {
|
||||
$sourceTicket = $ticketLink->source_ticket_id === null
|
||||
? Ticket::factory()->create()
|
||||
: Ticket::query()->findOrFail($ticketLink->source_ticket_id);
|
||||
|
||||
$targetTicket = $ticketLink->target_ticket_id === null
|
||||
? Ticket::factory()->create([
|
||||
'project_id' => $sourceTicket->project_id,
|
||||
'ticket_priority_id' => $sourceTicket->ticket_priority_id,
|
||||
'ticket_type_id' => $sourceTicket->ticket_type_id,
|
||||
'sequence_number' => $sourceTicket->sequence_number + 1,
|
||||
'ticket_key' => "{$sourceTicket->project->key}-".($sourceTicket->sequence_number + 1),
|
||||
])
|
||||
: Ticket::query()->findOrFail($ticketLink->target_ticket_id);
|
||||
|
||||
if ($sourceTicket->id === $targetTicket->id) {
|
||||
$targetTicket = Ticket::factory()->create([
|
||||
'project_id' => $sourceTicket->project_id,
|
||||
'ticket_priority_id' => $sourceTicket->ticket_priority_id,
|
||||
'ticket_type_id' => $sourceTicket->ticket_type_id,
|
||||
'sequence_number' => $sourceTicket->sequence_number + 1,
|
||||
'ticket_key' => "{$sourceTicket->project->key}-".($sourceTicket->sequence_number + 1),
|
||||
]);
|
||||
}
|
||||
|
||||
$ticketLinkType = $ticketLink->ticket_link_type_id === null
|
||||
? TicketLinkType::query()
|
||||
->where('project_id', $sourceTicket->project_id)
|
||||
->orderBy('position')
|
||||
->first()
|
||||
?? TicketLinkType::factory()->for($sourceTicket->project)->create([
|
||||
'label' => 'Relates to',
|
||||
'position' => 1,
|
||||
])
|
||||
: TicketLinkType::query()->findOrFail($ticketLink->ticket_link_type_id);
|
||||
|
||||
$sortedIds = [$sourceTicket->id, $targetTicket->id];
|
||||
sort($sortedIds);
|
||||
|
||||
$ticketLink->source_ticket_id = $sortedIds[0];
|
||||
$ticketLink->target_ticket_id = $sortedIds[1];
|
||||
$ticketLink->ticket_link_type_id = $ticketLinkType->id;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\TicketLinkType;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<TicketLinkType>
|
||||
*/
|
||||
class TicketLinkTypeFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'label' => fake()->unique()->words(2, true),
|
||||
'position' => 1,
|
||||
'project_id' => Project::factory(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('tickets', function (Blueprint $table) {
|
||||
$table->boolean('is_blocked')
|
||||
->default(false)
|
||||
->after('parent_ticket_id');
|
||||
$table->text('blocked_comment')
|
||||
->nullable()
|
||||
->after('is_blocked');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('tickets', function (Blueprint $table) {
|
||||
$table->dropColumn(['blocked_comment', 'is_blocked']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('ticket_link_types', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('project_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('label');
|
||||
$table->unsignedInteger('position');
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['project_id', 'label']);
|
||||
$table->unique(['project_id', 'position']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('ticket_link_types');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('ticket_links', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('ticket_link_type_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('source_ticket_id')->constrained('tickets')->cascadeOnDelete();
|
||||
$table->foreignId('target_ticket_id')->constrained('tickets')->cascadeOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['source_ticket_id', 'target_ticket_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('ticket_links');
|
||||
}
|
||||
};
|
||||
@@ -19,6 +19,8 @@ class DatabaseSeeder extends Seeder
|
||||
ProjectTicketMetadataSeeder::class,
|
||||
TicketSeeder::class,
|
||||
TicketFieldValueSeeder::class,
|
||||
TicketLinkTypeSeeder::class,
|
||||
TicketLinkSeeder::class,
|
||||
TicketWorklogEntrySeeder::class,
|
||||
TeamSeeder::class,
|
||||
ProjectAccessSeeder::class,
|
||||
|
||||
@@ -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,
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\TicketLinkType;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class TicketLinkTypeSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Project::query()
|
||||
->orderBy('id')
|
||||
->get()
|
||||
->each(function (Project $project): void {
|
||||
TicketLinkType::factory()
|
||||
->count(2)
|
||||
->sequence(
|
||||
['label' => 'Relates to', 'position' => 1],
|
||||
['label' => 'Blocks', 'position' => 2],
|
||||
)
|
||||
->for($project)
|
||||
->create();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user