Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 public function testDeleteAllConfigsLocalCacheOnly()
 {
     $config = new Config(new EntityConfigId(self::SCOPE, self::ENTITY_CLASS), ['key1' => 'val1']);
     $this->configCache->saveConfig($config, true);
     $this->cache->expects($this->never())->method('deleteAll');
     $this->assertTrue($this->configCache->deleteAllConfigs(true));
     // check that a local cache is cleaned up
     $this->assertNull($this->configCache->getEntityConfig(self::SCOPE, self::ENTITY_CLASS, true));
 }
Ejemplo n.º 4
0
 public function testSaveFieldConfigWhenAnotherScopeIsAlreadyCached()
 {
     $configId = new FieldConfigId(self::SCOPE, self::ENTITY_CLASS, self::FIELD_NAME, self::FIELD_TYPE);
     $configValues = ['key1' => 'val1'];
     $config = new Config($configId, $configValues);
     $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->cache->expects($this->once())->method('save')->with($cacheKey, [ConfigCache::VALUES_KEY => ['another' => $anotherConfigValues, self::SCOPE => $configValues], ConfigCache::FIELD_TYPE_KEY => self::FIELD_TYPE])->willReturn(true);
     $this->assertTrue($this->configCache->saveConfig($config));
     // test local cache
     $this->assertEquals($config, $this->configCache->getConfig($configId));
     $this->assertEquals($anotherConfig, $this->configCache->getConfig($anotherConfigId));
 }