Esempio n. 1
0
 /**
  * @param ClassMetadata $metadata
  * @param bool          $force
  */
 protected function loadEntityConfigs(ClassMetadata $metadata, $force)
 {
     if ($this->hasEntityConfigs($metadata)) {
         $className = $metadata->getName();
         if ($this->configManager->hasConfig($className)) {
             $this->logger->info(sprintf('Update config for "%s" entity.', $className));
             $this->configManager->updateConfigEntityModel($className, $force);
         } else {
             $this->logger->info(sprintf('Create config for "%s" entity.', $className));
             $this->configManager->createConfigEntityModel($className);
         }
         $fieldNames = $metadata->getFieldNames();
         foreach ($fieldNames as $fieldName) {
             if ($this->hasFieldConfigs($metadata, $fieldName)) {
                 $fieldType = $metadata->getTypeOfField($fieldName);
                 $this->loadFieldConfigs($className, $fieldName, $fieldType, $force);
             }
         }
         $associationNames = $metadata->getAssociationNames();
         foreach ($associationNames as $associationName) {
             if ($this->hasAssociationConfigs($metadata, $associationName)) {
                 $associationType = $metadata->isSingleValuedAssociation($associationName) ? 'ref-one' : 'ref-many';
                 $this->loadFieldConfigs($className, $associationName, $associationType, $force);
             }
         }
     }
 }
Esempio n. 2
0
 public function testCreateConfigEntityModel()
 {
     $configId = new EntityConfigId('entity', self::ENTITY_CLASS);
     $model = $this->createEntityConfigModel(self::ENTITY_CLASS);
     $this->modelManager->expects($this->once())->method('findEntityModel')->with(self::ENTITY_CLASS)->will($this->returnValue(null));
     $this->modelManager->expects($this->once())->method('createEntityModel')->with(self::ENTITY_CLASS, ConfigModelManager::MODE_DEFAULT)->will($this->returnValue($model));
     $metadata = new EntityMetadata(self::ENTITY_CLASS);
     $metadata->defaultValues['entity'] = ['translatable' => 'labelVal', 'other' => 'otherVal'];
     $this->metadataFactory->expects($this->once())->method('getMetadataForClass')->with(self::ENTITY_CLASS)->will($this->returnValue($metadata));
     $propertyConfigContainer = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\PropertyConfigContainer')->disableOriginalConstructor()->getMock();
     $propertyConfigContainer->expects($this->once())->method('getDefaultValues')->with(PropertyConfigContainer::TYPE_ENTITY)->will($this->returnValue(['translatable10' => 'labelVal10', 'other10' => 'otherVal10']));
     $propertyConfigContainer->expects($this->once())->method('getTranslatableValues')->with(PropertyConfigContainer::TYPE_ENTITY)->will($this->returnValue(['translatable', 'translatable10', 'auto_generated']));
     $this->configProvider->expects($this->any())->method('getPropertyConfig')->will($this->returnValue($propertyConfigContainer));
     $this->eventDispatcher->expects($this->once())->method('dispatch')->with(Events::NEW_ENTITY_CONFIG, new EntityConfigEvent(self::ENTITY_CLASS, $this->configManager));
     $config = new Config($configId);
     $config->set('other', 'otherVal');
     $config->set('translatable', 'labelVal');
     $config->set('other10', 'otherVal10');
     $config->set('translatable10', 'labelVal10');
     $config->set('auto_generated', 'oro.entityconfig.tests.unit.fixture.demoentity.entity_auto_generated');
     $result = $this->configManager->createConfigEntityModel(self::ENTITY_CLASS);
     $this->assertEquals($model, $result);
     $this->assertEquals([$config], $this->configManager->getUpdateConfig());
     // test that a config for a created model is stored in a local cache
     $result = $this->configManager->getConfig($configId);
     $this->assertEquals($config, $result);
 }
 /**
  * @param string $className
  * @param string $mode
  * @param array  $configs
  * @throws \LogicException
  */
 protected function createEntityModel($className, $mode, array $configs)
 {
     if (!ExtendHelper::isCustomEntity($className)) {
         throw new \LogicException(sprintf('A new model can be created for custom entity only. Class: %s.', $className));
     }
     $this->logger->info(sprintf('Create entity "%s".', $className), ['configs' => $configs]);
     $this->configManager->createConfigEntityModel($className, $mode);
     $this->updateConfigs($configs, $className);
     $extendConfigProvider = $this->configManager->getProvider('extend');
     $extendConfig = $extendConfigProvider->getConfig($className);
     $extendConfig->set('state', ExtendScope::STATE_NEW);
     $this->configManager->persist($extendConfig);
 }
 /**
  * @param $entityName
  * @param $entityConfig
  * @return void
  */
 protected function createEntityModel($entityName, $entityConfig)
 {
     $mode = isset($entityConfig['mode']) ? $entityConfig['mode'] : ConfigModelManager::MODE_DEFAULT;
     $this->configManager->createConfigEntityModel($entityName, $mode);
     if (class_exists($entityName)) {
         $doctrineMetadata = $this->configManager->getEntityManager()->getClassMetadata($entityName);
         foreach ($doctrineMetadata->getFieldNames() as $fieldName) {
             $type = $doctrineMetadata->getTypeOfField($fieldName);
             $this->configManager->createConfigFieldModel($doctrineMetadata->getName(), $fieldName, $type);
         }
         foreach ($doctrineMetadata->getAssociationNames() as $fieldName) {
             $type = $doctrineMetadata->isSingleValuedAssociation($fieldName) ? 'ref-one' : 'ref-many';
             $this->configManager->createConfigFieldModel($doctrineMetadata->getName(), $fieldName, $type);
         }
     }
 }
