Laravel 9 Update (#1413)
Update to Laravel 9 and PHP 8+ Co-authored-by: B.Fatih KOZ <fatih.koz@gmail.com>
This commit is contained in:
@@ -10,8 +10,6 @@ use App\Notifications\Channels\Discord\DiscordWebhook;
|
||||
use App\Support\Units\Distance;
|
||||
use App\Support\Units\Time;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use PhpUnitsOfMeasure\Exception\NonNumericValue;
|
||||
use PhpUnitsOfMeasure\Exception\NonStringUnitName;
|
||||
|
||||
/**
|
||||
* Send the PIREP accepted message to a particular user, can also be sent to Discord
|
||||
@@ -78,36 +76,7 @@ class PirepStatusChanged extends Notification implements ShouldQueue
|
||||
}
|
||||
|
||||
$title = 'Flight '.$pirep->ident.' '.self::$verbs[$pirep->status];
|
||||
$fields = [
|
||||
'Dep.Airport' => $pirep->dpt_airport_id,
|
||||
'Arr.Airport' => $pirep->arr_airport_id,
|
||||
'Equipment' => $pirep->aircraft->ident,
|
||||
'Flight Time' => Time::minutesToTimeString($pirep->flight_time),
|
||||
];
|
||||
|
||||
// Show the distance, but include the planned distance if it's been set
|
||||
if ($pirep->distance) {
|
||||
$unit = config('phpvms.internal_units.distance');
|
||||
|
||||
try {
|
||||
$planned_distance = new Distance($pirep->distance, $unit);
|
||||
$pd = $planned_distance[$planned_distance->unit];
|
||||
$fields['Distance'] = $pd;
|
||||
|
||||
// Add the planned distance in
|
||||
if ($pirep->planned_distance) {
|
||||
try {
|
||||
$planned_distance = new Distance($pirep->planned_distance, $unit);
|
||||
$pd = $planned_distance[$planned_distance->unit];
|
||||
$fields['Distance'] .= '/'.$pd;
|
||||
} catch (NonNumericValue|NonStringUnitName $e) {
|
||||
}
|
||||
}
|
||||
|
||||
$fields['Distance'] .= ' '.$planned_distance->unit;
|
||||
} catch (NonNumericValue|NonStringUnitName $e) {
|
||||
}
|
||||
}
|
||||
$fields = $this->createFields($pirep);
|
||||
|
||||
// User avatar, somehow $pirep->user->resolveAvatarUrl() is not being accepted by Discord as thumbnail
|
||||
$user_avatar = !empty($pirep->user->avatar) ? $pirep->user->avatar->url : $pirep->user->gravatar(256);
|
||||
@@ -121,6 +90,7 @@ class PirepStatusChanged extends Notification implements ShouldQueue
|
||||
PirepStatus::PAUSED,
|
||||
PirepStatus::EMERG_DESCENT,
|
||||
];
|
||||
|
||||
$color = in_array($pirep->status, $danger_types, true) ? 'ED2939' : 'FD6A02';
|
||||
|
||||
$dm = new DiscordMessage();
|
||||
@@ -136,6 +106,38 @@ class PirepStatusChanged extends Notification implements ShouldQueue
|
||||
->fields($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Pirep $pirep
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function createFields(Pirep $pirep): array
|
||||
{
|
||||
$fields = [
|
||||
'Dep.Airport' => $pirep->dpt_airport_id,
|
||||
'Arr.Airport' => $pirep->arr_airport_id,
|
||||
'Equipment' => $pirep->aircraft->ident,
|
||||
'Flight Time' => Time::minutesToTimeString($pirep->flight_time),
|
||||
];
|
||||
|
||||
// Show the distance, but include the planned distance if it's been set
|
||||
$fields['Distance'] = [];
|
||||
if ($pirep->distance) {
|
||||
$fields['Distance'][] = $pirep->distance->local(2);
|
||||
}
|
||||
|
||||
if ($pirep->planned_distance) {
|
||||
$fields['Distance'][] = $pirep->planned_distance->local(2);
|
||||
}
|
||||
|
||||
if (!empty($fields['Distance'])) {
|
||||
$fields['Distance'] = implode('/', $fields['Distance']);
|
||||
$fields['Distance'] .= ' '.setting('units.distance');
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user