diff --git a/Classes/SignalSlot/SitemapSignalSlot.php b/Classes/SignalSlot/SitemapSignalSlot.php index 5e3fffb1bed4aecc85216c1f2b3c707f4d9628f7..ebdcaf9562604a01c2011a44c052ebf29ac4c156 100644 --- a/Classes/SignalSlot/SitemapSignalSlot.php +++ b/Classes/SignalSlot/SitemapSignalSlot.php @@ -28,8 +28,13 @@ namespace SGalinski\SgJobs\SignalSlot; use TYPO3\CMS\Core\Database\DatabaseConnection; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Configuration\ConfigurationManager; use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; use TYPO3\CMS\Extbase\Object\ObjectManager; +use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; +use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; +use TYPO3\CMS\Frontend\Page\PageGenerator; +use TYPO3\CMS\Frontend\Utility\EidUtility; /** * Signal functions regarding sg_seo sitemap generation @@ -47,8 +52,27 @@ class SitemapSignalSlot { * before the sitemap is generated * * @param array $pageList + * @throws \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException */ public function beforeSitemapGeneration(array &$pageList) { + $objectManager = GeneralUtility::makeInstance(ObjectManager::class); + $request = $objectManager->get(\TYPO3\CMS\Extbase\Mvc\Web\Request::class); + $request->setRequestUri(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')); + $request->setBaseUri(GeneralUtility::getIndpEnv('TYPO3_SITE_URL')); + + /** @var ObjectManager $objectManager */ + $objectManager = GeneralUtility::makeInstance(ObjectManager::class); + /** @var ContentObjectRenderer $contentObjectRenderer */ + $contentObjectRenderer = $objectManager->get(ContentObjectRenderer::class); + + /** @var ConfigurationManager $configurationManager */ + $configurationManager = $objectManager->get(ConfigurationManager::class); + $configurationManager->setContentObject($contentObjectRenderer); + $this->uriBuilder = $objectManager->get(UriBuilder::class); + $this->uriBuilder->injectConfigurationManager($configurationManager); + + $this->initTSFE(); + /** @var $databaseConnection DatabaseConnection */ $databaseConnection = $GLOBALS['TYPO3_DB']; @@ -62,16 +86,10 @@ class SitemapSignalSlot { foreach ($rows as $row) { $jobs = $this->getJobsByPid($row['pages']); - $objectManager = GeneralUtility::makeInstance(ObjectManager::class); - $request = $objectManager->get(\TYPO3\CMS\Extbase\Mvc\Web\Request::class); - $request->setRequestUri(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')); - $request->setBaseUri(GeneralUtility::getIndpEnv('TYPO3_SITE_URL')); - $this->uriBuilder = $objectManager->get(UriBuilder::class); - foreach ($jobs as $job) { $url = $this->uriBuilder->reset()->setTargetPageUid($row['pid'])->setArguments( ['tx_sgjobs_jobapplication' => ['jobId' => $job['uid']]] - )->buildFrontendUri(); + )->setCreateAbsoluteUri(TRUE)->buildFrontendUri(); $pageList[] = [ 'url' => $url, @@ -81,6 +99,31 @@ class SitemapSignalSlot { } } + /** + * Initializes TSFE and sets $GLOBALS['TSFE'] + * + * @return void + * @throws \RuntimeException + * @throws \InvalidArgumentException + * @throws \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException + */ + private function initTSFE() { + $GLOBALS['TSFE'] = $tsfe = GeneralUtility::makeInstance( + TypoScriptFrontendController::class, $GLOBALS['TYPO3_CONF_VARS'], GeneralUtility::_GP('id'), '' + ); + /** @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $tsfe */ + $tsfe->connectToDB(); + $tsfe->initFEuser(); + EidUtility::initTCA(); + $tsfe->determineId(); + $tsfe->initTemplate(); + $tsfe->getConfigArray(); + $tsfe->settingLanguage(); + + // Get linkVars, absRefPrefix, etc + PageGenerator::pagegenInit(); + } + /** * get all jobs stored on specific page ids *