/** * @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 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(); }
/** * @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'))); }