Skip to content

Commit

Permalink
chore: CD-319266 First tagged TYPO3 v12 version
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcesoldier committed Aug 20, 2024
1 parent adc120d commit c2cf70e
Show file tree
Hide file tree
Showing 22 changed files with 209 additions and 216 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ var
/typo3conf
/vendor
.php_cs.cache
Tests/Unit/.phpunit.cache
35 changes: 18 additions & 17 deletions Classes/Controller/BanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use Aoe\Varnish\System\Varnish;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

class BanController extends ActionController
Expand All @@ -49,15 +49,15 @@ public function __construct(ModuleTemplateFactory $moduleTemplateFactory, Varnis
public function indexAction(): ResponseInterface
{
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setContent($this->view->render());
return $this->htmlResponse($moduleTemplate->renderContent());

return $moduleTemplate->renderResponse('index');
}

public function confirmBanTypo3PagesAction(): ResponseInterface
{
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setContent($this->view->render());
return $this->htmlResponse($moduleTemplate->renderContent());

return $moduleTemplate->renderResponse('confirmBanTypo3Pages');
}

public function banTypo3PagesAction(): void
Expand All @@ -70,23 +70,23 @@ public function banTypo3PagesAction(): void
if ($result['success']) {
$this->addFlashMessage($result['reason']);
} else {
$this->addFlashMessage($result['reason'], '', AbstractMessage::ERROR);
$this->addFlashMessage($result['reason'], '', ContextualFeedbackSeverity::ERROR);
}
}

$this->redirect('index');
return $this->redirect('index');
}

public function confirmBanTagByNameAction(string $tagName): ResponseInterface
{
if ($this->isValidTagName($tagName)) {
$this->view->assign('tagName', $tagName);
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setContent($this->view->render());
return $this->htmlResponse($moduleTemplate->renderContent());
$moduleTemplate->assign('tagName', $tagName);

return $moduleTemplate->renderResponse('confirmBanTagByName');
}

$this->redirect('index');
return $this->redirect('index');
}

public function banTagByNameAction(string $tagName): void
Expand All @@ -99,7 +99,7 @@ public function banTagByNameAction(string $tagName): void
if ($result['success']) {
$this->addFlashMessage($result['reason']);
} else {
$this->addFlashMessage($result['reason'], '', AbstractMessage::ERROR);
$this->addFlashMessage($result['reason'], '', ContextualFeedbackSeverity::ERROR);
}
}

Expand All @@ -111,8 +111,9 @@ public function confirmBanByRegexAction(string $regex): ResponseInterface
if (!$this->isCriticalRegex($regex)) {
$this->view->assign('regex', $regex);
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setContent($this->view->render());
return $this->htmlResponse($moduleTemplate->renderContent());
$moduleTemplate->assign('regex', $regex);

return $moduleTemplate->renderResponse('confirmBanByRegex');
}

$this->redirect('index');
Expand All @@ -128,7 +129,7 @@ public function banByRegexAction(string $regex): void
if ($result['success']) {
$this->addFlashMessage($result['reason']);
} else {
$this->addFlashMessage($result['reason'], '', AbstractMessage::ERROR);
$this->addFlashMessage($result['reason'], '', ContextualFeedbackSeverity::ERROR);
}
}

