Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
namespace TYPO3\TYPO3\Setup\Step;
/* *
* This script belongs to the FLOW3 package "TYPO3.Setup". *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* *
* The TYPO3 project - inspiring people to share! *
* */
use TYPO3\FLOW3\Annotations as FLOW3,
TYPO3\Form\Core\Model\FormDefinition;
/**
* @FLOW3\Scope("singleton")
*/
class SiteImportStep extends \TYPO3\Setup\Step\AbstractStep {
/**
* @var \TYPO3\FLOW3\Package\PackageManagerInterface
* @FLOW3\Inject
*/
protected $packageManager;
/**
* @FLOW3\Inject
* @var \TYPO3\TYPO3\Domain\Repository\SiteRepository
*/
protected $siteRepository;
/**
* @FLOW3\Inject
* @var \TYPO3\TYPO3\Domain\Service\SiteImportService
*/
protected $siteImportService;
/**
* @FLOW3\Inject
* @var \TYPO3\TYPO3\Domain\Repository\DomainRepository
*/
protected $domainRepository;
/**
* @FLOW3\Inject
* @var \TYPO3\TYPO3CR\Domain\Repository\NodeRepository
*/
protected $nodeRepository;
/**
* @FLOW3\Inject
* @var \TYPO3\TYPO3CR\Domain\Repository\WorkspaceRepository
*/
protected $workspaceRepository;
/**
* Returns the form definitions for the step
*
* @param \TYPO3\Form\Core\Model\FormDefinition $formDefinition
* @return void
*/
protected function buildForm(\TYPO3\Form\Core\Model\FormDefinition $formDefinition) {
$page1 = $formDefinition->createPage('page1');
$title = $page1->createElement('connectionSection', 'TYPO3.Form:Section');
$title->setLabel('Import a website');
$sitePackages = array();
foreach ($this->packageManager->getActivePackages() as $package) {
$packageMetaData = $package->getPackageMetaData();
if (in_array('Site', $packageMetaData->getCategories())) {
$sitePackages[$package->getPackageKey()] = $packageMetaData->getTitle();
}
}
$site = $page1->createElement('site', 'TYPO3.Form:SingleSelectDropdown');
$site->setLabel('Select a site');
$site->setProperty('options', $sitePackages);
$site->addValidator(new \TYPO3\FLOW3\Validation\Validator\NotEmptyValidator());
$step = $this;
$callback = function(\TYPO3\Form\Core\Runtime\FormRuntime $formRuntime) use ($step) {
$step->importSite($formRuntime->getFormState()->getFormValues());
};
$closureFinisher = new \TYPO3\Form\Finishers\ClosureFinisher();
$closureFinisher->setOption('closure', $callback);
$formDefinition->addFinisher($closureFinisher);
}
/**
* @param array $formValues
* @return void
*/
public function importSite(array $formValues) {
$this->nodeRepository->removeAll();
$this->workspaceRepository->removeAll();
$this->domainRepository->removeAll();
$this->siteRepository->removeAll();
$packageKey = $formValues['site'];
try {
$this->siteImportService->importFromPackage($packageKey);
} catch (\Exception $exception) {
throw new \Exception('Error: During the import of the "Sites.xml" from the package "%s" an exception occurred: %s', array($packageKey, $exception->getMessage()));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.