Skip to content

Commit

Permalink
handle more deprecations and improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
cradeck committed Feb 1, 2024
1 parent 49b6eb3 commit fef747a
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 55 deletions.
42 changes: 26 additions & 16 deletions Classes/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
*
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use Psr\Log\LoggerInterface;
use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException;
use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Core\Utility\HttpUtility;
use Subugoe\Find\Service\ServiceProviderInterface;
use Subugoe\Find\Utility\ArrayUtility;
use Subugoe\Find\Utility\FrontendUtility;
Expand All @@ -43,18 +48,18 @@ class SearchController extends ActionController

protected ?object $searchProvider = null;

private \Psr\Log\LoggerInterface $logger;
private LoggerInterface $logger;

public function __construct(LogManagerInterface $logManager)
{
$this->logger = $logManager->getLogger('find');
}

/**
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws NoSuchArgumentException
* @throws StopActionException
*/
public function detailAction(string $id)
public function detailAction(string $id): ResponseInterface
{
$arguments = $this->searchProvider->getRequestArguments();
$detail = $this->searchProvider->getDocumentById($id);
Expand All @@ -76,12 +81,13 @@ public function detailAction(string $id)
'arguments' => $arguments,
'config' => $this->searchProvider->getConfiguration()
]);
return $this->htmlResponse();
}

/**
* Citation Action.
*/
public function citationAction() {
public function citationAction(): ResponseInterface {

$arguments = $this->requestArguments;
$detail = $this->searchProvider->getDocumentById($arguments["id"]);
Expand All @@ -94,23 +100,24 @@ public function citationAction() {
'config' => $this->searchProvider->getConfiguration(),
'type' => $arguments['type']
]);
return $this->htmlResponse();
}

