Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Create a fake TYPO3_REQUEST, as this throws errors through Cron job manager #503

Open
wants to merge 1 commit into
base: 12.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Classes/DirectMailUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
use DirectMailTeam\DirectMail\Utility\RdctUtility;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver;
use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
Expand Down Expand Up @@ -94,6 +99,21 @@ public static function getTypolinkURL(
bool $forceAbsoluteUrl = true,
bool $linkAccessRestrictedPages = true
): string {

if (empty($GLOBALS['TYPO3_REQUEST'])) {
$context = GeneralUtility::makeInstance(Context::class);
// Retrieve site and site language from context
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
$site = $siteFinder->getSiteByPageId(1);
$siteLanguageId = $context->getPropertyFromAspect('language', 'id');
$siteLanguage = $site->getLanguageById($siteLanguageId);
$request = new ServerRequest(new Uri((string)$siteLanguage->getBase()));
$request = $request->withAttribute('site', $site);
$request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE);
$request = $request->withAttribute('language', $siteLanguage);
$request = $request->withQueryParams(['id' => $site->getRootPageId()]);
$GLOBALS['TYPO3_REQUEST'] = $request;
}
$typolinkPageUrl = 't3://page?uid=';
$cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);

Expand Down