Just optimisations

This commit is contained in:
Deon George
2019-05-20 17:18:18 +10:00
parent 9317f78a3a
commit df849c0cfd
12 changed files with 877 additions and 519 deletions

View File

@@ -56,7 +56,7 @@ class FtnPkt extends Command
$o->fqfa,
$o->to,
$o->fqda,
$o->description(),
$o->type,
strlen($o->message)
));

View File

@@ -90,7 +90,7 @@ class ImportNodelist extends Command
default:
$this->error(sprintf('Unhandled first field [%s]',$fields[0]));
$bar->advance();
continue;
continue 2;
}
if (! $zone)

View File

@@ -2,23 +2,22 @@
namespace App\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command;
use App\Traits\{GetNode,ParseNodes,ParseZNFPDomain};
use App\Traits\{GetNode,ParseNodes};
use App\Classes\FTNPacket;
use App\Models\{Echomail,Netmail,Zone};
class ImportPacket extends Command
{
use GetNode,ParseNodes,ParseZNFPDomain;
use GetNode,ParseNodes;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'import:pkt {file : Packet File}';
protected $signature = 'import:pkt {file : Packet File} {--f|force : Force import of duplicates}';
/**
* The console command description.
@@ -49,60 +48,78 @@ class ImportPacket extends Command
foreach ($pkt->messages as $o)
{
switch ($o->type())
$o->date->setTimezone(($o->tzutc >= 0 ? '+' : '').substr_replace($o->tzutc,':',2,0));
switch ($o->type)
{
case 'echomail':
$date = Carbon::createFromFormat('d M y H:i:s',$o->date,($o->tzutc >= 0 ? '+' : '').substr_replace($o->tzutc,':',2,0));
// See if we already have this message.
$eo = Echomail::firstOrNew([
'date'=>$date,
'from_ftn'=>$this->get_node($o->fz,$o->fn,$o->ff,$o->fp)->id,
$oo = Echomail::firstOrNew([
'date'=>$o->date,
'from_ftn'=>$this->get_node(['z'=>$o->fz,'n'=>$o->fn,'f'=>$o->ff,'p'=>$o->fp])->id,
'msgid'=>$o->msgid,
]);
if (md5(utf8_decode($eo->message)) == md5($o->message))
{
$this->warn(sprintf('Duplicate message: %s@%s with id: %s',$o->from,$o->fqfa,$o->msgid));
continue;
}
$oo->area = $o->echoarea;
$eo->pkt_from = $this->get_node($pkt->sz,$pkt->sn,$pkt->sf,$pkt->sp)->id;
$eo->pkt_to = $this->get_node($pkt->dz,$pkt->dn,$pkt->df,$pkt->dp)->id;
$eo->pkt = $pkt->filename;
$eo->pkt_date = $pkt->date;
break;
$eo->flags = $o->flags;
$eo->cost = $o->cost;
$eo->from_user = utf8_encode($o->from);
$eo->to_user = utf8_encode($o->to);
$eo->subject = utf8_encode($o->subject);
$eo->tz = $o->tzutc;
case 'netmail':
// See if we already have this message.
$oo = Netmail::firstOrNew([
'date'=>$o->date,
'from_ftn'=>$this->get_node(['z'=>$o->fz,'n'=>$o->fn,'f'=>$o->ff,'p'=>$o->fp])->id,
'msgid'=>$o->msgid,
]);
$eo->area = $o->echoarea;
$eo->replyid = $o->replyid;
$eo->message = utf8_encode($o->message);
$oo->to_ftn = $this->get_node(['z'=>$o->tz,'n'=>$o->tn,'f'=>$o->tf,'p'=>$o->tp])->id;
$eo->origin = utf8_encode($o->origin);
//$eo->original = (string)$o;
break;
$eo->save();
default:
abort(500,'Unknown type: '.$o->type);
}
foreach ($o->kludge as $k=>$v)
{
$eo->kludges()->attach($k,['value'=>json_encode($v)]);
}
if (md5(utf8_decode($oo->message)) == md5($o->message))
{
$this->warn(sprintf('Duplicate message: %s@%s with id: %s',$o->from,$o->fqfa,$o->msgid));
if (! $this->option('force'))
continue;
}
foreach ($o->unknown as $v)
{
$eo->kludges()->attach('UNKNOWN',['value'=>json_encode($v)]);
}
$oo->pkt_from = $this->get_node(['z'=>$pkt->sz,'n'=>$pkt->sn,'f'=>$pkt->sf,'p'=>$pkt->sp])->id;
$oo->pkt_to = $this->get_node(['z'=>$pkt->dz,'n'=>$pkt->dn,'f'=>$pkt->df,'p'=>$pkt->dp])->id;
$oo->pkt = $pkt->filename;
$oo->pkt_date = $pkt->date;
$oo->flags = $o->flags;
$oo->cost = $o->cost;
$oo->from_user = utf8_encode($o->from);
$oo->to_user = utf8_encode($o->to);
$oo->subject = utf8_encode($o->subject);
$oo->tz = $o->tzutc;
$oo->replyid = $o->replyid;
$oo->message = utf8_encode($o->message);
$oo->origin = utf8_encode($o->origin);
$oo->save();
foreach ($o->kludge as $k=>$v)
{
$oo->kludges()->attach($k,['value'=>json_encode($v)]);
}
foreach ($o->unknown as $v)
{
$oo->kludges()->attach('UNKNOWN',['value'=>json_encode($v)]);
}
// Finish off the import
switch($o->type) {
case 'echomail':
foreach ($o->seenby as $v)
{
foreach ($this->parse_nodes(Zone::findOrFail($pkt->sz),$v) as $no)
{
$eo->seenbys()->attach($no->id);
$oo->seenbys()->attach($no->id);
}
}
@@ -111,71 +128,25 @@ class ImportPacket extends Command
{
foreach ($this->parse_nodes(Zone::findOrFail($pkt->sz),$v) as $no)
{
$eo->paths()->attach($no->id,['sequence'=>$seq++]);
$oo->paths()->attach($no->id,['sequence'=>$seq++]);
}
}
break;
case 'netmail':
$date = Carbon::createFromFormat('d M y H:i:s',$o->date,($o->tzutc >= 0 ? '+' : '').substr_replace($o->tzutc,':',2,0));
// See if we already have this message.
$no = Netmail::firstOrNew([
'date'=>$date,
'from_ftn'=>$this->get_node($o->fz,$o->fn,$o->ff,$o->fp)->id,
'msgid'=>$o->msgid,
]);
if (md5(utf8_decode($no->message)) == md5($o->message))
{
$this->warn(sprintf('Duplicate message: %s@%s with id: %s',$o->from,$o->fqfa,$o->msgid));
//continue;
}
$no->pkt_from = $this->get_node($pkt->sz,$pkt->sn,$pkt->sf,$pkt->sp)->id;
$no->pkt_to = $this->get_node($pkt->dz,$pkt->dn,$pkt->df,$pkt->dp)->id;
$no->pkt = $pkt->filename;
$no->pkt_date = $pkt->date;
$no->flags = $o->flags;
$no->cost = $o->cost;
$no->from_user = utf8_encode($o->from);
$no->to_user = utf8_encode($o->to);
$no->to_ftn = $this->get_node($o->tz,$o->tn,$o->tf,$o->tp)->id;
$no->subject = utf8_encode($o->subject);
$no->tz = $o->tzutc;
$no->replyid = $o->replyid;
$no->message = utf8_encode($o->message);
$no->origin = utf8_encode($o->origin);
$no->save();
foreach ($o->kludge as $k=>$v)
{
$no->kludges()->attach($k,['value'=>json_encode($v)]);
}
foreach ($o->unknown as $v)
{
$no->kludges()->attach('UNKNOWN',['value'=>json_encode($v)]);
}
$seq = 0;
foreach ($o->via as $v)
{
dump($v);
$data = preg_split('/\s/',$v);
$ftno = $this->parse_znfp_domain($data[0]);
unset($data[0]);
$no->paths()->attach($ftno->id,['sequence'=>$seq++,'value'=>json_encode($data)]);
}
break;
default:
abort(500,'Unknown type: '.$o->type());
case 'netmail':
$seq = 0;
foreach ($o->via as $v)
{
$data = preg_split('/\s/',$v);
$ftno = $this->get_node(ftn_address_split($data[0]));
unset($data[0]);
$oo->paths()->attach($ftno->id,['sequence'=>$seq++,'value'=>json_encode($data)]);
}
break;
}
}
}