From cb40d767f1bca1cf057987765b235da0d35e0362 Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 28 Nov 2024 23:20:10 +1100 Subject: [PATCH] Implemented filefix %RESEND --- .../Process/Netmail/Robot/Filefix/Resend.php | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 app/Classes/FTN/Process/Netmail/Robot/Filefix/Resend.php diff --git a/app/Classes/FTN/Process/Netmail/Robot/Filefix/Resend.php b/app/Classes/FTN/Process/Netmail/Robot/Filefix/Resend.php new file mode 100644 index 0000000..00c091a --- /dev/null +++ b/app/Classes/FTN/Process/Netmail/Robot/Filefix/Resend.php @@ -0,0 +1,79 @@ + ', + ' Resend a file from a file area', + ' Arguments:', + ' - FILEAREA (required) name of area to subscribe or unsubscribe', + ' - FILENAME (required) number of file to resend', + ' Notes:', + ' * You can obtain a list of files in an area with %FILELIST ', + ]; + } + + public function process(): string + { + $command = self::command.' '.join(' ',$this->arguments); + + if (count($this->arguments) < 2) + return sprintf('%-25s <-- INVALID, NOT ENOUGH ARGUMENTS',$command); + elseif (count($this->arguments) > 2) + return sprintf('%-25s <-- INVALID, TOO MANU ARGUMENTS',$command); + + Log::debug(sprintf('%s:- Resending [%s] from [%s] to [%s]',self::LOGKEY,$this->arguments[1],$this->arguments[0],$this->mo->fftn->ftn)); + + // Area exists + if ($fa=$this->mo->fftn->domain->fileareas->where('name',$this->arguments[0])->pop()) { + // If already subscribed + if ($nea=$this->mo->fftn->fileareas->where('name',$fa->name)->pop()) { + // Check the file is in the area + if ($fo=$nea->files()->where('name','ilike',$this->arguments[1])->single()) { + // File hasnt been exported before + if (! $fo->seenby->where('id',$this->mo->fftn_id)->count()) { + Log::info(sprintf('Exported [%d] FILE (%s) dated (%s) to [%s]',$fo->id,$fo->name,$fo->datetime->format('Y-m-d H:i:s'),$this->mo->fftn->ftn3d)); + $fo->seenby()->attach($this->mo->fftn_id,['export_at'=>Carbon::now()]); + + } else { + Log::debug(sprintf('Re-exported [%d] FILE (%s) dated (%s) to [%s]',$fo->id,$fo->name,$fo->datetime,$this->mo->fftn->ftn3d)); + $fo->seenby()->updateExistingPivot($this->mo->fftn_id,['export_at'=>Carbon::now(),'sent_at'=>NULL]); + } + + return sprintf('%-25s <-- FILE QUEUED TO RESEND',$command); + + // No file in area + } else { + Log::debug(sprintf('%s:- FTN [%s] doesnt have a file [%s], NO ACTION taken',self::LOGKEY,$this->mo->fftn->ftn,$this->arguments[1])); + + return sprintf('%-25s <-- FILE NOT FOUND, NO ACTION taken',$command); + } + + // If not subscribed + } else { + Log::debug(sprintf('%s:- FTN [%s] is NOT subscribed to [%s], NO ACTION taken',self::LOGKEY,$this->mo->fftn->ftn,$this->arguments[0])); + + return sprintf('%-25s <-- NOT subscribed, NO ACTION taken',$command); + } + + } else { + Log::debug(sprintf('%s:- FILE [%s] area UNKNOWN [%s], NO ACTION taken',self::LOGKEY,$this->mo->fftn->ftn,$this->arguments[0])); + + return sprintf('%-25s <-- AREA UNKNOWN, NO ACTION TAKEN',$command); + } + } +} \ No newline at end of file