当前位置: 首页>>代码示例>>PHP>>正文


PHP NodeHelper::deleteAllNodes方法代码示例

本文整理汇总了PHP中PHPCR\Util\NodeHelper::deleteAllNodes方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeHelper::deleteAllNodes方法的具体用法?PHP NodeHelper::deleteAllNodes怎么用?PHP NodeHelper::deleteAllNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHPCR\Util\NodeHelper的用法示例。


在下文中一共展示了NodeHelper::deleteAllNodes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: purge

 /**
  * @inheritDoc
  */
 public function purge()
 {
     $session = $this->dm->getPhpcrSession();
     NodeHelper::deleteAllNodes($session);
     $session->save();
 }
开发者ID:glaucosydow,项目名称:curso-zf2,代码行数:9,代码来源:PHPCRPurger.php

示例2: addNode

 /**
  * 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
         }
     }
     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::deleteAllNodes($parentNode->getSession());
         $node = $existing;
     } else {
         // logging echo "Adding node $nodename ($type)\n";
         $node = $parentNode->addNode($nodename, $type);
     }
     foreach ($properties as $name => $info) {
         // logging echo "Adding property $name\n";
         if ('jcr:primaryType' == $name) {
             // handled in node constructor
         } else {
             if ('jcr:mixinTypes' == $name) {
                 if (is_array($info['values'])) {
                     foreach ($info['values'] as $type) {
                         $node->addMixin($type);
                     }
                 } else {
                     $node->addMixin($info['values']);
                 }
             } else {
                 if ('jcr:created' == $name || 'jcr:createdBy' == $name) {
                     // skip PROTECTED properties. TODO: get the names from node type instead of hardcode
                 } else {
                     if ('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;
 }
开发者ID:ruflin,项目名称:jackalope,代码行数:92,代码来源:ImportExport.php


注:本文中的PHPCR\Util\NodeHelper::deleteAllNodes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。