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


PHP ConfigManager::persist方法代码示例

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


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

示例1: preUpdate

 /**
  * {@inheritdoc}
  */
 public function preUpdate()
 {
     $ownershipConfigProvider = $this->configManager->getProvider('ownership');
     $extendConfigProvider = $this->configManager->getProvider('extend');
     $entityConfigs = $extendConfigProvider->getConfigs();
     foreach ($entityConfigs as $entityConfig) {
         if (!$entityConfig->is('owner', ExtendScope::OWNER_CUSTOM)) {
             continue;
         }
         if (!$ownershipConfigProvider->hasConfig($entityConfig->getId()->getClassName())) {
             continue;
         }
         $ownershipConfig = $ownershipConfigProvider->getConfig($entityConfig->getId()->getClassName());
         $ownerType = $ownershipConfig->get('owner_type');
         if (empty($ownerType)) {
             continue;
         }
         $this->createOwnerRelation($entityConfig, $this->getOwnerTargetEntityClassName($ownerType), $ownershipConfig->get('owner_field_name'));
         if (in_array($ownerType, [OwnershipType::OWNER_TYPE_USER, OwnershipType::OWNER_TYPE_BUSINESS_UNIT])) {
             if (!$ownershipConfig->has('organization_field_name')) {
                 $ownershipConfig->set('organization_field_name', 'organization');
                 $ownershipConfig->set('organization_column_name', 'organization_id');
                 $this->configManager->persist($ownershipConfig);
                 $organizationFieldName = 'organization';
             } else {
                 $organizationFieldName = $ownershipConfig->get('organization_field_name');
             }
             $this->createOwnerRelation($entityConfig, $this->ownershipMetadataProvider->getOrganizationClass(), $organizationFieldName);
         }
     }
 }
开发者ID:ramunasd,项目名称:platform,代码行数:34,代码来源:OwnershipEntityConfigDumperExtension.php

示例2: testFlush

 public function testFlush()
 {
     $model = new EntityConfigModel(self::ENTITY_CLASS);
     $entityConfigId = new EntityConfigId('entity', self::ENTITY_CLASS);
     $entityConfig = new Config($entityConfigId);
     $entityConfig->set('icon', 'test_icon');
     $entityConfig->set('label', 'test_label');
     $entityPropertyConfig = new PropertyConfigContainer(['entity' => ['items' => ['icon' => [], 'label' => ['options' => ['indexed' => true]]]]]);
     $this->entityConfigProvider->expects($this->once())->method('getPropertyConfig')->will($this->returnValue($entityPropertyConfig));
     $testConfigId = new EntityConfigId('test', self::ENTITY_CLASS);
     $testConfig = new Config($testConfigId);
     $testConfig->set('attr1', 'test_attr1');
     $testPropertyConfig = new PropertyConfigContainer(['entity' => ['items' => ['attr1' => []]]]);
     $this->testConfigProvider->expects($this->once())->method('getPropertyConfig')->will($this->returnValue($testPropertyConfig));
     $this->modelManager->expects($this->once())->method('getEntityModel')->with($entityConfigId->getClassName())->will($this->returnValue($model));
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->modelManager->expects($this->any())->method('getEntityManager')->will($this->returnValue($em));
     $this->setFlushExpectations($em, [$model]);
     $this->eventDispatcher->expects($this->at(2))->method('dispatch')->with(Events::PRE_FLUSH, new PreFlushConfigEvent(['entity' => $entityConfig, 'test' => $testConfig], $this->configManager));
     $this->configManager->persist($entityConfig);
     $this->configManager->persist($testConfig);
     $this->configManager->flush();
     $this->assertEquals(['icon' => 'test_icon', 'label' => 'test_label'], $model->toArray('entity'));
     $this->assertEquals(['attr1' => 'test_attr1'], $model->toArray('test'));
     $this->assertCount(3, $model->getIndexedValues());
     $this->assertEquals('entity_config', $model->getIndexedValues()[0]->getScope());
     $this->assertEquals('module_name', $model->getIndexedValues()[0]->getCode());
     $this->assertEquals('entity_config', $model->getIndexedValues()[1]->getScope());
     $this->assertEquals('entity_name', $model->getIndexedValues()[1]->getCode());
     $this->assertEquals('entity', $model->getIndexedValues()[2]->getScope());
     $this->assertEquals('label', $model->getIndexedValues()[2]->getCode());
 }
