コード例 #1
0
    /**
     * {@inheritDoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $session = $this->getPhpcrSession();
        $force = $input->getOption('force');

        $workspaceName = $session->getWorkspace()->getName();
        if (!$force) {
            /** @var $dialog DialogHelper */
            $dialog = $this->getHelperSet()->get('dialog');
            $force = $dialog->askConfirmation($output, sprintf(
                '<question>Are you sure you want to purge workspace "%s" Y/N ?</question>',
                $workspaceName
            ), false);
        }

        if (!$force) {
            $output->writeln('<error>Aborted</error>');

            return 1;
        }

        $output->writeln(sprintf('<info>Purging workspace:</info> %s', $workspaceName));

        // Using the static NodeHelper is bad for testing as we cannot mock it.
        NodeHelper::purgeWorkspace($session);
        $session->save();

        return 0;
    }
コード例 #2
0
 public function testPurge()
 {
     $systemNodeCount = count($this->session->getRootNode()->getNodes());
     $a = $this->session->getRootNode()->addNode('a', 'nt:unstructured');
     $a->addMixin('mix:referenceable');
     $b = $this->session->getRootNode()->addNode('b', 'nt:unstructured');
     $b->addMixin('mix:referenceable');
     $this->session->save();
     $a->setProperty('ref', $b, PropertyType::REFERENCE);
     $b->setProperty('ref', $a, PropertyType::REFERENCE);
     $this->session->save();
     NodeHelper::purgeWorkspace($this->session);
     if ($this->session->getWorkspace()->getName() == 'crx.default') {
         // if we would continue, we would delete all content from the only real workspace
         $this->markTestIncomplete('TODO: how to test this with crx where we have no workspaces?');
     }
     $this->session->save();
     // if there where system nodes, they should still be here
     $this->assertCount($systemNodeCount, $this->session->getRootNode()->getNodes());
 }
コード例 #3
0
ファイル: PHPCRInitCommand.php プロジェクト: kriswillis/sulu
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var SessionInterface $session */
     $session = $this->getContainer()->get('sulu.phpcr.session')->getSession();
     /** @var WorkspaceInterface $workspace */
     $workspace = $session->getWorkspace();
     // init node namespace and types
     $output->writeln('Register namespace');
     $workspace->getNamespaceRegistry()->registerNamespace('sulu', 'http://sulu.io/phpcr');
     $workspace->getNamespaceRegistry()->registerNamespace($this->getContainer()->getParameter('sulu.content.language.namespace'), 'http://sulu.io/phpcr/locale');
     $output->writeln('Register node types');
     foreach ([new SuluNodeType(), new PathNodeType(), new ContentNodeType(), new SnippetNodeType(), new PageNodeType(), new HomeNodeType()] as $nodeType) {
         $output->writeln('  - ' . $nodeType->getName());
         $workspace->getNodeTypeManager()->registerNodeType($nodeType, true);
     }
     /** @var SessionInterface $session */
     $session = $this->getContainer()->get('sulu.phpcr.session')->getSession();
     if ($input->getOption('clear')) {
         NodeHelper::purgeWorkspace($session);
         $session->save();
         $output->writeln('Clear repository');
     }
 }
コード例 #4
0
 public function testDeleteMoreThanOneThousandNodes()
 {
     $nodes = array();
     $root = $this->session->getNode('/');
     $parent = $root->addNode('test-more-than-one-thousand');
     for ($i = 0; $i <= 1200; $i++) {
         $nodes[] = $parent->addNode('node-' . $i);
     }
     $this->session->save();
     NodeHelper::purgeWorkspace($this->session);
     $this->session->save();
 }
