We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 18 |
| Paths | 152 |
| Total Lines | 113 |
| Code Lines | 79 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 269 | public function processCmdmap_postProcess($command, $table, $id) |
||
| 270 | { |
||
| 271 | if ( |
||
| 272 | in_array($command, ['move', 'delete', 'undelete']) |
||
| 273 | && $table == 'tx_dlf_documents' |
||
| 274 | ) { |
||
| 275 | // Get Solr core. |
||
| 276 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 277 | ->getQueryBuilderForTable('tx_dlf_solrcores'); |
||
| 278 | // Record in "tx_dlf_documents" is already deleted at this point. |
||
| 279 | $queryBuilder |
||
| 280 | ->getRestrictions() |
||
| 281 | ->removeByType(DeletedRestriction::class); |
||
| 282 | |||
| 283 | $result = $queryBuilder |
||
| 284 | ->select( |
||
| 285 | 'tx_dlf_solrcores.uid AS core' |
||
| 286 | ) |
||
| 287 | ->innerJoin( |
||
| 288 | 'tx_dlf_solrcores', |
||
| 289 | 'tx_dlf_documents', |
||
| 290 | 'tx_dlf_documents_join', |
||
| 291 | $queryBuilder->expr()->eq( |
||
| 292 | 'tx_dlf_documents_join.solrcore', |
||
| 293 | 'tx_dlf_solrcores.uid' |
||
| 294 | ) |
||
| 295 | ) |
||
| 296 | ->from('tx_dlf_solrcores') |
||
| 297 | ->where( |
||
| 298 | $queryBuilder->expr()->eq( |
||
| 299 | 'tx_dlf_documents_join.uid', |
||
| 300 | intval($id) |
||
| 301 | ) |
||
| 302 | ) |
||
| 303 | ->setMaxResults(1) |
||
| 304 | ->execute(); |
||
| 305 | |||
| 306 | if ($resArray = $result->fetch()) { |
||
| 307 | switch ($command) { |
||
| 308 | case 'move': |
||
| 309 | case 'delete': |
||
| 310 | // Establish Solr connection. |
||
| 311 | $solr = Solr::getInstance($resArray['core']); |
||
| 312 | if ($solr->ready) { |
||
| 313 | // Delete Solr document. |
||
| 314 | $updateQuery = $solr->service->createUpdate(); |
||
| 315 | $updateQuery->addDeleteQuery('uid:' . $id); |
||
| 316 | $updateQuery->addCommit(); |
||
| 317 | $solr->service->update($updateQuery); |
||
| 318 | if ($command == 'delete') { |
||
| 319 | break; |
||
| 320 | } |
||
| 321 | } |
||
| 322 | case 'undelete': |
||
| 323 | // Reindex document. |
||
| 324 | $document = $this->documentRepository->findByUid($id); |
||
| 325 | $doc = Doc::getInstance($document->getLocation(), ['storagePid' => $document->getPid()], true); |
||
| 326 | if ($document !== null && $doc !== null) { |
||
| 327 | $document->setDoc($doc); |
||
| 328 | Indexer::add($document); |
||
| 329 | } else { |
||
| 330 | $this->logger->error('Failed to re-index document with UID ' . $id); |
||
| 331 | } |
||
| 332 | break; |
||
| 333 | } |
||
| 334 | } |
||
| 335 | } |
||
| 336 | if ( |
||
| 337 | $command === 'delete' |
||
| 338 | && $table == 'tx_dlf_solrcores' |
||
| 339 | ) { |
||
| 340 | // Is core deletion allowed in extension configuration? |
||
| 341 | $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf'); |
||
| 342 | if (!empty($extConf['solrAllowCoreDelete'])) { |
||
| 343 | // Delete core from Apache Solr as well. |
||
| 344 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 345 | ->getQueryBuilderForTable('tx_dlf_solrcores'); |
||
| 346 | // Record in "tx_dlf_solrcores" is already deleted at this point. |
||
| 347 | $queryBuilder |
||
| 348 | ->getRestrictions() |
||
| 349 | ->removeByType(DeletedRestriction::class); |
||
| 350 | |||
| 351 | $result = $queryBuilder |
||
| 352 | ->select( |
||
| 353 | 'tx_dlf_solrcores.index_name AS core' |
||
| 354 | ) |
||
| 355 | ->from('tx_dlf_solrcores') |
||
| 356 | ->where($queryBuilder->expr()->eq('tx_dlf_solrcores.uid', intval($id))) |
||
| 357 | ->setMaxResults(1) |
||
| 358 | ->execute(); |
||
| 359 | |||
| 360 | if ($resArray = $result->fetch()) { |
||
| 361 | // Establish Solr connection. |
||
| 362 | $solr = Solr::getInstance(); |
||
| 363 | if ($solr->ready) { |
||
| 364 | // Delete Solr core. |
||
| 365 | $query = $solr->service->createCoreAdmin(); |
||
| 366 | $action = $query->createUnload(); |
||
| 367 | $action->setCore($resArray['core']); |
||
| 368 | $action->setDeleteDataDir(true); |
||
| 369 | $action->setDeleteIndex(true); |
||
| 370 | $action->setDeleteInstanceDir(true); |
||
| 371 | $query->setAction($action); |
||
| 372 | try { |
||
| 373 | $response = $solr->service->coreAdmin($query); |
||
| 374 | if ($response->getWasSuccessful()) { |
||
| 375 | return; |
||
| 376 | } |
||
| 377 | } catch (\Exception $e) { |
||
| 378 | // Nothing to do here. |
||
| 379 | } |
||
| 380 | } |
||
| 381 | $this->logger->warning('Core ' . $resArray['core'] . ' could not be deleted from Apache Solr'); |
||
| 382 | } |
||
| 387 |