|
@@ -11,6 +11,7 @@ class ParserFile
|
11
|
11
|
protected $rutaDiaria = "";
|
12
|
12
|
protected $rutaMensual = FCPATH . "DOWNLOADS/MONTH/format";
|
13
|
13
|
protected $fechaInicioParser = "";
|
|
14
|
+ protected $arrayLicitacionExiste = array();
|
14
|
15
|
|
15
|
16
|
//TODO: Añadir los nodos que falten mirando la libreria de java
|
16
|
17
|
//TODO Nuevo Nodo: Proveedor de pliegos->TenderingTerms->DocumentProviderParty
|
|
@@ -23,6 +24,7 @@ class ParserFile
|
23
|
24
|
{
|
24
|
25
|
$this->CI = &get_instance();
|
25
|
26
|
$this->CI->load->helper('file');
|
|
27
|
+ $this->CI->load->model("Parser_model");
|
26
|
28
|
$this->CI->load->library('parserdatabasebruto');
|
27
|
29
|
$this->CI->load->library('parserdatabaselimpio');
|
28
|
30
|
}
|
|
@@ -32,63 +34,155 @@ class ParserFile
|
32
|
34
|
$this->rutaDiaria = $rutaDiariaDownloader . "/format/";
|
33
|
35
|
$this->fechaInicioParser = $fechaInicioParser;
|
34
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
188
|
private function nodoEntry($xml, $xmlPrimitivo, $tipoPerfil)
|