Christian 3 years ago
parent
commit
c846444cbb

+ 50 - 56
application/controllers/Parser.php View File

25
 
25
 
26
     public function index()
26
     public function index()
27
     {
27
     {
28
-        $existCronRun = $this->Parser_model->existCronRun();
28
+        /*$existCronRun = $this->Parser_model->existCronRun();
29
 
29
 
30
         if ($existCronRun['num_rows'] > 0) {
30
         if ($existCronRun['num_rows'] > 0) {
31
-            if ($existCronRun['datos']->cron_ejecucion == 0) {
31
+        if ($existCronRun['datos']->cron_ejecucion == 0) {
32
 
32
 
33
-                $this->Parser_model->inicioParser();
33
+        $this->Parser_model->inicioParser();
34
 
34
 
35
-                $tablasTruncate = $this->Parser_model->getMapaTablas();
35
+        $resultSetPerfiles = $this->Parser_model->getUrlArchivos();
36
 
36
 
37
-                foreach ($tablasTruncate['datos'] as $row) {
38
-                    $this->Parser_model->truncateTables($row->tabla_sucia);
39
-                }
40
-
41
-                $resultSetPerfiles = $this->Parser_model->getUrlArchivos();
42
-
43
-                foreach ($resultSetPerfiles['datos'] as $row) {
44
-                    $fechaCarpeta = date("Y-m-d_H-i-s");
45
-                    $this->fechaCreacionLog = $fechaCarpeta;
46
-                    $rutaPerfil = $this->rutaDiaria . "/" . $row->prefijos_tablas;
37
+        foreach ($resultSetPerfiles['datos'] as $row) {
38
+        $fechaCarpeta = date("Y-m-d_H-i-s");
39
+        $this->fechaCreacionLog = $fechaCarpeta;
40
+        $rutaPerfil = $this->rutaDiaria . "/" . $row->prefijos_tablas;
47
 
41
 
48
-                    $this->newFolder($rutaPerfil);
42
+        $this->newFolder($rutaPerfil);
49
 
43
 
50
-                    if ($this->newFolder($rutaPerfil . "/" . $fechaCarpeta)) {
51
-                        $this->rutaDiariaFecha = $rutaPerfil . "/" . $fechaCarpeta . "/";
44
+        if ($this->newFolder($rutaPerfil . "/" . $fechaCarpeta)) {
45
+        $this->rutaDiariaFecha = $rutaPerfil . "/" . $fechaCarpeta . "/";
52
 
46
 
53
-                        $this->downloadProcess($row->url_descarga);
54
-                    }
55
-                }
47
+        $this->downloadProcess($row->url_descarga);
48
+        }
49
+        }
56
 
50
 
57
-                $this->parserfile->index($this->rutaDiariaFecha, $fechaCarpeta, $row);
51
+        $this->parserfile->index($this->rutaDiariaFecha, $fechaCarpeta, $row);
58
 
52
 
59
-            } else {
60
-                echo "EXISTE UN CRON EN MARCHA.";
61
-            }
62
         } else {
53
         } else {
63
-            echo "No existe parametro que iniciar.";
54
+        echo "EXISTE UN CRON EN MARCHA.";
55
+        }
56
+        } else {
57
+        echo "No existe parametro que iniciar.";
64
         }
58
         }
65
 
59
 
66
         $this->Parser_model->stopParser();
60
         $this->Parser_model->stopParser();
67
 
61
 
68
-        $this->tablasCalculadas($this->fechaCreacionLog);
62
+        $this->tablasCalculadas($this->fechaCreacionLog);*/
69
 
63
 
70
-        /*$resultSetPerfiles = $this->Parser_model->getUrlArchivos();
71
-    foreach ($resultSetPerfiles['datos'] as $row) {
72
-    $this->parserfile->index($this->rutaDiaria . "PER_PCSP_EX/2022-02-10_09-02-17", date("Y-m-n"), $row);
73
-    }*/
64
+        $resultSetPerfiles = $this->Parser_model->getUrlArchivos();
65
+        foreach ($resultSetPerfiles['datos'] as $row) {
66
+            $this->parserfile->index($this->rutaDiaria . "PER_PCSP_EX/2022-02-17_20-38-16", date("Y-m-d"), $row);
67
+        }
74
     }
68
     }
75
 
69
 
76
     private function downloadProcess($urlXML)
70
     private function downloadProcess($urlXML)