/**
* Index Action.
*/
public function indexAction()
public function indexAction(): ResponseInterface
{
if (array_key_exists('id', $this->requestArguments)) {
$this->forward('detail');
return new ForwardResponse('detail');
} elseif (array_key_exists('rsn', $this->requestArguments)) {
$this->forward('redirect');
return new ForwardResponse('redirect');
} elseif (array_key_exists('bc', $this->requestArguments)) {
$this->forward('redirect');
return new ForwardResponse('redirect');
} elseif (array_key_exists('ppn', $this->requestArguments)) {
$this->forward('redirect');
return new ForwardResponse('redirect');
} elseif (array_key_exists('oclc', $this->requestArguments)) {
$this->forward('redirect');
return new ForwardResponse('redirect');
} else {
$this->searchProvider->setCounter();
FrontendUtility::addQueryInformationAsJavaScript(
Expand All @@ -134,10 +141,11 @@ public function indexAction()
// if there are no search parameters provided, redirect to the URL given in setting 'nosearchRedirect'
if ($defaultQuery['noSearch']) {
if(strlen($this->settings['nosearchRedirect']) > 0) {
\TYPO3\CMS\Core\Utility\HttpUtility::redirect($this->settings['nosearchRedirect']);
HttpUtility::redirect($this->settings['nosearchRedirect']);
}
}
}
return $this->htmlResponse();
}

/**
Expand Down Expand Up @@ -186,7 +194,7 @@ public function redirectAction() {
}

$uri = $this->uriBuilder->reset()->setTargetPageUid(intval($GLOBALS['TSFE']->id))->setCreateAbsoluteUri(true)->setArguments($arguments)->build();
\TYPO3\CMS\Core\Utility\HttpUtility::redirect($uri);
HttpUtility::redirect($uri);

die();
}
Expand All @@ -211,18 +219,20 @@ protected function initializeAction()
/**
* Suggest/Autocomplete action.
*/
public function suggestAction()
public function suggestAction(): ResponseInterface
{
$results = $this->searchProvider->suggestQuery($this->searchProvider->getRequestArguments());
$this->view->assign('suggestions', $results);
return $this->htmlResponse();
}

/**
* Query indexed terms for given fields.
*/
public function termAction(){
public function termAction(): ResponseInterface{
$results = $this->searchProvider->getTerms($this->searchProvider->getRequestArguments());
$this->view->assign('terms', $results);
return $this->htmlResponse();
}

/**
Expand Down
14 changes: 7 additions & 7 deletions Classes/Service/SolrServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ protected function getTheRecordSpecified($id, $assignments)
$assignments['document'] = $resultSet[0];
} else {
$localisationKey = 'LLL:' . $this->settings['languageRootPath'] . 'locallang:exception.deatilNoresult';
$message = sprintf(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($localisationKey, null), $id);
$message = sprintf(LocalizationUtility::translate($localisationKey, null), $id);
if (!$message) {
$message = sprintf('»detail« action query for id »%s« returned no results.', $id);
}
Expand Down Expand Up @@ -1445,12 +1445,12 @@ protected function setSortOrder(array $arguments): void
}

/**
* Sets up $query’s grouping parameters from URL arguments or the TypoScript default.
*
* @param \Solarium\QueryType\Select\Query\Query $query
* @param array $arguments request arguments
*/
private function addGrouping ($arguments) {
* Sets up $query’s grouping parameters from URL arguments or the TypoScript default.
*
* @param Query $query
* @param array $arguments request arguments
*/
private function addGrouping ($arguments) {
$limit = -1;
$field = null;

Expand Down
6 changes: 4 additions & 2 deletions Classes/ViewHelpers/Find/HighlightFieldViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
use Solarium\QueryType\Select\Result\Result;
use Solarium\QueryType\Select\Result\Document;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

Expand Down Expand Up @@ -59,8 +61,8 @@ class HighlightFieldViewHelper extends AbstractViewHelper
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('results', \Solarium\QueryType\Select\Result\Result::class, 'Query results', true);
$this->registerArgument('document', \Solarium\QueryType\Select\Result\Document::class, 'Result document to work on',
$this->registerArgument('results', Result::class, 'Query results', true);
$this->registerArgument('document', Document::class, 'Result document to work on',
true);
$this->registerArgument('field', 'string', 'name of field in document to highlight', true);
$this->registerArgument('alternateField', 'string',
Expand Down
3 changes: 2 additions & 1 deletion Classes/ViewHelpers/Format/SolrEscapeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
use Solarium\Core\Query\Helper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

Expand Down Expand Up @@ -59,7 +60,7 @@ public static function renderStatic(
$string = $renderChildrenClosure();
}

$solariumHelper = new \Solarium\Core\Query\Helper();
$solariumHelper = new Helper();

return $arguments['phrase'] ? $solariumHelper->escapePhrase($string) : $solariumHelper->escapeTerm($string);
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/ViewHelpers/LinkedData/ContainerViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/

use Subugoe\Find\ViewHelpers\LinkedData\Renderer\AbstractRenderer;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

Expand Down Expand Up @@ -64,7 +64,7 @@ public static function renderStatic(
$items = $renderingContext->getVariableProvider()->get($arguments['name']);
$renderingContext->getVariableProvider()->remove($arguments['name']);

$LDRenderer = Renderer\AbstractRenderer::instantiateSubclassForType($arguments['format']);
$LDRenderer = AbstractRenderer::instantiateSubclassForType($arguments['format']);
$LDRenderer->setPrefixes($arguments['prefixes']);

return $LDRenderer->renderItems($items);
Expand Down
11 changes: 6 additions & 5 deletions Classes/ViewHelpers/Solr/CountFromSolrViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

use TYPO3\CMS\Core\Utility\GeneralUtility;
use Solarium\QueryType\Select\Query\Query;
use Solarium\Client;
use Solarium\QueryType\Select\Result\Result;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
Expand Down Expand Up @@ -72,7 +73,7 @@ public function initializeArguments()

public function render()
{
$findParameter = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('tx_find_find');
$findParameter = GeneralUtility::_GP('tx_find_find');

$activeFacets = $this->arguments['activeFacets'];
$queryConcat = $this->arguments['queryConcat'];
Expand Down Expand Up @@ -114,7 +115,7 @@ public function render()
/**
* Check configuration for shards and when found create Distributed Search.
*
* @param \Solarium\QueryType\Select\Query\Query $query
* @param Query $query
*/
private function createQueryComponents(&$query)
{
Expand All @@ -130,7 +131,7 @@ private function createQueryComponents(&$query)
/**
* Adds filter queries configured in TypoScript to $query.
*
* @param \Solarium\QueryType\Select\Query\Query $query
* @param Query $query
*/
private function addTypoScriptFilters($query)
{
Expand All @@ -148,7 +149,7 @@ private function addTypoScriptFilters($query)
* @param string $id the document id
* @param string $idfield the document id field
*
* @return \Solarium\QueryType\Select\Query\Query
* @return Query
*/
private function createQuery($query)
{
Expand Down
10 changes: 10 additions & 0 deletions Configuration/Icons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use \TYPO3\CMS\Core\Imaging\IconProvider\FontawesomeIconProvider;

return [
'ext-find-ce-wizard' => [
'provider' => FontawesomeIconProvider::class,
'name' => 'search'
],
];
8 changes: 6 additions & 2 deletions Configuration/TCA/Overrides/sys_template.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

defined('TYPO3') or die();

// TypoScript
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
ExtensionManagementUtility::addStaticFile(
'find',
'Configuration/TypoScript',
'Find'
);
);
6 changes: 5 additions & 1 deletion Configuration/TCA/Overrides/tt_content.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
use TYPO3\CMS\Extbase\Utility\ExtensionUtility;

defined('TYPO3') or die();

ExtensionUtility::registerPlugin(
'Find',
'find',
'find'
Expand Down
File renamed without changes
5 changes: 3 additions & 2 deletions Tests/Unit/Controller/SearchControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@
*
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */
use Nimut\TestingFramework\TestCase\UnitTestCase;
use Subugoe\Find\Controller\SearchController;

/**
* Tests for search controller.
*/
class SearchControllerTest extends \Nimut\TestingFramework\TestCase\UnitTestCase
class SearchControllerTest extends UnitTestCase
{
/**
* @var \Subugoe\Find\Controller\SearchController
* @var SearchController
*/
protected $fixture;

Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/ViewHelpers/Data/SplitViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class SplitViewHelperTest extends ViewHelperBaseTestcase
{
/**
* @var \Subugoe\Find\ViewHelpers\Data\SplitViewHelper
* @var SplitViewHelper
*/
public $fixture;

Expand Down
1 change: 0 additions & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
'version' => '3.1.1',
'state' => 'stable',
'category' => 'frontend',
'clearCacheOnLoad' => true,
'author' => 'Sven-S. Porst, Ingo Pfennigstorf',
'author_email' => 'pfennigstorf@sub.uni-goettingen.de',
'author_company' => 'SUB Göttingen',
Expand Down
17 changes: 2 additions & 15 deletions ext_localconf.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
defined('TYPO3_MODE') || exit;
defined('TYPO3') or die();

$autoexec = static function () {
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
Expand All @@ -12,20 +12,7 @@
\Subugoe\Find\Controller\SearchController::class => 'index, detail, suggest, term, citation',
]
);

if (TYPO3_MODE === 'BE') {
/*
* Register icons
*/
/** @var \TYPO3\CMS\Core\Imaging\IconRegistry $iconRegistry */
$iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class);
$iconRegistry->registerIcon(
'ext-find-ce-wizard',
\TYPO3\CMS\Core\Imaging\IconProvider\FontawesomeIconProvider::class,
['name' => 'search']
);
}


\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:find/Configuration/TSconfig/ContentElementWizard.tsconfig">');
};
$autoexec();
Expand Down

0 comments on commit fef747a

Please sign in to comment.