clearState() public method

Managed instances become detached, any fetches will return data directly from the persistence "backend".
public clearState ( ) : void
return void
 /**
  * Sends the given HTTP request
  *
  * @param Http\Request $httpRequest
  * @return Http\Response
  * @throws Http\Exception
  * @api
  */
 public function sendRequest(Http\Request $httpRequest)
 {
     $requestHandler = $this->bootstrap->getActiveRequestHandler();
     if (!$requestHandler instanceof FunctionalTestRequestHandler) {
         throw new Http\Exception('The browser\'s internal request engine has only been designed for use within functional tests.', 1335523749);
     }
     $this->securityContext->clearContext();
     $this->validatorResolver->reset();
     $response = new Http\Response();
     $componentContext = new ComponentContext($httpRequest, $response);
     $requestHandler->setComponentContext($componentContext);
     $objectManager = $this->bootstrap->getObjectManager();
     $baseComponentChain = $objectManager->get(\Neos\Flow\Http\Component\ComponentChain::class);
     $componentContext = new ComponentContext($httpRequest, $response);
     try {
         $baseComponentChain->handle($componentContext);
     } catch (\Throwable $throwable) {
         $this->prepareErrorResponse($throwable, $componentContext->getHttpResponse());
     } catch (\Exception $exception) {
         $this->prepareErrorResponse($exception, $componentContext->getHttpResponse());
     }
     $session = $this->bootstrap->getObjectManager()->get(SessionInterface::class);
     if ($session->isStarted()) {
         $session->close();
     }
     $this->persistenceManager->clearState();
     return $componentContext->getHttpResponse();
 }
Example #2
0
 /**
  * This method is used internal as a callback method to clear doctrine states
  *
  * @param integer $iteration
  * @return void
  */
 protected function clearState($iteration)
 {
     if ($iteration % 1000 === 0) {
         $this->persistenceManager->clearState();
     }
 }
 /**
  * Import redirects from CSV file
  *
  * This command is used to (re)import CSV files containing redirects.
  * The argument ``filename`` is the name of the file you uploaded to the root folder.
  * This operation requires the package ``league/csv``. Install it by running ``composer require league/csv``.
  * Structure per line is:
  * ``sourcePath``,``targetPath``,``statusCode``,``host`` (optional)
  * After a successful import a report will be shown. While `++` marks newly created redirects, `~~` marks already
  * existing redirect source paths along with the used status code and ``source``.
  * ``redirect:import`` will not delete pre-existing redirects. To do this run ``redirect:removeall`` before
  * the import. Be aware that this will also delete all automatically generated redirects.
  *
  * @param string $filename CSV file path
  * @return void
  */
 public function importCommand($filename)
 {
     $hasErrors = false;
     $this->outputLine();
     if (!class_exists(Reader::class)) {
         $this->outputWarningForLeagueCsvPackage();
     }
     if (!is_readable($filename)) {
         $this->outputLine('<error>Sorry, but the file "%s" is not readable or does not exist...</error>', [$filename]);
         $this->outputLine();
         $this->sendAndExit(1);
     }
     $this->outputLine('<b>Import redirects from "%s"</b>', [$filename]);
     $this->outputLine();
     $reader = Reader::createFromPath($filename);
     $counter = 0;
     foreach ($reader as $index => $row) {
         $skipped = false;
         list($sourceUriPath, $targetUriPath, $statusCode, $hosts) = $row;
         $hosts = Arrays::trimExplode('|', $hosts);
         if ($hosts === []) {
             $hosts = [null];
         }
         $forcePersist = false;
         foreach ($hosts as $key => $host) {
             $host = trim($host);
             $host = $host === '' ? null : $host;
             $redirect = $this->redirectStorage->getOneBySourceUriPathAndHost($sourceUriPath, $host);
             $isSame = $this->isSame($sourceUriPath, $targetUriPath, $host, $statusCode, $redirect);
             if ($redirect !== null && $isSame === false) {
                 $this->outputRedirectLine('<info>--</info>', $redirect);
                 $this->redirectStorage->removeOneBySourceUriPathAndHost($sourceUriPath, $host);
                 $forcePersist = true;
             } elseif ($isSame === true) {
                 $this->outputRedirectLine('<comment>~~</comment>', $redirect);
                 unset($hosts[$key]);
                 $skipped = true;
             }
         }
         if ($skipped === true && $hosts === []) {
             continue;
         }
         if ($forcePersist) {
             $this->persistenceManager->persistAll();
         }
         try {
             $redirects = $this->redirectStorage->addRedirect($sourceUriPath, $targetUriPath, $statusCode, $hosts);
             /** @var Redirect $redirect */
             foreach ($redirects as $redirect) {
                 $this->outputRedirectLine('<info>++</info>', $redirect);
                 $messageArguments = [$redirect->getSourceUriPath(), $redirect->getTargetUriPath(), $redirect->getStatusCode(), $redirect->getHost() ?: 'all host'];
                 $this->logger->log(vsprintf('Redirect import success, sourceUriPath=%s, targetUriPath=%s, statusCode=%d, hosts=%s', $messageArguments), LOG_ERR);
             }
             $this->persistenceManager->persistAll();
         } catch (Exception $exception) {
             $messageArguments = [$sourceUriPath, $targetUriPath, $statusCode, $hosts ? json_encode($hosts) : 'all host'];
             $this->outputLine('   <error>!!</error> %s => %s <comment>(%d)</comment> - %s', $messageArguments);
             $this->outputLine('      Message: %s', [$exception->getMessage()]);
             $this->logger->log(vsprintf('Redirect import error, sourceUriPath=%s, targetUriPath=%s, statusCode=%d, hosts=%s', $messageArguments), LOG_ERR);
             $this->logger->logException($exception);
             $hasErrors = true;
         }
         $counter++;
         if ($counter % 50 === 0) {
             $this->persistenceManager->persistAll();
             $this->persistenceManager->clearState();
         }
     }
     $this->outputLine();
     if ($hasErrors === true) {
         $this->outputLine('   <error>!!</error> some errors appeared during import, please check the log or the CLI output.');
     }
     $this->outputLegend();
 }