/** * @Route("/regenerate-project-info/{projectId}", name="regenerate_project_info") */ public function regenerateProjectInfoAction($projectId) { $this->init(); $projectInfo = $this->translationsManager->regenerateProjectInfo($projectId); ld($projectInfo->getBundles()); die("done!"); }
protected function blockSync(Project $project, $catalog, $language, $bundle, $data) { if (!$bundle || !$data || !$language || !$bundle || !$catalog) { return $this->exception('Validation exceptions, missing parameters'); } $result = array(); /** @var Message[] $localMessages */ $localMessages = $this->translationsManager->getMessagesForBundleCatalogAndLocale($project, $bundle, $catalog, $language); foreach ($localMessages as $message) { $key = $message->getKey(); $remoteMessage = isset($data[$key]) ? $data[$key] : null; if ($remoteMessage) { $remoteDate = new \DateTime($remoteMessage['updatedAt']); if ($message->getUpdatedAt() < $remoteDate) { $message->setMessage($remoteMessage['message']); $message->setUpdatedAt($remoteDate); $this->em->persist($message); } } if ($message->getApproved()) { $result[] = $message->asArray(); } } $this->em->flush(); $this->translationsManager->regenerateProjectInfo($project->getId()); return $this->resultOk($result); }
/** * * $data[key][locale] * { * message, * updatedAt, * bundle, * fileName, * } * */ protected function receiveKeys(Project $project, $catalog, $data) { if (!$project || !$catalog || !$data) { return $this->exception('Validation exceptions, missing parameters'); } $result = array(); /** @var Translation[] $messages */ $messages = $this->getTranslationRepository()->findBy(array('projectId' => $project->getId(), 'catalog' => $catalog)); if ($this->debug) { echo sprintf("found %d in translations\n", count($messages)); } foreach ($messages as $message) { $key = $message->getKey(); $bundle = ''; $translations = $message->getTranslations(); $dirty = false; if (count($translations)) { foreach ($translations as $locale => $translation) { if (isset($data[$key][$locale])) { $current = $data[$key][$locale]; $updatedAt = new \DateTime($current['updatedAt']); if ($message->getUpdatedAt()->sec < intval($updatedAt->format("U"))) { $result[$key][$locale] = $current['updatedAt']; $translations[$locale]['message'] = $current['message']; $translations[$locale]['updatedAt'] = $updatedAt; if (isset($current['approved'])) { $translations[$locale]['approved'] = $current['approved']; } $dirty = true; } $translations[$locale]['fileName'] = $current['fileName']; if (!$bundle) { if ($current['bundle']) { $bundle = $current['bundle']; } else { preg_match('/\\/(?<bundle>\\w+Bundle)\\//i', $current['fileName'], $matches); if (isset($matches['bundle'])) { $bundle = $matches['bundle']; } } } unset($data[$key][$locale]); } } if ($dirty) { $message->setBundle($bundle); $message->setTranslations($translations); $this->dm->persist($message); } } } if ($this->debug) { echo sprintf("found %d keys in data\n", count($data)); } foreach ($data as $key => $dataLocale) { if (count($dataLocale)) { if ($this->debug) { echo sprintf("processing key %s\n", $key); } $bundle = ''; $translation = new Translation(); $translation->setCatalog($catalog); $translation->setKey($key); $translation->setProjectId($project->getId()); $translation->setBundle($bundle); $translations = array(); foreach ($dataLocale as $locale => $message) { $translations[$locale] = array('message' => $message['message'], 'updatedAt' => new \DateTime($message['updatedAt']), 'approved' => true, 'fileName' => $message['fileName']); if (!$bundle) { if ($message['bundle']) { $bundle = $message['bundle']; } else { preg_match('/\\/(?<bundle>\\w+Bundle)\\//i', $current['fileName'], $matches); if (isset($matches['bundle'])) { $bundle = $matches['bundle']; } } } } $translation->setBundle($bundle); $translation->setTranslations($translations); $this->dm->persist($translation); } } $this->dm->flush(); // normalize $this->translationsManager->regenerateProjectInfo($project->getId()); return $this->resultOk($result); }