Implemented filefix %RESEND
This commit is contained in:
parent
ce19985c2d
commit
2ea8bbd0b8
79
app/Classes/FTN/Process/Netmail/Robot/Filefix/Resend.php
Normal file
79
app/Classes/FTN/Process/Netmail/Robot/Filefix/Resend.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\FTN\Process\Netmail\Robot\Filefix;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Classes\FTN\Process\Netmail\Robot\Areafix\Base;
|
||||
|
||||
// Resend a file
|
||||
class Resend extends Base
|
||||
{
|
||||
private const LOGKEY = 'FFA';
|
||||
|
||||
private const command = '%RESEND';
|
||||
|
||||
public static function help(): array
|
||||
{
|
||||
return [
|
||||
self::command.' <FILEAREA> <FILENAME>',
|
||||
' 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 <FILEAREA>',
|
||||
];
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user