/**
  * 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);
 }
Example #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $text = "";
     $this->entityManager = $this->getHelperSet()->get('em')->getEntityManager();
     $this->nsCacheHelper = $this->getHelperSet()->get('ns-cache');
     $assetsClearer = new AssetsClearer();
     $doctrineClearer = new DoctrineCacheClearer($this->entityManager);
     $routingClearer = new RoutingCacheClearer();
     $templatesClearer = new TemplatesCacheClearer();
     $translationsClearer = new TranslationsCacheClearer();
     $configurationClearer = new ConfigurationCacheClearer();
     $nodeSourcesUrlsClearer = new NodesSourcesUrlsCacheClearer($this->nsCacheHelper->getCacheProvider());
     $clearers = [$configurationClearer, $assetsClearer, $doctrineClearer, $routingClearer, $templatesClearer, $translationsClearer, $nodeSourcesUrlsClearer];
     if ($input->getOption('clear-all')) {
         foreach ($clearers as $clearer) {
             $clearer->clear();
             $text .= $clearer->getOutput();
         }
         $text .= '<info>All caches have been been purged…</info>' . PHP_EOL;
     } elseif ($input->getOption('clear-configuration')) {
         $configurationClearer->clear();
         $text .= $configurationClearer->getOutput();
     } elseif ($input->getOption('clear-doctrine')) {
         $doctrineClearer->clear();
         $text .= $doctrineClearer->getOutput();
     } elseif ($input->getOption('clear-routes')) {
         $routingClearer->clear();
         $text .= $routingClearer->getOutput();
     } elseif ($input->getOption('clear-assets')) {
         $assetsClearer->clear();
         $text .= $assetsClearer->getOutput();
     } elseif ($input->getOption('clear-templates')) {
         $templatesClearer->clear();
         $text .= $templatesClearer->getOutput();
     } elseif ($input->getOption('clear-translations')) {
         $translationsClearer->clear();
         $text .= $translationsClearer->getOutput();
     } elseif ($input->getOption('clear-nsurls')) {
         $nodeSourcesUrlsClearer->clear();
         $text .= $nodeSourcesUrlsClearer->getOutput();
     } else {
         $text .= $this->getInformations();
     }
     $output->writeln($text);
 }