/** * 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. The * filename php://stdin can be used to read from standard input. * * 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) { $exceedingArguments = $this->request->getExceedingArguments(); if (isset($exceedingArguments[0]) && $packageKey === null && $filename === null) { if (file_exists($exceedingArguments[0])) { $filename = $exceedingArguments[0]; } elseif ($this->packageManager->isPackageAvailable($exceedingArguments[0])) { $packageKey = $exceedingArguments[0]; } } if ($packageKey === null && $filename === null) { $this->outputLine('You have to specify either "--package-key" or "--filename"'); $this->quit(1); } $site = null; if ($filename !== null) { try { $site = $this->siteImportService->importFromFile($filename); } catch (\Exception $exception) { $this->systemLogger->logException($exception); $this->outputLine('Error: During the import of the file "%s" an exception occurred: %s, see log for further information.', array($filename, $exception->getMessage())); $this->quit(1); } } else { try { $site = $this->siteImportService->importFromPackage($packageKey); } catch (\Exception $exception) { $this->systemLogger->logException($exception); $this->outputLine('Error: During the import of the "Sites.xml" from the package "%s" an exception occurred: %s, see log for further information.', array($packageKey, $exception->getMessage())); $this->quit(1); } } $this->outputLine('Import of site "%s" finished.', array($site->getName())); }
/** * Kickstart a new site package * * This command generates a new site package with basic TypoScript and Sites.xml * * @param string $packageKey The packageKey for your site * @param string $siteName The siteName of your site * @return string */ public function siteCommand($packageKey, $siteName) { if (!$this->packageManager->isPackageKeyValid($packageKey)) { $this->outputLine('Package key "%s" is not valid. Only UpperCamelCase in the format "Vendor.PackageKey", please!', array($packageKey)); $this->quit(1); } if ($this->packageManager->isPackageAvailable($packageKey)) { $this->outputLine('Package "%s" already exists.', array($packageKey)); $this->quit(1); } $generatedFiles = $this->generatorService->generateSitePackage($packageKey, $siteName); $this->outputLine(implode(PHP_EOL, $generatedFiles)); }
/** * Kickstart a new site package * * This command generates a new site package with basic TypoScript and Sites.xml * * @param string $packageKey The packageKey for your site * @param string $siteName The siteName of your site * @return string */ public function siteCommand($packageKey, $siteName) { if (!$this->packageManager->isPackageKeyValid($packageKey)) { $this->outputLine('Package key "%s" is not valid. Only UpperCamelCase with alphanumeric characters and underscore, please!', array($packageKey)); $this->quit(1); } if ($this->packageManager->isPackageAvailable($packageKey)) { $this->outputLine('Package "%s" already exists.', array($packageKey)); $this->quit(1); } $generatedFiles = $this->generatorService->generateSitePackage($packageKey, $siteName); $this->outputLine(implode(PHP_EOL, $generatedFiles)); }
/** * 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); } } }
/** * Evaluates the absolute path and filename of the resource file specified * by the given path. * * @param string $requestedPath * @param boolean $checkForExistence Whether a (non-hash) path should be checked for existence before being returned * @return mixed The full path and filename or FALSE if the file doesn't exist * @throws \TYPO3\Flow\Resource\Exception * @throws \InvalidArgumentException */ protected function evaluateResourcePath($requestedPath, $checkForExistence = TRUE) { if (substr($requestedPath, 0, strlen(self::SCHEME)) !== self::SCHEME) { throw new \InvalidArgumentException('The ' . __CLASS__ . ' only supports the \'' . self::SCHEME . '\' scheme.', 1256052544); } $uriParts = parse_url($requestedPath); if (!is_array($uriParts) || !isset($uriParts['host'])) { return FALSE; } if (preg_match('/^[0-9a-f]{40}$/i', $uriParts['host']) === 1) { $resourcePath = $this->resourceManager->getPersistentResourcesStorageBaseUri() . $uriParts['host']; if ($checkForExistence === FALSE || file_exists($resourcePath)) { return $resourcePath; } else { return FALSE; } } if (!$this->packageManager->isPackageAvailable($uriParts['host'])) { throw new \TYPO3\Flow\Resource\Exception(sprintf('Invalid resource URI "%s": Package "%s" is not available.', $requestedPath, $uriParts['host']), 1309269952); } $package = $this->packageManager->getPackage($uriParts['host']); $resourcePath = \TYPO3\Flow\Utility\Files::concatenatePaths(array($package->getResourcesPath(), $uriParts['path'])); if ($checkForExistence === FALSE || file_exists($resourcePath)) { return $resourcePath; } return FALSE; }
/** * Kickstart a new CRUD Controller * * @param string $packageKey The package key of the package for the new controller with an optional subpackage, (e.g. "MyCompany.MyPackage/Admin"). * @param string $controllerName The name for the new controller. This may also be a comma separated list of controller names. * @param string $modelName The model class name. Either fully-qualified or assumed to be in $packageKey. * @param boolean $override override generated classes? * @return string * @see typo3.kickstart:kickstart:commandcontroller */ public function crudControllerCommand($packageKey, $controllerName, $modelName, $overwrite = FALSE) { $subpackageName = ''; if (strpos($packageKey, '/') !== FALSE) { list($packageKey, $subpackageName) = explode('/', $packageKey, 2); } $this->validatePackageKey($packageKey); if (!$this->packageManager->isPackageAvailable($packageKey)) { $this->outputLine('Package "%s" is not available.', array($packageKey)); exit(2); } $generatedFiles = array(); $generatedFiles += $this->crudGeneratorService->generateCrudController($packageKey, $subpackageName, $controllerName, $modelName, $overwrite); $generatedFiles += $this->crudGeneratorService->generateCrudAction($packageKey, $subpackageName, $controllerName, $modelName, 'Index', $overwrite); $generatedFiles += $this->crudGeneratorService->generateCrudAction($packageKey, $subpackageName, $controllerName, $modelName, 'New', $overwrite); $generatedFiles += $this->crudGeneratorService->generateCrudAction($packageKey, $subpackageName, $controllerName, $modelName, 'Edit', $overwrite); $this->outputLine(implode(PHP_EOL, $generatedFiles)); }
/** * Kickstart a new domain repository * * This command generates a new domain repository class for the given model name. * * @param string $packageKey The package key * @param string $modelName The name of the domain model class * @param boolean $force Overwrite any existing repository. * @return string * @see typo3.kickstart:kickstart:model */ public function repositoryCommand($packageKey, $modelName, $force = FALSE) { $this->validatePackageKey($packageKey); if (!$this->packageManager->isPackageAvailable($packageKey)) { $this->outputLine('Package "%s" is not available.', array($packageKey)); exit(2); } $generatedFiles = $this->generatorService->generateRepository($packageKey, $modelName, $force); $this->outputLine(implode(PHP_EOL, $generatedFiles)); }
/** * Kickstart documentation * * Generates a documentation skeleton for the given package. * * @param string $packageKey The package key of the package for the documentation * @return string */ public function documentationCommand($packageKey) { $this->validatePackageKey($packageKey); if (!$this->packageManager->isPackageAvailable($packageKey)) { $this->outputLine('Package "%s" is not available.', array($packageKey)); exit(2); } $generatedFiles = $this->generatorService->generateDocumentation($packageKey); $this->outputLine(implode(PHP_EOL, $generatedFiles)); }
/** * Imports one or multiple sites from the XML file at $pathAndFilename * * @param string $pathAndFilename * @return Site The imported site * @throws UnknownPackageException|InvalidPackageStateException|NeosException */ public function importFromFile($pathAndFilename) { /** @var Site $importedSite */ $site = NULL; $this->eventEmittingService->withoutEventLog(function () use($pathAndFilename, &$site) { $xmlReader = new \XMLReader(); $xmlReader->open($pathAndFilename, NULL, LIBXML_PARSEHUGE); if ($this->workspaceRepository->findOneByName('live') === NULL) { $this->workspaceRepository->add(new Workspace('live')); } $rootNode = $this->contextFactory->create()->getRootNode(); $this->persistenceManager->persistAll(); $sitesNode = $rootNode->getNode('/sites'); if ($sitesNode === NULL) { $sitesNode = $rootNode->createSingleNode('sites'); } while ($xmlReader->read()) { if ($xmlReader->nodeType != \XMLReader::ELEMENT || $xmlReader->name !== 'site') { continue; } $isLegacyFormat = $xmlReader->getAttribute('nodeName') !== NULL && $xmlReader->getAttribute('state') === NULL && $xmlReader->getAttribute('siteResourcesPackageKey') === NULL; if ($isLegacyFormat) { $site = $this->legacySiteImportService->importSitesFromFile($pathAndFilename); return; } $site = $this->getSiteByNodeName($xmlReader->getAttribute('siteNodeName')); $site->setName($xmlReader->getAttribute('name')); $site->setState((int) $xmlReader->getAttribute('state')); $siteResourcesPackageKey = $xmlReader->getAttribute('siteResourcesPackageKey'); if (!$this->packageManager->isPackageAvailable($siteResourcesPackageKey)) { throw new UnknownPackageException(sprintf('Package "%s" specified in the XML as site resources package does not exist.', $siteResourcesPackageKey), 1303891443); } if (!$this->packageManager->isPackageActive($siteResourcesPackageKey)) { throw new InvalidPackageStateException(sprintf('Package "%s" specified in the XML as site resources package is not active.', $siteResourcesPackageKey), 1303898135); } $site->setSiteResourcesPackageKey($siteResourcesPackageKey); $rootNode = $this->contextFactory->create()->getRootNode(); // We fetch the workspace to be sure it's known to the persistence manager and persist all // so the workspace and site node are persisted before we import any nodes to it. $rootNode->getContext()->getWorkspace(); $this->persistenceManager->persistAll(); $sitesNode = $rootNode->getNode('/sites'); if ($sitesNode === NULL) { $sitesNode = $rootNode->createNode('sites'); } $this->nodeImportService->import($xmlReader, $sitesNode->getPath(), dirname($pathAndFilename) . '/Resources'); } }); if ($site === NULL) { throw new NeosException(sprintf('The XML file did not contain a valid site node.'), 1418999522); } $this->emitSiteImported($site); return $site; }
/** * @param string $packageKey * @return void */ public function deactivateAction($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) === false) { $this->flashMessageContainer->addMessage(new \TYPO3\Flow\Error\Error('Package ' . $packageKey . ' is currently not activated.')); $this->redirect('index'); } if ($requiredBy = $this->packageDependencyService->getPackageRequirements($packageKey)) { $this->flashMessageContainer->addMessage(new \TYPO3\Flow\Error\Error('Package ' . $packageKey . ' is required by ' . $requiredBy)); $this->redirect('index'); } $this->packageManager->deactivatePackage($packageKey); $this->redirect('index'); }
/** * Imports one or multiple sites from the XML file at $pathAndFilename * * @param string $pathAndFilename * @return Site The imported site or NULL if not successful * @throws UnknownPackageException * @throws InvalidPackageStateException */ public function importSitesFromFile($pathAndFilename) { $contentContext = $this->createContext(); $sitesXmlString = $this->loadSitesXml($pathAndFilename); if (defined('LIBXML_PARSEHUGE')) { $options = LIBXML_PARSEHUGE; } else { $options = 0; } $site = null; $sitesXml = new \SimpleXMLElement($sitesXmlString, $options); foreach ($sitesXml->site as $siteXml) { $site = $this->getSiteByNodeName((string) $siteXml['nodeName']); if ((string) $siteXml->properties->name !== '') { $site->setName((string) $siteXml->properties->name); } $site->setState((int) $siteXml->properties->state); $siteResourcesPackageKey = (string) $siteXml->properties->siteResourcesPackageKey; if (!$this->packageManager->isPackageAvailable($siteResourcesPackageKey)) { throw new UnknownPackageException(sprintf('Package "%s" specified in the XML as site resources package does not exist.', $siteResourcesPackageKey), 1303891443); } if (!$this->packageManager->isPackageActive($siteResourcesPackageKey)) { throw new InvalidPackageStateException(sprintf('Package "%s" specified in the XML as site resources package is not active.', $siteResourcesPackageKey), 1303898135); } $site->setSiteResourcesPackageKey($siteResourcesPackageKey); $rootNode = $contentContext->getRootNode(); $sitesNode = $rootNode->getNode(SiteService::SITES_ROOT_PATH); if ($sitesNode === null) { $sitesNode = $rootNode->createSingleNode(NodePaths::getNodeNameFromPath(SiteService::SITES_ROOT_PATH)); } // We fetch the workspace to be sure it's known to the persistence manager and persist all // so the workspace and site node are persisted before we import any nodes to it. $rootNode->getContext()->getWorkspace(); $this->persistenceManager->persistAll(); if ($siteXml['type'] === null) { $this->upgradeLegacySiteXml($siteXml, $site); } $this->importNode($siteXml, $sitesNode); } return $site; }
/** * Replace resource on an asset. Takes variants and redirect handling into account. * * @param AssetInterface $asset * @param FlowResource $resource * @param array $options * @return void */ public function replaceAssetResource(AssetInterface $asset, FlowResource $resource, array $options = []) { $originalAssetResource = $asset->getResource(); $asset->setResource($resource); if (isset($options['keepOriginalFilename']) && (bool) $options['keepOriginalFilename'] === true) { $asset->getResource()->setFilename($originalAssetResource->getFilename()); } $uriMapping = []; $redirectHandlerEnabled = isset($options['generateRedirects']) && (bool) $options['generateRedirects'] === true && $this->packageManager->isPackageAvailable('Neos.RedirectHandler'); if ($redirectHandlerEnabled) { $uriMapping[$this->resourceManager->getPublicPersistentResourceUri($originalAssetResource)] = $this->resourceManager->getPublicPersistentResourceUri($asset->getResource()); } if (method_exists($asset, 'getVariants')) { $variants = $asset->getVariants(); foreach ($variants as $variant) { $originalVariantResource = $variant->getResource(); $variant->refresh(); foreach ($variant->getAdjustments() as $adjustment) { if (method_exists($adjustment, 'refit')) { $adjustment->refit($asset); } } if ($redirectHandlerEnabled) { $uriMapping[$this->resourceManager->getPublicPersistentResourceUri($originalVariantResource)] = $this->resourceManager->getPublicPersistentResourceUri($variant->getResource()); } $this->getRepository($variant)->update($variant); } } if ($redirectHandlerEnabled) { /** @var \Neos\RedirectHandler\Storage\RedirectStorageInterface $redirectStorage */ $redirectStorage = $this->objectManager->get(\Neos\RedirectHandler\Storage\RedirectStorageInterface::class); foreach ($uriMapping as $originalUri => $newUri) { $existingRedirect = $redirectStorage->getOneBySourceUriPathAndHost($originalUri); if ($existingRedirect === null) { $redirectStorage->addRedirect($originalUri, $newUri, 301); } } } $this->getRepository($asset)->update($asset); $this->emitAssetResourceReplaced($asset); }
/** * Refreeze a package * * Refreezes a currently frozen package: all precompiled information is removed * and file monitoring will consider the package exactly once, on the next * request. After that request, the package remains frozen again, just with the * updated data. * * By specifying <b>all</b> as a package key, all currently frozen packages are * refrozen (the default). * * @param string $packageKey Key of the package to refreeze, or 'all' * @return void * @see typo3.flow:package:freeze * @see typo3.flow:cache:flush */ public function refreezeCommand($packageKey = 'all') { if (!$this->bootstrap->getContext()->isDevelopment()) { $this->outputLine('Package freezing is only supported in Development context.'); $this->quit(3); } $packagesToRefreeze = []; if ($packageKey === 'all') { foreach (array_keys($this->packageManager->getAvailablePackages()) as $packageKey) { if ($this->packageManager->isPackageFrozen($packageKey)) { $packagesToRefreeze[] = $packageKey; } } if ($packagesToRefreeze === []) { $this->outputLine('Nothing to do, no packages were frozen.'); $this->quit(0); } } else { if ($packageKey === null) { $this->outputLine('You must specify a package to refreeze.'); $this->quit(1); } if (!$this->packageManager->isPackageAvailable($packageKey)) { $this->outputLine('Package "%s" is not available.', [$packageKey]); $this->quit(2); } if (!$this->packageManager->isPackageFrozen($packageKey)) { $this->outputLine('Package "%s" was not frozen.', [$packageKey]); $this->quit(0); } $packagesToRefreeze = [$packageKey]; } foreach ($packagesToRefreeze as $packageKey) { $this->packageManager->refreezePackage($packageKey); $this->outputLine('Refroze package "%s".', [$packageKey]); } Scripts::executeCommand('typo3.flow:cache:flush', $this->settings, false); $this->sendAndExit(0); }
/** * Evaluates the absolute path and filename of the resource file specified * by the given path. * * @param string $requestedPath * @param boolean $checkForExistence Whether a (non-hash) path should be checked for existence before being returned * @return mixed The full path and filename or FALSE if the file doesn't exist * @throws \InvalidArgumentException|Exception */ protected function evaluateResourcePath($requestedPath, $checkForExistence = true) { if (substr($requestedPath, 0, strlen(self::SCHEME)) !== self::SCHEME) { throw new \InvalidArgumentException('The ' . __CLASS__ . ' only supports the \'' . self::SCHEME . '\' scheme.', 1256052544); } $uriParts = Functions::parse_url($requestedPath); if (!is_array($uriParts) || !isset($uriParts['host'])) { return false; } if (preg_match('/^[0-9a-f]{40}$/i', $uriParts['host']) === 1) { $resource = $this->resourceManager->getResourceBySha1($uriParts['host']); return $this->resourceManager->getStreamByResource($resource); } if (!$this->packageManager->isPackageAvailable($uriParts['host'])) { throw new Exception(sprintf('Invalid resource URI "%s": Package "%s" is not available.', $requestedPath, $uriParts['host']), 1309269952); } $package = $this->packageManager->getPackage($uriParts['host']); $resourceUri = Files::concatenatePaths(array($package->getResourcesPath(), $uriParts['path'])); if ($checkForExistence === false || file_exists($resourceUri)) { return $resourceUri; } return false; }
/** * @param Asset $asset * @return void */ public function replaceAssetResourceAction(Asset $asset) { $maximumFileUploadSize = $this->maximumFileUploadSize(); $this->view->assignMultiple(array('asset' => $asset, 'maximumFileUploadSize' => $maximumFileUploadSize, 'redirectPackageEnabled' => $this->packageManager->isPackageAvailable('Neos.RedirectHandler'), 'humanReadableMaximumFileUploadSize' => Files::bytesToSizeString($maximumFileUploadSize))); }