Expand All @@ -138,7 +139,7 @@ public function banByRegexAction(string $regex): void
private function isCriticalRegex(string $regex): bool
{
if (strlen($regex) < 6) {
$this->addFlashMessage('Bitte geben Sie einen spezifischeren RegEx ein!', '', AbstractMessage::ERROR);
$this->addFlashMessage('Bitte geben Sie einen spezifischeren RegEx ein!', '', ContextualFeedbackSeverity::ERROR);
return true;
}

Expand All @@ -148,7 +149,7 @@ private function isCriticalRegex(string $regex): bool
private function isValidTagName(string $tagName): bool
{
if (strlen($tagName) < 2) {
$this->addFlashMessage('Bitte geben Sie einen gültigen Tag-Namen ein! ', '', AbstractMessage::ERROR);
$this->addFlashMessage('Bitte geben Sie einen gültigen Tag-Namen ein! ', '', ContextualFeedbackSeverity::ERROR);
return false;
}

Expand Down
30 changes: 30 additions & 0 deletions Classes/EventListener/ClearCacheMenu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Aoe\Varnish\EventListener;

use TYPO3\CMS\Backend\Backend\Event\ModifyClearCacheActionsEvent;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;

final class ClearCacheMenu
{
/**
* Hook to add 'clear-varnish-cache'-button in TYPO3-BE
*/
public function __invoke(ModifyClearCacheActionsEvent $event): void
{
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);

$cacheAction = [
'id' => 'varnish',
'title' => 'LLL:EXT:varnish/Resources/Private/Language/locallang.xlf:backendAjaxHook.title',
'description' => 'LLL:EXT:varnish/Resources/Private/Language/locallang.xlf:backendAjaxHook.description',
'href' => (string) $uriBuilder->buildUriFromRoute('ajax_varnish_ban_all'),
'iconIdentifier' => 'varnish',
];

$event->addCacheAction($cacheAction);
}
}
59 changes: 59 additions & 0 deletions Classes/EventListener/Crawler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace Aoe\Varnish\EventListener;

use Aoe\Varnish\Domain\Model\Tag\PageIdTag;
use Aoe\Varnish\System\Varnish;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Frontend\Event\ShouldUseCachedPageDataIfAvailableEvent;

class Crawler
{
protected Varnish $varnish;

/**
* Hook to clear varnish-cache - hook is called when crawler-extension crawl the page
* Is used in TYPO3-Context: FE (but we should always see those hooks also in the BE-configuration-module for a better overview of configured hooks)
*/
public function __invoke(ShouldUseCachedPageDataIfAvailableEvent $event): void
{
$TypoScriptFrontendController = $event->getController();

$this->clearVarnishCache($TypoScriptFrontendController);
}

public function clearVarnishCache(TypoScriptFrontendController $parentObject): void
{
if ($this->isCrawlerExtensionLoaded() && $this->isCrawlerRunning($parentObject)) {
$this->clearPageCacheInVarnish($parentObject->id);
}
}

protected function isCrawlerExtensionLoaded(): bool
{
return ExtensionManagementUtility::isLoaded('crawler');
}

protected function getVarnish(): Varnish
{
$this->varnish ??= GeneralUtility::makeInstance(Varnish::class);
return $this->varnish;
}

private function clearPageCacheInVarnish(int $pageId): void
{
$pageIdTag = new PageIdTag($pageId);

$varnish = $this->getVarnish();
$varnish->banByTag($pageIdTag);
}

private function isCrawlerRunning(TypoScriptFrontendController $tsfe): bool
{
return isset($tsfe->applicationData['tx_crawler']['running']);
}
}
53 changes: 0 additions & 53 deletions Classes/TYPO3/Hooks/ClearCacheMenuHook.php

This file was deleted.

65 changes: 0 additions & 65 deletions Classes/TYPO3/Hooks/CrawlerHook.php

This file was deleted.

15 changes: 15 additions & 0 deletions Configuration/Icons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider;

return [
// Icon identifier
'varnish' => [
// Icon provider class
'provider' => SvgIconProvider::class,
// The source SVG for the SvgIconProvider
'source' => 'EXT:varnish/Resources/Public/Icons/Extension.svg',
]
];
14 changes: 13 additions & 1 deletion Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,16 @@ services:
public: false

Aoe\Varnish\:
resource: '../Classes/*'
resource: '../Classes/*'

Aoe\Varnish\EventListener\Crawler:
tags:
- name: event.listener
identifier: 'aoe-varnish/crawler-hook'
event: TYPO3\CMS\Frontend\Event\ShouldUseCachedPageDataIfAvailableEvent

Aoe\Varnish\EventListener\ClearCacheMenu:
tags:
- name: event.listener
identifier: 'aoe-varnish/toolbar/clear-cache-menu'
event: TYPO3\CMS\Backend\Backend\Event\ModifyClearCacheActionsEvent
11 changes: 6 additions & 5 deletions Configuration/TCA/Overrides/pages.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('pages', [
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

defined('TYPO3') or die();

ExtensionManagementUtility::addTCAcolumns('pages', [
'varnish_cache' => [
'exclude' => 0,
'label' => 'LLL:EXT:varnish/Resources/Private/Language/locallang_db.xlf:varnish.field',
Expand All @@ -14,7 +15,7 @@
]
]);

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette(
ExtensionManagementUtility::addFieldsToPalette(
'pages',
'caching',
'varnish_cache'
Expand Down
1 change: 1 addition & 0 deletions Tests/Unit/System/HeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class HeaderTest extends UnitTestCase

protected function setUp(): void
{
parent::setUp();
$this->header = new Header();
}

Expand Down
Loading

0 comments on commit c2cf70e

Please sign in to comment.