Fix for single encoding error, when only the first message was decoded, some logging for Address objects
This commit is contained in:
parent
f216f42917
commit
12a40a79fb
@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Collection;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
use App\Classes\FTN\Packet;
|
use App\Classes\FTN\Packet;
|
||||||
use App\Http\Controllers\DomainController;
|
use App\Http\Controllers\DomainController;
|
||||||
@ -24,6 +25,8 @@ use App\Traits\ScopeActive;
|
|||||||
*/
|
*/
|
||||||
class Address extends Model
|
class Address extends Model
|
||||||
{
|
{
|
||||||
|
private const LOGKEY = 'MA-';
|
||||||
|
|
||||||
use ScopeActive,SoftDeletes;
|
use ScopeActive,SoftDeletes;
|
||||||
|
|
||||||
protected $with = ['zone'];
|
protected $with = ['zone'];
|
||||||
@ -383,6 +386,7 @@ class Address extends Model
|
|||||||
* Get echomail for this node
|
* Get echomail for this node
|
||||||
*
|
*
|
||||||
* @param bool $update
|
* @param bool $update
|
||||||
|
* @param Collection|null $echomail
|
||||||
* @return Packet|null
|
* @return Packet|null
|
||||||
*/
|
*/
|
||||||
public function getEchomail(bool $update=TRUE,Collection $echomail=NULL): ?Packet
|
public function getEchomail(bool $update=TRUE,Collection $echomail=NULL): ?Packet
|
||||||
@ -394,6 +398,8 @@ class Address extends Model
|
|||||||
if (($x=$this->echomailWaiting())
|
if (($x=$this->echomailWaiting())
|
||||||
->count())
|
->count())
|
||||||
{
|
{
|
||||||
|
Log::debug(sprintf('%s:= Got [%d] echomails for [%s] for sending',self::LOGKEY,$x->count(),$this->ftn));
|
||||||
|
|
||||||
$pkt = $this->getPacket($x);
|
$pkt = $this->getPacket($x);
|
||||||
|
|
||||||
if ($pkt && $pkt->count() && $update)
|
if ($pkt && $pkt->count() && $update)
|
||||||
@ -422,6 +428,8 @@ class Address extends Model
|
|||||||
if (($x=$this->netmailWaiting())
|
if (($x=$this->netmailWaiting())
|
||||||
->count())
|
->count())
|
||||||
{
|
{
|
||||||
|
Log::debug(sprintf('%s:= Got [%d] netmails for [%s] for sending',self::LOGKEY,$x->count(),$this->ftn));
|
||||||
|
|
||||||
$pkt = $this->getPacket($x);
|
$pkt = $this->getPacket($x);
|
||||||
|
|
||||||
if ($pkt && $pkt->count() && $update)
|
if ($pkt && $pkt->count() && $update)
|
||||||
@ -436,7 +444,7 @@ class Address extends Model
|
|||||||
/**
|
/**
|
||||||
* Return a packet of mail
|
* Return a packet of mail
|
||||||
*
|
*
|
||||||
* @param Collection $c
|
* @param Collection $c of message models (Echomail/Netmail)
|
||||||
* @return Packet|null
|
* @return Packet|null
|
||||||
*/
|
*/
|
||||||
private function getPacket(Collection $c): ?Packet
|
private function getPacket(Collection $c): ?Packet
|
||||||
@ -449,6 +457,7 @@ class Address extends Model
|
|||||||
|
|
||||||
$o = new Packet($ao,$this);
|
$o = new Packet($ao,$this);
|
||||||
|
|
||||||
|
// $oo = Netmail/Echomail Model
|
||||||
foreach ($c as $oo)
|
foreach ($c as $oo)
|
||||||
$o->addMail($oo->packet($this));
|
$o->addMail($oo->packet($this));
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@ use Illuminate\Support\Arr;
|
|||||||
|
|
||||||
trait EncodeUTF8
|
trait EncodeUTF8
|
||||||
{
|
{
|
||||||
|
private array $_encoded = []; // Remember what we've decoded - when calling getAttribute()
|
||||||
|
|
||||||
private function decode(array $values): void
|
private function decode(array $values): void
|
||||||
{
|
{
|
||||||
$properties = (new \ReflectionClass($this))->getProperties();
|
$properties = (new \ReflectionClass($this))->getProperties();
|
||||||
@ -79,11 +81,9 @@ trait EncodeUTF8
|
|||||||
|
|
||||||
public function getAttribute($key)
|
public function getAttribute($key)
|
||||||
{
|
{
|
||||||
static $encoded = [];
|
if (in_array($key,self::cast_utf8) && Arr::get($this->attributes,$key) && (! Arr::get($this->_encoded,$key))) {
|
||||||
|
|
||||||
if (in_array($key,self::cast_utf8) && Arr::get($this->attributes,$key) && (! Arr::get($encoded,$key))) {
|
|
||||||
$this->attributes[$key] = utf8_decode($this->attributes[$key]);
|
$this->attributes[$key] = utf8_decode($this->attributes[$key]);
|
||||||
$encoded[$key] = TRUE;
|
$this->_encoded[$key] = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getAttribute($key);
|
return parent::getAttribute($key);
|
||||||
|
Loading…
Reference in New Issue
Block a user