Enable us to create an outbound packet without updating send details. Determine the send address for packets earlier

This commit is contained in:
Deon George
2022-01-20 17:54:02 +11:00
parent d930c410dc
commit 421cd565bd
2 changed files with 38 additions and 24 deletions

View File

@@ -371,9 +371,10 @@ class Address extends Model
/**
* Get echomail for this node
*
* @param bool $update
* @return Packet|null
*/
public function getEchomail(): ?Packet
public function getEchomail(bool $update=TRUE): ?Packet
{
$pkt = NULL;
@@ -382,13 +383,14 @@ class Address extends Model
{
$pkt = $this->getPacket($x);
DB::table('echomail_seenby')
->whereIn('echomail_id',$x->pluck('id'))
->where('address_id',$this->id)
->whereNull('sent_at')
->whereNull('packet')
->whereNotNull('echomail_seenby.export_at')
->update(['sent_at'=>Carbon::now(),'packet'=>$pkt->name]);
if ($pkt && $pkt->count() && $update)
DB::table('echomail_seenby')
->whereIn('echomail_id',$x->pluck('id'))
->where('address_id',$this->id)
->whereNull('sent_at')
->whereNull('packet')
->whereNotNull('echomail_seenby.export_at')
->update(['sent_at'=>Carbon::now(),'packet'=>$pkt->name]);
}
return $pkt;
@@ -397,9 +399,10 @@ class Address extends Model
/**
* Get netmail for this node (including it's children)
*
* @param bool $update
* @return Packet|null
*/
public function getNetmail(): ?Packet
public function getNetmail(bool $update=TRUE): ?Packet
{
$pkt = NULL;
@@ -408,9 +411,10 @@ class Address extends Model
{
$pkt = $this->getPacket($x);
DB::table('netmails')
->whereIn('id',$x->pluck('id'))
->update(['sent_at'=>Carbon::now(),'sent_pkt'=>$pkt->name]);
if ($pkt && $pkt->count() && $update)
DB::table('netmails')
->whereIn('id',$x->pluck('id'))
->update(['sent_at'=>Carbon::now(),'sent_pkt'=>$pkt->name]);
}
return $pkt;
@@ -422,9 +426,15 @@ class Address extends Model
* @param Collection $c
* @return Packet
*/
private function getPacket(Collection $c): Packet
private function getPacket(Collection $c): ?Packet
{
$o = new Packet($this);
$ao = Setup::findOrFail(config('app.id'))->system->match($this->zone)->first();
// If we dont match on the address, we cannot pack mail for that system
if (! $ao)
return NULL;
$o = new Packet($ao,$this);
foreach ($c as $oo)
$o->addMail($oo->packet($this));