/**
  * Create a new site.
  *
  * @param string $site Site to import
  * @param string $packageKey Package Name to create
  * @param string $siteName Site Name to create
  * @Flow\Validate(argumentName="$packageKey", type="\TYPO3\Neos\Validation\Validator\PackageKeyValidator")
  * @return void
  */
 public function createSiteAction($site, $packageKey = '', $siteName = '')
 {
     if ($packageKey !== '' && $this->packageManager->isPackageActive('TYPO3.Neos.Kickstarter')) {
         if ($this->packageManager->isPackageAvailable($packageKey)) {
             $this->addFlashMessage('The package key "%s" already exists.', 'Invalid package key', Message::SEVERITY_ERROR, array(htmlspecialchars($packageKey)), 1412372021);
             $this->redirect('index');
         }
         $generatorService = $this->objectManager->get('TYPO3\\Neos\\Kickstarter\\Service\\GeneratorService');
         $generatorService->generateSitePackage($packageKey, $siteName);
     } else {
         $packageKey = $site;
     }
     $deactivatedSitePackages = $this->deactivateAllOtherSitePackages($packageKey);
     if (count($deactivatedSitePackages) > 0) {
         $this->flashMessageContainer->addMessage(new Message(sprintf('The existing Site Packages "%s" were deactivated, in order to prevent interactions with the newly created package "%s".', htmlspecialchars(implode(', ', $deactivatedSitePackages)), htmlspecialchars($packageKey))));
     }
     $this->packageManager->activatePackage($packageKey);
     if ($packageKey !== '') {
         try {
             $this->siteImportService->importFromPackage($packageKey);
             $this->addFlashMessage('The site has been created.', '', null, array(), 1412372266);
         } catch (\Exception $exception) {
             $this->systemLogger->logException($exception);
             $this->addFlashMessage('Error: During the import of the "Sites.xml" from the package "%s" an exception occurred: %s', 'Import error', Message::SEVERITY_ERROR, array(htmlspecialchars($packageKey), htmlspecialchars($exception->getMessage())), 1412372375);
         }
     } else {
         $this->addFlashMessage('No site selected for import and no package name provided.', 'No site selected', Message::SEVERITY_ERROR, array(), 1412372554);
         $this->redirect('newSite');
     }
     $this->unsetLastVisitedNodeAndRedirect('index');
 }
 /**
  * @param \TYPO3\Form\Core\Model\FinisherContext $finisherContext
  * @return void
  * @throws \TYPO3\Setup\Exception
  */
 public function importSite(\TYPO3\Form\Core\Model\FinisherContext $finisherContext)
 {
     $formValues = $finisherContext->getFormRuntime()->getFormState()->getFormValues();
     if (isset($formValues['prune']) && intval($formValues['prune']) === 1) {
         $this->nodeDataRepository->removeAll();
         $this->workspaceRepository->removeAll();
         $this->domainRepository->removeAll();
         $this->siteRepository->removeAll();
         $this->persistenceManager->persistAll();
     }
     if (!empty($formValues['packageKey'])) {
         if ($this->packageManager->isPackageAvailable($formValues['packageKey'])) {
             throw new \TYPO3\Setup\Exception(sprintf('The package key "%s" already exists.', $formValues['packageKey']), 1346759486);
         }
         $packageKey = $formValues['packageKey'];
         $siteName = $formValues['siteName'];
         $generatorService = $this->objectManager->get('TYPO3\\Neos\\Kickstarter\\Service\\GeneratorService');
         $generatorService->generateSitePackage($packageKey, $siteName);
     } elseif (!empty($formValues['site'])) {
         $packageKey = $formValues['site'];
     }
     $this->deactivateOtherSitePackages($packageKey);
     $this->packageManager->activatePackage($packageKey);
     if (!empty($packageKey)) {
         try {
             $contentContext = $this->contextFactory->create(array('workspaceName' => 'live'));
             $this->siteImportService->importFromPackage($packageKey, $contentContext);
         } catch (\Exception $exception) {
             $finisherContext->cancel();
             $this->systemLogger->logException($exception);
             throw new SetupException(sprintf('Error: During the import of the "Sites.xml" from the package "%s" an exception occurred: %s', $packageKey, $exception->getMessage()), 1351000864);
         }
     }
 }
 /**
  * @param string $packageKey
  * @return void
  */
 public function activateAction($packageKey)
 {
     if ($this->packageManager->isPackageAvailable($packageKey) === false) {
         $this->flashMessageContainer->addMessage(new \TYPO3\Flow\Error\Error('Package ' . $packageKey . ' does not exists.'));
         $this->redirect('index');
     }
     if ($this->packageManager->isPackageActive($packageKey) === true) {
         $this->flashMessageContainer->addMessage(new \TYPO3\Flow\Error\Error('Package ' . $packageKey . ' is already activated.'));
         $this->redirect('index');
     }
     if ($requiredPackage = $this->packageDependencyService->getMissingPackageRequirements($packageKey)) {
         $this->flashMessageContainer->addMessage(new \TYPO3\Flow\Error\Error('Package ' . $packageKey . ' could not activate. ' . $requiredPackage . ' not active or missing.'));
         $this->redirect('index');
     }
     $this->packageManager->activatePackage($packageKey);
     $this->redirect('index');
 }
 /**
  * @param string $packageKey
  * @return Error|Message
  */
 protected function activatePackage($packageKey)
 {
     try {
         $this->packageManager->activatePackage($packageKey);
         $message = new Message('The package %s is activated', 1343231680, array($packageKey));
     } catch (UnknownPackageException $exception) {
         $message = new Error('The package %s is not present and can not be activated', 1343231681, array($packageKey));
     }
     return $message;
 }
 /**
  * Activate an available package
  *
  * This command activates an existing, but currently inactive package.
  *
  * @Flow\FlushesCaches
  * @param string $packageKey The package key of the package to create
  * @return string
  * @see typo3.flow:package:deactivate
  */
 public function activateCommand($packageKey)
 {
     if (!$this->packageManager->isPackageAvailable($packageKey)) {
         $this->outputLine('The package "%s" does not exist.', [$packageKey]);
         $this->quit(1);
     }
     if ($this->packageManager->isPackageActive($packageKey)) {
         $this->outputLine('Package "%s" is already active.', [$packageKey]);
         $this->quit(1);
     }
     $this->packageManager->activatePackage($packageKey);
     $this->outputLine('Activated package "%s".', [$packageKey]);
     Scripts::executeCommand('typo3.flow:cache:flush', $this->settings, false);
     $this->sendAndExit(0);
 }