M3 Security Fixes for pass 28

This commit is contained in:
Mark Gregory
2026-09-17 10:45:19 +01:00
parent 1644efed9c
commit 1037c1c202
3 changed files with 248 additions and 484 deletions
+47 -114
View File
@@ -12,129 +12,62 @@ use Str;
class CallCloseAPI extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:CallCloseAPI {user?} {manifest?} {co?} {whs?} ';
protected $description = 'Call Close API';
public function __construct()
{
parent::__construct();
}
public function handle()
{
// $this->info('Start CallCloseAPI...');
ini_set('max_execution_time', Config::get('arrays.PHPTimeOut'));
ini_set('max_input_time', Config::get('arrays.PHPTimeOut'));
ini_set('default_socket_timeout', Config::get('arrays.PHPTimeOut'));
self::configureTimeouts();
try {
// Get the Calling User
$userId = $this->argument('user');
$SHUSER = isset($userId) ? $userId : (m3_user() !== '' ? Str::upper(trim(m3_user())) : '');
// Get the Manifest Number
$manifest = $this->argument('manifest');
$MANIFESTNum = isset($manifest) ? $manifest : '';
$co = $this->argument('co');
$APCO = isset($co) ? $co : '';
$whs = $this->argument('whs');
$APWHS = isset($whs) ? $whs : '';
// if ($SHUSER!='') {
// Log::channel('dailyCron')->info("Cron...Start CallCloseAPI...For Manifest#: ".$MANIFESTNum); // ".$SHUSER."
if ($MANIFESTNum == '') {
// Get Macpickers from ICM705M1
$ICM705M1 = DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
->select('APMANIFEST', 'APCO', 'APWHS')
->where('APSPARE2', '')
->where('APMANIFEST', '!=', '0')
->whereRaw('EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP - APLDCLOZ)) / 60 > 15')
->orderBy('APMANIFEST', 'desc')
->get();
// dump($ICM705M1);
if (count($ICM705M1) > 0) {
// Loop the Results from $ICM705M1
foreach ($ICM705M1 as $key => $ICM705M1R) {
$MANIFESTNum = $ICM705M1R->APMANIFEST;
$USERCO = isset($ICM705M1R->APCO) ? $ICM705M1R->APCO : '';
$USERWH = isset($ICM705M1R->APWHS) ? $ICM705M1R->APWHS : '';
// Update ICM705M1 and set APSPARE2 to P
$ICM705M1U = DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
->where('APMANIFEST', $MANIFESTNum)
->where('APCO', $USERCO)
->where('APWHS', $USERWH)
->update(['APSPARE2' => 'P']);
$myRequest = new Request;
$myRequest->setMethod('POST');
$myRequest->request->add([
'WHS' => $USERWH,
'COMPANY' => $USERCO,
'TRANSTYPE' => 'M',
'MANIFEST' => $MANIFESTNum,
]);
$callCloseShipment = CloseShipment::CloseShipmentCoChargeAPI($myRequest);
$responseData = $callCloseShipment->getData();
$jsonData = json_encode($responseData);
Log::channel('dailyCron')->info('Close Shipment API Response for Manifest:' . (string) (int) $MANIFESTNum . '-' . $jsonData);
}
}
$manifest = (string) ($this->argument('manifest') ?? '');
if ($manifest !== '') {
return $this->closeSpecificManifest($manifest, (string) ($this->argument('co') ?? ''), (string) ($this->argument('whs') ?? ''));
}
// Call Closing for a specific Manifest
else {
// Get Macpickers from ICM705M1
$ICM705M1 = DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
->select('APMANIFEST', 'APCO', 'APWHS')
->where('APSPARE2', '')
->where('APCO', $APCO)
->where('APWHS', $APWHS)
->where('APMANIFEST', '=', $MANIFESTNum)
->first();
// Update ICM705M1 and set APSPARE2 to P
$ICM705M1U = DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
->where('APMANIFEST', $MANIFESTNum)
->where('APCO', $APCO)
->where('APWHS', $APWHS)
->update(['APSPARE2' => 'P']);
$myRequest = new Request;
$myRequest->setMethod('POST');
$myRequest->request->add([
'WHS' => $APWHS,
'COMPANY' => $APCO,
'TRANSTYPE' => 'M',
'MANIFEST' => $MANIFESTNum,
]);
$callCloseShipment = CloseShipment::CloseShipmentCoChargeAPI($myRequest);
$responseData = $callCloseShipment->getData();
$jsonData = json_encode($responseData);
Log::channel('dailyCron')->info('Close Shipment API Response for Manifest:' . $MANIFESTNum . '-' . $jsonData);
return 1;
}
// }
// else{
// Log::channel('dailyCron')->error('A user must be defined...');
// $this->error('A user must be defined...');
// }
$this->closePendingManifests();
return self::SUCCESS;
} catch (\Throwable $th) {
// Log::error($th);
Log::channel('dailyCron')->error($th);
return self::FAILURE;
}
}
private static function configureTimeouts(): void
{
$timeout = Config::get('arrays.PHPTimeOut');
ini_set('max_execution_time', $timeout);
ini_set('max_input_time', $timeout);
ini_set('default_socket_timeout', $timeout);
}
private function closePendingManifests(): void
{
$rows = DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
->select('APMANIFEST', 'APCO', 'APWHS')->where('APSPARE2', '')->where('APMANIFEST', '!=', '0')
->whereRaw('EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP - APLDCLOZ)) / 60 > 15')->orderBy('APMANIFEST', 'desc')->get();
foreach ($rows as $row) {
$this->closeManifest((string) $row->APMANIFEST, (string) ($row->APCO ?? ''), (string) ($row->APWHS ?? ''));
}
}
private function closeSpecificManifest(string $manifest, string $co, string $whs): int
{
$exists = DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
->where('APSPARE2', '')->where('APCO', $co)->where('APWHS', $whs)->where('APMANIFEST', $manifest)->exists();
if (! $exists) {
Log::channel('dailyCron')->warning('Manifest not available for close', compact('manifest', 'co', 'whs'));
return self::FAILURE;
}
$this->closeManifest($manifest, $co, $whs);
return self::SUCCESS;
}
private function closeManifest(string $manifest, string $co, string $whs): void
{
DB::connection(config('m3.connection', 'pgsql'))->table('icm705m1')
->where('APMANIFEST', $manifest)->where('APCO', $co)->where('APWHS', $whs)->update(['APSPARE2' => 'P']);
$request = Request::create('', 'POST', ['WHS' => $whs, 'COMPANY' => $co, 'TRANSTYPE' => 'M', 'MANIFEST' => $manifest]);
$response = CloseShipment::CloseShipmentCoChargeAPI($request);
$json = json_encode($response->getData());
Log::channel('dailyCron')->info('Close Shipment API Response for Manifest:' . $manifest . '-' . $json);
}
}