From e510207a7c766c74b6df66ce44c1a9c635afa6dc Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Wed, 3 Aug 2022 21:24:35 +0100 Subject: [PATCH 1/5] feat: deduplicate webhooks and move tags to linking table --- app/Models/DivisionDiscordWebhook.php | 4 +- ...nDiscordWebhookFlightInformationRegion.php | 12 ++++ app/Models/FlightInformationRegion.php | 4 +- ...ebhook_flight_information_region_table.php | 34 +++++++++++ ..._migrate_division_discord_webhook_tags.php | 59 +++++++++++++++++++ 5 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 app/Models/DivisionDiscordWebhookFlightInformationRegion.php create mode 100644 database/migrations/2022_08_03_193646_add_tag_column_to_division_discord_webhook_flight_information_region_table.php create mode 100644 database/migrations/2022_08_03_194127_migrate_division_discord_webhook_tags.php diff --git a/app/Models/DivisionDiscordWebhook.php b/app/Models/DivisionDiscordWebhook.php index c9cd5e6e..37419c90 100644 --- a/app/Models/DivisionDiscordWebhook.php +++ b/app/Models/DivisionDiscordWebhook.php @@ -22,7 +22,9 @@ class DivisionDiscordWebhook extends Model implements WebhookInterface, TagProvi public function flightInformationRegions(): BelongsToMany { - return $this->belongsToMany(FlightInformationRegion::class); + return $this->belongsToMany(FlightInformationRegion::class) + ->withTimestamps() + ->using(DivisionDiscordWebhookFlightInformationRegion::class); } public function id(): ?int diff --git a/app/Models/DivisionDiscordWebhookFlightInformationRegion.php b/app/Models/DivisionDiscordWebhookFlightInformationRegion.php new file mode 100644 index 00000000..3493bfdb --- /dev/null +++ b/app/Models/DivisionDiscordWebhookFlightInformationRegion.php @@ -0,0 +1,12 @@ +belongsToMany(DivisionDiscordWebhook::class); + return $this->belongsToMany(DivisionDiscordWebhook::class) + ->withTimestamps() + ->using(DivisionDiscordWebhookFlightInformationRegion::class); } } diff --git a/database/migrations/2022_08_03_193646_add_tag_column_to_division_discord_webhook_flight_information_region_table.php b/database/migrations/2022_08_03_193646_add_tag_column_to_division_discord_webhook_flight_information_region_table.php new file mode 100644 index 00000000..6a10e6d9 --- /dev/null +++ b/database/migrations/2022_08_03_193646_add_tag_column_to_division_discord_webhook_flight_information_region_table.php @@ -0,0 +1,34 @@ +string('tag') + ->nullable() + ->after('flight_information_region_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('division_discord_webhook_flight_information_region', function (Blueprint $table) { + // + }); + } +}; diff --git a/database/migrations/2022_08_03_194127_migrate_division_discord_webhook_tags.php b/database/migrations/2022_08_03_194127_migrate_division_discord_webhook_tags.php new file mode 100644 index 00000000..b869e1c0 --- /dev/null +++ b/database/migrations/2022_08_03_194127_migrate_division_discord_webhook_tags.php @@ -0,0 +1,59 @@ +each(function (FlightInformationRegion $fir) { + $fir->divisionDiscordWebhooks + ->each(function (DivisionDiscordWebhook $discordWebhook) use ($fir) { + $fir->divisionDiscordWebhooks()->updateExistingPivot( + $discordWebhook->id, + ['tag' => $discordWebhook->tag] + ); + }); + }); + + // Deduplicate them by URL + DivisionDiscordWebhook::all() + ->groupBy('url') + ->reject(fn(Collection $webhooks) => $webhooks->count() === 1) + ->each(function (Collection $webhooks) { + // Get the one we're going to keep + $webhookToKeep = $webhooks->shift(); + + $webhooks->each(function (DivisionDiscordWebhook $webhook) use ($webhookToKeep) { + // Migrate the FIRs to the main webhook + $webhook->flightInformationRegions + ->each(function (FlightInformationRegion $flightInformationRegion) use ($webhook, $webhookToKeep) { + $flightInformationRegion->divisionDiscordWebhooks() + ->attach($webhookToKeep->id, ['tag' => $webhook->tag]); + }); + + // Delete the webhooks + $webhook->forceDelete(); + }); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}; From 205c8ffa57bb00d568c9f1a3e75c70f4f22ae9ee Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Thu, 4 Aug 2022 15:43:22 +0100 Subject: [PATCH 2/5] feat: allow multiple recipient tags per division discord --- .../Content/DivisionWebhookRecipients.php | 11 +- .../Content/FlowMeasureRecipientsFactory.php | 16 ++- app/Models/DivisionDiscordWebhook.php | 11 +- ...nDiscordWebhookFlightInformationRegion.php | 8 +- app/Models/FlightInformationRegion.php | 1 + .../DivisionDiscordWebhookFactory.php | 8 +- .../Content/DivisionWebhookRecipientsTest.php | 8 +- .../FlowMeasureRecipientsFactoryTest.php | 103 +++++++++++++++--- 8 files changed, 122 insertions(+), 44 deletions(-) diff --git a/app/Discord/FlowMeasure/Content/DivisionWebhookRecipients.php b/app/Discord/FlowMeasure/Content/DivisionWebhookRecipients.php index 0653a9f3..826b7870 100644 --- a/app/Discord/FlowMeasure/Content/DivisionWebhookRecipients.php +++ b/app/Discord/FlowMeasure/Content/DivisionWebhookRecipients.php @@ -3,18 +3,21 @@ namespace App\Discord\FlowMeasure\Content; use App\Discord\Message\Tag\TagInterface; +use Illuminate\Support\Collection; class DivisionWebhookRecipients implements FlowMeasureRecipientsInterface { - private readonly TagInterface $tag; + private readonly Collection $tags; - public function __construct(TagInterface $tag) + public function __construct(Collection $tags) { - $this->tag = $tag; + $this->tags = $tags; } public function toString(): string { - return (string)$this->tag; + return $this->tags + ->map(fn(TagInterface $tag) => (string)$tag) + ->join(' '); } } diff --git a/app/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactory.php b/app/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactory.php index 7ae1ed4d..62544099 100644 --- a/app/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactory.php +++ b/app/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactory.php @@ -46,10 +46,18 @@ private function ecfmpRecipients(PendingMessageInterface $pendingMessage): FlowM private function divisionRecipients(PendingMessageInterface $pendingMessage): FlowMeasureRecipientsInterface { - $divisionWebhook = DivisionDiscordWebhook::find($pendingMessage->webhook()->id()); - - return empty($divisionWebhook->tag) + $recipients = DivisionDiscordWebhook::find($pendingMessage->webhook()->id()) + ->flightInformationRegions + ->filter( + fn(FlightInformationRegion $flightInformationRegion) => $pendingMessage + ->flowMeasure() + ->notifiedFlightInformationRegions + ->firstWhere(fn(FlightInformationRegion $notifiedFir) => $notifiedFir->id === $flightInformationRegion->id)) + ->filter(fn(FlightInformationRegion $flightInformationRegion) => !empty($flightInformationRegion->pivot->tag)) + ->map(fn(FlightInformationRegion $flightInformationRegion) => new Tag($flightInformationRegion->pivot)); + + return $recipients->isEmpty() ? new NoRecipients() - : new DivisionWebhookRecipients(new Tag($divisionWebhook)); + : new DivisionWebhookRecipients($recipients); } } diff --git a/app/Models/DivisionDiscordWebhook.php b/app/Models/DivisionDiscordWebhook.php index 37419c90..3f73a973 100644 --- a/app/Models/DivisionDiscordWebhook.php +++ b/app/Models/DivisionDiscordWebhook.php @@ -9,21 +9,21 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\SoftDeletes; -class DivisionDiscordWebhook extends Model implements WebhookInterface, TagProviderInterface +class DivisionDiscordWebhook extends Model implements WebhookInterface { use HasFactory; use SoftDeletes; protected $fillable = [ 'url', - 'description', - 'tag', + 'description' ]; public function flightInformationRegions(): BelongsToMany { return $this->belongsToMany(FlightInformationRegion::class) ->withTimestamps() + ->withPivot('tag') ->using(DivisionDiscordWebhookFlightInformationRegion::class); } @@ -41,9 +41,4 @@ public function description(): string { return $this->description; } - - public function rawTagString(): string - { - return $this->tag; - } } diff --git a/app/Models/DivisionDiscordWebhookFlightInformationRegion.php b/app/Models/DivisionDiscordWebhookFlightInformationRegion.php index 3493bfdb..88b26eca 100644 --- a/app/Models/DivisionDiscordWebhookFlightInformationRegion.php +++ b/app/Models/DivisionDiscordWebhookFlightInformationRegion.php @@ -2,11 +2,17 @@ namespace App\Models; +use App\Discord\Message\Tag\TagProviderInterface; use Illuminate\Database\Eloquent\Relations\Pivot; -class DivisionDiscordWebhookFlightInformationRegion extends Pivot +class DivisionDiscordWebhookFlightInformationRegion extends Pivot implements TagProviderInterface { public $incrementing = true; public $timestamps = true; + + public function rawTagString(): string + { + return (string)$this->tag; + } } diff --git a/app/Models/FlightInformationRegion.php b/app/Models/FlightInformationRegion.php index 1f86aff4..f2488691 100644 --- a/app/Models/FlightInformationRegion.php +++ b/app/Models/FlightInformationRegion.php @@ -60,6 +60,7 @@ protected function identifierName(): Attribute public function divisionDiscordWebhooks(): BelongsToMany { return $this->belongsToMany(DivisionDiscordWebhook::class) + ->withPivot('tag') ->withTimestamps() ->using(DivisionDiscordWebhookFlightInformationRegion::class); } diff --git a/database/factories/DivisionDiscordWebhookFactory.php b/database/factories/DivisionDiscordWebhookFactory.php index 02b75477..a40a061c 100644 --- a/database/factories/DivisionDiscordWebhookFactory.php +++ b/database/factories/DivisionDiscordWebhookFactory.php @@ -21,13 +21,7 @@ public function definition() { return [ 'url' => $this->faker->url(), - 'description' => $this->faker->sentence(3), - 'tag' => sprintf('@%s', $this->faker->unique()->numberBetween(0, PHP_INT_MAX)), + 'description' => $this->faker->sentence(3) ]; } - - public function withNoTag(): static - { - return $this->state(fn (array $attributes) => ['tag' => '']); - } } diff --git a/tests/Discord/FlowMeasure/Content/DivisionWebhookRecipientsTest.php b/tests/Discord/FlowMeasure/Content/DivisionWebhookRecipientsTest.php index 00ca9b39..f6b9447d 100644 --- a/tests/Discord/FlowMeasure/Content/DivisionWebhookRecipientsTest.php +++ b/tests/Discord/FlowMeasure/Content/DivisionWebhookRecipientsTest.php @@ -11,9 +11,11 @@ class DivisionWebhookRecipientsTest extends TestCase { public function testItReturnsRecipients() { - $this->assertSame( - '<@1234>', - (new DivisionWebhookRecipients(new Tag(new DiscordTag(['tag' => '1234']))))->toString() + $this->assertEquals( + '<@1234> <@5678>', + (new DivisionWebhookRecipients( + collect([new Tag(new DiscordTag(['tag' => '1234'])), new Tag(new DiscordTag(['tag' => '5678']))]) + ))->toString() ); } } diff --git a/tests/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactoryTest.php b/tests/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactoryTest.php index 31afbe0a..1b4b62c8 100644 --- a/tests/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactoryTest.php +++ b/tests/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactoryTest.php @@ -45,7 +45,7 @@ public function testItReturnsNoDivisionRecipients() $this->pendingMessage ->shouldReceive('type') ->andReturn(DiscordNotificationTypeEnum::FLOW_MEASURE_ACTIVATED); - $divisionWebhook = DivisionDiscordWebhook::factory()->create(['tag' => '']); + $divisionWebhook = DivisionDiscordWebhook::factory()->create(); $this->webhook->shouldReceive('id')->andReturn($divisionWebhook->id); $this->assertInstanceOf(NoRecipients::class, $this->factory->makeRecipients($this->pendingMessage)); @@ -56,7 +56,26 @@ public function testItReturnsNoDivisionRecipientsIfTagNull() $this->pendingMessage ->shouldReceive('type') ->andReturn(DiscordNotificationTypeEnum::FLOW_MEASURE_ACTIVATED); - $divisionWebhook = DivisionDiscordWebhook::factory()->create(['tag' => null]); + $divisionWebhook = DivisionDiscordWebhook::factory()->create(); + $fir = FlightInformationRegion::factory()->create(); + $divisionWebhook->flightInformationRegions()->sync([$fir->id => ['tag' => null]]); + $this->flowMeasure->notifiedFlightInformationRegions()->sync([$fir->id]); + + $this->webhook->shouldReceive('id')->andReturn($divisionWebhook->id); + + $this->assertInstanceOf(NoRecipients::class, $this->factory->makeRecipients($this->pendingMessage)); + } + + public function testItReturnsNoDivisionRecipientsIfTagEmptyString() + { + $this->pendingMessage + ->shouldReceive('type') + ->andReturn(DiscordNotificationTypeEnum::FLOW_MEASURE_ACTIVATED); + $divisionWebhook = DivisionDiscordWebhook::factory()->create(); + $fir = FlightInformationRegion::factory()->create(); + $divisionWebhook->flightInformationRegions()->sync([$fir->id => ['tag' => '']]); + $this->flowMeasure->notifiedFlightInformationRegions()->sync([$fir->id]); + $this->webhook->shouldReceive('id')->andReturn($divisionWebhook->id); $this->assertInstanceOf(NoRecipients::class, $this->factory->makeRecipients($this->pendingMessage)); @@ -68,11 +87,50 @@ public function testItReturnsDivisionRecipients() ->shouldReceive('type') ->andReturn(DiscordNotificationTypeEnum::FLOW_MEASURE_ACTIVATED); $divisionWebhook = DivisionDiscordWebhook::factory()->create(); + $fir = FlightInformationRegion::factory()->create(); + $divisionWebhook->flightInformationRegions()->sync([$fir->id => ['tag' => '1234']]); + $this->webhook->shouldReceive('id')->andReturn($divisionWebhook->id); + $this->flowMeasure->notifiedFlightInformationRegions()->sync([$fir->id]); + + $recipients = $this->factory->makeRecipients($this->pendingMessage); + $this->assertInstanceOf(DivisionWebhookRecipients::class, $recipients); + $this->assertEquals('<@1234>', $recipients->toString()); + } + + public function testItReturnsMultipleDivisionRecipients() + { + $this->pendingMessage + ->shouldReceive('type') + ->andReturn(DiscordNotificationTypeEnum::FLOW_MEASURE_ACTIVATED); + $divisionWebhook = DivisionDiscordWebhook::factory()->create(); + $fir = FlightInformationRegion::factory()->create(); + $divisionWebhook->flightInformationRegions()->attach([$fir->id => ['tag' => '1234']]); + $fir2 = FlightInformationRegion::factory()->create(); + $divisionWebhook->flightInformationRegions()->attach([$fir2->id => ['tag' => '5678']]); $this->webhook->shouldReceive('id')->andReturn($divisionWebhook->id); + $this->flowMeasure->notifiedFlightInformationRegions()->sync([$fir->id, $fir2->id]); $recipients = $this->factory->makeRecipients($this->pendingMessage); $this->assertInstanceOf(DivisionWebhookRecipients::class, $recipients); - $this->assertEquals(sprintf('<%s>', $divisionWebhook->tag), $recipients->toString()); + $this->assertEquals('<@1234> <@5678>', $recipients->toString()); + } + + public function testItIgnoresRecipientsThatAreNotForFlowMeasure() + { + $this->pendingMessage + ->shouldReceive('type') + ->andReturn(DiscordNotificationTypeEnum::FLOW_MEASURE_ACTIVATED); + $divisionWebhook = DivisionDiscordWebhook::factory()->create(); + $fir = FlightInformationRegion::factory()->create(); + $divisionWebhook->flightInformationRegions()->attach([$fir->id => ['tag' => '1234']]); + $fir2 = FlightInformationRegion::factory()->create(); + $divisionWebhook->flightInformationRegions()->attach([$fir2->id => ['tag' => '5678']]); + $this->webhook->shouldReceive('id')->andReturn($divisionWebhook->id); + $this->flowMeasure->notifiedFlightInformationRegions()->sync([$fir2->id]); + + $recipients = $this->factory->makeRecipients($this->pendingMessage); + $this->assertInstanceOf(DivisionWebhookRecipients::class, $recipients); + $this->assertEquals('<@5678>', $recipients->toString()); } public function testItReturnsEcfmpRecipients() @@ -95,8 +153,10 @@ public function testItReturnsNoRecipientsIfNotifiedRecently() $this->pendingMessage ->shouldReceive('type') ->andReturn(DiscordNotificationTypeEnum::FLOW_MEASURE_ACTIVATED); - $divisionWebhook = DivisionDiscordWebhook::factory()->withNoTag()->create(); - $this->webhook->shouldReceive('id')->andReturn($divisionWebhook->id); + $fir = FlightInformationRegion::factory()->has(DiscordTag::factory()->withoutAtSymbol()->count(1))->create(); + $this->flowMeasure->notifiedFlightInformationRegions()->sync([$fir->id]); + $this->webhook->shouldReceive('id')->andReturn(null); + $notification = $this->flowMeasure->discordNotifications()->create( [ 'content' => '', @@ -121,8 +181,11 @@ public function testItReturnsRecipientsIfNotifiedALongTimeAgo() $this->pendingMessage ->shouldReceive('type') ->andReturn(DiscordNotificationTypeEnum::FLOW_MEASURE_ACTIVATED); - $divisionWebhook = DivisionDiscordWebhook::factory()->create(); - $this->webhook->shouldReceive('id')->andReturn($divisionWebhook->id); + $fir = FlightInformationRegion::factory()->has(DiscordTag::factory()->withoutAtSymbol()->count(1))->create(); + $tag = $fir->discordTags->first(); + $this->flowMeasure->notifiedFlightInformationRegions()->sync([$fir->id]); + $this->webhook->shouldReceive('id')->andReturn(null); + $notification = $this->flowMeasure->discordNotifications()->create( [ 'content' => '', @@ -139,8 +202,8 @@ public function testItReturnsRecipientsIfNotifiedALongTimeAgo() $notification->save(); $recipients = $this->factory->makeRecipients($this->pendingMessage); - $this->assertInstanceOf(DivisionWebhookRecipients::class, $recipients); - $this->assertEquals(sprintf('<%s>', $divisionWebhook->tag), $recipients->toString()); + $this->assertInstanceOf(EcfmpInterestedParties::class, $recipients); + $this->assertStringContainsString($tag->tag, $recipients->toString()); } public function testItReturnsRecipientsIfNotifiedAsReissue() @@ -148,8 +211,11 @@ public function testItReturnsRecipientsIfNotifiedAsReissue() $this->pendingMessage ->shouldReceive('type') ->andReturn(DiscordNotificationTypeEnum::FLOW_MEASURE_ACTIVATED); - $divisionWebhook = DivisionDiscordWebhook::factory()->create(); - $this->webhook->shouldReceive('id')->andReturn($divisionWebhook->id); + $fir = FlightInformationRegion::factory()->has(DiscordTag::factory()->withoutAtSymbol()->count(1))->create(); + $tag = $fir->discordTags->first(); + $this->flowMeasure->notifiedFlightInformationRegions()->sync([$fir->id]); + $this->webhook->shouldReceive('id')->andReturn(null); + $notification = $this->flowMeasure->discordNotifications()->create( [ 'content' => '', @@ -166,8 +232,8 @@ public function testItReturnsRecipientsIfNotifiedAsReissue() $notification->save(); $recipients = $this->factory->makeRecipients($this->pendingMessage); - $this->assertInstanceOf(DivisionWebhookRecipients::class, $recipients); - $this->assertEquals(sprintf('<%s>', $divisionWebhook->tag), $recipients->toString()); + $this->assertInstanceOf(EcfmpInterestedParties::class, $recipients); + $this->assertStringContainsString($tag->tag, $recipients->toString()); } public function testItReturnsRecipientsIfNotActivating() @@ -175,8 +241,11 @@ public function testItReturnsRecipientsIfNotActivating() $this->pendingMessage ->shouldReceive('type') ->andReturn(DiscordNotificationTypeEnum::FLOW_MEASURE_WITHDRAWN); - $divisionWebhook = DivisionDiscordWebhook::factory()->create(); - $this->webhook->shouldReceive('id')->andReturn($divisionWebhook->id); + $fir = FlightInformationRegion::factory()->has(DiscordTag::factory()->withoutAtSymbol()->count(1))->create(); + $tag = $fir->discordTags->first(); + $this->flowMeasure->notifiedFlightInformationRegions()->sync([$fir->id]); + $this->webhook->shouldReceive('id')->andReturn(null); + $notification = $this->flowMeasure->discordNotifications()->create( [ 'content' => '', @@ -193,7 +262,7 @@ public function testItReturnsRecipientsIfNotActivating() $notification->save(); $recipients = $this->factory->makeRecipients($this->pendingMessage); - $this->assertInstanceOf(DivisionWebhookRecipients::class, $recipients); - $this->assertEquals(sprintf('<%s>', $divisionWebhook->tag), $recipients->toString()); + $this->assertInstanceOf(EcfmpInterestedParties::class, $recipients); + $this->assertStringContainsString($tag->tag, $recipients->toString()); } } From ca431a445ef247803efd5570dc785f78eb84ff0f Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Thu, 4 Aug 2022 15:43:33 +0100 Subject: [PATCH 3/5] style: pint --- .../FlowMeasure/Content/DivisionWebhookRecipients.php | 2 +- .../FlowMeasure/Content/FlowMeasureRecipientsFactory.php | 9 +++++---- app/Models/DivisionDiscordWebhook.php | 1 - ...n_discord_webhook_flight_information_region_table.php | 3 +-- ...8_03_194127_migrate_division_discord_webhook_tags.php | 4 ++-- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/Discord/FlowMeasure/Content/DivisionWebhookRecipients.php b/app/Discord/FlowMeasure/Content/DivisionWebhookRecipients.php index 826b7870..7767057a 100644 --- a/app/Discord/FlowMeasure/Content/DivisionWebhookRecipients.php +++ b/app/Discord/FlowMeasure/Content/DivisionWebhookRecipients.php @@ -17,7 +17,7 @@ public function __construct(Collection $tags) public function toString(): string { return $this->tags - ->map(fn(TagInterface $tag) => (string)$tag) + ->map(fn (TagInterface $tag) => (string)$tag) ->join(' '); } } diff --git a/app/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactory.php b/app/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactory.php index 62544099..a7daecb1 100644 --- a/app/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactory.php +++ b/app/Discord/FlowMeasure/Content/FlowMeasureRecipientsFactory.php @@ -49,12 +49,13 @@ private function divisionRecipients(PendingMessageInterface $pendingMessage): Fl $recipients = DivisionDiscordWebhook::find($pendingMessage->webhook()->id()) ->flightInformationRegions ->filter( - fn(FlightInformationRegion $flightInformationRegion) => $pendingMessage + fn (FlightInformationRegion $flightInformationRegion) => $pendingMessage ->flowMeasure() ->notifiedFlightInformationRegions - ->firstWhere(fn(FlightInformationRegion $notifiedFir) => $notifiedFir->id === $flightInformationRegion->id)) - ->filter(fn(FlightInformationRegion $flightInformationRegion) => !empty($flightInformationRegion->pivot->tag)) - ->map(fn(FlightInformationRegion $flightInformationRegion) => new Tag($flightInformationRegion->pivot)); + ->firstWhere(fn (FlightInformationRegion $notifiedFir) => $notifiedFir->id === $flightInformationRegion->id) + ) + ->filter(fn (FlightInformationRegion $flightInformationRegion) => !empty($flightInformationRegion->pivot->tag)) + ->map(fn (FlightInformationRegion $flightInformationRegion) => new Tag($flightInformationRegion->pivot)); return $recipients->isEmpty() ? new NoRecipients() diff --git a/app/Models/DivisionDiscordWebhook.php b/app/Models/DivisionDiscordWebhook.php index 3f73a973..e32ad74e 100644 --- a/app/Models/DivisionDiscordWebhook.php +++ b/app/Models/DivisionDiscordWebhook.php @@ -2,7 +2,6 @@ namespace App\Models; -use App\Discord\Message\Tag\TagProviderInterface; use App\Discord\Webhook\WebhookInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; diff --git a/database/migrations/2022_08_03_193646_add_tag_column_to_division_discord_webhook_flight_information_region_table.php b/database/migrations/2022_08_03_193646_add_tag_column_to_division_discord_webhook_flight_information_region_table.php index 6a10e6d9..69a65044 100644 --- a/database/migrations/2022_08_03_193646_add_tag_column_to_division_discord_webhook_flight_information_region_table.php +++ b/database/migrations/2022_08_03_193646_add_tag_column_to_division_discord_webhook_flight_information_region_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_08_03_194127_migrate_division_discord_webhook_tags.php b/database/migrations/2022_08_03_194127_migrate_division_discord_webhook_tags.php index b869e1c0..9d2e8a5f 100644 --- a/database/migrations/2022_08_03_194127_migrate_division_discord_webhook_tags.php +++ b/database/migrations/2022_08_03_194127_migrate_division_discord_webhook_tags.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Migrations\Migration; -return new class extends Migration { +return new class () extends Migration { /** * Run the migrations. * @@ -28,7 +28,7 @@ public function up() // Deduplicate them by URL DivisionDiscordWebhook::all() ->groupBy('url') - ->reject(fn(Collection $webhooks) => $webhooks->count() === 1) + ->reject(fn (Collection $webhooks) => $webhooks->count() === 1) ->each(function (Collection $webhooks) { // Get the one we're going to keep $webhookToKeep = $webhooks->shift(); From 0c1fc74d35eae59dae234e1d9639200d4dc964c5 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Thu, 4 Aug 2022 15:49:18 +0100 Subject: [PATCH 4/5] refactor: drop tag column from discord webhooks table --- ...mn_from_division_discord_webhook_table.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 database/migrations/2022_08_04_144847_drop_tag_column_from_division_discord_webhook_table.php diff --git a/database/migrations/2022_08_04_144847_drop_tag_column_from_division_discord_webhook_table.php b/database/migrations/2022_08_04_144847_drop_tag_column_from_division_discord_webhook_table.php new file mode 100644 index 00000000..1930b986 --- /dev/null +++ b/database/migrations/2022_08_04_144847_drop_tag_column_from_division_discord_webhook_table.php @@ -0,0 +1,29 @@ +dropColumn('tag'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + } +}; From 4d26906e9ed6a33ce9bb94dafc60f53feeca2fb6 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Thu, 4 Aug 2022 15:51:40 +0100 Subject: [PATCH 5/5] style: pint --- ...847_drop_tag_column_from_division_discord_webhook_table.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/database/migrations/2022_08_04_144847_drop_tag_column_from_division_discord_webhook_table.php b/database/migrations/2022_08_04_144847_drop_tag_column_from_division_discord_webhook_table.php index 1930b986..8004b577 100644 --- a/database/migrations/2022_08_04_144847_drop_tag_column_from_division_discord_webhook_table.php +++ b/database/migrations/2022_08_04_144847_drop_tag_column_from_division_discord_webhook_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { /** * Run the migrations. *