/** * Changes a type of a field * * @param string $className * @param string $fieldName * @param string $newFieldName * * @return bool TRUE if the name was changed; otherwise, FALSE */ public function changeFieldName($className, $fieldName, $newFieldName) { $result = $this->modelManager->changeFieldName($className, $fieldName, $newFieldName); if ($result) { // @todo: Should be removed together with deprecated events if ($this->hasListeners(Events::RENAME_FIELD_OLD)) { $this->eventDispatcher->dispatch(Events::RENAME_FIELD_OLD, new Event\RenameFieldEvent($className, $fieldName, $newFieldName, $this)); } $this->eventDispatcher->dispatch(Events::RENAME_FIELD, new Event\RenameFieldEvent($className, $fieldName, $newFieldName, $this)); foreach ($this->providers as $scope => $provider) { $cachedConfig = $this->cache->getFieldConfig($scope, $className, $fieldName, true); if ($cachedConfig) { $this->cache->saveConfig($this->changeConfigFieldName($cachedConfig, $newFieldName), true); $this->cache->deleteFieldConfig($className, $fieldName, true); } $newConfigKey = $scope . '.' . $className . '.' . $newFieldName; $configKey = $scope . '.' . $className . '.' . $fieldName; if (isset($this->persistConfigs[$configKey])) { $this->persistConfigs[$newConfigKey] = $this->changeConfigFieldName($this->persistConfigs[$configKey], $newFieldName); unset($this->persistConfigs[$configKey]); } if (isset($this->originalValues[$configKey])) { $this->originalValues[$newConfigKey] = $this->originalValues[$configKey]; unset($this->originalValues[$configKey]); } if (isset($this->configChangeSets[$configKey])) { $this->configChangeSets[$newConfigKey] = $this->configChangeSets[$configKey]; unset($this->configChangeSets[$configKey]); } } } return $result; }
/** * Changes a type of a field * * @param string $className * @param string $fieldName * @param string $newFieldName * @return bool TRUE if the name was changed; otherwise, FALSE */ public function changeFieldName($className, $fieldName, $newFieldName) { $result = $this->modelManager->changeFieldName($className, $fieldName, $newFieldName); if ($result) { $this->eventDispatcher->dispatch(Events::RENAME_FIELD, new RenameFieldEvent($className, $fieldName, $newFieldName, $this)); foreach ($this->getProviders() as $provider) { /** @var FieldConfigId $newConfigId */ $newConfigId = $this->getId($provider->getScope(), $className, $newFieldName); $newConfigKey = $this->buildConfigKey($newConfigId); $configId = new FieldConfigId($newConfigId->getScope(), $newConfigId->getClassName(), $fieldName, $newConfigId->getFieldType()); $cachedConfig = $this->cache->getFieldConfig($configId->getScope(), $configId->getClassName(), $configId->getFieldName(), true); if ($cachedConfig) { $this->cache->saveConfig($this->changeConfigFieldName($cachedConfig, $newFieldName), true); $this->cache->deleteFieldConfig($configId->getClassName(), $configId->getFieldName(), true); } $configKey = $this->buildConfigKey($configId); if (isset($this->persistConfigs[$configKey])) { $this->persistConfigs[$newConfigKey] = $this->changeConfigFieldName($this->persistConfigs[$configKey], $newFieldName); unset($this->persistConfigs[$configKey]); } if (isset($this->originalConfigs[$configKey])) { $this->originalConfigs[$newConfigKey] = $this->changeConfigFieldName($this->originalConfigs[$configKey], $newFieldName); unset($this->originalConfigs[$configKey]); } if (isset($this->configChangeSets[$configKey])) { $this->configChangeSets[$newConfigKey] = $this->configChangeSets[$configKey]; unset($this->configChangeSets[$configKey]); } } } return $result; }
public function testGetFieldConfigNotCachedScope() { $configId = new FieldConfigId(self::SCOPE, self::ENTITY_CLASS, self::FIELD_NAME, self::FIELD_TYPE); $anotherConfigId = new FieldConfigId('another', self::ENTITY_CLASS, self::FIELD_NAME, self::FIELD_TYPE); $anotherConfigValues = ['key2' => 'val2']; $anotherConfig = new Config($anotherConfigId, $anotherConfigValues); $cacheKey = self::ENTITY_CLASS . '.' . self::FIELD_NAME; $this->cache->expects($this->once())->method('fetch')->with($cacheKey)->willReturn([ConfigCache::VALUES_KEY => ['another' => $anotherConfigValues], ConfigCache::FIELD_TYPE_KEY => self::FIELD_TYPE]); $this->assertNull($this->configCache->getFieldConfig($configId->getScope(), $configId->getClassName(), $configId->getFieldName())); // test local cache $this->assertNull($this->configCache->getFieldConfig($configId->getScope(), $configId->getClassName(), $configId->getFieldName())); $this->assertEquals($anotherConfig, $this->configCache->getFieldConfig($anotherConfigId->getScope(), $anotherConfigId->getClassName(), $anotherConfigId->getFieldName())); }