2024-05-25 12:25:57 +00:00
< ? php
namespace App\Notifications\Echomails ;
use Carbon\Carbon ;
use Illuminate\Support\Collection ;
use Illuminate\Support\Facades\Log ;
use App\Classes\ { Fonts\Thick , Page };
use App\Models\ { Address , Echomail , Setup };
use App\Notifications\Echomails ;
use App\Traits\MessagePath ;
class AbsentNodes extends Echomails
{
use MessagePath ;
private const LOGKEY = 'NNP' ;
private Echomail $mo ;
/**
2024-06-09 23:19:21 +00:00
* Report on nodes that are have been marked Idle .
2024-05-25 12:25:57 +00:00
*/
public function __construct ( private Collection $aos )
{
parent :: __construct ();
}
/**
* Get the mail representation of the notification .
*
* @ param mixed $notifiable
* @ return Echomail
* @ throws \Exception
*/
public function toEchomail ( object $notifiable ) : Echomail
{
$echoarea = $notifiable -> routeNotificationFor ( static :: via );
$o = $this -> setupEchomail ( $echoarea );
$now = Carbon :: now ();
Log :: info ( sprintf ( '%s:+ Creating NODE ABSENT echomail in [%s]' , self :: LOGKEY , $echoarea -> name ));
2024-06-06 23:30:40 +00:00
$our = our_address ( $echoarea -> domain ) -> last ();
2024-05-25 12:25:57 +00:00
$o -> to = 'All' ;
$o -> subject = 'Status changes for nodes' ;
2024-06-06 23:30:40 +00:00
$o -> fftn_id = $our -> id ;
2024-05-25 12:25:57 +00:00
$o -> kludges -> put ( 'CHRS:' , 'CP437 2' );
// Message
$msg = new Page ;
$header = new Thick ;
$header -> addText ( 'Clearing Houz' );
$msg -> addHeader ( $header , 'FTN Mailer and Tosser' , TRUE , 0xc4 );
$msg -> addText ( " The following nodes have had their status changed, because they are absent from the network. \r \r " );
// Nodes marked HOLD - will be marked down ...
2024-09-08 10:39:10 +00:00
if (( $x = $this -> aos -> filter ( fn ( $item ) => $item -> active && ( $item -> role & Address :: NODE_HOLD ))) -> count ()) {
2024-05-26 12:01:35 +00:00
$msg -> addText ( " The following nodes have been marked HOLD: \r " );
foreach ( $x as $ao )
2024-09-15 12:00:40 +00:00
$msg -> addText ( sprintf ( '* %s (%s), last seen %d days ago' , $ao -> ftn4d , $ao -> system -> name , $ao -> system -> last_seen ? -> diffInDays ( $now )) . ( $ao -> contacted ? '' : ' ^' ) . " \r " );
2024-05-26 12:01:35 +00:00
$msg -> addText ( " \r " );
}
2024-05-25 12:25:57 +00:00
// Nodes marked DOWN - will be delisted on...
2024-09-08 10:39:10 +00:00
if (( $x = $this -> aos -> filter ( fn ( $item ) => $item -> active && ( $item -> role & Address :: NODE_DOWN ))) -> count ()) {
2024-05-26 12:01:35 +00:00
$msg -> addText ( " The following nodes have been marked DOWN: \r " );
foreach ( $x as $ao )
2024-09-15 12:00:40 +00:00
$msg -> addText ( sprintf ( '* %s (%s), last seen %d days ago' , $ao -> ftn4d , $ao -> system -> name , $ao -> system -> last_seen ? -> diffInDays ( $now )) . ( $ao -> contacted ? '' : ' ^' ) . " \r " );
2024-05-26 12:01:35 +00:00
$msg -> addText ( " \r " );
}
2024-05-25 12:25:57 +00:00
// Nodes DELISTED
2024-05-26 12:01:35 +00:00
if (( $x = $this -> aos -> filter ( fn ( $item ) =>! $item -> active )) -> count ()) {
$msg -> addText ( " The following nodes have been DE-LISTED: \r " );
foreach ( $x as $ao )
2024-09-15 12:00:40 +00:00
$msg -> addText ( sprintf ( '* %s (%s), last seen %d days ago' , $ao -> ftn4d , $ao -> system -> name , $ao -> system -> last_seen ? -> diffInDays ( $now )) . ( $ao -> contacted ? '' : ' ^' ) . " \r " );
2024-05-26 12:01:35 +00:00
$msg -> addText ( " \r " );
}
2024-05-25 12:25:57 +00:00
if ( $this -> aos -> filter ( fn ( $item ) => ( ! $item -> contacted )) -> count ())
2024-05-26 12:01:35 +00:00
$msg -> addText ( " ^ Unable to contact these nodes. \r " );
2024-05-25 12:25:57 +00:00
$msg -> addText ( " \r Emails 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 ();
2024-06-03 09:08:40 +00:00
$o -> set_tagline = 'When life gives you lemons, freeze them and throw them back.' ;
2024-06-06 23:30:40 +00:00
$o -> set_origin = sprintf ( '%s (%s)' , Setup :: PRODUCT_NAME , $our -> ftn4d );
2024-05-25 12:25:57 +00:00
$o -> save ();
return $o ;
}
}