Пример #1
0
 /**
  * @param array $models
  */
 protected function prepareFlush(&$models)
 {
     foreach ($this->persistConfigs as $config) {
         $this->calculateConfigChangeSet($config);
         $this->eventDispatcher->dispatch(Events::PRE_PERSIST_CONFIG, new PersistConfigEvent($config, $this));
         $configId = $config->getId();
         $configKey = $configId instanceof FieldConfigId ? $configId->getClassName() . '.' . $configId->getFieldName() : $configId->getClassName();
         if (isset($models[$configKey])) {
             $model = $models[$configKey];
         } else {
             $model = $this->getModelByConfigId($configId);
             $models[$configKey] = $model;
         }
         $indexedValues = $this->getProvider($configId->getScope())->getPropertyConfig()->getIndexedValues($configId);
         $model->fromArray($configId->getScope(), $config->all(), $indexedValues);
         if ($configId instanceof FieldConfigId) {
             $this->cache->deleteFieldConfig($configId->getClassName(), $configId->getFieldName());
         } else {
             $this->cache->deleteEntityConfig($configId->getClassName());
         }
     }
     if (count($this->persistConfigs) !== count($this->configChangeSets)) {
         $this->prepareFlush($models);
     }
 }
Пример #2
0
 public function testDeleteEntityConfig()
 {
     $configId = new EntityConfigId(self::SCOPE, self::ENTITY_CLASS);
     $cacheKey = self::ENTITY_CLASS;
     $this->cache->expects($this->once())->method('delete')->with($cacheKey)->willReturn(true);
     $this->assertTrue($this->configCache->deleteEntityConfig($configId->getClassName()));
 }
Пример #3
0
 /**
  * @param array $models
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function prepareFlush(&$models)
 {
     $groupedConfigs = [];
     foreach ($this->persistConfigs as $config) {
         $this->calculateConfigChangeSet($config);
         // @todo: Should be removed together with deprecated events
         if ($this->hasListeners(Events::PRE_PERSIST_CONFIG)) {
             $this->eventDispatcher->dispatch(Events::PRE_PERSIST_CONFIG, new Event\PersistConfigEvent($config, $this));
         }
         $configId = $config->getId();
         $modelKey = $configId instanceof FieldConfigId ? $configId->getClassName() . '.' . $configId->getFieldName() : $configId->getClassName();
         $groupedConfigs[$modelKey][$configId->getScope()] = $config;
     }
     /** @var ConfigInterface[] $configs */
     foreach ($groupedConfigs as $modelKey => $configs) {
         $this->eventDispatcher->dispatch(Events::PRE_FLUSH, new Event\PreFlushConfigEvent($configs, $this));
         foreach ($configs as $scope => $config) {
             $configId = $config->getId();
             $className = $configId->getClassName();
             $fieldName = $configId instanceof FieldConfigId ? $configId->getFieldName() : null;
             if (isset($models[$modelKey])) {
                 $model = $models[$modelKey];
             } else {
                 $model = null !== $fieldName ? $this->modelManager->getFieldModel($className, $fieldName) : $this->modelManager->getEntityModel($className);
                 $models[$modelKey] = $model;
             }
             $indexedValues = $this->getPropertyConfig($scope)->getIndexedValues(null !== $fieldName ? PropertyConfigContainer::TYPE_FIELD : PropertyConfigContainer::TYPE_ENTITY);
             $model->fromArray($scope, $config->getValues(), $indexedValues);
             if (null !== $fieldName) {
                 $this->cache->deleteFieldConfig($className, $fieldName);
             } else {
                 $this->cache->deleteEntityConfig($className);
             }
         }
     }
     if (count($this->persistConfigs) !== count($this->configChangeSets)) {
         $this->prepareFlush($models);
     }
 }