Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $webspaceKey = $input->getArgument('webspaceKey');
     $locale = $input->getArgument('locale');
     $basePath = $input->getOption('base-path');
     $dryRun = $input->getOption('dry-run');
     $this->session = $this->getContainer()->get('doctrine_phpcr')->getManager()->getPhpcrSession();
     $this->sessionManager = $this->getContainer()->get('sulu.phpcr.session');
     $this->output = $output;
     $path = $this->sessionManager->getRoutePath($webspaceKey, $locale);
     $relativePath = $basePath !== null ? '/' . ltrim($basePath, '/') : '/';
     $fullPath = rtrim($path . $relativePath, '/');
     if (!$this->session->nodeExists($fullPath)) {
         $this->output->write('<error>Resource-Locator "' . $relativePath . '" not found</error>');
         return;
     }
     $node = $this->session->getNode($fullPath);
     $this->cleanup($node, $path, $dryRun);
     if (false === $dryRun) {
         $this->output->writeln('<info>Saving ...</info>');
         $this->session->save();
         $this->output->writeln('<info>Done</info>');
     } else {
         $this->output->writeln('<info>Dry run complete</info>');
     }
 }
Ejemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var Webspace $webspace */
     foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) {
         $this->upgradeWebspace($webspace, $output);
     }
     $this->liveSession->save();
 }
Ejemplo n.º 3
0
 private function handleSession(SessionInterface $session, $fileName)
 {
     if ($session->getRootNode()->hasNode('cmf')) {
         $session->getNode('/cmf')->remove();
         $session->save();
     }
     $session->importXML('/', $fileName, ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
     $session->save();
 }
Ejemplo n.º 4
0
 public function testRemove()
 {
     $this->property->expects($this->any())->method('getName')->will($this->returnValue('i18n:de-hotels'));
     $pageNode = $this->session->getNode('/cmf/sulu_io/contents/hotels');
     $this->contentType->remove($pageNode, $this->property, 'sulu_io', 'de', null);
     $this->session->save();
     $this->assertFalse($pageNode->hasProperty('i18n:de-hotels'));
 }
 protected function removeTestNode()
 {
     $root = $this->session->getRootNode();
     if ($root->hasNode($this->testNodeName)) {
         $root->getNode($this->testNodeName)->remove();
         $this->session->save();
     }
 }
 public function testDelete()
 {
     $structure = $this->prepareHistoryTestData();
     $this->repository->delete('/test', 'sulu_io', 'en');
     $this->session->save();
     $result = $this->repository->getHistory($structure->getUuid(), 'sulu_io', 'en');
     $this->assertEquals(1, count($result['_embedded']['resourcelocators']));
     $this->assertEquals('/test-1', $result['_embedded']['resourcelocators'][0]['resourceLocator']);
 }
Ejemplo n.º 7
0
 /**
  * Remove a PHPCR node under the root node
  *
  * @param string $name The name of the node to remove
  *
  * @return void
  */
 protected function removeTestNode($name)
 {
     $root = $this->session->getNode('/');
     if ($root->hasNode($name)) {
         $root->getNode($name)->remove();
         $this->session->save();
         $this->dm->clear();
     }
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $webspaceKey = $input->getArgument('webspaceKey');
     $locale = $input->getArgument('locale');
     $basePath = $input->getOption('base-path');
     $dryRun = $input->getOption('dry-run');
     $path = $this->sessionManager->getRoutePath($webspaceKey, $locale);
     $relativePath = $basePath !== null ? '/' . ltrim($basePath, '/') : '/';
     $fullPath = rtrim($path . $relativePath, '/');
     $this->cleanSession($output, $this->defaultSession, $fullPath, $dryRun);
     $this->cleanSession($output, $this->liveSession, $fullPath, $dryRun);
     if (false === $dryRun) {
         $this->defaultSession->save();
         $this->liveSession->save();
         $output->writeln('<info>Save complete</info>');
     } else {
         $output->writeln('<info>Dry run complete</info>');
     }
 }
Ejemplo n.º 9
0
 public function testFindByUUID()
 {
     $this->doc->topic = 'Un autre sujet';
     $this->doc->locale = 'fr';
     $this->dm->persist($this->doc);
     $this->dm->flush();
     $node = $this->session->getNode('/functional/' . $this->testNodeName);
     $node->addMixin('mix:referenceable');
     $this->session->save();
     $this->document = $this->dm->findTranslation($this->class, $node->getIdentifier(), 'fr');
     $this->assertInstanceOf($this->class, $this->document);
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) {
         $contentPath = $this->sessionManager->getContentPath($webspace->getKey());
         $this->context->getOutput()->writeln('Default workspace');
         $this->traverse($this->defaultSession->getNode($contentPath));
         $this->context->getOutput()->writeln('');
         $this->context->getOutput()->writeln('Live workspace');
         $this->traverse($this->liveSession->getNode($contentPath));
     }
     $this->defaultSession->save();
     $this->liveSession->save();
 }
