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
 
24
 
25
     public function index()
25
     public function index()
26
     {
26
     {
27
+
27
         $fechaCarpeta = "";
28
         $fechaCarpeta = "";
28
 
29
 
29
         $this->Parser_model->inicioParser();
30
         $this->Parser_model->inicioParser();
38
             $this->Xlsexport_model->getLastDateLog($idUltimaImportacion);
39
             $this->Xlsexport_model->getLastDateLog($idUltimaImportacion);
39
             $this->fechaCreacionLog = $fechaCarpeta;
40
             $this->fechaCreacionLog = $fechaCarpeta;
40
             $rutaPerfil = $this->rutaDiaria . "/" . $row->prefijos_tablas;
41
             $rutaPerfil = $this->rutaDiaria . "/" . $row->prefijos_tablas;
42
+            $this->removeFoldersFromThursdayToMonday($rutaPerfil);
41
 
43
 
42
             $this->newFolder($rutaPerfil);
44
             $this->newFolder($rutaPerfil);
43
 
45
 
44
             if ($this->newFolder($rutaPerfil . "/" . $fechaCarpeta)) {
46
             if ($this->newFolder($rutaPerfil . "/" . $fechaCarpeta)) {
45
                 $this->rutaDiariaFecha = $rutaPerfil . "/" . $fechaCarpeta . "/";
47
                 $this->rutaDiariaFecha = $rutaPerfil . "/" . $fechaCarpeta . "/";
48
+
46
                 $this->downloadZip($row->url_descarga);
49
                 $this->downloadZip($row->url_descarga);
47
             }
50
             }
48
 
51
 
49
             $files = get_filenames($this->rutaDiariaFecha . "/format");
52
             $files = get_filenames($this->rutaDiariaFecha . "/format");
50
             emailInicioProcesoDescarga($fechaImportacionLog, $files);
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
         $this->tablasCalculadas($idUltimaImportacion);
58
         $this->tablasCalculadas($idUltimaImportacion);
131
     {
134
     {
132
         $openingFormat = $this->regExIniciosEsquema($xml);
135
         $openingFormat = $this->regExIniciosEsquema($xml);
133
         $closureFormat = $this->regExFinalesEsquema($openingFormat);
136
         $closureFormat = $this->regExFinalesEsquema($openingFormat);
137
+        unlink($this->rutaDiariaFecha . "/" . $fileName);
134
         file_put_contents($this->rutaDiariaFecha . "/format/" . $fileName, $closureFormat);
138
         file_put_contents($this->rutaDiariaFecha . "/format/" . $fileName, $closureFormat);
135
     }
139
     }
136
 
140
 
167
 
171
 
168
         insertBucleDuplicateOnKey($licitaciones['datos'], "vista_datos_licitacion", "");
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
 }