Selaa lähdekoodia

remove files between actual friday and last friday

Nermosis 3 vuotta sitten
vanhempi
commit
5021131a56
1 muutettua tiedostoa jossa 38 lisäystä ja 1 poistoa
  1. 38 1
      application/controllers/Parser.php

+ 38 - 1
application/controllers/Parser.php Näytä tiedosto

@@ -24,6 +24,7 @@ class Parser extends CI_Controller
24 24
 
25 25
     public function index()
26 26
     {
27
+
27 28
         $fechaCarpeta = "";
28 29
 
29 30
         $this->Parser_model->inicioParser();
@@ -38,18 +39,20 @@ class Parser extends CI_Controller
38 39
             $this->Xlsexport_model->getLastDateLog($idUltimaImportacion);
39 40
             $this->fechaCreacionLog = $fechaCarpeta;
40 41
             $rutaPerfil = $this->rutaDiaria . "/" . $row->prefijos_tablas;
42
+            $this->removeFoldersFromThursdayToMonday($rutaPerfil);
41 43
 
42 44
             $this->newFolder($rutaPerfil);
43 45
 
44 46
             if ($this->newFolder($rutaPerfil . "/" . $fechaCarpeta)) {
45 47
                 $this->rutaDiariaFecha = $rutaPerfil . "/" . $fechaCarpeta . "/";
48
+
46 49
                 $this->downloadZip($row->url_descarga);
47 50
             }
48 51
 
49 52
             $files = get_filenames($this->rutaDiariaFecha . "/format");
50 53
             emailInicioProcesoDescarga($fechaImportacionLog, $files);
51 54
 
52
-            $this->Parserfile->index($this->rutaDiariaFecha, $fechaCarpeta, $row, $idUltimaImportacion);
55
+            $this->parserfile->index($this->rutaDiariaFecha, $fechaCarpeta, $row, $idUltimaImportacion);
53 56
         }
54 57
 
55 58
         $this->tablasCalculadas($idUltimaImportacion);
@@ -131,6 +134,7 @@ class Parser extends CI_Controller
131 134
     {
132 135
         $openingFormat = $this->regExIniciosEsquema($xml);
133 136
         $closureFormat = $this->regExFinalesEsquema($openingFormat);
137
+        unlink($this->rutaDiariaFecha . "/" . $fileName);
134 138
         file_put_contents($this->rutaDiariaFecha . "/format/" . $fileName, $closureFormat);
135 139
     }
136 140
 
@@ -167,4 +171,37 @@ class Parser extends CI_Controller
167 171
 
168 172
         insertBucleDuplicateOnKey($licitaciones['datos'], "vista_datos_licitacion", "");
169 173
     }
174
+
175
+    private function removeFoldersFromThursdayToMonday($ruta)
176
+    {
177
+        $dayWeek = date('l');
178
+
179
+        if ($dayWeek == "Tuesday") {
180
+            $folders = glob($ruta . "/*");
181
+            $actualDay = date("Y-m-d");
182
+
183
+            $minusSixDays =  date('Y-m-d', strtotime($actualDay . ' -6 days'));
184
+
185
+            foreach ($folders as $folder) {
186
+
187
+                $folderDate = substr($folder, -19, 10);
188
+                if ($folderDate <= $actualDay && $folderDate >= $minusSixDays) {
189
+                    $this->eliminarArchivosProcesoCompleto($folder);
190
+                }
191
+            }
192
+        }
193
+    }
194
+
195
+    private function eliminarArchivosProcesoCompleto($ruta)
196
+    {
197
+        $files = glob($ruta . "/format/*");
198
+        foreach ($files as $file) { // iterate files
199
+            if (is_file($file)) {
200
+                unlink($file); // delete file
201
+            }
202
+        }
203
+
204
+        rmdir($ruta . "/format");
205
+        rmdir($ruta);
206
+    }
170 207
 }