예제 #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;
 }
예제 #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));
         $providers = $this->getProviders();
         foreach ($providers 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());
             $configKey = $this->buildConfigKey($configId);
             if (isset($this->localCache[$configKey])) {
                 $this->localCache[$newConfigKey] = $this->changeConfigFieldName($this->localCache[$configKey], $newFieldName);
                 unset($this->localCache[$configKey]);
             }
             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;
 }
예제 #3
0
 public function testChangeFieldName()
 {
     $entityModel = $this->createEntityModel(self::TEST_ENTITY);
     $fieldModel = $this->createFieldModel($entityModel, self::TEST_FIELD);
     $this->createRepositoryMock([$entityModel], [UnitOfWork::STATE_MANAGED, UnitOfWork::STATE_MANAGED, UnitOfWork::STATE_MANAGED]);
     $this->em->expects($this->once())->method('persist')->with($this->equalTo($fieldModel));
     $this->em->expects($this->never())->method('flush');
     $result = $this->configModelManager->changeFieldName(self::TEST_ENTITY, self::TEST_FIELD, 'newField');
     $this->assertTrue($result);
     $this->assertEquals('newField', $this->configModelManager->getFieldModel(self::TEST_ENTITY, 'newField')->getFieldName());
     $this->assertNull($this->configModelManager->findFieldModel(self::TEST_ENTITY, self::TEST_FIELD));
 }