Exemple #1
0
 /**
  * @param Project $project
  * @param string  $bundleName
  * @param string  $catalog
  * @param string  $key
  * @param string  $language
  * @param string  $msg
  *
  * @return Message
  */
 protected function insertOrUpdateMessage(Project $project, $bundleName, $catalog, $key, $language, $msg)
 {
     /** @var Key $keyRecord */
     $keyRecord = $this->getKeyRepository()->findOneBy(array('project' => $project, 'bundle' => $bundleName, 'catalog' => $catalog, 'key' => $key));
     if (!$keyRecord) {
         $keyRecord = new Key();
         $keyRecord->setProject($project);
         $keyRecord->setBundle($bundleName);
         $keyRecord->setCatalog($catalog);
         $keyRecord->setKey($key);
         $this->em->persist($keyRecord);
         $this->em->flush();
     }
     /** @var Message $message */
     $message = $this->getMessageRepository()->findOneBy(array('key' => $keyRecord, 'language' => $language));
     if (!$message) {
         $message = new Message();
         $message->setKey($keyRecord);
         $message->setLanguage($language);
     }
     $message->setMessage($msg);
     $message->setUpdatedAt();
     $this->em->persist($message);
     $this->em->flush();
     return $message;
 }
 /**
  * @Given /^The next messages are present in database:$/
  */
 public function theNextMessagesArePresentInDatabase(TableNode $table)
 {
     $rows = $table->getHash();
     foreach ($rows as $row) {
         $message = new Message();
         $message->setLanguage($row['language']);
         $message->setKey($this->keys[$row['bundle'] . ':' . $row['key']]);
         $message->setMessage($row['message']);
         $this->em->persist($message);
     }
     $this->em->flush();
 }
Exemple #3
0
 /**
  * @Route("/update/message/if-newest/{projectId}/{bundle}/{key}/{language}/{catalog}")
  * @Method("POST")
  * @ParamConverter("project", class="TranslationsBundle:Project", options={"id" = "projectId"})
  */
 public function updateMessageIfNewest(Request $request, $project, $bundle, $key, $language, $catalog = self::DEFAULT_CATALOG)
 {
     $this->init();
     $key = urldecode($key);
     $param = json_decode($request->getContent(), true);
     $lastModification = new \DateTime($param['last_modification']);
     $message = $param['message'];
     if (!$bundle || !$language || !$key || !$lastModification || !$message) {
         return $this->exception('Validation exceptions, missing parameters');
     }
     /** @var Key $keyRecord */
     $keyRecord = $this->getKeyRepository()->findOneBy(array('project' => $project, 'bundle' => $bundle, 'key' => $key, 'catalog' => $catalog));
     if (!$keyRecord) {
         $keyRecord = new Key();
         $keyRecord->setProject($project);
         $keyRecord->setKey($key);
         $keyRecord->setBundle($bundle);
         $keyRecord->setCatalog($catalog);
         $this->em->persist($keyRecord);
         $this->em->flush();
     }
     /** @var Message $messageRecord */
     $messageRecord = $this->getMessageRepository()->findOneBy(array('key' => $keyRecord, 'language' => $language));
     if (!$messageRecord) {
         $messageRecord = new Message();
         $messageRecord->setKey($keyRecord);
         $messageRecord->setLanguage($language);
     } else {
         if ($messageRecord->getUpdatedAt() >= $lastModification) {
             return $this->resultOk(array('updated' => false, 'message' => $messageRecord->getMessage(), 'updatedAt' => $messageRecord->getUpdatedAt()->format('c')));
         }
     }
     $messageRecord->setMessage($message);
     $messageRecord->setUpdatedAt($lastModification);
     $this->em->persist($messageRecord);
     $this->em->flush();
     return $this->resultOk(array('updated' => true));
 }