|
| 1 | +<?php |
| 2 | +namespace Flowpack\ElasticSearch\ContentRepositoryQueueIndexer; |
| 3 | + |
| 4 | +use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexer; |
| 5 | +use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface; |
| 6 | +use TYPO3\Flow\Annotations as Flow; |
| 7 | +use TYPO3\Flow\Utility\Algorithms; |
| 8 | +use TYPO3\Jobqueue\Common\Job\JobInterface; |
| 9 | +use TYPO3\Jobqueue\Common\Queue\Message; |
| 10 | +use TYPO3\Jobqueue\Common\Queue\QueueInterface; |
| 11 | +use TYPO3\TYPO3CR\Domain\Factory\NodeFactory; |
| 12 | +use TYPO3\TYPO3CR\Domain\Model\NodeData; |
| 13 | +use TYPO3\TYPO3CR\Domain\Model\NodeInterface; |
| 14 | +use TYPO3\TYPO3CR\Domain\Repository\NodeDataRepository; |
| 15 | +use TYPO3\TYPO3CR\Domain\Service\ContextFactory; |
| 16 | + |
| 17 | +/** |
| 18 | + * ElasticSearch Indexing Job Interface |
| 19 | + */ |
| 20 | +class UpdateAliasJob implements JobInterface { |
| 21 | + |
| 22 | + /** |
| 23 | + * @var NodeIndexer |
| 24 | + * @Flow\Inject |
| 25 | + */ |
| 26 | + protected $nodeIndexer; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var LoggerInterface |
| 30 | + * @Flow\Inject |
| 31 | + */ |
| 32 | + protected $logger; |
| 33 | + |
| 34 | + /** |
| 35 | + * @var string |
| 36 | + */ |
| 37 | + protected $identifier; |
| 38 | + |
| 39 | + /** |
| 40 | + * @var string |
| 41 | + */ |
| 42 | + protected $indexPostfix; |
| 43 | + |
| 44 | + /** |
| 45 | + * @param string $indexPostfix |
| 46 | + * @param string $workspaceName |
| 47 | + * @param array $nodes |
| 48 | + */ |
| 49 | + public function __construct($indexPostfix) { |
| 50 | + $this->identifier = Algorithms::generateRandomString(24); |
| 51 | + $this->indexPostfix = $indexPostfix; |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Execute the job |
| 56 | + * A job should finish itself after successful execution using the queue methods. |
| 57 | + * |
| 58 | + * @param QueueInterface $queue |
| 59 | + * @param Message $message The original message |
| 60 | + * @return boolean TRUE if the job was executed successfully and the message should be finished |
| 61 | + */ |
| 62 | + public function execute(QueueInterface $queue, Message $message) { |
| 63 | + $this->nodeIndexer->setIndexNamePostfix($this->indexPostfix); |
| 64 | + $this->nodeIndexer->updateIndexAlias(); |
| 65 | + $this->logger->log(sprintf('Update Index Alias (%s)', $this->indexPostfix), LOG_NOTICE); |
| 66 | + |
| 67 | + return TRUE; |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Get an optional identifier for the job |
| 72 | + * |
| 73 | + * @return string A job identifier |
| 74 | + */ |
| 75 | + public function getIdentifier() { |
| 76 | + return $this->identifier; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Get a readable label for the job |
| 81 | + * |
| 82 | + * @return string A label for the job |
| 83 | + */ |
| 84 | + public function getLabel() { |
| 85 | + return sprintf('ElasticSearch Indexing Job (%s)', $this->getIdentifier()); |
| 86 | + } |
| 87 | + |
| 88 | +} |
0 commit comments