em = $em; $this->userManager = $userManager; $this->tokenStorage = $tokenStorage; $this->projectDir = $kernel->getProjectDir(); $this->propertyAccessor = PropertyAccess::createPropertyAccessor(); } /** * {@inheritdoc} */ public function configure(): void { $this->setName('zitec:fill:translations'); $this->addArgument( 'language', InputArgument::REQUIRED, 'language to translate' ); $this->setDescription( 'Translation tables filler' ); } /** * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output): int { $language=$input->getArgument('language'); $folderentity='src/Entity'; $translationClass=null; foreach (glob($folderentity."/*.php") as $index=>$nombre_fichero) { $tokenize=explode('/',$nombre_fichero); $clase= preg_replace('/\\.[^.\\s]{3,4}$/', '', end($tokenize)); $clase='App\Entity\\'.$clase; $reader = new Reader(); $ref = new \ReflectionClass($clase); //Check if class is translatable if($reader->getClassAnnotation($ref, 'Gedmo\TranslationEntity')){ $translationClass=$reader->getClassAnnotation($ref, 'Gedmo\TranslationEntity')->getClass(); echo "Identificada Clase ".$translationClass; }else{ continue; } //Get properties $properties= array_map(function (\ReflectionProperty $prop) { return $prop->getName(); }, $ref->getProperties()); $translatable=[]; foreach($properties as $property) { if($type=$reader->getPropertyAnnotation( $ref->getProperty($property), 'Gedmo\Mapping\Annotation\Translatable' )) { $translatable[] = $property; } } echo "Propiedades Traducibles de Clase ".$translationClass."\n".print_r($translatable,true); foreach($translatable as $prop){ $this->insertTranslation($prop, $language,$clase,$translationClass); } } exit(0); } private function insertTranslation($prop, $language,$class, $translationClass){ $records = $this->em->getRepository($class)->findAll(); echo "Translation class $class with class Translatos $translationClass to language $language"; foreach($records as $record){ //$record->addTranslation(new Entity\CategoryTranslation($language, $prop, $propertyAccessor->getValue($record,$prop))); echo "'$language', '$prop', '".$propertyAccessor->getValue($record,$prop)."'\n"; //$this->em->persist($record); } //$this->em->flush(); } }