Esempio n. 1
0
 /**
  * @param string $scopeEntityName
  * @param mixed  $scopeEntityIdentifier
  *
  * @return Config
  */
 public function getByEntity($scopeEntityName, $scopeEntityIdentifier)
 {
     $config = $this->findOneBy(['scopedEntity' => $scopeEntityName, 'recordId' => $scopeEntityIdentifier]);
     if (!$config) {
         $config = new Config();
         $config->setScopedEntity($scopeEntityName)->setRecordId($scopeEntityIdentifier);
     }
     return $config;
 }
Esempio n. 2
0
 /**
  * Save settings with fallback to global scope (default)
  *
  * @param array $settings
  *
  * @return array [updated, removed]
  */
 public function save($settings)
 {
     $entity = $this->getScopedEntityName();
     $entityId = $this->getScopeId();
     $em = $this->doctrine->getManagerForClass('Oro\\Bundle\\ConfigBundle\\Entity\\Config');
     /** @var Config $config */
     $config = $em->getRepository('Oro\\Bundle\\ConfigBundle\\Entity\\Config')->findByEntity($entity, $entityId);
     if (null === $config) {
         $config = new Config();
         $config->setScopedEntity($entity)->setRecordId($entityId);
     }
     $this->storedSettings[$entityId] = $this->convertToSettings($config);
     list($updated, $removed) = $this->calculateChangeSet($settings);
     foreach ($removed as $name) {
         list($section, $key) = explode(ConfigManager::SECTION_MODEL_SEPARATOR, $name);
         $config->removeValue($section, $key);
     }
     foreach ($updated as $name => $value) {
         list($section, $key) = explode(ConfigManager::SECTION_MODEL_SEPARATOR, $name);
         $configValue = $config->getOrCreateValue($section, $key);
         $configValue->setValue($value);
         if (!$configValue->getId()) {
             $config->getValues()->add($configValue);
         }
     }
     $em->persist($config);
     $em->flush();
     $settings = $this->convertToSettings($config);
     $this->cache->save($this->getCacheKey($entity, $entityId), $settings);
     $this->storedSettings[$entityId] = $settings;
     return [$updated, $removed];
 }