开发者ID:Maksold,项目名称:platform,代码行数:32,代码来源:FlushConfigManagerTest.php

示例3: postSubmit

 /**
  * POST_SUBMIT event handler
  *
  * @param FormEvent $event
  */
 public function postSubmit(FormEvent $event)
 {
     $form = $event->getForm();
     $options = $form->getConfig()->getOptions();
     /** @var ConfigIdInterface $configId */
     $configId = $options['config_id'];
     if (!$form->isValid()) {
         return;
     }
     // change the entity state to "Requires update" if the attribute has "require_schema_update" option
     // and the value of the attribute was changed
     $configProvider = $this->configManager->getProvider($configId->getScope());
     if ($configProvider->getPropertyConfig()->isSchemaUpdateRequired($form->getName(), $configId)) {
         $newVal = $form->getData();
         $oldVal = $this->configManager->getConfig($configId)->get($form->getName());
         if ($this->isSchemaUpdateRequired($newVal, $oldVal)) {
             $extendConfigProvider = $this->configManager->getProvider('extend');
             $extendConfig = $extendConfigProvider->getConfig($configId->getClassName());
             if ($extendConfig->is('state', ExtendScope::STATE_ACTIVE)) {
                 $extendConfig->set('state', ExtendScope::STATE_UPDATE);
                 $this->configManager->persist($extendConfig);
             }
         }
     }
 }
开发者ID:Maksold,项目名称:platform,代码行数:30,代码来源:AbstractConfigType.php

示例4: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addEventListener(FormEvents::POST_SUBMIT, function () use($options) {
         /** @var FieldConfigId $fieldConfigId */
         $fieldConfigId = $options['config_id'];
         $entityConfig = $this->configManager->getProvider('extend')->getConfig($fieldConfigId->getClassName());
         if ($entityConfig->is('state', ExtendScope::STATE_ACTIVE) && !$this->hasRelation($entityConfig, $this->getRelationKey($fieldConfigId))) {
             $entityConfig->set('state', ExtendScope::STATE_UPDATE);
             $this->configManager->persist($entityConfig);
             $this->configManager->flush();
         }
     });
 }
开发者ID:Maksold,项目名称:platform,代码行数:16,代码来源:FileConfigType.php

示例5: updateStateValues

 /**
  * @param ConfigInterface $entityConfig
  * @param ConfigProvider  $configProvider
  */
 protected function updateStateValues(ConfigInterface $entityConfig, ConfigProvider $configProvider)
 {
     if ($entityConfig->is('state', ExtendScope::STATE_DELETE)) {
         // mark entity as deleted
         if (!$entityConfig->is('is_deleted')) {
             $entityConfig->set('is_deleted', true);
             $this->configManager->persist($entityConfig);
         }
         // mark all fields as deleted
         $fieldConfigs = $configProvider->getConfigs($entityConfig->getId()->getClassName(), true);
         foreach ($fieldConfigs as $fieldConfig) {
             if (!$fieldConfig->is('is_deleted')) {
                 $fieldConfig->set('is_deleted', true);
                 $this->configManager->persist($fieldConfig);
             }
         }
     } elseif (!$entityConfig->is('state', ExtendScope::STATE_ACTIVE)) {
         $hasNotActiveFields = false;
         $fieldConfigs = $configProvider->getConfigs($entityConfig->getId()->getClassName(), true);
         foreach ($fieldConfigs as $fieldConfig) {
             if (!$fieldConfig->in('state', [ExtendScope::STATE_ACTIVE, ExtendScope::STATE_DELETE])) {
                 $hasNotActiveFields = true;
                 break;
             }
         }
         // Set entity state to active if all fields are active or deleted
         if (!$hasNotActiveFields) {
             $entityConfig->set('state', ExtendScope::STATE_ACTIVE);
             $this->configManager->persist($entityConfig);
         }
     }
 }
