mirror of
https://github.com/werkraum-media/abtest.git
synced 2024-11-14 18:36:10 +01:00
Now it generates a cHash for each Version, so it can use the cache
This commit is contained in:
parent
c4ff8f2fee
commit
45b675ba92
1 changed files with 86 additions and 62 deletions
|
@ -11,6 +11,7 @@ namespace WapplerSystems\ABTest2;
|
|||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
|
||||
use TYPO3\CMS\Frontend\Page\CacheHashCalculator;
|
||||
use TYPO3\CMS\Frontend\Page\PageRepository;
|
||||
|
||||
/**
|
||||
|
@ -25,20 +26,20 @@ class Helper
|
|||
/**
|
||||
*
|
||||
* @param array $params
|
||||
* @param $pObj TypoScriptFrontendController
|
||||
* @param $tsFeController TypoScriptFrontendController
|
||||
* @return void
|
||||
* @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.
|
||||
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.
|
||||
$realurlConfig = $pObj->TYPO3_CONF_VARS['EXTCONF']['realurl'];
|
||||
$realurlConfig = $tsFeController->TYPO3_CONF_VARS['EXTCONF']['realurl'];
|
||||
if (array_key_exists($_SERVER['SERVER_NAME'], $realurlConfig)) {
|
||||
$rootpage_id = $realurlConfig[$_SERVER['SERVER_NAME']]['pagePath']['rootpage_id'];
|
||||
} 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 ($currentPageId !== $targetPageId) {
|
||||
$pObj->contentPid = $targetPageId;
|
||||
$pObj->page['content_from_pid'] = $targetPageId;
|
||||
$tsFeController->contentPid = $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) {
|
||||
$additionalHeaderData = $currentPagePropertiesArray['tx_abtest2_header'];
|
||||
$additionalFooterData = $currentPagePropertiesArray['tx_abtest2_footer'];
|
||||
if ($additionalHeaderData) {
|
||||
$pObj->additionalHeaderData['abtest2'] = $additionalHeaderData;
|
||||
$tsFeController->additionalHeaderData['abtest2'] = $additionalHeaderData;
|
||||
}
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue