Skip to content

Commit

Permalink
[FEATURE] Exclude sub entries of page/storage recursively
Browse files Browse the repository at this point in the history
* adds `no_search_sub_entries` field  to page and storage folder
* updates the sub pages of page/storage marked as `no_search_sub_entries`

Resolves: #2432
  • Loading branch information
dkd-kaehm committed Dec 7, 2020
1 parent 54e7b8d commit 542e927
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 11 deletions.
1 change: 1 addition & 0 deletions Classes/Access/Rootline.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public static function getAccessRootlineByPageId(
$pageId,
$mountPointParameter = ''
) {
/* @var Rootline $accessRootline */
$accessRootline = GeneralUtility::makeInstance(Rootline::class);
$rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $pageId, $mountPointParameter);
try {
Expand Down
23 changes: 23 additions & 0 deletions Classes/Domain/Site/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,29 @@ public function getPages($rootPageId = 'SITE_ROOT', $maxDepth = 999)
return array_merge($pageIds, $this->pagesRepository->findAllSubPageIdsByRootPage($rootPageId, $maxDepth, $initialPagesAdditionalWhereClause));
}

/**
* @param string $rootPageId
* @param int $maxDepth
* @return array
*/
public function getPagesWithinNoSearchSubEntriesPages($rootPageId = 'SITE_ROOT', $maxDepth = 999): array
{
if ($rootPageId === 'SITE_ROOT') {
$rootPageId = (int)$this->rootPage['uid'];
}

$configurationAwareRecordService = GeneralUtility::makeInstance(ConfigurationAwareRecordService::class);
// Fetch configuration in order to be able to read initialPagesAdditionalWhereClause
$solrConfiguration = $this->getSolrConfiguration();
$indexQueueConfigurationName = $configurationAwareRecordService->getIndexingConfigurationName('pages', $this->rootPage['uid'], $solrConfiguration);
$initialPagesAdditionalWhereClause = $solrConfiguration->getInitialPagesAdditionalWhereClause($indexQueueConfigurationName);

return $this->pagesRepository->findAllPagesWithinNoSearchSubEntriesMarkedPagesByRootPage(
$rootPageId,
$maxDepth,
$initialPagesAdditionalWhereClause
);
}

