TODO: resource, cacheLifetime and view should be removed. They should instead be options.
Inheritance: extends ItemMetadata
Example #1
0
 /**
  * It should get a legacy structure bridge.
  */
 public function testGetStructure()
 {
     $structureType = 'content';
     $documentType = 'page';
     $this->factory->getStructureMetadata($documentType, $structureType)->willReturn($this->structure->reveal());
     $bridge = $this->structureManager->getStructure($structureType, $documentType);
     $this->assertInstanceOf(StructureBridge::class, $bridge);
 }
 /**
  * It returns all structures that are available.
  */
 public function testGetStructures()
 {
     $this->loader->load($this->mappingFile, 'page')->willReturn($this->structure->reveal());
     $this->loader->load($this->mappingFile, 'page')->shouldBeCalledTimes(1);
     $structures = $this->factory->getStructures('page');
     $this->assertEquals($this->structure->reveal(), $structures[0]);
 }
Example #3
0
 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';
     $categoryName = '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'];
         $categoryName = $mapping['category'];
     }
     $indexMeta->setCategoryName($categoryName);
     $indexMeta->setIndexName($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(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;
 }
Example #4
0
 public function bind($data, $clearMissing = true)
 {
     foreach ($this->structureMetadata->getProperties() as $childName => $child) {
         if (false === $clearMissing && !isset($data[$childName])) {
             continue;
         }
         $value = isset($data[$childName]) ? $data[$childName] : null;
         $property = $this->getProperty($childName);
         $property->setValue($value);
     }
 }
 /**
  * It returns all structures that are available.
  */
 public function testGetStructures()
 {
     $this->loader->load($this->somethingMappingFile, 'page')->willReturn($this->somethingStructure->reveal());
     $this->loader->load($this->defaultMappingFile, 'page')->willReturn($this->defaultStructure->reveal());
     $this->loader->load($this->somethingMappingFile, 'page')->shouldBeCalledTimes(1);
     $this->loader->load($this->defaultMappingFile, 'page')->shouldBeCalledTimes(1);
     $structures = $this->factory->getStructures('page');
     $this->assertCount(3, $structures);
     $this->assertEquals($this->defaultStructure->reveal(), $structures[0]);
     $this->assertEquals($this->somethingStructure->reveal(), $structures[1]);
     $this->assertEquals($this->defaultStructure->reveal(), $structures[2]);
 }
Example #6
0
 /**
  * Adds the properties of the structure to the serialization.
  *
  * @param StructureBehavior $document
  * @param VisitorInterface $visitor
  */
 private function addStructureProperties(StructureMetadata $structureMetadata, StructureBehavior $document, VisitorInterface $visitor)
 {
     /** @var ManagedStructure $structure */
     $structure = $document->getStructure();
     $data = $structure->toArray();
     foreach ($structureMetadata->getProperties() as $name => $property) {
         if ($name === 'title' || !array_key_exists($name, $data) || $property->hasTag('sulu.rlp')) {
             continue;
         }
         $visitor->addData($name, $data[$name]);
     }
 }
Example #7
0
 private function doGetProperty($name, $contentTypeName, $locale)
 {
     $this->propertyMetadata->getType()->willReturn($contentTypeName);
     $this->structureMetadata->getProperty($name)->willReturn($this->propertyMetadata);
     $this->contentTypeManager->get($contentTypeName)->willReturn($this->contentType->reveal());
     if ($locale) {
         $this->propertyFactory->createTranslatedProperty($this->propertyMetadata->reveal(), $locale, Argument::type(StructureBridge::class))->willReturn($this->legacyProperty->reveal());
     } else {
         $this->propertyFactory->createProperty($this->propertyMetadata->reveal(), $locale)->willReturn($this->legacyProperty->reveal());
     }
     $this->contentType->read($this->node->reveal(), $this->legacyProperty->reveal(), null, null, null)->shouldBeCalledTimes(1);
     $property = $this->structure->getProperty($name);
     $this->assertInstanceOf(PropertyValue::class, $property);
     $this->assertEquals($name, $property->getName());
 }
 /**
  * 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());
 }
Example #9
0
 /**
  * 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);
         }
     }
 }
Example #10
0
 /**
  * {@inheritdoc}
  */
 public function getLocalizedTitle($languageCode)
 {
     return $this->structure->getTitle($languageCode);
 }