/** * {@inheritdoc} */ public function toArray($complete = true) { $document = $this->getDocument(); $result = ['id' => $this->inspector->getUuid($document), 'path' => $this->inspector->getContentPath($document), 'nodeType' => $this->getNodeType(), 'nodeState' => $this->getNodeState(), 'internal' => false, 'concreteLanguages' => $this->inspector->getLocales($document), 'hasSub' => $this->getHasChildren(), 'title' => $document->getTitle()]; if ($document instanceof OrderBehavior) { $result['order'] = $document->getSuluOrder(); } if ($document instanceof RedirectTypeBehavior) { $redirectType = $document->getRedirectType(); $result['linked'] = null; if ($redirectType == RedirectType::INTERNAL && $document->getRedirectTarget() !== null) { $result['linked'] = 'internal'; $result['internal_link'] = $document->getRedirectTarget()->getUuid(); } elseif ($redirectType == RedirectType::EXTERNAL) { $result['linked'] = 'external'; $result['external'] = $document->getRedirectExternal(); } } if ($document instanceof WorkflowStageBehavior) { $result['publishedState'] = $document->getWorkflowStage() === WorkflowStage::PUBLISHED; $result['published'] = $document->getPublished(); } $result['navContexts'] = []; if ($document instanceof NavigationContextBehavior) { $result['navContexts'] = $document->getNavigationContexts(); } if (null !== $this->getType()) { $result['type'] = $this->getType()->toArray(); } if ($complete) { if ($document instanceof ShadowLocaleBehavior) { $result = array_merge($result, ['enabledShadowLanguages' => $this->inspector->getShadowLocales($document), 'shadowOn' => $document->isShadowLocaleEnabled(), 'shadowBaseLanguage' => $document->getShadowLocale() ?: false]); } $result = array_merge($result, ['template' => $this->structure->getName(), 'originTemplate' => $this->structure->getName(), 'creator' => $document->getCreator(), 'changer' => $document->getChanger(), 'created' => $document->getCreated(), 'changed' => $document->getChanged(), 'title' => $document->getTitle(), 'url' => null]); if ($document instanceof ResourceSegmentBehavior) { $result['url'] = $document->getResourceSegment(); } if ($document instanceof ExtensionBehavior) { $result['ext'] = $document->getExtensionsData(); } $result = array_merge($this->getDocument()->getStructure()->toArray(), $result); return $result; } return $result; }
/** * It should throw an exception if the property is required but the value is null. * * @expectedException Sulu\Component\Content\Exception\MandatoryPropertyException */ public function testThrowExceptionPropertyRequired() { $document = new TestContentDocument($this->structure->reveal()); $document->setStructureType('foobar'); $this->persistEvent->getDocument()->willReturn($document); // map the structure type $this->persistEvent->getLocale()->willReturn('fr'); // map the content $this->inspector->getStructureMetadata($document)->willReturn($this->structureMetadata->reveal()); $this->inspector->getWebspace($document)->willReturn('webspace'); $this->structureMetadata->getProperties()->willReturn(['prop1' => $this->structureProperty->reveal()]); $this->structureProperty->isRequired()->willReturn(true); $this->structure->getProperty('prop1')->willReturn($this->propertyValue->reveal()); $this->propertyValue->getValue()->willReturn(null); $this->structureMetadata->getName()->willReturn('test'); $this->structureMetadata->getResource()->willReturn('/path/to/resource.xml'); $this->subscriber->handlePersist($this->persistEvent->reveal()); }
/** * 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); } } }
public function getMetadata(Metadata $documentMetadata, StructureMetadata $structure) { $classMetadata = $this->factory->createClassMetadata($documentMetadata->getClass()); $class = $documentMetadata->getReflectionClass(); $indexMeta = $this->factory->createIndexMetadata(); $indexMeta->setIdField($this->factory->createMetadataField('uuid')); $indexMeta->setLocaleField($this->factory->createMetadataField('locale')); $indexName = 'page'; // See if the mapping overrides the default index and category name foreach ($this->mapping as $className => $mapping) { if ($documentMetadata->getAlias() !== $className && $class->name !== $className && false === $class->isSubclassOf($className)) { continue; } $indexName = $mapping['index']; } if ($indexName === 'page') { $indexMeta->setIndexName(new Expression('"page_"~object.getWebspaceName()')); } else { $indexMeta->setIndexName(new Value($indexName)); } foreach ($structure->getProperties() as $property) { if ($property instanceof BlockMetadata) { $propertyMapping = new ComplexMetadata(); foreach ($property->getComponents() as $component) { foreach ($component->getChildren() as $componentProperty) { if (false === $componentProperty->hasTag('sulu.search.field')) { continue; } $tag = $componentProperty->getTag('sulu.search.field'); $tagAttributes = $tag['attributes']; if (!isset($tagAttributes['index']) || $tagAttributes['index'] !== 'false') { $propertyMapping->addFieldMapping($property->getName() . '.' . $componentProperty->getName(), ['type' => isset($tagAttributes['type']) ? $tagAttributes['type'] : 'string', 'field' => $this->factory->createMetadataProperty('[' . $componentProperty->getName() . ']'), 'aggregate' => true, 'indexed' => false]); } } } $indexMeta->addFieldMapping($property->getName(), ['type' => 'complex', 'mapping' => $propertyMapping, 'field' => $this->getContentField($property)]); } else { $this->mapProperty($property, $indexMeta); } } if ($class->isSubclassOf(ExtensionBehavior::class)) { $extensions = $this->extensionManager->getExtensions($structure->getName()); foreach ($extensions as $extension) { foreach ($extension->getFieldMapping() as $name => $mapping) { $indexMeta->addFieldMapping($name, $mapping); } } } if ($class->isSubclassOf(ResourceSegmentBehavior::class)) { $indexMeta->setUrlField($this->factory->createMetadataField('resourceSegment')); } if (!$indexMeta->getTitleField()) { if ($class->isSubclassOf(TitleBehavior::class)) { $indexMeta->setTitleField($this->factory->createMetadataProperty('title')); $indexMeta->addFieldMapping('title', ['type' => 'string', 'field' => $this->factory->createMetadataField('title'), 'aggregate' => true, 'indexed' => false]); } } if ($class->isSubclassOf(WebspaceBehavior::class)) { // index the webspace $indexMeta->addFieldMapping('webspace_key', ['type' => 'string', 'field' => $this->factory->createMetadataProperty('webspaceName')]); } if ($class->isSubclassOf(WorkflowStageBehavior::class)) { $indexMeta->addFieldMapping('state', ['type' => 'string', 'field' => $this->factory->createMetadataExpression('object.getWorkflowStage() == 1 ? "test" : "published"')]); } $indexMeta->addFieldMapping(self::FIELD_STRUCTURE_TYPE, ['type' => 'string', 'stored' => true, 'indexed' => false, 'field' => $this->factory->createMetadataProperty('structureType')]); $classMetadata->addIndexMetadata('_default', $indexMeta); return $classMetadata; }