/** * 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->getConfig($configId, true); if ($cachedConfig) { $this->cache->saveConfig($this->changeConfigFieldName($cachedConfig, $newFieldName), true); $this->cache->deleteConfig($configId, 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->getConfig($configId)); // test local cache $this->assertNull($this->configCache->getConfig($configId)); $this->assertEquals($anotherConfig, $this->configCache->getConfig($anotherConfigId)); }