Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 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();
 }