/** * @param PersistEvent $event * * @throws DocumentManagerException */ public function handlePersist(PersistEvent $event) { $options = $event->getOptions(); $this->validateOptions($options); $document = $event->getDocument(); $parentPath = null; $nodeName = null; if ($options['path']) { $parentPath = PathHelper::getParentPath($options['path']); $nodeName = PathHelper::getNodeName($options['path']); } if ($options['parent_path']) { $parentPath = $options['parent_path']; } if ($parentPath) { $event->setParentNode($this->resolveParent($parentPath, $options)); } if ($options['node_name']) { if (!$event->hasParentNode()) { throw new DocumentManagerException(sprintf('The "node_name" option can only be used either with the "parent_path" option ' . 'or when a parent node has been established by a previous subscriber. ' . 'When persisting document: %s', DocumentHelper::getDebugTitle($document))); } $nodeName = $options['node_name']; } if (!$nodeName) { return; } if ($event->hasNode()) { $this->renameNode($event->getNode(), $nodeName); return; } $node = $this->strategy->createNodeForDocument($document, $event->getParentNode(), $nodeName); $event->setNode($node); }
/** * Persists the data of creator and changer to the Node. * * @param PersistEvent $event */ public function handlePersist(PersistEvent $event) { $document = $event->getDocument(); if (!$document instanceof LocalizedBlameBehavior) { return; } $userId = $this->getUserId($event->getOptions()); if (null === $userId) { return; } if (!$event->getLocale()) { return; } if (!$document->getCreator()) { $event->getAccessor()->set(self::CREATOR, $userId); } $event->getAccessor()->set(self::CHANGER, $userId); }
/** * @param PersistEvent $event */ public function handlePersist(PersistEvent $event) { $document = $event->getDocument(); if (!$document instanceof BlameBehavior) { return; } $userId = $this->getUserId($event->getOptions()); if (null === $userId) { return; } $node = $event->getNode(); $locale = $event->getLocale(); if (!$this->getCreator($node, $locale)) { $name = $this->encoder->localizedSystemName(self::CREATOR, $locale); $node->setProperty($name, $userId, PropertyType::LONG); } $name = $this->encoder->localizedSystemName(self::CHANGER, $locale); $node->setProperty($name, $userId, PropertyType::LONG); $this->handleHydrate($event); }