Skip to content

Commit

Permalink
[TASK] Use solarium as http client
Browse files Browse the repository at this point in the history
  • Loading branch information
Timo Schmidt committed Aug 10, 2018
1 parent 7bb24ba commit 044df49
Show file tree
Hide file tree
Showing 88 changed files with 1,311 additions and 5,422 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -11,6 +11,6 @@ typo3conf
typo3temp
uploads
vendor
composer.lock
/composer.lock
.Build
Documentation/_make
7 changes: 4 additions & 3 deletions Classes/AdditionalFieldsIndexer.php
Expand Up @@ -25,6 +25,7 @@
***************************************************************/
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
use ApacheSolrForTypo3\Solr\System\ContentObject\ContentObjectService;
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand Down Expand Up @@ -78,10 +79,10 @@ public function __construct(TypoScriptConfiguration $configuration = null, Conte
* Uses the original document and adds fields as defined in
* plugin.tx_solr.index.additionalFields.
*
* @param \Apache_Solr_Document $pageDocument The original page document.
* @return \Apache_Solr_Document A Apache_Solr_Document object that replace the default page document
* @param Document $pageDocument The original page document.
* @return Document A Apache Solr Document object that replace the default page document
*/
public function getPageDocument(\Apache_Solr_Document $pageDocument)
public function getPageDocument(Document $pageDocument)
{
$substitutePageDocument = clone $pageDocument;
$additionalFields = $this->getAdditionalFields();
Expand Down
9 changes: 4 additions & 5 deletions Classes/AdditionalPageIndexer.php
Expand Up @@ -27,6 +27,8 @@
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;

/**
* Interface that defines the method an indexer must implement to provide
* additional documents to index for a page being indexed.
Expand All @@ -39,12 +41,9 @@ interface AdditionalPageIndexer
/**
* Provides additional documents that should be indexed together with a page.
*
* @param \Apache_Solr_Document $pageDocument The original page document.
* @param Document $pageDocument The original page document.
* @param array $allDocuments An array containing all the documents collected until here, including the page document
* @return array An array of additional Apache_Solr_Document objects
*/
public function getAdditionalPageDocuments(
\Apache_Solr_Document $pageDocument,
array $allDocuments
);
public function getAdditionalPageDocuments(Document $pageDocument, array $allDocuments);
}
12 changes: 6 additions & 6 deletions Classes/Controller/Backend/Search/AbstractModuleController.php
Expand Up @@ -211,16 +211,16 @@ protected function generateCoreSelectorMenu(Site $site, string $uriToRedirectTo
foreach ($cores as $core) {
$coreAdmin = $core->getAdminService();
$menuItem = $this->coreSelectorMenu->makeMenuItem();
$menuItem->setTitle($coreAdmin->getPath());
$menuItem->setTitle($coreAdmin->getCorePath());
$uri = $this->uriBuilder->reset()->uriFor('switchCore',
[
'corePath' => $coreAdmin->getPath(),
'corePath' => $coreAdmin->getCorePath(),
'uriToRedirectTo' => $uriToRedirectTo
]
);
$menuItem->setHref($uri);

if ($coreAdmin->getPath() == $this->selectedSolrCoreConnection->getAdminService()->getPath()) {
if ($coreAdmin->getCorePath() == $this->selectedSolrCoreConnection->getAdminService()->getCorePath()) {
$menuItem->setActive(true);
}
$this->coreSelectorMenu->addMenuItem($menuItem);
Expand Down Expand Up @@ -264,13 +264,13 @@ private function initializeSelectedSolrCoreConnection()
return;
}
foreach ($solrCoreConnections as $solrCoreConnection) {
if ($solrCoreConnection->getAdminService()->getPath() == $currentSolrCorePath) {
if ($solrCoreConnection->getAdminService()->getCorePath() == $currentSolrCorePath) {
$this->selectedSolrCoreConnection = $solrCoreConnection;
}
}
if (!$this->selectedSolrCoreConnection instanceof SolrCoreConnection && count($solrCoreConnections) > 0) {
$this->initializeFirstAvailableSolrCoreConnection($solrCoreConnections, $moduleData);
$message = LocalizationUtility::translate('coreselector_switched_to_default_core', 'solr', [$currentSolrCorePath, $this->selectedSite->getLabel(), $this->selectedSolrCoreConnection->getAdminService()->getPath()]);
$message = LocalizationUtility::translate('coreselector_switched_to_default_core', 'solr', [$currentSolrCorePath, $this->selectedSite->getLabel(), $this->selectedSolrCoreConnection->getAdminService()->getCorePath()]);
$this->addFlashMessage($message, '', AbstractMessage::NOTICE);
}
}
Expand All @@ -284,7 +284,7 @@ private function initializeFirstAvailableSolrCoreConnection(array $solrCoreConne
return;
}
$this->selectedSolrCoreConnection = $solrCoreConnections[0];
$moduleData->setCore($this->selectedSolrCoreConnection->getAdminService()->getPath());
$moduleData->setCore($this->selectedSolrCoreConnection->getAdminService()->getCorePath());
$this->moduleDataStorageService->persistModuleData($moduleData);
}
}
23 changes: 12 additions & 11 deletions Classes/Controller/Backend/Search/InfoModuleController.php
Expand Up @@ -28,6 +28,7 @@
use ApacheSolrForTypo3\Solr\ConnectionManager;
use ApacheSolrForTypo3\Solr\Domain\Search\Statistics\StatisticsRepository;
use ApacheSolrForTypo3\Solr\Domain\Search\ApacheSolrDocument\Repository;
use ApacheSolrForTypo3\Solr\System\Solr\ResponseAdapter;
use ApacheSolrForTypo3\Solr\System\Validator\Path;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
Expand Down Expand Up @@ -132,16 +133,16 @@ protected function collectConnectionInfos()

foreach ($connections as $connection) {
$coreAdmin = $connection->getAdminService();
$coreUrl = $coreAdmin->getScheme() . '://' . $coreAdmin->getHost() . ':' . $coreAdmin->getPort() . $coreAdmin->getPath();
$coreUrl = (string)$coreAdmin;

if ($coreAdmin->ping()) {
$connectedHosts[] = $coreUrl;
} else {
$missingHosts[] = $coreUrl;
}

if (!$path->isValidSolrPath($coreAdmin->getPath())) {
$invalidPaths[] = $coreAdmin->getPath();
if (!$path->isValidSolrPath($coreAdmin->getCorePath())) {
$invalidPaths[] = $coreAdmin->getCorePath();
}
}

Expand Down Expand Up @@ -208,7 +209,7 @@ protected function collectIndexFieldsInfo()
$coreAdmin = $solrCoreConnection->getAdminService();

$indexFieldsInfo = [
'corePath' => $coreAdmin->getPath()
'corePath' => $coreAdmin->getCorePath()
];
if ($coreAdmin->ping()) {
$lukeData = $coreAdmin->getLukeMetaData();
Expand Down Expand Up @@ -238,11 +239,11 @@ protected function collectIndexFieldsInfo()

$this->addFlashMessage(
'',
'Unable to contact Apache Solr server: ' . $this->selectedSite->getLabel() . ' ' . $coreAdmin->getPath(),
'Unable to contact Apache Solr server: ' . $this->selectedSite->getLabel() . ' ' . $coreAdmin->getCorePath(),
FlashMessage::ERROR
);
}
$indexFieldsInfoByCorePaths[$coreAdmin->getPath()] = $indexFieldsInfo;
$indexFieldsInfoByCorePaths[$coreAdmin->getCorePath()] = $indexFieldsInfo;
}
$this->view->assign('indexFieldsInfoByCorePaths', $indexFieldsInfoByCorePaths);
}
Expand All @@ -262,7 +263,7 @@ protected function collectIndexInspectorInfo()

