Returns TRUE if a package is activated or FALSE if it's not.
public isPackageActive ( string $packageKey ) : boolean | ||
$packageKey | string | The key of the package to check |
return | boolean | TRUE if package is active, otherwise FALSE |
/** * Fetches the site with the given name and exports it into XML in the given package. * * @param array<Site> $sites * @param boolean $tidy Whether to export formatted XML * @param string $packageKey Package key where the export output should be saved to * @param string $nodeTypeFilter Filter the node type of the nodes, allows complex expressions (e.g. "Neos.Neos:Page", "!Neos.Neos:Page,Neos.Neos:Text") * @return void * @throws NeosException */ public function exportToPackage(array $sites, $tidy = false, $packageKey, $nodeTypeFilter = null) { if (!$this->packageManager->isPackageActive($packageKey)) { throw new NeosException(sprintf('Error: Package "%s" is not active.', $packageKey), 1404375719); } $contentPathAndFilename = sprintf('resource://%s/Private/Content/Sites.xml', $packageKey); $this->resourcesPath = Files::concatenatePaths(array(dirname($contentPathAndFilename), 'Resources')); Files::createDirectoryRecursively($this->resourcesPath); $this->xmlWriter = new \XMLWriter(); $this->xmlWriter->openUri($contentPathAndFilename); $this->xmlWriter->setIndent($tidy); $this->exportSites($sites, $nodeTypeFilter); $this->xmlWriter->flush(); }
/** * @return void */ public function indexAction() { $packageGroups = array(); foreach ($this->packageManager->getAvailablePackages() as $package) { /** @var Package $package */ $packagePath = substr($package->getPackagepath(), strlen(FLOW_PATH_PACKAGES)); $packageGroup = substr($packagePath, 0, strpos($packagePath, '/')); $packageGroups[$packageGroup][$package->getPackageKey()] = array('sanitizedPackageKey' => str_replace('.', '', $package->getPackageKey()), 'version' => $package->getInstalledVersion(), 'name' => $package->getComposerManifest('name'), 'type' => $package->getComposerManifest('type'), 'description' => $package->getComposerManifest('description'), 'isActive' => $this->packageManager->isPackageActive($package->getPackageKey()), 'isFrozen' => $this->packageManager->isPackageFrozen($package->getPackageKey()), 'isProtected' => $package->isProtected()); } ksort($packageGroups); foreach (array_keys($packageGroups) as $packageGroup) { ksort($packageGroups[$packageGroup]); } $this->view->assignMultiple(array('packageGroups' => $packageGroups, 'isDevelopmentContext' => $this->objectManager->getContext()->isDevelopment())); }
/** * Index action * * @return void */ public function indexAction() { $this->view->assign('flowPathRoot', realpath(FLOW_PATH_ROOT)); $this->view->assign('flowPathWeb', realpath(FLOW_PATH_WEB)); $this->view->assign('isMyPackageActive', $this->packageManager->isPackageActive('MyCompany.MyPackage')); $baseUri = $this->request->getHttpRequest()->getBaseUri(); $this->view->assign('baseUri', $baseUri); $this->view->assign('isWindows', DIRECTORY_SEPARATOR !== '/'); $flowPackage = $this->packageManager->getPackage('Neos.Flow'); $version = $flowPackage->getInstalledVersion(); $this->view->assign('version', $version); $activePackages = $this->packageManager->getActivePackages(); $this->view->assign('activePackages', $activePackages); $this->view->assign('notDevelopmentContext', !$this->objectManager->getContext()->isDevelopment()); }
/** * @param string $packageKey * @return string|null */ protected function getPackagePrivateResourcesPath($packageKey) { if (!$this->packageManager->isPackageActive($packageKey)) { return null; } $packageResourcesPath = $this->packageManager->getPackage($packageKey)->getResourcesPath(); return Files::concatenatePaths([$packageResourcesPath, 'Private']); }
/** * Returns the form definitions for the step * * @param FormDefinition $formDefinition * @return void */ protected function buildForm(FormDefinition $formDefinition) { $page1 = $formDefinition->createPage('page1'); $page1->setRenderingOption('header', 'Create a new site'); $introduction = $page1->createElement('introduction', 'Neos.Form:StaticText'); $introduction->setProperty('text', 'There are two ways of creating a site. Choose between the following:'); $importSection = $page1->createElement('import', 'Neos.Form:Section'); $importSection->setLabel('Import a site from an existing site package'); $sitePackages = array(); foreach ($this->packageManager->getFilteredPackages('available', null, 'neos-site') as $package) { $sitePackages[$package->getPackageKey()] = $package->getPackageKey(); } if (count($sitePackages) > 0) { $site = $importSection->createElement('site', 'Neos.Form:SingleSelectDropdown'); $site->setLabel('Select a site package'); $site->setProperty('options', $sitePackages); $site->addValidator(new NotEmptyValidator()); $sites = $this->siteRepository->findAll(); if ($sites->count() > 0) { $prune = $importSection->createElement('prune', 'Neos.Form:Checkbox'); $prune->setLabel('Delete existing sites'); } } else { $error = $importSection->createElement('noSitePackagesError', 'Neos.Form:StaticText'); $error->setProperty('text', 'No site packages were available, make sure you have an active site package'); $error->setProperty('elementClassAttribute', 'alert alert-warning'); } if ($this->packageManager->isPackageActive('Neos.SiteKickstarter')) { $separator = $page1->createElement('separator', 'Neos.Form:StaticText'); $separator->setProperty('elementClassAttribute', 'section-separator'); $newPackageSection = $page1->createElement('newPackageSection', 'Neos.Form:Section'); $newPackageSection->setLabel('Create a new site package with a dummy site'); $packageName = $newPackageSection->createElement('packageKey', 'Neos.Form:SingleLineText'); $packageName->setLabel('Package Name (in form "Vendor.DomainCom")'); $packageName->addValidator(new PackageKeyValidator()); $siteName = $newPackageSection->createElement('siteName', 'Neos.Form:SingleLineText'); $siteName->setLabel('Site Name (e.g. "domain.com")'); } else { $error = $importSection->createElement('neosKickstarterUnavailableError', 'Neos.Form:StaticText'); $error->setProperty('text', 'The Neos Kickstarter package (Neos.SiteKickstarter) is not installed, install it for kickstarting new sites (using "composer require typo3/neos-kickstarter")'); $error->setProperty('elementClassAttribute', 'alert alert-warning'); } $explanation = $page1->createElement('explanation', 'Neos.Form:StaticText'); $explanation->setProperty('text', 'Notice the difference between a site package and a site. A site package is a Flow package that can be used for creating multiple site instances.'); $explanation->setProperty('elementClassAttribute', 'alert alert-info'); $step = $this; $callback = function (FinisherContext $finisherContext) use($step) { $step->importSite($finisherContext); }; $this->closureFinisher = new ClosureFinisher(); $this->closureFinisher->setOption('closure', $callback); $formDefinition->addFinisher($this->closureFinisher); $formDefinition->setRenderingOption('skipStepNotice', 'You can always import a site using the site:import command'); }
/** * 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; $xmlReader = new \XMLReader(); $xmlReader->open($pathAndFilename, null, LIBXML_PARSEHUGE); if ($this->workspaceRepository->findOneByName('live') === null) { $this->workspaceRepository->add(new Workspace('live')); $this->persistenceManager->persistAll(); } while ($xmlReader->read()) { if ($xmlReader->nodeType != \XMLReader::ELEMENT || $xmlReader->name !== 'site') { continue; } $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(SiteService::SITES_ROOT_PATH); if ($sitesNode === null) { $sitesNode = $rootNode->createNode(NodePaths::getNodeNameFromPath(SiteService::SITES_ROOT_PATH)); } $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; }
/** * Create a new site-package and directly import it. * * @param string $packageKey Package Name to create * @param string $siteName Site Name to create * @Flow\Validate(argumentName="$packageKey", type="\Neos\Neos\Validation\Validator\PackageKeyValidator") * @return void */ public function createSitePackageAction($packageKey, $siteName) { if ($this->packageManager->isPackageActive('Neos.SiteKickstarter') === false) { $this->addFlashMessage('The package "%s" is required to create new site packages.', 'Missing Package', Message::SEVERITY_ERROR, array('Neos.SiteKickstarter'), 1475736232); $this->redirect('index'); } 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(GeneratorService::class); $generatorService->generateSitePackage($packageKey, $siteName); $this->flashMessageContainer->addMessage(new Message(sprintf('Site Packages "%s" was created.', htmlspecialchars($packageKey)))); $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); $this->forward('importSite', null, null, ['packageKey' => $packageKey]); }
/** * Freeze a package * * This function marks a package as <b>frozen</b> in order to improve performance * in a development context. While a package is frozen, any modification of files * within that package won't be tracked and can lead to unexpected behavior. * * File monitoring won't consider the given package. Further more, reflection * data for classes contained in the package is cached persistently and loaded * directly on the first request after caches have been flushed. The precompiled * reflection data is stored in the <b>Configuration</b> directory of the * respective package. * * By specifying <b>all</b> as a package key, all currently frozen packages are * frozen (the default). * * @param string $packageKey Key of the package to freeze * @return void * @see neos.flow:package:unfreeze * @see neos.flow:package:refreeze */ public function freezeCommand($packageKey = 'all') { if (!$this->bootstrap->getContext()->isDevelopment()) { $this->outputLine('Package freezing is only supported in Development context.'); $this->quit(3); } $packagesToFreeze = []; if ($packageKey === 'all') { foreach (array_keys($this->packageManager->getActivePackages()) as $packageKey) { if (!$this->packageManager->isPackageFrozen($packageKey)) { $packagesToFreeze[] = $packageKey; } } if ($packagesToFreeze === []) { $this->outputLine('Nothing to do, all active packages were already frozen.'); $this->quit(0); } } elseif ($packageKey === 'blackberry') { $this->outputLine('http://bit.ly/freeze-blackberry'); $this->quit(42); } else { if (!$this->packageManager->isPackageActive($packageKey)) { if ($this->packageManager->isPackageAvailable($packageKey)) { $this->outputLine('Package "%s" is not active and thus cannot be frozen.', [$packageKey]); $this->quit(1); } else { $this->outputLine('Package "%s" is not available.', [$packageKey]); $this->quit(2); } } if ($this->packageManager->isPackageFrozen($packageKey)) { $this->outputLine('Package "%s" was already frozen.', [$packageKey]); $this->quit(0); } $packagesToFreeze = [$packageKey]; } foreach ($packagesToFreeze as $packageKey) { $this->packageManager->freezePackage($packageKey); $this->outputLine('Froze package "%s".', [$packageKey]); } }
/** * Clean up resource registry * * This command checks the resource registry (that is the database tables) for orphaned resource objects which don't * seem to have any corresponding data anymore (for example: the file in Data/Persistent/Resources has been deleted * without removing the related PersistentResource object). * * If the Neos.Media package is active, this command will also detect any assets referring to broken resources * and will remove the respective Asset object from the database when the broken resource is removed. * * This command will ask you interactively what to do before deleting anything. * * @return void */ public function cleanCommand() { $this->outputLine('Checking if resource data exists for all known resource objects ...'); $this->outputLine(); $mediaPackagePresent = $this->packageManager->isPackageActive('Neos.Media'); $resourcesCount = $this->resourceRepository->countAll(); $this->output->progressStart($resourcesCount); $brokenResources = []; $relatedAssets = new \SplObjectStorage(); $relatedThumbnails = new \SplObjectStorage(); $iterator = $this->resourceRepository->findAllIterator(); foreach ($this->resourceRepository->iterate($iterator, function ($iteration) { $this->clearState($iteration); }) as $resource) { $this->output->progressAdvance(1); /* @var PersistentResource $resource */ $stream = $resource->getStream(); if (!is_resource($stream)) { $brokenResources[] = $resource->getSha1(); } } $this->output->progressFinish(); $this->outputLine(); if ($mediaPackagePresent && count($brokenResources) > 0) { /* @var AssetRepository $assetRepository */ $assetRepository = $this->objectManager->get(AssetRepository::class); /* @var ThumbnailRepository $thumbnailRepository */ $thumbnailRepository = $this->objectManager->get(ThumbnailRepository::class); foreach ($brokenResources as $key => $resourceSha1) { $resource = $this->resourceRepository->findOneBySha1($resourceSha1); $brokenResources[$key] = $resource; $assets = $assetRepository->findByResource($resource); if ($assets !== null) { $relatedAssets[$resource] = $assets; } $thumbnails = $thumbnailRepository->findByResource($resource); if ($assets !== null) { $relatedThumbnails[$resource] = $thumbnails; } } } if (count($brokenResources) > 0) { $this->outputLine('<b>Found %s broken resource(s):</b>', [count($brokenResources)]); $this->outputLine(); foreach ($brokenResources as $resource) { $this->outputLine('%s (%s) from "%s" collection', [$resource->getFilename(), $resource->getSha1(), $resource->getCollectionName()]); if (isset($relatedAssets[$resource])) { foreach ($relatedAssets[$resource] as $asset) { $this->outputLine(' -> %s (%s)', [get_class($asset), $asset->getIdentifier()]); } } } $response = null; while (!in_array($response, ['y', 'n', 'c'])) { $response = $this->output->ask('<comment>Do you want to remove all broken resource objects and related assets from the database? (y/n/c) </comment>'); } switch ($response) { case 'y': $brokenAssetCounter = 0; $brokenThumbnailCounter = 0; foreach ($brokenResources as $sha1 => $resource) { $this->outputLine('- delete %s (%s) from "%s" collection', [$resource->getFilename(), $resource->getSha1(), $resource->getCollectionName()]); $resource->disableLifecycleEvents(); $this->resourceRepository->remove($resource); if (isset($relatedAssets[$resource])) { foreach ($relatedAssets[$resource] as $asset) { $assetRepository->remove($asset); $brokenAssetCounter++; } } if (isset($relatedThumbnails[$resource])) { foreach ($relatedThumbnails[$resource] as $thumbnail) { $thumbnailRepository->remove($thumbnail); $brokenThumbnailCounter++; } } $this->persistenceManager->persistAll(); } $brokenResourcesCounter = count($brokenResources); if ($brokenResourcesCounter > 0) { $this->outputLine('Removed %s resource object(s) from the database.', [$brokenResourcesCounter]); } if ($brokenAssetCounter > 0) { $this->outputLine('Removed %s asset object(s) from the database.', [$brokenAssetCounter]); } if ($brokenThumbnailCounter > 0) { $this->outputLine('Removed %s thumbnail object(s) from the database.', [$brokenThumbnailCounter]); } break; case 'n': $this->outputLine('Did not delete any resource objects.'); break; case 'c': $this->outputLine('Stopping. Did not delete any resource objects.'); $this->quit(0); break; } } }