コード例 #5
0
ファイル: ImportExport.php プロジェクト: viral810/ngSimpleCMS
 /**
  * Helper method for importing to add a node with the proper uuid behavior
  *
  * @param \PHPCR\NodeInterface $parentNode   the node to add this node to
  * @param string               $nodename     the node name to use
  * @param string               $type         the primary type name to use
  * @param int                  $uuidBehavior one of the constants of ImportUUIDBehaviorInterface
  *
  * @return NodeInterface the created node
  *
  * @throws \PHPCR\ItemExistsException if IMPORT_UUID_COLLISION_THROW and
  *      duplicate id
  * @throws \PHPCR\NodeType\ConstraintViolationException if behavior is remove or
  *      replace and the node with the uuid is in the parent path.
  */
 private static function addNode(NodeInterface $parentNode, $nodename, $type, $properties, $uuidBehavior)
 {
     $forceReferenceable = false;
     if (isset($properties['jcr:uuid'])) {
         try {
             $existing = $parentNode->getSession()->getNodeByIdentifier($properties['jcr:uuid']['values']);
             switch ($uuidBehavior) {
                 case self::IMPORT_UUID_CREATE_NEW:
                     unset($properties['jcr:uuid']);
                     $forceReferenceable = true;
                     break;
                 case self::IMPORT_UUID_COLLISION_THROW:
                     throw new ItemExistsException('There already is a node with uuid ' . $properties['jcr:uuid']['values'] . ' in this workspace.');
                 case self::IMPORT_UUID_COLLISION_REMOVE_EXISTING:
                 case self::IMPORT_UUID_COLLISION_REPLACE_EXISTING:
                     if (self::IMPORT_UUID_COLLISION_REPLACE_EXISTING == $uuidBehavior && 'jcr:root' == $nodename && $existing->getDepth() == 0) {
                         break;
                     }
                     if (!strncmp($existing->getPath() . '/', $parentNode->getPath() . "/{$nodename}", strlen($existing->getPath() . '/'))) {
                         throw new ConstraintViolationException('Trying to remove/replace parent of the path we are adding to. ' . $existing->getIdentifier() . ' at ' . $existing->getPath());
                     }
                     if (self::IMPORT_UUID_COLLISION_REPLACE_EXISTING == $uuidBehavior) {
                         // replace the found node. spec is not precise: do we keep the name or use the one of existing?
                         $parentNode = $existing->getParent();
                     }
                     $existing->remove();
                     break;
                 default:
                     // @codeCoverageIgnoreStart
                     throw new RepositoryException("Unexpected type {$uuidBehavior}");
                     // @codeCoverageIgnoreEnd
             }
         } catch (\PHPCR\ItemNotFoundException $e) {
             // nothing to do, we can add the node without conflict
         }
     }
     /* we add a jcr:root somewhere in the tree (either create new ids or
      * the root was not referenceable. do not make jackrabbit think it
      * would be the real root node.
      */
     if ('jcr:root' === $nodename && 'rep:root' === $type) {
         $type = 'nt:unstructured';
     }
     if ('jcr:root' == $nodename && isset($existing) && $existing->getDepth() === 0 && self::IMPORT_UUID_COLLISION_REPLACE_EXISTING == $uuidBehavior) {
         // update the root node properties
         // http://www.day.com/specs/jcr/2.0/11_Import.html#11.9%20Importing%20%3CI%3Ejcr:root%3C/I%3E
         NodeHelper::purgeWorkspace($parentNode->getSession());
         $node = $existing;
     } else {
         $node = $parentNode->addNode($nodename, $type);
     }
     foreach ($properties as $name => $info) {
         if ('jcr:primaryType' == $name) {
             // handled in node constructor
         } elseif ('jcr:mixinTypes' == $name) {
             if (is_array($info['values'])) {
                 foreach ($info['values'] as $type) {
                     $node->addMixin($type);
                 }
             } else {
                 $node->addMixin($info['values']);
             }
         } elseif ('jcr:created' == $name || 'jcr:createdBy' == $name) {
             // skip PROTECTED properties. TODO: get the names from node type instead of hardcode
         } elseif ('jcr:uuid' == $name) {
             //avoid to throw an exception when trying to set a UUID when importing from XML
             $node->setProperty($name, $info['values'], $info['type'], false);
         } else {
             $node->setProperty($name, $info['values'], $info['type']);
         }
     }
     if ($forceReferenceable && !$node->isNodeType('mix:referenceable')) {
         $node->addMixin('mix:referenceable');
     }
     return $node;
 }
コード例 #6
0
ファイル: ContextBase.php プロジェクト: hason/phpcr-shell
 /**
  * @Given /^I purge the current workspace$/
  */
 public function iPurgeTheCurrentWorkspace()
 {
     $session = $this->getSession();
     NodeHelper::purgeWorkspace($session);
 }
コード例 #7
0
ファイル: PHPCRPurger.php プロジェクト: Dren-x/mobit
 /**
  * @inheritDoc
  */
 public function purge()
 {
     $session = $this->dm->getPhpcrSession();
     NodeHelper::purgeWorkspace($session);
     $session->save();
 }
コード例 #8
0
ファイル: SuluTestCase.php プロジェクト: sulu/sulu
 /**
  * Initialize / reset the Sulu PHPCR environment.
  *
  * NOTE: We could use the document initializer here rather than manually creating
  *       the webspace nodes, but it currently adds more overhead and offers
  *       no control over *which* webspaces are created, see
  *       https://github.com/sulu-io/sulu/pull/2063 for a solution.
  */
 protected function initPhpcr()
 {
     /** @var SessionInterface $session */
     $session = $this->getContainer()->get('sulu_document_manager.default_session');
     $liveSession = $this->getContainer()->get('sulu_document_manager.live_session');
     if ($session->nodeExists('/cmf')) {
         NodeHelper::purgeWorkspace($session);
         $session->save();
     }
     if ($liveSession->nodeExists('/cmf')) {
         NodeHelper::purgeWorkspace($liveSession);
         $liveSession->save();
     }
     if (!$this->importer) {
         $this->importer = new PHPCRImporter($session, $liveSession);
     }
     // initialize the content repository.  in order to speed things up, for
     // each process, we dump the initial state to an XML file and restore
     // it thereafter.
     $initializerDump = __DIR__ . '/../Resources/app/cache/initial.xml';
     $initializerDumpLive = __DIR__ . '/../Resources/app/cache/initial_live.xml';
     if (true === self::$workspaceInitialized) {
         $session->importXml('/', $initializerDump, ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
         $session->save();
         $liveSession->importXml('/', $initializerDumpLive, ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
         $liveSession->save();
         return;
     }
     $filesystem = new Filesystem();
     if (!$filesystem->exists(dirname($initializerDump))) {
         $filesystem->mkdir(dirname($initializerDump));
     }
     $this->getContainer()->get('sulu_document_manager.initializer')->initialize();
     $handle = fopen($initializerDump, 'w');
     $liveHandle = fopen($initializerDumpLive, 'w');
     $session->exportSystemView('/cmf', $handle, false, false);
     $liveSession->exportSystemView('/cmf', $liveHandle, false, false);
     fclose($handle);
     self::$workspaceInitialized = true;
 }
コード例 #9
0
 /**
  * Purge the workspace.
  */
 public function purgeWorkspace()
 {
     NodeHelper::purgeWorkspace($this->session);
 }