mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix errors for some devices loading components (#11527)
* Test WIP * WIP * port getComponents to Eloquent * port more * simpler creation * change to explicit arrays * add missed file * restore commented code * fix inserting null value for component prefs * Fix some bugs in setCompenentPrefs Can't create tests without fixing bugs first :D * another test * another test * Modernize setComponentPrefs * Test for event log entries * Fix delete event * fix invalid values for component toggles * status log too * Use Setters to work around bad data, $casts doesn't do what we want.
This commit is contained in:
@@ -29,4 +29,34 @@ class Component extends DeviceRelatedModel
|
||||
{
|
||||
public $timestamps = false;
|
||||
protected $table = 'component';
|
||||
protected $fillable = ['device_id', 'type', 'label', 'status', 'disabled', 'ignore', 'error'];
|
||||
|
||||
// ---- Accessors/Mutators ----
|
||||
|
||||
public function setStatusAttribute($status)
|
||||
{
|
||||
$this->attributes['status'] = (int)$status;
|
||||
}
|
||||
|
||||
public function setDisabledAttribute($disabled)
|
||||
{
|
||||
$this->attributes['disabled'] = (int)$disabled;
|
||||
}
|
||||
|
||||
public function setIgnoreAttribute($ignore)
|
||||
{
|
||||
$this->attributes['ignore'] = (int)$ignore;
|
||||
}
|
||||
|
||||
// ---- Define Relationships ----
|
||||
|
||||
public function logs()
|
||||
{
|
||||
return $this->hasMany(\App\Models\ComponentStatusLog::class, 'component_id', 'id');
|
||||
}
|
||||
|
||||
public function prefs()
|
||||
{
|
||||
return $this->hasMany(\App\Models\ComponentPref::class, 'component', 'id');
|
||||
}
|
||||
}
|
||||
|
16
app/Models/ComponentPref.php
Normal file
16
app/Models/ComponentPref.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ComponentPref extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['component', 'attribute', 'value'];
|
||||
|
||||
public function setValueAttribute($value)
|
||||
{
|
||||
$this->attributes['value'] = is_array($value) ? json_encode($value) : (string)$value;
|
||||
}
|
||||
}
|
19
app/Models/ComponentStatusLog.php
Normal file
19
app/Models/ComponentStatusLog.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ComponentStatusLog extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
protected $table = 'component_statuslog';
|
||||
protected $fillable = ['component_id', 'status', 'message'];
|
||||
|
||||
// ---- Accessors/Mutators ----
|
||||
|
||||
public function setStatusAttribute($status)
|
||||
{
|
||||
$this->attributes['status'] = (int)$status;
|
||||
}
|
||||
}
|
@@ -31,4 +31,5 @@ class DeviceAttrib extends DeviceRelatedModel
|
||||
protected $primaryKey = 'attrib_id';
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['attrib_type', 'attrib_value'];
|
||||
// protected $casts = ['attrib_value' => 'array'];
|
||||
}
|
||||
|
Reference in New Issue
Block a user