mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Implementada funcionalidad
This commit is contained in:
@ -40,13 +40,14 @@ class SafekatFtpClient
|
||||
public function uploadXML(string $content, string $filename): bool
|
||||
{
|
||||
try {
|
||||
if ($this->xml_enabled == false) return false;
|
||||
$remotePath = implode("/", [$this->base_dir,'pedidos','xml_nuevos']);
|
||||
if ($this->xml_enabled == false)
|
||||
return false;
|
||||
$remotePath = implode("/", [$this->base_dir, 'pedidos', 'xml_nuevos']);
|
||||
$this->ftp->login(username: $this->username, password: $this->password);
|
||||
if(!$this->ftp->is_dir($remotePath)){
|
||||
$this->ftp->mkdir($remotePath,recursive:true);
|
||||
if (!$this->ftp->is_dir($remotePath)) {
|
||||
$this->ftp->mkdir($remotePath, recursive: true);
|
||||
}
|
||||
$this->ftp->put($remotePath.'/'.$filename, $content);
|
||||
$this->ftp->put($remotePath . '/' . $filename, $content);
|
||||
|
||||
return true;
|
||||
} catch (\Throwable $th) {
|
||||
@ -58,22 +59,23 @@ class SafekatFtpClient
|
||||
public function uploadFilePresupuesto(int $presupuesto_id)
|
||||
{
|
||||
try {
|
||||
if ($this->xml_enabled == false) return false;
|
||||
if ($this->xml_enabled == false)
|
||||
return false;
|
||||
$model = model(PresupuestoFicheroModel::class);
|
||||
$modelPedidoLinea = model(PedidoLineaModel::class);
|
||||
$pedidoLinea = $modelPedidoLinea->findByPresupuesto($presupuesto_id);
|
||||
$rootIdExtern = $this->pedido_xml_config->id_offset + $pedidoLinea->pedido_id;
|
||||
$presupuestoFiles = $model->getFiles($presupuesto_id);
|
||||
$this->ftp->login(username: $this->username, password: $this->password);
|
||||
|
||||
|
||||
foreach ($presupuestoFiles as $key => $value) {
|
||||
$filename = array_reverse(explode("/", $value->file_path))[0];
|
||||
$remoteDir = implode("/", [$this->base_dir,"pedidos_files",$rootIdExtern]);
|
||||
$remoteFile = implode("/", [$this->base_dir,"pedidos_files",$rootIdExtern,$filename]);
|
||||
if(!$this->ftp->is_dir($remoteDir)){
|
||||
$this->ftp->mkdir($remoteDir,recursive:true);
|
||||
$remoteDir = implode("/", [$this->base_dir, "pedidos_files", $rootIdExtern]);
|
||||
$remoteFile = implode("/", [$this->base_dir, "pedidos_files", $rootIdExtern, $filename]);
|
||||
if (!$this->ftp->is_dir($remoteDir)) {
|
||||
$this->ftp->mkdir($remoteDir, recursive: true);
|
||||
}
|
||||
$this->ftp->put($remoteFile,$value->file_path,mode:$this->ftp::SOURCE_LOCAL_FILE);
|
||||
$this->ftp->put($remoteFile, $value->file_path, mode: $this->ftp::SOURCE_LOCAL_FILE);
|
||||
}
|
||||
$this->ftp->disconnect();
|
||||
} catch (Exception $e) {
|
||||
@ -91,10 +93,10 @@ class SafekatFtpClient
|
||||
$rootIdExtern = $this->pedido_xml_config->id_offset + $pedidoLinea->pedido_id;
|
||||
$presupuestoFiles = $model->getFiles($presupuesto_id);
|
||||
$this->ftp->login(username: $this->username, password: $this->password);
|
||||
|
||||
|
||||
foreach ($presupuestoFiles as $key => $value) {
|
||||
$filename = array_reverse(explode("/", $value->file_path))[0];
|
||||
$remoteFile = implode("/", [$this->base_dir,"pedidos_files",$rootIdExtern,$filename]);
|
||||
$remoteFile = implode("/", [$this->base_dir, "pedidos_files", $rootIdExtern, $filename]);
|
||||
$this->ftp->delete($remoteFile);
|
||||
}
|
||||
$this->ftp->disconnect();
|
||||
@ -103,4 +105,13 @@ class SafekatFtpClient
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function getPresupuestoRemotePath(int $presupuesto_id): string
|
||||
{
|
||||
$modelPedidoLinea = model(PedidoLineaModel::class);
|
||||
$pedidoLinea = $modelPedidoLinea->findByPresupuesto($presupuesto_id);
|
||||
$rootIdExtern = $this->pedido_xml_config->id_offset + $pedidoLinea->pedido_id;
|
||||
|
||||
return implode('/', [$this->base_dir, 'pedidos_files', $rootIdExtern]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user