Esempio n. 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //register log in DB
     $dateBegin = new \DateTime();
     $activity = Activity::concept(ConstDb::LOAD_CRL)->first();
     if ($activity) {
         $activity->date_begin = $dateBegin->format('Y-m-d H:i:s');
         $activity->save();
     } else {
         Activity::create(['concept' => ConstDb::LOAD_CRL, 'date_begin' => $dateBegin->format('Y-m-d H:i:s')]);
     }
     //end log
     $this->info('Begin: ' . date('H:i:s'));
     $result = DB::connection('mysql_crl')->select($this->getQuery(true));
     $rows = $result[0]->total;
     $this->info("Total de filas: {$rows}");
     $begin = 0;
     $block = 10000;
     $countBlock = 1;
     $fCsv = storage_path('app/crl.csv');
     if (file_exists($fCsv)) {
         unlink($fCsv);
     }
     $fp = fopen($fCsv, 'w');
     fputs($fp, "organization, from, year, quarter, month, total \n");
     while ($rows > $begin) {
         $result = DB::connection('mysql_crl')->select($this->getQuery(false, $begin, $block));
         foreach ($result as $key => $value) {
             $array = json_decode(json_encode($value), true);
             $replace = ["\n", ',', '  '];
             $replaceTo = ["", ';', ' '];
             foreach ($array as $key => $value) {
                 $array[$key] = str_replace($replace, $replaceTo, $value);
             }
             fputs($fp, implode($array, ',') . "\n");
         }
         $this->info("End block {$countBlock}: " . date('H:i:s'));
         $begin += $block;
         $countBlock++;
     }
     fclose($fp);
     $this->info('End export CSV: ' . date('H:i:s'));
     Schema::drop('crl');
     $db = env('MONGO_DATABASE');
     $command = "mongoimport -d {$db} -c crl --type csv --file {$fCsv} --headerline";
     shell_exec($command);
     //register log in DB
     $dateEnd = new \DateTime();
     $activity = Activity::concept(ConstDb::LOAD_CRL)->first();
     if ($activity) {
         $activity->date_end = $dateEnd->format('Y-m-d H:i:s');
         $activity->save();
     } else {
         Activity::create(['concept' => ConstDb::LOAD_CRL, 'date_end' => $dateEnd->format('Y-m-d H:i:s')]);
     }
     //end log
     $this->info('End: ' . $dateEnd->format('H:i:s'));
 }
Esempio n. 2
0
 public function saveLog($begin, $concept)
 {
     $date = new \DateTime();
     $activity = Activity::concept($concept)->first();
     if ($activity) {
         if ($begin) {
             $activity->date_begin = $date->format('Y-m-d H:i:s');
         } else {
             $activity->date_end = $date->format('Y-m-d H:i:s');
         }
         $activity->save();
     } else {
         if ($begin) {
             Activity::create(['concept' => $concept, 'date_begin' => $date->format('Y-m-d H:i:s')]);
         } else {
             Activity::create(['concept' => $concept, 'date_end' => $date->format('Y-m-d H:i:s')]);
         }
     }
 }
Esempio n. 3
0
 public function getLastUpdate($concept)
 {
     switch ($concept) {
         case 1:
             $concept = ConstDb::LOAD_CERT;
             break;
         case 2:
             $concept = ConstDb::LOAD_CERT_VIG;
             break;
         case 3:
             $concept = ConstDb::LOAD_CRL;
             break;
         case 4:
             $concept = ConstDb::LOAD_CERT_OPER;
             break;
         default:
             $concept = ConstDb::LOAD_CERT;
             break;
     }
     $oActivity = Activity::concept($concept)->first(['date_begin']);
     $time = strtotime($oActivity->date_begin);
     $date = date('d/m/Y H:i', $time);
     return response()->json($date);
 }