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()); }
public function flush() { $models = []; $this->prepareFlush($models); $this->auditManager->log(); foreach ($models as $model) { $this->getEntityManager()->persist($model); } // @todo: need investigation if we can call this flush only if !empty($models) $this->getEntityManager()->flush(); $this->eventDispatcher->dispatch(Events::POST_FLUSH_CONFIG, new FlushConfigEvent($models, $this)); if ($this->cache && !empty($models)) { $this->cache->removeAllConfigurable(); } $this->persistConfigs = []; $this->configChangeSets = []; }
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()); }