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 | 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 |
||
| 291 | public function processCmdmap_postProcess($command, $table, $id) |
||
| 292 | { |
||
| 293 | if ( |
||
| 294 | in_array($command, ['move', 'delete', 'undelete']) |
||
| 295 | && $table == 'tx_dlf_documents' |
||
| 296 | ) { |
||
| 297 | // Get Solr core. |
||
| 298 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 299 | ->getQueryBuilderForTable('tx_dlf_solrcores'); |
||
| 300 | // Record in "tx_dlf_documents" is already deleted at this point. |
||
| 301 | $queryBuilder |
||
| 302 | ->getRestrictions() |
||
| 303 | ->removeByType(DeletedRestriction::class); |
||
| 304 | |||
| 305 | $result = $queryBuilder |
||
| 306 | ->select( |
||
| 307 | 'tx_dlf_solrcores.uid AS core' |
||
| 308 | ) |
||
| 309 | ->innerJoin( |
||
| 310 | 'tx_dlf_solrcores', |
||
| 311 | 'tx_dlf_documents', |
||
| 312 | 'tx_dlf_documents_join', |
||
| 313 | $queryBuilder->expr()->eq( |
||
| 314 | 'tx_dlf_documents_join.solrcore', |
||
| 315 | 'tx_dlf_solrcores.uid' |
||
| 316 | ) |
||
| 317 | ) |
||
| 318 | ->from('tx_dlf_solrcores') |
||
| 319 | ->where( |
||
| 320 | $queryBuilder->expr()->eq( |
||
| 321 | 'tx_dlf_documents_join.uid', |
||
| 322 | intval($id) |
||
| 323 | ) |
||
| 324 | ) |
||
| 325 | ->setMaxResults(1) |
||
| 326 | ->execute(); |
||
| 327 | |||
| 328 | $allResults = $result->fetchAll(); |
||
| 329 | |||
| 330 | if (count($allResults) == 1) { |
||
| 331 | $resArray = $allResults[0]; |
||
| 332 | switch ($command) { |
||
| 333 | case 'move': |
||
| 334 | case 'delete': |
||
| 335 | // Establish Solr connection. |
||
| 336 | $solr = Solr::getInstance($resArray['core']); |
||
| 337 | if ($solr->ready) { |
||
| 338 | // Delete Solr document. |
||
| 339 | $updateQuery = $solr->service->createUpdate(); |
||
| 340 | $updateQuery->addDeleteQuery('uid:' . $id); |
||
| 341 | $updateQuery->addCommit(); |
||
| 342 | $solr->service->update($updateQuery); |
||
| 343 | if ($command == 'delete') { |
||
| 344 | break; |
||
| 345 | } |
||
| 346 | } |
||
| 347 | case 'undelete': |
||
| 348 | // Reindex document. |
||
| 349 | $doc = Doc::getInstance($id); |
||
| 350 | if ($doc->ready) { |
||
| 351 | Indexer::add($doc, $resArray['core']); |
||
|
|
|||
| 352 | } else { |
||
| 353 | $this->logger->error('Failed to re-index document with UID ' . $id); |
||
| 354 | } |
||
| 355 | break; |
||
| 356 | } |
||
| 357 | } |
||
| 358 | } |
||
| 359 | if ( |
||
| 360 | $command === 'delete' |
||
| 361 | && $table == 'tx_dlf_solrcores' |
||
| 362 | ) { |
||
| 363 | // Is core deletion allowed in extension configuration? |
||
| 364 | $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf'); |
||
| 365 | if (!empty($extConf['solrAllowCoreDelete'])) { |
||
| 366 | // Delete core from Apache Solr as well. |
||
| 367 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 368 | ->getQueryBuilderForTable('tx_dlf_solrcores'); |
||
| 369 | // Record in "tx_dlf_solrcores" is already deleted at this point. |
||
| 370 | $queryBuilder |
||
| 371 | ->getRestrictions() |
||
| 372 | ->removeByType(DeletedRestriction::class); |
||
| 373 | |||
| 374 | $result = $queryBuilder |
||
| 375 | ->select( |
||
| 376 | 'tx_dlf_solrcores.index_name AS core' |
||
| 377 | ) |
||
| 378 | ->from('tx_dlf_solrcores') |
||
| 379 | ->where($queryBuilder->expr()->eq('tx_dlf_solrcores.uid', intval($id))) |
||
| 380 | ->setMaxResults(1) |
||
| 381 | ->execute(); |
||
| 382 | |||
| 383 | $allResults = $result->fetchAll(); |
||
| 384 | |||
| 385 | if (count($allResults) == 1) { |
||
| 386 | $resArray = $allResults[0]; |
||
| 387 | // Establish Solr connection. |
||
| 388 | $solr = Solr::getInstance(); |
||
| 389 | if ($solr->ready) { |
||
| 390 | // Delete Solr core. |
||
| 391 | $query = $solr->service->createCoreAdmin(); |
||
| 392 | $action = $query->createUnload(); |
||
| 393 | $action->setCore($resArray['core']); |
||
| 394 | $action->setDeleteDataDir(true); |
||
| 395 | $action->setDeleteIndex(true); |
||
| 396 | $action->setDeleteInstanceDir(true); |
||
| 397 | $query->setAction($action); |
||
| 398 | try { |
||
| 399 | $response = $solr->service->coreAdmin($query); |
||
| 400 | if ($response->getWasSuccessful()) { |
||
| 401 | return; |
||
| 402 | } |
||
| 403 | } catch (\Exception $e) { |
||
| 404 | // Nothing to do here. |
||
| 405 | } |
||
| 406 | } |
||
| 407 | $this->logger->warning('Core ' . $resArray['core'] . ' could not be deleted from Apache Solr'); |
||
| 408 | } |
||
| 413 |