开发者ID:Maksold,项目名称:platform,代码行数:36,代码来源:ExtendConfigDumper.php

示例6: updateConfigs

 /**
  * @param array       $configs
  * @param string      $className
  * @param string|null $fieldName
  * @return bool TRUE is any changes were made
  */
 protected function updateConfigs(array $configs, $className, $fieldName = null)
 {
     $result = false;
     foreach ($configs as $scope => $values) {
         $config = $this->configManager->getProvider($scope)->getConfig($className, $fieldName);
         $hasChanges = false;
         foreach ($values as $key => $value) {
             $path = explode('.', $key);
             $pathLength = count($path);
             if ($pathLength > 1) {
                 $code = array_shift($path);
                 $existingVal = (array) $config->get($code);
                 $current =& $existingVal;
                 foreach ($path as $name) {
                     if (!array_key_exists($name, $current)) {
                         $current[$name] = [];
                     }
                     $current =& $current[$name];
                 }
                 $current = $this->isAppend($scope, $key, $className, $fieldName) ? array_merge($current, (array) $value) : $value;
                 $config->set($code, $existingVal);
             } elseif ($this->isAppend($scope, $key, $className, $fieldName)) {
                 $config->set($key, array_merge((array) $config->get($key), (array) $value));
             } else {
                 $config->set($key, $value);
             }
             $hasChanges = true;
         }
         if ($hasChanges) {
             $this->configManager->persist($config);
             $result = true;
         }
     }
     return $result;
 }
开发者ID:startupz,项目名称:platform-1,代码行数:41,代码来源:ExtendConfigProcessor.php

示例7: setRelationKeyToFieldConfig

 /**
  * @param ConfigInterface $fieldConfig
  */
 protected function setRelationKeyToFieldConfig(ConfigInterface $fieldConfig)
 {
     /** @var FieldConfigId $fieldConfigId */
     $fieldConfigId = $fieldConfig->getId();
     $relationKey = ExtendHelper::buildRelationKey($fieldConfigId->getClassName(), $fieldConfigId->getFieldName(), $this->fieldTypeHelper->getUnderlyingType($fieldConfigId->getFieldType()), $fieldConfig->get('target_entity'));
     $fieldConfig->set('relation_key', $relationKey);
     $this->configManager->persist($fieldConfig);
 }
开发者ID:paulstoica,项目名称:platform,代码行数:11,代码来源:RelationEntityConfigDumperExtension.php

示例8: preUpdate

 /**
  * {@inheritdoc}
  */
 public function preUpdate()
 {
     $targetEntityConfigs = $this->configManager->getProvider('extend')->getConfigs();
     foreach ($targetEntityConfigs as $targetEntityConfig) {
         if ($targetEntityConfig->is('is_extend')) {
             $indices = $targetEntityConfig->has('index') ? $targetEntityConfig->get('index') : [];
             if ($this->updateIndices($indices, $targetEntityConfig->getId()->getClassName())) {
                 if (empty($indices)) {
                     $targetEntityConfig->remove('index');
                 } else {
                     $targetEntityConfig->set('index', $indices);
                 }
                 $this->configManager->persist($targetEntityConfig);
             }
         }
     }
 }
开发者ID:Maksold,项目名称:platform,代码行数:20,代码来源:IndexEntityConfigDumperExtension.php