Esempio n. 5
0
 public function testCreateConfigEntityModel()
 {
     $configId = new EntityConfigId('entity', self::ENTITY_CLASS);
     $model = $this->createEntityConfigModel(self::ENTITY_CLASS);
     $metadata = $this->getEntityMetadata(self::ENTITY_CLASS, ['translatable' => 'labelVal', 'other' => 'otherVal']);
     $this->modelManager->expects($this->once())->method('findEntityModel')->with(self::ENTITY_CLASS)->willReturn(null);
     $this->modelManager->expects($this->once())->method('createEntityModel')->with(self::ENTITY_CLASS, ConfigModelManager::MODE_DEFAULT)->willReturn($model);
     $this->metadataFactory->expects($this->once())->method('getMetadataForClass')->with(self::ENTITY_CLASS)->willReturn($metadata);
     $propertyConfigContainer = $this->getPropertyConfigContainerMock();
     $propertyConfigContainer->expects($this->once())->method('getDefaultValues')->with(PropertyConfigContainer::TYPE_ENTITY)->willReturn(['translatable10' => 'labelVal10', 'other10' => 'otherVal10']);
     $propertyConfigContainer->expects($this->once())->method('getTranslatableValues')->with(PropertyConfigContainer::TYPE_ENTITY)->willReturn(['translatable', 'translatable10', 'auto_generated']);
     $this->configProvider->expects($this->any())->method('getPropertyConfig')->willReturn($propertyConfigContainer);
     $this->eventDispatcher->expects($this->once())->method('dispatch')->with(Events::NEW_ENTITY_CONFIG, new EntityConfigEvent(self::ENTITY_CLASS, $this->configManager));
     $config = $this->getConfig($configId, ['other' => 'otherVal', 'translatable' => 'labelVal', 'other10' => 'otherVal10', 'translatable10' => 'labelVal10', 'auto_generated' => 'oro.entityconfig.tests.unit.fixture.demoentity.entity_auto_generated']);
     $this->configCache->expects($this->once())->method('saveConfig')->with($config, true);
     $result = $this->configManager->createConfigEntityModel(self::ENTITY_CLASS);
     $this->assertEquals($model, $result);
     $this->assertEquals([$config], $this->configManager->getUpdateConfig());
 }
