SI EXISTE UN PROCESO EN MARCHA, NO INICIAR SIGUIENTE DESCARGA, AVISAR protected $rutaDiaria = FCPATH . "DOWNLOADS/DAILY/"; protected $rutaDiariaFecha = ""; protected $rutaMensual = FCPATH . "DOWNLOADS/MONTH/"; protected $enlaceAtom = ""; protected $fechaCreacionLog = ""; public function __construct() { parent::__construct(); $this->load->helper('file'); $this->load->helper('xml'); $this->load->library('Parserfile'); $this->load->model("Parser_model"); } public function index() { /*$fechaCarpeta = ""; $this->Parser_model->inicioParser(); $resultSetPerfiles = $this->Parser_model->getUrlArchivos(); $fechaCarpeta = date("Y-m-d_H-i-s"); $fechaImportacionLog = date("Y-m-d H:i:s"); foreach ($resultSetPerfiles['datos'] as $row) { $idUltimaImportacion = $this->Parser_model->setFechaNuevaImportacion($fechaImportacionLog); $this->Xlsexport_model->getLastDateLog($idUltimaImportacion); $this->fechaCreacionLog = $fechaCarpeta; $rutaPerfil = $this->rutaDiaria . "/" . $row->prefijos_tablas; $this->removeFoldersFromThursdayToMonday($rutaPerfil); $this->newFolder($rutaPerfil); if ($this->newFolder($rutaPerfil . "/" . $fechaCarpeta)) { $this->rutaDiariaFecha = $rutaPerfil . "/" . $fechaCarpeta . "/"; $this->downloadZip($row->url_descarga); } $files = get_filenames($this->rutaDiariaFecha . "/format"); emailInicioProcesoDescarga($fechaImportacionLog, $files); $this->parserfile->index($this->rutaDiariaFecha, $fechaCarpeta, $row, $idUltimaImportacion); } */ $idUltimaImportacion = 81; $this->tablasCalculadas($idUltimaImportacion); $this->load->library('ExportXls'); $this->exportxls->exportDatosCompletos(); $this->Parser_model->stopParser(); } private function downloadZip($urlXML) { $fechaDescarga = $this->getFechaForDownloadZip(); $fileName = basename($urlXML); $downladedZip = $this->downloadFile($fileName, $urlXML . $fechaDescarga, $this->rutaDiariaFecha); if ($downladedZip) { $zip = new ZipArchive; if ($zip->open($this->rutaDiariaFecha . $fileName)) { $zip->extractTo($this->rutaDiariaFecha); $zip->close(); unlink($this->rutaDiariaFecha . $fileName); $archivosTotales = get_filenames($this->rutaDiariaFecha); foreach ($archivosTotales as $file) { $this->getFile($this->rutaDiariaFecha . $file, $file); } } } } private function getFechaForDownloadZip(): String { $result = "_"; $anyo = date("Y"); $mes = date("m"); $mesPrevious = date("m", strtotime("-1 months")); $yearPrevious = date("Y", strtotime("-1 year")); $dia = date("d"); if (date("m") == "01") { $result .= $yearPrevious . $mesPrevious . ".zip"; } else { if ($dia == "01") { $result .= $anyo . $mesPrevious . ".zip"; } else { $result .= $anyo . $mes . ".zip"; } } return $result; } private function getFile($url, $fileName) { $feed = implode(file($url)); $xml = simplexml_load_string($feed); $json = json_encode($xml); $array = json_decode($json, true); $this->formatXml($feed, $fileName); return $array; } private function newFolder($rutaFinal) { $result = false; if (!is_dir($rutaFinal)) { $result = mkdir($rutaFinal); mkdir($rutaFinal . "/format"); } return $result; } private function formatXml($xml, $fileName) { $openingFormat = $this->regExIniciosEsquema($xml); $closureFormat = $this->regExFinalesEsquema($openingFormat); unlink($this->rutaDiariaFecha . "/" . $fileName); file_put_contents($this->rutaDiariaFecha . "/format/" . $fileName, $closureFormat); } private function downloadFile($fileName, $url, $ruta) { if (file_put_contents($ruta . $fileName, file_get_contents($url))) { return true; } else { return false; } } private function regExIniciosEsquema($xml) { $pattern = "/(Parser_model->truncateTables("vista_datos_licitacion"); $licitaciones = $this->Xlsexport_model->getLicitaciones($idUltimaImportacion); insertBucleDuplicateOnKey($licitaciones['datos'], "vista_datos_licitacion", "insertVistaDatosLicitacionesPreExcel"); } private function removeFoldersFromThursdayToMonday($ruta) { $dayWeek = date('l'); if ($dayWeek == "Friday") { $folders = glob($ruta . "/*"); $thursday = date('Y-m-d', strtotime(date("Y-m-d") . ' -1 days')); $minusSixDays = date('Y-m-d', strtotime($thursday . ' -6 days')); foreach ($folders as $folder) { $folderDate = substr($folder, -19, 10); if ($folderDate <= $thursday && $folderDate >= $minusSixDays) { eliminarArchivosProcesoCompleto($folder); } } } } }