Ejemplo n.º 11
0
 public function testFindWithInternalLinkToItself()
 {
     $this->initPhpcr();
     $link = $this->createPage('test-1', 'de');
     $page = $this->createInternalLinkPage('test-2', 'de', $link);
     $node = $this->session->getNodeByIdentifier($page->getUuid());
     $node->setProperty('i18n:de-internal_link', $node);
     $this->session->save();
     // should load content with requested node and not try to follow internal link
     $result = $this->contentRepository->find($page->getUuid(), 'de', 'sulu_io', MappingBuilder::create()->addProperties(['title'])->getMapping());
     $this->assertEquals($page->getUuid(), $result->getId());
     $this->assertEquals('/test-2', $result->getPath());
     $this->assertEquals('test-2', $result['title']);
 }
Ejemplo n.º 12
0
 private function migrateHome(SessionInterface $session, $from, $to, $referenceWebspace)
 {
     $webspaceManager = $this->container->get('sulu_core.webspace.webspace_manager');
     $pathRegistry = $this->container->get('sulu_document_manager.path_segment_registry');
     $webspaces = $webspaceManager->getWebspaceCollection();
     foreach ($webspaces as $webspace) {
         $webspacePath = sprintf('/%s/%s', $pathRegistry->getPathSegment('base'), $webspace->getKey());
         $homeNodeName = $pathRegistry->getPathSegment('content');
         $webspace = $session->getNode($webspacePath);
         if ($referenceWebspace) {
             $webspace->addMixin('mix:referenceable');
         } else {
             $webspace->removeMixin('mix:referenceable');
         }
         $homeNode = $webspace->getNode($homeNodeName);
         $tmpNode = $session->getRootNode()->addNode('/tmp');
         $tmpNode->addMixin('mix:referenceable');
         $session->save();
         $homeNodeReferences = $homeNode->getReferences();
         $homeNodeReferenceValues = [];
         foreach ($homeNodeReferences as $homeNodeReference) {
             /* @var Property $homeNodeReference */
             $homeNodeReferenceValues[$homeNodeReference->getPath()] = $homeNodeReference->getValue();
             $homeNodeReference->setValue($tmpNode);
         }
         $session->save();
         $homeNode->removeMixin($from);
         $session->save();
         $homeNode->addMixin($to);
         $session->save();
         foreach ($homeNodeReferences as $homeNodeReference) {
             $homeNodeReference->setValue($homeNodeReferenceValues[$homeNodeReference->getPath()], PropertyType::REFERENCE);
         }
         $session->save();
         $tmpNode->remove();
     }
 }
