Move mailer details into a separate table
This commit is contained in:
31
app/Models/Mailer.php
Normal file
31
app/Models/Mailer.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Mailer extends Model
|
||||
{
|
||||
public $timestamps = FALSE;
|
||||
|
||||
private const SORTORDER = [
|
||||
'BINKP'=>1,
|
||||
'EMSI'=>2,
|
||||
];
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function system()
|
||||
{
|
||||
return $this->belongsTo(System::class);
|
||||
}
|
||||
|
||||
/* SCOPES */
|
||||
|
||||
public function scopePreferred($query)
|
||||
{
|
||||
return $query
|
||||
->orderBy('priority','ASC')
|
||||
->where('mailer_system.active',TRUE);
|
||||
}
|
||||
}
|
@@ -48,6 +48,18 @@ class System extends Model
|
||||
->active();
|
||||
}
|
||||
|
||||
public function mailers()
|
||||
{
|
||||
return $this->belongsToMany(Mailer::class)
|
||||
->withPivot(['last_poll','port','attempts','active']);
|
||||
}
|
||||
|
||||
public function mailer_preferred()
|
||||
{
|
||||
return $this->mailers()
|
||||
->preferred();
|
||||
}
|
||||
|
||||
public function logs()
|
||||
{
|
||||
return $this->hasMany(SystemLog::class);
|
||||
@@ -119,11 +131,11 @@ class System extends Model
|
||||
|
||||
public function getAccessMailerAttribute(): string
|
||||
{
|
||||
switch ($this->mailer_type) {
|
||||
case Setup::O_BINKP: return sprintf('binkp://%s:%s',$this->mailer_address,$this->mailer_port);
|
||||
case Setup::O_EMSI: return sprintf('emsi://%s:%s',$this->mailer_address,$this->mailer_port);
|
||||
switch (($x=$this->mailer_preferred()->first())?->name) {
|
||||
case 'BINKP': return sprintf('binkp://%s:%s',$this->address,$x->pivot->port);
|
||||
case 'EMSI': return sprintf('emsi://%s:%s',$this->address,$x->pivot->port);
|
||||
default:
|
||||
return $this->mailer_type ? sprintf('%s:%s',$this->address,$this->port) : 'No mailer available.';
|
||||
return $x?->name ? sprintf('%s:%s',$this->address,$x->pivot->port) : 'No mailer available.';
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user