This commit is contained in:
parent
2be165a8c1
commit
f7b2a93197
@ -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.');
|
||||
|
65
src/Entity/HlsCountry.php
Normal file
65
src/Entity/HlsCountry.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\HlsCountryRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: HlsCountryRepository::class)]
|
||||
class HlsCountry
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $short_name = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $short_iso = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $name = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->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;
|
||||
}
|
||||
}
|
176
src/Helper/HiltesImport.php
Normal file
176
src/Helper/HiltesImport.php
Normal file
@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helper;
|
||||
|
||||
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class HiltesImport
|
||||
{
|
||||
protected $currentDirPath;
|
||||
protected $arrData = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
|
||||
|
66
src/Repository/HlsCountryRepository.php
Normal file
66
src/Repository/HlsCountryRepository.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\HlsCountry;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<HlsCountry>
|
||||
*
|
||||
* @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()
|
||||
// ;
|
||||
// }
|
||||
}
|
Loading…
Reference in New Issue
Block a user