/** * Install theme. * * @param Symfony\Component\HttpFoundation\Request $request * @param string $classname * @param Doctrine\ORM\EntityManager $em * * @return bool */ public static function install(Request $request, $classname, EntityManager $em) { $data = static::getThemeInformation($classname); $fix = new Fixtures($em, $request); $data["className"] = $classname; $fix->installTheme($data); $installedLanguage = $em->getRepository("RZ\\Roadiz\\Core\\Entities\\Translation")->findAll(); foreach ($installedLanguage as $key => $locale) { $installedLanguage[$key] = $locale->getLocale(); } $exist = false; foreach ($data["supportedLocale"] as $locale) { if (in_array($locale, $installedLanguage)) { $exist = true; } } if ($exist === false) { $newTranslation = new Translation(); $newTranslation->setLocale($data["supportedLocale"][0]); $newTranslation->setName(Translation::$availableLocales[$data["supportedLocale"][0]]); $em->persist($newTranslation); $em->flush(); } $importFile = false; foreach ($data["importFiles"] as $name => $filenames) { foreach ($filenames as $filename) { $importFile = true; break; } } return $importFile; }
/** * User creation screen. * * @param Symfony\Component\HttpFoundation\Request $request * * @return Symfony\Component\HttpFoundation\Response */ public function userAction(Request $request) { $userForm = $this->buildUserForm($request); if ($userForm !== null) { $userForm->handleRequest($request); if ($userForm->isValid()) { /* * Create user */ try { $fixtures = new Fixtures($this->getService("em"), $request); $fixtures->createDefaultUser($userForm->getData()); /* * Force redirect to avoid resending form when refreshing page */ $user = $this->getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\User')->findOneBy(['username' => $userForm->getData()['username']]); return $this->redirect($this->generateUrl('installUserSummaryPage', ["userId" => $user->getId()])); } catch (\Exception $e) { $this->assignation['error'] = true; $this->assignation['errorMessage'] = $e->getMessage(); } } $this->assignation['userForm'] = $userForm->createView(); } return $this->render('steps/user.html.twig', $this->assignation); }
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; } }
/** * Theme install screen. * * @param Symfony\Component\HttpFoundation\Request $request * * @return Symfony\Component\HttpFoundation\Response */ public function themesAction(Request $request) { $infosForm = $this->buildInformationsForm($request); if ($infosForm !== null) { $infosForm->handleRequest($request); if ($infosForm->isValid()) { /* * Save informations */ try { $fixtures = new Fixtures($this->getService("em")); $fixtures->saveInformations($infosForm->getData()); if (!empty($infosForm->getData()["install_theme"])) { /* * Force redirect to avoid resending form when refreshing page */ return $this->redirect($this->generateUrl('installThemeSummaryPage', ['classname' => $infosForm->getData()['className']])); } else { return $this->redirect($this->generateUrl('installUserPage')); } } catch (\Exception $e) { $this->assignation['error'] = true; $this->assignation['errorMessage'] = $e->getMessage() . PHP_EOL . $e->getTraceAsString(); } } $this->assignation['infosForm'] = $infosForm->createView(); } return $this->render('steps/themes.html.twig', $this->assignation); }
/** * Perform database fixtures importation. * * @param Symfony\Component\HttpFoundation\Request $request * * @return Symfony\Component\HttpFoundation\Response */ public function databaseFixturesAction(Request $request) { $fixtures = new Fixtures($this->getService('em'), $request); $fixtures->installFixtures(); /* * files to import */ $yaml = new YamlConfiguration(ROADIZ_ROOT . "/themes/Install/config.yml"); $yaml->load(); $installData = $yaml->getConfiguration(); $this->assignation['imports'] = $installData['importFiles']; return $this->render('steps/databaseFixtures.html.twig', $this->assignation); }