diff --git a/Classes/Controller/AbstractController.php b/Classes/Controller/AbstractController.php index 52c44dd..963270a 100644 --- a/Classes/Controller/AbstractController.php +++ b/Classes/Controller/AbstractController.php @@ -21,8 +21,13 @@ namespace Wrm\Events\Controller; * 02110-1301, USA. */ +use TYPO3\CMS\Core\Exception\Page\PageNotFoundException; +use TYPO3\CMS\Core\Http\ImmediateResponseException; +use TYPO3\CMS\Core\Http\PropagateResponseException; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; +use TYPO3\CMS\Frontend\Controller\ErrorController; use Wrm\Events\Caching\CacheManager; class AbstractController extends ActionController @@ -66,4 +71,21 @@ class AbstractController extends ActionController return $view; } + + protected function trigger404(string $message): void + { + $errorController = GeneralUtility::makeInstance(ErrorController::class); + + if (class_exists(ImmediateResponseException::class)) { + throw new ImmediateResponseException( + $errorController->pageNotFoundAction($GLOBALS['TYPO3_REQUEST'], $message), + 1695881164 + ); + } + + throw new PropagateResponseException( + $errorController->pageNotFoundAction($this->request, $message), + 1695881170 + ); + } } diff --git a/Classes/Controller/DateController.php b/Classes/Controller/DateController.php index 7e3d8be..eecb7e4 100644 --- a/Classes/Controller/DateController.php +++ b/Classes/Controller/DateController.php @@ -5,6 +5,7 @@ namespace Wrm\Events\Controller; use TYPO3\CMS\Core\EventDispatcher\EventDispatcher; use TYPO3\CMS\Extbase\Annotation as Extbase; use TYPO3\CMS\Extbase\Service\ExtensionService; +use Throwable; use Wrm\Events\Domain\Model\Date; use Wrm\Events\Domain\Model\Dto\DateDemandFactory; use Wrm\Events\Domain\Repository\CategoryRepository; @@ -155,6 +156,12 @@ class DateController extends AbstractController */ public function showAction(Date $date): void { + try { + $date->getEvent(); + } catch (Throwable $e) { + $this->trigger404('No event found for requested date.'); + } + $this->view->assign('date', $date); } diff --git a/Documentation/Changelog/3.5.1.rst b/Documentation/Changelog/3.5.1.rst new file mode 100644 index 0000000..3b195d6 --- /dev/null +++ b/Documentation/Changelog/3.5.1.rst @@ -0,0 +1,31 @@ +3.5.1 +===== + +Breaking +-------- + +Nothing + +Features +-------- + +Nothing + +Fixes +----- + +* Properly trigger 404 if a date is requested where event is not available. + This might happen if an event is set to hidden. + The date record is still available and can be requested. + But the event is missing, which in turn should make dates also unavailable. + This situation is now properly handled and will result in a 404. + +Tasks +----- + +Nothing + +Deprecation +----------- + +Nothing diff --git a/Documentation/Maintenance/TYPO3/V10.rst b/Documentation/Maintenance/TYPO3/V10.rst index e4f8619..6d096a9 100644 --- a/Documentation/Maintenance/TYPO3/V10.rst +++ b/Documentation/Maintenance/TYPO3/V10.rst @@ -9,3 +9,9 @@ Remove fetching cached page stage from body from tests We have different assertions based on TYPO3 version, due to how TYPO3 exposes the info. We can remove the condition with its content once we drop v10. + +Remove condition for page not found handling +-------------------------------------------- + +The :php:`AbstractController->trigger404()` method has a condition to handle 404 differently for TYPO3 v10. +The condition can be removed. diff --git a/Tests/Functional/AbstractFunctionalTestCase.php b/Tests/Functional/AbstractFunctionalTestCase.php index d67b785..7095d73 100644 --- a/Tests/Functional/AbstractFunctionalTestCase.php +++ b/Tests/Functional/AbstractFunctionalTestCase.php @@ -69,6 +69,11 @@ abstract class AbstractFunctionalTestCase extends FunctionalTestCase ]); ArrayUtility::mergeRecursiveWithOverrule($this->configurationToUseInTestInstance, [ + 'FE' => [ + 'cacheHash' => [ + 'enforceValidation' => false, + ], + ], 'GFX' => [ 'processor_enabled' => true, 'processor_path' => '/usr/bin/', diff --git a/Tests/Functional/Frontend/DatesTest.php b/Tests/Functional/Frontend/DatesTest.php index 65eb57a..dff5386 100644 --- a/Tests/Functional/Frontend/DatesTest.php +++ b/Tests/Functional/Frontend/DatesTest.php @@ -153,6 +153,23 @@ class DatesTest extends AbstractFunctionalTestCase self::assertStringContainsString('Event 9', $html); } + /** + * @test + */ + public function returns404IfEventIsHidden(): void + { + $this->importCSVDataSet(__DIR__ . '/DatesTestFixtures/Returns404IfEventIsHidden.csv'); + + $request = new InternalRequest(); + $request = $request->withPageId(1); + $request = $request->withQueryParameters([ + 'tx_events_dateshow[date]' => '1', + ]); + $response = $this->executeFrontendRequest($request); + + self::assertSame(404, $response->getStatusCode()); + } + /** * @test */ diff --git a/Tests/Functional/Frontend/DatesTestFixtures/Returns404IfEventIsHidden.csv b/Tests/Functional/Frontend/DatesTestFixtures/Returns404IfEventIsHidden.csv new file mode 100644 index 0000000..a4e309e --- /dev/null +++ b/Tests/Functional/Frontend/DatesTestFixtures/Returns404IfEventIsHidden.csv @@ -0,0 +1,9 @@ +tt_content +,uid,pid,CType,list_type,header +,1,1,list,events_dateshow,Singleview +tx_events_domain_model_event +,uid,pid,title,hidden +,1,2,"Event 1 starts before search, ends before search",1 +tx_events_domain_model_date +,uid,pid,event,start,end +,1,2,1,1676419200,1676484000 diff --git a/ext_emconf.php b/ext_emconf.php index f78498d..6f87866 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -9,7 +9,7 @@ $EM_CONF['events'] = [ 'state' => 'alpha', 'createDirs' => '', 'clearCacheOnLoad' => 0, - 'version' => '3.5.0', + 'version' => '3.5.1', 'constraints' => [ 'depends' => [ 'typo3' => '10.4.00-11.5.99', diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f7e71be..7db735c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,20 @@ parameters: ignoreErrors: + - + message: "#^Instantiated class TYPO3\\\\CMS\\\\Core\\\\Http\\\\PropagateResponseException not found\\.$#" + count: 1 + path: Classes/Controller/AbstractController.php + + - + message: "#^Parameter \\#1 \\$request of method TYPO3\\\\CMS\\\\Frontend\\\\Controller\\\\ErrorController\\:\\:pageNotFoundAction\\(\\) expects Psr\\\\Http\\\\Message\\\\ServerRequestInterface, TYPO3\\\\CMS\\\\Extbase\\\\Mvc\\\\Request given\\.$#" + count: 1 + path: Classes/Controller/AbstractController.php + + - + message: "#^Throwing object of an unknown class TYPO3\\\\CMS\\\\Core\\\\Http\\\\PropagateResponseException\\.$#" + count: 1 + path: Classes/Controller/AbstractController.php + - message: "#^Cannot call method typoLink_URL\\(\\) on TYPO3\\\\CMS\\\\Frontend\\\\ContentObject\\\\ContentObjectRenderer\\|null\\.$#" count: 1