77
     {
71
     {
78
-        /*$fileName = basename($urlXML);
72
+        $fileName = basename($urlXML);
79
         $downladedZip = $this->downloadFile($fileName, $urlXML, $this->rutaDiariaFecha);
73
         $downladedZip = $this->downloadFile($fileName, $urlXML, $this->rutaDiariaFecha);
80
 
74
 
81
         if ($downladedZip) {
75
         if ($downladedZip) {
82
-        $zip = new ZipArchive;
83
-        if ($zip->open($this->rutaDiariaFecha . $fileName)) {
84
-        $zip->extractTo($this->rutaDiariaFecha);
85
-        $zip->close();
86
-        unlink($this->rutaDiariaFecha . $fileName);
87
-        $archivosTotales = get_filenames($this->rutaDiariaFecha);
88
-
89
-        foreach ($archivosTotales as $file) {
90
-        $this->getFile($this->rutaDiariaFecha . $file, $file);
91
-        }
76
+            $zip = new ZipArchive;
77
+            if ($zip->open($this->rutaDiariaFecha . $fileName)) {
78
+                $zip->extractTo($this->rutaDiariaFecha);
79
+                $zip->close();
80
+                unlink($this->rutaDiariaFecha . $fileName);
81
+                $archivosTotales = get_filenames($this->rutaDiariaFecha);
82
+
83
+                foreach ($archivosTotales as $file) {
84
+                    $this->getFile($this->rutaDiariaFecha . $file, $file);
85
+                }
92
 
86
 
93
-        }
87
+            }
94
 
88
 
95
-        }*/
96
-        $fileName = basename($urlXML);
97
-        $this->downloadFile($fileName, $urlXML, $this->rutaDiariaFecha);
98
-        $archivoAtom = $this->getFile($this->rutaDiariaFecha . $fileName, $fileName);
99
-        $nuevoAtomAttrNext = $this->readNextAttribute($archivoAtom);
89
+        }
90
+        /*$fileName = basename($urlXML);
91
+    $this->downloadFile($fileName, $urlXML, $this->rutaDiariaFecha);
92
+    $archivoAtom = $this->getFile($this->rutaDiariaFecha . $fileName, $fileName);
93
+    $nuevoAtomAttrNext = $this->readNextAttribute($archivoAtom);
100
 
94
 
101
-        while ($nuevoAtomAttrNext !== "") {
102
-            //$aux = 0;
103
-            //while ($aux <= 3) {
95
+    while ($nuevoAtomAttrNext !== "") {
96
+    //$aux = 0;
97
+    //while ($aux <= 3) {
104
 
98
 
105
-            $fileName = basename($nuevoAtomAttrNext);
106
-            $this->downloadFile($fileName, $nuevoAtomAttrNext, $this->rutaDiariaFecha);
107
-            $archivoAtom = $this->getFile($this->rutaDiariaFecha . $fileName, $fileName);
99
+    $fileName = basename($nuevoAtomAttrNext);
100
+    $this->downloadFile($fileName, $nuevoAtomAttrNext, $this->rutaDiariaFecha);
101
+    $archivoAtom = $this->getFile($this->rutaDiariaFecha . $fileName, $fileName);
108
 
102
 
109
-            $nuevoAtomAttrNext = $this->readNextAttribute($archivoAtom);
110
-            //$aux++;
111
-        }
103
+    $nuevoAtomAttrNext = $this->readNextAttribute($archivoAtom);
104
+    //$aux++;
105
+    }*/
112
     }
106
     }
113
 
107
 
114
     private function getFile($url, $fileName)
108
     private function getFile($url, $fileName)

+ 62 - 69
application/core/MY_DB_mysqli_driver.php View File

1
 <?php
1
 <?php
2
-class MY_DB_mysqli_driver extends CI_DB_mysqli_driver {
3
-
4
-   final public function __construct($params)
2
+class MY_DB_mysqli_driver extends CI_DB_mysqli_driver
5
 {
3
 {
6
-  parent::__construct($params);
7
-}
8
 
4
 
9
-  /**
10
-   * Insert_On_Duplicate_Update_Batch
11
-   *
12
-   * Compiles batch insert strings and runs the queries
13
-   * MODIFIED to do a MySQL 'ON DUPLICATE KEY UPDATE'
14
-   *
15
-   * @access public
16
-   * @param string the table to retrieve the results from
17
-   * @param array an associative array of insert values
18
-   * @return object
19
-   */
20
-  function insert_on_duplicate_update_batch($table = '', $set = NULL)
21
-  {
22
-    if ( ! is_null($set))
5
+    final public function __construct($params)
23
     {
6
     {
24
-     $this->set_insert_batch($set);
7
+        parent::__construct($params);
25
     }
8
     }
26
 
9
 
27
-    if (count($this->qb_set) == 0)
10
+    /**
11
+     * Insert_On_Duplicate_Update_Batch
12
+     *
13
+     * Compiles batch insert strings and runs the queries
14
+     * MODIFIED to do a MySQL 'ON DUPLICATE KEY UPDATE'
15
+     *
16
+     * @access public
17
+     * @param string the table to retrieve the results from
18
+     * @param array an associative array of insert values
19
+     * @return object
20
+     */
21
+    public function insert_on_duplicate_update_batch($table = '', $set = null)
28
     {
22
     {
29
-     if ($this->db_debug)
30
-     {
31
-      //No valid data array.  Folds in cases where keys and values did not match up
32
-      return $this->display_error('db_must_use_set');
33
-     }
34
-     return FALSE;
35
-    }
23
+        if (!is_null($set)) {
24
+            $this->set_insert_batch($set);
25
+        }
36
 
26
 
37
-    if ($table == '')
38
-    {
39
-     if ( ! isset($this->qb_from[0]))
40
-     {
41
-      if ($this->db_debug)
42
-      {
43
-       return $this->display_error('db_must_set_table');
44
-      }
45
-      return FALSE;
46
-     }
27
+        if (count($this->qb_set) == 0) {
28
+            if ($this->db_debug) {
29
+                //No valid data array.  Folds in cases where keys and values did not match up
30
+                return $this->display_error('db_must_use_set');
31
+            }
32
+            return false;
33
+        }
47
 
34
 
48
-     $table = $this->qb_from[0];
49
-    }
35
+        if ($table == '') {
36
+            if (!isset($this->qb_from[0])) {
37
+                if ($this->db_debug) {
38
+                    return $this->display_error('db_must_set_table');
39
+                }
40
+                return false;
41
+            }
50
 
42
 
51
-    // Batch this baby
52
-    for ($i = 0, $total = count($this->qb_set); $i < $total; $i = $i + 5000)
53
-    {
43
+            $table = $this->qb_from[0];
44
+        }
54
 
45
 
55
-     $sql = $this->_insert_on_duplicate_update_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), $this->qb_keys, array_slice($this->qb_set, $i, 5000));
46
+        // Batch this baby
47
+        for ($i = 0, $total = count($this->qb_set); $i < $total; $i = $i + 5000) {
56
 
48
 
57
-     // echo $sql;
49
+            $sql = $this->_insert_on_duplicate_update_batch($this->protect_identifiers($table, true, null, false), $this->qb_keys, array_slice($this->qb_set, $i, 5000));
58
 
50
 
59
-     $this->query($sql);
60
-    }
51
+            // echo $sql;
61
 
52
 
62
-    $this->_reset_write();
53
+            $this->query($sql);
54
+        }
63
 
55
 
56
+        $this->_reset_write();
64
 
57
 
65
-    return TRUE;
66
-  }
58
+        return true;
59
+    }
67
 