/**
* Generates the site's unique Site Hash.
Expand Down
18 changes: 11 additions & 7 deletions Classes/GarbageCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function processCmdmap_preProcess($command, $table, $uid, $value, DataHan
}

/**
* Holds the configuration when a recursive page queing should be triggered.
* Holds the configuration when a recursive page deletion should be triggered.
*
* Note: The SQL transaction is already committed, so the current state covers only "non"-changed fields.
*
Expand All @@ -109,7 +109,11 @@ protected function getUpdateSubPagesRecursiveTriggerConfiguration()
'hiddenIsEnabledAndExtendToSubPagesWasAdded' => [
'currentState' => ['hidden' => '1'],
'changeSet' => ['extendToSubpages' => '1']
]
],
// the field "no_search_sub_entries" of current page was set to 1
'no_search_sub_entriesFlagWasAdded' => [
'changeSet' => ['no_search_sub_entries' => '1']
],
];
}

Expand All @@ -132,7 +136,7 @@ public function collectGarbage($table, $uid)
* @param int $uid
* @param array $changedFields
*/
protected function deleteSubpagesWhenExtendToSubpagesIsSet($table, $uid, $changedFields)
protected function deleteSubEntriesWhenRecursiveTriggerIsRecognized($table, $uid, $changedFields)
{
if (!$this->isRecursivePageUpdateRequired($uid, $changedFields)) {
return;
Expand Down Expand Up @@ -242,17 +246,17 @@ public function processDatamap_afterDatabaseOperations($status, $table, $uid, ar
return;
}

if ($table === 'pages') {
$this->deleteSubEntriesWhenRecursiveTriggerIsRecognized($table, $uid, $fields);
}

$record = $this->tcaService->normalizeFrontendGroupField($table, $record);
$isGarbage = $this->getIsGarbageRecord($table, $record);
if (!$isGarbage) {
return;
}

$this->collectGarbage($table, $uid);

if ($table === 'pages') {
$this->deleteSubpagesWhenExtendToSubpagesIsSet($table, $uid, $fields);
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions Classes/IndexQueue/Initializer/AbstractInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ protected function getPages()
$pages = array_merge($pages, $additionalPageIds);
sort($pages, SORT_NUMERIC);

$pagesWithinNoSearchSubEntriesPages = $this->site->getPagesWithinNoSearchSubEntriesPages();
// @todo: log properly if $additionalPageIds are within $pagesWithinNoSearchSubEntriesPages
$pages = array_values(array_diff($pages, $pagesWithinNoSearchSubEntriesPages));
return $pages;
}

Expand Down
15 changes: 12 additions & 3 deletions Classes/IndexQueue/RecordMonitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function setLogger(SolrLogManager $logger)
}

/**
* Holds the configuration when a recursive page queing should be triggered.
* Holds the configuration when a recursive page queuing should be triggered.
*
* Note: The SQL transaction is already committed, so the current state covers only "non"-changed fields.
*
Expand All @@ -142,7 +142,11 @@ protected function getUpdateSubPagesRecursiveTriggerConfiguration()
'hiddenIsEnabledAndExtendToSubPagesWasRemoved' => [
'currentState' => ['hidden' => '1'],
'changeSet' => ['extendToSubpages' => '0']
]
],
// the field "no_search_sub_entries" of current page was set to 0
'no_search_sub_entriesFlagWasAdded' => [
'changeSet' => ['no_search_sub_entries' => '0']
],
];
}

Expand Down Expand Up @@ -244,7 +248,7 @@ protected function applyPageChangesToQueue($uid)

/**
* Add's a record to the queue if it is monitored and enabled, otherwise it removes the record from the queue.
*
*
* @param string $table
* @param integer $uid
* @param integer $pid
Expand Down Expand Up @@ -366,6 +370,11 @@ protected function processRecord($recordTable, $recordPageId, $recordUid, $field
// TODO move this part to the garbage collector
// check if the item should be removed from the index because it no longer matches the conditions
$this->removeFromIndexAndQueueWhenItemInQueue($recordTable, $recordUid);
// Handle sub entries for pages, which are not in index queue.
if ($recordTable === 'pages' && $this->isRecursivePageUpdateRequired($recordUid, $fields)) {
$treePageIds = $this->getSubPageIds($recordUid);
$this->updatePageIdItems($treePageIds);
}
return;
}

Expand Down
37 changes: 37 additions & 0 deletions Classes/System/Records/Pages/PagesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use ApacheSolrForTypo3\Solr\System\Records\AbstractRepository;
use ApacheSolrForTypo3\Solr\Util;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -213,6 +214,42 @@ protected function getPageIdsFromCurrentDepthAndCallRecursive(int $maxDepth, int

return $pageIds;
}

/**
* @param int $rootPageId
* @param int $maxDepth
* @param string $initialPagesAdditionalWhereClause
* @return array
*/
public function findAllPagesWithinNoSearchSubEntriesMarkedPagesByRootPage(
int $rootPageId,
int $maxDepth = 999,
string $initialPagesAdditionalWhereClause = ''
): array
{
$wholePagetree = $this->findAllSubPageIdsByRootPage($rootPageId, $maxDepth, $initialPagesAdditionalWhereClause);

$queryBuilder = $this->getQueryBuilder();
$queryBuilder->getRestrictions()->removeAll();
$noSearchSubEntriesEnabledPages = $queryBuilder
->select('uid')
->from($this->table)
->where(
$queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter($wholePagetree, Connection::PARAM_INT_ARRAY)),
$queryBuilder->expr()->eq('no_search_sub_entries', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT))
)->execute()->fetchAll();

if (empty($noSearchSubEntriesEnabledPages)) {
return [];
}

$pageIds = [];
foreach ($noSearchSubEntriesEnabledPages as $page) {
$pageIds = array_merge($pageIds, $this->findAllSubPageIdsByRootPage($page['uid'], $maxDepth - 1));
}

return $pageIds;
}

/**
* Finds translation overlays by given page Id.
Expand Down
49 changes: 49 additions & 0 deletions Configuration/TCA/Overrides/pages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
defined('TYPO3_MODE') or die();

/**
* No Search for sub entries of page tree.
*/
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'pages',
[
'no_search_sub_entries' => [
'exclude' => true,
'label' => 'LLL:EXT:solr/Resources/Private/Language/locallang_tca.xlf:pages.no_search_sub_entries',
'config' => [
'type' => 'check',
'renderType' => 'checkboxToggle',
'items' => [
[
0 => '',
1 => '',
'invertStateDisplay' => true
]
],
'behaviour' => [
'allowLanguageSynchronization' => true
]
]
],
]
);

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette(
'pages',
'miscellaneous',
'no_search_sub_entries',
'after:no_search'
);

