persistAll() публичный Метод

If $onlyWhitelisteObjects is set to TRUE, only those objects which have been registered with whitelistObject() will be persisted. If other objects are in the queue, an exception will be raised.
public persistAll ( boolean $onlyWhitelistedObjects = false ) : void
$onlyWhitelistedObjects boolean
Результат void
 /**
  * Fetches the identifier from the set content object. If that
  * is not using automatically introduced UUIDs by Flow it tries
  * to call persistAll() and fetch the identifier again. If it still
  * fails, an exception is thrown.
  *
  * @return void
  * @throws IllegalObjectTypeException
  */
 protected function initializeObject()
 {
     if ($this->contentObject !== null) {
         $this->targetType = get_class($this->contentObject);
         $this->targetId = $this->persistenceManager->getIdentifierByObject($this->contentObject);
         if ($this->targetId === null) {
             $this->persistenceManager->persistAll();
             $this->targetId = $this->persistenceManager->getIdentifierByObject($this->contentObject);
             if ($this->targetId === null) {
                 throw new IllegalObjectTypeException('You cannot add an object without an identifier to a ContentObjectProxy. Probably you didn\'t add a valid entity?', 1303859434);
             }
         }
     }
 }
 /**
  * Generate missing URI path segments
  *
  * This generates URI path segment properties for all document nodes which don't have
  * a path segment set yet.
  *
  * @param string $workspaceName
  * @param boolean $dryRun
  * @return void
  */
 public function generateUriPathSegments($workspaceName, $dryRun)
 {
     $baseContext = $this->createContext($workspaceName, []);
     $baseContextSitesNode = $baseContext->getNode(SiteService::SITES_ROOT_PATH);
     if (!$baseContextSitesNode) {
         $this->output->outputLine('<error>Could not find "' . SiteService::SITES_ROOT_PATH . '" root node</error>');
         return;
     }
     $baseContextSiteNodes = $baseContextSitesNode->getChildNodes();
     if ($baseContextSiteNodes === []) {
         $this->output->outputLine('<error>Could not find any site nodes in "' . SiteService::SITES_ROOT_PATH . '" root node</error>');
         return;
     }
     foreach ($this->dimensionCombinator->getAllAllowedCombinations() as $dimensionCombination) {
         $flowQuery = new FlowQuery($baseContextSiteNodes);
         $siteNodes = $flowQuery->context(['dimensions' => $dimensionCombination, 'targetDimensions' => []])->get();
         if (count($siteNodes) > 0) {
             $this->output->outputLine('Checking for nodes with missing URI path segment in dimension "%s"', array(trim(NodePaths::generateContextPath('', '', $dimensionCombination), '@;')));
             foreach ($siteNodes as $siteNode) {
                 $this->generateUriPathSegmentsForNode($siteNode, $dryRun);
             }
         }
     }
     $this->persistenceManager->persistAll();
 }
 /**
  * Add a redirect
  *
  * Creates a new custom redirect. The optional argument ``host`` is used to define a specific redirect only valid
  * for a certain domain If no ``host`` argument is supplied, the redirect will act as a fallback redirect for all
  * domains in use. If any redirect exists with the same ``source`` property, it will be replaced if the ``force``
  * property has been set.
  *
  * @param string $source The relative URI path that should trigger the redirect
  * @param string $target The relative URI path that the redirect should point to
  * @param integer $statusCode The status code of the redirect header
  * @param string $host (optional) The host the redirect is valid for. If none is set, the redirect is valid for all
  * @param boolean $force Replace existing redirect (based on the source URI)
  * @return void
  */
 public function addCommand($source, $target, $statusCode, $host = null, $force = false)
 {
     $this->outputLine();
     $this->outputLine('<b>Create a redirect ...</b>');
     $this->outputLine();
     $redirect = $this->redirectStorage->getOneBySourceUriPathAndHost($source, $host, false);
     $isSame = $this->isSame($source, $target, $host, $statusCode, $redirect);
     if ($redirect !== null && $isSame === false && $force === false) {
         $this->outputLine('A redirect with the same source URI exist, see below:');
         $this->outputLine();
         $this->outputRedirectLine('<error>!!</error>', $redirect);
         $this->outputLine();
         $this->outputLine('Use --force to replace it');
         $this->outputLine();
         $this->sendAndExit(1);
     } elseif ($redirect !== null && $isSame === false && $force === true) {
         $this->redirectStorage->removeOneBySourceUriPathAndHost($source, $host);
         $this->outputRedirectLine('<info>--</info>', $redirect);
         $this->persistenceManager->persistAll();
     } elseif ($redirect !== null && $isSame === true) {
         $this->outputRedirectLine('<comment>~~</comment>', $redirect);
         $this->outputLine();
         $this->outputLegend();
         $this->sendAndExit();
     }
     $redirects = $this->redirectStorage->addRedirect($source, $target, $statusCode, [$host]);
     $redirect = reset($redirects);
     $this->outputRedirectLine('<info>++</info>', $redirect);
     $this->outputLine();
     $this->outputLegend();
 }
 /**
  * @param FinisherContext $finisherContext
  * @return void
  * @throws Exception
  */
 public function importSite(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 Exception(sprintf('The package key "%s" already exists.', $formValues['packageKey']), 1346759486);
         }
         $packageKey = $formValues['packageKey'];
         $siteName = $formValues['siteName'];
         $generatorService = $this->objectManager->get(\Neos\SiteKickstarter\Service\GeneratorService::class);
         $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);
         }
     }
 }
 /**
  * Remove given site all nodes for that site and all domains associated.
  *
  * @param Site $site
  * @return void
  */
 public function pruneSite(Site $site)
 {
     $siteNodePath = NodePaths::addNodePathSegment(static::SITES_ROOT_PATH, $site->getNodeName());
     $this->nodeDataRepository->removeAllInPath($siteNodePath);
     $siteNodes = $this->nodeDataRepository->findByPath($siteNodePath);
     foreach ($siteNodes as $siteNode) {
         $this->nodeDataRepository->remove($siteNode);
     }
     $site->setPrimaryDomain(null);
     $this->siteRepository->update($site);
     $domainsForSite = $this->domainRepository->findBySite($site);
     foreach ($domainsForSite as $domain) {
         $this->domainRepository->remove($domain);
     }
     $this->persistenceManager->persistAll();
     $this->siteRepository->remove($site);
     $this->emitSitePruned($site);
 }
 /**
  * If the specified workspace or its root node does not exist yet, the workspace and root node will be created.
  *
  * This method is basically a safeguard for legacy and potentially broken websites where users might not have
  * their own workspace yet. In a normal setup, the Domain User Service is responsible for creating and deleting
  * user workspaces.
  *
  * @param string $workspaceName Name of the workspace
  * @return void
  */
 protected function createWorkspaceAndRootNodeIfNecessary($workspaceName)
 {
     $workspace = $this->workspaceRepository->findOneByName($workspaceName);
     if ($workspace === null) {
         $liveWorkspace = $this->workspaceRepository->findOneByName('live');
         $owner = $this->userService->getBackendUser();
         $workspace = new Workspace($workspaceName, $liveWorkspace, $owner);
         $this->workspaceRepository->add($workspace);
         $this->persistenceManager->whitelistObject($workspace);
     }
     $contentContext = $this->createContext($workspaceName);
     $rootNode = $contentContext->getRootNode();
     $this->persistenceManager->whitelistObject($rootNode);
     $this->persistenceManager->whitelistObject($rootNode->getNodeData());
     $this->persistenceManager->persistAll(true);
 }
 /**
  * Render ungenerated thumbnails
  *
  * Loops over ungenerated thumbnails and renders them. Optional ``limit`` parameter to limit the amount of
  * thumbnails to be rendered to avoid memory exhaustion.
  *
  * @param integer $limit Limit the amount of thumbnails to be rendered to avoid memory exhaustion
  * @return void
  */
 public function renderThumbnailsCommand($limit = null)
 {
     $thumbnailCount = $this->thumbnailRepository->countUngenerated();
     $iterator = $this->thumbnailRepository->findUngeneratedIterator();
     $this->output->progressStart($limit !== null && $thumbnailCount > $limit ? $limit : $thumbnailCount);
     $iteration = 0;
     foreach ($this->thumbnailRepository->iterate($iterator) as $thumbnail) {
         if ($thumbnail->getResource() === null) {
             $this->thumbnailService->refreshThumbnail($thumbnail);
             $this->persistenceManager->persistAll();
         }
         $this->output->progressAdvance(1);
         $iteration++;
         if ($iteration === $limit) {
             break;
         }
     }
 }
 /**
  * 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;
 }
 /**
  *
  *
  * @return void
  */
 public function updateEventsAfterPublish()
 {
     if (!$this->eventEmittingService->isEnabled()) {
         return;
     }
     /** @var $entityManager EntityManager */
     $entityManager = $this->entityManager;
     foreach ($this->scheduledNodeEventUpdates as $documentPublish) {
         /* @var $nodeEvent NodeEvent */
         $nodeEvent = $this->eventEmittingService->emit(self::DOCUMENT_PUBLISHED, array(), NodeEvent::class);
         $nodeEvent->setNode($documentPublish['documentNode']);
         $nodeEvent->setWorkspaceName($documentPublish['targetWorkspace']);
         $this->persistenceManager->whitelistObject($nodeEvent);
         $this->persistenceManager->persistAll(true);
         $parentEventIdentifier = $this->persistenceManager->getIdentifierByObject($nodeEvent);
         $qb = $entityManager->createQueryBuilder();
         $qb->update(NodeEvent::class, 'e')->set('e.parentEvent', ':parentEventIdentifier')->setParameter('parentEventIdentifier', $parentEventIdentifier)->where('e.parentEvent IS NULL')->andWhere('e.workspaceName = :workspaceName')->setParameter('workspaceName', $documentPublish['workspaceName'])->andWhere('e.documentNodeIdentifier = :documentNodeIdentifier')->setParameter('documentNodeIdentifier', $documentPublish['documentNode']->getIdentifier())->andWhere('e.eventType != :publishedEventType')->setParameter('publishedEventType', self::DOCUMENT_PUBLISHED)->getQuery()->execute();
     }
     $this->scheduledNodeEventUpdates = array();
 }
 /**
  * Create a new site
  *
  * This command allows to create a blank site with just a single empty document in the default dimension.
  * The name of the site, the packageKey must be specified.
  *
  * If no ``nodeType`` option is specified the command will use `Neos.Neos.NodeTypes:Page` as fallback. The node type
  * must already exists and have the superType ``Neos.Neos:Document``.
  *
  * If no ``nodeName` option is specified the command will create a unique node-name from the name of the site.
  * If a node name is given it has to be unique for the setup.
  *
  * If the flag ``activate` is set to false new site will not be activated.
  *
  * @param string $name The name of the site
  * @param string $packageKey The site package
  * @param string $nodeType The node type to use for the site node. (Default = Neos.Neos.NodeTypes:Page)
  * @param string $nodeName The name of the site node. If no nodeName is given it will be determined from the siteName.
  * @param boolean $inactive The new site is not activated immediately (default = false).
  * @return void
  */
 public function createCommand($name, $packageKey, $nodeType = 'Neos.Neos.NodeTypes:Page', $nodeName = null, $inactive = false)
 {
     if ($nodeName === null) {
         $nodeName = $this->nodeService->generateUniqueNodeName(SiteService::SITES_ROOT_PATH, $name);
     }
     if ($this->siteRepository->findOneByNodeName($nodeName)) {
         $this->outputLine('<error>A site with siteNodeName "%s" already exists</error>', [$nodeName]);
         $this->quit(1);
     }
     if ($this->packageManager->isPackageAvailable($packageKey) === false) {
         $this->outputLine('<error>Could not find package "%s"</error>', [$packageKey]);
         $this->quit(1);
     }
     $siteNodeType = $this->nodeTypeManager->getNodeType($nodeType);
     if ($siteNodeType === null || $siteNodeType->getName() === 'Neos.Neos:FallbackNode') {
         $this->outputLine('<error>The given node type "%s" was not found</error>', [$nodeType]);
         $this->quit(1);
     }
     if ($siteNodeType->isOfType('Neos.Neos:Document') === false) {
         $this->outputLine('<error>The given node type "%s" is not based on the superType "%s"</error>', [$nodeType, 'Neos.Neos:Document']);
         $this->quit(1);
     }
     $rootNode = $this->nodeContextFactory->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));
     }
     $siteNode = $sitesNode->createNode($nodeName, $siteNodeType);
     $siteNode->setProperty('title', $name);
     $site = new Site($nodeName);
     $site->setSiteResourcesPackageKey($packageKey);
     $site->setState($inactive ? Site::STATE_OFFLINE : Site::STATE_ONLINE);
     $site->setName($name);
     $this->siteRepository->add($site);
     $this->outputLine('Successfully created site "%s" with siteNode "%s", type "%s", packageKey "%s" and state "%s"', [$name, $nodeName, $nodeType, $packageKey, $inactive ? 'offline' : 'online']);
 }
Пример #11
0
 /**
  * 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;
         }
     }
 }
 /**
  * Reorder child nodes according to the current position configuration of child nodes.
  *
  * @param string $workspaceName Name of the workspace to consider
  * @param boolean $dryRun Simulate?
  * @param NodeType $nodeType Only for this node type, if specified
  * @return void
  */
 protected function reorderChildNodes($workspaceName, $dryRun, NodeType $nodeType = null)
 {
     if ($nodeType !== null) {
         $this->output->outputLine('Checking nodes of type "%s" for child nodes that need reordering ...', array($nodeType->getName()));
         $this->reorderChildNodesByNodeType($workspaceName, $dryRun, $nodeType);
     } else {
         $this->output->outputLine('Checking for child nodes that need reordering ...');
         foreach ($this->nodeTypeManager->getNodeTypes() as $nodeType) {
             /** @var NodeType $nodeType */
             if ($nodeType->isAbstract()) {
                 continue;
             }
             $this->reorderChildNodesByNodeType($workspaceName, $dryRun, $nodeType);
         }
     }
     $this->persistenceManager->persistAll();
 }