Normalise tagline/tearline/origin
This commit is contained in:
parent
1d354da6e3
commit
8fb3a21fcd
@ -673,7 +673,7 @@ class Message extends FTNBase
|
||||
* @return Echomail|Netmail
|
||||
* @throws InvalidPacketException
|
||||
*/
|
||||
private function unpackMessage(string $message,Echomail|Netmail $o): Echomail|Netmail
|
||||
public function unpackMessage(string $message,Echomail|Netmail $o): Echomail|Netmail
|
||||
{
|
||||
// Remove DOS \n\r
|
||||
$message = preg_replace("/\n\r/","\r",$message);
|
||||
@ -796,6 +796,9 @@ class Message extends FTNBase
|
||||
$ptr_content_start = $ptr_end-$ptr_start;
|
||||
}
|
||||
|
||||
// Trim any right \r from the message
|
||||
$o->msg = rtrim($o->msg,"\r");
|
||||
|
||||
// Quick validation that we are done
|
||||
if ($ptr_content_start !== strlen($content))
|
||||
throw new InvalidPacketException('There is more data in the message content?');
|
||||
@ -847,9 +850,6 @@ class Message extends FTNBase
|
||||
'replyid' => 'sometimes|min:1',
|
||||
'msg' => 'required|min:1', // @todo max message length?
|
||||
'msg_crc' => 'required|size:32',
|
||||
'tagline' => 'sometimes|min:1|max:255',
|
||||
'tearline' => 'sometimes|min:1|max:255',
|
||||
'origin' => 'sometimes|min:1|max:255',
|
||||
'local' => 'sometimes|boolean',
|
||||
'fftn_id' => 'required|exists:App\Models\Address,id',
|
||||
'tftn_id' => $this->isNetmail() ? 'required|exists:App\Models\Address,id' : 'prohibited',
|
||||
|
@ -507,7 +507,7 @@ class SystemController extends Controller
|
||||
$no->flags = (Message::FLAG_LOCAL|Message::FLAG_PRIVATE|Message::FLAG_CRASH);
|
||||
$no->cost = 0;
|
||||
|
||||
$no->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
|
||||
$no->set_tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
|
||||
$no->save();
|
||||
|
||||
Log::info(sprintf('%s:= Areafix to [%s], scheduling a poll',self::LOGKEY,$no->tftn->ftn));
|
||||
|
@ -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')
|
||||
|
@ -45,6 +45,27 @@ final class Netmail extends Model implements Packet
|
||||
'sent_at' => 'datetime:Y-m-d H:i:s',
|
||||
];
|
||||
|
||||
public function __get($key)
|
||||
{
|
||||
switch ($key) {
|
||||
case 'set_fftn':
|
||||
case 'set_tftn':
|
||||
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) {
|
||||
@ -67,7 +88,7 @@ final class Netmail 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':
|
||||
@ -94,6 +115,26 @@ final class Netmail 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;
|
||||
}
|
||||
});
|
||||
|
||||
static::created(function($model) {
|
||||
@ -160,27 +201,12 @@ final class Netmail extends Model implements Packet
|
||||
]);
|
||||
}
|
||||
|
||||
// Save our origin, tearline & tagline
|
||||
if ($model->set->has('set_tagline'))
|
||||
$model->tagline = $model->set->get('set_tagline');
|
||||
if ($model->set->has('set_tearline'))
|
||||
$model->tearline = $model->set->get('set_tearline');
|
||||
if ($model->set->has('set_origin'))
|
||||
$model->origin = $model->set->get('set_origin');
|
||||
|
||||
$model->save();
|
||||
});
|
||||
}
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function fftn()
|
||||
{
|
||||
return $this
|
||||
->belongsTo(Address::class)
|
||||
->withTrashed();
|
||||
}
|
||||
|
||||
public function path()
|
||||
{
|
||||
return $this->belongsToMany(Address::class,'netmail_path')
|
||||
|
20
app/Models/Origin.php
Normal file
20
app/Models/Origin.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Origin extends Model
|
||||
{
|
||||
//use HasFactory;
|
||||
|
||||
public const UPDATED_AT = NULL;
|
||||
|
||||
protected $fillable = ['value'];
|
||||
|
||||
public function complete(Address $o): string
|
||||
{
|
||||
return sprintf(' * Origin: %s (%s)',$this->value,$o->point_id ? $o->ftn4d : $o->ftn3d);
|
||||
}
|
||||
}
|
20
app/Models/Tagline.php
Normal file
20
app/Models/Tagline.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Tagline extends Model
|
||||
{
|
||||
//use HasFactory;
|
||||
|
||||
public const UPDATED_AT = NULL;
|
||||
|
||||
protected $fillable = ['value'];
|
||||
|
||||
public function complete(): string
|
||||
{
|
||||
return sprintf('... %s',$this->value);
|
||||
}
|
||||
}
|
20
app/Models/Tearline.php
Normal file
20
app/Models/Tearline.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Tearline extends Model
|
||||
{
|
||||
//use HasFactory;
|
||||
|
||||
public const UPDATED_AT = NULL;
|
||||
|
||||
protected $fillable = ['value'];
|
||||
|
||||
public function complete(): string
|
||||
{
|
||||
return sprintf('--- %s',$this->value);
|
||||
}
|
||||
}
|
@ -58,7 +58,7 @@ abstract class Echomails extends Notification //implements ShouldQueue
|
||||
|
||||
$o->flags = (Message::FLAG_LOCAL);
|
||||
|
||||
$o->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
|
||||
$o->set_tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
@ -48,7 +48,6 @@ class AbsentNodes extends Echomails
|
||||
$o->subject = 'Status changes for nodes';
|
||||
$o->fftn_id = ($x=our_address($echoarea->domain)->last())->id;
|
||||
$o->kludges->put('CHRS:','CP437 2');
|
||||
$o->origin = sprintf('%s (%s)',Setup::PRODUCT_NAME,$x->ftn4d);
|
||||
|
||||
// Message
|
||||
$msg = new Page;
|
||||
@ -95,7 +94,8 @@ class AbsentNodes extends Echomails
|
||||
$msg->addText("\rEmails and/or Netmails have been sent to these nodes. If you can help let them know that they have outstanding mail on the Hub, that would be helpful :)");
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'When life gives you lemons, freeze them and throw them back.';
|
||||
$o->set_tagline = 'When life gives you lemons, freeze them and throw them back.';
|
||||
$o->set_origin = sprintf('%s (%s)',Setup::PRODUCT_NAME,$x->ftn4d);
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -50,7 +50,6 @@ class Test extends Echomails
|
||||
$o->replyid = $this->mo->msgid;
|
||||
$o->subject = 'Test Reply';
|
||||
$o->kludges->put('CHRS:',$this->mo->kludges->get('chrs') ?: 'CP437 2');
|
||||
$o->origin = sprintf('%s (%s)',Setup::PRODUCT_NAME,$x->ftn4d);
|
||||
|
||||
// Message
|
||||
$msg = new Page;
|
||||
@ -74,7 +73,8 @@ class Test extends Echomails
|
||||
$msg->addText($this->message_path($this->mo));
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'I ate a clock yesterday, it was very time-consuming.';
|
||||
$o->set_tagline = 'I ate a clock yesterday, it was very time-consuming.';
|
||||
$o->set_origin = sprintf('%s (%s)',Setup::PRODUCT_NAME,$x->ftn4d);
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -64,7 +64,7 @@ abstract class Netmails extends Notification //implements ShouldQueue
|
||||
$o->flags = (Message::FLAG_LOCAL|Message::FLAG_PRIVATE);
|
||||
$o->cost = 0;
|
||||
|
||||
$o->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
|
||||
$o->set_tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ class AddressLink extends Netmails
|
||||
));
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'Address Linking...';
|
||||
$o->set_tagline = 'Address Linking...';
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -55,7 +55,7 @@ class Areafix extends Netmails
|
||||
$msg->addText($this->message_path($this->mo));
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'Why did the robot cross the road? The chicken programmed it.';
|
||||
$o->set_tagline = 'Why did the robot cross the road? The chicken programmed it.';
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -55,7 +55,7 @@ class NotConfiguredHere extends Netmails
|
||||
$msg->addText($this->message_path($this->mo));
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'Why did the robot cross the road? The chicken programmed it.';
|
||||
$o->set_tagline = 'Why did the robot cross the road? The chicken programmed it.';
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -63,7 +63,7 @@ class EchoareaNoWrite extends Netmails
|
||||
$msg->addText($this->message_path($this->mo));
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'See something wrong? Do something right.';
|
||||
$o->set_tagline = 'See something wrong? Do something right.';
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -65,7 +65,7 @@ class EchoareaNotExist extends Netmails
|
||||
$msg->addText($this->message_path($this->mo));
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'Don\'t let your trash become someone else\'s treasure. Feed your shredder often.';
|
||||
$o->set_tagline = 'Don\'t let your trash become someone else\'s treasure. Feed your shredder often.';
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -64,7 +64,7 @@ class EchoareaNotSubscribed extends Netmails
|
||||
$msg->addText($this->message_path($this->mo));
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'Don\'t let your trash become someone else\'s treasure. Feed your shredder.';
|
||||
$o->set_tagline = 'Don\'t let your trash become someone else\'s treasure. Feed your shredder.';
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -64,7 +64,7 @@ class EchomailBadAddress extends Netmails
|
||||
$msg->addText($this->message_path($this->mo));
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'I enjoyed reading your message, even though nobody else will get it :)';
|
||||
$o->set_tagline = 'I enjoyed reading your message, even though nobody else will get it :)';
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -61,7 +61,7 @@ class NetmailForward extends Netmails
|
||||
$msg->addText(sprintf("To avoid receiving this netmail, send messages to [%s] to [%s].\r\r",$this->mo->to,$this->ao->ftn3d));
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'Thank you so much for your mail. I love it already.';
|
||||
$o->set_tagline = 'Thank you so much for your mail. I love it already.';
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -64,7 +64,7 @@ class NetmailHubNoUser extends Netmails
|
||||
$msg->addText($this->message_path($this->mo));
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'Do you think it was fate which brought us together? Nah, bad luck :(';
|
||||
$o->set_tagline = 'Do you think it was fate which brought us together? Nah, bad luck :(';
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -50,7 +50,7 @@ class NodeDelisted extends Netmails //implements ShouldQueue
|
||||
->addText(sprintf('If you think about returning to %s, then reach out and we can get you back online pretty quickly.',$x));
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'You\'ve been DE-LISTED';
|
||||
$o->set_tagline = 'You\'ve been DE-LISTED';
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -55,7 +55,7 @@ class NodeMarkedDown extends Netmails //implements ShouldQueue
|
||||
->addText("If you think you've received this netmail by mistake or need help, please let me know.\r");
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'Pending de-list';
|
||||
$o->set_tagline = 'Pending de-list';
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -55,7 +55,7 @@ class NodeMarkedHold extends Netmails //implements ShouldQueue
|
||||
->addText("If you think you've received this netmail by mistake or need help, please let me know.\r");
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'You\'ve been marked HOLD';
|
||||
$o->set_tagline = 'You\'ve been marked HOLD';
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -62,7 +62,7 @@ class PacketPasswordInvalid extends Netmails
|
||||
$msg->addText("Head over to the website if you dont know what your packet password should be :)\r");
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'Safety first, password second.';
|
||||
$o->set_tagline = 'Safety first, password second.';
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -63,7 +63,7 @@ class Ping extends Netmails
|
||||
$msg->addText($this->message_path($this->mo));
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'My ping pong opponent was not happy with my serve. He kept returning it.';
|
||||
$o->set_tagline = 'My ping pong opponent was not happy with my serve. He kept returning it.';
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -47,7 +47,7 @@ class PollingFailed extends Netmails
|
||||
$msg->addText("To fix this, update your details that I use in the web interface, or change your system to HOLD while you are there.\r\r");
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'Painful? We can make that painless :)';
|
||||
$o->set_tagline = 'Painful? We can make that painless :)';
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -40,7 +40,7 @@ class Test extends Netmails
|
||||
);
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->tagline = 'Testing, testing, 1 2 3.';
|
||||
$o->set_tagline = 'Testing, testing, 1 2 3.';
|
||||
|
||||
$o->save();
|
||||
|
||||
|
@ -11,7 +11,7 @@ use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
use App\Classes\FTN\Message;
|
||||
use App\Models\{Address,Echomail};
|
||||
use App\Models\{Address,Echomail,Origin,Tagline,Tearline};
|
||||
|
||||
trait MessageAttributes
|
||||
{
|
||||
@ -28,26 +28,35 @@ trait MessageAttributes
|
||||
$this->set = collect();
|
||||
}
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function fftn()
|
||||
{
|
||||
return $this
|
||||
->belongsTo(Address::class)
|
||||
->withTrashed();
|
||||
}
|
||||
|
||||
public function origin()
|
||||
{
|
||||
return $this->belongsTo(Origin::class);
|
||||
}
|
||||
|
||||
public function tagline()
|
||||
{
|
||||
return $this->belongsTo(Tagline::class);
|
||||
}
|
||||
|
||||
public function tearline()
|
||||
{
|
||||
return $this->belongsTo(Tearline::class);
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getContentAttribute(): string
|
||||
{
|
||||
if ($this->msg_src)
|
||||
return $this->msg_src;
|
||||
|
||||
// If we have a msg_src attribute, we'll use that
|
||||
$result = $this->msg."\r\r";
|
||||
|
||||
if ($this->tagline)
|
||||
$result .= sprintf("%s\r",$this->tagline);
|
||||
|
||||
if ($this->tearline)
|
||||
$result .= sprintf("%s\r",$this->tearline);
|
||||
|
||||
if ($this->origin)
|
||||
$result .= sprintf("%s",$this->origin);
|
||||
|
||||
return rtrim($result,"\r");
|
||||
return ($this->msg_src) ? $this->msg_src : $this->rebuildMessage();
|
||||
}
|
||||
|
||||
public function getDateAttribute(): Carbon
|
||||
@ -57,38 +66,35 @@ trait MessageAttributes
|
||||
|
||||
public function getOriginAttribute(string $val=NULL): ?string
|
||||
{
|
||||
if ($this->exists && (! $val))
|
||||
return $val;
|
||||
if (($x=$this->getRelationValue('origin')) && $x->value)
|
||||
return $x->complete($this->fftn);
|
||||
|
||||
// If $val is not set, then it may be an unsaved object
|
||||
return sprintf(' * Origin: %s',
|
||||
((! $this->exists) && $this->set->has('set_origin'))
|
||||
? $this->set->get('set_origin')
|
||||
: $val);
|
||||
if (($this->set->has('set_origin')) || ($val))
|
||||
return sprintf(' * Origin: %s',$this->set->get('set_origin',$val));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function getTaglineAttribute(string $val=NULL): ?string
|
||||
{
|
||||
if ($this->exists && (! $val))
|
||||
return $val;
|
||||
if (($x=$this->getRelationValue('tagline')) && $x->value)
|
||||
return $x->complete();
|
||||
|
||||
// If $val is not set, then it may be an unsaved object
|
||||
return sprintf('... %s',
|
||||
((! $this->exists) && $this->set->has('set_tagline'))
|
||||
? $this->set->get('set_tagline')
|
||||
: $val);
|
||||
if (($this->set->has('set_tagline')) || ($val))
|
||||
return sprintf('... %s',$this->set->get('set_tagline',$val));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function getTearlineAttribute(string $val=NULL): ?string
|
||||
{
|
||||
if ($this->exists && (! $val))
|
||||
return $val;
|
||||
if (($x=$this->getRelationValue('tearline')) && $x->value)
|
||||
return $x->complete();
|
||||
|
||||
// If $val is not set, then it may be an unsaved object
|
||||
return sprintf('--- %s',
|
||||
((! $this->exists) && $this->set->has('set_tearline'))
|
||||
? $this->set->get('set_tearline')
|
||||
: $val);
|
||||
if (($this->set->has('set_tearline')) || ($val))
|
||||
return sprintf('--- %s',$this->set->get('set_tearline',$val));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
@ -164,6 +170,23 @@ trait MessageAttributes
|
||||
return Message::packMessage($this);
|
||||
}
|
||||
|
||||
public function rebuildMessage(): string
|
||||
{
|
||||
// If we have a msg_src attribute, we'll use that
|
||||
$result = $this->msg."\r";
|
||||
|
||||
if ($x=$this->tagline)
|
||||
$result .= sprintf("%s\r",$x);
|
||||
|
||||
if ($x=$this->tearline)
|
||||
$result .= sprintf("%s\r",$x);
|
||||
|
||||
if ($x=$this->origin)
|
||||
$result .= sprintf("%s",$x);
|
||||
|
||||
return rtrim($result,"\r");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return our path in order
|
||||
*
|
||||
|
81
database/migrations/2024_06_03_072631_msg_attributes.php
Normal file
81
database/migrations/2024_06_03_072631_msg_attributes.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('taglines', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->timestamp('created_at');
|
||||
$table->softDeletes();
|
||||
$table->string('value')->unique();
|
||||
});
|
||||
|
||||
Schema::create('tearlines', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->timestamp('created_at');
|
||||
$table->softDeletes();
|
||||
$table->string('value')->unique();
|
||||
});
|
||||
|
||||
Schema::create('origins', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->timestamp('created_at');
|
||||
$table->softDeletes();
|
||||
$table->string('value')->unique();
|
||||
});
|
||||
|
||||
Schema::table('echomails', function (Blueprint $table) {
|
||||
$table->bigInteger('tagline_id')->nullable();
|
||||
$table->foreign('tagline_id')->references('id')->on('taglines');
|
||||
|
||||
$table->bigInteger('tearline_id')->nullable();
|
||||
$table->foreign('tearline_id')->references('id')->on('tearlines');
|
||||
|
||||
$table->bigInteger('origin_id')->nullable();
|
||||
$table->foreign('origin_id')->references('id')->on('origins');
|
||||
});
|
||||
|
||||
Schema::table('netmails', function (Blueprint $table) {
|
||||
$table->bigInteger('tagline_id')->nullable();
|
||||
$table->foreign('tagline_id')->references('id')->on('taglines');
|
||||
|
||||
$table->bigInteger('tearline_id')->nullable();
|
||||
$table->foreign('tearline_id')->references('id')->on('tearlines');
|
||||
|
||||
$table->bigInteger('origin_id')->nullable();
|
||||
$table->foreign('origin_id')->references('id')->on('origins');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('netmails', function (Blueprint $table) {
|
||||
$table->dropForeign(['tagline_id']);
|
||||
$table->dropForeign(['tearline_id']);
|
||||
$table->dropForeign(['origin_id']);
|
||||
$table->dropColumn(['tagline_id','tearline_id','origin_id']);
|
||||
});
|
||||
|
||||
Schema::table('echomails', function (Blueprint $table) {
|
||||
$table->dropForeign(['tagline_id']);
|
||||
$table->dropForeign(['tearline_id']);
|
||||
$table->dropForeign(['origin_id']);
|
||||
$table->dropColumn(['tagline_id','tearline_id','origin_id']);
|
||||
});
|
||||
|
||||
Schema::dropIfExists('origins');
|
||||
Schema::dropIfExists('tearlines');
|
||||
Schema::dropIfExists('taglines');
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user