示例#1
0
 /**
  * Load the given fixture classes.
  *
  * @param array           $fixtures
  * @param mixed           $purge
  * @param mixed           $initialize
  * @param OutputInterface $output
  */
 public function execute(array $fixtures, $purge = true, $initialize = true, OutputInterface $output = null)
 {
     $output = $output ?: new NullOutput();
     if (true === $initialize) {
         $output->writeln('<comment>Initializing repository</comment>');
         $this->initializer->initialize($output, $purge);
     }
     $output->writeln('<comment>Loading fixtures</comment>');
     foreach ($fixtures as $fixture) {
         $output->writeln(sprintf(' - %s<info>loading "</info>%s<info>"</info>', $fixture instanceof OrderedFixtureInterface ? '[' . $fixture->getOrder() . ']' : '', get_class($fixture)));
         $fixture->load($this->documentManager);
         $this->documentManager->clear();
     }
 }
示例#2
0
文件: Webspace.php 项目: sulu/sulu
 /**
  * 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;
 }
示例#3
0
 public function testOrderAtInternalLink()
 {
     $this->tokenStorage->setToken($this->createUserTokenWithId(17));
     $data = $this->prepareOrderAtData();
     $this->documentManager->clear();
     $testSiteData = ['title' => 'Test', 'nodeType' => Structure::NODE_TYPE_INTERNAL_LINK, 'url' => '/test/123', 'internal_link' => $data[0]->getUuid()];
     $site = $this->mapper->save($testSiteData, 'internal_link_page', 'sulu_io', 'en', 1, true, null, $data[0]->getUuid());
     $this->documentManager->clear();
     $result = $this->mapper->orderAt($site->getUuid(), 3, 17, 'sulu_io', 'en');
     $this->assertEquals($site->getUuid(), $result->getUuid());
     $this->assertEquals('/page-1/test', $result->getPath());
     $this->assertEquals(17, $result->getChanger());
     $this->documentManager->clear();
     $result = $this->documentManager->find($site->getUuid(), 'en');
     $this->assertEquals(30, $result->getSuluOrder());
     $this->assertEquals(RedirectType::INTERNAL, $result->getRedirectType());
     $result = $this->mapper->loadByParent($data[0]->getUuid(), 'sulu_io', 'en');
     $this->assertEquals('/page-1/page-1-1', $result[0]->getPath());
     $this->assertEquals('/page-1/page-1-2', $result[1]->getPath());
     $this->assertEquals('/page-1/test', $result[2]->getPath());
     $this->assertEquals('/page-1/page-1-3', $result[3]->getPath());
     $this->assertEquals('/page-1/page-1-4', $result[4]->getPath());
 }