From c59f8ee0ed2fd31310d3d61730f8d168ef4a42ed Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 3 Aug 2023 22:11:59 +1000 Subject: [PATCH] Improvements to Echoarea Import, area names are now uppercase and descriptions use ucfirst() --- app/Jobs/EchoareaImport.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/app/Jobs/EchoareaImport.php b/app/Jobs/EchoareaImport.php index 38a240a..31bf77d 100644 --- a/app/Jobs/EchoareaImport.php +++ b/app/Jobs/EchoareaImport.php @@ -52,13 +52,7 @@ class EchoareaImport implements ShouldQueue */ 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'); + $fh = fopen($this->file,'r'); $p = $c = 0; while (! feof($fh)) { @@ -73,16 +67,16 @@ class EchoareaImport implements ShouldQueue $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; + if (str_contains($line,' ')) + list($area,$description) = preg_split('/[\s|\t]+/',$line,2); + else { + $area = $line; + $description = '[No Description]'; } - $o = new Echoarea; - $o->name = $area; - $o->description = ($this->prefix ?: '').$description; + $o = Echoarea::whereRaw(sprintf("LOWER(name)='%s'",strtolower($area)))->firstOrNew(); + $o->name = strtoupper($area); + $o->description = ($this->prefix.' ' ?: '').ucfirst($description); $o->active = TRUE; $o->show = TRUE;