setName('chill:main:languages:populate') ->setDescription('Load or update languages in db. This command does not delete existing '. 'languages, but will update names according to available languages') ->addOption( self::INCLUDE_REGIONAL_VERSION, null, InputOption::VALUE_NONE, 'Include the regional languages. The regional languages are languages with code containing _ excepted ' .implode(',', $this->regionalVersionToInclude).'.' ) ->addOption( self::INCLUDE_ANCIENT, null, InputOption::VALUE_NONE, 'Include the ancient languages that are languages with code ' .implode(', ', $this->ancientToExclude).'.' ); } /** * (non-PHPdoc). * * @see \Symfony\Component\Console\Command\Command::execute() */ protected function execute(InputInterface $input, OutputInterface $output): int { $em = $this->entityManager; $chillAvailableLanguages = $this->parameterBag->get('chill_main.available_languages'); $languages = []; foreach ($chillAvailableLanguages as $avLang) { $languages[$avLang] = Languages::getNames(); } foreach (Languages::getNames() as $code => $lang) { $excludeCode = ( ( !$input->getOption(self::INCLUDE_REGIONAL_VERSION) && strpos($code, '_') && !\in_array($code, $this->regionalVersionToInclude, true) ) || ( !$input->getOption(self::INCLUDE_ANCIENT) && \in_array($code, $this->ancientToExclude, true) ) ); if (true === $excludeCode) { continue; } $languageDB = $em->getRepository(Language::class)->find($code); if (null === $languageDB) { $languageDB = new Language(); $languageDB->setId($code); $em->persist($languageDB); } $avLangNames = []; foreach ($chillAvailableLanguages as $avLang) { $avLangNames[$avLang] = ucfirst(Languages::getName($code, $avLang)); } $languageDB->setName($avLangNames); } $em->flush(); return 0; } }