Skip to content

Commit

Permalink
!!![BUGFIX] SolrCell broken due of EXT:solr BC change on connection conf
Browse files Browse the repository at this point in the history
EXT:solr 12.0.0 requires separate configurations for 
`path` + `core` and `username` + `password`.
All this settings must be given separately now.
The `path` setting is handled the same way as in EXT:solr also:
> Must not contain "/solr/"! Unless you have an additional "solr" segment in your path like "http://localhost:8983/solr/solr/core_en".

Fixes: #212
  • Loading branch information
dkd-kaehm committed Oct 19, 2023
1 parent 86ce68a commit cdd7134
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 10 deletions.
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/.dockerignore export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.github export-ignore
/.styleci.yml export-ignore
/Build/ export-ignore
/CONTRIBUTING.md export-ignore
/Dockerfile export-ignore
/Tests/ export-ignore
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
/.idea/
/.project
/.settings/
/Resources/Public/Documentation/
composer.lock
Documentation.HTML
index.php
tika_pid
typo3
Expand Down
30 changes: 23 additions & 7 deletions Classes/Service/Tika/SolrCellService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
namespace ApacheSolrForTypo3\Tika\Service\Tika;

use ApacheSolrForTypo3\Solr\ConnectionManager;
use ApacheSolrForTypo3\Solr\Exception\InvalidConnectionException;
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection;
use ApacheSolrForTypo3\Tika\Util;
use Solarium\QueryType\Extract\Query;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -37,6 +39,8 @@ class SolrCellService extends AbstractService

/**
* Service initialization
*
* @throws InvalidConnectionException
*/
protected function initializeService(): void
{
Expand All @@ -45,14 +49,26 @@ protected function initializeService(): void
/** @var ConnectionManager $connectionManager */
$connectionManager = GeneralUtility::makeInstance(ConnectionManager::class);

$readNode = [
'host' => $this->configuration['solrHost'],
'port' => (int)$this->configuration['solrPort'],
'path' => $this->configuration['solrPath'],
'scheme' => $this->configuration['solrScheme'],
$readEndpoint = [
'scheme' => Util::convertEnvVarStringToValue((string)$this->configuration['solrScheme']),
'host' => Util::convertEnvVarStringToValue((string)$this->configuration['solrHost']),
'port' => (int)(Util::convertEnvVarStringToValue((string)$this->configuration['solrPort'])),
'path' => Util::convertEnvVarStringToValue((string)$this->configuration['solrPath']),
'core' => Util::convertEnvVarStringToValue((string)$this->configuration['solrCore']),
];
$writeNode = $readNode;
$this->solrConnection = $connectionManager->getSolrConnectionForNodes($readNode, $writeNode);
if (!empty(trim($this->configuration['solrUsername'] ?? ''))
&& !empty(trim($this->configuration['solrPassword'] ?? ''))
) {
$readEndpoint['username'] = Util::convertEnvVarStringToValue($this->configuration['solrUsername']);
$readEndpoint['password'] = Util::convertEnvVarStringToValue($this->configuration['solrPassword']);
}
$writeEndpoint = $readEndpoint;
$this->solrConnection = $connectionManager->getSolrConnectionForEndpoints($readEndpoint, $writeEndpoint);
}

public function getSolrConnection(): SolrConnection
{
return $this->solrConnection;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions Classes/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,17 @@ public static function getTikaExtensionConfiguration(): array
{
return GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('tika');
}

public static function convertEnvVarStringToValue(string $value): string
{
if (preg_match('/%env\(([a-zA-Z0-9_]+)\)%/', $value, $matches) === 0) {
return $value;
}
$resolved = getenv($matches[1]);
if (is_string($resolved) && !empty($resolved)) {
return $resolved;
}

return $value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ protected function getConfiguration(): array
'solrScheme' => getenv('TESTING_SOLR_SCHEME') ?: 'http',
'solrHost' => getenv('TESTING_SOLR_HOST') ?: 'localhost',
'solrPort' => getenv('TESTING_SOLR_PORT') ?: 8999,
'solrPath' => getenv('TESTING_SOLR_PATH') ?: '/solr/core_en',
'solrPath' => getenv('TESTING_SOLR_PATH') ?: '/',
'solrCore' => getenv('TESTING_SOLR_CORE') ?: 'core_en',
];
}

Expand Down
13 changes: 11 additions & 2 deletions ext_conf_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,14 @@ solrHost = localhost
# cat=solr//30; type=int; label=Port
solrPort = 8983

# cat=solr//40; type=string; label=Path: Path to a Solr core
solrPath = /solr/
# cat=solr//40; type=string; label=Path: URL path to Apache Solr server
solrPath = /

# cat=solr//50; type=string; label=Core name: Apache Solr core name
solrCore = core_en

# cat=solr//60; type=user[ApacheSolrForTypo3\Tika\Lowlevel\EventListener\BlindedSecrets->hideInExtConf]; label=User name: Username for authentication on Apache Solr
solrUsername =

# cat=solr//70; type=user[ApacheSolrForTypo3\Tika\Lowlevel\EventListener\BlindedSecrets->hideInExtConf]; label=Password: Password for authentication on Apache Solr
solrPassword =

0 comments on commit cdd7134

Please sign in to comment.