Now it generates a cHash for each Version, so it can use the cache

This commit is contained in:
Sven Wappler 2017-12-24 00:00:55 +01:00
parent c4ff8f2fee
commit 45b675ba92

View file

@ -11,6 +11,7 @@ namespace WapplerSystems\ABTest2;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Frontend\Page\CacheHashCalculator;
use TYPO3\CMS\Frontend\Page\PageRepository; use TYPO3\CMS\Frontend\Page\PageRepository;
/** /**
@ -25,20 +26,20 @@ class Helper
/** /**
* *
* @param array $params * @param array $params
* @param $pObj TypoScriptFrontendController * @param $tsFeController TypoScriptFrontendController
* @return void * @return void
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function determineContentId(array $params, &$pObj) public function determineContentId(array $params, &$tsFeController)
{ {
// only try to change the page if it's not the googlebot. // only try to change the page if it's not the googlebot.
if (false === stripos($_SERVER['HTTP_USER_AGENT'], 'googlebot')) { if (true === stripos($_SERVER['HTTP_USER_AGENT'], 'googlebot')) return;
$currentPageId = $targetPageId = $pObj->id; $currentPageId = $targetPageId = $tsFeController->id;
// Get the rootpage_id from realurl config. // Get the rootpage_id from realurl config.
$realurlConfig = $pObj->TYPO3_CONF_VARS['EXTCONF']['realurl']; $realurlConfig = $tsFeController->TYPO3_CONF_VARS['EXTCONF']['realurl'];
if (array_key_exists($_SERVER['SERVER_NAME'], $realurlConfig)) { if (array_key_exists($_SERVER['SERVER_NAME'], $realurlConfig)) {
$rootpage_id = $realurlConfig[$_SERVER['SERVER_NAME']]['pagePath']['rootpage_id']; $rootpage_id = $realurlConfig[$_SERVER['SERVER_NAME']]['pagePath']['rootpage_id'];
} else { } else {
@ -91,28 +92,51 @@ class Helper
// If current page ID is different from the random page ID we set the correct page ID. // If current page ID is different from the random page ID we set the correct page ID.
if ($currentPageId !== $targetPageId) { if ($currentPageId !== $targetPageId) {
$pObj->contentPid = $targetPageId; $tsFeController->contentPid = $targetPageId;
$pObj->page['content_from_pid'] = $targetPageId; $tsFeController->page['content_from_pid'] = $targetPageId;
} }
$pObj->page['no_cache'] = true; //$pObj->page['no_cache'] = true;
$_GET['abtest'] = $cookieValue;
$this->makeCacheHash($tsFeController);
if ($currentPagePropertiesArray) { if ($currentPagePropertiesArray) {
$additionalHeaderData = $currentPagePropertiesArray['tx_abtest2_header']; $additionalHeaderData = $currentPagePropertiesArray['tx_abtest2_header'];
$additionalFooterData = $currentPagePropertiesArray['tx_abtest2_footer']; $additionalFooterData = $currentPagePropertiesArray['tx_abtest2_footer'];
if ($additionalHeaderData) { if ($additionalHeaderData) {
$pObj->additionalHeaderData['abtest2'] = $additionalHeaderData; $tsFeController->additionalHeaderData['abtest2'] = $additionalHeaderData;
} }
if ($additionalFooterData) { if ($additionalFooterData) {
$pObj->additionalFooterData['abtest2'] = $additionalFooterData; $tsFeController->additionalFooterData['abtest2'] = $additionalFooterData;
} }
} }
} }
} }
/**
*
* @param $tsFeController TypoScriptFrontendController
* @return void
* @throws \InvalidArgumentException
*/
private function makeCacheHash(&$tsFeController)
{
$GET = GeneralUtility::_GET();
/** @var CacheHashCalculator $cacheHash */
$cacheHash = GeneralUtility::makeInstance(CacheHashCalculator::class);
$tsFeController->cHash_array = $cacheHash->getRelevantParameters(GeneralUtility::implodeArrayForUrl('', $GET));
$tsFeController->cHash = $cacheHash->calculateCacheHash($tsFeController->cHash_array);
} }
} }