/**
  * Try to set the current account identifier emitting the events, if possible
  *
  * @return void
  */
 protected function initializeAccountIdentifier()
 {
     if ($this->securityContext->canBeInitialized()) {
         $account = $this->securityContext->getAccount();
         if ($account !== NULL) {
             $this->eventEmittingService->setCurrentAccountIdentifier($account->getAccountIdentifier());
         }
     }
 }
コード例 #2
0
 /**
  * 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;
 }
 /**
  * Record events for entity changes.
  *
  * Note: this method is registered as an Doctrine event listener in the settings of this package.
  *
  * TODO: Update/Delete of Entities
  *
  * @param OnFlushEventArgs $eventArgs
  * @return void
  * @throws \TYPO3\Eel\Exception
  */
 public function onFlush(OnFlushEventArgs $eventArgs)
 {
     if (!$this->eventEmittingService->isEnabled()) {
         return;
     }
     $entityManager = $eventArgs->getEntityManager();
     $unitOfWork = $entityManager->getUnitOfWork();
     foreach ($unitOfWork->getScheduledEntityInsertions() as $entity) {
         $className = get_class($entity);
         if (isset($this->monitorEntitiesSetting[$className])) {
             $entityMonitoringConfiguration = $this->monitorEntitiesSetting[$className];
             if (isset($entityMonitoringConfiguration['events']['created'])) {
                 $this->initializeAccountIdentifier();
                 $data = array();
                 foreach ($entityMonitoringConfiguration['data'] as $key => $eelExpression) {
                     $data[$key] = Utility::evaluateEelExpression($eelExpression, $this->eelEvaluator, array('entity' => $entity));
                 }
                 $event = $this->eventEmittingService->emit($entityMonitoringConfiguration['events']['created'], $data);
                 $unitOfWork->computeChangeSet($entityManager->getClassMetadata('TYPO3\\Neos\\EventLog\\Domain\\Model\\Event'), $event);
             }
         }
     }
     foreach ($unitOfWork->getScheduledEntityDeletions() as $entity) {
         $className = get_class($entity);
         if (isset($this->monitorEntitiesSetting[$className])) {
             $entityMonitoringConfiguration = $this->monitorEntitiesSetting[$className];
             if (isset($entityMonitoringConfiguration['events']['deleted'])) {
                 $this->initializeAccountIdentifier();
                 $data = array();
                 foreach ($entityMonitoringConfiguration['data'] as $key => $eelExpression) {
                     $data[$key] = Utility::evaluateEelExpression($eelExpression, $this->eelEvaluator, array('entity' => $entity));
                 }
                 $event = $this->eventEmittingService->emit($entityMonitoringConfiguration['events']['deleted'], $data);
                 $unitOfWork->computeChangeSet($entityManager->getClassMetadata('TYPO3\\Neos\\EventLog\\Domain\\Model\\Event'), $event);
             }
         }
     }
 }