mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Convert optional() to nullsafe operator
This commit is contained in:
@@ -92,7 +92,7 @@ class Os implements Module
|
||||
|
||||
if (! empty($location)) { // legacy support, remove when no longer needed
|
||||
$deviceModel->setLocation($location);
|
||||
optional($deviceModel->location)->save();
|
||||
$deviceModel->location?->save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ class Os implements Module
|
||||
|
||||
$device->icon = basename(Url::findOsImage($device->os, $device->features, null, 'images/os/'));
|
||||
|
||||
echo trans('device.attributes.location') . ': ' . optional($device->location)->display() . PHP_EOL;
|
||||
echo trans('device.attributes.location') . ': ' . $device->location?->display() . PHP_EOL;
|
||||
foreach (['hardware', 'version', 'features', 'serial'] as $attribute) {
|
||||
if (isset($device->$attribute)) {
|
||||
$device->$attribute = trim($device->$attribute);
|
||||
@@ -143,7 +143,7 @@ class Os implements Module
|
||||
$device = $os->getDevice();
|
||||
$new_location = $device->override_sysLocation ? new Location() : $os->fetchLocation(); // fetch location data from device
|
||||
$device->setLocation($new_location, true); // set location and lookup coordinates if needed
|
||||
optional($device->location)->save();
|
||||
$device->location?->save();
|
||||
}
|
||||
|
||||
private function sysContact(\LibreNMS\OS $os): void
|
||||
|
||||
@@ -141,7 +141,7 @@ class Url
|
||||
$text = $label;
|
||||
}
|
||||
|
||||
$content = '<div class=list-large>' . addslashes(htmlentities(optional($port->device)->displayName() . ' - ' . $label)) . '</div>';
|
||||
$content = '<div class=list-large>' . addslashes(htmlentities($port->device?->displayName() . ' - ' . $label)) . '</div>';
|
||||
if ($description = $port->getDescription()) {
|
||||
$content .= addslashes(htmlentities($description)) . '<br />';
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ class PortsController extends TableController
|
||||
'status' => $status,
|
||||
'device' => Url::deviceLink($port->device),
|
||||
'port' => Url::portLink($port),
|
||||
'secondsIfLastChange' => ceil(optional($port->device)->uptime - ($port->ifLastChange / 100)),
|
||||
'secondsIfLastChange' => ceil($port->device?->uptime - ($port->ifLastChange / 100)),
|
||||
'ifConnectorPresent' => ($port->ifConnectorPresent == 'true') ? 'yes' : 'no',
|
||||
'ifSpeed' => $port->ifSpeed,
|
||||
'ifMtu' => $port->ifMtu,
|
||||
|
||||
@@ -410,7 +410,7 @@ class Device extends BaseModel
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->relationLoaded('location') || optional($this->location)->location !== $new_location->location) {
|
||||
if (! $this->relationLoaded('location') || $this->location?->location !== $new_location->location) {
|
||||
if (! $new_location->exists) { // don't fetch if new location persisted to the DB, just use it
|
||||
$new_location = Location::firstOrCreate(['location' => $new_location->location], $coord);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class Port extends DeviceRelatedModel
|
||||
DB::table('links')->where('local_port_id', $port->port_id)->orWhere('remote_port_id', $port->port_id)->delete();
|
||||
DB::table('ports_stack')->where('port_id_low', $port->port_id)->orWhere('port_id_high', $port->port_id)->delete();
|
||||
|
||||
\Rrd::purge(optional($port->device)->hostname, \Rrd::portName($port->port_id)); // purge all port rrd files
|
||||
\Rrd::purge($port->device?->hostname, \Rrd::portName($port->port_id)); // purge all port rrd files
|
||||
});
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class Port extends DeviceRelatedModel
|
||||
*/
|
||||
public function getLabel()
|
||||
{
|
||||
$os = optional($this->device)->os;
|
||||
$os = $this->device?->os;
|
||||
|
||||
if (\LibreNMS\Config::getOsSetting($os, 'ifname')) {
|
||||
$label = $this->ifName;
|
||||
|
||||
Reference in New Issue
Block a user