60
 
68
-  /**
69
-   * Insert_on_duplicate_update_batch statement
70
-   *
71
-   * Generates a platform-specific insert string from the supplied data
72
-   * MODIFIED to include ON DUPLICATE UPDATE
73
-   *
74
-   * @access public
75
-   * @param string the table name
76
-   * @param array the insert keys
77
-   * @param array the insert values
78
-   * @return string
79
-   */
80
-  private function _insert_on_duplicate_update_batch($table, $keys, $values)
81
-  {
82
-    foreach($keys as $key)
83
-     $update_fields[] = $key.'=VALUES('.$key.')';
61
+    /**
62
+     * Insert_on_duplicate_update_batch statement
63
+     *
64
+     * Generates a platform-specific insert string from the supplied data
65
+     * MODIFIED to include ON DUPLICATE UPDATE
66
+     *
67
+     * @access public
68
+     * @param string the table name
69
+     * @param array the insert keys
70
+     * @param array the insert values
71
+     * @return string
72
+     */
73
+    private function _insert_on_duplicate_update_batch($table, $keys, $values)
74
+    {
75
+        foreach ($keys as $key) {
76
+            $update_fields[] = $key . '=VALUES(' . $key . ')';
77
+        }
84
 
78
 
85
-    return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values)." ON DUPLICATE KEY UPDATE ".implode(', ', $update_fields);
86
-  }
79
+        return "INSERT INTO " . $table . " (" . implode(', ', $keys) . ") VALUES " . implode(', ', $values) . " ON DUPLICATE KEY UPDATE " . implode(', ', $update_fields);
80
+    }
87
 
81
 
88
 }
82
 }
89
-?>

+ 11 - 3
application/helpers/funciones_helper.php View File

73
         if (count($conjunto) > 0) {
73
         if (count($conjunto) > 0) {
74
             guardar_log($nombreLog, count($conjunto));
74
             guardar_log($nombreLog, count($conjunto));
75
             $CI->db->insert_batch($nombreTabla, $conjunto);
75
             $CI->db->insert_batch($nombreTabla, $conjunto);
76
+
76
         }
77
         }
77
 
78
 
79
+        unset($conjunto);
80
+        gc_collect_cycles();
81
+        /*$query = $this->db->query($sql);
82
+        $result = $query->result();
83
+        $query->free_result();*/
84
+
78
         return $CI->db->insert_id();
85
         return $CI->db->insert_id();
79
     }
86
     }
80
 }
87
 }
105
             if ($contador % 5000 == 0) {
112
             if ($contador % 5000 == 0) {
106
                 guardar_log($nombreLog, "Insertados - " . count($conjunto));
113
                 guardar_log($nombreLog, "Insertados - " . count($conjunto));
107
                 //$CI->db->insert_batch($nombreTabla, $conjunto);
114
                 //$CI->db->insert_batch($nombreTabla, $conjunto);
108
-                $CI->db->insert_on_duplicate_update_batch($nombreTabla, $conjunto);
115
+                $CI->db->insert_on_duplicate_update_batch($nombreTabla, $conjunto, $nombreLog);
109
 
116
 
110
                 $conjunto = array();
117
                 $conjunto = array();
111
             }
118
             }
