private function downloadPronsVoice($name, $force)
 {
     $params = array();
     if ($force) {
         $sql = "SELECT * FROM pronunciation WHERE 1 = 1";
     } else {
         $sql = "SELECT * FROM pronunciation WHERE (voice IS NULL or voice = '')";
     }
     if ($name != null) {
         $sql .= ' AND name = :name';
         $params['name'] = $name;
     }
     $sql .= " AND voice not like '%/%'";
     $handle = $this->db->executeQuery($sql, $params);
     while ($row = $handle->fetch()) {
         $entity = new PronEntity();
         $entity->fromArray($row);
         try {
             $this->updatePron($entity, $force);
         } catch (\Exception $e) {
             $this->output->writeln(sprintf("pron [%s] update failed, error info: %s", $entity->getName(), $e->getMessage()));
         }
     }
 }
 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);
 }