entityManager = $entityManager; $this->availableLanguages = $availableLanguages; parent::__construct(); } /** * (non-PHPdoc). * * @see \Symfony\Component\Console\Command\Command::configure() */ protected function configure() { $this ->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) { $em = $this->entityManager; $chillAvailableLanguages = $this->availableLanguages; $languageBundle = Intl::getLanguageBundle(); $languages = []; foreach ($chillAvailableLanguages as $avLang) { $languages[$avLang] = $languageBundle->getLanguageNames($avLang); } $languageCodes = array_keys($languages[$chillAvailableLanguages[0]]); foreach ($languageCodes as $code) { $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) ) ); $langageDB = $em->getRepository(Language::class)->find($code); if (!$excludeCode) { if (!$langageDB) { $langageDB = new \Chill\MainBundle\Entity\Language(); $langageDB->setId($code); $em->persist($langageDB); } $avLangNames = []; foreach ($chillAvailableLanguages as $avLang) { $avLangNames[$avLang] = $languages[$avLang][$code]; } $langageDB->setName($avLangNames); } else { if ($langageDB) { $em->remove($langageDB); } echo 'Code excluded : ' . $code . ' - ' . $languageBundle->getLanguageName($code) . "\n"; } } $em->flush(); } }