Esempio n. 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')));
 }
 /**
  * @Given /^The next keys are present in database:$/
  */
 public function theNextKeysArePresentInDatabase(TableNode $table)
 {
     $rows = $table->getHash();
     foreach ($rows as $row) {
         $key = new Key();
         $key->setComment($row['comment']);
         $key->setKey($row['key']);
         $key->setProject($this->project);
         $key->setBundle($row['bundle']);
         $this->em->persist($key);
         $this->bundles[$row['bundle']] = false;
         $this->keys[$row['bundle'] . ':' . $row['key']] = $key;
     }
     $this->em->flush();
 }
Esempio n. 3
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')));
 }