Ejemplo n.º 1
0
 public function __construct()
 {
     $themes = Kernel::getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\Theme')->findAll();
     $choices = [];
     $finder = new Finder();
     // Extracting the PHP files from every Theme folder
     $iterator = $finder->followLinks()->files()->name('config.yml')->depth(1)->in(ROADIZ_ROOT . '/themes');
     // And storing it into an array, used in the form
     foreach ($iterator as $file) {
         $yaml = new YamlConfiguration($file->getPathname());
         $yaml->load();
         $data = $yaml->getConfiguration();
         $classname = '\\Themes\\' . $data['themeDir'] . "\\" . $data['themeDir'] . "App";
         /*
          * Parsed file is not or does not contain any PHP Class
          * Bad Theme !
          */
         $choices[$classname] = $data['name'];
     }
     foreach ($themes as $theme) {
         if (array_key_exists($theme->getClassName(), $choices)) {
             unset($choices[$theme->getClassName()]);
         }
         if (array_key_exists(Kernel::INSTALL_CLASSNAME, $choices)) {
             unset($choices[Kernel::INSTALL_CLASSNAME]);
         }
     }
     $this->choices = $choices;
 }
Ejemplo n.º 2
0
 /**
  * get Theme informations.
  *
  * @param RZ\Roadiz\Core\Entities\Theme $theme
  *
  * @return array
  */
 public static function getThemeInformation($classname)
 {
     $array = explode('\\', $classname);
     $file = ROADIZ_ROOT . "/themes/" . $array[2] . "/config.yml";
     $yaml = new YamlConfiguration($file);
     $yaml->load();
     $data = $yaml->getConfiguration();
     return $data;
 }
Ejemplo n.º 3
0
 /**
  * Install database screen.
  *
  * @param Symfony\Component\HttpFoundation\Request $request
  *
  * @return Symfony\Component\HttpFoundation\Response
  */
 public function databaseAction(Request $request)
 {
     $config = new YamlConfiguration();
     if (false === $config->load()) {
         $config->setConfiguration($config->getDefaultConfiguration());
     }
     $databaseForm = $this->buildDatabaseForm($request, $config);
     if ($databaseForm !== null) {
         $databaseForm->handleRequest($request);
         if ($databaseForm->isValid()) {
             try {
                 $config->testDoctrineConnexion($databaseForm->getData());
                 $tempConf = $config->getConfiguration();
                 foreach ($databaseForm->getData() as $key => $value) {
                     $tempConf['doctrine'][$key] = $value;
                 }
                 $config->setConfiguration($tempConf);
                 /*
                  * Test connexion
                  */
                 try {
                     $fixtures = new Fixtures($this->getService('em'), $request);
                     $fixtures->createFolders();
                     $config->writeConfiguration();
                     /*
                      * Need to clear configuration cache.
                      */
                     $configurationClearer = new ConfigurationCacheClearer();
                     $configurationClearer->clear();
                     /*
                      * Force redirect to avoid resending form when refreshing page
                      */
                     return $this->redirect($this->generateUrl('installDatabaseSchemaPage'));
                 } catch (\PDOException $e) {
                     $message = "";
                     if (strstr($e->getMessage(), 'SQLSTATE[')) {
                         preg_match('/SQLSTATE\\[(\\w+)\\] \\[(\\w+)\\] (.*)/', $e->getMessage(), $matches);
                         $message = $matches[3];
                     } else {
                         $message = $e->getMessage();
                     }
                     $this->assignation['error'] = true;
                     $this->assignation['errorMessage'] = ucfirst($message);
                 } catch (\Exception $e) {
                     $this->assignation['error'] = true;
                     $this->assignation['errorMessage'] = $e->getMessage() . PHP_EOL . $e->getTraceAsString();
                 }
             } catch (\Exception $e) {
                 $this->assignation['error'] = true;
                 $this->assignation['errorMessage'] = $e->getMessage();
             }
         }
         $this->assignation['databaseForm'] = $databaseForm->createView();
     }
     return $this->render('steps/database.html.twig', $this->assignation);
 }
 /**
  * @param Pimple\Container $container [description]
  */
 public function register(Container $container)
 {
     parent::register($container);
     /*
      * Inject app config
      */
     $container['config'] = function ($c) {
         $configuration = new YamlConfiguration();
         if (false !== $configuration->load()) {
             return $configuration->getConfiguration();
         } else {
             throw new NoYamlConfigurationFoundException();
         }
     };
     return $container;
 }
Ejemplo n.º 5
0
 /**
  * Install success screen.
  *
  * @param Symfony\Component\HttpFoundation\Request $request
  *
  * @return Symfony\Component\HttpFoundation\Response
  */
 public function doneAction(Request $request)
 {
     $doneForm = $this->buildDoneForm($request);
     if ($doneForm !== null) {
         $doneForm->handleRequest($request);
         if ($doneForm->isValid() && $doneForm->getData()['action'] == 'quit_install') {
             /*
              * Save informations
              */
             try {
                 $config = new YamlConfiguration();
                 if (false === $config->load()) {
                     $config->setConfiguration($config->getDefaultConfiguration());
                 }
                 $configuration = $config->getConfiguration();
                 $configuration['install'] = false;
                 $config->setConfiguration($configuration);
                 $config->writeConfiguration();
                 /*
                  * Close Session for security and temp translation
                  */
                 $this->getService('session')->invalidate();
                 $clearers = [new DoctrineCacheClearer($this->getService('em')), new TranslationsCacheClearer(), new RoutingCacheClearer(), new ConfigurationCacheClearer()];
                 foreach ($clearers as $clearer) {
                     $clearer->clear();
                 }
                 /*
                  * Force redirect to avoid resending form when refreshing page
                  */
                 return $this->redirect($this->generateUrl('installHomePage'));
             } catch (\Exception $e) {
                 $this->assignation['error'] = true;
                 $this->assignation['errorMessage'] = $e->getMessage() . PHP_EOL . $e->getTraceAsString();
             }
         }
         $this->assignation['doneForm'] = $doneForm->createView();
     }
     return $this->render('steps/done.html.twig', $this->assignation);
 }
