Fix remaining deprecations and follow best practice

This commit is contained in:
Björn Fromme
2021-09-06 16:35:19 +02:00
parent d7804ab336
commit f0039dbe7a
86 changed files with 20430 additions and 4065 deletions
@@ -35,20 +35,15 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Error\Http\ServiceUnavailableException;
use TYPO3\CMS\Core\Http\ImmediateResponseException;
use TYPO3\CMS\Core\Http\NormalizedParams;
use TYPO3\CMS\Core\Http\RedirectResponse;
use TYPO3\CMS\Core\Site\Entity\SiteInterface;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
class TrackingMiddleware implements MiddlewareInterface
{
use DbConnectionTrait;
const CODE_PATTERN = 'PA\d{3,4}';
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if ($redirect = $this->matchRedirect($request)) {
@@ -112,20 +107,22 @@ class TrackingMiddleware implements MiddlewareInterface
$targetPage = $redirect['target_page_uid'];
$responseCode = $redirect['response_code'];
$controller = $this->bootFrontendController($request->getAttribute('site'));
/** @var SiteFinder $siteFinder */
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
$site = $siteFinder->getSiteByPageId($targetPage);
$typolinkConfig = ['parameter' => $targetPage, 'forceAbsoluteUrl' => true];
$params = [];
if ($redirect['utm_source'] && $redirect['utm_medium'] && $redirect['utm_campaign'] && $redirect['utm_content']) {
$typolinkConfig['additionalParams'] = '&' . http_build_query([
'utm_source' => $redirect['utm_source'],
'utm_medium' => $redirect['utm_medium'],
'utm_campaign' => $redirect['utm_campaign'],
'utm_content' => $redirect['utm_content'],
]);
$params = [
'utm_source' => $redirect['utm_source'],
'utm_medium' => $redirect['utm_medium'],
'utm_campaign' => $redirect['utm_campaign'],
'utm_content' => $redirect['utm_content'],
];
}
return [$controller->cObj->typolink_URL($typolinkConfig), $responseCode];
return [$site->getRouter()->generateUri($targetPage, $params), $responseCode];
}
/**
@@ -157,34 +154,4 @@ class TrackingMiddleware implements MiddlewareInterface
return $uri;
}
/**
* Borrowed from \TYPO3\CMS\Redirects\Service\RedirectService
*
* @param SiteInterface|null $site
* @param array $queryParams
* @return TypoScriptFrontendController
* @throws ServiceUnavailableException
* @throws ImmediateResponseException
*/
protected function bootFrontendController(?SiteInterface $site, array $queryParams = []): TypoScriptFrontendController
{
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_handling'] = false;
/** @var TypoScriptFrontendController $controller */
$controller = GeneralUtility::makeInstance(
TypoScriptFrontendController::class,
null,
$site ? $site->getRootPageId() : $GLOBALS['TSFE']->id,
0
);
$controller->fe_user = $GLOBALS['TSFE']->fe_user ?? null;
$controller->fetch_the_id();
$controller->calculateLinkVars($queryParams);
$controller->getConfigArray();
$controller->settingLanguage();
$controller->settingLocale();
$controller->newCObj();
return $controller;
}
}
@@ -22,10 +22,6 @@ return [
'searchFields' => 'label, redirect_from, tracking_code',
'iconfile' => 'EXT:ep_track/Resources/Public/Icons/tx_eptrack_domain_model_redirect.gif'
],
'interface' => [
'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, label, redirect_from,
target_page_uid, tracking_code, response_code, utm_source, utm_medium, utm_campaign, utm_content',
],
'types' => [
'1' => [
'showitem' => 'hidden, label, source_host, redirect_from, target_page_uid, --palette--;;codes,
@@ -54,7 +50,6 @@ return [
],
'l10n_parent' => [
'displayCond' => 'FIELD:sys_language_uid:>:0',
'exclude' => 0,
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.l18n_parent',
'config' => [
'type' => 'select',