示例9: generateWorkflowFields

 /**
  * @param string $entityClass
  * @throws WorkflowException
  */
 public function generateWorkflowFields($entityClass)
 {
     if ($this->entityConnector->isWorkflowAware($entityClass)) {
         return;
     }
     $extendConfigProvider = $this->configManager->getProvider('extend');
     $entityConfig = $extendConfigProvider->getConfig($entityClass);
     if (!$entityConfig || !$entityConfig->is('is_extend')) {
         throw new WorkflowException(sprintf('Class %s can not be extended', $entityClass));
     }
     $workflowItemClass = 'Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowItem';
     $workflowStepClass = 'Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowStep';
     // add fields
     $hasWorkflowItemField = $this->configManager->hasConfig($entityClass, self::PROPERTY_WORKFLOW_ITEM);
     if (!$hasWorkflowItemField) {
         $this->addRelationField($entityClass, self::PROPERTY_WORKFLOW_ITEM, ConfigHelper::getTranslationKey('entity', 'label', $workflowItemClass, 'related_entity'), ConfigHelper::getTranslationKey('entity', 'description', $workflowItemClass, 'related_entity'), $workflowItemClass, 'id');
     }
     $hasWorkflowStepField = $this->configManager->hasConfig($entityClass, self::PROPERTY_WORKFLOW_STEP);
     if (!$hasWorkflowStepField) {
         $this->addRelationField($entityClass, self::PROPERTY_WORKFLOW_STEP, ConfigHelper::getTranslationKey('entity', 'label', $workflowStepClass, 'related_entity'), ConfigHelper::getTranslationKey('entity', 'description', $workflowStepClass, 'related_entity'), $workflowStepClass, 'label');
     }
     // update entity config
     $entityConfig->set('state', ExtendScope::STATE_UPDATE);
     $entityConfig->set('upgradeable', true);
     $this->configManager->persist($entityConfig);
     $this->configManager->flush();
     // update database
     $this->entityProcessor->updateDatabase();
     // make fields hidden
     // TODO: Fields can be hidden only after schema update due to a bug in DoctrineSubscriber
     // TODO: Should be fixed in scope of https://magecore.atlassian.net/browse/BAP-3621
     // TODO: If make fields hidden then these fields will be created only for the first extended entity
     // TODO: Should be fixed in scope of https://magecore.atlassian.net/browse/BAP-3632
     /*
     if (!$hasWorkflowItemField) {
         $this->hideRelationField($entityClass, self::PROPERTY_WORKFLOW_ITEM);
     }
     if (!$hasWorkflowStepField) {
         $this->hideRelationField($entityClass, self::PROPERTY_WORKFLOW_STEP);
     }
     $this->configManager->flush();
     */
 }
开发者ID:xamin123,项目名称:platform,代码行数:47,代码来源:FieldGenerator.php

示例10: testPersistAndMerge

 public function testPersistAndMerge()
 {
     $configId = new EntityConfigId('entity', self::ENTITY_CLASS);
     $config1 = $this->getConfig($configId, ['val1' => '1', 'val2' => '1']);
     $config2 = $this->getConfig($configId, ['val2' => '2_new', 'val3' => '3']);
     $expectedConfig = $this->getConfig($configId, ['val1' => '1', 'val2' => '2_new', 'val3' => '3']);
     $this->configManager->persist($config1);
     $this->configManager->merge($config2);
     $toBePersistedConfigs = $this->configManager->getUpdateConfig();
     $this->assertEquals([$expectedConfig], $toBePersistedConfigs);
 }
开发者ID:Maksold,项目名称:platform,代码行数:11,代码来源:ConfigManagerTest.php

示例11: setExtendData

 /**
  * @param string $className
  * @param string $fieldName
  * @param string $state
  */
 protected function setExtendData($className, $fieldName, $state)
 {
     $provider = $this->configManager->getProvider('extend');
     if (!$provider) {
         return;
     }
     $config = $provider->getConfig($className, $fieldName);
     $data = ['owner' => ExtendScope::OWNER_CUSTOM, 'state' => $config->is('state', ExtendScope::STATE_NEW) ? ExtendScope::STATE_NEW : $state, 'origin' => ExtendScope::ORIGIN_CUSTOM, 'is_extend' => true, 'is_deleted' => false, 'is_serialized' => false];
     foreach ($data as $code => $value) {
         $config->set($code, $value);
     }
     $this->configManager->persist($config);
 }
开发者ID:Maksold,项目名称:platform,代码行数:18,代码来源:EntityFieldWriter.php