Ejemplo n.º 13
0
 /**
  * Structures are updated according to their xml definition.
  *
  * @param bool $up Indicates that this is up or down
  */
 private function iterateStructures($up)
 {
     $properties = [];
     // find templates containing date fields
     $structureMetadatas = array_merge($this->structureMetadataFactory->getStructures('page'), $this->structureMetadataFactory->getStructures('snippet'));
     $structureMetadatas = array_filter($structureMetadatas, function (StructureMetadata $structureMetadata) use(&$properties) {
         $structureName = $structureMetadata->getName();
         $this->findDateProperties($structureMetadata, $properties);
         return !empty($properties[$structureName]) || !empty($blockProperties[$structureName]);
     });
     foreach ($structureMetadatas as $structureMetadata) {
         $this->iterateStructureNodes($structureMetadata, $properties[$structureMetadata->getName()], $up);
     }
     $this->session->save();
 }
Ejemplo n.º 14
0
 public function testOverride()
 {
     $property = new Property('url', [], 'resource_locator');
     $property->setValue('/test');
     $node = $this->sessionManager->getContentNode('sulu_io')->addNode('test');
     $node->addMixin('sulu:content');
     $this->session->save();
     $this->resourceLocator->write($node, $property, 1, 'sulu_io', 'en');
     $this->assertEquals('/test', $node->getPropertyValue('url'));
     $this->assertTrue($this->session->getRootNode()->hasNode('cmf/sulu_io/routes/en/test'));
     $property->setValue('/test-2');
     $this->resourceLocator->write($node, $property, 1, 'sulu_io', 'en');
     $this->assertEquals('/test-2', $node->getPropertyValue('url'));
     $this->assertTrue($this->session->getRootNode()->hasNode('cmf/sulu_io/routes/en/test-2'));
 }
Ejemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function reorderNode($sourcePath, $position)
 {
     $node = $this->getNode($sourcePath);
     $parent = $node->getParent();
     $nodeNames = $parent->getNodeNames();
     if ($position == 0) {
         $parent->orderBefore($node->getName(), $nodeNames[$position]);
     } elseif (isset($nodeNames[$position + 1])) {
         $parent->orderBefore($node->getName(), $nodeNames[$position + 1]);
     } else {
         $lastName = $nodeNames[count($nodeNames) - 1];
         $parent->orderBefore($node->getName(), $lastName);
         $parent->orderBefore($lastName, $node->getName());
     }
     $this->session->save();
 }
 /**
  * Pass parent document and check message.
  */
 public function testTranslateStrict()
 {
     $this->converter = new TranslationConverter($this->dm);
     $class = 'Doctrine\\Tests\\Models\\Translation\\ChildTranslationComment';
     $parentClass = 'Doctrine\\Tests\\Models\\Translation\\Comment';
     $field = 'text';
     $comment = $this->node->addNode('convert');
     $comment->setProperty($field, 'Lorem ipsum...');
     $comment->setProperty('phpcr:class', $class);
     $comment->setProperty('phpcr:classparents', array($parentClass));
     $this->session->save();
     $this->assertFalse($this->converter->convert($parentClass, array('en')));
     $notices = $this->converter->getLastNotices();
     $this->assertCount(1, $notices);
     $this->assertArrayHasKey('/functional/convert', $notices);
     $this->assertFalse($this->session->hasPendingChanges());
 }
Ejemplo n.º 17
0
 public function testPrimaryItem()
 {
     $this->registerNodeTypePrimaryItem();
     // Create a node of that type
     $root = $this->session->getRootNode();
     if ($root->hasNode('test_node')) {
         $node = $root->getNode('test_node');
         $node->remove();
         $this->session->save();
     }
     $node = $root->addNode('test_node', 'phpcr:primary_item_test');
     $node->setProperty('phpcr:content', 'test');
     $this->session->save();
     // Check the primary item of the new node
     $primary = $node->getPrimaryItem();
     $this->assertInstanceOf('PHPCR\\ItemInterface', $node);
     $this->assertEquals('phpcr:content', $primary->getName());
 }
