Move the send DB updates out of the protocol and into Send::class

This commit is contained in:
2023-07-19 12:32:41 +10:00
parent 7584e3e44e
commit f4fc6c24a4
6 changed files with 67 additions and 58 deletions

View File

@@ -573,7 +573,7 @@ final class Binkp extends BaseProtocol
$buf = $this->send->read(self::BLOCKSIZE);
} catch (UnreadableFileEncountered) {
$this->send->close(FALSE);
$this->send->close(FALSE,$this->node);
$this->sessionClear(self::SE_SENDFILE);
} catch (\Exception $e) {
@@ -863,7 +863,7 @@ final class Binkp extends BaseProtocol
$this->msgs(self::BPM_ERR,sprintf('M_FILE: unparsable file info: "%s", what are you on?',$buf));
if ($this->sessionGet(self::SE_SENDFILE))
$this->send->close(FALSE);
$this->send->close(FALSE,$this->node);
$this->rc = self::S_FAILURE;
@@ -957,7 +957,7 @@ final class Binkp extends BaseProtocol
Log::error(sprintf('%s:! Cannot send file from requested offset [%d]',self::LOGKEY,$file['offs']));
$this->msgs(self::BPM_ERR,'Can\'t send file from requested offset');
$this->send->close(FALSE);
$this->send->close(FALSE,$this->node);
$this->sessionClear(self::SE_SENDFILE);
} else {
@@ -998,45 +998,10 @@ final class Binkp extends BaseProtocol
Log::error(sprintf('%s:! M_got[skip] for unknown file [%s]',self::LOGKEY,$buf));
} else {
Log::info(sprintf('%s:= Packet/File [%s], type [%d] sent with [%d] items.',self::LOGKEY,$this->send->nameas,$this->send->type,$this->send->dbids->count()));
Log::info(sprintf('%s:= Packet/File [%s], type [%d] sent.',self::LOGKEY,$this->send->nameas,$this->send->type));
$this->sessionClear(self::SE_WAITGOT|self::SE_SENDFILE);
// Update netmail table
if (($this->send->type === Send::T_NETMAIL)
&& ($x=$this->send->dbids)->count())
DB::table('netmails')
->whereIn('id',$x)
->update([
'sent_at'=>Carbon::now(),
'sent_pkt'=>$this->send->name,
'sent_id'=>$this->node->address->id,
'flags'=>DB::raw('flags | '.Message::FLAG_SENT),
]);
// Update echomails table
elseif (($this->send->type === Send::T_ECHOMAIL)
&& ($x=$this->send->dbids)->count()
&& $this->node->aka_remote_authed->count())
DB::table('echomail_seenby')
->whereIn('echomail_id',$x)
->whereIn('address_id',$this->node->aka_remote_authed->pluck('id'))
->update([
'sent_at'=>Carbon::now(),
'sent_pkt'=>$this->send->name,
]);
// Update the file seenby
elseif (($this->send->type === Send::T_FILE)
&& ($x=$this->send->dbids)->count()
&& $this->node->aka_remote_authed->count())
DB::table('file_seenby')
->whereIn('file_id',$x)
->whereIn('address_id',$this->node->aka_remote_authed->pluck('id'))
->update([
'sent_at'=>Carbon::now(),
]);
$this->send->close(TRUE);
$this->send->close(TRUE,$this->node);
}
}