public function testEvent()
 {
     $config1 = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
     $config2 = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
     $configs = ['scope1' => $config1, 'scope2' => $config2];
     $configManager = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock();
     $event = new PreFlushConfigEvent($configs, $configManager);
     $this->assertSame($configManager, $event->getConfigManager());
     $this->assertEquals($configs, $event->getConfigs());
     $this->assertSame($config1, $event->getConfig('scope1'));
     $this->assertSame($config2, $event->getConfig('scope2'));
     $this->assertNull($event->getConfig('another_scope'));
 }
Esempio n. 2
0
 /**
  * @param PreFlushConfigEvent $event
  */
 public function preFlush(PreFlushConfigEvent $event)
 {
     $config = $event->getConfig('ownership');
     if (null === $config || $event->isFieldConfig()) {
         return;
     }
     $haveChanges = false;
     $ownerType = $config->get('owner_type');
     if ($ownerType === 'NONE') {
         $ownerType = null;
         $config->remove('owner_type');
         $haveChanges = true;
     }
     if ($ownerType && $this->isCustomEntity($config->getId()->getClassName(), $event->getConfigManager())) {
         if (!$config->has('owner_field_name')) {
             // update 'ownership' config for entity
             $config->set('owner_field_name', 'owner');
             $config->set('owner_column_name', 'owner_id');
             $haveChanges = true;
         }
         if (!$config->has('organization_field_name') && in_array($ownerType, [OwnershipType::OWNER_TYPE_USER, OwnershipType::OWNER_TYPE_BUSINESS_UNIT], true)) {
             // update organization config for entity
             $config->set('organization_field_name', 'organization');
             $config->set('organization_column_name', 'organization_id');
             $haveChanges = true;
         }
     }
     if ($haveChanges) {
         $configManager = $event->getConfigManager();
         $configManager->persist($config);
         $configManager->calculateConfigChangeSet($config);
     }
 }
Esempio n. 3
0
 /**
  * @param PreFlushConfigEvent $event
  */
 public function preFlush(PreFlushConfigEvent $event)
 {
     $config = $event->getConfig('email');
     if (null === $config || $event->isEntityConfig()) {
         return;
     }
     $changeSet = $event->getConfigManager()->getConfigChangeSet($config);
     if (isset($changeSet['available_in_template'])) {
         $this->cache->delete($this->cacheKey);
     }
 }
 /**
  * @param PreFlushConfigEvent $event
  */
 public function preFlush(PreFlushConfigEvent $event)
 {
     $config = $event->getConfig('extend');
     if (null === $config || $event->isFieldConfig()) {
         return;
     }
     $className = $config->getId()->getClassName();
     $this->provider->clearCache($className);
     $changeSet = $event->getConfigManager()->getConfigChangeSet($config);
     $isDeleted = isset($changeSet['state']) && $changeSet['state'][1] === ExtendScope::STATE_DELETE;
     if (!$isDeleted) {
         $this->provider->warmUpCache($className);
     }
 }
Esempio n. 5
0
 /**
  * @param PreFlushConfigEvent $event
  */
 public function preFlush(PreFlushConfigEvent $event)
 {
     $config = $event->getConfig('extend');
     if (null === $config || $event->isEntityConfig()) {
         return;
     }
     $configManager = $event->getConfigManager();
     $changeSet = $configManager->getConfigChangeSet($config);
     // synchronize field state with entity state, when custom field state changed
     if (isset($changeSet['state']) && $changeSet['state'][1] !== ExtendScope::STATE_ACTIVE && $config->is('owner', ExtendScope::OWNER_CUSTOM)) {
         $entityConfig = $configManager->getEntityConfig('extend', $config->getId()->getClassName());
         if ($entityConfig->in('state', [ExtendScope::STATE_ACTIVE, ExtendScope::STATE_DELETE])) {
             $entityConfig->set('state', ExtendScope::STATE_UPDATE);
             $configManager->persist($entityConfig);
             $configManager->calculateConfigChangeSet($entityConfig);
         }
     }
 }
 /**
  * @param PreFlushConfigEvent $event
  */
 public function preFlush(PreFlushConfigEvent $event)
 {
     $config = $event->getConfig('search');
     if (null === $config) {
         return;
     }
     $configManager = $event->getConfigManager();
     $changeSet = $configManager->getConfigChangeSet($config);
     if (!isset($changeSet['searchable'])) {
         return;
     }
     $className = $config->getId()->getClassName();
     $extendConfig = $configManager->getProvider('extend')->getConfig($className);
     if ($extendConfig->get('state') === ExtendScope::STATE_ACTIVE) {
         $this->addReindexJob($className);
     } else {
         $this->addPostponeJob($className);
     }
 }