$documentsByType = [];
foreach ($documents as $document) {
$documentsByType[$document->type][] = $document;
$documentsByType[$document['type']][] = $document;
}

$documentsByCoreAndType[$languageId]['core'] = $coreAdmin;
Expand All @@ -278,12 +279,12 @@ protected function collectIndexInspectorInfo()
/**
* Gets field metrics.
*
* @param \Apache_Solr_Response $lukeData Luke index data
* @param ResponseAdapter $lukeData Luke index data
* @param string $limitNote Note to display if there are too many documents in the index to show number of terms for a field
*
* @return array An array of field metrics
*/
protected function getFields(\Apache_Solr_Response $lukeData, $limitNote)
protected function getFields(ResponseAdapter $lukeData, $limitNote)
{
$rows = [];

Expand All @@ -304,12 +305,12 @@ protected function getFields(\Apache_Solr_Response $lukeData, $limitNote)
/**
* Gets general core metrics.
*
* @param \Apache_Solr_Response $lukeData Luke index data
* @param ResponseAdapter $lukeData Luke index data
* @param array $fields Fields metrics
*
* @return array An array of core metrics
*/
protected function getCoreMetrics(\Apache_Solr_Response $lukeData, array $fields)
protected function getCoreMetrics(ResponseAdapter $lukeData, array $fields)
{
$coreMetrics = [
'numberOfDocuments' => $lukeData->index->numDocs,
Expand Down
38 changes: 19 additions & 19 deletions Classes/Domain/Search/ApacheSolrDocument/Builder.php
Expand Up @@ -24,11 +24,11 @@
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

use Apache_Solr_Document;
use ApacheSolrForTypo3\Solr\Access\Rootline;
use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository;
use ApacheSolrForTypo3\Solr\Domain\Variants\IdBuilder;
use ApacheSolrForTypo3\Solr\Site;
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
use ApacheSolrForTypo3\Solr\Typo3PageContentExtractor;
use ApacheSolrForTypo3\Solr\Util;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -58,18 +58,18 @@ public function __construct(IdBuilder $variantIdBuilder = null)
}

/**
* This method can be used to build an Apache_Solr_Document from a TYPO3 page.
* This method can be used to build an Document from a TYPO3 page.
*
* @param TypoScriptFrontendController $page
* @param string $url
* @param Rootline $pageAccessRootline
* @param string $mountPointParameter
* @return Apache_Solr_Document|object
* @return Document|object
*/
public function fromPage(TypoScriptFrontendController $page, $url, Rootline $pageAccessRootline, $mountPointParameter): \Apache_Solr_Document
public function fromPage(TypoScriptFrontendController $page, $url, Rootline $pageAccessRootline, $mountPointParameter): Document
{
/* @var $document \Apache_Solr_Document */
$document = GeneralUtility::makeInstance(Apache_Solr_Document::class);
/* @var $document Document */
$document = GeneralUtility::makeInstance(Document::class);
$site = $this->getSiteByPageId($page->id);
$pageRecord = $page->page;

Expand Down Expand Up @@ -126,12 +126,12 @@ public function fromPage(TypoScriptFrontendController $page, $url, Rootline $pag
* @param string $type
* @param int $rootPageUid
* @param string $accessRootLine
* @return Apache_Solr_Document
* @return Document
*/
public function fromRecord(array $itemRecord, string $type, int $rootPageUid, string $accessRootLine): \Apache_Solr_Document
public function fromRecord(array $itemRecord, string $type, int $rootPageUid, string $accessRootLine): Document
{
/* @var $document Apache_Solr_Document */
$document = GeneralUtility::makeInstance(Apache_Solr_Document::class);
/* @var $document Document */
$document = GeneralUtility::makeInstance(Document::class);

$site = $this->getSiteByPageId($rootPageUid);

Expand Down Expand Up @@ -254,10 +254,10 @@ protected function getDocumentIdGroups(Rootline $pageAccessRootline)
/**
* Adds the access field to the document if needed.
*
* @param \Apache_Solr_Document $document
* @param Document $document
* @param Rootline $pageAccessRootline
*/
protected function addAccessField(\Apache_Solr_Document $document, Rootline $pageAccessRootline)
protected function addAccessField(Document $document, Rootline $pageAccessRootline)
{
$access = (string)$pageAccessRootline;
if (trim($access) !== '') {
Expand All @@ -266,12 +266,12 @@ protected function addAccessField(\Apache_Solr_Document $document, Rootline $pag
}

/**
* Adds the endtime field value to the Apache_Solr_Document.
* Adds the endtime field value to the Document.
*
* @param \Apache_Solr_Document $document
* @param Document $document
* @param array $pageRecord
*/
protected function addEndtimeField(\Apache_Solr_Document $document, $pageRecord)
protected function addEndtimeField(Document $document, $pageRecord)
{
if ($pageRecord['endtime']) {
$document->setField('endtime', $pageRecord['endtime']);
Expand All @@ -281,10 +281,10 @@ protected function addEndtimeField(\Apache_Solr_Document $document, $pageRecord
/**
* Adds keywords, multi valued.
*
* @param \Apache_Solr_Document $document
* @param Document $document
* @param array $pageRecord
*/
protected function addKeywordsField(\Apache_Solr_Document $document, $pageRecord)
protected function addKeywordsField(Document $document, $pageRecord)
{
if (!isset($pageRecord['keywords'])) {
return;
Expand All @@ -299,10 +299,10 @@ protected function addKeywordsField(\Apache_Solr_Document $document, $pageRecord
/**
* Add content from several tags like headers, anchors, ...
*
* @param \Apache_Solr_Document $document
* @param Document $document
* @param array $tagContent
*/
protected function addTagContentFields(\Apache_Solr_Document $document, $tagContent = [])
protected function addTagContentFields(Document $document, $tagContent = [])
{
foreach ($tagContent as $fieldName => $fieldValue) {
$document->setField($fieldName, $fieldValue);
Expand Down
11 changes: 6 additions & 5 deletions Classes/Domain/Search/ApacheSolrDocument/Repository.php
Expand Up @@ -31,6 +31,7 @@
use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException;
use ApacheSolrForTypo3\Solr\Search;
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection;
use ApacheSolrForTypo3\Solr\Util;
use TYPO3\CMS\Core\SingletonInterface;
Expand Down Expand Up @@ -80,7 +81,7 @@ public function __construct(DocumentEscapeService $documentEscapeService = null,
* Returns firs found Apache_Solr_Document for current page by given language id.
*
* @param $languageId
* @return \Apache_Solr_Document|false
* @return Document|false
*/
public function findOneByPageIdAndByLanguageId($pageId, $languageId)
{
Expand All @@ -94,7 +95,7 @@ public function findOneByPageIdAndByLanguageId($pageId, $languageId)
*
* @param int $pageId
* @param int $languageId
* @return \Apache_Solr_Document[]
* @return Document[]
*/
public function findByPageIdAndByLanguageId($pageId, $languageId)
{
Expand All @@ -106,15 +107,15 @@ public function findByPageIdAndByLanguageId($pageId, $languageId)
return [];
}
$data = $response->getParsedData();
return $this->documentEscapeService->applyHtmlSpecialCharsOnAllFields($data->response->docs);
return $this->documentEscapeService->applyHtmlSpecialCharsOnAllFields($data->response->docs ?? []);
}

/**
* @param string $type
* @param int $uid
* @param int $pageId
* @param int $languageId
* @return \Apache_Solr_Document[]|array
* @return Document[]|array
*/
public function findByTypeAndPidAndUidAndLanguageId($type, $uid, $pageId, $languageId): array
{
Expand All @@ -126,7 +127,7 @@ public function findByTypeAndPidAndUidAndLanguageId($type, $uid, $pageId, $langu
return [];
}
$data = $response->getParsedData();
return $this->documentEscapeService->applyHtmlSpecialCharsOnAllFields($data->response->docs);
return $this->documentEscapeService->applyHtmlSpecialCharsOnAllFields($data->response->docs ?? []);
}

/**
Expand Down

0 comments on commit 044df49

Please sign in to comment.