protected function setUp()
 {
     $this->renewSession();
     // reset session
     parent::setUp();
     $this->workspace = $this->session->getWorkspace();
 }
 /**
  * @param string $moved_path
  * @param string $target_path
  *
  * @return array
  */
 public function move($moved_path, $target_path)
 {
     $resulting_path = $target_path . '/' . PathHelper::getNodeName($moved_path);
     $workspace = $this->session->getWorkspace();
     $workspace->move($moved_path, $target_path . '/' . PathHelper::getNodeName($moved_path));
     return array('id' => $resulting_path, 'url_safe_id' => ltrim($resulting_path, '/'));
 }
Esempio n. 3
0
 public function __construct(SessionManagerInterface $sessionManager, PropertyEncoder $propertyEncoder, WebspaceManagerInterface $webspaceManager, LocalizationFinderInterface $localizationFinder, SuluNodeHelper $nodeHelper)
 {
     $this->sessionManager = $sessionManager;
     $this->propertyEncoder = $propertyEncoder;
     $this->webspaceManager = $webspaceManager;
     $this->localizationFinder = $localizationFinder;
     $this->nodeHelper = $nodeHelper;
     $this->session = $sessionManager->getSession();
     $this->qomFactory = $this->session->getWorkspace()->getQueryManager()->getQOMFactory();
 }
 public function setUp()
 {
     $this->session = $this->prophesize(SessionInterface::class);
     $this->workspace = $this->prophesize(WorkspaceInterface::class);
     $this->queryManager = $this->prophesize(QueryManagerInterface::class);
     $this->dispatcher = $this->prophesize(EventDispatcherInterface::class);
     $this->phpcrQuery = $this->prophesize(QueryInterface::class);
     $this->phpcrResult = $this->prophesize(QueryResultInterface::class);
     $this->queryCreateEvent = $this->prophesize(QueryCreateEvent::class);
     $this->queryExecuteEvent = $this->prophesize(QueryExecuteEvent::class);
     $this->query = $this->prophesize(Query::class);
     $this->subscriber = new QuerySubscriber($this->session->reveal(), $this->dispatcher->reveal());
     $this->session->getWorkspace()->willReturn($this->workspace->reveal());
     $this->workspace->getQueryManager()->willReturn($this->queryManager->reveal());
 }
Esempio n. 5
0
 public function up(SessionInterface $session)
 {
     $workspace = $session->getWorkspace();
     $nodeTypeManager = $workspace->getNodeTypeManager();
     $nodeTypeManager->registerNodeType(new HomeNodeType(), true);
     $this->migrateHome($session, 'sulu:page', 'sulu:home', true);
 }
Esempio n. 6
0
 /**
  * {@inheritDoc}
  */
 public function transactional($callback)
 {
     if (!is_callable($callback)) {
         throw new InvalidArgumentException(sprintf('Parameter $callback must be a valid callable, "%s" given', gettype($callback)));
     }
     $transactionManager = null;
     try {
         $transactionManager = $this->session->getWorkspace()->getTransactionManager();
     } catch (UnsupportedRepositoryOperationException $e) {
         $result = call_user_func($callback, $this);
         $this->flush();
         return $result;
     }
     $transactionManager->begin();
     try {
         $result = call_user_func($callback, $this);
         $this->flush();
     } catch (\Exception $exception) {
         $this->close();
         $transactionManager->rollback();
         throw $exception;
     }
     $transactionManager->commit();
     return $result;
 }
Esempio n. 7
0
 private function migrateExternalLinks(SessionInterface $session, $directionUp = true)
 {
     $workspace = $session->getWorkspace();
     $queryManager = $workspace->getQueryManager();
     $webspaceManager = $this->container->get('sulu_core.webspace.webspace_manager');
     $propertyEncoder = $this->container->get('sulu_document_manager.property_encoder');
     $webspaces = $webspaceManager->getWebspaceCollection();
     /** @var Webspace $webspace */
     foreach ($webspaces as $webspace) {
         foreach ($webspace->getAllLocalizations() as $localization) {
             $locale = $localization->getLocalization();
             $query = $queryManager->createQuery(sprintf('SELECT * FROM [nt:base] WHERE [%s] = 4 AND [jcr:mixinTypes] = "sulu:page"', $propertyEncoder->localizedSystemName('nodeType', $locale)), 'JCR-SQL2');
             $rows = $query->execute();
             foreach ($rows as $row) {
                 /** @var NodeInterface $node */
                 $node = $row->getNode();
                 $templatePropertyName = $propertyEncoder->localizedSystemName('template', $locale);
                 try {
                     if (true === $directionUp) {
                         $node->setProperty($templatePropertyName, $webspace->getDefaultTemplate('page'));
                     } else {
                         $node->setProperty($templatePropertyName, 'external-link');
                     }
                 } catch (\Exception $e) {
                     echo $e->getMessage() . PHP_EOL;
                 }
             }
         }
     }
 }
