示例#1
0
 /**
  * @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->nodeRepository->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['packageKey'];
         $this->packageManager->createPackage($packageKey, NULL, Files::getUnixStylePath(Files::concatenatePaths(array(FLOW3_PATH_PACKAGES, 'Sites'))));
         $this->generatorService->generateSitesXml($packageKey, $siteName);
         $this->generatorService->generateSitesTypoScript($packageKey, $siteName);
         $this->generatorService->generateSitesTemplate($packageKey, $siteName);
         $this->packageManager->activatePackage($packageKey);
     } else {
         $packageKey = $formValues['site'];
     }
     if ($packageKey !== '') {
         try {
             $contentContext = new \TYPO3\TYPO3\Domain\Service\ContentContext('live');
             $this->nodeRepository->setContext($contentContext);
             $this->siteImportService->importFromPackage($packageKey);
         } catch (\Exception $exception) {
             $finisherContext->cancel();
             $this->flashMessageContainer->addMessage(new \TYPO3\FLOW3\Error\Error(sprintf('Error: During the import of the "Sites.xml" from the package "%s" an exception occurred: %s', $packageKey, $exception->getMessage())));
         }
     }
 }
 /**
  * Import sites content
  *
  * This command allows for importing one or more sites or partial content from an XML source. The format must
  * be identical to that produced by the export command.
  *
  * If a filename is specified, this command expects the corresponding file to contain the XML structure
  *
  * If a package key is specified, this command expects a Sites.xml file to be located in the private resources
  * directory of the given package:
  * .../Resources/Private/Content/Sites.xml
  *
  * @param string $packageKey Package key specifying the package containing the sites content
  * @param string $filename relative path and filename to the XML file containing the sites content
  * @return void
  */
 public function importCommand($packageKey = NULL, $filename = NULL)
 {
     $contentContext = new \TYPO3\TYPO3\Domain\Service\ContentContext('live');
     $this->nodeRepository->setContext($contentContext);
     if ($filename !== NULL) {
         try {
             $this->siteImportService->importSitesFromFile($filename);
         } catch (\Exception $exception) {
             $this->outputLine('Error: During the import of the file "%s" an exception occurred: %s', array($filename, $exception->getMessage()));
             $this->quit(1);
         }
     } elseif ($packageKey !== NULL) {
         try {
             $this->siteImportService->importFromPackage($packageKey);
         } catch (\Exception $exception) {
             $this->outputLine('Error: During the import of the "Sites.xml" from the package "%s" an exception occurred: %s', array($packageKey, $exception->getMessage()));
             $this->quit(1);
         }
     } else {
         $this->outputLine('You have to specify either "--package-key" or "--filename"');
         $this->quit(1);
     }
     $this->outputLine('Import finished.');
 }