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();
 }
 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());
 }
Esempio n. 3
0
 public function testRemoveConfigFromCache()
 {
     $className = 'testClass';
     $scope = 'testScope';
     $configId = new EntityConfigId($scope, $className);
     $configCache = new ConfigCache($this->cacheProvider, $this->modelCacheProvider);
     $this->cacheProvider->expects($this->once())->method('delete')->will($this->returnValue(true));
     $this->assertTrue($configCache->removeConfigFromCache($configId));
 }
Esempio n. 4
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);
     }
 }