114
         if (count($conjunto) > 0) {
121
         if (count($conjunto) > 0) {
115
             guardar_log($nombreLog, "Insertados - " . count($conjunto));
122
             guardar_log($nombreLog, "Insertados - " . count($conjunto));
116
             //$CI->db->insert_batch($nombreTabla, $conjunto);
123
             //$CI->db->insert_batch($nombreTabla, $conjunto);
117
-            $CI->db->insert_on_duplicate_update_batch($nombreTabla, $conjunto);
124
+            $CI->db->insert_on_duplicate_update_batch($nombreTabla, $conjunto, $nombreLog);
118
         }
125
         }
119
-
126
+        unset($conjunto);
127
+        gc_collect_cycles();
120
         return $CI->db->insert_id();
128
         return $CI->db->insert_id();
121
     }
129
     }
122
 }
130
 }

+ 7 - 13
application/libraries/ParserDatabaseBruto.php View File

36
 
36
 
37
                 $this->setTenderingTerms($datosArchivo);
37
                 $this->setTenderingTerms($datosArchivo);
38
 
38
 
39
-                /*$this->setDatosMultiples($datosArchivo['tenderingTerms'], 1, "bruto_tendering_terms", "TenderingTerms");
40
-
41
-                $this->setDatosMultiples($datosArchivo['tenderingTerms'], 2, "bruto_tendering_terms", "TenderingTerms");
42
-
43
-                $this->setDatosMultiples($datosArchivo['tenderingTerms'], 3, "bruto_tendering_terms", "TenderingTerms");
44
-
45
-                $this->setDatosMultiples($datosArchivo['tenderingTerms'], 4, "bruto_tendering_terms", "TenderingTerms");*/
46
-
47
                 $this->setLocatedContractingParty($datosArchivo); //, "locatedContractingParty", "BRUTO_located_contracting_party", "locatedContractingParty");
39
                 $this->setLocatedContractingParty($datosArchivo); //, "locatedContractingParty", "BRUTO_located_contracting_party", "locatedContractingParty");
48
 
40
 
49
                 $this->setParty($datosArchivo);
41
                 $this->setParty($datosArchivo);
63
                 $this->setInsertArryByArray($datosArchivo, "generalDocs", ["BRUTO_general_documents", "mapa_nivel_general_docs"], "GeneralDocs");
55
                 $this->setInsertArryByArray($datosArchivo, "generalDocs", ["BRUTO_general_documents", "mapa_nivel_general_docs"], "GeneralDocs");
64
 
56
 
65
                 $this->setInsertArryByArray($datosArchivo, "additionalDocs", ["BRUTO_additional_documents", "mapa_nivel_additional_docs"], "additionalDocs");
57
                 $this->setInsertArryByArray($datosArchivo, "additionalDocs", ["BRUTO_additional_documents", "mapa_nivel_additional_docs"], "additionalDocs");
58
+
66
             }
59
             }
67
-        }
68
 
60
 
69
-        return;
61
+            $arrayDatosSucios = array();
62
+        }
70
     }
63
     }
71
 
64
 
72
     private function setProcurementProjectArray($procurementProjectData)
65
     private function setProcurementProjectArray($procurementProjectData)
399
     private function setDatosMultiples($arrayDatos, $arrayKey, $tabla, $nodoLog): void
392
     private function setDatosMultiples($arrayDatos, $arrayKey, $tabla, $nodoLog): void
