fix Hiltes import

This commit is contained in:
Marko
2023-09-19 15:29:22 +02:00
parent 0abbd0ab29
commit 86f28121aa
11 changed files with 127 additions and 127 deletions

0
src/ApiResource/.gitignore vendored Normal file
View File

View File

@@ -65,8 +65,6 @@ class HiltesImportCommand extends Command
return Command::FAILURE;
}else{
$io->info('Start Hiltes Push JTL');
// $pushStock = new SwPushStockCommand($this->productRepository,$this->logger);
// $pushStock->execute($input,$output);
$jtl = new JtlExportCommand($this->productRepository,$this->stockRepository,$this->warehouseRepository,$this->logger);
$jtl->execute($input,$output);

View File

@@ -1,8 +1,101 @@
<?php
namespace App\Helper;
use phpseclib3\Net\SFTP;
class Ftp
{
private string $host;
private int $port;
private string $user;
private string $password;
private string $remoteDir;
public function __construct()
{
$this->setHost($_ENV['FTP_HOST']);
$this->setPort((int)$_ENV['FTP_PORT']);
$this->setUser($_ENV['FTP_USER']);
$this->setPassword($_ENV['FTP_PASSWORD']);
$this->setRemoteDir($_ENV['FTP_REMOTE_DIR']);
}
public function getHost(): string
{
return $this->host;
}
public function setHost(string $host): void
{
$this->host = $host;
}
public function getPort(): int
{
return $this->port;
}
public function setPort(int $port): void
{
$this->port = $port;
}
public function getUser(): string
{
return $this->user;
}
public function setUser(string $user): void
{
$this->user = $user;
}
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): void
{
$this->password = $password;
}
public function getRemoteDir(): string
{
return $this->remoteDir;
}
public function setRemoteDir(string $remoteDir): void
{
$this->remoteDir = $remoteDir;
}
/**
* @param string $localFile
* @return bool
*/
public function uploadFile(string $localFile): bool
{
#dd(array($localFile,$this->getHost(),$this->getUser(), $this->getPassword(),$this->getRemoteDir()));
$sftp = new SFTP($this->getHost(),$this->getPort());
$sftp_login = $sftp->login($this->getUser(), $this->getPassword());
//dump(array('$sftp_login'=>$sftp_login,'Line'=>__LINE__,'Method'=>__METHOD__));
$remoteFile = 'order_'.date('YmdHis').'.csv';
if($sftp_login){
$r = $sftp->put($this->getRemoteDir().$remoteFile.'.tmp', $localFile, SFTP::SOURCE_LOCAL_FILE);
//dump(array('$r'=>$r,$this->getRemoteDir().$remoteFile, $localFile,'Line'=>__LINE__));
if($r){
if($sftp->rename($this->getRemoteDir().$remoteFile.'.tmp',$this->getRemoteDir().$remoteFile))
return unlink($localFile); # löschen der datei
else
return false;
}else
return false;
}
return false;
}
}

View File

@@ -47,6 +47,8 @@ class HiltesImport
$count = 0;
if(!empty($this->arrData['orgFiles']['data']) && count($this->arrData['orgFiles']['data'])){
foreach ($this->arrData['orgFiles']['data'] as $file) {
if(is_file($file['realPath'])){
$count += $this->loadFiles($file['realPath'],$file['fileSize']);
}else{
@@ -56,7 +58,7 @@ class HiltesImport
}
dump("Imported $count stocks");
//remove fertig file
unlink($this->currentDirPath.'/hiltes/h2c/WS.FERTIG');
//unlink($this->currentDirPath.'/hiltes/h2c/WS.FERTIG');
}else
return array('success'=>1,'text'=>'No Files');