Enable per system configuration of messages per packet

This commit is contained in:
Deon George 2024-06-01 16:47:13 +10:00
parent 0bc3d4cf60
commit 1d354da6e3
6 changed files with 57 additions and 13 deletions

View File

@ -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

View File

@ -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',
] : []));
}
}

View File

@ -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->pkt_msgs)
Log::notice(sprintf('%s:= Only sending [%d] echomails for [%s]',self::LOGKEY,$this->system->pkt_msgs,$this->ftn));
return $this->system->packet($this)->mail($num->take($s->msgs_pkt));
return $this->system->packet($this)->mail($num->take($this->system->pkt_msgs));
}
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)
Log::alert(sprintf('%s:= Only sending [%d] netmails for [%s]',self::LOGKEY,$num->count(),$this->ftn));
if ($num->count() > $this->system->pkt_msgs)
Log::alert(sprintf('%s:= Only sending [%d] netmails for [%s]',self::LOGKEY,$this->system->pkt_msgs,$this->ftn));
return $this->system->packet($this)->mail($num->take($s->msgs_pkt));
return $this->system->packet($this)->mail($num->take($this->system->pkt_msgs));
}
return NULL;
@ -1145,7 +1141,7 @@ class Address extends Model
$c = 0;
foreach ($msgs as $oo) {
// Only bundle up to max messages
if (++$c > $s->msgs_pkt)
if (++$c > $s->pkt_msgs)
break;
$o->addMail($oo->packet($this,$passwd));

View File

@ -170,6 +170,11 @@ class System extends Model
}
}
public function getPktMsgsAttribute(?int $val): int
{
return $val ?: Setup::findOrFail(config('app.id'))->msgs_pkt;
}
/* METHODS */
public function echoareas()

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('systems', function (Blueprint $table) {
$table->integer('pkt_msgs')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('systems', function (Blueprint $table) {
$table->dropColumn(['pkt_msgs']);
});
}
};

View File

@ -1,6 +1,6 @@
@php
use App\Classes\FTN\Packet;
use App\Models\{Mailer,User};
use App\Models\{Mailer,Setup,User};
@endphp
<!-- $o=System::class -->
@ -189,6 +189,20 @@ use App\Models\{Mailer,User};
</span>
</div>
</div>
<!-- Packet Msgs -->
<div class="col-2">
<label for="pkt_msgs" class="form-label w-100">Packet Msgs</label>
<div class="input-group has-validation">
<span class="input-group-text"><i class="bi bi-hash"></i></span>
<input type="text" class="form-control text-end @error('pkt_msgs') is-invalid @enderror" id="pkt_msgs" placeholder="{{ Setup::MAX_MSGS_PKT }}" name="pkt_msgs" value="{{ old('pkt_msgs',$o->pkt_msgs) }}" @cannot($action,$o)readonly @endcannot>
<span class="invalid-feedback" role="alert">
@error('pkt_msgs')
{{ $message }}
@enderror
</span>
</div>
</div>
</div>
</div>
</div>