Example #1
0
 protected function deleteDocument()
 {
     $documentUid = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('delete_uid');
     $documentType = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('delete_type');
     $message = 'Document(s) with type ' . $documentType . ' and id ' . $documentUid . ' deleted';
     $severity = t3lib_FlashMessage::OK;
     if (empty($documentUid) || empty($documentType)) {
         $message = 'Missing uid or type to delete documents.';
         $severity = t3lib_FlashMessage::ERROR;
     } else {
         try {
             $uids = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $documentUid);
             $uidCondition = implode(' OR ', $uids);
             $solrServers = $this->connectionManager->getConnectionsBySite($this->site);
             foreach ($solrServers as $solrServer) {
                 $response = $solrServer->deleteByQuery('uid:(' . $uidCondition . ')' . ' AND type:' . $documentType . ' AND siteHash:' . $this->site->getSiteHash());
                 $solrServer->commit(FALSE, FALSE, FALSE);
                 if ($response->getHttpStatus() != 200) {
                     throw new RuntimeException('Delete Query failed.', 1332250835);
                 }
             }
         } catch (Exception $e) {
             $message = $e->getMessage();
             $severity = t3lib_FlashMessage::ERROR;
         }
     }
     $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('t3lib_FlashMessage', $message, '', $severity);
     t3lib_FlashMessageQueue::addMessage($flashMessage);
 }
Example #2
0
 /**
  * Removes documents of the selected types from the index.
  *
  * @return bool TRUE if clean up was successful, FALSE on error
  */
 protected function cleanUpIndex()
 {
     $cleanUpResult = TRUE;
     $solrConfiguration = $this->site->getSolrConfiguration();
     $solrServers = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Solr_ConnectionManager')->getConnectionsBySite($this->site);
     $typesToCleanUp = array();
     foreach ($this->indexingConfigurationsToReIndex as $indexingConfigurationName) {
         $type = Tx_Solr_IndexQueue_Queue::getTableToIndexByIndexingConfigurationName($solrConfiguration, $indexingConfigurationName);
         $typesToCleanUp[] = $type;
     }
     foreach ($solrServers as $solrServer) {
         // make sure not-yet committed documents are removed, too
         $solrServer->commit();
         $deleteQuery = 'type:(' . implode(' OR ', $typesToCleanUp) . ')' . ' AND siteHash:' . $this->site->getSiteHash();
         $solrServer->deleteByQuery($deleteQuery);
         $response = $solrServer->commit(FALSE, FALSE, FALSE);
         if ($response->getHttpStatus() != 200) {
             $cleanUpResult = FALSE;
             break;
         }
     }
     return $cleanUpResult;
 }