From d022c8d05c898a74f140241def5171e0ef3363e8 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 1 Jun 2024 16:47:13 +1000 Subject: [PATCH] Enable per system configuration of messages per packet --- app/Http/Controllers/SystemController.php | 2 +- app/Http/Requests/SystemRegisterRequest.php | 1 + app/Models/Address.php | 14 ++++------ app/Models/System.php | 5 ++++ .../2024_06_01_162644_pktsize_to_systems.php | 28 +++++++++++++++++++ .../views/system/widget/system.blade.php | 16 ++++++++++- 6 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 database/migrations/2024_06_01_162644_pktsize_to_systems.php diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index 07875d2..c717043 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -31,7 +31,7 @@ class SystemController extends Controller public function add_edit(SystemRegisterRequest $request, System $o) { if ($request->validated()) { - foreach (['name','location','phone','address','port','active','method','pkt_type'] as $key) + foreach (['name','location','phone','address','port','active','method','pkt_msgs','pkt_type'] as $key) $o->{$key} = $request->validated($key); // Sometimes items diff --git a/app/Http/Requests/SystemRegisterRequest.php b/app/Http/Requests/SystemRegisterRequest.php index 9175ad5..6d79482 100644 --- a/app/Http/Requests/SystemRegisterRequest.php +++ b/app/Http/Requests/SystemRegisterRequest.php @@ -73,6 +73,7 @@ class SystemRegisterRequest extends FormRequest 'hold' => 'sometimes|boolean', 'pollmode' => 'required|integer|min:0|max:2', 'heartbeat' => 'nullable|integer|min:0|max:48', + 'pkt_msgs' => 'nullable|integer|min:5', ] : [])); } } \ No newline at end of file diff --git a/app/Models/Address.php b/app/Models/Address.php index 3f54a25..034b5ee 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -1045,15 +1045,13 @@ class Address extends Model public function getEchomail(): ?Packet { if (($num=$this->echomailWaiting())->count()) { - $s = Setup::findOrFail(config('app.id')); - Log::info(sprintf('%s:= Got [%d] echomails for [%s] for sending',self::LOGKEY,$num->count(),$this->ftn)); // Limit to max messages - if ($num->count() > $s->msgs_pkt) - Log::notice(sprintf('%s:= Only sending [%d] echomails for [%s]',self::LOGKEY,$s->msgs_pkt,$this->ftn)); + if ($num->count() > $this->system->msgs_pkt) + Log::notice(sprintf('%s:= Only sending [%d] echomails for [%s]',self::LOGKEY,$this->system->msgs_pkt,$this->ftn)); - return $this->system->packet($this)->mail($num->take($s->msgs_pkt)); + return $this->system->packet($this)->mail($num->take($this->system->msgs_pkt)); } return NULL; @@ -1103,15 +1101,13 @@ class Address extends Model } if (($num=$this->netmailWaiting())->count()) { - $s = Setup::findOrFail(config('app.id')); - Log::debug(sprintf('%s:= Got [%d] netmails for [%s] for sending',self::LOGKEY,$num->count(),$this->ftn)); // Limit to max messages - if ($num->count() > $s->msgs_pkt) + if ($num->count() > $this->system->msgs_pkt) Log::alert(sprintf('%s:= Only sending [%d] netmails for [%s]',self::LOGKEY,$num->count(),$this->ftn)); - return $this->system->packet($this)->mail($num->take($s->msgs_pkt)); + return $this->system->packet($this)->mail($num->take($this->system->msgs_pkt)); } return NULL; diff --git a/app/Models/System.php b/app/Models/System.php index c292cf8..657cfbe 100644 --- a/app/Models/System.php +++ b/app/Models/System.php @@ -170,6 +170,11 @@ class System extends Model } } + public function getMsgsPktAttribute(int $val): int + { + return $val ?: Setup::findOrFail(config('app.id'))->msgs_pkt; + } + /* METHODS */ public function echoareas() diff --git a/database/migrations/2024_06_01_162644_pktsize_to_systems.php b/database/migrations/2024_06_01_162644_pktsize_to_systems.php new file mode 100644 index 0000000..2a8d88b --- /dev/null +++ b/database/migrations/2024_06_01_162644_pktsize_to_systems.php @@ -0,0 +1,28 @@ +integer('pkt_msgs')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('systems', function (Blueprint $table) { + $table->dropColumn(['pkt_msgs']); + }); + } +}; diff --git a/resources/views/system/widget/system.blade.php b/resources/views/system/widget/system.blade.php index 78b5136..e5455a1 100644 --- a/resources/views/system/widget/system.blade.php +++ b/resources/views/system/widget/system.blade.php @@ -1,6 +1,6 @@ @php use App\Classes\FTN\Packet; -use App\Models\{Mailer,User}; +use App\Models\{Mailer,Setup,User}; @endphp @@ -189,6 +189,20 @@ use App\Models\{Mailer,User}; + + +
+ +
+ + + + @error('pkt_msgs') + {{ $message }} + @enderror + +
+