-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from ECFMP/division-discord-multiple-tags
Division discord multiple tags
- Loading branch information
Showing
11 changed files
with
259 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
app/Models/DivisionDiscordWebhookFlightInformationRegion.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use App\Discord\Message\Tag\TagProviderInterface; | ||
use Illuminate\Database\Eloquent\Relations\Pivot; | ||
|
||
class DivisionDiscordWebhookFlightInformationRegion extends Pivot implements TagProviderInterface | ||
{ | ||
public $incrementing = true; | ||
|
||
public $timestamps = true; | ||
|
||
public function rawTagString(): string | ||
{ | ||
return (string)$this->tag; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
..._03_193646_add_tag_column_to_division_discord_webhook_flight_information_region_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::table('division_discord_webhook_flight_information_region', function (Blueprint $table) { | ||
$table->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) { | ||
// | ||
}); | ||
} | ||
}; |
59 changes: 59 additions & 0 deletions
59
database/migrations/2022_08_03_194127_migrate_division_discord_webhook_tags.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
use App\Models\DivisionDiscordWebhook; | ||
use App\Models\FlightInformationRegion; | ||
use Illuminate\Database\Eloquent\Collection; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
return new class () extends Migration { | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
// Migrate the existing tag values | ||
FlightInformationRegion::all() | ||
->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() | ||
{ | ||
// | ||
} | ||
}; |
28 changes: 28 additions & 0 deletions
28
...base/migrations/2022_08_04_144847_drop_tag_column_from_division_discord_webhook_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class () extends Migration { | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::table('division_discord_webhooks', function (Blueprint $table) { | ||
$table->dropColumn('tag'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.