Ejemplo n.º 18
0
 /**
  * Reorder $moved (child of $parent) before or after $target
  *
  * @param string $parent the id of the parent
  * @param string $moved the id of the child being moved
  * @param string $target the id of the target node
  * @param bool $before insert before or after the target
  * 
  * @return void
  */
 public function reorder($parent, $moved, $target, $before)
 {
     $parentNode = $this->session->getNode($parent);
     $targetName = PathHelper::getNodeName($target);
     if (!$before) {
         $nodesIterator = $parentNode->getNodes();
         $nodesIterator->rewind();
         while ($nodesIterator->valid()) {
             if ($nodesIterator->key() == $targetName) {
                 break;
             }
             $nodesIterator->next();
         }
         $targetName = null;
         if ($nodesIterator->valid()) {
             $nodesIterator->next();
             if ($nodesIterator->valid()) {
                 $targetName = $nodesIterator->key();
             }
         }
     }
     $parentNode->orderBefore(PathHelper::getNodeName($moved), $targetName);
     $this->session->save();
 }
 /**
  * Produce the following entries at the end of the event journal:.
  *
  *      PROPERTY_ADDED      /child/jcr:primaryType
  *      NODE_ADDED          /child
  *      PERSIST
  *      PROPERTY_ADDED      /child/prop
  *      PERSIST
  *      PROPERTY_CHANGED    /child/prop
  *      PERSIST
  *      PROPERTY_REMOVED    /child/prop
  *      PERSIST
  *      NODE_REMOVED        /child
  *      PERSIST
  *
  * WARNING:
  * If you change the events (or the order of events) produced here, you
  * will have to adapt self::expectEvents so that it checks for the correct
  * events.
  *
  * @param $session
  */
 protected function produceEvents(SessionInterface $session)
 {
     $parent = $session->getNode($this->nodePath);
     // Will cause a PROPERTY_ADDED + a NODE_ADDED events
     $node = $parent->addNode('child');
     // Will cause a PERSIST event
     $session->save();
     // Will case a PROPERTY_ADDED event
     $prop = $node->setProperty('prop', 'value');
     // Will cause a PERSIST event
     $session->save();
     // Will cause a PROPERTY_CHANGED event
     $prop->setValue('something else');
     // Will cause a PERSIST event
     $session->save();
     // Will cause a PROPERTY_REMOVED event
     $prop->remove();
     // Will cause a PERSIST event
     $session->save();
     // Will cause a NODE_REMOVED + NODE_ADDED + NODE_MOVED events
     $session->move($node->getPath(), $this->nodePath . '/moved');
     // Will cause a PERSIST event
     $session->save();
     // Will cause a NODE_REMOVED event
     $node->remove();
     // Will cause a PERSIST event
     $session->save();
 }
Ejemplo n.º 20
0
 /**
  * Imports workspace.
  *
  * @param SessionInterface $session
  * @param string $path
  * @param string $fileName
  */
 private function import(SessionInterface $session, $path, $fileName)
 {
     if ($session->nodeExists($path)) {
         $session->getNode($path)->remove();
         $session->save();
     }
     $session->importXML(PathHelper::getParentPath($path), $fileName, ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
     $session->save();
 }
Ejemplo n.º 21
0
 /**
  * Save all pending changes currently recorded in this Session.
  */
 public function save()
 {
     $this->session->save();
 }
Ejemplo n.º 22
0
 /**
  * Utility method for tests to save the session and get a new one.
  *
  * Saves the old session and logs it out.
  *
  * @return \PHPCR\SessionInterface   The new session
  */
 protected function saveAndRenewSession()
 {
     $this->session->save();
     $this->renewSession();
     return $this->sharedFixture['session'];
 }
Ejemplo n.º 23
0
 /**
  * Flushes the live session.
  */
 public function flushPublicWorkspace()
 {
     $this->liveSession->save();
 }
Ejemplo n.º 24
0
 /**
  * {@inheritdoc}
  */
 public function flush()
 {
     $this->defaultSession->save();
     $this->liveSession->save();
 }