Esempio n. 6
0
 /**
  * @dataProvider createConfigEntityModelProvider
  */
 public function testCreateConfigEntityModel($mode, $hasMetadata, $metadataMode, $expectedMode, $cachedEntities, $expectedSavedCachedEntities)
 {
     $configId = new EntityConfigId('entity', self::ENTITY_CLASS);
     $model = $this->createEntityConfigModel(self::ENTITY_CLASS, $expectedMode);
     $metadata = null;
     if ($hasMetadata) {
         $metadata = $this->getEntityMetadata(self::ENTITY_CLASS, ['translatable' => 'labelVal', 'other' => 'otherVal']);
         if (null !== $metadataMode) {
             $metadata->mode = $metadataMode;
         }
     }
     $this->modelManager->expects($this->once())->method('findEntityModel')->with(self::ENTITY_CLASS)->willReturn(null);
     $this->modelManager->expects($this->once())->method('createEntityModel')->with(self::ENTITY_CLASS, $expectedMode)->willReturn($model);
     $this->metadataFactory->expects($this->once())->method('getMetadataForClass')->with(self::ENTITY_CLASS)->willReturn($metadata);
     $propertyConfigContainer = $this->getPropertyConfigContainerMock();
     $propertyConfigContainer->expects($this->once())->method('getDefaultValues')->with(PropertyConfigContainer::TYPE_ENTITY)->willReturn(['translatable10' => 'labelVal10', 'other10' => 'otherVal10']);
     $propertyConfigContainer->expects($this->once())->method('getTranslatableValues')->with(PropertyConfigContainer::TYPE_ENTITY)->willReturn(['translatable', 'translatable10', 'auto_generated']);
     $this->configProvider->expects($this->any())->method('getPropertyConfig')->willReturn($propertyConfigContainer);
     $this->eventDispatcher->expects($this->once())->method('dispatch')->with(Events::CREATE_ENTITY, new EntityConfigEvent(self::ENTITY_CLASS, $this->configManager));
     $config = $this->getConfig($configId, ['translatable' => 'oro.entityconfig.tests.unit.fixture.demoentity.entity_translatable', 'other10' => 'otherVal10', 'translatable10' => 'labelVal10', 'auto_generated' => 'oro.entityconfig.tests.unit.fixture.demoentity.entity_auto_generated']);
     if ($metadata) {
         $config->set('other', 'otherVal');
         $config->set('translatable', 'labelVal');
     }
     $this->configCache->expects($this->once())->method('saveConfig')->with($config, true);
     $this->configCache->expects($this->once())->method('saveConfigurable')->with(true, self::ENTITY_CLASS, null, true);
     $this->configCache->expects($this->once())->method('getEntities')->with(true)->willReturn($cachedEntities);
     if (null === $expectedSavedCachedEntities) {
         $this->configCache->expects($this->never())->method('saveEntities');
     } else {
         $this->configCache->expects($this->once())->method('saveEntities')->with($expectedSavedCachedEntities, true);
     }
     $result = $this->configManager->createConfigEntityModel(self::ENTITY_CLASS, $mode);
     $this->assertEquals($model, $result);
     $this->assertEquals([$config], $this->configManager->getUpdateConfig());
 }
 /**
  * @param string    $enumValueClassName The full class name of an entity is used to store enum values
  * @param string    $enumCode           The unique identifier of an enum
  * @param bool      $isMultiple         Indicates whether several options can be selected for this enum
  *                                      or it supports only one selected option
  * @param bool|null $isPublic           Indicates whether this enum can be used by any entity or
  *                                      it is designed to use in one entity only
  *                                      NULL means unspecified. In this case this attribute will not be
  *                                      changed for existing enum entity and will be set to FALSE
  *                                      for new enum entity
  */
 protected function createEnumValueConfigEntityModel($enumValueClassName, $enumCode, $isMultiple, $isPublic)
 {
     if ($this->configManager->hasConfigEntityModel($enumValueClassName)) {
         if (null !== $isPublic) {
             $this->relationBuilder->updateEntityConfigs($enumValueClassName, ['enum' => ['public' => $isPublic]]);
         }
         return;
     }
     if (null === $isPublic) {
         $isPublic = false;
     }
     // create entity
     $this->configManager->createConfigEntityModel($enumValueClassName, ConfigModelManager::MODE_HIDDEN);
     $this->relationBuilder->updateEntityConfigs($enumValueClassName, ['entity' => ['label' => ExtendHelper::getEnumTranslationKey('label', $enumCode), 'plural_label' => ExtendHelper::getEnumTranslationKey('plural_label', $enumCode), 'description' => ExtendHelper::getEnumTranslationKey('description', $enumCode)], 'extend' => ['owner' => ExtendScope::OWNER_SYSTEM, 'is_extend' => true, 'table' => $this->nameGenerator->generateEnumTableName($enumCode, true), 'inherit' => ExtendHelper::BASE_ENUM_VALUE_CLASS], 'enum' => ['code' => $enumCode, 'public' => $isPublic, 'multiple' => $isMultiple]]);
     // create fields
     $this->configManager->createConfigFieldModel($enumValueClassName, 'id', 'string');
     $this->relationBuilder->updateFieldConfigs($enumValueClassName, 'id', ['entity' => ['label' => ExtendHelper::getEnumTranslationKey('label', $enumCode, 'id'), 'description' => ExtendHelper::getEnumTranslationKey('description', $enumCode, 'id')], 'importexport' => ['identity' => true]]);
     $this->configManager->createConfigFieldModel($enumValueClassName, 'name', 'string');
     $this->relationBuilder->updateFieldConfigs($enumValueClassName, 'name', ['entity' => ['label' => ExtendHelper::getEnumTranslationKey('label', $enumCode, 'name'), 'description' => ExtendHelper::getEnumTranslationKey('description', $enumCode, 'name')], 'datagrid' => ['is_visible' => false]]);
     $this->configManager->createConfigFieldModel($enumValueClassName, 'priority', 'integer');
     $this->relationBuilder->updateFieldConfigs($enumValueClassName, 'priority', ['entity' => ['label' => ExtendHelper::getEnumTranslationKey('label', $enumCode, 'priority'), 'description' => ExtendHelper::getEnumTranslationKey('description', $enumCode, 'priority')], 'datagrid' => ['is_visible' => false]]);
     $this->configManager->createConfigFieldModel($enumValueClassName, 'default', 'boolean');
     $this->relationBuilder->updateFieldConfigs($enumValueClassName, 'default', ['entity' => ['label' => ExtendHelper::getEnumTranslationKey('label', $enumCode, 'default'), 'description' => ExtendHelper::getEnumTranslationKey('description', $enumCode, 'default')], 'datagrid' => ['is_visible' => false]]);
 }