‪TYPO3CMS  ‪main
QueueController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
30 
35 {
40  protected string ‪$defaultViewObjectName = JsonView::class;
41 
42  public function ‪__construct(
47  ) {
48  $this->dataMapFactory = ‪$dataMapFactory;
49  $this->queueService = ‪$queueService;
50  $this->contentRepository = ‪$contentRepository;
51  $this->persistenceManager = ‪$persistenceManager;
52  }
53 
54  public function ‪indexAction(): ResponseInterface
55  {
56  $calls = [];
57  $calls[] = ['Content', 'list'];
58  $contents = $this->contentRepository->findAll();
59  foreach ($contents as $content) {
60  ‪$uid = $content->getUid();
61  $calls[] = ['Content', 'show', ['content' => (string)‪$uid]];
62  }
63  $this->queueService->set($calls);
64  return new ‪ForwardResponse('process');
65  }
66 
67  public function ‪processAction(): ResponseInterface
68  {
69  $call = $this->queueService->shift();
70  if ($call === null) {
71  return new ‪ForwardResponse('finish');
72  }
73  // Clear these states and fetch fresh entities!
74  $this->persistenceManager->clearState();
75 
76  $response = (new ‪ForwardResponse($call[1]))
77  ->withControllerName($call[0]);
78 
79  ‪$arguments = $call[2] ?? null;
80  if (is_array(‪$arguments)) {
81  $response = $response->withArguments(‪$arguments);
82  }
83 
84  return $response;
85  }
86 
87  public function ‪finishAction(): ResponseInterface
88  {
89  $value = $this->queueService->getValues();
90  $this->view->assign('value', $value);
91  $body = new ‪Stream('php://temp', 'rw');
92  $body->write($this->view->render());
93  return (new ‪Response($body))->withHeader('Content-Type', 'application/json; charset=utf-8');
94  }
95 }
‪TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
Definition: PersistenceManagerInterface.php:24
‪TYPO3Tests\TestIrreForeignfield\Controller
Definition: AbstractController.php:18
‪TYPO3Tests\TestIrreForeignfield\Service\QueueService
Definition: QueueService.php:26
‪TYPO3\CMS\Extbase\Http\ForwardResponse
Definition: ForwardResponse.php:24
‪TYPO3Tests\TestIrreForeignfield\Domain\Repository\ContentRepository
Definition: ContentRepository.php:27
‪TYPO3Tests\TestIrreForeignfield\Controller\QueueController\$queueService
‪QueueService $queueService
Definition: QueueController.php:37
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory
Definition: DataMapFactory.php:34
‪TYPO3\CMS\Core\Http\Response
Definition: Response.php:32
‪TYPO3\CMS\Core\Http\Stream
Definition: Stream.php:31
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$arguments
‪Arguments $arguments
Definition: ActionController.php:123
‪TYPO3Tests\TestIrreForeignfield\Controller\QueueController\processAction
‪processAction()
Definition: QueueController.php:67
‪TYPO3Tests\TestIrreForeignfield\Controller\QueueController\finishAction
‪finishAction()
Definition: QueueController.php:87
‪TYPO3Tests\TestIrreForeignfield\Controller\QueueController\__construct
‪__construct(DataMapFactory $dataMapFactory, QueueService $queueService, ContentRepository $contentRepository, PersistenceManagerInterface $persistenceManager)
Definition: QueueController.php:42
‪TYPO3Tests\TestIrreForeignfield\Controller\QueueController\$contentRepository
‪ContentRepository $contentRepository
Definition: QueueController.php:38
‪TYPO3\CMS\Webhooks\Message\$uid
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
‪TYPO3Tests\TestIrreForeignfield\Controller\QueueController\indexAction
‪indexAction()
Definition: QueueController.php:54
‪TYPO3Tests\TestIrreForeignfield\Controller\QueueController\$defaultViewObjectName
‪string $defaultViewObjectName
Definition: QueueController.php:40
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController
Definition: ActionController.php:63
‪TYPO3Tests\TestIrreForeignfield\Controller\QueueController\$dataMapFactory
‪DataMapFactory $dataMapFactory
Definition: QueueController.php:36
‪TYPO3Tests\TestIrreForeignfield\Controller\QueueController\$persistenceManager
‪PersistenceManagerInterface $persistenceManager
Definition: QueueController.php:39
‪TYPO3\CMS\Extbase\Mvc\View\JsonView
Definition: JsonView.php:29
‪TYPO3Tests\TestIrreForeignfield\Controller\QueueController
Definition: QueueController.php:35