Esempio n. 1
0
 /**
  * @return ArrayHash|null
  */
 public function loadOptions()
 {
     $options = $this->cache->load(Option::getCacheKey(), function () use(&$dependencies) {
         $options = $this->em->createQuery('SELECT o FROM ' . Option::class . ' o')->getArrayResult();
         if (empty($options)) {
             return null;
         }
         $options = ArrayHash::from(Arrays::associate($options, 'name=value'));
         $dependencies = [Cache::TAGS => Option::getCacheKey()];
         return $options;
     });
     return $options;
 }
Esempio n. 2
0
 public function save(array $values)
 {
     $options = $this->prepareOptions($this->findOptions());
     foreach ((array) $values as $key => $value) {
         $options[$key]->setValue($value == '' ? null : $value);
         $this->em->persist($options[$key]);
     }
     try {
         $this->em->flush();
         $this->cache->remove(Option::getCacheKey());
         $this->onSuccessOptionsSaving();
     } catch (\Exception $e) {
         $this->em->rollback();
         $this->em->close();
         $this->logger->addError(sprintf('Save Options error: %s | error message: %s', date('Y-m-d H:i:s'), $e->getMessage()));
         throw $e;
     }
 }