public function testBigFile()
 {
     //var_dump($this->session->getWorkspace()->getNodeTypeManager()->getNodeType('nt:file')->hasOrderableChildNodes());die;
     $res = $this->cndParser->parseFile(__DIR__ . '/resources/cnd/jackrabbit_nodetypes.cnd');
     // some random sanity checks
     $this->assertTrue(isset($res['nodeTypes']));
     $def = $res['nodeTypes'];
     $this->assertTrue(isset($def['nt:file']));
     /** @var $parsed NodeTypeDefinitionInterface */
     $parsed = $def['nt:file'];
     $this->assertEquals('nt:file', $parsed->getName());
     $this->assertFalse($parsed->isAbstract());
     $this->assertFalse($parsed->hasOrderableChildNodes());
     $this->assertFalse($parsed->isMixin());
     // queryable default is implementation specific
 }
Esempio n. 2
0
    public function execute(InputInterface $input, OutputInterface $output)
    {
        $session = $this->get('phpcr.session');
        $editor = $this->get('helper.editor');
        $dialog = $this->get('helper.question');
        $nodeTypeName = $input->getArgument('nodeTypeName');
        $workspace = $session->getWorkspace();
        $namespaceRegistry = $workspace->getNamespaceRegistry();
        $nodeTypeManager = $workspace->getNodeTypeManager();
        try {
            $nodeType = $nodeTypeManager->getNodeType($nodeTypeName);
            $cndWriter = new CndWriter($namespaceRegistry);
            $out = $cndWriter->writeString([$nodeType]);
            $message = null;
        } catch (NoSuchNodeTypeException $e) {
            $parts = explode(':', $nodeTypeName);
            if (count($parts) != 2) {
                throw new \InvalidArgumentException('Node type names must be prefixed with a namespace, e.g. ns:foobar');
            }
            list($namespace, $name) = $parts;
            $uri = $session->getNamespaceURI($namespace);
            // so we will create one ..
            $out = <<<EOT
<{$namespace} ='{$uri}'>
[{$namespace}:{$name}] > nt:unstructured

EOT;
            $message = <<<EOT
Creating a new node type: {$nodeTypeName}
EOT;
        }
        $valid = false;
        $prefix = '# ';
        do {
            $res = $editor->fromStringWithMessage($out, $message);
            if (empty($res)) {
                $output->writeln('<info>Editor emptied the CND file, doing nothing. Use node-type:delete to remove node types.</info>');
                return 0;
            }
            try {
                $cndParser = new CndParser($nodeTypeManager);
                $namespacesAndNodeTypes = $cndParser->parseString($res);
                foreach ($namespacesAndNodeTypes['nodeTypes'] as $nodeType) {
                    $nodeTypeManager->registerNodeType($nodeType, true);
                }
                $valid = true;
            } catch (\Exception $e) {
                $output->writeln('<error>' . $e->getMessage() . '</error>');
                $tryAgain = false;
                if (false === $input->getOption('no-interaction')) {
                    $tryAgain = $dialog->ask($input, $output, new ConfirmationQuestion('Do you want to try again? (y/n)'));
                }
                if (false === $tryAgain) {
                    return 1;
                }
                $message = 'The following errors were encountered (all lines starting with ' . $prefix . ' will be ignored):';
                $message .= PHP_EOL;
                $message .= PHP_EOL;
                $message .= $e->getMessage();
                $out = $res;
            }
        } while (false === $valid);
    }
Esempio n. 3
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');
 }