mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
ftp service
This commit is contained in:
48
ci4/app/Services/FTPService.php
Normal file
48
ci4/app/Services/FTPService.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use CodeIgniter\Config\BaseService;
|
||||
use CodeIgniter\Files\File;
|
||||
use FtpClient\FtpClient;
|
||||
|
||||
class FTPService extends BaseService
|
||||
{
|
||||
protected FtpClient $ftp;
|
||||
protected string $host;
|
||||
protected string $port;
|
||||
protected string $username;
|
||||
protected string $password;
|
||||
protected string $base_dir;
|
||||
protected object $ftp_config;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->ftp = new FtpClient();
|
||||
$this->ftp_config = config("FTP");
|
||||
$this->host = $this->ftp_config->host;
|
||||
$this->username = $this->ftp_config->username;
|
||||
$this->password = $this->ftp_config->password;
|
||||
$this->base_dir = $this->ftp_config->base_dir;
|
||||
}
|
||||
/**
|
||||
* Upload the content of $filename to the base directory declared in App\Config\FTP.php
|
||||
*
|
||||
* @param string $content
|
||||
* @param string $filename
|
||||
* @return boolean
|
||||
*/
|
||||
public function uploadXML(string $content, string $filename): bool
|
||||
{
|
||||
try {
|
||||
$remotePath = implode("/", [$this->base_dir, $filename]);
|
||||
$this->ftp->connect(host: $this->host, port: $this->port);
|
||||
$this->ftp->login(username: $this->username, password: $this->password);
|
||||
$this->ftp->putFromString($remotePath, $content);
|
||||
return true;
|
||||
} catch (\Throwable $th) {
|
||||
log_message('error',$th->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,7 @@ use App\Models\Pedidos\PedidoLineaModel;
|
||||
use App\Models\Presupuestos\PresupuestoModel;
|
||||
use DOMDocument;
|
||||
use DOMNode;
|
||||
use FTP;
|
||||
|
||||
class PedidoXMLService extends BaseService
|
||||
{
|
||||
@ -168,8 +169,15 @@ class PedidoXMLService extends BaseService
|
||||
$xml_products_el->appendChild($xml->createElement('CommentsClient', $data["pedido_cliente_presupuesto"]->comentarios_cliente));
|
||||
$xml->appendChild($xml_products_el);
|
||||
$file_has_suffix = hash('sha512',$data["pedido_cliente_presupuesto"]->pedidoId);
|
||||
$file_name = PedidoXMLService::generate_xml_file_name($file_has_suffix);
|
||||
$ftp = service('FTPService');
|
||||
$ftp->uploadXML($xml->textContent,$file_name);
|
||||
return $data;
|
||||
}
|
||||
protected static function generate_xml_file_name(string $hash) : string
|
||||
{
|
||||
return implode("",["Safekat_",$hash,".xml"]);
|
||||
}
|
||||
protected static function get_color_interior($pre_linea): ?string
|
||||
{
|
||||
$color_interior = null;
|
||||
|
||||
Reference in New Issue
Block a user