400
     {
393
     {
401
         $setInsert = array();
394
         $setInsert = array();
395
+
402
         $resultInsert = 0;
396
         $resultInsert = 0;
403
 
397
 
404
         if (array_key_exists($arrayKey, $arrayDatos)) {
398
         if (array_key_exists($arrayKey, $arrayDatos)) {
405
             if (!empty($arrayDatos[$arrayKey])) {
399
             if (!empty($arrayDatos[$arrayKey])) {
406
 
400
 
407
-                $resultInsert = insertBucleDuplicateOnKey($arrayDatos[$arrayKey], $tabla, $this->nombreLog);
401
+                $resultInsert = insertBucle($arrayDatos[$arrayKey], $tabla, $this->nombreLog);
408
 
402
 
409
                 if ($resultInsert) {
403
                 if ($resultInsert) {
410
-                    $result = array("result" => true);
404
+                    //$result = array("result" => true);
411
                     guardar_log($this->nombreLog, $nodoLog . " Finalizada Inserción", "false");
405
                     guardar_log($this->nombreLog, $nodoLog . " Finalizada Inserción", "false");
412
                 } else {
406
                 } else {
413
-                    $result = array("result" => true, "id" => 0);
407
+                    //$result = array("result" => true, "id" => 0);
414
                     guardar_log($this->nombreLog, $nodoLog . " Fallida", "false", 2);
408
                     guardar_log($this->nombreLog, $nodoLog . " Fallida", "false", 2);
415
                 }
409
                 }
416
             } else {
410
             } else {

+ 120 - 26
application/libraries/ParserFile.php View File

11
     protected $rutaDiaria = "";
11
     protected $rutaDiaria = "";
12
     protected $rutaMensual = FCPATH . "DOWNLOADS/MONTH/format";
12
     protected $rutaMensual = FCPATH . "DOWNLOADS/MONTH/format";
13
     protected $fechaInicioParser = "";
13
     protected $fechaInicioParser = "";
14
+    protected $arrayLicitacionExiste = array();
14
 
15
 
15
     //TODO: Añadir los nodos que falten mirando la libreria de java
16
     //TODO: Añadir los nodos que falten mirando la libreria de java
16
     //TODO Nuevo Nodo: Proveedor de pliegos->TenderingTerms->DocumentProviderParty
17
     //TODO Nuevo Nodo: Proveedor de pliegos->TenderingTerms->DocumentProviderParty
23
     {
24
     {
24
         $this->CI = &get_instance();
25
         $this->CI = &get_instance();
25
         $this->CI->load->helper('file');
26
         $this->CI->load->helper('file');
27
+        $this->CI->load->model("Parser_model");
26
         $this->CI->load->library('parserdatabasebruto');
28
         $this->CI->load->library('parserdatabasebruto');
27
         $this->CI->load->library('parserdatabaselimpio');
29
         $this->CI->load->library('parserdatabaselimpio');
28
     }
30
     }
32
         $this->rutaDiaria = $rutaDiariaDownloader . "/format/";
34
         $this->rutaDiaria = $rutaDiariaDownloader . "/format/";
33
         $this->fechaInicioParser = $fechaInicioParser;
35
         $this->fechaInicioParser = $fechaInicioParser;
34
         $files = get_filenames($this->rutaDiaria, true);
36
         $files = get_filenames($this->rutaDiaria, true);
37
+        $filename = "";
38
+        $xml = "";
39
+        $json = "";
40
+        $array = "";
41
+        $aux = 0;
42
+        $this->arrayLicitacionExiste = array();
43
+        $resultEntries = array();
35
 
44
 
36
         guardar_log("setLicitacion__" . $datosPerfil->prefijos_tablas . "__" . $fechaInicioParser, "----------------------------------", false);
45
         guardar_log("setLicitacion__" . $datosPerfil->prefijos_tablas . "__" . $fechaInicioParser, "----------------------------------", false);
37
 
46
 
38
-        foreach ($files as $file) {
39
-            $resultEntries = array();
40
-            $entrada = file_get_contents($file);
41
-            $xml = simplexml_load_string($entrada, "SimpleXMLElement", LIBXML_NOCDATA);
42
-            $json = json_encode($xml);
43
-            $array = json_decode($json, true);
47
+        guardar_log("setLicitacion__" . $datosPerfil->prefijos_tablas . "__" . $fechaInicioParser, "MEMORIA Inicio archivos: " . $this->echo_memory_usage(), false);
44
 
48
 
49
+        foreach ($files as $file) {
45
             $filename = basename($file);
50
             $filename = basename($file);
51
+            guardar_log("setLicitacion__" . $datosPerfil->prefijos_tablas . "__" . $fechaInicioParser, "MEMORIA leyendo archivo - " . $filename . "-" . $this->echo_memory_usage(), false);
52
+            $xml = simplexml_load_file($file, "SimpleXMLElement", LIBXML_NOCDATA);
53
+            guardar_log("setLicitacion__" . $datosPerfil->prefijos_tablas . "__" . $fechaInicioParser, "MEMORIA xml- " . $filename . "-" . $this->echo_memory_usage(), false);
54
+            //$json = ;
55
+            guardar_log("setLicitacion__" . $datosPerfil->prefijos_tablas . "__" . $fechaInicioParser, "MEMORIA json_encode- " . $filename . "-" . $this->echo_memory_usage(), false);
56
+            $array = json_decode(json_encode($xml), true);
57
+            guardar_log("setLicitacion__" . $datosPerfil->prefijos_tablas . "__" . $fechaInicioParser, "MEMORIA json_decode- " . $filename . "-" . $this->echo_memory_usage(), false);
58
+            //$array = (array) $xml;
59
+            //var_dump($array);
46
             $aux = 0;
60
             $aux = 0;
61
+
62
+            $tablasTruncate = $this->CI->Parser_model->getMapaTablas();
63
+            foreach ($tablasTruncate['datos'] as $row) {
64
+                $this->CI->Parser_model->truncateTables($row->tabla_sucia);
65
+            }
66
+
67
+            gc_mem_caches();
68
+            gc_collect_cycles();
69
+
47
             foreach ($array['entry'] as $clave => $row) {
70
             foreach ($array['entry'] as $clave => $row) {
48
 
71
 
49
-                $arrayDeletedEntries = $xml->children('at', true);
72
+                $existLicitacionActualizada = $this->getDatosLicitacion($row);
73
+
74
+                if (!$existLicitacionActualizada) {
75
+                    //$arrayDeletedEntries = $xml->children('at', true);
50
 
76
 
51
-                $resultEntries[$filename]['general'][$aux] = $this->nodoEntry($row, $xml->entry[$clave], $datosPerfil->id);
77
+                    $resultEntries[$filename]['general'][$aux] = $this->nodoEntry($row, $xml->entry[$clave], $datosPerfil->id);
52
 
78
 
53
-                $resultEntries[$filename]['contractInfo'][$aux] = $this->nodoContractFolderStatus($row, $xml->entry[$clave]);
79
+                    $resultEntries[$filename]['contractInfo'][$aux] = $this->nodoContractFolderStatus($row, $xml->entry[$clave]);
54
 
80
 
55
-                $resultEntries[$filename]['locatedContractingParty'][$aux] = $this->nodoLocatedContractingParty($row, $xml->entry[$clave]);
81
+                    $resultEntries[$filename]['locatedContractingParty'][$aux] = $this->nodoLocatedContractingParty($row, $xml->entry[$clave]);
56
 
82
 
57
-                $resultEntries[$filename]['party'][$aux] = $this->nodoParty($row, $xml->entry[$clave]);
83
+                    $resultEntries[$filename]['party'][$aux] = $this->nodoParty($row, $xml->entry[$clave]);
58
 
84
 
59
-                $resultEntries[$filename]['procurementProject'][$aux] = $this->nodoPresupuesto($row, $xml->entry[$clave]);
85
+                    $resultEntries[$filename]['procurementProject'][$aux] = $this->nodoPresupuesto($row, $xml->entry[$clave]);
60
 
86
 
61
-                $resultEntries[$filename]['procurementProjectLot'][$aux] = $this->nodoProcurementProjectLot($row, $xml->entry[$clave]);
87
+                    $resultEntries[$filename]['procurementProjectLot'][$aux] = $this->nodoProcurementProjectLot($row, $xml->entry[$clave]);
62
 
88
 
63
-                $resultEntries[$filename]['tenderingTerms'][$aux] = $this->nodoTenderingTerms($row, $xml->entry[$clave]);
89
+                    $resultEntries[$filename]['tenderingTerms'][$aux] = $this->nodoTenderingTerms($row, $xml->entry[$clave]);
64
 
90
 
65
-                $resultEntries[$filename]['tenderingProcess'][$aux] = $this->nodoTenderingProcess($row, $xml->entry[$clave]);
91
+                    $resultEntries[$filename]['tenderingProcess'][$aux] = $this->nodoTenderingProcess($row, $xml->entry[$clave]);
66
 
92
 
67
-                $resultEntries[$filename]['tenderingResult'][$aux] = $this->nodoTenderResult($row, $xml->entry[$clave]);
93
+                    $resultEntries[$filename]['tenderingResult'][$aux] = $this->nodoTenderResult($row, $xml->entry[$clave]);
68
 
94
 
69
-                //$resultEntries[$filename]['validNoticeInfo'][$aux] = $this->nodoValidNoticeInfo($row);
95
+                    //$resultEntries[$filename]['validNoticeInfo'][$aux] = $this->nodoValidNoticeInfo($row);
70
 
96
 
71
-                $resultEntries[$filename]['legalDocs'][$aux] = $this->nodoLegalDoc($row, $xml->entry[$clave]);
97
+                    $resultEntries[$filename]['legalDocs'][$aux] = $this->nodoLegalDoc($row, $xml->entry[$clave]);
72
 
98
 
73
-                $resultEntries[$filename]['technicalDocs'][$aux] = $this->nodoTechnicalDocumentReference($row, $xml->entry[$clave]);
99
+                    $resultEntries[$filename]['technicalDocs'][$aux] = $this->nodoTechnicalDocumentReference($row, $xml->entry[$clave]);
74
 
100
 
75
-                $resultEntries[$filename]['generalDocs'][$aux] = $this->nodoGeneralDocuments($row, $xml->entry[$clave]);
101
+                    $resultEntries[$filename]['generalDocs'][$aux] = $this->nodoGeneralDocuments($row, $xml->entry[$clave]);
76
 
102
 
77
-                $resultEntries[$filename]['additionalDocs'][$aux] = $this->nodoAdditionalDocumentReference($row, $xml->entry[$clave]);
103
+                    $resultEntries[$filename]['additionalDocs'][$aux] = $this->nodoAdditionalDocumentReference($row, $xml->entry[$clave]);
78
 
104
 
79
-                $aux++;
105
+                    $aux++;
106
+                }
80
 
107
 
81
                 //$this->recurseXML($array['entry'], true);
108
                 //$this->recurseXML($array['entry'], true);
82
             }
109
             }
83
-
110
+            //guardar_log("setLicitacion__" . $datosPerfil->prefijos_tablas . "__" . $fechaInicioParser, count($resultEntries));
111
+            //guardar_log("setLicitacion__" . $datosPerfil->prefijos_tablas . "__" . $fechaInicioParser, count($resultEntries[$filename]));
112
+            //guardar_log("setLicitacion__" . $datosPerfil->prefijos_tablas . "__" . $fechaInicioParser, "MEMORIA insertando tabla bruta - " . $filename . "-" . $this->echo_memory_usage(), false);
84
             $this->CI->parserdatabasebruto->setDatosParser($resultEntries, $fechaInicioParser, $datosPerfil);
113
             $this->CI->parserdatabasebruto->setDatosParser($resultEntries, $fechaInicioParser, $datosPerfil);
114
+            unset($resultEntries[$filename]);
115
+            unset($resultEntries);
116
+            unset($this->arrayLicitacionExiste);
117
+            unset($xml);
118
+            //unset($json);
119
+            unset($array);
120
+
121
+            unset($tablasTruncate);
122
+            guardar_log("setLicitacion__" . $datosPerfil->prefijos_tablas . "__" . $fechaInicioParser, "MEMORIA borrando arrays - " . $filename . "-" . $this->echo_memory_usage(), false);
123
+            $this->CI->parserdatabaselimpio->index($fechaInicioParser, $filename);
124
+            guardar_log("setLicitacion__" . $datosPerfil->prefijos_tablas . "__" . $fechaInicioParser, "MEMORIA insertando maestros - " . $filename . "-" . $this->echo_memory_usage(), false);
125
+            guardar_log("setLicitacion__" . $datosPerfil->prefijos_tablas . "__" . $fechaInicioParser, "--------------------------------" . $this->echo_memory_usage(), false);
126
+            gc_mem_caches();
127
+            gc_collect_cycles();
128
+
129
+        }
130
+
131
+    }
132
+
133
+    public function echo_memory_usage()
134
+    {
135
+        $mem_usage = memory_get_usage(true);
85
 
136
 
86
-            $resultEntries = array();
87
-            $this->CI->parserdatabaselimpio->index($fechaInicioParser);
137
+        $result = "";
138
+        if ($mem_usage < 1024) {
139
+            $result = $mem_usage . " bytes";
140
+        } elseif ($mem_usage < 1048576) {
141
+            $result = round($mem_usage / 1024, 2) . " kilobytes";
142
+        } else {
143
+            $result = round($mem_usage / 1048576, 2) . " megabytes";
144
+        }
145
+
146
+        return $result;
147
+    }
148
+
149
+    private function getDatosLicitacion($xml): Bool
150
+    {
151
+        $idLicitacion = (string) substr($xml['id'], strrpos($xml['id'], '/') + 1);
152
+        $fechaUpdated = (string) $xml['updated'];
153
+        //$this->idLicitacion = $idLicitacion;
154
+        $this->fechaUpdateLicitacion = $fechaUpdated;
155
+        $result = false;
156
+
157
+        if ($idLicitacion == "9282002") {
158
+            $var = 1;
159
+        }
160
+
161
+        if (!array_key_exists($idLicitacion, $this->arrayLicitacionExiste)) {
162
+            $this->arrayLicitacionExiste[$idLicitacion] = $fechaUpdated;
163
+        } else {
164
+            $result = $this->existUpdatedLicitacion($idLicitacion, $fechaUpdated);
165
+        }
166
+
167
+        return $result;
168
+    }
88
 
169
 
170
+    private function existUpdatedLicitacion($idLicitacion, $fechaUpdated): Bool
171
+    {
172
+        $result = false;
173
+        if (array_key_exists($idLicitacion, $this->arrayLicitacionExiste)) {
174
+            $fechaExistente = $this->arrayLicitacionExiste[$idLicitacion];
175
+
176
+            if ($fechaExistente >= $fechaUpdated) {
177
+                $result = true;
178
+
179
+            } else {
180
+                $this->arrayLicitacionExiste[$idLicitacion] = $fechaUpdated;
181
+                $result = false;
182
+            }
89
         }
183
         }
90
 
184
 
91
-        return;
185
+        return $result;
92
     }
186
     }
93
 
187
 
94
     private function nodoEntry($xml, $xmlPrimitivo, $tipoPerfil)
188
     private function nodoEntry($xml, $xmlPrimitivo, $tipoPerfil)

+ 11 - 17
application/libraries/Parserdatabaselimpio.php View File

13
         $this->CI->load->model("Xlsexport_model");
13
         $this->CI->load->model("Xlsexport_model");
14
     }
14
     }
15
 
15
 
16
-    public function index($fechaInicioParser)
16
+    public function index($fechaInicioParser, $filename)
17
     {
17
     {
18
         $tablasInsert = $this->CI->Parser_model->getMapaTablas();
18
         $tablasInsert = $this->CI->Parser_model->getMapaTablas();
19
 
19
 
20
         if ($tablasInsert['num_rows'] > 0) {
20
         if ($tablasInsert['num_rows'] > 0) {
21
 
21
 
22
-            $licitacionDeleteCascada = $this->CI->Parser_model->getLicitacionesNuevasBruto();
22
+            //$licitacionDeleteCascada = $this->CI->Parser_model->getLicitacionesNuevasBruto();
23
 
23
 
24
-            if ($licitacionDeleteCascada['num_rows'] > 0) {
25
-                $this->CI->Parser_model->deleteCascadaNuevasLicitaciones();
24
+            //if ($licitacionDeleteCascada['num_rows'] > 0) {
25
+            $this->CI->Parser_model->deleteCascadaNuevasLicitaciones();
26
 
26
 
27
-                foreach ($tablasInsert['datos'] as $row) {
27
+            foreach ($tablasInsert['datos'] as $row) {
28
 
28
 
29
-                    $datosTablaToInsert = $this->CI->Parser_model->getDatosBrutos($row->tabla_sucia);
29
+                $datosTablaToInsert = $this->CI->Parser_model->getDatosBrutos($row->tabla_sucia);
30
 
30
 
31
-                    if ($datosTablaToInsert['num_rows'] > 0) {
32
-                        if ($row->tabla_maestra == "maestro_datos_iniciales_licitacion") {
33
-                            foreach ($datosTablaToInsert['datos'] as $datos) {
34
-                                unset($datos->id);
35
-                            }
36
-                        }
31
+                if ($datosTablaToInsert['num_rows'] > 0) {
32
+                    guardar_log("brutoToMaestro_" . $fechaInicioParser, "ARCHIVO--" . $row->tabla_maestra . "_" . $fechaInicioParser . " - " . $filename);
33
+                    insertBucle($datosTablaToInsert['datos'], $row->tabla_maestra, "brutoToMaestro_" . $fechaInicioParser);
37
 
34
 
38
-                        insertBucleDuplicateOnKey($datosTablaToInsert['datos'], $row->tabla_maestra, "brutoToMaestro_" . $fechaInicioParser);
39
-                    }
40
                 }
35
                 }
41
-
42
             }
36
             }
43
 
37
 
44
-        }
38
+            //}
45
 
39
 
46
-        return;
40
+        }
47
     }
41
     }
48
 
42
 
49
 }
43
 }

