protected function importTheme($classname, &$text)
 {
     $themeFile = $classname;
     $themeFile = str_replace('\\', '/', $themeFile);
     $themeFile = str_replace('Themes', 'themes', $themeFile);
     $themeFile .= ".php";
     if (file_exists($themeFile)) {
         $fixtures = new Fixtures($this->entityManager);
         $fixtures->installFrontendTheme($classname);
         $text .= '<info>Theme class “' . $themeFile . '” has been installed…</info>' . PHP_EOL;
         // install fixtures
         $array = explode('\\', $classname);
         $themeRoot = ROADIZ_ROOT . "/themes/" . $array[count($array) - 2];
         $yaml = new YamlConfiguration($themeRoot . "/config.yml");
         $yaml->load();
         $data = $yaml->getConfiguration();
         if (false !== $data && isset($data["importFiles"])) {
             if (isset($data["importFiles"]['roles'])) {
                 foreach ($data["importFiles"]['roles'] as $filename) {
                     \RZ\Roadiz\CMS\Importers\RolesImporter::importJsonFile(file_get_contents($themeRoot . "/" . $filename), $this->entityManager);
                     $text .= '     — <info>Theme file “' . $themeRoot . "/" . $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($themeRoot . "/" . $filename), $this->entityManager);
                     $text .= '     — <info>Theme file “' . $themeRoot . "/" . $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($themeRoot . "/" . $filename), $this->entityManager);
                     $text .= '     — <info>Theme files “' . $themeRoot . "/" . $filename . '” has been imported.</info>' . PHP_EOL;
                 }
             }
             if (isset($data["importFiles"]['nodetypes'])) {
                 foreach ($data["importFiles"]['nodetypes'] as $filename) {
                     \RZ\Roadiz\CMS\Importers\NodeTypesImporter::importJsonFile(file_get_contents($themeRoot . "/" . $filename), $this->entityManager);
                     $text .= '     — <info>Theme file “' . $themeRoot . "/" . $filename . '” has been imported.</info>' . PHP_EOL;
                 }
             }
             $text .= 'You should do a <info>bin/roadiz orm:schema-tool:update --force</info> to apply your themes into database.' . PHP_EOL;
         } else {
             $text .= '<info>Theme class “' . $themeFile . '” has no data to import.</info>' . PHP_EOL;
         }
     } else {
         $text .= '<error>Theme class “' . $themeFile . '” does not exist.</error>' . PHP_EOL;
     }
 }
 /**
  * Import a Json file (.rzt) containing Group datas and roles.
  *
  * @param Symfony\Component\HttpFoundation\Request $request
  *
  * @return Symfony\Component\HttpFoundation\Response
  */
 public function importJsonFileAction(Request $request)
 {
     $this->validateAccessForRole('ROLE_ACCESS_GROUPS');
     $form = $this->buildImportJsonFileForm();
     $form->handleRequest($request);
     if ($form->isValid() && !empty($form['group_file'])) {
         $file = $form['group_file']->getData();
         if ($file->isValid()) {
             $serializedData = file_get_contents($file->getPathname());
             if (null !== json_decode($serializedData)) {
                 GroupsImporter::importJsonFile($serializedData, $this->getService('em'));
                 $msg = $this->getTranslator()->trans('group.imported.updated');
                 $this->publishConfirmMessage($request, $msg);
                 // redirect even if its null
                 return $this->redirect($this->generateUrl('groupsHomePage'));
             } else {
                 $msg = $this->getTranslator()->trans('file.format.not_valid');
                 $request->getSession()->getFlashBag()->add('error', $msg);
                 $this->getService('logger')->error($msg);
                 // redirect even if its null
                 return $this->redirect($this->generateUrl('groupsImportPage'));
             }
         } else {
             $msg = $this->getTranslator()->trans('file.not_uploaded');
             $request->getSession()->getFlashBag()->add('error', $msg);
             $this->getService('logger')->error($msg);
         }
     }
     $this->assignation['form'] = $form->createView();
     return $this->render('groups/import.html.twig', $this->assignation);
 }
示例#3
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);
 }