Example #1
0
 private function processForm(Request $request, $document)
 {
     $locale = $this->getLocale($request);
     $data = $request->request->all();
     $data['workflowStage'] = $request->get('state', WorkflowStage::PUBLISHED);
     $form = $this->formFactory->create('snippet', $document, ['csrf_protection' => false]);
     $form->submit($data, false);
     if (!$form->isValid()) {
         throw new InvalidFormException($form);
     }
     $this->documentManager->persist($document, $locale, ['user' => $this->getUser()->getId(), 'clear_missing_content' => false]);
     $this->documentManager->publish($document, $locale);
     $this->documentManager->flush();
     return $form;
 }
Example #2
0
 /**
  * Import document by locale into given webspace.
  *
  * @param array $parsedData
  * @param string $webspaceKey
  * @param string $locale
  *
  * @return bool
  */
 protected function importDocument(array $parsedData, $format, $webspaceKey, $locale, $overrideSettings)
 {
     $uuid = null;
     try {
         if (!isset($parsedData['uuid']) || !isset($parsedData['structureType']) || !isset($parsedData['data'])) {
             $this->addException('uuid, structureType or data for import not found.', 'ignore');
             throw new \Exception('uuid, structureType or data for import not found.');
         }
         $uuid = $parsedData['uuid'];
         $structureType = $parsedData['structureType'];
         $data = $parsedData['data'];
         $documentType = Structure::TYPE_PAGE;
         if ($this->getParser($format)->getPropertyData('url', $data) === '/') {
             $documentType = 'home';
             // TODO no constant
         }
         /** @var BasePageDocument $document */
         $document = $this->documentManager->find($uuid, $locale, ['type' => $documentType, 'load_ghost_content' => false]);
         $document->setStructureType($structureType);
         if ($document->getWebspaceName() != $webspaceKey) {
             $this->addException(sprintf('Document(%s) is part of another webspace: "%s"', $uuid, $document->getWebspaceName()), 'ignore');
             throw new \Exception(sprintf('Document(%s) is part of another webspace: "%s"', $uuid, $document->getWebspaceName()));
         }
         if (!$document instanceof BasePageDocument) {
             throw new \Exception(sprintf('Document(%s) is not an instanecof BasePageDocument', $uuid));
         }
         if (!$this->setDocumentData($document, $structureType, $webspaceKey, $locale, $format, $data)) {
             return false;
         }
         $this->setDocumentSettings($document, $structureType, $webspaceKey, $locale, $format, $data, $overrideSettings);
         // save document
         $this->documentManager->persist($document, $locale);
         $this->documentManager->publish($document, $locale);
         $this->documentManager->flush();
         $this->documentRegistry->clear();
         // FIXME else it failed on multiple page import
         return true;
     } catch (\Exception $e) {
         if ($e instanceof DocumentManagerException) {
             return;
         }
         $this->logger->error(sprintf('<info>%s</info>%s: <error>%s</error>%s', $uuid, PHP_EOL . get_class($e), $e->getMessage(), PHP_EOL . $e->getTraceAsString()));
         $this->documentManager->flush();
         $this->documentManager->clear();
     }
     return false;
 }