file = $file; $this->do = $do; $this->prefix = $prefix ?: ''; $this->delete_file = $delete_file; $this->delete_recs = $delete_recs; } /** * Execute the job. * * @return void * @throws \Exception */ public function handle() { // Get the file from the host $file = $this->getFileFromHost('',self::importkey,$this->file); Log::debug(sprintf('%s:Loading file [%s] (%s).',static::LOGKEY,$file,getcwd())); $lines = $this->getFileLines($file); Log::debug(sprintf('%s:Processing [%d] lines.',static::LOGKEY,$lines)); $fh = fopen($file,'r'); $p = $c = 0; while (! feof($fh)) { $line = stream_get_line($fh, 0, "\n"); // Remove any embedded CR and BOM $line = str_replace("\r",'',$line); $line = preg_replace('/^\x{feff}/u','',$line); if (! $line) continue; $c++; list($area,$description) = preg_split('/[\s|\t]+/',$line,2); if ($this->do->echoareas->pluck('name')->search($area) !== FALSE) { Log::info(sprintf('%s: Area [%s] already exists.',self::LOGKEY,$area)); continue; } $o = new Echoarea; $o->name = $area; $o->description = ($this->prefix ?: '').$description; $o->active = TRUE; $o->public = TRUE; $this->do->echoareas()->save($o); } fclose($fh); if ($this->delete_file and $c) unlink($file); Log::info(sprintf('%s:Updated %d records',self::LOGKEY,$p)); } }