We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 100 |
| Total Lines | 950 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Complex classes like tx_dlf_list 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_list, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | class tx_dlf_list implements ArrayAccess, Countable, Iterator, \TYPO3\CMS\Core\SingletonInterface { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * This holds the number of documents in the list |
||
| 24 | * @see Countable |
||
| 25 | * |
||
| 26 | * @var integer |
||
| 27 | * @access protected |
||
| 28 | */ |
||
| 29 | protected $count = 0; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * This holds the list entries in sorted order |
||
| 33 | * @see ArrayAccess |
||
| 34 | * |
||
| 35 | * @var array() |
||
| 36 | * @access protected |
||
| 37 | */ |
||
| 38 | protected $elements = array (); |
||
| 39 | |||
| 40 | /** |
||
| 41 | * This holds the list's metadata |
||
| 42 | * |
||
| 43 | * @var array |
||
| 44 | * @access protected |
||
| 45 | */ |
||
| 46 | protected $metadata = array (); |
||
| 47 | |||
| 48 | /** |
||
| 49 | * This holds the current list position |
||
| 50 | * @see Iterator |
||
| 51 | * |
||
| 52 | * @var integer |
||
| 53 | * @access protected |
||
| 54 | */ |
||
| 55 | protected $position = 0; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * This holds the full records of already processed list elements |
||
| 59 | * |
||
| 60 | * @var array() |
||
| 61 | * @access protected |
||
| 62 | */ |
||
| 63 | protected $records = array (); |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Instance of Apache_Solr_Service class |
||
|
|
|||
| 67 | * |
||
| 68 | * @var Apache_Solr_Service |
||
| 69 | * @access protected |
||
| 70 | */ |
||
| 71 | protected $solr; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * This holds the Solr metadata configuration |
||
| 75 | * |
||
| 76 | * @var array |
||
| 77 | * @access protected |
||
| 78 | */ |
||
| 79 | protected $solrConfig = array (); |
||
| 80 | |||
| 81 | /** |
||
| 82 | * This adds an array of elements at the given position to the list |
||
| 83 | * |
||
| 84 | * @access public |
||
| 85 | * |
||
| 86 | * @param array $elements: Array of elements to add to list |
||
| 87 | * @param integer $position: Numeric position for including |
||
| 88 | * |
||
| 89 | * @return void |
||
| 90 | */ |
||
| 91 | public function add(array $elements, $position = -1) { |
||
| 92 | |||
| 93 | $position = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($position, 0, $this->count, $this->count); |
||
| 94 | |||
| 95 | if (!empty($elements)) { |
||
| 96 | |||
| 97 | array_splice($this->elements, $position, 0, $elements); |
||
| 98 | |||
| 99 | $this->count = count($this->elements); |
||
| 100 | |||
| 101 | } |
||
| 102 | |||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * This counts the elements |
||
| 107 | * @see Countable::count() |
||
| 108 | * |
||
| 109 | * @access public |
||
| 110 | * |
||
| 111 | * @return integer The number of elements in the list |
||
| 112 | */ |
||
| 113 | public function count() { |
||
| 116 | |||
| 117 | } |
||
| 118 | |||
| 119 | /** |
||
| 120 | * This returns the current element |
||
| 121 | * @see Iterator::current() |
||
| 122 | * |
||
| 123 | * @access public |
||
| 124 | * |
||
| 125 | * @return array The current element |
||
| 126 | */ |
||
| 127 | public function current() { |
||
| 128 | |||
| 129 | if ($this->valid()) { |
||
| 130 | |||
| 131 | return $this->getRecord($this->elements[$this->position]); |
||
| 132 | |||
| 133 | } else { |
||
| 134 | |||
| 135 | if (TYPO3_DLOG) { |
||
| 136 | |||
| 137 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_list->current()] Invalid position "'.$this->position.'" for list element', $this->extKey, SYSLOG_SEVERITY_NOTICE); |
||
| 138 | |||
| 139 | } |
||
| 140 | |||
| 141 | return; |
||
| 142 | |||
| 143 | } |
||
| 144 | |||
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * This returns the full record of any list element |
||
| 149 | * |
||
| 150 | * @access protected |
||
| 151 | * |
||
| 152 | * @param mixed $element: The list element |
||
| 153 | * |
||
| 154 | * @return mixed The element's full record |
||
| 155 | */ |
||
| 156 | protected function getRecord($element) { |
||
| 157 | |||
| 158 | if (is_array($element) && array_keys($element) == array ('u', 'h', 's', 'p')) { |
||
| 159 | |||
| 160 | // Return already processed record if possible. |
||
| 161 | if (!empty($this->records[$element['u']])) { |
||
| 162 | |||
| 163 | return $this->records[$element['u']]; |
||
| 164 | |||
| 165 | } |
||
| 166 | |||
| 167 | $record = array ( |
||
| 168 | 'uid' => $element['u'], |
||
| 169 | 'page' => 1, |
||
| 170 | 'preview' => '', |
||
| 171 | 'subparts' => $element['p'] |
||
| 172 | ); |
||
| 173 | |||
| 174 | // Check if it's a list of database records or Solr documents. |
||
| 175 | if (!empty($this->metadata['options']['source']) && $this->metadata['options']['source'] == 'collection') { |
||
| 176 | |||
| 177 | // Get document's thumbnail and metadata from database. |
||
| 178 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 179 | 'tx_dlf_documents.uid AS uid,tx_dlf_documents.thumbnail AS thumbnail,tx_dlf_documents.metadata AS metadata', |
||
| 180 | 'tx_dlf_documents', |
||
| 181 | '(tx_dlf_documents.uid='.intval($record['uid']).' OR tx_dlf_documents.partof='.intval($record['uid']).')'.tx_dlf_helper::whereClause('tx_dlf_documents'), |
||
| 182 | '', |
||
| 183 | '', |
||
| 184 | '' |
||
| 185 | ); |
||
| 186 | |||
| 187 | // Process results. |
||
| 188 | while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { |
||
| 189 | |||
| 190 | // Prepare document's metadata. |
||
| 191 | $metadata = unserialize($resArray['metadata']); |
||
| 192 | |||
| 193 | if (!empty($metadata['type'][0]) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($metadata['type'][0])) { |
||
| 194 | |||
| 195 | $metadata['type'][0] = tx_dlf_helper::getIndexName($metadata['type'][0], 'tx_dlf_structures', $this->metadata['options']['pid']); |
||
| 196 | |||
| 197 | } |
||
| 198 | |||
| 199 | if (!empty($metadata['owner'][0]) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($metadata['owner'][0])) { |
||
| 200 | |||
| 201 | $metadata['owner'][0] = tx_dlf_helper::getIndexName($metadata['owner'][0], 'tx_dlf_libraries', $this->metadata['options']['pid']); |
||
| 202 | |||
| 203 | } |
||
| 204 | |||
| 205 | if (!empty($metadata['collection']) && is_array($metadata['collection'])) { |
||
| 206 | |||
| 207 | foreach ($metadata['collection'] as $i => $collection) { |
||
| 208 | |||
| 209 | if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($collection)) { |
||
| 210 | |||
| 211 | $metadata['collection'][$i] = tx_dlf_helper::getIndexName($metadata['collection'][$i], 'tx_dlf_collections', $this->metadata['options']['pid']); |
||
| 212 | |||
| 213 | } |
||
| 214 | |||
| 215 | } |
||
| 216 | |||
| 217 | } |
||
| 218 | |||
| 219 | // Add metadata to list element. |
||
| 220 | if ($resArray['uid'] == $record['uid']) { |
||
| 221 | |||
| 222 | $record['thumbnail'] = $resArray['thumbnail']; |
||
| 223 | |||
| 224 | $record['metadata'] = $metadata; |
||
| 225 | |||
| 226 | } elseif (($key = array_search(array('u' => $resArray['uid']), $record['subparts'], TRUE)) !== FALSE) { |
||
| 227 | |||
| 228 | $record['subparts'][$key] = array ( |
||
| 229 | 'uid' => $resArray['uid'], |
||
| 230 | 'page' => 1, |
||
| 231 | 'preview' => (!empty($record['subparts'][$key]['h']) ? $record['subparts'][$key]['h'] : ''), |
||
| 232 | 'thumbnail' => $resArray['thumbnail'], |
||
| 233 | 'metadata' => $metadata |
||
| 234 | ); |
||
| 235 | |||
| 236 | } |
||
| 237 | |||
| 238 | } |
||
| 239 | |||
| 240 | } elseif (!empty($this->metadata['options']['source']) && $this->metadata['options']['source'] == 'search') { |
||
| 241 | |||
| 242 | if ($this->solrConnect()) { |
||
| 243 | |||
| 244 | $params = array (); |
||
| 245 | |||
| 246 | // Restrict the fields to the required ones |
||
| 247 | $params['fl'] = 'uid,id,toplevel,thumbnail,page'; |
||
| 248 | |||
| 249 | foreach ($this->solrConfig as $solr_name) { |
||
| 250 | |||
| 251 | $params['fl'] .= ','.$solr_name; |
||
| 252 | |||
| 253 | } |
||
| 254 | |||
| 255 | // Get document's thumbnail and metadata from Solr index. |
||
| 256 | $result = $this->solr->service->search('uid:'.tx_dlf_solr::escapeQuery($record['uid']), 0, $this->solr->limit, $params); |
||
| 257 | |||
| 258 | // If it is a fulltext search, enable highlighting and fetch the results |
||
| 259 | if ($this->metadata['fulltextSearch']) { |
||
| 260 | |||
| 261 | $params = array (); |
||
| 262 | |||
| 263 | $params['hl'] = 'true'; |
||
| 264 | $params['hl.useFastVectorHighlighter'] = 'true'; |
||
| 265 | $params['hl.fl'] = 'fulltext'; |
||
| 266 | $params['fl'] = 'id'; |
||
| 267 | |||
| 268 | $query_highlights = 'uid:'.tx_dlf_solr::escapeQuery($record['uid']).' AND fulltext:('.tx_dlf_solr::escapeQuery($this->metadata['searchString']).')'; |
||
| 269 | |||
| 270 | $result_highlights = $this->solr->service->search($query_highlights, 0, $this->solr->limit, $params); |
||
| 271 | |||
| 272 | } |
||
| 273 | |||
| 274 | // Process results. |
||
| 275 | foreach ($result->response->docs as $resArray) { |
||
| 276 | |||
| 277 | // Prepare document's metadata. |
||
| 278 | $metadata = array (); |
||
| 279 | |||
| 280 | foreach ($this->solrConfig as $index_name => $solr_name) { |
||
| 281 | |||
| 282 | if (!empty($resArray->$solr_name)) { |
||
| 283 | |||
| 284 | $metadata[$index_name] = (is_array($resArray->$solr_name) ? $resArray->$solr_name : array ($resArray->$solr_name)); |
||
| 285 | |||
| 286 | } |
||
| 287 | |||
| 288 | } |
||
| 289 | |||
| 290 | // Add metadata to list elements. |
||
| 291 | if ($resArray->toplevel) { |
||
| 292 | |||
| 293 | $record['thumbnail'] = $resArray->thumbnail; |
||
| 294 | |||
| 295 | $record['metadata'] = $metadata; |
||
| 296 | |||
| 297 | } elseif (isset($record['subparts'][$resArray->id])) { |
||
| 298 | |||
| 299 | $record['subparts'][$resArray->id] = array ( |
||
| 300 | 'uid' => $resArray->uid, |
||
| 301 | 'page' => $resArray->page, |
||
| 302 | 'preview' => (!empty($result_highlights->highlighting->{$resArray->id}->fulltext[0]) ? $result_highlights->highlighting->{$resArray->id}->fulltext[0] : ''), |
||
| 303 | 'thumbnail' => $resArray->thumbnail, |
||
| 304 | 'metadata' => $metadata |
||
| 305 | ); |
||
| 306 | |||
| 307 | } |
||
| 308 | |||
| 309 | } |
||
| 310 | |||
| 311 | } |
||
| 312 | |||
| 313 | } |
||
| 314 | |||
| 315 | // Save record for later usage. |
||
| 316 | $this->records[$element['u']] = $record; |
||
| 317 | |||
| 318 | } else { |
||
| 319 | |||
| 320 | if (TYPO3_DLOG) { |
||
| 321 | |||
| 322 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_list->getRecord([data])] No UID of list element to fetch full record', $this->extKey, SYSLOG_SEVERITY_NOTICE, $element); |
||
| 323 | |||
| 324 | } |
||
| 325 | |||
| 326 | $record = $element; |
||
| 327 | |||
| 328 | } |
||
| 329 | |||
| 330 | return $record; |
||
| 331 | |||
| 332 | } |
||
| 333 | |||
| 334 | /** |
||
| 335 | * This returns the current position |
||
| 336 | * @see Iterator::key() |
||
| 337 | * |
||
| 338 | * @access public |
||
| 339 | * |
||
| 340 | * @return integer The current position |
||
| 341 | */ |
||
| 342 | public function key() { |
||
| 343 | |||
| 344 | return $this->position; |
||
| 345 | |||
| 346 | } |
||
| 347 | |||
| 348 | |||
| 349 | |||
| 350 | /** |
||
| 351 | * This moves the element at the given position up or down |
||
| 352 | * |
||
| 353 | * @access public |
||
| 354 | * |
||
| 355 | * @param integer $position: Numeric position for moving |
||
| 356 | * @param integer $steps: Amount of steps to move up or down |
||
| 357 | * |
||
| 358 | * @return void |
||
| 359 | */ |
||
| 360 | public function move($position, $steps) { |
||
| 361 | |||
| 362 | // Save parameters for logging purposes. |
||
| 363 | $_position = $position; |
||
| 364 | |||
| 365 | $_steps = $steps; |
||
| 366 | |||
| 367 | $position = intval($position); |
||
| 368 | |||
| 369 | // Check if list position is valid. |
||
| 370 | if ($position < 0 || $position >= $this->count) { |
||
| 371 | |||
| 372 | if (TYPO3_DLOG) { |
||
| 373 | |||
| 374 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_list->move('.$_position.', '.$_steps.')] Invalid position "'.$position.'" for element moving', $this->extKey, SYSLOG_SEVERITY_WARNING); |
||
| 375 | |||
| 376 | } |
||
| 377 | |||
| 378 | return; |
||
| 379 | |||
| 380 | } |
||
| 381 | |||
| 382 | $steps = intval($steps); |
||
| 383 | |||
| 384 | // Check if moving given amount of steps is possible. |
||
| 385 | if (($position + $steps) < 0 || ($position + $steps) >= $this->count) { |
||
| 386 | |||
| 387 | if (TYPO3_DLOG) { |
||
| 388 | |||
| 389 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_list->move('.$_position.', '.$_steps.')] Invalid steps "'.$steps.'" for moving element at position "'.$position.'"', $this->extKey, SYSLOG_SEVERITY_WARNING); |
||
| 390 | |||
| 391 | } |
||
| 392 | |||
| 393 | return; |
||
| 394 | |||
| 395 | } |
||
| 396 | |||
| 397 | $element = $this->remove($position); |
||
| 398 | |||
| 399 | $this->add(array ($element), $position + $steps); |
||
| 400 | |||
| 401 | } |
||
| 402 | |||
| 403 | /** |
||
| 404 | * This moves the element at the given position up |
||
| 405 | * |
||
| 406 | * @access public |
||
| 407 | * |
||
| 408 | * @param integer $position: Numeric position for moving |
||
| 409 | * |
||
| 410 | * @return void |
||
| 411 | */ |
||
| 412 | public function moveUp($position) { |
||
| 413 | |||
| 414 | $this->move($position, -1); |
||
| 415 | |||
| 416 | } |
||
| 417 | |||
| 418 | /** |
||
| 419 | * This moves the element at the given position down |
||
| 420 | * |
||
| 421 | * @access public |
||
| 422 | * |
||
| 423 | * @param integer $position: Numeric position for moving |
||
| 424 | * |
||
| 425 | * @return void |
||
| 426 | */ |
||
| 427 | public function moveDown($position) { |
||
| 428 | |||
| 429 | $this->move($position, 1); |
||
| 430 | |||
| 431 | } |
||
| 432 | |||
| 433 | /** |
||
| 434 | * This increments the current list position |
||
| 435 | * @see Iterator::next() |
||
| 436 | * |
||
| 437 | * @access public |
||
| 438 | * |
||
| 439 | * @return void |
||
| 440 | */ |
||
| 441 | public function next() { |
||
| 442 | |||
| 443 | $this->position++; |
||
| 444 | |||
| 445 | } |
||
| 446 | |||
| 447 | /** |
||
| 448 | * This checks if an offset exists |
||
| 449 | * @see ArrayAccess::offsetExists() |
||
| 450 | * |
||
| 451 | * @access public |
||
| 452 | * |
||
| 453 | * @param mixed $offset: The offset to check |
||
| 454 | * |
||
| 455 | * @return boolean Does the given offset exist? |
||
| 456 | */ |
||
| 457 | public function offsetExists($offset) { |
||
| 458 | |||
| 459 | return isset($this->elements[$offset]); |
||
| 460 | |||
| 461 | } |
||
| 462 | |||
| 463 | /** |
||
| 464 | * This returns the element at the given offset |
||
| 465 | * @see ArrayAccess::offsetGet() |
||
| 466 | * |
||
| 467 | * @access public |
||
| 468 | * |
||
| 469 | * @param mixed $offset: The offset to return |
||
| 470 | * |
||
| 471 | * @return array The element at the given offset |
||
| 472 | */ |
||
| 473 | public function offsetGet($offset) { |
||
| 488 | |||
| 489 | } |
||
| 490 | |||
| 491 | } |
||
| 492 | |||
| 493 | /** |
||
| 494 | * This sets the element at the given offset |
||
| 495 | * @see ArrayAccess::offsetSet() |
||
| 496 | * |
||
| 497 | * @access public |
||
| 498 | * |
||
| 499 | * @param mixed $offset: The offset to set (non-integer offsets will be appended) |
||
| 500 | * @param mixed $value: The value to set |
||
| 501 | * |
||
| 502 | * @return void |
||
| 503 | */ |
||
| 504 | public function offsetSet($offset, $value) { |
||
| 520 | |||
| 521 | } |
||
| 522 | |||
| 523 | /** |
||
| 524 | * This removes the element at the given position from the list |
||
| 525 | * |
||
| 526 | * @access public |
||
| 527 | * |
||
| 528 | * @param integer $position: Numeric position for removing |
||
| 529 | * |
||
| 530 | * @return array The removed element |
||
| 531 | */ |
||
| 532 | public function remove($position) { |
||
| 556 | |||
| 557 | } |
||
| 558 | |||
| 559 | /** |
||
| 560 | * This removes elements at the given range from the list |
||
| 561 | * |
||
| 562 | * @access public |
||
| 563 | * |
||
| 564 | * @param integer $position: Numeric position for start of range |
||
| 565 | * |
||
| 566 | * @param integer $length: Numeric position for length of range |
||
| 567 | * |
||
| 568 | * @return array The indizes of the removed elements |
||
| 569 | */ |
||
| 570 | public function removeRange($position, $length) { |
||
| 571 | |||
| 572 | // Save parameter for logging purposes. |
||
| 573 | $_position = $position; |
||
| 574 | |||
| 575 | $position = intval($position); |
||
| 576 | |||
| 577 | if ($position < 0 || $position >= $this->count) { |
||
| 578 | |||
| 579 | if (TYPO3_DLOG) { |
||
| 580 | |||
| 581 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_list->remove('.$_position.')] Invalid position "'.$position.'" for element removing', $this->extKey, SYSLOG_SEVERITY_WARNING); |
||
| 582 | } |
||
| 583 | |||
| 584 | return; |
||
| 585 | } |
||
| 586 | |||
| 587 | $removed = array_splice($this->elements, $position, $length); |
||
| 588 | |||
| 589 | $this->count = count($this->elements); |
||
| 590 | |||
| 591 | return $removed; |
||
| 592 | } |
||
| 593 | |||
| 594 | /** |
||
| 595 | * This clears the current list |
||
| 596 | * |
||
| 597 | * @access public |
||
| 598 | * |
||
| 599 | * @return void |
||
| 600 | */ |
||
| 601 | public function reset() { |
||
| 602 | |||
| 603 | $this->elements = array (); |
||
| 604 | |||
| 605 | $this->records = array (); |
||
| 606 | |||
| 607 | $this->metadata = array (); |
||
| 608 | |||
| 609 | $this->count = 0; |
||
| 610 | |||
| 611 | $this->position = 0; |
||
| 612 | |||
| 613 | } |
||
| 614 | |||
| 615 | /** |
||
| 616 | * This resets the list position |
||
| 617 | * @see Iterator::rewind() |
||
| 618 | * |
||
| 619 | * @access public |
||
| 620 | * |
||
| 621 | * @return void |
||
| 622 | */ |
||
| 623 | public function rewind() { |
||
| 624 | |||
| 625 | $this->position = 0; |
||
| 626 | |||
| 627 | } |
||
| 628 | |||
| 629 | /** |
||
| 630 | * This saves the current list |
||
| 631 | * |
||
| 632 | * @access public |
||
| 633 | * |
||
| 634 | * @param integer $pid: PID for saving in database |
||
| 635 | * |
||
| 636 | * @return void |
||
| 637 | */ |
||
| 638 | public function save($pid = 0) { |
||
| 639 | |||
| 640 | $pid = max(intval($pid), 0); |
||
| 641 | |||
| 642 | // If no PID is given, save to the user's session instead |
||
| 643 | if ($pid > 0) { |
||
| 644 | |||
| 645 | // TODO: Liste in Datenbank speichern (inkl. Sichtbarkeit, Beschreibung, etc.) |
||
| 646 | |||
| 647 | } else { |
||
| 648 | |||
| 649 | tx_dlf_helper::saveToSession(array ($this->elements, $this->metadata), get_class($this)); |
||
| 650 | |||
| 651 | } |
||
| 652 | |||
| 653 | } |
||
| 654 | |||
| 655 | /** |
||
| 656 | * Connects to Solr server. |
||
| 657 | * |
||
| 658 | * @access protected |
||
| 659 | * |
||
| 660 | * @return boolean TRUE on success or FALSE on failure |
||
| 661 | */ |
||
| 662 | protected function solrConnect() { |
||
| 663 | |||
| 664 | // Get Solr instance. |
||
| 665 | if (!$this->solr) { |
||
| 666 | |||
| 667 | // Connect to Solr server. |
||
| 668 | if ($this->solr = tx_dlf_solr::getInstance($this->metadata['options']['core'])) { |
||
| 669 | |||
| 670 | // Load index configuration. |
||
| 671 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 672 | 'tx_dlf_metadata.index_name AS index_name,tx_dlf_metadata.index_tokenized AS index_tokenized,tx_dlf_metadata.index_indexed AS index_indexed', |
||
| 673 | 'tx_dlf_metadata', |
||
| 674 | 'tx_dlf_metadata.is_listed=1 AND tx_dlf_metadata.pid='.intval($this->metadata['options']['pid']).tx_dlf_helper::whereClause('tx_dlf_metadata'), |
||
| 675 | '', |
||
| 676 | 'tx_dlf_metadata.sorting ASC', |
||
| 677 | '' |
||
| 678 | ); |
||
| 679 | |||
| 680 | while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { |
||
| 681 | |||
| 682 | $this->solrConfig[$resArray['index_name']] = $resArray['index_name'].'_'.($resArray['index_tokenized'] ? 't' : 'u').'s'.($resArray['index_indexed'] ? 'i' : 'u'); |
||
| 683 | |||
| 684 | } |
||
| 685 | |||
| 686 | // Add static fields. |
||
| 687 | $this->solrConfig['type'] = 'type'; |
||
| 688 | |||
| 689 | } else { |
||
| 690 | |||
| 691 | return FALSE; |
||
| 692 | |||
| 693 | } |
||
| 694 | |||
| 695 | } |
||
| 696 | |||
| 697 | return TRUE; |
||
| 698 | |||
| 699 | } |
||
| 700 | |||
| 701 | /** |
||
| 702 | * This sorts the current list by the given field |
||
| 703 | * |
||
| 704 | * @access public |
||
| 705 | * |
||
| 706 | * @param string $by: Sort the list by this field |
||
| 707 | * @param boolean $asc: Sort ascending? |
||
| 708 | * |
||
| 709 | * @return void |
||
| 710 | */ |
||
| 711 | public function sort($by, $asc = TRUE) { |
||
| 712 | |||
| 713 | $newOrder = array (); |
||
| 714 | |||
| 715 | $nonSortable = array (); |
||
| 716 | |||
| 717 | foreach ($this->elements as $num => $element) { |
||
| 718 | |||
| 719 | // Is this element sortable? |
||
| 720 | if (!empty($element['s'][$by])) { |
||
| 721 | |||
| 722 | $newOrder[$element['s'][$by].str_pad($num, 6, '0', STR_PAD_LEFT)] = $element; |
||
| 723 | |||
| 724 | } else { |
||
| 725 | |||
| 726 | $nonSortable[] = $element; |
||
| 727 | |||
| 728 | } |
||
| 729 | |||
| 730 | } |
||
| 731 | |||
| 732 | // Reorder elements. |
||
| 733 | if ($asc) { |
||
| 734 | |||
| 735 | ksort($newOrder, SORT_LOCALE_STRING); |
||
| 736 | |||
| 737 | } else { |
||
| 738 | |||
| 739 | krsort($newOrder, SORT_LOCALE_STRING); |
||
| 740 | |||
| 741 | } |
||
| 742 | |||
| 743 | // Add non sortable elements to the end of the list. |
||
| 744 | $newOrder = array_merge(array_values($newOrder), $nonSortable); |
||
| 745 | |||
| 746 | // Check if something is missing. |
||
| 747 | if ($this->count == count($newOrder)) { |
||
| 748 | |||
| 749 | $this->elements = $newOrder; |
||
| 750 | |||
| 751 | } else { |
||
| 752 | |||
| 753 | if (TYPO3_DLOG) { |
||
| 754 | |||
| 755 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_list->sort('.$by.', ['.($asc ? 'TRUE' : 'FALSE').'])] Sorted list elements do not match unsorted elements', $this->extKey, SYSLOG_SEVERITY_ERROR); |
||
| 756 | |||
| 757 | } |
||
| 758 | |||
| 759 | } |
||
| 760 | |||
| 761 | } |
||
| 762 | |||
| 763 | /** |
||
| 764 | * This unsets the element at the given offset |
||
| 765 | * @see ArrayAccess::offsetUnset() |
||
| 766 | * |
||
| 767 | * @access public |
||
| 768 | * |
||
| 769 | * @param mixed $offset: The offset to unset |
||
| 770 | * |
||
| 771 | * @return void |
||
| 772 | */ |
||
| 773 | public function offsetUnset($offset) { |
||
| 774 | |||
| 775 | unset ($this->elements[$offset]); |
||
| 776 | |||
| 777 | // Re-number the elements. |
||
| 778 | $this->elements = array_values($this->elements); |
||
| 779 | |||
| 780 | $this->count = count($this->elements); |
||
| 781 | |||
| 782 | } |
||
| 783 | |||
| 784 | /** |
||
| 785 | * This checks if the current list position is valid |
||
| 786 | * @see Iterator::valid() |
||
| 787 | * |
||
| 788 | * @access public |
||
| 789 | * |
||
| 790 | * @return boolean Is the current list position valid? |
||
| 791 | */ |
||
| 792 | public function valid() { |
||
| 793 | |||
| 794 | return isset($this->elements[$this->position]); |
||
| 795 | |||
| 796 | } |
||
| 797 | |||
| 798 | /** |
||
| 799 | * This returns $this->metadata via __get() |
||
| 800 | * |
||
| 801 | * @access protected |
||
| 802 | * |
||
| 803 | * @return array The list's metadata |
||
| 804 | */ |
||
| 805 | protected function _getMetadata() { |
||
| 806 | |||
| 807 | return $this->metadata; |
||
| 808 | |||
| 809 | } |
||
| 810 | |||
| 811 | /** |
||
| 812 | * This sets $this->metadata via __set() |
||
| 813 | * |
||
| 814 | * @access protected |
||
| 815 | * |
||
| 816 | * @param array $metadata: Array of new metadata |
||
| 817 | * |
||
| 818 | * @return void |
||
| 819 | */ |
||
| 820 | protected function _setMetadata(array $metadata = array ()) { |
||
| 821 | |||
| 822 | $this->metadata = $metadata; |
||
| 823 | |||
| 824 | } |
||
| 825 | |||
| 826 | /** |
||
| 827 | * This is the constructor |
||
| 828 | * |
||
| 829 | * @access public |
||
| 830 | * |
||
| 831 | * @param array $elements: Array of documents initially setting up the list |
||
| 832 | * @param array $metadata: Array of initial metadata |
||
| 833 | * |
||
| 834 | * @return void |
||
| 835 | */ |
||
| 836 | public function __construct(array $elements = array (), array $metadata = array ()) { |
||
| 837 | |||
| 838 | if (empty($elements) && empty($metadata)) { |
||
| 839 | |||
| 840 | // Let's check the user's session. |
||
| 841 | $sessionData = tx_dlf_helper::loadFromSession(get_class($this)); |
||
| 842 | |||
| 843 | // Restore list from session data. |
||
| 844 | if (is_array($sessionData)) { |
||
| 845 | |||
| 846 | if (is_array($sessionData[0])) { |
||
| 847 | |||
| 848 | $this->elements = $sessionData[0]; |
||
| 849 | |||
| 850 | } |
||
| 851 | |||
| 852 | if (is_array($sessionData[1])) { |
||
| 853 | |||
| 854 | $this->metadata = $sessionData[1]; |
||
| 855 | |||
| 856 | } |
||
| 857 | |||
| 858 | } |
||
| 859 | |||
| 860 | } else { |
||
| 861 | |||
| 862 | // Add metadata to the list. |
||
| 863 | $this->metadata = $metadata; |
||
| 864 | |||
| 865 | // Add initial set of elements to the list. |
||
| 866 | $this->elements = $elements; |
||
| 867 | |||
| 868 | } |
||
| 869 | |||
| 870 | $this->count = count($this->elements); |
||
| 871 | |||
| 872 | } |
||
| 873 | |||
| 874 | /** |
||
| 875 | * This magic method is invoked each time a clone is called on the object variable |
||
| 876 | * (This method is defined as private/protected because singleton objects should not be cloned) |
||
| 877 | * |
||
| 878 | * @access protected |
||
| 879 | * |
||
| 880 | * @return void |
||
| 881 | */ |
||
| 882 | protected function __clone() {} |
||
| 883 | |||
| 884 | /** |
||
| 885 | * This magic method is called each time an invisible property is referenced from the object |
||
| 886 | * |
||
| 887 | * @access public |
||
| 888 | * |
||
| 889 | * @param string $var: Name of variable to get |
||
| 890 | * |
||
| 891 | * @return mixed Value of $this->$var |
||
| 892 | */ |
||
| 893 | public function __get($var) { |
||
| 894 | |||
| 895 | $method = '_get'.ucfirst($var); |
||
| 896 | |||
| 897 | if (!property_exists($this, $var) || !method_exists($this, $method)) { |
||
| 898 | |||
| 899 | if (TYPO3_DLOG) { |
||
| 900 | |||
| 901 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_list->__get('.$var.')] There is no getter function for property "'.$var.'"', $this->extKey, SYSLOG_SEVERITY_WARNING); |
||
| 902 | |||
| 903 | } |
||
| 904 | |||
| 905 | return; |
||
| 906 | |||
| 907 | } else { |
||
| 908 | |||
| 909 | return $this->$method(); |
||
| 910 | |||
| 911 | } |
||
| 912 | |||
| 913 | } |
||
| 914 | |||
| 915 | /** |
||
| 916 | * This magic method is called each time an invisible property is referenced from the object |
||
| 917 | * |
||
| 918 | * @access public |
||
| 919 | * |
||
| 920 | * @param string $var: Name of variable to set |
||
| 921 | * @param mixed $value: New value of variable |
||
| 922 | * |
||
| 923 | * @return void |
||
| 924 | */ |
||
| 925 | public function __set($var, $value) { |
||
| 926 | |||
| 927 | $method = '_set'.ucfirst($var); |
||
| 928 | |||
| 929 | if (!property_exists($this, $var) || !method_exists($this, $method)) { |
||
| 930 | |||
| 931 | if (TYPO3_DLOG) { |
||
| 932 | |||
| 933 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_list->__set('.$var.', [data])] There is no setter function for property "'.$var.'"', $this->extKey, SYSLOG_SEVERITY_WARNING, $value); |
||
| 934 | |||
| 935 | } |
||
| 936 | |||
| 937 | } else { |
||
| 938 | |||
| 939 | $this->$method($value); |
||
| 940 | |||
| 941 | } |
||
| 942 | |||
| 943 | } |
||
| 944 | |||
| 945 | /** |
||
| 946 | * This magic method is executed prior to any serialization of the object |
||
| 947 | * @see __wakeup() |
||
| 948 | * |
||
| 949 | * @access public |
||
| 950 | * |
||
| 951 | * @return array Properties to be serialized |
||
| 952 | */ |
||
| 953 | public function __sleep() { |
||
| 954 | |||
| 955 | return array ('elements', 'metadata'); |
||
| 956 | |||
| 957 | } |
||
| 958 | |||
| 959 | /** |
||
| 960 | * This magic method is executed after the object is deserialized |
||
| 961 | * @see __sleep() |
||
| 962 | * |
||
| 963 | * @access public |
||
| 964 | * |
||
| 965 | * @return void |
||
| 966 | */ |
||
| 967 | public function __wakeup() { |
||
| 970 | |||
| 971 | } |
||
| 972 | |||
| 973 | } |
||
| 974 |
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