‪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 
44  protected ‪$defaultViewObjectName = JsonView::class;
45 
46  public function ‪__construct(
51  ) {
52  $this->dataMapFactory = ‪$dataMapFactory;
53  $this->queueService = ‪$queueService;
54  $this->contentRepository = ‪$contentRepository;
55  $this->persistenceManager = ‪$persistenceManager;
56  }
57 
58  public function ‪indexAction(): ResponseInterface
59  {
60  $calls = [];
61  $calls[] = ['Content', 'list'];
62  $contents = $this->contentRepository->findAll();
63  foreach ($contents as $content) {
64  ‪$uid = $content->getUid();
65  $calls[] = ['Content', 'show', ['content' => (string)‪$uid]];
66  }
67  $this->queueService->set($calls);
68  return new ‪ForwardResponse('process');
69  }
70 
71  public function ‪processAction(): ResponseInterface
72  {
73  $call = $this->queueService->shift();
74  if ($call === null) {
75  return new ‪ForwardResponse('finish');
76  }
77  // Clear these states and fetch fresh entities!
78  $this->persistenceManager->clearState();
79 
80  $response = (new ‪ForwardResponse($call[1]))
81  ->withControllerName($call[0]);
82 
83  ‪$arguments = $call[2] ?? null;
84  if (is_array(‪$arguments)) {
85  $response = $response->withArguments(‪$arguments);
86  }
87 
88  return $response;
89  }
90 
91  public function ‪finishAction(): ResponseInterface
92  {
93  $value = $this->queueService->getValues();
94  $this->view->assign('value', $value);
95  $body = new ‪Stream('php://temp', 'rw');
96  $body->write($this->view->render());
97  return (new ‪Response($body))->withHeader('Content-Type', 'application/json; charset=utf-8');
98  }
99 }
‪TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
Definition: PersistenceManagerInterface.php:22
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$arguments
‪TYPO3 CMS Extbase Mvc Controller Arguments $arguments
Definition: ActionController.php:141
‪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
‪TYPO3Tests\TestIrreForeignfield\Controller\QueueController\processAction
‪processAction()
Definition: QueueController.php:70
‪TYPO3Tests\TestIrreForeignfield\Controller\QueueController\finishAction
‪finishAction()
Definition: QueueController.php:90
‪TYPO3Tests\TestIrreForeignfield\Controller\QueueController\__construct
‪__construct(DataMapFactory $dataMapFactory, QueueService $queueService, ContentRepository $contentRepository, PersistenceManagerInterface $persistenceManager)
Definition: QueueController.php:45
‪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:57
‪TYPO3Tests\TestIrreForeignfield\Controller\QueueController\$defaultViewObjectName
‪string $defaultViewObjectName
Definition: QueueController.php:43
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController
Definition: ActionController.php:61
‪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