public function testCache()
 {
     $cacheProvider = $this->getMockBuilder('Doctrine\\Common\\Cache\\CacheProvider')->disableOriginalConstructor()->setMethods(array('fetch', 'save', 'delete', 'deleteAll'))->getMockForAbstractClass();
     $modelCacheProvider = $this->getMockBuilder('Doctrine\\Common\\Cache\\CacheProvider')->disableOriginalConstructor()->setMethods(array('fetch', 'save', 'delete', 'deleteAll'))->getMockForAbstractClass();
     $className = 'testClass';
     $scope = 'testScope';
     $configId = new EntityConfigId($className, $scope);
     $config = new Config($configId);
     $configCache = new ConfigCache($cacheProvider, $modelCacheProvider);
     $cacheProvider->expects($this->once())->method('save')->will($this->returnValue(true));
     $this->assertTrue($configCache->putConfigInCache($config));
     $cacheProvider->expects($this->once())->method('delete')->will($this->returnValue(true));
     $this->assertTrue($configCache->removeConfigFromCache($configId));
     $cacheProvider->expects($this->once())->method('deleteAll')->will($this->returnValue(true));
     $this->assertTrue($configCache->removeAll());
     $cacheProvider->expects($this->once())->method('fetch')->will($this->returnValue(serialize($config)));
     $this->assertEquals($config, $configCache->loadConfigFromCache($configId));
     $value = 'testValue';
     $modelCacheProvider->expects($this->once())->method('save')->will($this->returnValue(true));
     $this->assertTrue($configCache->setConfigurable($value, $className));
     $modelCacheProvider->expects($this->once())->method('fetch')->will($this->returnValue($value));
     $this->assertEquals($value, $configCache->getConfigurable($className));
     $modelCacheProvider->expects($this->once())->method('deleteAll')->will($this->returnValue(true));
     $this->assertTrue($configCache->removeAllConfigurable());
 }
 public function flush()
 {
     $models = array();
     foreach ($this->persistConfigs as $config) {
         $this->calculateConfigChangeSet($config);
         $this->eventDispatcher->dispatch(Events::PRE_PERSIST_CONFIG, new PersistConfigEvent($config, $this));
         if (isset($models[$config->getId()->toString()])) {
             $model = $models[$config->getId()->toString()];
         } else {
             $model = $this->modelManager->getModelByConfigId($config->getId());
             $models[$config->getId()->toString()] = $model;
         }
         //TODO::refactoring
         $serializableValues = $this->getProvider($config->getId()->getScope())->getPropertyConfig()->getSerializableValues($config->getId());
         $model->fromArray($config->getId()->getScope(), $config->all(), $serializableValues);
         if ($this->cache) {
             $this->cache->removeConfigFromCache($config->getId());
             $this->cache->removeAllConfigurable();
         }
     }
     $this->auditManager->log();
     foreach ($models as $model) {
         $this->getEntityManager()->persist($model);
     }
     $this->getEntityManager()->flush();
     $this->persistConfigs = new \SplObjectStorage();
     $this->configChangeSets = new ArrayCollection();
 }
Example #3
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;
 }
Example #4
0
 /**
  * Checks whether a field is configurable.
  *
  * @param string $className
  * @param string $fieldName
  *
  * @return bool
  */
 protected function isConfigurableField($className, $fieldName)
 {
     $isConfigurable = $this->cache->getConfigurable($className, $fieldName);
     if (null === $isConfigurable) {
         $isConfigurable = null !== $this->modelManager->findFieldModel($className, $fieldName);
         $this->cache->saveConfigurable($isConfigurable, $className, $fieldName);
     }
     return $isConfigurable;
 }
Example #5
0
 protected function loadVirtualFields()
 {
     $entities = $this->cache->getEntities();
     foreach ($entities as $className => $entityData) {
         $virtualFields = $this->virtualFieldProvider->getVirtualFields($className);
         if (!empty($virtualFields)) {
             foreach ($virtualFields as $fieldName) {
                 if (null === $this->cache->getConfigurable($className, $fieldName)) {
                     $this->cache->saveConfigurable(false, $className, $fieldName);
                 }
             }
         }
         $virtualRelations = $this->virtualRelationProvider->getVirtualRelations($className);
         if (!empty($virtualRelations)) {
             foreach ($virtualRelations as $fieldName => $config) {
                 if (null === $this->cache->getConfigurable($className, $fieldName)) {
                     $this->cache->saveConfigurable(false, $className, $fieldName);
                 }
             }
         }
     }
 }
Example #6
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 ? sprintf('%s_%s', $configId->getClassName(), $configId->getFieldName()) : $configId->getClassName();
         if (isset($models[$configKey])) {
             $model = $models[$configKey];
         } else {
             $model = $configId instanceof FieldConfigId ? $this->modelManager->getFieldModel($configId->getClassName(), $configId->getFieldName()) : $this->modelManager->getEntityModel($configId->getClassName());
             $models[$configKey] = $model;
         }
         $indexedValues = $this->getProvider($config->getId()->getScope())->getPropertyConfig()->getIndexedValues($config->getId());
         $model->fromArray($config->getId()->getScope(), $config->all(), $indexedValues);
         if ($this->cache) {
             $this->cache->removeConfigFromCache($config->getId());
         }
     }
     if (count($this->persistConfigs) != count($this->configChangeSets)) {
         $this->prepareFlush($models);
     }
 }
Example #7
0
 public function testFlushAllConfigurable()
 {
     $this->modelCache->expects($this->once())->method('flushAll')->willReturn(true);
     $this->assertTrue($this->configCache->flushAllConfigurable());
 }
Example #8
0
 public function testRemoveAllConfigurable()
 {
     $configCache = new ConfigCache($this->cacheProvider, $this->modelCacheProvider);
     $this->modelCacheProvider->expects($this->once())->method('deleteAll')->will($this->returnValue(true));
     $this->assertTrue($configCache->removeAllConfigurable());
 }