Esempio n. 8
0
 /**
  * Iterates over all nodes of the given type, and upgrades them.
  *
  * @param StructureMetadata $structureMetadata The structure metadata, whose pages have to be upgraded
  * @param array $properties The properties which are or contain URL fields
  * @param bool $addScheme Adds the scheme to URLs if true, removes the scheme otherwise
  */
 private function iterateStructureNodes(StructureMetadata $structureMetadata, array $properties, $addScheme)
 {
     foreach ($this->localizationManager->getLocalizations() as $localization) {
         $rows = $this->session->getWorkspace()->getQueryManager()->createQuery(sprintf('SELECT * FROM [nt:unstructured] WHERE [%s] = "%s" OR [%s] = "%s"', $this->propertyEncoder->localizedSystemName('template', $localization->getLocalization()), $structureMetadata->getName(), 'template', $structureMetadata->getName()), 'JCR-SQL2')->execute();
         foreach ($rows->getNodes() as $node) {
             $this->upgradeNode($node, $localization->getLocalization(), $properties, $addScheme);
         }
     }
 }
 /**
  * Copy the document with the given path or ID to the path
  * of the destination document (as a child).
  *
  * @param string $srcId
  * @param string $destId
  * @param string $name
  *
  * @return string
  */
 public function copy($srcId, $destId, $name)
 {
     $workspace = $this->session->getWorkspace();
     $srcPath = $this->normalizeToPath($srcId);
     $parentDestPath = $this->normalizeToPath($destId);
     $destPath = $parentDestPath . '/' . $name;
     $workspace->copy($srcPath, $destPath);
     return $destPath;
 }
Esempio n. 10
0
    /**
     * Register the system node types on the given session.
     *
     * @param SessionInterface
     */
    public function registerNodeTypes(SessionInterface $session)
    {
        $cnd = <<<CND
// register phpcr_locale namespace
<{$this->localeNamespace}='{$this->localeNamespaceUri}'>
// register phpcr namespace
<{$this->phpcrNamespace}='{$this->phpcrNamespaceUri}'>
[phpcr:managed]
mixin
- phpcr:class (STRING)
- phpcr:classparents (STRING) multiple
CND;
        $nodeTypeManager = $session->getWorkspace()->getNodeTypeManager();
        $nodeTypeManager->registerNodeTypesCnd($cnd, true);
    }
Esempio n. 11
0
 /**
  * Register node types with compact node definition format
  *
  * This is only a proxy to the transport
  *
  * @param  string  $cnd         a string with cnd information
  * @param  boolean $allowUpdate whether to fail if node already exists or to update it
  * @return bool    true on success
  */
 public function registerNodeTypesCnd($cnd, $allowUpdate)
 {
     if ($this->transport instanceof NodeTypeCndManagementInterface) {
         return $this->transport->registerNodeTypesCnd($cnd, $allowUpdate);
     }
     if ($this->transport instanceof NodeTypeManagementInterface) {
         $workspace = $this->session->getWorkspace();
         $nsRegistry = $workspace->getNamespaceRegistry();
         $parser = new CndParser($workspace->getNodeTypeManager());
         $res = $parser->parseString($cnd);
         $ns = $res['namespaces'];
         $types = $res['nodeTypes'];
         foreach ($ns as $prefix => $uri) {
             $nsRegistry->registerNamespace($prefix, $uri);
         }
         return $workspace->getNodeTypeManager()->registerNodeTypes($types, $allowUpdate);
     }
     throw new UnsupportedRepositoryOperationException('Transport does not support registering node types');
 }
