Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog
All notable changes to this extension will be documented in this file.

## [13.0.4] - 2025-09-02

### Fixed
- Fixed cache invalidation bug when creating or deleting a page.
13 changes: 4 additions & 9 deletions Classes/Cache/CloudFrontCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function queueClearCache(int $pageId, bool $recursive = false, string|nul

if (count($languages) > 0) {
if ($this->isMultiLanguageDomains($entry)) {
$this->enqueue($this->buildLink($entry, array('_language' => 0)) . $wildcard, $this->distributionsMapping[$languages[0]->getBase()->getHost()]);
$this->enqueue($this->buildLink($entry, array('_language' => 0)) . $wildcard, $this->distributionsMapping[(string)$languages[0]->getBase()->getHost()]);
foreach ($languages as $k => $lang) {
if ($lang->getLanguageId() != 0) {
$this->enqueue($this->buildLink($entry, array('_language' => $lang->getLanguageId())) . $wildcard, $this->distributionsMapping[$lang->getBase()->getHost()]);
Expand Down Expand Up @@ -327,15 +327,10 @@ public function getLanguagesDomains(int $uid_page): array
* @return bool True if there are multiple languages with different domains, false otherwise.
*/
public function isMultiLanguageDomains(int $uid_page): bool
{
$multi = true;
{;
$domains = $this->getLanguagesDomains($uid_page);
foreach ($domains as $lang => $domain) {
if (strpos($domain, '.') === false) {
$multi = false;
}
}
return $multi;

return count(array_unique(array_map('strtolower', $domains))) > 1;
}

/**
Expand Down
37 changes: 32 additions & 5 deletions Classes/Hooks/ClearCachePostProc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace Toumoro\TmCloudfront\Hooks;

use Doctrine\DBAL\ParameterType;
use Toumoro\TmCloudfront\Cache\CloudFrontCacheManager;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -33,7 +34,9 @@ class ClearCachePostProc

protected CloudFrontCacheManager $cacheManager;

public function __construct()
public function __construct(
protected SiteFinder $siteFinder
)
{
$this->cloudFrontConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class)
->get('tm_cloudfront')['cloudfront'];
Expand Down Expand Up @@ -105,8 +108,10 @@ public function clearCachePostProc(&$params, &$pObj): void
$distributionIds = $this->getDistributionIds($uid_page, $params);

// Priority to TsConfig settings
if (!empty($tsConfig['distributionIds'])) {
$distributionIds = $tsConfig['distributionIds'];
if (!empty($tsConfig['TCEMAIN.'])) {
if(!empty($tsConfig['TCEMAIN.']['distributionIds'])) {
$distributionIds = $tsConfig['TCEMAIN.']['distributionIds'];
}
}

// If the record is not a page, enqueue only the current page
Expand Down Expand Up @@ -178,8 +183,10 @@ protected function getDistributionsFromDomains(array $domains): string
protected function getDistributionIds(int $uid_page, array $params): string
{
$domain = '';
if ($uid_page > 0 && isset($params['table'], $params['uid'])) {
$site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId($uid_page);

if ($uid_page > 0 && isset($params['table'], $params['uid']) && !$this->isPageDeleted($uid_page)) {
$site = $this->siteFinder->getSiteByPageId($uid_page);

$row = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($params['table'])
->select('*')
Expand All @@ -206,4 +213,24 @@ protected function getDistributionIds(int $uid_page, array $params): string

return $distributionIds;
}

private function isPageDeleted($uid): int
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('pages');

$queryBuilder->getRestrictions()->removeAll();

return (int)$queryBuilder
->select('deleted')
->from('pages')
->where(
$queryBuilder->expr()->eq(
'uid',
$queryBuilder->createNamedParameter($uid, ParameterType::INTEGER)
)
)
->executeQuery()
->fetchOne();
}
}
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
'author' => 'Simon Ouellet',
'author_email' => '',
'state' => 'beta',
'version' => '13.0.2',
'version' => '13.0.4',
'constraints' => [
'depends' => [
'typo3' => '12.4.0-13.5.99',
Expand Down