Ejemplo n.º 6
0
 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;
     }
 }
Ejemplo n.º 7
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $text = "";
     $configuration = new YamlConfiguration();
     if (false === $configuration->load()) {
         $configuration->setConfiguration($configuration->getDefaultConfiguration());
     }
     if ($input->getOption('enable-devmode')) {
         $configuration->setDevMode(true);
         $configuration->writeConfiguration();
         $text .= '<info>Dev mode has been changed to true</info>' . PHP_EOL;
     }
     if ($input->getOption('disable-devmode')) {
         $configuration->setDevMode(false);
         $configuration->writeConfiguration();
         $text .= '<info>Dev mode has been changed to false</info>' . PHP_EOL;
         $text .= 'Do not forget to empty all cache and purge XCache/APC caches manually.' . PHP_EOL;
     }
     if ($input->getOption('enable-install')) {
         $configuration->setInstall(true);
         $configuration->setDevMode(true);
         $configuration->writeConfiguration();
         $text .= '<info>Install mode has been changed to true</info>' . PHP_EOL;
     }
     if ($input->getOption('disable-install')) {
         $configuration->setInstall(false);
         $configuration->writeConfiguration();
         $text .= '<info>Install mode has been changed to false</info>' . PHP_EOL;
         $text .= 'Do not forget to empty all cache and purge XCache/APC caches manually.' . PHP_EOL;
     }
     if ($input->getOption('generate-htaccess')) {
         $text .= '<info>Generating .htaccess files…</info>' . PHP_EOL;
         // Simple deny access files
         $this->protectFolders(["/conf", "/src", "/samples", "/gen-src", "/files/fonts", "/files/private", "/bin", "/tests", "/cache", "/logs"], $text);
         $filePath = ROADIZ_ROOT . "/.htaccess";
         if (file_exists(ROADIZ_ROOT) && !file_exists($filePath)) {
             file_put_contents($filePath, $this->getMainHtaccessContent() . PHP_EOL);
             $text .= '    — ' . $filePath . PHP_EOL;
         } else {
             $text .= '    — Can’t write ' . $filePath . ", file already exists or folder is absent." . PHP_EOL;
         }
     }
     $output->writeln($text);
 }
Ejemplo n.º 8
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.º 9
0
 /**
  * @param array $data
  *
  * @return void
  */
 public function saveInformations($data)
 {
     /*
      * Save settings
      */
     $set1 = $this->getSetting('site_name');
     $set1->setValue($data['site_name']);
     $set1->setType(NodeTypeField::STRING_T);
     $set2 = $this->getSetting('email_sender');
     $set2->setValue($data['email_sender']);
     $set2->setType(NodeTypeField::EMAIL_T);
     $set2 = $this->getSetting('email_sender_name');
     $set2->setValue($data['email_sender_name']);
     $set2->setType(NodeTypeField::STRING_T);
     $set2 = $this->getSetting('seo_description');
     $set2->setValue($data['seo_description']);
     $set2->setType(NodeTypeField::TEXT_T);
     $set2 = $this->getSetting('display_debug_panel');
     $set2->setValue(false);
     $set2->setType(NodeTypeField::BOOLEAN_T);
     $this->entityManager->flush();
     /*
      * Update timezone
      */
     if (!empty($data['timezone'])) {
         $conf = new YamlConfiguration();
         if (false === $conf->load()) {
             $conf->setConfiguration($conf->getDefaultConfiguration());
         }
         $config = $conf->getConfiguration();
         $config['timezone'] = $data['timezone'];
         $conf->setConfiguration($config);
         $conf->writeConfiguration();
     }
 }
Ejemplo n.º 10
0
 /**
  * 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);
 }
Ejemplo n.º 11
0
 /**
  * Theme summary screen
  *
  * @param Symfony\Component\HttpFoundation\Request $request
  *
  * @return Symfony\Component\HttpFoundation\Response
  */
 public function themeSummaryAction(Request $request)
 {
     $array = explode('\\', $request->get("classname"));
     $file = ROADIZ_ROOT . "/themes/" . $array[2] . "/config.yml";
     $yaml = new YamlConfiguration($file);
     $yaml->load();
     $data = $yaml->getConfiguration();
     $this->assignation["theme"] = ["name" => $data["name"], "version" => $data["versionRequire"], "supportedLocale" => $data["supportedLocale"], "imports" => $data["importFiles"]];
     $this->assignation["cms"] = ["version" => Kernel::$cmsVersion];
     $this->assignation["status"] = [];
     $this->assignation["status"]["version"] = version_compare($data["versionRequire"], Kernel::$cmsVersion) <= 0 ? true : false;
     $this->assignation["cms"]["locale"] = $request->getLocale();
     $this->assignation["status"]["locale"] = in_array($request->getLocale(), $data["supportedLocale"]);
     $this->assignation["status"]["import"] = [];
     $this->assignation['theme']['haveFileImport'] = false;
     foreach ($data["importFiles"] as $name => $filenames) {
         foreach ($filenames as $filename) {
             $this->assignation["status"]["import"][$filename] = file_exists(ROADIZ_ROOT . "/themes/" . $array[2] . "/" . $filename);
             $this->assignation['theme']['haveFileImport'] = true;
         }
     }
     $this->assignation['classname'] = $request->get("classname");
     return $this->render('steps/themeSummary.html.twig', $this->assignation);
 }