Total Complexity | 65 |
Total Lines | 422 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like tx_dlf_tcemain often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use tx_dlf_tcemain, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | class tx_dlf_tcemain { |
||
21 | |||
22 | /** |
||
23 | * Field post-processing hook for the process_datamap() method. |
||
24 | * |
||
25 | * @access public |
||
26 | * |
||
27 | * @param string $status: 'new' or 'update' |
||
28 | * @param string $table: The destination table |
||
29 | * @param integer $id: The uid of the record |
||
30 | * @param array &$fieldArray: Array of field values |
||
31 | * @param \TYPO3\CMS\Core\DataHandling\DataHandler $pObj: The parent object |
||
|
|||
32 | * |
||
33 | * @return void |
||
34 | */ |
||
35 | public function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray, $pObj) { |
||
36 | |||
37 | if ($status == 'new') { |
||
38 | |||
39 | switch ($table) { |
||
40 | |||
41 | // Field post-processing for table "tx_dlf_documents". |
||
42 | case 'tx_dlf_documents': |
||
43 | |||
44 | // Set sorting field if empty. |
||
45 | if (empty($fieldArray['title_sorting']) && !empty($fieldArray['title'])) { |
||
46 | |||
47 | $fieldArray['title_sorting'] = $fieldArray['title']; |
||
48 | |||
49 | } |
||
50 | |||
51 | break; |
||
52 | |||
53 | // Field post-processing for table "tx_dlf_metadata". |
||
54 | case 'tx_dlf_metadata': |
||
55 | |||
56 | // Store field in index if it should appear in lists. |
||
57 | if (!empty($fieldArray['is_listed'])) { |
||
58 | |||
59 | $fieldArray['index_stored'] = 1; |
||
60 | |||
61 | } |
||
62 | |||
63 | // Index field in index if it should be used for auto-completion. |
||
64 | if (!empty($fieldArray['index_autocomplete'])) { |
||
65 | |||
66 | $fieldArray['index_indexed'] = 1; |
||
67 | |||
68 | } |
||
69 | |||
70 | // Field post-processing for tables "tx_dlf_metadata", "tx_dlf_collections", "tx_dlf_libraries" and "tx_dlf_structures". |
||
71 | case 'tx_dlf_collections': |
||
72 | case 'tx_dlf_libraries': |
||
73 | case 'tx_dlf_structures': |
||
74 | |||
75 | // Set label as index name if empty. |
||
76 | if (empty($fieldArray['index_name']) && !empty($fieldArray['label'])) { |
||
77 | |||
78 | $fieldArray['index_name'] = $fieldArray['label']; |
||
79 | |||
80 | } |
||
81 | |||
82 | // Set index name as label if empty. |
||
83 | if (empty($fieldArray['label']) && !empty($fieldArray['index_name'])) { |
||
84 | |||
85 | $fieldArray['label'] = $fieldArray['index_name']; |
||
86 | |||
87 | } |
||
88 | |||
89 | // Ensure that index names don't get mixed up with sorting values. |
||
90 | if (substr($fieldArray['index_name'], -8) == '_sorting') { |
||
91 | |||
92 | $fieldArray['index_name'] .= '0'; |
||
93 | |||
94 | } |
||
95 | |||
96 | break; |
||
97 | |||
98 | // Field post-processing for table "tx_dlf_solrcores". |
||
99 | case 'tx_dlf_solrcores': |
||
100 | |||
101 | // Get number of existing cores. |
||
102 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
103 | '*', |
||
104 | 'tx_dlf_solrcores', |
||
105 | '', |
||
106 | '', |
||
107 | '', |
||
108 | '' |
||
109 | ); |
||
110 | |||
111 | // Get first unused core number. |
||
112 | $coreNumber = tx_dlf_solr::solrGetCoreNumber($GLOBALS['TYPO3_DB']->sql_num_rows($result)); |
||
113 | |||
114 | // Get Solr credentials. |
||
115 | $conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dlf']); |
||
116 | |||
117 | // Prepend username and password to hostname. |
||
118 | if ($conf['solrUser'] && $conf['solrPass']) { |
||
119 | |||
120 | $host = $conf['solrUser'].':'.$conf['solrPass'].'@'.($conf['solrHost'] ? $conf['solrHost'] : 'localhost'); |
||
121 | |||
122 | } else { |
||
123 | |||
124 | $host = ($conf['solrHost'] ? $conf['solrHost'] : 'localhost'); |
||
125 | |||
126 | } |
||
127 | |||
128 | // Set port if not set. |
||
129 | $port = (intval($conf['solrPort']) > 0 ? intval($conf['solrPort']) : 8180); |
||
130 | |||
131 | // Trim path and append trailing slash. |
||
132 | $path = (trim($conf['solrPath'], '/') ? trim($conf['solrPath'], '/').'/' : ''); |
||
133 | |||
134 | $context = stream_context_create(array ( |
||
135 | 'http' => array ( |
||
136 | 'method' => 'GET', |
||
137 | 'user_agent' => ($conf['useragent'] ? $conf['useragent'] : ini_get('user_agent')) |
||
138 | ) |
||
139 | )); |
||
140 | |||
141 | // Build request for adding new Solr core. |
||
142 | // @see http://wiki.apache.org/solr/CoreAdmin |
||
143 | $url = 'http://'.$host.':'.$port.'/'.$path.'admin/cores?wt=xml&action=CREATE&name=dlfCore'.$coreNumber.'&instanceDir=.&dataDir=dlfCore'.$coreNumber; |
||
144 | |||
145 | $response = @simplexml_load_string(file_get_contents($url, FALSE, $context)); |
||
146 | |||
147 | // Process response. |
||
148 | if ($response) { |
||
149 | |||
150 | $status = $response->xpath('//lst[@name="responseHeader"]/int[@name="status"]'); |
||
151 | |||
152 | if ($status && $status[0] == 0) { |
||
153 | |||
154 | $fieldArray['index_name'] = 'dlfCore'.$coreNumber; |
||
155 | |||
156 | return; |
||
157 | |||
158 | } |
||
159 | |||
160 | } |
||
161 | |||
162 | if (TYPO3_DLOG) { |
||
163 | |||
164 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_tcemain->processDatamap_postProcessFieldArray('.$status.', '.$table.', '.$id.', [data], ['.get_class($pObj).'])] Could not create new Apache Solr core "dlfCore'.$coreNumber.'"', $this->extKey, SYSLOG_SEVERITY_ERROR, $fieldArray); |
||
165 | |||
166 | } |
||
167 | |||
168 | // Solr core could not be created, thus unset field array. |
||
169 | $fieldArray = array (); |
||
170 | |||
171 | break; |
||
172 | |||
173 | } |
||
174 | |||
175 | } elseif ($status == 'update') { |
||
176 | |||
177 | switch ($table) { |
||
178 | |||
179 | // Field post-processing for table "tx_dlf_metadata". |
||
180 | case 'tx_dlf_metadata': |
||
181 | |||
182 | // Store field in index if it should appear in lists. |
||
183 | if (!empty($fieldArray['is_listed'])) { |
||
184 | |||
185 | $fieldArray['index_stored'] = 1; |
||
186 | |||
187 | } |
||
188 | |||
189 | if (isset($fieldArray['index_stored']) && $fieldArray['index_stored'] == 0 && !isset($fieldArray['is_listed'])) { |
||
190 | |||
191 | // Get current configuration. |
||
192 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
193 | $table.'.is_listed AS is_listed', |
||
194 | $table, |
||
195 | $table.'.uid='.intval($id).tx_dlf_helper::whereClause($table), |
||
196 | '', |
||
197 | '', |
||
198 | '1' |
||
199 | ); |
||
200 | |||
201 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { |
||
202 | |||
203 | // Reset storing to current. |
||
204 | list ($fieldArray['index_stored']) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result); |
||
205 | |||
206 | } |
||
207 | |||
208 | } |
||
209 | |||
210 | // Index field in index if it should be used for auto-completion. |
||
211 | if (!empty($fieldArray['index_autocomplete'])) { |
||
212 | |||
213 | $fieldArray['index_indexed'] = 1; |
||
214 | |||
215 | } |
||
216 | |||
217 | if (isset($fieldArray['index_indexed']) && $fieldArray['index_indexed'] == 0 && !isset($fieldArray['index_autocomplete'])) { |
||
218 | |||
219 | // Get current configuration. |
||
220 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
221 | $table.'.index_autocomplete AS index_autocomplete', |
||
222 | $table, |
||
223 | $table.'.uid='.intval($id).tx_dlf_helper::whereClause($table), |
||
224 | '', |
||
225 | '', |
||
226 | '1' |
||
227 | ); |
||
228 | |||
229 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { |
||
230 | |||
231 | // Reset indexing to current. |
||
232 | list ($fieldArray['index_indexed']) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result); |
||
233 | |||
234 | } |
||
235 | |||
236 | } |
||
237 | |||
238 | // Field post-processing for tables "tx_dlf_metadata" and "tx_dlf_structures". |
||
239 | case 'tx_dlf_structures': |
||
240 | |||
241 | // The index name should not be changed in production. |
||
242 | if (isset($fieldArray['index_name'])) { |
||
243 | |||
244 | if (count($fieldArray) < 2) { |
||
245 | |||
246 | // Unset the whole field array. |
||
247 | $fieldArray = array (); |
||
248 | |||
249 | } else { |
||
250 | |||
251 | // Get current index name. |
||
252 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
253 | $table.'.index_name AS index_name', |
||
254 | $table, |
||
255 | $table.'.uid='.intval($id).tx_dlf_helper::whereClause($table), |
||
256 | '', |
||
257 | '', |
||
258 | '1' |
||
259 | ); |
||
260 | |||
261 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { |
||
262 | |||
263 | // Reset index name to current. |
||
264 | list ($fieldArray['index_name']) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result); |
||
265 | |||
266 | } |
||
267 | |||
268 | } |
||
269 | |||
270 | if (TYPO3_DLOG) { |
||
271 | |||
272 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_tcemain->processDatamap_postProcessFieldArray('.$status.', '.$table.', '.$id.', [data], ['.get_class($pObj).'])] Prevented change of "index_name" for UID "'.$id.'" in table "'.$table.'"', $this->extKey, SYSLOG_SEVERITY_NOTICE, $fieldArray); |
||
273 | |||
274 | } |
||
275 | |||
276 | } |
||
277 | |||
278 | break; |
||
279 | |||
280 | } |
||
281 | |||
282 | } |
||
283 | |||
284 | } |
||
285 | |||
286 | /** |
||
287 | * After database operations hook for the process_datamap() method. |
||
288 | * |
||
289 | * @access public |
||
290 | * |
||
291 | * @param string $status: 'new' or 'update' |
||
292 | * @param string $table: The destination table |
||
293 | * @param integer $id: The uid of the record |
||
294 | * @param array &$fieldArray: Array of field values |
||
295 | * @param \TYPO3\CMS\Core\DataHandling\DataHandler $pObj: The parent object |
||
296 | * |
||
297 | * @return void |
||
298 | */ |
||
299 | public function processDatamap_afterDatabaseOperations($status, $table, $id, &$fieldArray, $pObj) { |
||
363 | |||
364 | } |
||
365 | |||
366 | } |
||
367 | |||
368 | } |
||
369 | |||
370 | /** |
||
371 | * Post-processing hook for the process_cmdmap() method. |
||
372 | * |
||
373 | * @access public |
||
374 | * |
||
375 | * @param string $command: 'move', 'copy', 'localize', 'inlineLocalizeSynchronize', 'delete' or 'undelete' |
||
376 | * @param string $table: The destination table |
||
377 | * @param integer $id: The uid of the record |
||
378 | * @param mixed $value: The value for the command |
||
379 | * @param \TYPO3\CMS\Core\DataHandling\DataHandler $pObj: The parent object |
||
380 | * |
||
381 | * @return void |
||
382 | */ |
||
383 | public function processCmdmap_postProcess($command, $table, $id, $value, $pObj) { |
||
452 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths