Esempio n. 1
0
 /**
  * @return void
  */
 protected function installDefaultTranslation()
 {
     $existing = $this->entityManager->getRepository('RZ\\Roadiz\\Core\\Entities\\Translation')->findOneBy(['defaultTranslation' => true, 'available' => true]);
     if (null === $existing) {
         $translation = new Translation();
         /*
          * Create a translation according to
          * current language
          */
         if (null !== $this->request) {
             $translation->setLocale($this->request->getLocale());
         } else {
             $translation->setLocale('en');
         }
         $translation->setDefaultTranslation(true);
         $translation->setName(Translation::$availableLocales[$translation->getLocale()]);
         $translation->setAvailable(true);
         $this->entityManager->persist($translation);
     }
 }
Esempio 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);
 }
 public static function getUrlProvider()
 {
     $sources = array();
     /*
      * Test 1 - regular node
      */
     $n1 = new Node();
     $n1->setNodeName('page');
     $t1 = new Translation();
     $t1->setLocale('fr');
     $t1->setDefaultTranslation(true);
     $t1->setAvailable(true);
     $ns1 = new NodesSources($n1, $t1);
     $sources[] = array($ns1, '/page');
     /*
      * Test 2  - regular node
      */
     $n2 = new Node();
     $n2->setNodeName('page');
     $t2 = new Translation();
     $t2->setLocale('en');
     $t2->setDefaultTranslation(false);
     $t2->setAvailable(true);
     $ns2 = new NodesSources($n2, $t2);
     $sources[] = array($ns2, '/en/page');
     /*
      * Test 3 - home node
      */
     $n3 = new Node();
     $n3->setNodeName('page');
     $n3->setHome(true);
     $t3 = new Translation();
     $t3->setLocale('fr');
     $t3->setDefaultTranslation(true);
     $t3->setAvailable(true);
     $ns3 = new NodesSources($n3, $t3);
     $sources[] = array($ns3, '/');
     /*
      * Test 4 - home node non-default
      */
     $n4 = new Node();
     $n4->setNodeName('page');
     $n4->setHome(true);
     $t4 = new Translation();
     $t4->setLocale('en');
     $t4->setDefaultTranslation(false);
     $t4->setAvailable(true);
     $ns4 = new NodesSources($n4, $t4);
     $sources[] = array($ns4, '/en');
     /*
      * Test 5  - regular node with alias
      */
     $n5 = new Node();
     $n5->setNodeName('page');
     $t5 = new Translation();
     $t5->setLocale('en');
     $t5->setDefaultTranslation(false);
     $t5->setAvailable(true);
     $ns5 = new NodesSources($n5, $t5);
     $a5 = new Urlalias($ns5);
     $a5->setAlias('tralala-en');
     $ns5->getUrlAliases()->add($a5);
     $sources[] = array($ns5, '/tralala-en');
     /*
      * Test 6  - regular node with 1 parent
      */
     $n6 = new Node();
     $n6->setNodeName('other-page');
     $t6 = new Translation();
     $t6->setLocale('en');
     $t6->setDefaultTranslation(true);
     $t6->setAvailable(true);
     $ns6 = new NodesSources($n6, $t6);
     $ns6->getHandler()->setParentNodeSource($ns1);
     $sources[] = array($ns6, '/page/other-page');
     /*
      * Test 7  - regular node with 2 parents
      */
     $n7 = new Node();
     $n7->setNodeName('sub-page');
     $t7 = new Translation();
     $t7->setLocale('en');
     $t7->setDefaultTranslation(true);
     $t7->setAvailable(true);
     $ns7 = new NodesSources($n7, $t7);
     $ns7->getHandler()->setParentNodeSource($ns6);
     $sources[] = array($ns7, '/page/other-page/sub-page');
     /*
      * Test 8  - regular node with 1 parent and 2 alias
      */
     $n8 = new Node();
     $n8->setNodeName('other-page-alias');
     $t8 = new Translation();
     $t8->setLocale('en');
     $t8->setDefaultTranslation(true);
     $t8->setAvailable(true);
     $ns8 = new NodesSources($n8, $t8);
     $a8 = new Urlalias($ns8);
     $a8->setAlias('other-tralala-en');
     $ns8->getUrlAliases()->add($a8);
     $ns8->getHandler()->setParentNodeSource($ns5);
     $sources[] = array($ns8, '/tralala-en/other-tralala-en');
     /*
      * Test 9 - hidden node
      */
     $n9 = new Node();
     $n9->setNodeName('pagehidden');
     $n9->setVisible(false);
     $t9 = new Translation();
     $t9->setLocale('fr');
     $t9->setDefaultTranslation(true);
     $t9->setAvailable(true);
     $ns9 = new NodesSources($n9, $t9);
     $sources[] = array($ns9, '/pagehidden');
     /*
      * Test 10 - regular node with hidden parent
      */
     $n10 = new Node();
     $n10->setNodeName('page-with-hidden-parent');
     $t10 = new Translation();
     $t10->setLocale('fr');
     $t10->setDefaultTranslation(true);
     $t10->setAvailable(true);
     $ns10 = new NodesSources($n10, $t10);
     $ns10->getHandler()->setParentNodeSource($ns9);
     $sources[] = array($ns10, '/page-with-hidden-parent');
     return $sources;
 }