diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index 9f4e03b..da9e09f 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -215,6 +215,11 @@ class Message extends FTNBase $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) { switch ($key) { diff --git a/app/Classes/FTN/Packet.php b/app/Classes/FTN/Packet.php index 5cd53f8..a0b40a7 100644 --- a/app/Classes/FTN/Packet.php +++ b/app/Classes/FTN/Packet.php @@ -13,7 +13,7 @@ use App\Classes\FTN as FTNBase; 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 { @@ -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 */ diff --git a/app/Classes/File/Mail.php b/app/Classes/File/Mail.php index d3d8b2a..7826446 100644 --- a/app/Classes/File/Mail.php +++ b/app/Classes/File/Mail.php @@ -18,9 +18,6 @@ class Mail extends Item switch ($action) { case self::I_SEND: $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; @@ -31,8 +28,21 @@ class Mail extends Item $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 { return substr((string)$this->file,$start,$length); } + + public function youngest(): Carbon + { + return $this->file->messages->pluck('date')->sort()->last(); + } } \ No newline at end of file diff --git a/app/Classes/File/Send.php b/app/Classes/File/Send.php index b0b438f..0662928 100644 --- a/app/Classes/File/Send.php +++ b/app/Classes/File/Send.php @@ -70,12 +70,18 @@ final class Send extends Item + $this->packets->sum(function($item) { return $item->size; }); 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': + 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': - return $this->sending ? $this->sending->{'file_'.$key} : NULL; + return strlen($this->sending?->file); case 'total_sent': return $this->list @@ -297,7 +303,7 @@ final class Send extends Item * @throws Exception * @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; @@ -309,7 +315,7 @@ final class Send extends Item } // 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)); $this->packets->push(new Mail($x,self::I_SEND)); @@ -317,7 +323,7 @@ final class Send extends Item } // 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)); $this->packets->push(new Mail($x,self::I_SEND)); diff --git a/app/Console/Commands/ServerStart.php b/app/Console/Commands/ServerStart.php index d6f3764..2324287 100644 --- a/app/Console/Commands/ServerStart.php +++ b/app/Console/Commands/ServerStart.php @@ -31,7 +31,7 @@ class ServerStart extends Command /** * Execute the console command. * - * @return mixed + * @return void * @throws \Exception */ public function handle() @@ -67,10 +67,11 @@ class ServerStart extends Command $children = collect(); - Log::debug(sprintf('%s: # Servers [%d]',self::LOGKEY,$start->count())); + Log::debug(sprintf('%s:# Servers [%d]',self::LOGKEY,$start->count())); if (! $start->count()) { Log::alert(sprintf('%s:- No servers configured to start',self::LOGKEY)); + return; }