+ 7 - 0
application/models/Parser_model.php View File

55
         $result = $this->db->query($sql);
55
         $result = $this->db->query($sql);
56
         $datos['datos'] = $result->row();
56
         $datos['datos'] = $result->row();
57
         $datos['num_rows'] = $result->num_rows();
57
         $datos['num_rows'] = $result->num_rows();
58
+        $result->free_result();
58
         return $datos;
59
         return $datos;
59
     }
60
     }
60
 
61
 
64
         $result = $this->db->query($sql);
65
         $result = $this->db->query($sql);
65
         $datos['datos'] = $result->result();
66
         $datos['datos'] = $result->result();
66
         $datos['num_rows'] = $result->num_rows();
67
         $datos['num_rows'] = $result->num_rows();
68
+        $result->free_result();
67
         return $datos;
69
         return $datos;
68
     }
70
     }
69
 
71
 
79
         $result = $this->db->query($sql);
81
         $result = $this->db->query($sql);
80
         $datos['datos'] = $result->result();
82
         $datos['datos'] = $result->result();
81
         $datos['num_rows'] = $result->num_rows();
83
         $datos['num_rows'] = $result->num_rows();
84
+        $result->free_result();
82
         return $datos;
85
         return $datos;
83
     }
86
     }
84
 
87
 
