Skip to content

Commit

Permalink
[!!!][TASK] Remove deprecated Node class
Browse files Browse the repository at this point in the history
Removes deprecated class ApacheSolrForTypo3\Solr\System\Solr\Node
and it's usages.

- Replace deprecated Node class with Endpoint
- Replace getUsername/getPassword with getAuthentication()

Resolves: #3630
  • Loading branch information
sfroemkenjw authored and dkd-friedrich committed Sep 25, 2023
1 parent afb986e commit 72adf9b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 172 deletions.
6 changes: 3 additions & 3 deletions Classes/ConnectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository;
use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException;
use ApacheSolrForTypo3\Solr\System\Records\Pages\PagesRepository as PagesRepositoryAtExtSolr;
use ApacheSolrForTypo3\Solr\System\Solr\Node;
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection;
use ApacheSolrForTypo3\Solr\System\Util\SiteUtility;
use Doctrine\DBAL\Exception as DBALException;
use Solarium\Core\Client\Endpoint;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Site\Entity\Site as Typo3Site;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -63,8 +63,8 @@ public function getSolrConnectionForNodes(array $readNodeConfiguration, array $w
{
$connectionHash = md5(json_encode($readNodeConfiguration) . json_encode($writeNodeConfiguration));
if (!isset(self::$connections[$connectionHash])) {
$readNode = Node::fromArray($readNodeConfiguration);
$writeNode = Node::fromArray($writeNodeConfiguration);
$readNode = new Endpoint($readNodeConfiguration);
$writeNode = new Endpoint($writeNodeConfiguration);
self::$connections[$connectionHash] = GeneralUtility::makeInstance(SolrConnection::class, $readNode, $writeNode);
}
return self::$connections[$connectionHash];
Expand Down
144 changes: 0 additions & 144 deletions Classes/System/Solr/Node.php

This file was deleted.

18 changes: 9 additions & 9 deletions Classes/System/Solr/SolrConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Psr\Http\Message\StreamFactoryInterface;
use Solarium\Client;
use Solarium\Core\Client\Adapter\Psr18Adapter;
use Solarium\Core\Client\Endpoint;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand All @@ -58,7 +59,7 @@ class SolrConnection
protected ?SchemaParser $schemaParser = null;

/**
* @var Node[]
* @var Endpoint[]
*/
protected array $nodes = [];

Expand All @@ -83,8 +84,8 @@ class SolrConnection
* @throws NotFoundExceptionInterface
*/
public function __construct(
Node $readNode,
Node $writeNode,
Endpoint $readNode,
Endpoint $writeNode,
TypoScriptConfiguration $configuration = null,
SynonymParser $synonymParser = null,
StopWordParser $stopWordParser = null,
Expand Down Expand Up @@ -112,7 +113,7 @@ public function __construct(
/**
* Returns Endpoint by key
*/
public function getNode(string $key): Node
public function getNode(string $key): Endpoint
{
return $this->nodes[$key];
}
Expand Down Expand Up @@ -200,13 +201,12 @@ protected function buildWriteService(): SolrWriteService
*/
protected function initializeClient(Client $client, string $endpointKey): Client
{
if (trim($this->getNode($endpointKey)->getUsername()) === '') {
$authentication = $this->getNode($endpointKey)->getAuthentication();
if (trim($authentication['username']) === '') {
return $client;
}

$username = $this->getNode($endpointKey)->getUsername();
$password = $this->getNode($endpointKey)->getPassword();
$this->setAuthenticationOnAllEndpoints($client, $username, $password);
$this->setAuthenticationOnAllEndpoints($client, $authentication['username'], $authentication['password']);

return $client;
}
Expand Down Expand Up @@ -236,7 +236,7 @@ protected function getClient(string $endpointKey): Client
$client->getPlugin('postbigrequest');
$client->clearEndpoints();

$newEndpointOptions = $this->getNode($endpointKey)->getSolariumClientOptions();
$newEndpointOptions = $this->getNode($endpointKey)->getOptions();
$newEndpointOptions['key'] = $endpointKey;
$client->createEndpoint($newEndpointOptions, true);

Expand Down
6 changes: 3 additions & 3 deletions Tests/Unit/ConnectionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
use ApacheSolrForTypo3\Solr\System\Records\Pages\PagesRepository;
use ApacheSolrForTypo3\Solr\System\Solr\Node;
use ApacheSolrForTypo3\Solr\System\Solr\Parser\SchemaParser;
use ApacheSolrForTypo3\Solr\System\Solr\Parser\StopWordParser;
use ApacheSolrForTypo3\Solr\System\Solr\Parser\SynonymParser;
Expand All @@ -31,6 +30,7 @@
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Solarium\Core\Client\Endpoint;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use UnexpectedValueException;

Expand Down Expand Up @@ -92,8 +92,8 @@ public function canConnect(string $host, string|int $port, string $path, string
$self = $this;
$this->connectionManager->expects(self::once())->method('getSolrConnectionForNodes')->willReturnCallback(
function ($readNode, $writeNode) use ($self) {
$readNode = Node::fromArray($readNode);
$writeNode = Node::fromArray($writeNode);
$readNode = new Endpoint($readNode);
$writeNode = new Endpoint($writeNode);
$typoScriptConfigurationMock = $self->createMock(TypoScriptConfiguration::class);
$synonymsParserMock = $self->createMock(SynonymParser::class);
$stopWordParserMock = $self->createMock(StopWordParser::class);
Expand Down
25 changes: 12 additions & 13 deletions Tests/Unit/System/Solr/SolrConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
use ApacheSolrForTypo3\Solr\System\Solr\Node;
use ApacheSolrForTypo3\Solr\System\Solr\Parser\SchemaParser;
use ApacheSolrForTypo3\Solr\System\Solr\Parser\StopWordParser;
use ApacheSolrForTypo3\Solr\System\Solr\Parser\SynonymParser;
Expand All @@ -38,8 +37,8 @@
class SolrConnectionTest extends SetUpUnitTestCase
{
/**
* @param Node|null $readNode
* @param Node|null $writeNode
* @param Endpoint|null $readNode
* @param Endpoint|null $writeNode
* @param TypoScriptConfiguration|null $configuration
* @param SynonymParser|null $synonymParser
* @param StopWordParser|null $stopWordParser
Expand All @@ -49,11 +48,11 @@ class SolrConnectionTest extends SetUpUnitTestCase
* @param RequestFactoryInterface|null $requestFactory
* @param StreamFactoryInterface|null $streamFactory
* @param EventDispatcherInterface|null $eventDispatcher
* @return SolrConnection
* @return SolrConnection|null
*/
protected function getSolrConnectionWithDummyConstructorArgs(
Node $readNode = null,
Node $writeNode = null,
Endpoint $readNode = null,
Endpoint $writeNode = null,
TypoScriptConfiguration $configuration = null,
SynonymParser $synonymParser = null,
StopWordParser $stopWordParser = null,
Expand All @@ -66,8 +65,8 @@ protected function getSolrConnectionWithDummyConstructorArgs(
): ?SolrConnection {
try {
return new SolrConnection(
$readNode ?? $this->createMock(Node::class),
$writeNode ?? $this->createMock(Node::class),
$readNode ?? $this->createMock(Endpoint::class),
$writeNode ?? $this->createMock(Endpoint::class),
$configuration ?? $this->createMock(TypoScriptConfiguration::class),
$synonymParser ?? $this->createMock(SynonymParser::class),
$stopWordParser ?? $this->createMock(StopWordParser::class),
Expand All @@ -93,7 +92,7 @@ public function authenticationIsNotTriggeredWithoutUsername()
$clientMock = $this->createMock(Client::class);
$clientMock->expects(self::any())->method('getEndpoints')->willReturn([$endpointMock]);

$readNode = Node::fromArray(
$readNode = new Endpoint(
['host' => 'localhost', 'port' => 8080, 'path' => '/solr/core_en/', 'scheme' => 'https', 'username' => '', 'password' => '']
);
$writeNode = $readNode;
Expand All @@ -113,7 +112,7 @@ public function authenticationIsTriggeredWhenUsernameIsPassed()
$clientMock = $this->createMock(Client::class);
$clientMock->expects(self::any())->method('getEndpoints')->willReturn([$endpointMock]);

$readNode = Node::fromArray(
$readNode = new Endpoint(
['host' => 'localhost', 'port' => 8080, 'path' => '/solr/core_en/', 'scheme' => 'https', 'username' => 'foo', 'password' => 'bar']
);
$writeNode = $readNode;
Expand Down Expand Up @@ -142,7 +141,7 @@ public function coreNameDataProvider(): array
public function canGetCoreName($path, $expectedCoreName)
{
$fakeConfiguration = $this->createMock(TypoScriptConfiguration::class);
$readNode = Node::fromArray(
$readNode = new Endpoint(
['host' => 'localhost', 'port' => 8080, 'path' => $path, 'scheme' => 'http', 'username' => '', 'password' => '']
);
$writeNode = $readNode;
Expand All @@ -167,7 +166,7 @@ public function coreBasePathDataProvider(): array
*/
public function canGetCoreBasePath($path, $expectedCoreBasePath)
{
$readNode = Node::fromArray(
$readNode = new Endpoint(
['host' => 'localhost', 'port' => 8080, 'path' => $path, 'scheme' => 'http', 'username' => '', 'password' => '']
);
$writeNode = $readNode;
Expand All @@ -180,7 +179,7 @@ public function canGetCoreBasePath($path, $expectedCoreBasePath)
*/
public function toStringContainsAllSegments()
{
$readNode = Node::fromArray(
$readNode = new Endpoint(
['host' => 'localhost', 'port' => 8080, 'path' => '/core_de/', 'scheme' => 'http', 'username' => '', 'password' => '']
);
$writeNode = $readNode;
Expand Down

0 comments on commit 72adf9b

Please sign in to comment.