Beispiel #1
0
 /**
  * @see BackBee\Config\Persistor\PersistorInterface::persist
  */
 public function persist(Config $config, array $configToPersist)
 {
     if (array_key_exists('override_site', $configToPersist)) {
         $configToPersist = array('override_site' => $configToPersist['override_site']);
     }
     $baseScope = 'BUNDLE_CONFIG.';
     $key = $this->app->getContainer()->get('bundle.loader')->getBundleIdByBaseDir($config->getBaseDir());
     if (null === $key) {
         $key = $application;
         $baseScope = 'APPLICATION_CONFIG.';
     }
     $scope = $baseScope . $this->app->getContext() . '.' . $this->app->getEnvironment();
     $registry = $this->app->getEntityManager()->getRepository('BackBee\\Bundle\\Registry')->findOneBy(array('key' => $key, 'scope' => $scope));
     if (null === $registry) {
         $registry = new RegistryEntity();
         $registry->setKey($key);
         $registry->setScope($scope);
         $this->app->getEntityManager()->persist($registry);
     }
     $registry->setValue(serialize($configToPersist));
     $success = true;
     try {
         $this->app->getEntityManager()->flush($registry);
     } catch (\Exception $e) {
         $success = false;
     }
     return $success;
 }
 /**
  * Instantiate a ClassContentManager.
  *
  * @param ApplicationInterface   $app      The current application.
  * @param IconizerInterface|null $iconizer Optional, an content iconizer.
  */
 public function __construct(ApplicationInterface $app, IconizerInterface $iconizer = null)
 {
     $this->app = $app;
     $this->entityManager = $app->getEntityManager();
     $this->iconizer = $iconizer;
     $this->cache = $app->getContainer()->get('cache.control');
 }
Beispiel #3
0
 /**
  * Returns the theme registry or null if not found.
  *
  * @param  Site|null     $site
  * @return Registry|null
  */
 protected function getThemeRegistry(Site $site = null)
 {
     $registry = null;
     $criteria = ['type' => 'selected_theme', 'scope' => 'THEME_CONFIG'];
     if (null !== $site) {
         $criteria['key'] = $site->getLabel();
         $registry = $this->app->getEntityManager()->getRepository(Registry::class)->findOneBy($criteria);
     }
     if (null === $registry) {
         $criteria['key'] = 'default';
         $registry = $this->app->getEntityManager()->getRepository(Registry::class)->findOneBy($criteria);
     }
     return $registry;
 }
Beispiel #4
0
 /**
  * Returns the registry entry for bundle's config storing.
  *
  * @param  string  $bundleId            The id of the bundle we are looking for override config in registry.
  * @param  boolean $scopePerContext     If TRUE use context in registry scope.
  * @param  boolean $scopePerEnvironment If TRUE use environment in regsitry scope.
  *
  * @return \BackBee\Bundle\Registry|NULL
  */
 private function getRegistryConfig($bundleId, $scopePerContext, $scopePerEnvironment)
 {
     $registry = null;
     try {
         if (null !== ($em = $this->application->getEntityManager())) {
             $registry = $em->getRepository('BackBee\\Bundle\\Registry')->findOneBy(array('key' => $bundleId, 'scope' => $this->getRegistryScope('BUNDLE_CONFIG', $scopePerContext, $scopePerEnvironment)));
         }
     } catch (DBALException $e) {
         $expectedError = false;
         if (null !== $e->getPrevious() && $e->getPrevious() instanceof \PDOException) {
             // expected error is if we try to get overrided config in registry on application installation process
             // PDOException has two methods for retrieving information about an error
             // @see http://php.net/manual/en/class.pdoexception.php
             $expectedError = '42S02' === $e->getPrevious()->getCode() || false !== strpos($e->getPrevious()->getMessage(), 'SQLSTATE[42S02]');
         }
         if (false === $expectedError) {
             throw $e;
         }
     }
     return $registry;
 }
 /**
  * Instantiate a ClassContentManager.
  *
  * @param ApplicationInterface $application
  */
 public function __construct(ApplicationInterface $application)
 {
     $this->application = $application;
     $this->em = $application->getEntityManager();
     $this->categoryManager = $application->getContainer()->get('classcontent.category_manager');
 }
 /**
  * @see BackBee\Bundle\BundleInterface::getEntityManager
  */
 public function getEntityManager()
 {
     return $this->application->getEntityManager();
 }