Esempio n. 12
0
    private function migrateInternalLinks(SessionInterface $session, $directionUp = true)
    {
        $workspace = $session->getWorkspace();
        $queryManager = $workspace->getQueryManager();
        $webspaceManager = $this->container->get('sulu_core.webspace.webspace_manager');
        $propertyEncoder = $this->container->get('sulu_document_manager.property_encoder');
        $webspaces = $webspaceManager->getWebspaceCollection();
        foreach ($webspaces as $webspace) {
            foreach ($webspace->getAllLocalizations() as $localization) {
                $locale = $localization->getLocalization();
                $sql = <<<EOT
SELECT * FROM [nt:unstructured] WHERE %s = 2
EOT;
                $query = $queryManager->createQuery(sprintf($sql, '[' . $propertyEncoder->localizedSystemName('nodeType', $locale) . ']'), 'JCR-SQL2');
                $rows = $query->execute();
                foreach ($rows as $row) {
                    $node = $row->getNode();
                    $internalLinkName = $propertyEncoder->localizedSystemName('internal_link', $locale);
                    try {
                        if (true === $directionUp) {
                            $internalUuid = $node->getPropertyValue($internalLinkName);
                            $internalNode = $session->getNodeByIdentifier($internalUuid);
                            $node->setProperty($internalLinkName, null);
                            $node->setProperty($internalLinkName, $internalNode);
                        } else {
                            $internalNode = $node->getPropertyValue($internalLinkName);
                            $internalNodeUuid = $internalNode->getIdentifier();
                            $node->setProperty($internalLinkName, null);
                            $node->setProperty($internalLinkName, $internalNodeUuid);
                        }
                    } catch (\Exception $e) {
                        echo $e->getMessage() . PHP_EOL;
                    }
                }
            }
        }
    }
Esempio n. 13
0
 /**
  * Create the fluent query builder.
  *
  * After building your query, use DocumentManager::getDocumentsByQuery with the
  * query returned by QueryBuilder::getQuery()
  *
  * @return QueryBuilder
  */
 public function createQueryBuilder()
 {
     $qm = $this->session->getWorkspace()->getQueryManager();
     return new QueryBuilder($qm->getQOMFactory());
 }
 /**
  * Register the content-type node types with the given PHPCR session.
  */
 public function registerNodeTypes(SessionInterface $session)
 {
     $cnd = sprintf('<%s=\'https://github.com/symfony-cmf/content-type\'>', $this->encoder->getPrefix(), $this->encoder->getUri());
     $nodeTypeManager = $session->getWorkspace()->getNodeTypeManager();
     $nodeTypeManager->registerNodeTypesCnd($cnd, true);
 }
Esempio n. 15
0
 private function cleanSession(OutputInterface $output, SessionInterface $session, $path, $dryRun)
 {
     $sessionName = $session->getWorkspace()->getName();
     $output->writeln(sprintf('<info>Session</info> %s', $sessionName));
     if (!$session->nodeExists($path)) {
         $output->write(sprintf('<error>Resource-Locator "%s" not found in session "%s"</error>', $path, $sessionName));
         return;
     }
     $node = $session->getNode($path);
     $this->cleanup($output, $node, $path, $dryRun);
     $output->writeln('');
 }
Esempio n. 16
0
 /**
  * @see \PHPCR\SessionInterface::getWorkspace
  */
 public function getWorkspace()
 {
     return new Workspace($this->session->getWorkspace(), $this);
 }
 /**
  * @return QueryManagerInterface
  */
 private function getQueryManager()
 {
     return $this->session->getWorkspace()->getQueryManager();
 }
Esempio n. 18
0
 /**
  * {@inheritdoc}
  */
 public function down(SessionInterface $session)
 {
     $liveSession = $this->container->get('sulu_document_manager.live_session');
     $session->getWorkspace()->deleteWorkspace($liveSession->getWorkspace()->getName());
 }
Esempio n. 19
0
 protected function registerCnd(SessionInterface $session, $cnd)
 {
     $session->getWorkspace()->getNodeTypeManager()->registerNodeTypesCnd($cnd, true);
 }
 /**
  * Actually do the update.
  *
  * @param OutputInterface  $output      the console output stream
  * @param SessionInterface $session     the PHPCR session to talk to
  * @param string           $cnd         the compact namespace and node type definition in string form
  * @param bool             $allowUpdate whether to allow updating existing node types.
  *
  * @throws \PHPCR\RepositoryException on other errors
  */
 protected function updateFromCnd(OutputInterface $output, SessionInterface $session, $cnd, $allowUpdate)
 {
     $ntm = $session->getWorkspace()->getNodeTypeManager();
     try {
         $ntm->registerNodeTypesCnd($cnd, $allowUpdate);
     } catch (NodeTypeExistsException $e) {
         if (!$allowUpdate) {
             $output->write(PHP_EOL . '<error>The node type(s) you tried to register already exist.</error>' . PHP_EOL);
             $output->write(PHP_EOL . 'If you want to override the existing definition call this command with the ');
             $output->write('<info>--allow-update</info> option.' . PHP_EOL);
         }
         throw $e;
     }
 }