NodesNew also now sends an Echomail
This commit is contained in:
parent
f4ee2e1a51
commit
46cf488337
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
@ -19,7 +20,9 @@ class AddressIdleDomain implements ShouldQueue
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
foreach (Domain::whereNotNull('nodestatus_id')->cursor() as $do)
|
||||
foreach (Domain::whereNotNull('nodestatus_id')->cursor() as $do) {
|
||||
AddressIdle::dispatch($do);
|
||||
NodesNew::dispatch($do,Carbon::now()->subWeek()->startOfDay());
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,8 @@ use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
use App\Models\{Address,Domain};
|
||||
use App\Notifications\Netmails\NodesNew as NotificationNodesNew;
|
||||
use App\Notifications\Echomails\NodesNew as NodesNewEchomail;
|
||||
use App\Notifications\Netmails\NodesNew as NodesNewNetmail;
|
||||
|
||||
class NodesNew implements ShouldQueue
|
||||
{
|
||||
@ -21,7 +22,7 @@ class NodesNew implements ShouldQueue
|
||||
private const LOGKEY = 'JNN';
|
||||
|
||||
private ?Carbon $since; // New nodes since this date
|
||||
private Address $ao; // Domain we are processing
|
||||
private ?Address $ao; // Domain we are processing
|
||||
private Domain $do; // Domain we are processing
|
||||
|
||||
/**
|
||||
@ -39,7 +40,7 @@ class NodesNew implements ShouldQueue
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$since = ($this->since ?: Carbon::parse('last saturday'))->startOfDay();
|
||||
$since = ($this->since ?: Carbon::parse('last monday'))->startOfDay();
|
||||
|
||||
$result = Address::FTN()
|
||||
->ActiveFTN()
|
||||
@ -48,18 +49,19 @@ class NodesNew implements ShouldQueue
|
||||
->join('system_zone',['system_zone.system_id'=>'systems.id','system_zone.zone_id'=>'zones.id'])
|
||||
->whereIn('zones.id',$this->do->zones->pluck('id'))
|
||||
->where('systems.active',TRUE)
|
||||
->where('systems.created_at','>=',$since)
|
||||
->where('addresses.created_at','>=',$since)
|
||||
->orderBy('addresses.created_at')
|
||||
->get();
|
||||
|
||||
if ($result->count()) {
|
||||
Log::notice(sprintf('%s:- Sending new nodes since [%s] (%d)',self::LOGKEY,$since,$result->count()));
|
||||
|
||||
if ($this->ao)
|
||||
Notification::route('netmail',$this->ao->withoutRelations())
|
||||
->notify(new NotificationNodesNew(
|
||||
$since,
|
||||
$result,
|
||||
));
|
||||
->notify(new NodesNewNetmail($since,$result));
|
||||
else
|
||||
Notification::route('echomail',$this->do->nodestatus_echoarea)
|
||||
->notify(new NodesNewEchomail($since,$result));
|
||||
|
||||
} else
|
||||
Log::notice(sprintf('%s:- No nodes since [%s]',self::LOGKEY,$since));
|
||||
|
114
app/Notifications/Echomails/NodesNew.php
Normal file
114
app/Notifications/Echomails/NodesNew.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Echomails;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Notifications\Echomails;
|
||||
use App\Models\{Address,Echomail};
|
||||
use App\Traits\PageTemplate;
|
||||
|
||||
class NodesNew extends Echomails //implements ShouldQueue
|
||||
{
|
||||
use Queueable,PageTemplate;
|
||||
|
||||
private const LOGKEY = 'NNN';
|
||||
|
||||
private Carbon $since;
|
||||
private Collection $list;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct(Carbon $since,Collection $list)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->list = $list;
|
||||
$this->since = $since;
|
||||
}
|
||||
|
||||
public function toEchomail(object $notifiable): Echomail
|
||||
{
|
||||
$echoarea = $notifiable->routeNotificationFor(static::via);
|
||||
$o = $this->setupEchomail($echoarea);
|
||||
|
||||
Log::info(sprintf('%s:+ Sending a NEW NODE LIST to echoarea [%s]',self::LOGKEY,$echoarea->name));
|
||||
|
||||
$o->subject = sprintf('Here is a list of new nodes on clrghouz since %s',$this->since->format('Y-m-d'));
|
||||
|
||||
$our = our_address($echoarea->domain)->last();
|
||||
$o->to = 'All';
|
||||
$o->subject = 'New nodes to '.$echoarea->domain->name;
|
||||
$o->fftn_id = $our->id;
|
||||
$o->kludges->put('CHRS:','CP437 2');
|
||||
|
||||
$o->msg = $this->report();
|
||||
$o->set_tagline = 'All aboard!';
|
||||
|
||||
$o->save();
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the rendered new nodes report.
|
||||
*/
|
||||
public function report(): string
|
||||
{
|
||||
// Message
|
||||
$msg = $this->page(FALSE,'new nodes');
|
||||
|
||||
$msg->addText("Hi Everyone,\r\r")
|
||||
->addText(sprintf("The following new system have been defined on clrghouz since %s.\r\r",$this->since->format('Y-m-d')));
|
||||
|
||||
$this->list->loadMissing(['system']);
|
||||
|
||||
$space = str_repeat(' ',$this->list->pluck('ftn4d')->max(fn($item)=>strlen($item))+2);
|
||||
|
||||
$c = 0;
|
||||
foreach ($this->list as $oo) {
|
||||
if ($c++)
|
||||
$msg->addText("\r");
|
||||
|
||||
$msg->addText(sprintf("* %s - %s (%s) from %s.\r",$oo->ftn4D,$oo->system->sysop,$oo->system->name,$oo->system->location));
|
||||
$msg->addText(sprintf("%s Address registered: %s\r\r",$space,$oo->created_at->format('Y-m-d')));
|
||||
|
||||
if ($oo->system->method) {
|
||||
switch ($oo->system->method) {
|
||||
case 23:
|
||||
$msg->addText(sprintf("%s - BBS is available TELNET [%s:%d]\r",$space,$oo->system->address,$oo->system->port));
|
||||
break;
|
||||
|
||||
case 22:
|
||||
$msg->addText(sprintf("%s - BBS is available SSH [%s:%d]\r",$space,$oo->system->address,$oo->system->port));
|
||||
break;
|
||||
|
||||
case 519:
|
||||
$msg->addText(sprintf("%s - BBS is available RLOGIN [%s:%d]\r",$space,$oo->system->address,$oo->system->port));
|
||||
break;
|
||||
|
||||
default:
|
||||
$msg->addText(sprintf("%s - No Details available for connecting to BBS\r",$space));
|
||||
}
|
||||
}
|
||||
|
||||
if ($oo->system->mailers->count()) {
|
||||
$msg->addText("\r");
|
||||
$msg->addText(sprintf("%s - Mail can be sent using:\r",$space));
|
||||
|
||||
foreach ($oo->system->mailers as $mo) {
|
||||
$msg->addText(sprintf("%s * %s [%s:%d]\r",$space,$mo->name,$oo->system->address,$mo->pivot->port));
|
||||
}
|
||||
|
||||
} else {
|
||||
$msg->addText(sprintf("%s - No mailer information provided, so will be PRIVATE\r",$space));
|
||||
}
|
||||
}
|
||||
|
||||
return $msg->render();
|
||||
}
|
||||
}
|
@ -32,9 +32,6 @@ class NodesNew extends Netmails //implements ShouldQueue
|
||||
$this->since = $since;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*/
|
||||
public function toNetmail(object $notifiable): Netmail
|
||||
{
|
||||
$o = $this->setupNetmail($notifiable);
|
||||
@ -42,14 +39,27 @@ class NodesNew extends Netmails //implements ShouldQueue
|
||||
|
||||
Log::info(sprintf('%s:+ Sending a NEW NODE LIST to [%s] at address [%s]',self::LOGKEY,$ao->system->sysop,$ao->ftn));
|
||||
|
||||
$o->subject = sprintf('Here is a list of new nodes on clrghouz since %s',$x=$this->since->format('Y-m-d'));
|
||||
$o->subject = sprintf('Here is a list of new nodes on clrghouz since %s',$this->since->format('Y-m-d'));
|
||||
$o->flags = (Message::FLAG_LOCAL|Message::FLAG_PRIVATE|Message::FLAG_CRASH);
|
||||
|
||||
$o->msg = $this->report($ao);
|
||||
$o->set_tagline = 'All aboard!';
|
||||
|
||||
$o->save();
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the rendered new nodes report.
|
||||
*/
|
||||
public function report(Address $ao): string
|
||||
{
|
||||
// Message
|
||||
$msg = $this->page(FALSE,'new nodes');
|
||||
|
||||
$msg->addText(sprintf("Hi %s,\r\r",$ao->system->sysop))
|
||||
->addText(sprintf("The following new system have been defined on clrghouz since %s.\r\r",$x));
|
||||
->addText(sprintf("The following new system have been defined on clrghouz since %s.\r\r",$this->since->format('Y-m-d')));
|
||||
|
||||
$this->list->loadMissing(['system']);
|
||||
|
||||
@ -95,11 +105,6 @@ class NodesNew extends Netmails //implements ShouldQueue
|
||||
}
|
||||
}
|
||||
|
||||
$o->msg = $msg->render();
|
||||
$o->set_tagline = 'All aboard!';
|
||||
|
||||
$o->save();
|
||||
|
||||
return $o;
|
||||
return $msg->render();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user