Bladeren bron

Parametrizar tipo perfiles. No solapar varias instancias de cron

Nermosis 3 jaren geleden
bovenliggende
commit
aab90d8121

+ 34 - 6
application/controllers/Parser.php Bestand weergeven

@@ -8,6 +8,7 @@ class Parser extends CI_Controller
8 8
     //TODO: PARAMETRIZAR BBDD -> SI EXISTE UN PROCESO EN MARCHA, NO INICIAR SIGUIENTE DESCARGA, AVISAR
9 9
     protected $rutaDiaria = FCPATH . "DOWNLOADS/DAILY/";
10 10
     protected $rutaDiariaFecha = "";
11
+
11 12
     protected $rutaMensual = FCPATH . "DOWNLOADS/MONTH/";
12 13
     protected $enlaceAtom = "";
13 14
 
@@ -17,16 +18,43 @@ class Parser extends CI_Controller
17 18
         $this->load->helper('file');
18 19
         $this->load->helper('xml');
19 20
         $this->load->library('parserfile');
21
+        $this->load->model("Parser_model");
20 22
     }
21 23
 
22 24
     public function index()
23 25
     {
24
-        $fechaCarpeta = date("Y-m-d_H-i-s");
25
-        if ($this->newFolder($this->rutaDiaria . $fechaCarpeta)) {
26
-            $this->rutaDiariaFecha = $this->rutaDiaria . $fechaCarpeta . "/";
27
-            $this->downloadProcess(URL_DIARIA_CONTRATOS_MENORES_PERFILES_CONTRATANES);
28
-            $this->parserfile->index($this->rutaDiariaFecha, $fechaCarpeta);
26
+        $existCronRun = $this->Parser_model->existCronRun();
27
+
28
+        if ($existCronRun['num_rows'] > 0) {
29
+            if ($existCronRun['datos']->cron_ejecucion == 0) {
30
+
31
+                $this->Parser_model->inicioParser();
32
+
33
+                $resultSetPerfiles = $this->Parser_model->getUrlArchivos();
34
+
35
+                foreach ($resultSetPerfiles['datos'] as $row) {
36
+                    $fechaCarpeta = date("Y-m-d_H-i-s");
37
+                    $rutaPerfil = $this->rutaDiaria . "/" . $row->prefijos_tablas;
38
+
39
+                    $this->newFolder($rutaPerfil);
40
+
41
+                    if ($this->newFolder($rutaPerfil . "/" . $fechaCarpeta)) {
42
+                        $this->rutaDiariaFecha = $rutaPerfil . "/" . $fechaCarpeta . "/";
43
+
44
+                        $this->downloadProcess($row->url_descarga);
45
+
46
+                        $this->parserfile->index($this->rutaDiariaFecha, $fechaCarpeta);
47
+                    }
48
+                }
49
+            } else {
50
+                echo "EXISTE UN CRON EN MARCHA.";
51
+            }
52
+        } else {
53
+            echo "No existe parametro que iniciar.";
29 54
         }
55
+
56
+        $this->Parser_model->stopParser();
57
+
30 58
     }
31 59
 
32 60
     private function downloadProcess($urlXML)
@@ -50,7 +78,7 @@ class Parser extends CI_Controller
50 78
         }
51 79
     }
52 80
 
53
-    private function getFile($url = URL_DIARIA, $fileName)
81
+    private function getFile($url, $fileName)
54 82
     {
55 83
 
56 84
         $feed = implode(file($url));

+ 2 - 0
application/libraries/ParserDatabase.php Bestand weergeven

@@ -55,6 +55,8 @@ class ParserDatabase
55 55
                 }
56 56
             }
57 57
         }
58
+
59
+        return;
58 60
     }
59 61
 
60 62
     private function setInicioLicitacion($datosInicioLicitacion): array

+ 2 - 0
application/libraries/ParserFile.php Bestand weergeven

@@ -71,6 +71,8 @@ class ParserFile
71 71
         }
72 72
 
73 73
         $this->CI->parserdatabase->setDatosParser($resultEntries, $fechaInicioParser);
74
+
75
+        return;
74 76
     }
75 77
 
76 78
     private function nodoEntry($xml)

+ 36 - 8
application/models/Parser_model.php Bestand weergeven

@@ -26,21 +26,49 @@ class Parser_model extends CI_Model
26 26
         parent::__construct();
27 27
     }
28 28
 
29
-    public function setInicioLicitacion($licitacionArr)
29
+    public function inicioParser()
30 30
     {
31
-        $this->db->insert('BRUTO_datos_iniciales', $licitacionArr);
32
-        return $this->db->insert_id();
31
+        $data = array(
32
+            'cron_ejecucion' => 1,
33
+            "fecha_ejecucion" => date("Y-m-d h:i:s"),
34
+        );
35
+
36
+        $this->db->where('id', 0);
37
+        $this->db->update('parametros_cron', $data);
33 38
     }
34 39
 
35
-    public function setLocatedContractInfo($locatedContractArr)
40
+    public function stopParser()
36 41
     {
37
-        $this->db->insert('BRUTO_located_contracting_party', $locatedContractArr);
38
-        return $this->db->insert_id();
42
+        $data = array(
43
+            'cron_ejecucion' => 0,
44
+            "fecha_ejecucion" => date("Y-m-d h:i:s"),
45
+        );
46
+
47
+        $this->db->where('id', 0);
48
+        $this->db->update('parametros_cron', $data);
49
+    }
50
+
51
+    public function existCronRun()
52
+    {
53
+        $sql = "SELECT * FROM parametros_cron";
54
+        $result = $this->db->query($sql);
55
+        $datos['datos'] = $result->row();
56
+        $datos['num_rows'] = $result->num_rows();
57
+        return $datos;
39 58
     }
40 59
 
41
-    public function setParty($partyArr)
60
+    public function getUrlArchivos()
42 61
     {
43
-        $this->db->insert('BRUTO_party', $partyArr);
62
+        $sql = "SELECT * FROM tipo_licitacion_tablas";
63
+        $result = $this->db->query($sql);
64
+        $datos['datos'] = $result->result();
65
+        $datos['num_rows'] = $result->num_rows();
66
+        return $datos;
67
+    }
68
+
69
+    public function setInicioLicitacion($licitacionArr)
70
+    {
71
+        $this->db->insert('BRUTO_datos_iniciales', $licitacionArr);
44 72
         return $this->db->insert_id();
45 73
     }
46 74