93
         $result = $this->db->query($sql);
96
         $result = $this->db->query($sql);
94
         $datos['datos'] = $result->result();
97
         $datos['datos'] = $result->result();
95
         $datos['num_rows'] = $result->num_rows();
98
         $datos['num_rows'] = $result->num_rows();
99
+        $result->free_result();
96
         return $datos;
100
         return $datos;
97
     }
101
     }
98
 
102
 
100
     {
104
     {
101
         $sql = "SELECT DISTINCT id_licitacion FROM bruto_datos_iniciales";
105
         $sql = "SELECT DISTINCT id_licitacion FROM bruto_datos_iniciales";
102
         $result = $this->db->query($sql);
106
         $result = $this->db->query($sql);
107
+        $datos['datos'] = $result->result();
103
         $datos['num_rows'] = $result->num_rows();
108
         $datos['num_rows'] = $result->num_rows();
109
+        $result->free_result();
104
         return $datos;
110
         return $datos;
105
     }
111
     }
106
 
112
 
122
         $result = $this->db->query($sql);
128
         $result = $this->db->query($sql);
123
         $datos['datos'] = $result->result();
129
         $datos['datos'] = $result->result();
124
         $datos['num_rows'] = $result->num_rows();
130
         $datos['num_rows'] = $result->num_rows();
131
+        $result->free_result();
125
         return $datos;
132
         return $datos;
126
 
133
 
127
     }
134
     }

+ 2 - 1
composer.json View File

12
 	},
12
 	},
13
 	"require": {
13
 	"require": {
14
 		"php": ">=5.3.7",
14
 		"php": ">=5.3.7",
15
-		"phpoffice/phpspreadsheet": "^1.21"
15
+		"phpoffice/phpspreadsheet": "^1.21",
16
+		"halaxa/json-machine": "^1.0"
16
 	},
17
 	},
17
 	"suggest": {
18
 	"suggest": {
18
 		"paragonie/random_compat": "Provides better randomness in PHP 5.x"
19
 		"paragonie/random_compat": "Provides better randomness in PHP 5.x"