Пример #1
0
 public function testBuildLogEntryWithUnsupportedSecurityToken()
 {
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $token->expects($this->once())->method('getUser')->willReturn('test');
     $this->tokenStorage->expects($this->any())->method('getToken')->willReturn($token);
     $this->configManager->expects($this->never())->method('getUpdateConfig');
     $this->auditManager->buildLogEntry($this->configManager);
 }
 public function testLogWithoutUser()
 {
     $securityContext = $this->getMockForAbstractClass('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $securityContext->expects($this->any())->method('getToken');
     $securityLink = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\DependencyInjection\\Utils\\ServiceLink')->disableOriginalConstructor()->getMock();
     $securityLink->expects($this->any())->method('getService')->will($this->returnValue($securityContext));
     $configManager = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock();
     $configManagerLink = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\DependencyInjection\\Utils\\ServiceLink')->disableOriginalConstructor()->getMock();
     $configManagerLink->expects($this->any())->method('getService')->will($this->returnValue($configManager));
     $auditManager = new AuditManager($configManagerLink, $securityLink);
     $auditManager->log();
 }
Пример #3
0
 /**
  * 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 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();
 }
Пример #5
0
 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 = [];
 }
Пример #6
0
 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 = [];
 }