Added file areas and TIC processing
This commit is contained in:
@@ -159,7 +159,29 @@ class Address extends Model
|
||||
public function echomails()
|
||||
{
|
||||
return $this->belongsToMany(Echomail::class,'echomail_seenby')
|
||||
->withPivot(['sent_at','packet']);
|
||||
->withPivot(['sent_at','export_at','packet']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Files that this address has seen
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function files()
|
||||
{
|
||||
return $this->belongsToMany(File::class,'file_seenby')
|
||||
->withPivot(['sent_at','export_at']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Echoareas this address is subscribed to
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function fileareas()
|
||||
{
|
||||
return $this->belongsToMany(Filearea::class)
|
||||
->withPivot(['subscribed']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -409,7 +431,7 @@ class Address extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Netmail waiting to be sent to this system
|
||||
* Echomail waiting to be sent to this system
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -421,6 +443,19 @@ class Address extends Model
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Files waiting to be sent to this system
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function filesWaiting(): Collection
|
||||
{
|
||||
return $this->files()
|
||||
->whereNull('file_seenby.sent_at')
|
||||
->whereNotNull('file_seenby.export_at')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get echomail for this node
|
||||
*
|
||||
|
@@ -46,7 +46,7 @@ final class Echomail extends Model implements Packet
|
||||
|
||||
protected $dates = ['datetime'];
|
||||
|
||||
public function __set($key, $value)
|
||||
public function __set($key,$value)
|
||||
{
|
||||
switch ($key) {
|
||||
case 'no_export':
|
||||
@@ -68,7 +68,7 @@ final class Echomail extends Model implements Packet
|
||||
// @todo if the message is updated with new SEEN-BY's from another route, we'll delete the pending export for systems (if there is one)
|
||||
static::created(function($model) {
|
||||
if (! $model->echoarea_id) {
|
||||
Log::alert(sprintf('%s:- Message has no echo area, not exporting',self::LOGKEY,$model->id));
|
||||
Log::alert(sprintf('%s:- Message has no echoarea, not exporting',self::LOGKEY,$model->id));
|
||||
return;
|
||||
}
|
||||
|
||||
|
157
app/Models/File.php
Normal file
157
app/Models/File.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Rennokki\QueryCache\Traits\QueryCacheable;
|
||||
|
||||
use App\Casts\{CollectionOrNull,CompressedString};
|
||||
use App\Traits\EncodeUTF8;
|
||||
|
||||
class File extends Model
|
||||
{
|
||||
use SoftDeletes,EncodeUTF8,QueryCacheable;
|
||||
|
||||
private const LOGKEY = 'MF-';
|
||||
private bool $no_export = FALSE;
|
||||
|
||||
protected $casts = [
|
||||
'kludges' => CollectionOrNull::class,
|
||||
'rogue_seenby' => CollectionOrNull::class,
|
||||
'rogue_path' => CollectionOrNull::class,
|
||||
'desc' => CompressedString::class,
|
||||
'ldesc' => CompressedString::class,
|
||||
'size' => 'int',
|
||||
];
|
||||
|
||||
private const cast_utf8 = [
|
||||
'desc',
|
||||
'ldesc',
|
||||
];
|
||||
|
||||
protected $dates = ['datetime'];
|
||||
|
||||
public function __set($key,$value)
|
||||
{
|
||||
switch ($key) {
|
||||
case 'fullname':
|
||||
case 'replaces':
|
||||
case 'no_export':
|
||||
case 'set_path':
|
||||
case 'set_packet':
|
||||
case 'set_seenby':
|
||||
$this->{$key} = $value;
|
||||
break;
|
||||
|
||||
default:
|
||||
parent::__set($key,$value);
|
||||
}
|
||||
}
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function($model) {
|
||||
Log::debug(sprintf('%s:- Storing file [%s]',self::LOGKEY,$model->file));
|
||||
|
||||
// Store file
|
||||
|
||||
// Delete file from inbound
|
||||
|
||||
// Delete anything being replaced
|
||||
});
|
||||
|
||||
// @todo if the file is updated with new SEEN-BY's from another route, we'll delete the pending export for systems (if there is one)
|
||||
static::created(function($model) {
|
||||
if (! $model->filearea_id) {
|
||||
Log::alert(sprintf('%s:- File has no filearea, not exporting',self::LOGKEY,$model->id));
|
||||
return;
|
||||
}
|
||||
|
||||
$so = Setup::findOrFail(config('app.id'));
|
||||
|
||||
// Our address
|
||||
$ftns = $so
|
||||
->system
|
||||
->match($model->fftn->zone,Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_HOLD);
|
||||
|
||||
// Add our address to the seenby;
|
||||
$model->set_seenby = $model->set_seenby->merge($ftns->pluck('id'))->unique();
|
||||
$model->set_path = $model->set_path->merge([[
|
||||
'address'=>$ftns->first(),
|
||||
'datetime'=>($x=Carbon::now())->timestamp,
|
||||
'extra'=>sprintf('%s %s (%s)',$x->toRfc7231String(),$so::PRODUCT_NAME,$so->version),
|
||||
]]);
|
||||
|
||||
// Save the seenby
|
||||
$model->seenby()->sync($model->set_seenby);
|
||||
|
||||
// Save the Path
|
||||
$ppoid = NULL;
|
||||
foreach ($model->set_path as $path) {
|
||||
$po = DB::select('INSERT INTO file_path (file_id,address_id,parent_id,datetime,extra) VALUES (?,?,?,?,?) RETURNING id',[
|
||||
$model->id,
|
||||
$path['address']->id,
|
||||
$ppoid,
|
||||
Carbon::createFromTimestamp($path['datetime']),
|
||||
$path['extra'],
|
||||
]);
|
||||
|
||||
$ppoid = $po[0]->id;
|
||||
}
|
||||
|
||||
// See if we need to export this message.
|
||||
$exportto = $model->filearea->addresses->pluck('id')->diff($model->set_seenby);
|
||||
|
||||
if ($exportto->count()) {
|
||||
if ($model->no_export) {
|
||||
Log::debug(sprintf('%s:- NOT processing exporting of message by configuration [%s] to [%s]',self::LOGKEY,$model->id,$exportto->join(',')));
|
||||
return;
|
||||
}
|
||||
|
||||
Log::debug(sprintf('%s:- Exporting file [%s] to [%s]',self::LOGKEY,$model->id,$exportto->join(',')));
|
||||
|
||||
// Save the seenby for the exported systems
|
||||
$model->seenby()->syncWithPivotValues($exportto,['export_at'=>Carbon::now()],FALSE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function filearea()
|
||||
{
|
||||
return $this->belongsTo(Filearea::class);
|
||||
}
|
||||
|
||||
public function fftn()
|
||||
{
|
||||
return $this->belongsTo(Address::class)
|
||||
->withTrashed();
|
||||
}
|
||||
|
||||
public function seenby()
|
||||
{
|
||||
return $this->belongsToMany(Address::class,'file_seenby')
|
||||
->ftnOrder();
|
||||
}
|
||||
|
||||
public function path()
|
||||
{
|
||||
return $this->belongsToMany(Address::class,'file_path')
|
||||
->withPivot(['id','parent_id','extra']);
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return $this->encode();
|
||||
}
|
||||
}
|
@@ -11,6 +11,10 @@ class Filearea extends Model
|
||||
{
|
||||
use SoftDeletes,ScopeActive;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
];
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function addresses()
|
||||
|
@@ -92,6 +92,14 @@ class System extends Model
|
||||
->where('addresses.system_id',$this->id);
|
||||
}
|
||||
|
||||
public function fileareas()
|
||||
{
|
||||
return Filearea::select('fileareas.*')
|
||||
->join('address_filearea',['address_filearea.filearea_id'=>'fileareas.id'])
|
||||
->join('addresses',['addresses.id'=>'address_filearea.address_id'])
|
||||
->where('addresses.system_id',$this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the system name, or role name for the zone
|
||||
*
|
||||
|
Reference in New Issue
Block a user