Move the send DB updates out of the protocol and into Send::class
This commit is contained in:
@@ -2,9 +2,12 @@
|
||||
|
||||
namespace App\Classes\File;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
use App\Classes\Node;
|
||||
use App\Models\File as FileModel;
|
||||
|
||||
final class File extends Send
|
||||
@@ -49,11 +52,22 @@ final class File extends Send
|
||||
}
|
||||
}
|
||||
|
||||
public function close(bool $successful): void
|
||||
public function close(bool $successful,Node $node): void
|
||||
{
|
||||
if ($successful)
|
||||
if ($successful) {
|
||||
$this->complete = TRUE;
|
||||
|
||||
if (($this->type === Send::T_FILE)
|
||||
&& ($x=$this->dbids)->count()
|
||||
&& $node->aka_remote_authed->count())
|
||||
DB::table('file_seenby')
|
||||
->whereIn('file_id',$x)
|
||||
->whereIn('address_id',$node->aka_remote_authed->pluck('id'))
|
||||
->update([
|
||||
'sent_at'=>Carbon::now(),
|
||||
]);
|
||||
}
|
||||
|
||||
fclose($this->fd);
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,10 @@ namespace App\Classes\File;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
use App\Classes\FTN\Packet;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use App\Classes\Node;
|
||||
use App\Classes\FTN\{Message,Packet};
|
||||
|
||||
final class Mail extends Send
|
||||
{
|
||||
@@ -48,10 +51,35 @@ final class Mail extends Send
|
||||
}
|
||||
}
|
||||
|
||||
public function close(bool $successful): void
|
||||
public function close(bool $successful,Node $node): void
|
||||
{
|
||||
if ($successful)
|
||||
if ($successful) {
|
||||
$this->complete = TRUE;
|
||||
|
||||
// Update netmail table
|
||||
if (($this->type === Send::T_NETMAIL)
|
||||
&& ($x=$this->dbids)->count())
|
||||
DB::table('netmails')
|
||||
->whereIn('id',$x)
|
||||
->update([
|
||||
'sent_at'=>Carbon::now(),
|
||||
'sent_pkt'=>$this->name,
|
||||
'sent_id'=>$node->address->id,
|
||||
'flags'=>DB::raw('flags | '.Message::FLAG_SENT),
|
||||
]);
|
||||
|
||||
// Update echomails table
|
||||
elseif (($this->type === Send::T_ECHOMAIL)
|
||||
&& ($x=$this->dbids)->count()
|
||||
&& $node->aka_remote_authed->count())
|
||||
DB::table('echomail_seenby')
|
||||
->whereIn('echomail_id',$x)
|
||||
->whereIn('address_id',$node->aka_remote_authed->pluck('id'))
|
||||
->update([
|
||||
'sent_at'=>Carbon::now(),
|
||||
'sent_pkt'=>$this->name,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function feof(): bool
|
||||
|
@@ -6,6 +6,7 @@ use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use League\Flysystem\UnreadableFileEncountered;
|
||||
|
||||
use App\Classes\Node;
|
||||
use App\Models\Address;
|
||||
|
||||
/**
|
||||
@@ -72,7 +73,6 @@ class Send extends Base
|
||||
->filter(function($item) { return $item->isType(self::IS_ARC|self::IS_PKT); })
|
||||
->sum(function($item) { return $item->size; });
|
||||
|
||||
case 'dbids':
|
||||
case 'name':
|
||||
case 'nameas':
|
||||
case 'mtime':
|
||||
@@ -112,19 +112,20 @@ class Send extends Base
|
||||
* Close the file descriptor of the file we are sending
|
||||
*
|
||||
* @param bool $successful
|
||||
* @param Node $node
|
||||
* @throws Exception
|
||||
*/
|
||||
public function close(bool $successful): void
|
||||
public function close(bool $successful,Node $node): void
|
||||
{
|
||||
if (! $this->fd)
|
||||
throw new Exception('No file to close');
|
||||
|
||||
if ($successful) {
|
||||
$end = time()-$this->start;
|
||||
Log::debug(sprintf('%s: - Closing [%s], sent in [%d]',self::LOGKEY,$this->sending->nameas,$end));
|
||||
Log::debug(sprintf('%s: - Closing [%s], sent in [%d] with [%s] items',self::LOGKEY,$this->sending->nameas,$end,$this->sending->dbids->count()));
|
||||
}
|
||||
|
||||
$this->sending->close($successful);
|
||||
$this->sending->close($successful,$node);
|
||||
$this->index = NULL;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user