Exemple #1
0
 /**
  */
 public function updateCommentIfNewest(Project $project, $bundle, $key, $catalog, $lastModification, $comment)
 {
     if (!$bundle || !$lastModification || !$comment || !$key) {
         return $this->exception('Validation exceptions, missing parameters');
     }
     $keyRecord = $this->getKeyRepository()->findOneBy(array('project' => $project, 'bundle' => $bundle, 'key' => $key, 'catalog' => $catalog));
     if (!$keyRecord instanceof Key) {
         $keyRecord = new Key();
         $keyRecord->setBundle($bundle);
         $keyRecord->setKey($key);
         $keyRecord->setCatalog($catalog);
     } else {
         if ($keyRecord->getUpdatedAt() >= $lastModification) {
             return $this->resultOk(array('updated' => false, 'message' => $keyRecord->getComment(), 'updatedAt' => $keyRecord->getUpdatedAt()->format('c')));
         }
     }
     $keyRecord->setComment($comment);
     $keyRecord->setUpdatedAt($lastModification);
     $this->em->persist($keyRecord);
     $this->em->flush($keyRecord);
     return $this->resultOk(array('updated' => true, 'message' => $keyRecord->getComment(), 'updatedAt' => $keyRecord->getUpdatedAt()->format('c')));
 }
Exemple #2
0
 /**
  * @Route("/update/comment/if-newest/{projectId}/{bundle}/{key}/{catalog}")
  * @Method("POST")
  * @ParamConverter("project", class="TranslationsBundle:Project", options={"id" = "projectId"})
  */
 public function updateCommentIfNewest(Request $request, $project, $bundle, $key, $catalog = self::DEFAULT_CATALOG)
 {
     $this->init();
     $key = urldecode($key);
     $param = json_decode($request->getContent(), true);
     $lastModification = new \DateTime($param['last_modification']);
     $comment = $param['comment'];
     if (!$bundle || !$lastModification || !$comment || !$key) {
         return $this->exception('Validation exceptions, missing parameters');
     }
     $keyRecord = $this->getKeyRepository()->findOneBy(array('project' => $project, 'bundle' => $bundle, 'key' => $request->get('key'), 'catalog' => $catalog));
     if (!$keyRecord instanceof Key) {
         $keyRecord = new Key();
         $keyRecord->setBundle($bundle);
         $keyRecord->setKey($key);
         $keyRecord->setCatalog($catalog);
     } else {
         if ($keyRecord->getUpdatedAt() >= $lastModification) {
             return $this->resultOk(array('updated' => false, 'message' => $keyRecord->getComment(), 'updatedAt' => $keyRecord->getUpdatedAt()->format('c')));
         }
     }
     $keyRecord->setComment($comment);
     $keyRecord->setUpdatedAt($lastModification);
     $this->em->persist($keyRecord);
     $this->em->flush();
     return $this->resultOk(array('updated' => true, 'message' => $keyRecord->getComment(), 'updatedAt' => $keyRecord->getUpdatedAt()->format('c')));
 }