Skip to content

Commit

Permalink
[BUGFIX] Undefined array key "sortByAdmin", fixes #252
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbltr committed Oct 25, 2024
1 parent 0c29f07 commit 13027bb
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 21 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
ChangeLog

Upcoming version
[BUGFIX] Undefined array key "sortByAdmin". Thanks to Simon Praetorius. https://github.com/tpwd/ke_search/issues/252

Version 5.5.2, 23 August 2024
[BUGFIX] Fix cropping if "resultChars" is empty. Thanks to Andreas Kießling. https://github.com/tpwd/ke_search/issues/242
[BUGFIX] Fix regression in page indexer if translated page is not available. Thanks to Jens Vollmer. https://github.com/tpwd/ke_search/issues/243
Expand Down
19 changes: 10 additions & 9 deletions Classes/Lib/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,26 +526,27 @@ public function createQueryForDateRange()
*/
public function getOrdering()
{
// if the following code fails, fall back to this default ordering
$orderBy = $this->conf['sortWithoutSearchword'] ?? 'sortdate desc';
// If the following code fails, fall back to this default ordering
$orderBy = $this->conf['sortWithoutSearchword'];

// if sorting in FE is allowed
// If sorting in FE is allowed
if ($this->conf['showSortInFrontend'] ?? false) {
$piVarsField = $this->pObj->piVars['sortByField'] ?? '';
$piVarsDir = $this->pObj->piVars['sortByDir'] ?? '';
$piVarsDir = ($piVarsDir == '') ? 'asc' : $piVarsDir;
if (!empty($piVarsField)) { // if an ordering field is defined by GET/POST

// Check if an ordering field is defined by GET/POST and use that.
// If sortByVisitor is not set OR not in the list of
// allowed fields then use fallback ordering in "sortWithoutSearchword"
if (!empty($piVarsField)) {
$isInList = GeneralUtility::inList($this->conf['sortByVisitor'], $piVarsField);
if ($this->conf['sortByVisitor'] != '' && $isInList) {
$orderBy = $piVarsField . ' ' . $piVarsDir;
}
// if sortByVisitor is not set OR not in the list of
// allowed fields then use fallback ordering in "sortWithoutSearchword"
}
} else {
// if sortByVisitor is not set OR not in the list of
// allowed fields then use fallback ordering in "sortWithoutSearchword"
if (!empty($this->pObj->wordsAgainst)) { // if sorting is predefined by admin
// If sorting is predefined by admin
if (!empty($this->pObj->wordsAgainst)) {
$orderBy = $this->conf['sortByAdmin'];
}
}
Expand Down
8 changes: 7 additions & 1 deletion Classes/Lib/PluginBaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ public function getStartingPoint(): string
// plugin.tx_kesearch_pi1.overrideStartingPointRecursive = 1
if ($this->pObj->conf['overrideStartingPoint'] ?? false) {
$startingpoint['pages'] = $this->pObj->conf['overrideStartingPoint'];
$startingpoint['recursive'] = $this->pObj->conf['overrideStartingPointRecursive'];
$startingpoint['recursive'] = $this->pObj->conf['overrideStartingPointRecursive'] ?? 0;
}

if (empty($startingpoint['pages'])) {
throw new \Exception('No starting point found. Please set the starting point in the plugin'
. ' configuration or via TypoScript: '
. 'https://docs.typo3.org/p/tpwd/ke_search/main/en-us/Configuration/OverrideRecordStoragePage.html.');
}

return $this->pObj->pi_getPidList($startingpoint['pages'], $startingpoint['recursive']);
Expand Down
22 changes: 17 additions & 5 deletions Classes/Plugins/PluginBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ public function init(ServerRequestInterface $request)

// make settings from FlexForm available in general configuration ($this->conf)
$this->moveFlexFormDataToConf($flexFormConfiguration);
$this->setConfigurationDefaults();

// explode flattened piVars to multi-dimensional array and clean them
$additionalAllowedPiVars = $this->conf['additionalAllowedPiVars'] ?? '';
// explode flattened piVars to multidimensional array and clean them
$additionalAllowedPiVars = $this->conf['additionalAllowedPiVars'];
$this->piVars = SearchHelper::explodePiVars($this->piVars, $additionalAllowedPiVars);
$this->piVars = $this->div->cleanPiVars($this->piVars, $additionalAllowedPiVars);

Expand Down Expand Up @@ -284,16 +285,16 @@ public function init(ServerRequestInterface $request)
$this->piVars['sortByDir'] = 'desc';
}

// after the searchword is removed, sorting for "score" is not possible
// After the searchword is removed, sorting for "score" is not possible
// anymore. So remove this sorting here and put it back to default.
if (!$this->sword && ($this->piVars['sortByField'] ?? '') == 'score') {
unset($this->piVars['sortByField']);
unset($this->piVars['sortByDir']);
}

// perform search at this point already if we need to calculate what
// Perform search at this point already if we need to calculate what
// filters to display.
if (isset($this->conf['checkFilterCondition']) && $this->conf['checkFilterCondition'] != 'none' && !$this->allowEmptySearch()) {
if ($this->conf['checkFilterCondition'] != 'none' && !$this->allowEmptySearch()) {
$this->db->getSearchResults();
}

Expand All @@ -309,6 +310,17 @@ public function init(ServerRequestInterface $request)
}
}

protected function setConfigurationDefaults(): void
{
$this->conf['resultsPerPage'] = $this->conf['resultsPerPage'] ?? 10;
$this->conf['resultLinkTargetFiles'] = $this->conf['resultLinkTargetFiles'] ?? '_blank';
$this->conf['resultLinkTarget'] = $this->conf['resultLinkTarget'] ?? '';
$this->conf['additionalAllowedPiVars'] = $this->conf['additionalAllowedPiVars'] ?? '';
$this->conf['sortByAdmin'] = $this->conf['sortByAdmin'] ?? 'score desc';
$this->conf['sortWithoutSearchword'] = $this->conf['sortWithoutSearchword'] ?? 'sortdate desc';
$this->conf['checkFilterCondition'] = $this->conf['checkFilterCondition'] ?? 'multi';
}

/**
* Move all FlexForm data of current record to conf array ($this->conf)
*
Expand Down
15 changes: 9 additions & 6 deletions Documentation/Configuration/OverrideRecordStoragePage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

.. _configuration-override-record-storage-page:

============================
Override record storage page
============================
============================================
Override record storage page (Startingpoint)
============================================

It is possible to override the record storage page defined in the plugin using TypoScript. This is useful
if you want to serve different search results depending on TypoScript conditions.
It is possible to override the record storage page (or "Startingpoint") defined
in the plugin using TypoScript. This is useful if you want to serve different
search results depending on TypoScript conditions or if you include the plugin
via TypoScript.

For example you could serve different search results to logged in users.
For example you could serve different search results to logged in users by
setting the override record storage page to a different page id.

Setup TypoScript:

Expand Down

0 comments on commit 13027bb

Please sign in to comment.