From 2f639ab344fe02d37c35c3386df47f5ad9a07ad4 Mon Sep 17 00:00:00 2001 From: Stefan Galinski <stefan@sgalinski.de> Date: Fri, 19 Oct 2018 21:14:53 +0200 Subject: [PATCH] [BUGFIX] Fix the complete broken code --- Classes/SignalSlot/SitemapSignalSlot.php | 80 +++++++----------------- 1 file changed, 24 insertions(+), 56 deletions(-) diff --git a/Classes/SignalSlot/SitemapSignalSlot.php b/Classes/SignalSlot/SitemapSignalSlot.php index ebdcaf95..a6ce4eb1 100644 --- a/Classes/SignalSlot/SitemapSignalSlot.php +++ b/Classes/SignalSlot/SitemapSignalSlot.php @@ -26,21 +26,17 @@ namespace SGalinski\SgJobs\SignalSlot; * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ -use TYPO3\CMS\Core\Database\DatabaseConnection; +use TYPO3\CMS\Core\Database\ConnectionPool; 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 */ class SitemapSignalSlot { - const PLUGIN_NAME = 'sgjobs_jobapplication'; /** @@ -49,7 +45,7 @@ class SitemapSignalSlot { protected $uriBuilder; /** - * before the sitemap is generated + * Before the sitemap is generated * * @param array $pageList * @throws \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException @@ -60,28 +56,27 @@ class SitemapSignalSlot { $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']; - // find sites where job detail plugin is added - $rows = $databaseConnection->exec_SELECTgetRows( - 'pid, pages', - 'tt_content', - 'CType = "list" and list_type = "' . self::PLUGIN_NAME . '" and hidden = 0 and deleted = 0' - ); + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); + $databaseResource = $queryBuilder->select('pid', 'pages') + ->from('tt_content') + ->where( + $queryBuilder->expr()->andX( + $queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('list')), + $queryBuilder->expr()->eq('list_type', $queryBuilder->createNamedParameter(self::PLUGIN_NAME)) + ) + ) + ->execute(); + + $rows = $databaseResource->fetchAll(); foreach ($rows as $row) { $jobs = $this->getJobsByPid($row['pages']); @@ -100,45 +95,18 @@ class SitemapSignalSlot { } /** - * Initializes TSFE and sets $GLOBALS['TSFE'] + * Get all jobs stored on specific page ids * - * @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 - * - * @param string $pid + * @param string $pageList * @return array|null */ - private function getJobsByPid($pid) { - /** @var $databaseConnection DatabaseConnection */ - $databaseConnection = $GLOBALS['TYPO3_DB']; - $rows = $databaseConnection->exec_SELECTgetRows( - '*', - 'tx_sgjobs_domain_model_job', - 'pid IN (' . $pid . ')' - ); - - return $rows; + private function getJobsByPid($pageList) { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); + $databaseResource = $queryBuilder->select('*') + ->from('tx_sgjobs_domain_model_job') + ->where($queryBuilder->expr()->in('pid', $queryBuilder->createNamedParameter($pageList))) + ->execute(); + + return $databaseResource->fetchAll(); } } -- GitLab