Normalise tagline/tearline/origin
This commit is contained in:
@@ -46,6 +46,27 @@ final class Echomail extends Model implements Packet
|
||||
'rogue_path' => CollectionOrNull::class, // @deprecated?
|
||||
];
|
||||
|
||||
public function __get($key)
|
||||
{
|
||||
switch ($key) {
|
||||
case 'set_echoarea':
|
||||
case 'set_fftn':
|
||||
case 'set_path':
|
||||
case 'set_pkt':
|
||||
case 'set_recvtime':
|
||||
case 'set_seenby':
|
||||
case 'set_sender':
|
||||
|
||||
case 'set_tagline':
|
||||
case 'set_tearline':
|
||||
case 'set_origin':
|
||||
return $this->set->get($key);
|
||||
|
||||
default:
|
||||
return parent::__get($key);
|
||||
}
|
||||
}
|
||||
|
||||
public function __set($key,$value)
|
||||
{
|
||||
switch ($key) {
|
||||
@@ -71,7 +92,7 @@ final class Echomail extends Model implements Packet
|
||||
case 'set_pkt':
|
||||
case 'set_recvtime':
|
||||
case 'set_sender':
|
||||
// @todo We'll normalise these values when saving the netmail
|
||||
|
||||
case 'set_tagline':
|
||||
case 'set_tearline':
|
||||
case 'set_origin':
|
||||
@@ -101,6 +122,26 @@ final class Echomail extends Model implements Packet
|
||||
static::creating(function($model) {
|
||||
if (isset($model->errors) && $model->errors->count())
|
||||
throw new \Exception('Cannot save, validation errors exist');
|
||||
|
||||
if ($model->set->has('set_tagline'))
|
||||
$model->tagline_id = Tagline::firstOrCreate(['value'=>$model->set_tagline])->id;
|
||||
|
||||
if ($model->set->has('set_tearline'))
|
||||
$model->tearline_id = Tearline::firstOrCreate(['value'=>$model->set_tearline])->id;
|
||||
|
||||
if ($model->set->has('set_origin')) {
|
||||
// Make sure our origin contains our FTN
|
||||
$m = [];
|
||||
if ((preg_match('#^(.*)\s+\(([0-9]+:[0-9]+/[0-9]+.*)\)+\s*$#',$model->set_origin,$m))
|
||||
&& (Address::findFTN($m[2])->id === $model->fftn_id))
|
||||
$model->origin_id = Origin::firstOrCreate(['value'=>$m[1]])->id;
|
||||
}
|
||||
|
||||
// If we can rebuild the message content, then we can do away with msg_src
|
||||
if (md5($model->rebuildMessage()) === $model->msg_crc) {
|
||||
Log::debug(sprintf('%s:- Pruning message source, since we can rebuild the message [%s]',self::LOGKEY,$model->msgid));
|
||||
$model->msg_src = NULL;
|
||||
}
|
||||
});
|
||||
|
||||
// @todo if the message is updated with new SEEN-BY's from another route, we'll delete the pending export for systems (if there is one)
|
||||
@@ -213,12 +254,6 @@ final class Echomail extends Model implements Packet
|
||||
return $this->belongsTo(Echoarea::class);
|
||||
}
|
||||
|
||||
public function fftn()
|
||||
{
|
||||
return $this->belongsTo(Address::class)
|
||||
->withTrashed();
|
||||
}
|
||||
|
||||
public function seenby()
|
||||
{
|
||||
return $this->belongsToMany(Address::class,'echomail_seenby')
|
||||
|
Reference in New Issue
Block a user