private function updatePron(PronEntity $entity)
 {
     if (str_word_count($entity->getName(), 0) == 1) {
         $voiceName = $this->c['pronsWordVoiceDownloader']->download($entity->getName());
     } else {
         $entity->setMeans('NONE');
         $entity->setPronunciation('NONE');
         $voiceName = $this->c['pronsPhraseVoiceDownloader']->download($entity->getName());
     }
     $entity->setVoice($voiceName);
     $this->em->merge($entity);
     $this->em->flush();
     $this->output->writeln(sprintf("pron [%s] is updated.", $entity->getName()));
 }
 public function addNewAction()
 {
     $json = array('status' => 0, 'errorWords' => '');
     $key = trim($this->request->request->get('key'));
     $words = preg_split("|[\r\n]+|i", $key);
     if (empty($words)) {
         return new JsonResponse($json);
     }
     $errorProns = array();
     $successProns = array();
     $updateProns = array();
     foreach ($words as $word) {
         $entity = $this->em->getRepository('Eng:PronEntity')->findOneBy(array('name' => $word));
         if ($entity === null) {
             $entity = new PronEntity();
             $entity->setName($word);
             $entity->setCreateTime(new \Datetime('now'));
         }
         try {
             if (str_word_count($entity->getName(), 0) == 1) {
                 $mean = $this->c['wordMeanDownloader']->download($entity->getName());
                 $entity->setMeans(implode("\n", $mean->getMeaning()));
                 $entity->setPronunciation($mean->getPhonetic());
                 $voiceName = $this->c['pronsWordVoiceDownloader']->download($entity->getName());
             } else {
                 $entity->setMeans('NONE');
                 $entity->setPronunciation('NONE');
                 $voiceName = $this->c['pronsPhraseVoiceDownloader']->download($entity->getName());
             }
             $entity->setVoice($voiceName);
             $entity->setStatus(PronEntity::NEWONE);
         } catch (\Exception $e) {
             $this->log->addWarning(sprintf("Can not find this sentence:%s, info:%s", $entity->getName(), $e->getMessage()));
             $errorProns[] = $entity->getName();
             continue;
         }
         if ($entity->getId() !== null) {
             $updateProns[] = $entity->getName();
         } else {
             $successProns[] = $entity->getName();
         }
         $this->em->persist($entity);
         $this->em->flush();
     }
     $message = array();
     if (!empty($successProns)) {
         $message[] = 'new prons: ' . count($successProns);
     }
     if (!empty($updateProns)) {
         $message[] = 'update prons: ' . count($updateProns);
     }
     if (!empty($errorProns)) {
         if (empty($successProns) && empty($updateProns)) {
             $json['status'] = 1;
         }
         $message[] = 'error prons: ' . count($errorProns);
         $json['errorWords'] = implode("\n", $errorProns);
     }
     $json['message'] = implode(', ', $message);
     return new JsonResponse($json);
 }