We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 17 |
| Paths | 152 |
| Total Lines | 117 |
| Code Lines | 81 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 284 | public function processCmdmap_postProcess($command, $table, $id) |
||
| 285 | { |
||
| 286 | if ( |
||
| 287 | in_array($command, ['move', 'delete', 'undelete']) |
||
| 288 | && $table == 'tx_dlf_documents' |
||
| 289 | ) { |
||
| 290 | // Get Solr core. |
||
| 291 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 292 | ->getQueryBuilderForTable('tx_dlf_solrcores'); |
||
| 293 | // Record in "tx_dlf_documents" is already deleted at this point. |
||
| 294 | $queryBuilder |
||
| 295 | ->getRestrictions() |
||
| 296 | ->removeByType(DeletedRestriction::class); |
||
| 297 | |||
| 298 | $result = $queryBuilder |
||
| 299 | ->select( |
||
| 300 | 'tx_dlf_solrcores.uid AS core' |
||
| 301 | ) |
||
| 302 | ->innerJoin( |
||
| 303 | 'tx_dlf_solrcores', |
||
| 304 | 'tx_dlf_documents', |
||
| 305 | 'tx_dlf_documents_join', |
||
| 306 | $queryBuilder->expr()->eq( |
||
| 307 | 'tx_dlf_documents_join.solrcore', |
||
| 308 | 'tx_dlf_solrcores.uid' |
||
| 309 | ) |
||
| 310 | ) |
||
| 311 | ->from('tx_dlf_solrcores') |
||
| 312 | ->where( |
||
| 313 | $queryBuilder->expr()->eq( |
||
| 314 | 'tx_dlf_documents_join.uid', |
||
| 315 | intval($id) |
||
| 316 | ) |
||
| 317 | ) |
||
| 318 | ->setMaxResults(1) |
||
| 319 | ->execute(); |
||
| 320 | |||
| 321 | $allResults = $result->fetchAll(); |
||
| 322 | |||
| 323 | if (count($allResults) == 1) { |
||
| 324 | $resArray = $allResults[0]; |
||
| 325 | switch ($command) { |
||
| 326 | case 'move': |
||
| 327 | case 'delete': |
||
| 328 | // Establish Solr connection. |
||
| 329 | $solr = Solr::getInstance($resArray['core']); |
||
| 330 | if ($solr->ready) { |
||
| 331 | // Delete Solr document. |
||
| 332 | $updateQuery = $solr->service->createUpdate(); |
||
| 333 | $updateQuery->addDeleteQuery('uid:' . $id); |
||
| 334 | $updateQuery->addCommit(); |
||
| 335 | $solr->service->update($updateQuery); |
||
| 336 | if ($command == 'delete') { |
||
| 337 | break; |
||
| 338 | } |
||
| 339 | } |
||
| 340 | case 'undelete': |
||
| 341 | // Reindex document. |
||
| 342 | $doc = Document::getInstance($id); |
||
| 343 | if ($doc->ready) { |
||
| 344 | Indexer::add($doc, $resArray['core']); |
||
| 345 | } else { |
||
| 346 | Helper::devLog('Failed to re-index document with UID ' . $id, DEVLOG_SEVERITY_ERROR); |
||
| 347 | } |
||
| 348 | break; |
||
| 349 | } |
||
| 350 | } |
||
| 351 | } |
||
| 352 | if ( |
||
| 353 | $command === 'delete' |
||
| 354 | && $table == 'tx_dlf_solrcores' |
||
| 355 | ) { |
||
| 356 | // Is core deletion allowed in extension configuration? |
||
| 357 | $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dlf']); |
||
| 358 | if (!empty($extConf['solrAllowCoreDelete'])) { |
||
| 359 | // Delete core from Apache Solr as well. |
||
| 360 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 361 | ->getQueryBuilderForTable('tx_dlf_solrcores'); |
||
| 362 | // Record in "tx_dlf_solrcores" is already deleted at this point. |
||
| 363 | $queryBuilder |
||
| 364 | ->getRestrictions() |
||
| 365 | ->removeByType(DeletedRestriction::class); |
||
| 366 | |||
| 367 | $result = $queryBuilder |
||
| 368 | ->select( |
||
| 369 | 'tx_dlf_solrcores.index_name AS core' |
||
| 370 | ) |
||
| 371 | ->from('tx_dlf_solrcores') |
||
| 372 | ->where($queryBuilder->expr()->eq('tx_dlf_solrcores.uid', intval($id))) |
||
| 373 | ->setMaxResults(1) |
||
| 374 | ->execute(); |
||
| 375 | |||
| 376 | $allResults = $result->fetchAll(); |
||
| 377 | |||
| 378 | if (count($allResults) == 1) { |
||
| 379 | $resArray = $allResults[0]; |
||
| 380 | // Establish Solr connection. |
||
| 381 | $solr = Solr::getInstance(); |
||
| 382 | if ($solr->ready) { |
||
| 383 | // Delete Solr core. |
||
| 384 | $query = $solr->service->createCoreAdmin(); |
||
| 385 | $action = $query->createUnload(); |
||
| 386 | $action->setCore($resArray['core']); |
||
| 387 | $action->setDeleteDataDir(true); |
||
| 388 | $action->setDeleteIndex(true); |
||
| 389 | $action->setDeleteInstanceDir(true); |
||
| 390 | $query->setAction($action); |
||
| 391 | try { |
||
| 392 | $response = $solr->service->coreAdmin($query); |
||
| 393 | if ($response->getWasSuccessful()) { |
||
| 394 | return; |
||
| 395 | } |
||
| 396 | } catch (\Exception $e) { |
||
| 397 | // Nothing to do here. |
||
| 398 | } |
||
| 399 | } |
||
| 400 | Helper::devLog('Core ' . $resArray['core'] . ' could not be deleted from Apache Solr', DEVLOG_SEVERITY_WARNING); |
||
| 401 | } |
||
| 406 |