Make core deletion configurable

This commit is contained in:
Sebastian Meyer 2020-12-23 09:13:42 +01:00
parent d5c882a0ff
commit 366c9ae2d1
3 changed files with 47 additions and 39 deletions

View File

@ -353,48 +353,52 @@ class DataHandler
$command === 'delete' $command === 'delete'
&& $table == 'tx_dlf_solrcores' && $table == 'tx_dlf_solrcores'
) { ) {
// Delete core from Apache Solr as well. // Is core deletion allowed in extension configuration?
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dlf']);
->getQueryBuilderForTable('tx_dlf_solrcores'); if (!empty($extConf['solrAllowCoreDelete'])) {
// Record in "tx_dlf_solrcores" is already deleted at this point. // Delete core from Apache Solr as well.
$queryBuilder $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getRestrictions() ->getQueryBuilderForTable('tx_dlf_solrcores');
->removeByType(DeletedRestriction::class); // Record in "tx_dlf_solrcores" is already deleted at this point.
$queryBuilder
->getRestrictions()
->removeByType(DeletedRestriction::class);
$result = $queryBuilder $result = $queryBuilder
->select( ->select(
'tx_dlf_solrcores.index_name AS core' 'tx_dlf_solrcores.index_name AS core'
) )
->from('tx_dlf_solrcores') ->from('tx_dlf_solrcores')
->where($queryBuilder->expr()->eq('tx_dlf_solrcores.uid', intval($id))) ->where($queryBuilder->expr()->eq('tx_dlf_solrcores.uid', intval($id)))
->setMaxResults(1) ->setMaxResults(1)
->execute(); ->execute();
$allResults = $result->fetchAll(); $allResults = $result->fetchAll();
if (count($allResults) == 1) { if (count($allResults) == 1) {
$resArray = $allResults[0]; $resArray = $allResults[0];
// Establish Solr connection. // Establish Solr connection.
$solr = Solr::getInstance(); $solr = Solr::getInstance();
if ($solr->ready) { if ($solr->ready) {
// Delete Solr core. // Delete Solr core.
$query = $solr->service->createCoreAdmin(); $query = $solr->service->createCoreAdmin();
$action = $query->createUnload(); $action = $query->createUnload();
$action->setCore($resArray['core']); $action->setCore($resArray['core']);
$action->setDeleteDataDir(true); $action->setDeleteDataDir(true);
$action->setDeleteIndex(true); $action->setDeleteIndex(true);
$action->setDeleteInstanceDir(true); $action->setDeleteInstanceDir(true);
$query->setAction($action); $query->setAction($action);
try { try {
$response = $solr->service->coreAdmin($query); $response = $solr->service->coreAdmin($query);
if ($response->getWasSuccessful()) { if ($response->getWasSuccessful()) {
return; return;
}
} catch (\Exception $e) {
// Nothing to do here.
} }
} catch (\Exception $e) {
// Nothing to do here.
} }
Helper::devLog('Core ' . $resArray['core'] . ' could not be deleted from Apache Solr', DEVLOG_SEVERITY_WARNING);
} }
Helper::devLog('Core ' . $resArray['core'] . ' could not be deleted from Apache Solr', DEVLOG_SEVERITY_WARNING);
} }
} }
} }

View File

