public function register(Container $container)
 {
     $container['backendClass'] = function ($c) {
         $theme = $c['backendTheme'];
         if ($theme !== null) {
             return $theme->getClassName();
         }
         return 'RZ\\Roadiz\\CMS\\Controllers\\BackendController';
     };
     $container['backendTheme'] = function ($c) {
         if (isset($c['config']['install']) && false === $c['config']['install']) {
             return $c['em']->getRepository('RZ\\Roadiz\\Core\\Entities\\Theme')->findAvailableBackend();
         } else {
             return null;
         }
     };
     $container['frontendThemes'] = function ($c) {
         if (isset($c['config']['install']) && false === $c['config']['install']) {
             $themes = $c['em']->getRepository('RZ\\Roadiz\\Core\\Entities\\Theme')->findAvailableFrontends();
             if (count($themes) < 1) {
                 $defaultTheme = new Theme();
                 $defaultTheme->setClassName('RZ\\Roadiz\\CMS\\Controllers\\FrontendController');
                 $defaultTheme->setAvailable(true);
                 return [$defaultTheme];
             } else {
                 return $themes;
             }
         } else {
             return [];
         }
     };
     return $container;
 }
Beispiel #2
0
 /**
  * Build delete theme form with classname constraint.
  *
  * @param RZ\Roadiz\Core\Entities\Theme $theme
  *
  * @return \Symfony\Component\Form\Form
  */
 protected function buildDeleteForm(Theme $theme)
 {
     $builder = $this->createFormBuilder()->add('themeId', 'hidden', ['data' => $theme->getId()]);
     return $builder->getForm();
 }
Beispiel #3
0
 /**
  * Install theme and return its ID.
  *
  * @return integer
  */
 public function installFrontendTheme($classname)
 {
     $existing = $this->entityManager->getRepository('RZ\\Roadiz\\Core\\Entities\\Theme')->findOneByClassName($classname);
     if (null === $existing) {
         $feTheme = new Theme();
         $feTheme->setClassName($classname);
         $feTheme->setAvailable(true);
         $feTheme->setBackendTheme(false);
         $this->entityManager->persist($feTheme);
         $this->entityManager->flush();
         $this->clearResultCache();
         return $feTheme->getId();
     }
     return $existing->getId();
 }
Beispiel #4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $this->entityManager = $this->getHelperSet()->get('em')->getEntityManager();
     $text = "";
     $question = new ConfirmationQuestion('Before installing Roadiz, did you create database schema? ' . PHP_EOL . 'If not execute: <info>bin/roadiz orm:schema-tool:create</info>' . PHP_EOL . '<question>Are you sure to perform installation?</question> : ', false);
     if ($input->getOption('no-interaction') || $helper->ask($input, $output, $question)) {
         /*
          * Create backend theme
          */
         if (!$this->hasDefaultBackend()) {
             $theme = new Theme();
             $theme->setAvailable(true)->setBackendTheme(true)->setClassName("Themes\\Rozier\\RozierApp");
             $this->entityManager->persist($theme);
             $this->entityManager->flush();
             $text .= '<info>Rozier back-end theme installed…</info>' . PHP_EOL;
         } else {
             $text .= '<error>A back-end theme is already installed.</error>' . PHP_EOL;
         }
         /**
          * Import default data
          */
         $installRoot = ROADIZ_ROOT . "/themes/Install";
         $yaml = new YamlConfiguration($installRoot . "/config.yml");
         $yaml->load();
         $data = $yaml->getConfiguration();
         if (isset($data["importFiles"]['roles'])) {
             foreach ($data["importFiles"]['roles'] as $filename) {
                 \RZ\Roadiz\CMS\Importers\RolesImporter::importJsonFile(file_get_contents($installRoot . "/" . $filename), $this->entityManager);
                 $text .= '     — <info>Theme file “' . $installRoot . "/" . $filename . '” has been imported.</info>' . PHP_EOL;
             }
         }
         if (isset($data["importFiles"]['groups'])) {
             foreach ($data["importFiles"]['groups'] as $filename) {
                 \RZ\Roadiz\CMS\Importers\GroupsImporter::importJsonFile(file_get_contents($installRoot . "/" . $filename), $this->entityManager);
                 $text .= '     — <info>Theme file “' . $installRoot . "/" . $filename . '” has been imported..</info>' . PHP_EOL;
             }
         }
         if (isset($data["importFiles"]['settings'])) {
             foreach ($data["importFiles"]['settings'] as $filename) {
                 \RZ\Roadiz\CMS\Importers\SettingsImporter::importJsonFile(file_get_contents($installRoot . "/" . $filename), $this->entityManager);
                 $text .= '     — <info>Theme files “' . $installRoot . "/" . $filename . '” has been imported.</info>' . PHP_EOL;
             }
         }
         /*
          * Create default translation
          */
         if (!$this->hasDefaultTranslation()) {
             $defaultTrans = new Translation();
             $defaultTrans->setDefaultTranslation(true)->setLocale("en")->setName("Default translation");
             $this->entityManager->persist($defaultTrans);
             $this->entityManager->flush();
             $text .= '<info>Default translation installed…</info>' . PHP_EOL;
         } else {
             $text .= '<error>A default translation is already installed.</error>' . PHP_EOL;
         }
         /*
          * Disable install mode
          */
         $configuration = new YamlConfiguration();
         if (false === $configuration->load()) {
             $configuration->setConfiguration($configuration->getDefaultConfiguration());
         }
         $configuration->setInstall(false);
         $configuration->writeConfiguration();
         // Clear result cache
         $cacheDriver = $this->entityManager->getConfiguration()->getResultCacheImpl();
         if ($cacheDriver !== null) {
             $cacheDriver->deleteAll();
         }
         $text .= 'Install mode has been changed to false.' . PHP_EOL;
     }
     $output->writeln($text);
 }
 /**
  * Return a NodesSources url without hostname and without
  * root folder.
  *
  * It returns a relative url to Roadiz, not relative to your server root.
  *
  * @param RZ\Roadiz\Core\Entities\Theme $theme
  *
  * @return string
  */
 public function getNonContextualUrl(Theme $theme = null)
 {
     if (null !== $this->nodeSource) {
         if ($this->nodeSource->getNode()->isHome() || null !== $theme && $theme->getHomeNode() == $this->nodeSource->getNode()) {
             if ($this->nodeSource->getTranslation()->isDefaultTranslation() && false === $this->forceLocale) {
                 return '';
             } else {
                 return $this->nodeSource->getTranslation()->getPreferredLocale();
             }
         }
         $urlTokens = [];
         $urlTokens[] = $this->nodeSource->getHandler()->getIdentifier();
         $parent = $this->nodeSource->getHandler()->getParent();
         if ($parent !== null && !$parent->getNode()->isHome()) {
             do {
                 if ($parent->getNode()->isVisible()) {
                     $handler = $parent->getHandler();
                     $urlTokens[] = $handler->getIdentifier();
                 }
                 $parent = $parent->getHandler()->getParent();
             } while ($parent !== null && !$parent->getNode()->isHome());
         }
         /*
          * If using node-name, we must use shortLocale when current
          * translation is not the default one.
          */
         if ($urlTokens[0] == $this->nodeSource->getNode()->getNodeName() && !$this->nodeSource->getTranslation()->isDefaultTranslation() || true === $this->forceLocale) {
             $urlTokens[] = $this->nodeSource->getTranslation()->getPreferredLocale();
         }
         $urlTokens = array_reverse($urlTokens);
         return implode('/', $urlTokens);
     } else {
         throw new \RuntimeException("Cannot generate Url for a NULL NodesSources", 1);
     }
 }