mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
refactor upload files from stp side
This commit is contained in:
@ -58,12 +58,14 @@ class SafekatFtpClient
|
||||
public function uploadFilePresupuesto(int $presupuesto_id)
|
||||
{
|
||||
try {
|
||||
if ($this->xml_enabled == false) return false;
|
||||
$model = model(PresupuestoFicheroModel::class);
|
||||
$modelPedidoLinea = model(PedidoLineaModel::class);
|
||||
$pedidoLinea = $modelPedidoLinea->findByPresupuesto($presupuesto_id);
|
||||
$rootIdExtern = 1e6 + $pedidoLinea->pedido_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]);
|
||||
@ -73,6 +75,29 @@ class SafekatFtpClient
|
||||
}
|
||||
$this->ftp->put($remoteFile,$value->file_path,mode:$this->ftp::SOURCE_LOCAL_FILE);
|
||||
}
|
||||
$this->ftp->disconnect();
|
||||
} catch (Exception $e) {
|
||||
log_message('error', $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
public function removeFiles(int $presupuesto_id)
|
||||
{
|
||||
try {
|
||||
// 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];
|
||||
$remoteFile = implode("/", [$this->base_dir,"pedidos_files",$rootIdExtern,$filename]);
|
||||
$this->ftp->delete($remoteFile);
|
||||
}
|
||||
$this->ftp->disconnect();
|
||||
} catch (Exception $e) {
|
||||
log_message('error', $e->getMessage());
|
||||
throw $e;
|
||||
|
||||
Reference in New Issue
Block a user