@ -189,13 +189,14 @@
<label index="config.iiifThumbnailWidth">Maximum thumbnail width for IIIF images: Only for images without a thumbnail declaration (default is "150")</label> <label index="config.iiifThumbnailWidth">Maximum thumbnail width for IIIF images: Only for images without a thumbnail declaration (default is "150")</label>
<label index="config.iiifThumbnailHeight">Maximum thumbnail height for IIIF images: Only for images without a thumbnail declaration (default is "150")</label> <label index="config.iiifThumbnailHeight">Maximum thumbnail height for IIIF images: Only for images without a thumbnail declaration (default is "150")</label>
<label index="config.solrConnect">Solr Connection</label> <label index="config.solrConnect">Solr Connection</label>
<label index="config.solrHttps">Use https: (default is "FALSE")</label> <label index="config.solrHttps">Use HTTPS: (default is "FALSE")</label>
<label index="config.solrHost">Solr Server Host: (default is "localhost")</label> <label index="config.solrHost">Solr Server Host: (default is "localhost")</label>
<label index="config.solrPort">Solr Server Port: (default is "8983")</label> <label index="config.solrPort">Solr Server Port: (default is "8983")</label>
<label index="config.solrPath">Solr Server Path: without API endpoint "/solr" (default is "/")</label> <label index="config.solrPath">Solr Server Path: without API endpoint "/solr" (default is "/")</label>
<label index="config.solrUser">Solr Server User: (default is "")</label> <label index="config.solrUser">Solr Server User: (default is "")</label>
<label index="config.solrPass">Solr Server Password: (default is "")</label> <label index="config.solrPass">Solr Server Password: (default is "")</label>
<label index="config.solrTimeout">Solr Server Timeout: (default is "10")</label> <label index="config.solrTimeout">Solr Server Timeout: (default is "10")</label>
<label index="config.solrAllowCoreDelete">Allow Solr Core Deletion?: If a Solr Core is deleted in the TYPO3 Backend, should it be deleted in Apache Solr as well? (Standard ist "FALSE")</label>
</languageKey> </languageKey>
<languageKey index="de" type="array"> <languageKey index="de" type="array">
<label index="tx_dlf_actionlog">Aktionsprotokoll</label> <label index="tx_dlf_actionlog">Aktionsprotokoll</label>
@ -291,7 +292,7 @@
<label index="tx_dlf_solrcores">Solr Kerne</label> <label index="tx_dlf_solrcores">Solr Kerne</label>
<label index="tx_dlf_solrcores.label">Anzeigeform</label> <label index="tx_dlf_solrcores.label">Anzeigeform</label>
<label index="tx_dlf_solrcores.index_name">Solr-Bezeichnung</label> <label index="tx_dlf_solrcores.index_name">Solr-Bezeichnung</label>
<label index="tx_dlf_solrcores.tab1">General</label> <label index="tx_dlf_solrcores.tab1">Allgemein</label>
<label index="tx_dlf_collections">Sammlungen</label> <label index="tx_dlf_collections">Sammlungen</label>
<label index="tx_dlf_collections.label">Anzeigeform</label> <label index="tx_dlf_collections.label">Anzeigeform</label>
<label index="tx_dlf_collections.index_name">Index-Bezeichnung</label> <label index="tx_dlf_collections.index_name">Index-Bezeichnung</label>
@ -372,13 +373,14 @@
<label index="config.iiifThumbnailWidth">Maximale Thumbnail-Breite für IIIF-Images: Gilt nur für Bilder ohne Thumbnail-Angaben (Standard ist "150")</label> <label index="config.iiifThumbnailWidth">Maximale Thumbnail-Breite für IIIF-Images: Gilt nur für Bilder ohne Thumbnail-Angaben (Standard ist "150")</label>
<label index="config.iiifThumbnailHeight">Maximale Thumbnail-Höhe für IIIF-Images: Gilt nur für Bilder ohne Thumbnail-Angaben (Standard ist "150")</label> <label index="config.iiifThumbnailHeight">Maximale Thumbnail-Höhe für IIIF-Images: Gilt nur für Bilder ohne Thumbnail-Angaben (Standard ist "150")</label>
<label index="config.solrConnect">Solr Verbindung</label> <label index="config.solrConnect">Solr Verbindung</label>
<label index="config.solrHttps">Https verwenden: (Standard ist "FALSE")</label> <label index="config.solrHttps">HTTPS verwenden: (Standard ist "FALSE")</label>
<label index="config.solrHost">Solr Server Host: (Standard ist "localhost")</label> <label index="config.solrHost">Solr Server Host: (Standard ist "localhost")</label>
<label index="config.solrPort">Solr Server Port: (Standard ist "8983")</label> <label index="config.solrPort">Solr Server Port: (Standard ist "8983")</label>
<label index="config.solrPath">Solr Server Pfad: ohne API-Endpunkt "/solr" (Standard ist "/")</label> <label index="config.solrPath">Solr Server Pfad: ohne API-Endpunkt "/solr" (Standard ist "/")</label>
<label index="config.solrUser">Solr Server Benutzername: (Standard ist "")</label> <label index="config.solrUser">Solr Server Benutzername: (Standard ist "")</label>
<label index="config.solrPass">Solr Server Kennwort: (Standard ist "")</label> <label index="config.solrPass">Solr Server Kennwort: (Standard ist "")</label>
<label index="config.solrTimeout">Solr Server Timeout: (Standard ist "10")</label> <label index="config.solrTimeout">Solr Server Timeout: (Standard ist "10")</label>
<label index="config.solrAllowCoreDelete">Löschen von Solr Kern zulassen?: Soll beim Löschen eines Solr Kerns im TYPO3 Backend auch der entsprechende Index in Apache Solr gelöscht werden? (Standard ist "FALSE")</label>
</languageKey> </languageKey>
</data> </data>
</T3locallang> </T3locallang>

View File

@ -44,3 +44,5 @@ solrUser =
solrPass = solrPass =
# cat=Solr; type=string; label=LLL:EXT:dlf/Resources/Private/Language/Labels.xml:config.solrTimeout # cat=Solr; type=string; label=LLL:EXT:dlf/Resources/Private/Language/Labels.xml:config.solrTimeout
solrTimeout = 10 solrTimeout = 10
# cat=Solr; type=boolean; label=LLL:EXT:dlf/Resources/Private/Language/Labels.xml:config.solrAllowCoreDelete
solrAllowCoreDelete = 0