1 | <?php |
||
40 | class IndexQueueModuleController extends AbstractModuleController |
||
41 | { |
||
42 | |||
43 | /** |
||
44 | * Module name, used to identify a module f.e. in URL parameters. |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $moduleName = 'IndexQueue'; |
||
49 | |||
50 | /** |
||
51 | * Module title, shows up in the module menu. |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $moduleTitle = 'Index Queue'; |
||
56 | |||
57 | /** |
||
58 | * @var Queue |
||
59 | */ |
||
60 | protected $indexQueue; |
||
61 | |||
62 | /** |
||
63 | * IndexQueueModuleController constructor. |
||
64 | * @param Queue $indexQueue |
||
65 | */ |
||
66 | public function __construct(Queue $indexQueue = null) |
||
67 | { |
||
68 | parent::__construct(); |
||
69 | $this->indexQueue = is_null($indexQueue) ? GeneralUtility::makeInstance(Queue::class) : $indexQueue; |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Lists the available indexing configurations |
||
74 | * |
||
75 | * @return void |
||
76 | */ |
||
77 | public function indexAction() |
||
78 | { |
||
79 | $statistics = $this->indexQueue->getStatisticsBySite($this->site); |
||
80 | $this->view->assign('indexQueueInitializationSelector', $this->getIndexQueueInitializationSelector()); |
||
81 | $this->view->assign('indexqueue_statistics', $statistics); |
||
82 | $this->view->assign('indexqueue_errors', $this->indexQueue->getErrorsBySite($this->site)); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Renders a field to select which indexing configurations to initialize. |
||
87 | * |
||
88 | * Uses TCEforms. |
||
89 | * |
||
90 | * @return string Markup for the select field |
||
91 | */ |
||
92 | protected function getIndexQueueInitializationSelector() |
||
93 | { |
||
94 | $selector = GeneralUtility::makeInstance(IndexingConfigurationSelectorField::class, $this->site); |
||
95 | $selector->setFormElementName('tx_solr-index-queue-initialization'); |
||
96 | |||
97 | return $selector->render(); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Initializes the Index Queue for selected indexing configurations |
||
102 | * |
||
103 | * @return void |
||
104 | */ |
||
105 | public function initializeIndexQueueAction() |
||
106 | { |
||
107 | $initializedIndexingConfigurations = []; |
||
108 | |||
109 | $indexingConfigurationsToInitialize = GeneralUtility::_POST('tx_solr-index-queue-initialization'); |
||
110 | if ((!empty($indexingConfigurationsToInitialize)) && (is_array($indexingConfigurationsToInitialize))) { |
||
111 | // initialize selected indexing configuration |
||
112 | foreach ($indexingConfigurationsToInitialize as $indexingConfigurationName) { |
||
113 | $initializedIndexingConfiguration = $this->indexQueue->initialize( |
||
114 | $this->site, |
||
115 | $indexingConfigurationName |
||
116 | ); |
||
117 | |||
118 | // track initialized indexing configurations for the flash message |
||
119 | $initializedIndexingConfigurations = array_merge( |
||
120 | $initializedIndexingConfigurations, |
||
121 | $initializedIndexingConfiguration |
||
122 | ); |
||
123 | } |
||
124 | } else { |
||
125 | $messageLabel = 'solr.backend.index_queue_module.flashmessage.initialize.no_selection'; |
||
126 | $titleLabel = 'solr.backend.index_queue_module.flashmessage.not_initialized.title'; |
||
127 | $this->addFlashMessage( |
||
128 | LocalizationUtility::translate($messageLabel, 'Solr'), |
||
129 | LocalizationUtility::translate($titleLabel, 'Solr'), |
||
130 | FlashMessage::WARNING |
||
131 | ); |
||
132 | } |
||
133 | |||
134 | $messagesForConfigurations = []; |
||
135 | foreach (array_keys($initializedIndexingConfigurations) as $indexingConfigurationName) { |
||
136 | $itemCount = $this->indexQueue->getItemsCountBySite($this->site, $indexingConfigurationName); |
||
137 | $messagesForConfigurations[] = $indexingConfigurationName . ' (' . $itemCount . ' records)'; |
||
138 | } |
||
139 | |||
140 | if (!empty($initializedIndexingConfigurations)) { |
||
141 | $messageLabel = 'solr.backend.index_queue_module.flashmessage.initialize.success'; |
||
142 | $titleLabel = 'solr.backend.index_queue_module.flashmessage.initialize.title'; |
||
143 | $this->addFlashMessage( |
||
144 | LocalizationUtility::translate($messageLabel, 'Solr', |
||
145 | [implode(', ', $messagesForConfigurations)]), |
||
146 | LocalizationUtility::translate($titleLabel, 'Solr'), |
||
147 | FlashMessage::OK |
||
148 | ); |
||
149 | |||
150 | $this->addFlashMessagesByQueueIdentifier('solr.queue.initializer'); |
||
151 | } |
||
152 | |||
153 | $this->forward('index'); |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * Empties the Index Queue |
||
158 | * |
||
159 | * @return void |
||
160 | */ |
||
161 | public function clearIndexQueueAction() |
||
166 | |||
167 | /** |
||
168 | * Removes all errors in the index queue list. So that the items can be indexed again. |
||
169 | * |
||
170 | * @return void |
||
171 | */ |
||
172 | public function resetLogErrorsAction() |
||
191 | |||
192 | /** |
||
193 | * Shows the error message for one queue item. |
||
194 | * |
||
195 | * @return void |
||
196 | */ |
||
197 | public function showErrorAction() |
||
218 | |||
219 | /** |
||
220 | * Indexes a few documents with the index service. |
||
221 | * @return void |
||
222 | */ |
||
223 | public function doIndexingRunAction() |
||
244 | } |
||
245 |