Commit 37b7a893 authored by Richard Haeser's avatar Richard Haeser Committed by Benni Mack

[BUGFIX] Add workspace restriction to RecordsXmlSitemapDataProvider

By adding the workspace restriction to the RecordsXmlSitemapDataProvider,
only records in the live workspace are shown in the XML sitemap.

Resolves: #93010
Releases: master, 10.4
Change-Id: Ib46c3ebc925405de81afefda83100ccddb761fad
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/67392Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 0fabdc18
......@@ -19,8 +19,10 @@ namespace TYPO3\CMS\Seo\XmlSitemap;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\WorkspaceAspect;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Seo\XmlSitemap\Exception\MissingConfigurationException;
......@@ -100,6 +102,10 @@ class RecordsXmlSitemapDataProvider extends AbstractXmlSitemapDataProvider
$constraints[] = QueryHelper::stripLogicalOperatorPrefix($this->config['additionalWhere']);
}
$queryBuilder->getRestrictions()->add(
GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getCurrentWorkspaceAspect()->getId())
);
$queryBuilder->select('*')
->from($table);
......@@ -200,4 +206,12 @@ class RecordsXmlSitemapDataProvider extends AbstractXmlSitemapDataProvider
$context = GeneralUtility::makeInstance(Context::class);
return (int)$context->getPropertyFromAspect('language', 'id');
}
/**
* @return WorkspaceAspect
*/
protected function getCurrentWorkspaceAspect(): WorkspaceAspect
{
return GeneralUtility::makeInstance(Context::class)->getAspect('workspace');
}
}
......@@ -49,6 +49,21 @@ plugin.tx_seo {
}
}
}
records_without_workspace_settings {
provider = TYPO3\CMS\Seo\XmlSitemap\RecordsXmlSitemapDataProvider
config {
table = sys_news
sortField = uid
lastModifiedField = tstamp
pid = 11
url {
pageId = 1
fieldToParameterMap {
uid = tx_example_news[id]
}
}
}
}
}
}
}
......
......@@ -39,4 +39,19 @@
<title>Alternative language</title>
<sys_language_uid>1</sys_language_uid>
</sys_category>
<sys_category>
<uid>4</uid>
<pid>11</pid>
<tstamp>1610245386</tstamp>
<crdate>1610245386</crdate>
<deleted>0</deleted>
<hidden>0</hidden>
<starttime>0</starttime>
<endtime>0</endtime>
<sorting>64</sorting>
<t3ver_wsid>1</t3ver_wsid>
<t3ver_state>1</t3ver_state>
<title>Category in workspace</title>
<sys_language_uid>0</sys_language_uid>
</sys_category>
</data>
<?xml version="1.0" encoding="UTF-8"?>
<data>
<sys_news>
<uid>1</uid>
<pid>11</pid>
<tstamp>1610246150</tstamp>
<crdate>1610246150</crdate>
<deleted>0</deleted>
<hidden>0</hidden>
<starttime>0</starttime>
<endtime>0</endtime>
<title>News item 1</title>
</sys_news>
<sys_news>
<uid>2</uid>
<pid>11</pid>
<tstamp>1610246150</tstamp>
<crdate>1610246150</crdate>
<deleted>0</deleted>
<hidden>0</hidden>
<starttime>0</starttime>
<endtime>0</endtime>
<title>News item 2</title>
</sys_news>
</data>
......@@ -40,6 +40,7 @@ class XmlSitemapRecordsTest extends AbstractTestCase
$this->importDataSet('EXT:seo/Tests/Functional/Fixtures/pages-sitemap.xml');
$this->importDataSet('EXT:seo/Tests/Functional/Fixtures/sys_category.xml');
$this->importDataSet('EXT:seo/Tests/Functional/Fixtures/tt_content.xml');
$this->importDataSet('EXT:seo/Tests/Functional/Fixtures/sys_news.xml');
$this->setUpFrontendRootPage(
1,
[
......@@ -69,13 +70,13 @@ class XmlSitemapRecordsTest extends AbstractTestCase
* @var array $expectedEntries
* @var array $notExpectedEntries
*/
public function checkIfSiteMapIndexContainsSysCategoryLinks(string $host, array $expectedEntries, array $notExpectedEntries): void
public function checkIfSiteMapIndexContainsSysCategoryLinks(string $sitemap, string $host, array $expectedEntries, array $notExpectedEntries): void
{
$response = $this->executeFrontendSubRequest(
(new InternalRequest($host))->withQueryParameters(
[
'type' => 1533906435,
'sitemap' => 'records',
'sitemap' => $sitemap,
]
)
);
......@@ -108,6 +109,7 @@ class XmlSitemapRecordsTest extends AbstractTestCase
{
return [
'default-language' => [
'records',
'http://localhost/',
[
'http://localhost/?tx_example_category%5Bid%5D=1&amp;',
......@@ -120,6 +122,7 @@ class XmlSitemapRecordsTest extends AbstractTestCase
]
],
'french-language' => [
'records',
'http://localhost/fr',
[
'http://localhost/fr/?tx_example_category%5Bid%5D=3&amp;',
......@@ -132,6 +135,26 @@ class XmlSitemapRecordsTest extends AbstractTestCase
'http://localhost/?tx_example_category%5Bid%5D=2&amp;',
]
],
'only-records-in-live-workspace-should-be-shown-when-not-in-workspace-mode' => [
'records',
'http://localhost/',
[
'http://localhost/?tx_example_category%5Bid%5D=1&amp;',
'http://localhost/?tx_example_category%5Bid%5D=2&amp;',
],
[
'http://localhost/?tx_example_category%5Bid%5D=4&amp;',
]
],
'non-workspace-tables-should-work-fine' => [
'records_without_workspace_settings',
'http://localhost/',
[
'http://localhost/?tx_example_news%5Bid%5D=1&amp;',
'http://localhost/?tx_example_news%5Bid%5D=2&amp;',
],
[]
],
];
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment