Skip to content

Commit d172650

Browse files
committed
TASK: PSR2 code formating
1 parent 3d0ab46 commit d172650

File tree

4 files changed

+190
-188
lines changed

4 files changed

+190
-188
lines changed

Classes/Flowpack/ElasticSearch/ContentRepositoryQueueIndexer/Command/NodeIndexQueueCommandController.php

Lines changed: 128 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -27,130 +27,132 @@
2727
*
2828
* @Flow\Scope("singleton")
2929
*/
30-
class NodeIndexQueueCommandController extends CommandController {
31-
32-
/**
33-
* @Flow\Inject
34-
* @var JobManager
35-
*/
36-
protected $jobManager;
37-
38-
/**
39-
* @var PersistenceManagerInterface
40-
* @Flow\Inject
41-
*/
42-
protected $persistenceManager;
43-
44-
/**
45-
* @Flow\Inject
46-
* @var NodeTypeMappingBuilder
47-
*/
48-
protected $nodeTypeMappingBuilder;
49-
50-
/**
51-
* @Flow\Inject
52-
* @var NodeDataRepository
53-
*/
54-
protected $nodeDataRepository;
55-
56-
/**
57-
* @Flow\Inject
58-
* @var WorkspaceRepository
59-
*/
60-
protected $workspaceRepository;
61-
62-
/**
63-
* @Flow\Inject
64-
* @var NodeIndexer
65-
*/
66-
protected $nodeIndexer;
67-
68-
/**
69-
* @Flow\Inject
70-
* @var LoggerInterface
71-
*/
72-
protected $logger;
73-
74-
/**
75-
* Index all nodes by creating a new index and when everything was completed, switch the index alias.
76-
*
77-
* @param string $workspace
78-
*/
79-
public function buildCommand($workspace = NULL) {
80-
$indexPostfix = time();
81-
$this->createNextIndex($indexPostfix);
82-
$this->updateMapping();
83-
84-
85-
$this->outputLine(sprintf('Indexing on %s ... ', $indexPostfix));
86-
87-
if ($workspace === NULL) {
88-
foreach ($this->workspaceRepository->findAll() as $workspace) {
89-
$this->indexWorkspace($workspace->getName(), $indexPostfix);
90-
}
91-
} else {
92-
$this->indexWorkspace($workspace, $indexPostfix);
93-
}
94-
$updateAliasJob = new UpdateAliasJob($indexPostfix);
95-
$queueName = 'Flowpack.ElasticSearch.ContentRepositoryQueueIndexer';
96-
$this->jobManager->queue($queueName, $updateAliasJob);
97-
98-
$this->outputLine();
99-
$this->outputLine(sprintf('Indexing jobs created for queue %s with success ...', $queueName));
100-
}
101-
102-
/**
103-
* @param string $workspaceName
104-
* @param string $indexPostfix
105-
*/
106-
protected function indexWorkspace($workspaceName, $indexPostfix) {
107-
$offset = 0;
108-
$batchSize = 250;
109-
while (TRUE) {
110-
$iterator = $this->nodeDataRepository->findAllBySiteAndWorkspace($workspaceName, $offset, $batchSize);
111-
112-
$jobData = [];
113-
114-
foreach ($this->nodeDataRepository->iterate($iterator) as $data) {
115-
$jobData[] = [
116-
'nodeIdentifier' => $data['nodeIdentifier'],
117-
'dimensions' => $data['dimensions']
118-
];
119-
}
120-
121-
if ($jobData === []) {
122-
break;
123-
}
124-
125-
$indexingJob = new IndexingJob($indexPostfix, $workspaceName, $jobData);
126-
$this->jobManager->queue('Flowpack.ElasticSearch.ContentRepositoryQueueIndexer', $indexingJob);
127-
$this->output('.');
128-
$offset += $batchSize;
129-
$this->persistenceManager->clearState();
130-
}
131-
}
132-
133-
/**
134-
* Create next index
135-
* @param string $indexPostfix
136-
*/
137-
protected function createNextIndex($indexPostfix) {
138-
$this->nodeIndexer->setIndexNamePostfix($indexPostfix);
139-
$this->nodeIndexer->getIndex()->create();
140-
$this->logger->log(sprintf('action=indexing step=index-created index=%s', $this->nodeIndexer->getIndexName()), LOG_INFO);
141-
}
142-
143-
/**
144-
* Update Index Mapping
145-
*/
146-
protected function updateMapping() {
147-
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
148-
foreach ($nodeTypeMappingCollection as $mapping) {
149-
/** @var \Flowpack\ElasticSearch\Domain\Model\Mapping $mapping */
150-
$mapping->apply();
151-
}
152-
$this->logger->log(sprintf('action=indexing step=mapping-updated index=%s', $this->nodeIndexer->getIndexName()), LOG_INFO);
153-
}
154-
155-
30+
class NodeIndexQueueCommandController extends CommandController
31+
{
32+
/**
33+
* @Flow\Inject
34+
* @var JobManager
35+
*/
36+
protected $jobManager;
37+
38+
/**
39+
* @var PersistenceManagerInterface
40+
* @Flow\Inject
41+
*/
42+
protected $persistenceManager;
43+
44+
/**
45+
* @Flow\Inject
46+
* @var NodeTypeMappingBuilder
47+
*/
48+
protected $nodeTypeMappingBuilder;
49+
50+
/**
51+
* @Flow\Inject
52+
* @var NodeDataRepository
53+
*/
54+
protected $nodeDataRepository;
55+
56+
/**
57+
* @Flow\Inject
58+
* @var WorkspaceRepository
59+
*/
60+
protected $workspaceRepository;
61+
62+
/**
63+
* @Flow\Inject
64+
* @var NodeIndexer
65+
*/
66+
protected $nodeIndexer;
67+
68+
/**
69+
* @Flow\Inject
70+
* @var LoggerInterface
71+
*/
72+
protected $logger;
73+
74+
/**
75+
* Index all nodes by creating a new index and when everything was completed, switch the index alias.
76+
*
77+
* @param string $workspace
78+
*/
79+
public function buildCommand($workspace = null)
80+
{
81+
$indexPostfix = time();
82+
$this->createNextIndex($indexPostfix);
83+
$this->updateMapping();
84+
85+
86+
$this->outputLine(sprintf('Indexing on %s ... ', $indexPostfix));
87+
88+
if ($workspace === null) {
89+
foreach ($this->workspaceRepository->findAll() as $workspace) {
90+
$this->indexWorkspace($workspace->getName(), $indexPostfix);
91+
}
92+
} else {
93+
$this->indexWorkspace($workspace, $indexPostfix);
94+
}
95+
$updateAliasJob = new UpdateAliasJob($indexPostfix);
96+
$queueName = 'Flowpack.ElasticSearch.ContentRepositoryQueueIndexer';
97+
$this->jobManager->queue($queueName, $updateAliasJob);
98+
99+
$this->outputLine();
100+
$this->outputLine(sprintf('Indexing jobs created for queue %s with success ...', $queueName));
101+
}
102+
103+
/**
104+
* @param string $workspaceName
105+
* @param string $indexPostfix
106+
*/
107+
protected function indexWorkspace($workspaceName, $indexPostfix)
108+
{
109+
$offset = 0;
110+
$batchSize = 250;
111+
while (true) {
112+
$iterator = $this->nodeDataRepository->findAllBySiteAndWorkspace($workspaceName, $offset, $batchSize);
113+
114+
$jobData = [];
115+
116+
foreach ($this->nodeDataRepository->iterate($iterator) as $data) {
117+
$jobData[] = [
118+
'nodeIdentifier' => $data['nodeIdentifier'],
119+
'dimensions' => $data['dimensions']
120+
];
121+
}
122+
123+
if ($jobData === []) {
124+
break;
125+
}
126+
127+
$indexingJob = new IndexingJob($indexPostfix, $workspaceName, $jobData);
128+
$this->jobManager->queue('Flowpack.ElasticSearch.ContentRepositoryQueueIndexer', $indexingJob);
129+
$this->output('.');
130+
$offset += $batchSize;
131+
$this->persistenceManager->clearState();
132+
}
133+
}
134+
135+
/**
136+
* Create next index
137+
* @param string $indexPostfix
138+
*/
139+
protected function createNextIndex($indexPostfix)
140+
{
141+
$this->nodeIndexer->setIndexNamePostfix($indexPostfix);
142+
$this->nodeIndexer->getIndex()->create();
143+
$this->logger->log(sprintf('action=indexing step=index-created index=%s', $this->nodeIndexer->getIndexName()), LOG_INFO);
144+
}
145+
146+
/**
147+
* Update Index Mapping
148+
*/
149+
protected function updateMapping()
150+
{
151+
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
152+
foreach ($nodeTypeMappingCollection as $mapping) {
153+
/** @var \Flowpack\ElasticSearch\Domain\Model\Mapping $mapping */
154+
$mapping->apply();
155+
}
156+
$this->logger->log(sprintf('action=indexing step=mapping-updated index=%s', $this->nodeIndexer->getIndexName()), LOG_INFO);
157+
}
156158
}

Classes/Flowpack/ElasticSearch/ContentRepositoryQueueIndexer/Domain/Repository/NodeDataRepository.php

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,61 +12,61 @@
1212
/**
1313
* @Flow\Scope("singleton")
1414
*/
15-
class NodeDataRepository extends Repository {
15+
class NodeDataRepository extends Repository
16+
{
17+
const ENTITY_CLASSNAME = 'TYPO3\TYPO3CR\Domain\Model\NodeData';
1618

17-
const ENTITY_CLASSNAME = 'TYPO3\TYPO3CR\Domain\Model\NodeData';
19+
/**
20+
* @Flow\Inject
21+
* @var ObjectManager
22+
*/
23+
protected $entityManager;
1824

19-
/**
20-
* @Flow\Inject
21-
* @var ObjectManager
22-
*/
23-
protected $entityManager;
25+
/**
26+
* @param string $workspaceName
27+
* @param integer $firstResult
28+
* @param integer $maxResults
29+
* @return IterableResult
30+
*/
31+
public function findAllBySiteAndWorkspace($workspaceName, $firstResult = 0, $maxResults = 1000)
32+
{
2433

25-
/**
26-
* @param string $workspaceName
27-
* @param integer $firstResult
28-
* @param integer $maxResults
29-
* @return IterableResult
30-
*/
31-
public function findAllBySiteAndWorkspace($workspaceName, $firstResult = 0, $maxResults = 1000) {
34+
/** @var QueryBuilder $queryBuilder */
35+
$queryBuilder = $this->entityManager->createQueryBuilder();
3236

33-
/** @var QueryBuilder $queryBuilder */
34-
$queryBuilder = $this->entityManager->createQueryBuilder();
37+
$queryBuilder->select('n.Persistence_Object_Identifier nodeIdentifier, n.dimensionValues dimensions')
38+
->from('TYPO3\TYPO3CR\Domain\Model\NodeData', 'n')
39+
->where("n.workspace = :workspace AND n.removed = :removed AND n.movedTo IS NULL")
40+
->setFirstResult((integer)$firstResult)
41+
->setMaxResults((integer)$maxResults)
42+
->setParameters([
43+
':workspace' => $workspaceName,
44+
':removed' => false,
45+
]);
3546

36-
$queryBuilder->select('n.Persistence_Object_Identifier nodeIdentifier, n.dimensionValues dimensions')
37-
->from('TYPO3\TYPO3CR\Domain\Model\NodeData', 'n')
38-
->where("n.workspace = :workspace AND n.removed = :removed AND n.movedTo IS NULL")
39-
->setFirstResult((integer)$firstResult)
40-
->setMaxResults((integer)$maxResults)
41-
->setParameters([
42-
':workspace' => $workspaceName,
43-
':removed' => FALSE,
44-
]);
45-
46-
return $queryBuilder->getQuery()->iterate();
47-
}
48-
49-
/**
50-
* Iterator over an IterableResult and return a Generator
51-
*
52-
* This methos is useful for batch processing huge result set as it clear the object
53-
* manager and detach the current object on each iteration.
54-
*
55-
* @param IterableResult $iterator
56-
* @param callable $callback
57-
* @return \Generator
58-
*/
59-
public function iterate(IterableResult $iterator, callable $callback = null)
60-
{
61-
$iteration = 0;
62-
foreach ($iterator as $object) {
63-
$object = current($object);
64-
yield $object;
65-
if ($callback !== null) {
66-
call_user_func($callback, $iteration, $object);
67-
}
68-
++$iteration;
69-
}
70-
}
47+
return $queryBuilder->getQuery()->iterate();
48+
}
7149

50+
/**
51+
* Iterator over an IterableResult and return a Generator
52+
*
53+
* This methos is useful for batch processing huge result set as it clear the object
54+
* manager and detach the current object on each iteration.
55+
*
56+
* @param IterableResult $iterator
57+
* @param callable $callback
58+
* @return \Generator
59+
*/
60+
public function iterate(IterableResult $iterator, callable $callback = null)
61+
{
62+
$iteration = 0;
63+
foreach ($iterator as $object) {
64+
$object = current($object);
65+
yield $object;
66+
if ($callback !== null) {
67+
call_user_func($callback, $iteration, $object);
68+
}
69+
++$iteration;
70+
}
71+
}
7272
}

Classes/Flowpack/ElasticSearch/ContentRepositoryQueueIndexer/IndexingJob.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*/
2020
class IndexingJob implements JobInterface
2121
{
22-
2322
/**
2423
* @var NodeIndexer
2524
* @Flow\Inject
@@ -117,7 +116,6 @@ public function execute(QueueInterface $queue, Message $message)
117116
$this->logger->log(sprintf('action=indexing step=started node=%s', $currentNode->getIdentifier()));
118117

119118
$this->nodeIndexer->indexNode($currentNode);
120-
121119
}
122120

123121
$this->nodeIndexer->flush();
@@ -148,5 +146,4 @@ public function getLabel()
148146
{
149147
return sprintf('ElasticSearch Indexing Job (%s)', $this->getIdentifier());
150148
}
151-
152149
}

0 commit comments

Comments
 (0)