From 8edc45fbd54fa9dbc67dc825ee9ef532aced3b7a Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 20 Apr 2025 22:19:05 +1000 Subject: [PATCH] Change our $casts array to a casts() function for our updated laravel, fix incoming TICs to not export to our system --- app/Models/Address.php | 3 +-- app/Models/AddressEchoarea.php | 9 ++++++--- app/Models/Domain.php | 9 ++++++--- app/Models/Dynamic.php | 15 +++++++++------ app/Models/Echoarea.php | 11 +++++++---- app/Models/Echomail.php | 27 +++++++++++++++------------ app/Models/File.php | 30 ++++++++++++++++++------------ app/Models/Filearea.php | 11 +++++++---- app/Models/Job.php | 29 ++++++++++++++++------------- app/Models/Netmail.php | 23 +++++++++++++---------- app/Models/Nodelist.php | 9 ++++++--- app/Models/Origin.php | 9 ++++++--- app/Models/Pivots/ViaPivot.php | 11 +++++++---- app/Models/Setup.php | 11 +++++++---- app/Models/System.php | 9 ++++++--- app/Models/Tagline.php | 9 ++++++--- app/Models/Tearline.php | 9 ++++++--- app/Models/User.php | 15 +++++++++------ 18 files changed, 151 insertions(+), 98 deletions(-) diff --git a/app/Models/Address.php b/app/Models/Address.php index eb8ef19..350b155 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -9,10 +9,9 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\QueryException; -use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; -use App\Classes\FTN\{Message,Packet}; +use App\Classes\FTN\Packet; use App\Exceptions\InvalidFTNException; use App\Traits\{QueryCacheableConfig,ScopeActive}; diff --git a/app/Models/AddressEchoarea.php b/app/Models/AddressEchoarea.php index 85a7c13..5cc02e4 100644 --- a/app/Models/AddressEchoarea.php +++ b/app/Models/AddressEchoarea.php @@ -6,7 +6,10 @@ use Illuminate\Database\Eloquent\Relations\Pivot; class AddressEchoarea extends Pivot { - protected $casts = [ - 'subscribed' => 'datetime:Y-m-d H:i', - ]; + protected function casts(): array + { + return [ + 'subscribed' => 'datetime:Y-m-d H:i', + ]; + } } \ No newline at end of file diff --git a/app/Models/Domain.php b/app/Models/Domain.php index 91c92f8..132d34a 100644 --- a/app/Models/Domain.php +++ b/app/Models/Domain.php @@ -28,9 +28,12 @@ class Domain extends Model private const CACHE_TIME = 3600; private const STATS_MONTHS = 6; - protected $casts = [ - 'homepage' => CompressedStringOrNull::class, - ]; + protected function casts(): array + { + return [ + 'homepage' => CompressedStringOrNull::class, + ]; + } /* SCOPES */ diff --git a/app/Models/Dynamic.php b/app/Models/Dynamic.php index 932066e..2718961 100644 --- a/app/Models/Dynamic.php +++ b/app/Models/Dynamic.php @@ -11,12 +11,15 @@ class Dynamic extends Model { use SoftDeletes; - protected $casts = [ - 'arguments' => CollectionOrNull::class, - 'next_at' => 'datetime:Y-m-d H:i:s', - 'start_date' => 'datetime:Y-m-d', - 'start_time' => 'datetime:H:i:s', - ]; + protected function casts(): array + { + return [ + 'arguments' => CollectionOrNull::class, + 'next_at' => 'datetime:Y-m-d H:i:s', + 'start_date' => 'datetime:Y-m-d', + 'start_time' => 'datetime:H:i:s', + ]; + } /* RELATIONS */ diff --git a/app/Models/Echoarea.php b/app/Models/Echoarea.php index 08be3c4..963f2dc 100644 --- a/app/Models/Echoarea.php +++ b/app/Models/Echoarea.php @@ -45,10 +45,13 @@ class Echoarea extends Model private const CACHE_TIME = 3600; - protected $casts = [ - 'first_message' => 'datetime:Y-m-d H:i:s', - 'last_message' => 'datetime:Y-m-d H:i:s', - ]; + protected function casts(): array + { + return [ + 'first_message' => 'datetime:Y-m-d H:i:s', + 'last_message' => 'datetime:Y-m-d H:i:s', + ]; + } /* RELATIONS */ diff --git a/app/Models/Echomail.php b/app/Models/Echomail.php index d8275b0..dc51736 100644 --- a/app/Models/Echomail.php +++ b/app/Models/Echomail.php @@ -34,17 +34,20 @@ final class Echomail extends Model implements Packet // When generating a packet for this echomail, the packet recipient is our tftn public Address $tftn; - protected $casts = [ - 'to' => UTF8StringOrNull::class, - 'from' => UTF8StringOrNull::class, - 'subject' => UTF8StringOrNull::class, - 'datetime' => 'datetime:Y-m-d H:i:s', - 'kludges' => CollectionOrNull::class, - 'msg' => CompressedStringOrNull::class, - 'msg_src' => CompressedStringOrNull::class, - 'rogue_seenby' => CollectionOrNull::class, - 'rogue_path' => CollectionOrNull::class, // @deprecated? - ]; + protected function casts(): array + { + return [ + 'to' => UTF8StringOrNull::class, + 'from' => UTF8StringOrNull::class, + 'subject' => UTF8StringOrNull::class, + 'datetime' => 'datetime:Y-m-d H:i:s', + 'kludges' => CollectionOrNull::class, + 'msg' => CompressedStringOrNull::class, + 'msg_src' => CompressedStringOrNull::class, + 'rogue_seenby' => CollectionOrNull::class, + 'rogue_path' => CollectionOrNull::class, // @deprecated? + ]; + } public function __get($key) { @@ -258,7 +261,7 @@ final class Echomail extends Model implements Packet $exportto = $model ->echoarea ->addresses - ->filter(function($item) use ($model) { return $model->echoarea->can_read($item->security); }) + ->filter(fn($item)=>$model->echoarea->can_read($item->security)) ->pluck('id') ->diff(our_address($model->fftn->zone->domain,FALSE)->pluck('id')) ->diff($seenby); diff --git a/app/Models/File.php b/app/Models/File.php index 598dc3f..86df787 100644 --- a/app/Models/File.php +++ b/app/Models/File.php @@ -25,15 +25,18 @@ class File extends Model public Collection $set_seenby; public string $src_file = ''; - protected $casts = [ - 'kludges' => CollectionOrNull::class, - 'datetime' => 'datetime:Y-m-d H:i:s', - 'desc' => CompressedStringOrNull::class, - 'ldesc' => CompressedStringOrNull::class, - 'rogue_seenby' => CollectionOrNull::class, - 'rogue_path' => CollectionOrNull::class, - 'size' => 'int', - ]; + protected function casts(): array + { + return [ + 'kludges' => CollectionOrNull::class, + 'datetime' => 'datetime:Y-m-d H:i:s', + 'desc' => CompressedStringOrNull::class, + 'ldesc' => CompressedStringOrNull::class, + 'rogue_seenby' => CollectionOrNull::class, + 'rogue_path' => CollectionOrNull::class, + 'size' => 'int', + ]; + } public static function boot() { @@ -146,18 +149,21 @@ class File extends Model $rogue->push($sb); } - $model->rogue_seenby = $rogue; + if (count($rogue)) { + $model->rogue_seenby = $rogue; + $model->save(); + } $model->seenby()->sync($seenby); - $model->save(); // See if we need to export this file. if ($model->filearea->sec_read) { $exportto = $model ->filearea ->addresses - ->filter(function($item) use ($model) { return $model->filearea->can_read($item->security); }) + ->filter(fn($item)=>$model->filearea->can_read($item->security)) ->pluck('id') + ->diff(our_address($model->fftn->zone->domain,FALSE)->pluck('id')) ->diff($seenby); if ($exportto->count()) { diff --git a/app/Models/Filearea.php b/app/Models/Filearea.php index c291eec..552cca3 100644 --- a/app/Models/Filearea.php +++ b/app/Models/Filearea.php @@ -11,10 +11,13 @@ class Filearea extends Model { use SoftDeletes,ScopeActive,AreaSecurity; - protected $casts = [ - 'first_file' => 'datetime:Y-m-d H:i:s', - 'last_file' => 'datetime:Y-m-d H:i:s', - ]; + protected function casts(): array + { + return [ + 'first_file' => 'datetime:Y-m-d H:i:s', + 'last_file' => 'datetime:Y-m-d H:i:s', + ]; + } protected $fillable = [ 'name', diff --git a/app/Models/Job.php b/app/Models/Job.php index 5ad67fa..dbfb2dc 100644 --- a/app/Models/Job.php +++ b/app/Models/Job.php @@ -7,20 +7,23 @@ use Illuminate\Support\Facades\Config; class Job extends Model { - public $timestamps = false; + public $timestamps = false; - protected $casts = [ - 'payload' => 'array', - 'reserved_at' => 'datetime', - 'available_at' => 'datetime', - 'created_at' => 'datetime', - ]; + protected function casts(): array + { + return [ + 'payload' => 'array', + 'reserved_at' => 'datetime', + 'available_at' => 'datetime', + 'created_at' => 'datetime', + ]; + } - public function __construct(array $attributes = []) - { - parent::__construct($attributes); - $this->table = Config::get('queue.connections.' . (Config::get('queue.default', 'database')) . '.table', 'jobs'); - } + public function __construct(array $attributes=[]) + { + parent::__construct($attributes); + $this->table = Config::get('queue.connections.' . (Config::get('queue.default', 'database')) . '.table', 'jobs'); + } public function getDisplayNameAttribute() { @@ -66,4 +69,4 @@ class Job extends Model { return unserialize($this->payload['data']['command']); } -} +} \ No newline at end of file diff --git a/app/Models/Netmail.php b/app/Models/Netmail.php index b82e2ed..ca0584d 100644 --- a/app/Models/Netmail.php +++ b/app/Models/Netmail.php @@ -34,16 +34,19 @@ final class Netmail extends Model implements Packet 'Via' => 'set_path', ]; - protected $casts = [ - 'to' => UTF8StringOrNull::class, - 'from' => UTF8StringOrNull::class, - 'subject' => UTF8StringOrNull::class, - 'datetime' => 'datetime:Y-m-d H:i:s', - 'kludges' => CollectionOrNull::class, - 'msg' => CompressedStringOrNull::class, - 'msg_src' => CompressedStringOrNull::class, - 'sent_at' => 'datetime:Y-m-d H:i:s', - ]; + protected function casts(): array + { + return [ + 'to' => UTF8StringOrNull::class, + 'from' => UTF8StringOrNull::class, + 'subject' => UTF8StringOrNull::class, + 'datetime' => 'datetime:Y-m-d H:i:s', + 'kludges' => CollectionOrNull::class, + 'msg' => CompressedStringOrNull::class, + 'msg_src' => CompressedStringOrNull::class, + 'sent_at' => 'datetime:Y-m-d H:i:s', + ]; + } public function __get($key) { diff --git a/app/Models/Nodelist.php b/app/Models/Nodelist.php index d0fe273..a2823bc 100644 --- a/app/Models/Nodelist.php +++ b/app/Models/Nodelist.php @@ -9,9 +9,12 @@ class Nodelist extends Model { use SoftDeletes; - protected $casts = [ - 'date' => 'datetime:Y-m-d H:i:s' - ]; + protected function casts(): array + { + return [ + 'date' => 'datetime:Y-m-d H:i:s' + ]; + } protected $fillable = ['date','domain_id']; diff --git a/app/Models/Origin.php b/app/Models/Origin.php index 54c4597..d61cfca 100644 --- a/app/Models/Origin.php +++ b/app/Models/Origin.php @@ -12,9 +12,12 @@ class Origin extends Model public const UPDATED_AT = NULL; - protected $casts = [ - 'value' => UTF8StringOrNull::class, - ]; + protected function casts(): array + { + return [ + 'value' => UTF8StringOrNull::class, + ]; + } public function complete(Address $o): string { diff --git a/app/Models/Pivots/ViaPivot.php b/app/Models/Pivots/ViaPivot.php index 3021544..ab10a55 100644 --- a/app/Models/Pivots/ViaPivot.php +++ b/app/Models/Pivots/ViaPivot.php @@ -6,7 +6,10 @@ use Illuminate\Database\Eloquent\Relations\Pivot; class ViaPivot extends Pivot { - protected $casts = [ - 'datetime' => 'datetime', - ]; -} + protected function casts(): array + { + return [ + 'datetime' => 'datetime', + ]; + } +} \ No newline at end of file diff --git a/app/Models/Setup.php b/app/Models/Setup.php index 1ac420e..32757b7 100644 --- a/app/Models/Setup.php +++ b/app/Models/Setup.php @@ -35,10 +35,13 @@ class Setup extends Model public const MAX_BATCH_FILES = 5; public const MAX_MSGS_PKT = 50; - protected $casts = [ - 'options' => 'array', - 'servers' => 'array', - ]; + protected function casts(): array + { + return [ + 'options' => 'array', + 'servers' => 'array', + ]; + } /** * @throws \Exception diff --git a/app/Models/System.php b/app/Models/System.php index 615670b..2beea3f 100644 --- a/app/Models/System.php +++ b/app/Models/System.php @@ -17,9 +17,12 @@ class System extends Model public const default = 'Discovered System'; - protected $casts = [ - 'last_session' => 'datetime:Y-m-d H:i:s' - ]; + protected function casts(): array + { + return [ + 'last_session' => 'datetime:Y-m-d H:i:s' + ]; + } /* STATIC */ diff --git a/app/Models/Tagline.php b/app/Models/Tagline.php index 7bccbdf..2c16364 100644 --- a/app/Models/Tagline.php +++ b/app/Models/Tagline.php @@ -12,9 +12,12 @@ class Tagline extends Model public const UPDATED_AT = NULL; - protected $casts = [ - 'value' => UTF8StringOrNull::class, - ]; + protected function casts(): array + { + return [ + 'value' => UTF8StringOrNull::class, + ]; + } public function complete(): string { diff --git a/app/Models/Tearline.php b/app/Models/Tearline.php index d0dd7a0..dd4c439 100644 --- a/app/Models/Tearline.php +++ b/app/Models/Tearline.php @@ -12,9 +12,12 @@ class Tearline extends Model public const UPDATED_AT = NULL; - protected $casts = [ - 'value' => UTF8StringOrNull::class, - ]; + protected function casts(): array + { + return [ + 'value' => UTF8StringOrNull::class, + ]; + } public function complete(): string { diff --git a/app/Models/User.php b/app/Models/User.php index 7dff43f..8cc3a80 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -53,13 +53,16 @@ class User extends Authenticatable implements MustVerifyEmail /** * The attributes that should be cast to native types. * - * @var array + * @return array */ - protected $casts = [ - 'email_verified_at' => 'datetime', - 'last_on' => 'datetime:Y-m-d H:i:s', - 'passkey' => 'json', - ]; + protected function casts(): array + { + return [ + 'email_verified_at' => 'datetime', + 'last_on' => 'datetime:Y-m-d H:i:s', + 'passkey' => 'json', + ]; + } /* RELATIONS */