Cast empty Collections to null, Cast strings to zstd compressed strings, add msg_src to echomails processed, fix duplicate seenbys

This commit is contained in:
Deon George
2022-10-30 23:42:30 +11:00
parent 31db017a0d
commit da85e85774
5 changed files with 100 additions and 43 deletions

View File

@@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use App\Casts\CompressedString;
use App\Traits\{QueryCacheableConfig,ScopeActive};
class Domain extends Model
@@ -17,6 +18,10 @@ class Domain extends Model
private const CACHE_TIME = 3600;
private const STATS_MONTHS = 6;
protected $casts = [
'homepage' => CompressedString::class,
];
/* SCOPES */
/**
@@ -49,12 +54,7 @@ class Domain extends Model
public function getHomePageAttribute(string $value): string
{
//0xFD2FB528
return $value ? zstd_uncompress(base64_decode($value)) : 'No available information at the moment.';
}
public function setHomePageAttribute(string $value): void
{
$this->attributes['homepage'] = base64_encode(zstd_compress($value,9));
return $this->castAttribute('homepage',$value) ?: 'No available information at the moment.';
}
/* METHODS */

View File

@@ -10,6 +10,7 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Rennokki\QueryCache\Traits\QueryCacheable;
use App\Casts\{CollectionOrNull,CompressedString};
use App\Classes\FTN\Message;
use App\Interfaces\Packet;
use App\Traits\{EncodeUTF8,MsgID};
@@ -19,15 +20,17 @@ final class Echomail extends Model implements Packet
use SoftDeletes,EncodeUTF8,MsgID,QueryCacheable;
private const LOGKEY = 'ME-';
private array $set_seenby = [];
private array $set_path = [];
private Collection $set_seenby;
private Collection $set_path;
private ?string $set_packet = NULL;
private bool $no_export = FALSE;
protected $casts = [
'kludges' => 'json',
'rogue_seenby' => 'json',
'rogue_path' => 'json',
'kludges' => CollectionOrNull::class,
'rogue_seenby' => CollectionOrNull::class,
'rogue_path' => CollectionOrNull::class,
'msg' => CompressedString::class,
'msg_src' => CompressedString::class,
];
private const cast_utf8 = [
@@ -70,20 +73,16 @@ final class Echomail extends Model implements Packet
}
// Our address
$ftns = Setup::findOrFail(config('app.id'))->system->match($model->fftn->zone,Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_HOLD);
$ftns = Setup::findOrFail(config('app.id'))
->system
->match($model->fftn->zone,Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_HOLD);
// Add our address to the seenby;
$model->set_seenby = array_merge($model->set_seenby,$ftns->pluck('id')->toArray());
$model->set_path = array_merge($model->set_path,$ftns->pluck('id')->toArray());
$model->set_seenby = $model->set_seenby->merge($ftns->pluck('id'))->unique();
$model->set_path = $model->set_path->merge($ftns->pluck('id'));
// Save the seenby
foreach ($model->set_seenby as $aoid) {
DB::insert('INSERT INTO echomail_seenby (echomail_id,address_id,packet) VALUES (?,?,?)',[
$model->id,
$aoid,
$model->set_packet,
]);
}
$model->seenby()->syncWithPivotValues($model->set_seenby,['packet'=>$model->set_packet]);
// Save the Path
$ppoid = NULL;
@@ -109,14 +108,7 @@ final class Echomail extends Model implements Packet
Log::debug(sprintf('%s:- Exporting message [%s] to [%s]',self::LOGKEY,$model->id,$exportto->join(',')));
// Save the seenby for the exported systems
$export_at = Carbon::now();
foreach ($exportto as $aoid) {
DB::insert('INSERT INTO echomail_seenby (echomail_id,address_id,export_at) VALUES (?,?,?)',[
$model->id,
$aoid,
$export_at,
]);
}
$model->seenby()->syncWithPivotValues($exportto,['export_at'=>Carbon::now()],FALSE);
}
});
}
@@ -146,18 +138,6 @@ final class Echomail extends Model implements Packet
->withPivot(['id','parent_id']);
}
/* ATTRIBUTES */
public function getMsgAttribute($value): ?string
{
return $value ? zstd_uncompress(base64_decode($value)) : NULL;
}
public function getMsgSrcAttribute($value): ?string
{
return $value ? zstd_uncompress(base64_decode($value)) : NULL;
}
/* METHODS */
public function jsonSerialize(): array