/** * Flushes all changes that have been queued up to now to a database. */ public function flush() { /** @var ConfigModel[] $models */ $models = []; $this->prepareFlush($models); $em = $this->getEntityManager(); $now = new \DateTime('now', new \DateTimeZone('UTC')); $logEntry = $this->auditManager->buildEntity($this); foreach ($models as $model) { if (null === $model->getId()) { $model->setCreated($now); } $model->setUpdated($now); $em->persist($model); } if (!empty($models)) { $em->flush(); } if (null !== $logEntry) { $this->auditManager->save($logEntry); } // @todo: Should be removed together with deprecated events if ($this->hasListeners(Events::POST_FLUSH_CONFIG)) { $this->eventDispatcher->dispatch(Events::POST_FLUSH_CONFIG, new Event\FlushConfigEvent($models, $this)); } $this->eventDispatcher->dispatch(Events::POST_FLUSH, new Event\PostFlushConfigEvent($models, $this)); if (!empty($models)) { $this->cache->deleteAllConfigurable(); } $this->persistConfigs = []; $this->configChangeSets = []; }
public function testDeleteAllConfigurableLocalCacheOnly() { $this->configCache->saveConfigurable(true, self::ENTITY_CLASS, null, true); $this->modelCache->expects($this->never())->method('deleteAll'); $this->assertTrue($this->configCache->deleteAllConfigurable(true)); // test that a local cache is cleaned up $this->assertNull($this->configCache->getConfigurable(self::ENTITY_CLASS)); }
public function flush() { $models = []; $this->prepareFlush($models); $em = $this->getEntityManager(); $logEntry = $this->auditManager->buildLogEntry($this); if (null !== $logEntry) { $em->persist($logEntry); } foreach ($models as $model) { $em->persist($model); } // @todo: need investigation if we can call this flush only if !empty($models) $em->flush(); $this->eventDispatcher->dispatch(Events::POST_FLUSH_CONFIG, new FlushConfigEvent($models, $this)); if (!empty($models)) { $this->cache->deleteAllConfigurable(); } $this->persistConfigs = []; $this->configChangeSets = []; }
public function testDeleteAllConfigurable() { $this->modelCache->expects($this->once())->method('deleteAll')->willReturn(true); $this->assertTrue($this->configCache->deleteAllConfigurable()); }