diff --git a/src/Command/HiltesImportCommand.php b/src/Command/HiltesImportCommand.php index ebf560f..fb9e6cd 100644 --- a/src/Command/HiltesImportCommand.php +++ b/src/Command/HiltesImportCommand.php @@ -2,7 +2,7 @@ namespace App\Command; -use App\Helper\Hiltes; +use App\Helper\HiltesImport; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -35,10 +35,12 @@ class HiltesImportCommand extends Command if ($arg1) { $io->note(sprintf('You passed an argument: %s', $arg1)); } + /** + * @var HiltesImport + */ + $hiltesImport = new HiltesImport(); - $hiltes = new Hiltes(); - - $hiltes->import(); + $hiltesImport->startImport(); $io->success('You have a new command! Now make it your own! Pass --help to see your options.'); diff --git a/src/Entity/HlsCountry.php b/src/Entity/HlsCountry.php new file mode 100644 index 0000000..c09662f --- /dev/null +++ b/src/Entity/HlsCountry.php @@ -0,0 +1,65 @@ +id; + } + + public function getShortName(): ?string + { + return $this->short_name; + } + + public function setShortName(string $short_name): self + { + $this->short_name = $short_name; + + return $this; + } + + public function getShortIso(): ?string + { + return $this->short_iso; + } + + public function setShortIso(string $short_iso): self + { + $this->short_iso = $short_iso; + + return $this; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): self + { + $this->name = $name; + + return $this; + } +} diff --git a/src/Helper/HiltesImport.php b/src/Helper/HiltesImport.php new file mode 100644 index 0000000..b1281c2 --- /dev/null +++ b/src/Helper/HiltesImport.php @@ -0,0 +1,176 @@ +currentDirPath = getcwd(); + } + + + + public function startImport() + { + #*** Holt alle Dateien + if($this->getFiles()){ + if(!empty($this->arrData['orgFiles']['data']) && count($this->arrData['orgFiles']['data'])){ + foreach ($this->arrData['orgFiles']['data'] as $file) { + if(is_file($file['realPath'])){ + $this->loadFiles($file['realPath'],$file['fileSize']); + }else{ + return array('error'=>1,'text'=>'Error is_file('.$file['realPath'].')'); + } + } + }else + return array('success'=>1,'text'=>'No Files'); + }else + return array('error'=>1,'text'=>'Error in getFiles'); + } + protected function getFiles() + { + $return = true; + $finder = Finder::create(); + $finder + ->in($this->currentDirPath.'/hiltes/h2c/') + ->depth(0); + #->filter(static function (SplFileInfo $file) { + # return $file->isDir() || \preg_match('/\.(php|json)$/', $file->getPathname()); + #}); + if ($finder->hasResults()) { + foreach ($finder as $file) { + $this->arrData['orgFiles']['data'][] = array( + 'realPath' => $file->getRealPath(), + 'fileSize' => $file->getFileInfo()->getSize(), + 'onlyFileName' => $file->getRelativePathname(), + ); + /* + $absoluteFilePath = $file->getRealPath(); + $fileInfo = $file->getFileInfo(); + $fileNameWithExtension = $file->getRelativePathname(); + dump($absoluteFilePath); + dump($fileInfo->getSize()); + dump($fileNameWithExtension); + */ + #dump($this->arrData); + } + return $return; + }else{ + return $return; + } + + + #print_r(\iterator_to_array($finder,true)); + } + protected function loadFiles($srcFile,$size) + { +# $t = memory_get_usage(); +# dump($t); + $file = new \SplFileObject($srcFile); +# dump(memory_get_usage()-$t); + + $c = 0; + while (!$file->eof()) { + #*** Convertiert die Zeile in UTF8 + $str = iconv('ISO-8859-1','UTF-8',$file->fgets()); + #*** Zerlegt die Zeile ********** + $arr = $this->splitLine($str); + $this->switchSaveData($arr); + # + #dump('-----------------------'); + #dump($str); + #dump($arr); + $c++; +# if($c>=50){ +# dump(memory_get_usage()-$t); +# die(); +# } + } +# dump(memory_get_usage()-$t); +# die(); + } + protected function splitLine($str){ + return str_getcsv($str,';','"'); + } + + /** + * Hier wird festgelegt wo und wie die Zeile gespeichert wird + * + * @param array $arr + * @return void + */ + protected function switchSaveData(array $arr){ + if(!empty($arr[0])){ + #*** Leerzeichen löschen bei den einzelnen Einträgen ********** + $this->trimArray($arr); + #*** + $arr[0] = strtolower($arr[0]); + switch ($arr[0]){ + case 'datei': # Datei + $this->saveInfoDatei($arr); + break; + case 'filiale': # Filiale + #$this->saveInfoFiliale($arr); + break; + case 'land': # Länder + $this->saveInfoLand($arr); + break; + case 'hwg': # Hauptwarengruppe + #$this->saveInfoHauptWarenGruppe($arr); + break; + case 'wg': # Warengruppe + #$this->saveInfoWarenGruppe($arr); + break; + case 'anrede': # Anrede + #$this->saveInfoAnrede($arr); + break; + case 'lieferant': # Lieferant + #$this->saveInfoLieferant($arr); + break; + case 'farb': # Farbcodierung + #$this->saveInfoFarbCodierung($arr); + break; + case 'nlart': # NachlassArt + #$this->saveInfoNachlassArt($arr); + break; + case 'kollektion': # Kollektion + #$this->saveInfoKollektion($arr); + break; + case 'bestand': # Bestand + #$this->saveInfoBestand($arr); + break; + case 'merkmale': # Made In XXXX = Land + #$this->saveInfoMerkmale($arr); + break; + case 'material': # MAterial + #$this->saveInfoMaterial($arr); + break; + default: # + dump('!!!!! KEIN DEFINIERTER ANFANG "'.$arr[0].'" !!!!!!!!!'); + break; + } + } + } + protected function trimArray(Array &$arr){ + foreach ($arr as $k=>$v) { + $arr[$k] = trim($v); + } + } + protected function saveInfoDatei(Array $arr){ + + } + protected function saveInfoLand(Array $arr){ + #dump($arr); + + dd($arr); + } +} + + diff --git a/src/Repository/HlsCountryRepository.php b/src/Repository/HlsCountryRepository.php new file mode 100644 index 0000000..d271f13 --- /dev/null +++ b/src/Repository/HlsCountryRepository.php @@ -0,0 +1,66 @@ + + * + * @method HlsCountry|null find($id, $lockMode = null, $lockVersion = null) + * @method HlsCountry|null findOneBy(array $criteria, array $orderBy = null) + * @method HlsCountry[] findAll() + * @method HlsCountry[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class HlsCountryRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, HlsCountry::class); + } + + public function save(HlsCountry $entity, bool $flush = false): void + { + $this->getEntityManager()->persist($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } + } + + public function remove(HlsCountry $entity, bool $flush = false): void + { + $this->getEntityManager()->remove($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } + } + +// /** +// * @return HlsCountry[] Returns an array of HlsCountry objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('h') +// ->andWhere('h.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('h.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?HlsCountry +// { +// return $this->createQueryBuilder('h') +// ->andWhere('h.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +}