Sending Mail now dynamically creates packet name, size and mtime

This commit is contained in:
Deon George 2023-07-14 20:03:09 +10:00
parent 28101237e8
commit 7bf957df3a
5 changed files with 35 additions and 13 deletions

View File

@ -215,6 +215,11 @@ class Message extends FTNBase
$this->unknown = collect(); $this->unknown = collect();
} }
// Fix for a call to pluck('date') (which is resolved via __get()), but it returns false.
public function __isset($key) {
return (bool)$this->{$key};
}
public function __get($key) public function __get($key)
{ {
switch ($key) { switch ($key) {

View File

@ -13,7 +13,7 @@ use App\Classes\FTN as FTNBase;
use App\Models\{Address,Software,System,Zone}; use App\Models\{Address,Software,System,Zone};
/** /**
* Represents the structure of a packet * Represents the structure of a message bundle
*/ */
class Packet extends FTNBase implements \Iterator, \Countable class Packet extends FTNBase implements \Iterator, \Countable
{ {
@ -398,7 +398,7 @@ class Packet extends FTNBase implements \Iterator, \Countable
} }
/** /**
* Add a netmail message to this packet * Add a message to this packet
* *
* @param Message $o * @param Message $o
*/ */

View File

@ -18,9 +18,6 @@ class Mail extends Item
switch ($action) { switch ($action) {
case self::I_SEND: case self::I_SEND:
$this->file = $mail; $this->file = $mail;
$this->file_name = sprintf('%s.pkt',$mail->name);
$this->file_size = strlen($mail);
$this->file_mtime = Carbon::now()->timestamp; // @todo This timestamp should be consistent incase of retries
break; break;
@ -31,8 +28,21 @@ class Mail extends Item
$this->action = $action; $this->action = $action;
} }
public function __get($key) {
switch ($key) {
case 'file': return $this->file;
default:
return parent::__get($key);
}
}
public function read(int $start,int $length): string public function read(int $start,int $length): string
{ {
return substr((string)$this->file,$start,$length); return substr((string)$this->file,$start,$length);
} }
public function youngest(): Carbon
{
return $this->file->messages->pluck('date')->sort()->last();
}
} }

View File

@ -70,12 +70,18 @@ final class Send extends Item
+ $this->packets->sum(function($item) { return $item->size; }); + $this->packets->sum(function($item) { return $item->size; });
case 'sendas': case 'sendas':
return $this->sending ? $this->sending->{$key} : NULL; return $this->sending?->{$key};
case 'name': // The mtime is the time of the youngest message in the packet for the sending packet
case 'mtime': case 'mtime':
return $this->sending?->youngest()->timestamp;
// The name is derived from the youngest message in the packet
case 'name':
return sprintf('%08x',timew($this->sending?->youngest()));
case 'size': case 'size':
return $this->sending ? $this->sending->{'file_'.$key} : NULL; return strlen($this->sending?->file);
case 'total_sent': case 'total_sent':
return $this->list return $this->list
@ -297,7 +303,7 @@ final class Send extends Item
* @throws Exception * @throws Exception
* @todo We need to make this into a transaction, incase the transfer fails. * @todo We need to make this into a transaction, incase the transfer fails.
*/ */
public function mail(Address $ao): bool public function mail(Address $ao,bool $update=TRUE): bool
{ {
$mail = FALSE; $mail = FALSE;
@ -309,7 +315,7 @@ final class Send extends Item
} }
// Netmail // Netmail
if ($x=$ao->getNetmail()) { if ($x=$ao->getNetmail($update)) {
Log::debug(sprintf('%s: - Netmail(s) added for sending to [%s]',self::LOGKEY,$ao->ftn)); Log::debug(sprintf('%s: - Netmail(s) added for sending to [%s]',self::LOGKEY,$ao->ftn));
$this->packets->push(new Mail($x,self::I_SEND)); $this->packets->push(new Mail($x,self::I_SEND));
@ -317,7 +323,7 @@ final class Send extends Item
} }
// Echomail // Echomail
if ($x=$ao->getEchomail()) { if ($x=$ao->getEchomail($update)) {
Log::debug(sprintf('%s: - Echomail(s) added for sending to [%s]',self::LOGKEY,$ao->ftn)); Log::debug(sprintf('%s: - Echomail(s) added for sending to [%s]',self::LOGKEY,$ao->ftn));
$this->packets->push(new Mail($x,self::I_SEND)); $this->packets->push(new Mail($x,self::I_SEND));

View File

@ -31,7 +31,7 @@ class ServerStart extends Command
/** /**
* Execute the console command. * Execute the console command.
* *
* @return mixed * @return void
* @throws \Exception * @throws \Exception
*/ */
public function handle() public function handle()
@ -71,6 +71,7 @@ class ServerStart extends Command
if (! $start->count()) { if (! $start->count()) {
Log::alert(sprintf('%s:- No servers configured to start',self::LOGKEY)); Log::alert(sprintf('%s:- No servers configured to start',self::LOGKEY));
return; return;
} }