示例12: postSubmit

 /**
  * @param FormEvent $event
  */
 public function postSubmit(FormEvent $event)
 {
     $options = $event->getForm()->getConfig()->getOptions();
     $configModel = $options['config_model'];
     if ($configModel instanceof FieldConfigModel) {
         $className = $configModel->getEntity()->getClassName();
         $fieldName = $configModel->getFieldName();
     } else {
         $fieldName = null;
         $className = $configModel->getClassName();
     }
     $data = $event->getData();
     foreach ($this->configManager->getProviders() as $provider) {
         if (isset($data[$provider->getScope()])) {
             $config = $provider->getConfig($className, $fieldName);
             $config->setValues($data[$provider->getScope()]);
             $this->configManager->persist($config);
         }
     }
     if ($event->getForm()->isValid()) {
         $this->configManager->flush();
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:26,代码来源:ConfigSubscriber.php

示例13: postSubmit

 /**
  * @param FormEvent $event
  */
 public function postSubmit(FormEvent $event)
 {
     $form = $event->getForm();
     $configModel = $form->getConfig()->getOption('config_model');
     $data = $event->getData();
     $labelsToBeUpdated = [];
     foreach ($this->configManager->getProviders() as $provider) {
         $scope = $provider->getScope();
         if (isset($data[$scope])) {
             $configId = $this->configManager->getConfigIdByModel($configModel, $scope);
             $config = $provider->getConfigById($configId);
             $translatable = $provider->getPropertyConfig()->getTranslatableValues($configId);
             foreach ($data[$scope] as $code => $value) {
                 if (in_array($code, $translatable, true)) {
                     // check if a label text was changed
                     $labelKey = $config->get($code);
                     if (!$configModel->getId()) {
                         $labelsToBeUpdated[$labelKey] = $value;
                     } elseif ($value != $this->translator->trans($labelKey)) {
                         $labelsToBeUpdated[$labelKey] = $value;
                     }
                     // replace label text with label name in $value variable
                     $value = $config->get($code);
                 }
                 $config->set($code, $value);
             }
             $this->configManager->persist($config);
         }
     }
     if ($form->isValid()) {
         // update changed labels if any
         if (!empty($labelsToBeUpdated)) {
             /** @var EntityManager $translationEm */
             $translationEm = $this->doctrine->getManagerForClass(Translation::ENTITY_NAME);
             /** @var TranslationRepository $translationRepo */
             $translationRepo = $translationEm->getRepository(Translation::ENTITY_NAME);
             $values = [];
             $locale = $this->translator->getLocale();
             foreach ($labelsToBeUpdated as $labelKey => $labelText) {
                 // save into translation table
                 $values[] = $translationRepo->saveValue($labelKey, $labelText, $locale, TranslationRepository::DEFAULT_DOMAIN, Translation::SCOPE_UI);
             }
             // mark translation cache dirty
             $this->dbTranslationMetadataCache->updateTimestamp($locale);
             $translationEm->flush($values);
         }
         $this->configManager->flush();
     }
 }
开发者ID:Maksold,项目名称:platform,代码行数:52,代码来源:ConfigSubscriber.php

示例14: updateEnumFieldConfig

 /**
  * @param ConfigInterface $enumFieldConfig
  *
  * @return bool
  */
 protected function updateEnumFieldConfig(ConfigInterface $enumFieldConfig)
 {
     $hasChanges = false;
     $attributes = ['enum_name', 'enum_locale', 'enum_public', 'enum_options'];
     foreach ($attributes as $code) {
         if ($enumFieldConfig->get($code) !== null) {
             $enumFieldConfig->remove($code);
             $hasChanges = true;
         }
     }
     if ($hasChanges) {
         $this->configManager->persist($enumFieldConfig);
     }
     return $hasChanges;
 }
开发者ID:sagikazarmark,项目名称:platform,代码行数:20,代码来源:EnumSynchronizer.php

示例15: updateConfigs

 /**
  * @param string $className
  * @param array  $options
  * @param string $fieldName
  */
 protected function updateConfigs($className, $fieldName, $options)
 {
     foreach ($options as $scope => $scopeValues) {
         $config = $this->configManager->getProvider($scope)->getConfig($className, $fieldName);
         $hasChanges = false;
         foreach ($scopeValues as $code => $val) {
             if (!$config->is($code, $val)) {
                 $config->set($code, $val);
                 $hasChanges = true;
             }
         }
         if ($hasChanges) {
             $this->configManager->persist($config);
         }
     }
 }
开发者ID:VadymKalin,项目名称:crm,代码行数:21,代码来源:ActivityContactConfigDumperExtension.php


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