// Enable no_search_sub_entries for storage folders.
$GLOBALS['TCA']['pages']['palettes']['slimmed_miscellaneous'] = [
'label' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.palettes.miscellaneous',
'showitem' => 'no_search_sub_entries;LLL:EXT:solr/Resources/Private/Language/locallang_tca.xlf:pages.no_search_sub_entries',
];

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'pages',
'--palette--;;slimmed_miscellaneous',
(string)\TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SYSFOLDER,
'after:module'
);
12 changes: 12 additions & 0 deletions Resources/Private/Language/de.locallang_csh_pages.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.0" xmlns:t3="http://typo3.org/schemas/xliff">
<file t3:id="1415814793" source-language="en" datatype="plaintext" original="EXT:core/Resources/Private/Language/locallang_csh_pages.xlf" date="2020-12-1T15:22:32Z" product-name="context_help">
<header/>
<body>
<trans-unit id="no_search_sub_entries.description" resname="no_search_sub_entries.description">
<source>If enabled, this option includes the sub entries of this page in Solr index. (NOTE: Value=0 means enabled in this view.)</source>
<target>Falls aktiviert, werden die Untereinträge dieser Seite bei einer Suche berücksichtigt. (Bitte beachte, dass der Wert=0 wegen Negation in dieser Ansicht "aktiviert" bedeutet.)</target>
</trans-unit>
</body>
</file>
</xliff>
14 changes: 14 additions & 0 deletions Resources/Private/Language/de.locallang_tca.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" datatype="plaintext" original="messages" date="2020-12-01T11:42:09Z">
<header>
<generator>LFEditor</generator>
</header>
<body>
<trans-unit id="pages.no_search_sub_entries" xml:space="preserve">
<source>Include sub entries in Search</source>
<target>Untereinträge in Indexsuche einbeziehen</target>
</trans-unit>
</body>
</file>
</xliff>
11 changes: 11 additions & 0 deletions Resources/Private/Language/locallang_csh_pages.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.0" xmlns:t3="http://typo3.org/schemas/xliff">
<file t3:id="1415814793" source-language="en" datatype="plaintext" original="EXT:core/Resources/Private/Language/locallang_csh_pages.xlf" date="2020-12-1T15:22:32Z" product-name="context_help">
<header/>
<body>
<trans-unit id="no_search_sub_entries.description" resname="no_search_sub_entries.description">
<source>If enabled, this option includes the sub entries of this page in Solr index. (NOTE: Value=0 means enabled in this view.)</source>
</trans-unit>
</body>
</file>
</xliff>
15 changes: 15 additions & 0 deletions Resources/Private/Language/locallang_tca.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" datatype="plaintext" original="messages" date="2020-12-01T11:42:09Z">
<header>
<generator>LFEditor</generator>
</header>
<body>

<trans-unit id="pages.no_search_sub_entries" xml:space="preserve">
<source>Include sub entries in Search</source>
</trans-unit>

</body>
</file>
</xliff>
8 changes: 7 additions & 1 deletion ext_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@
// register Initialize Solr Connection Button in page tree context menu
$GLOBALS['TYPO3_CONF_VARS']['BE']['ContextMenu']['ItemProviders'][1487876780] = \ApacheSolrForTypo3\Solr\ContextMenu\ItemProviders\InitializeConnectionProvider::class;
}

// Register Context Sensitive Help (CSH) translation labels
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr(
'pages',
'EXT:solr/Resources/Private/Language/locallang_csh_pages.xlf'
);
}

if ((TYPO3_MODE === 'BE') || (TYPO3_MODE === 'FE' && isset($_POST['TSFE_EDIT']))) {
Expand All @@ -153,4 +159,4 @@
// we load the autoloader for our libraries
$dir = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('solr');
require $dir . '/Resources/Private/Php/ComposerLibraries/vendor/autoload.php';
}
}
1 change: 1 addition & 0 deletions ext_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ CREATE TABLE sys_registry (
# Extending 'pages' table with extra keys
#
CREATE TABLE pages (
no_search_sub_entries tinyint(3) unsigned DEFAULT '0' NOT NULL,
KEY content_from_pid_deleted (content_from_pid,deleted),
KEY doktype_no_search_deleted (doktype,no_search,deleted)
);

0 comments on commit 542e927

Please sign in to comment.