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 = ""; public function __construct() { parent::__construct(); $this->load->helper('file'); $this->load->helper('xml'); $this->load->library('parserfile'); } public function index() { $fechaCarpeta = date("Y-m-d_H-i-s"); if ($this->newFolder($this->rutaDiaria . $fechaCarpeta)) { $this->rutaDiariaFecha = $this->rutaDiaria . $fechaCarpeta . "/"; $this->downloadProcess(URL_DIARIA_CONTRATOS_MENORES_PERFILES_CONTRATANES); $this->parserfile->index($this->rutaDiariaFecha, $fechaCarpeta); } } private function downloadProcess($urlXML) { $fileName = basename($urlXML); $this->downloadFile($fileName, $urlXML, $this->rutaDiariaFecha); $archivoAtom = $this->getFile($this->rutaDiariaFecha . $fileName, $fileName); $nuevoAtomAttrNext = $this->readNextAttribute($archivoAtom); //while ($nuevoAtomAttrNext !== "") { $aux = 0; while ($aux <= 3) { $fileName = basename($nuevoAtomAttrNext); $this->downloadFile($fileName, $nuevoAtomAttrNext, $this->rutaDiariaFecha); $archivoAtom = $this->getFile($this->rutaDiariaFecha . $fileName, $fileName); $nuevoAtomAttrNext = $this->readNextAttribute($archivoAtom); $aux++; } } private function getFile($url = URL_DIARIA, $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); file_put_contents($this->rutaDiariaFecha . "/format/" . $fileName, $closureFormat); } private function readNextAttribute($archivo) { $enlace = ""; foreach ($archivo['link'] as $row) { $attrNext = $row['@attributes']['rel']; $attrHref = $row['@attributes']['href']; if ($attrNext === "next") { $enlace = $attrHref; } } return $enlace; } 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 = "/(