Commit badca6be authored by Claus Due's avatar Claus Due Committed by Oliver Hader
Browse files

[!!!][TASK] Deprecate cache FrontendInterface->getByTag

See #81460 for a detailed reasoning behind the change.

The patch declares the getByTags method as deprecated
and removes the only usage that existed in TYPO3.

Resolves: #81460
Related: #81432
Releases: master
Change-Id: I9647563246d96228cb906b7d9008b2cec564d3ae
Reviewed-on: https://review.typo3.org/53091


Reviewed-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
parent 137376c1
......@@ -15,7 +15,6 @@ namespace TYPO3\CMS\Backend;
*/
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
......@@ -66,13 +65,6 @@ class FrontendBackendUserAuthentication extends BackendUserAuthentication
*/
public $writeAttemptLog = false;
/**
* Array of page related information (uid, title, depth).
*
* @var array
*/
public $extPageInTreeInfo = [];
/**
* General flag which is set if the adminpanel is enabled at all.
*
......@@ -266,7 +258,6 @@ class FrontendBackendUserAuthentication extends BackendUserAuthentication
while ($row = $result->fetch()) {
if ($begin <= 0) {
$theList .= $row['uid'] . ',';
$this->extPageInTreeInfo[] = [$row['uid'], htmlspecialchars($row['title'], $depth)];
}
if ($depth > 1) {
$theList .= $this->extGetTreeList($row['uid'], $depth - 1, $begin - 1, $perms_clause);
......@@ -276,20 +267,6 @@ class FrontendBackendUserAuthentication extends BackendUserAuthentication
return $theList;
}
/**
* Returns the number of cached pages for a page id.
*
* @param int $pageId The page id.
* @return int The number of pages for this page in the "cache_pages" cache
*/
public function extGetNumberOfCachedPages($pageId)
{
/** @var FrontendInterface $pageCache */
$pageCache = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('cache_pages');
$pageCacheEntries = $pageCache->getByTag('pageId_' . (int)$pageId);
return count($pageCacheEntries);
}
/*****************************************************
*
* Localization handling
......
......@@ -71,15 +71,6 @@ interface FrontendInterface
*/
public function get($entryIdentifier);
/**
* Finds and returns all cache entries which are tagged by the specified tag.
*
* @param string $tag The tag to search for
* @return array An array with the content of all matching entries. An empty array if no entries matched
* @api
*/
public function getByTag($tag);
/**
* Checks if a cache entry with the specified identifier exists.
*
......
......@@ -74,9 +74,11 @@ class StringFrontend extends AbstractFrontend
* @return array An array with the content of all matching entries. An empty array if no entries matched
* @throws \InvalidArgumentException if the tag is not valid
* @api
* @deprecated since TYPO3 v9, Avoid using this method since it is not compliant to PSR-6
*/
public function getByTag($tag)
{
trigger_error('This method will be removed in TYPO3 v10. Avoid using this method since it is not compliant to PSR-6.', E_USER_DEPRECATED);
if (!$this->isValidTag($tag)) {
throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233057772);
}
......
......@@ -94,9 +94,11 @@ class VariableFrontend extends AbstractFrontend
* @return array An array with the content of all matching entries. An empty array if no entries matched
* @throws \InvalidArgumentException if the tag is not valid
* @api
* @deprecated since TYPO3 v9, Avoid using this method since it is not compliant to PSR-6
*/
public function getByTag($tag)
{
trigger_error('This method will be removed in TYPO3 v10. Avoid using this method since it is not compliant to PSR-6.', E_USER_DEPRECATED);
if (!$this->isValidTag($tag)) {
throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233058312);
}
......
.. include:: ../../Includes.txt
==========================================================
Breaking: #81460 - Deprecate getByTag() on cache frontends
==========================================================
See :issue:`81460`
Description
===========
The following public method and property have been removed without any substitute
since it invoked or was used in combination with Cache\FrontendInterface::getByTag
method which has been deprecated and removed from the interface declaration.
* TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication::extGetNumberOfCachedPages
* TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication::$extPageInTreeInfo
Impact
======
Calling TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication::extGetNumberOfCachedPages will
result in a PHP fatal error. Using the property FrontendUserAuthentication::$extPageInTreeInfo will
return an implicit `null` instead of an `array`.
Affected Installations
======================
All that make use of TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication::extGetNumberOfCachedPages
or property TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication::$extPageInTreeInfo.
Migration
=========
Remove invocation of TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication::extGetNumberOfCachedPages
and property TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication::$extPageInTreeInfo.
.. index:: PHP-API, FullyScanned
.. include:: ../../Includes.txt
=============================================================
Deprecation: #81460 - Deprecate getByTag() on cache frontends
=============================================================
See :issue:`81460`
Description
===========
The method ``getByTag($tag)`` on ``TYPO3\CMS\Core\Cache\Frontend\FrontendInterface`` and all implementations have been
deprecated with no alternative planned. This is done because the concept of cache tags were originally designed for
invalidation purposes, not for identification and retrieval.
Cache frontends still support the much more efficient ``flushByTag`` and ``flushByTags`` methods to perform invalidation
by tag, rather than use the deprecated method to retrieve a list of identifiers and removing each.
Impact
======
Calling this method on any TYPO3 provided cache frontend implementations triggers a deprecation log entry, with the
exception of ``StringFrontend`` which has itself been deprecated in a separate patch.
Affected Installations
======================
Avoid usage of the method - if necessary, use the same cache to store a list of identifiers for each tag.
Migration
=========
Where possible, switch to ``flushByTag`` or ``flushByTags``. In cases where you depend on getting identifiers by tag,
reconsider your business logic - and if necessary, keep track of which identifiers use a given tag, using a separate
list that you for example store in the cache alongside the usual cached entries.
.. index:: PHP-API, FullyScanned
......@@ -127,35 +127,4 @@ class StringFrontendTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
$cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
$this->assertTrue($cache->remove($cacheIdentifier), 'remove() did not return TRUE');
}
/**
* @test
*/
public function getByTagRejectsInvalidTags()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionCode(1233057772);
$backend = $this->createMock(\TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface::class);
$cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
$cache->getByTag('SomeInvalid\\Tag');
}
/**
* @test
*/
public function getByTagCallsBackend()
{
$tag = 'sometag';
$identifiers = ['one', 'two'];
$entries = ['one value', 'two value'];
$backend = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
->disableOriginalConstructor()
->getMock();
$backend->expects($this->once())->method('findIdentifiersByTag')->with($this->equalTo($tag))->will($this->returnValue($identifiers));
$backend->expects($this->exactly(2))->method('get')->will($this->onConsecutiveCalls('one value', 'two value'));
$cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
$this->assertEquals($entries, $cache->getByTag($tag), 'Did not receive the expected entries');
}
}
......@@ -163,37 +163,4 @@ class VariableFrontendTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCas
$cache = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('VariableFrontend', $backend);
$this->assertTrue($cache->remove($cacheIdentifier), 'remove() did not return TRUE');
}
/**
* @test
*/
public function getByTagRejectsInvalidTags()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionCode(1233058312);
$backend = $this->createMock(\TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface::class);
$cache = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('VariableFrontend', $backend);
$cache->getByTag('SomeInvalid\Tag');
}
/**
* @test
*/
public function getByTagCallsBackend()
{
$tag = 'sometag';
$identifiers = ['one', 'two'];
$entries = ['one value', 'two value'];
$backend = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
->disableOriginalConstructor()
->getMock();
$backend->expects($this->once())->method('findIdentifiersByTag')->with($this->equalTo($tag))->will($this->returnValue($identifiers));
$backend->expects($this->exactly(2))->method('get')->will($this->onConsecutiveCalls(serialize('one value'), serialize('two value')));
$cache = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('VariableFrontend', $backend);
$this->assertEquals($entries, $cache->getByTag($tag), 'Did not receive the expected entries');
}
}
......@@ -155,7 +155,6 @@ class AdminPanelView
unset($beUser->uc['TSFE_adminConfig']['action']);
// Actions:
if (($input['action']['clearCache'] && $this->isAdminModuleEnabled('cache')) || isset($input['preview_showFluidDebug'])) {
$beUser->extPageInTreeInfo = [];
$theStartId = (int)$input['cache_clearCacheId'];
$this->getTypoScriptFrontendController()
->clearPageCacheContent_pidList(
......@@ -522,8 +521,7 @@ class AdminPanelView
protected function getCacheModule()
{
$output = [];
$beUser = $this->getBackendUser();
if ($beUser->uc['TSFE_adminConfig']['display_cache']) {
if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_cache']) {
$this->extNeedUpdate = true;
$output[] = '<div class="typo3-adminPanel-form-group">';
......@@ -536,7 +534,7 @@ class AdminPanelView
$output[] = ' </div>';
$output[] = '</div>';
$levels = $beUser->uc['TSFE_adminConfig']['cache_clearCacheLevels'];
$levels = $this->getBackendUser()->uc['TSFE_adminConfig']['cache_clearCacheLevels'];
$output[] = '<div class="typo3-adminPanel-form-group">';
$output[] = ' <label for="' . htmlspecialchars('cache_clearCacheLevels') . '">';
$output[] = ' ' . $this->extGetLL('cache_clearLevels');
......@@ -558,44 +556,6 @@ class AdminPanelView
$output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[cache_clearCacheId]" value="' . $GLOBALS['TSFE']->id . '" />';
$output[] = ' <input class="typo3-adminPanel-btn typo3-adminPanel-btn-default" type="submit" value="' . $this->extGetLL('update') . '" />';
$output[] = '</div>';
// Generating tree:
$depth = (int)$this->extGetFeAdminValue('cache', 'clearCacheLevels');
$outTable = '';
$tsfe = $this->getTypoScriptFrontendController();
$beUser->extPageInTreeInfo = [];
$beUser->extPageInTreeInfo[] = [
$tsfe->page['uid'],
htmlspecialchars($tsfe->page['title']),
$depth + 1
];
$beUser->extGetTreeList(
$tsfe->id,
$depth,
0,
$beUser->getPagePermsClause(1)
);
$output[] = '<div class="typo3-adminPanel-table-overflow">';
$output[] = '<table class="typo3-adminPanel-table">';
$output[] = ' <thead>';
$output[] = ' <tr>';
$output[] = ' <th colspan="2">' . $this->extGetLL('cache_cacheEntries') . '</th>';
$output[] = ' </tr>';
$output[] = ' </thead>';
$output[] = ' <tbody>';
foreach ($beUser->extPageInTreeInfo as $key => $row) {
$output[] = '<tr>';
$output[] = ' <td>';
$output[] = ' <span style="width: ' . ($depth + 1 - $row[2]) * 5 . 'px; height: 1px; display: inline-block;"></span>';
$output[] = ' ' . $this->iconFactory->getIcon('apps-pagetree-page-default', Icon::SIZE_SMALL)->render() . htmlspecialchars($row[1]);
$output[] = ' </td>';
$output[] = ' <td>' . $beUser->extGetNumberOfCachedPages($row[0]) . '</td>';
$output[] = '</tr>';
}
$output[] = ' <tbody>';
$output[] = '</table>';
$output[] = '</div>';
$output[] = '<div class="typo3-adminPanel-form-group">';
$output[] = ' <input class="typo3-adminPanel-btn typo3-adminPanel-btn-default" type="submit" name="TSFE_ADMIN_PANEL[action][clearCache]" value="' . $this->extGetLL('cache_doit') . '" />';
$output[] = '</div>';
......
......@@ -1500,4 +1500,11 @@ return [
'Breaking-82426-ExtJSAndExtDirectRemoval.rst',
],
],
'TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication->extGetNumberOfCachedPages' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Breaking-81460-DeprecateGetByTagOnCacheFrontends.rst',
],
],
];
......@@ -214,6 +214,11 @@ return [
'Breaking-82639-LoggingActivatedForAuthenticationAndServiceClasses.rst',
],
],
'TYPO3\CMS\Backend\FrontendBackendUserAuthentication->extPageInTreeInfo' => [
'restFiles' => [
'Breaking-81460-DeprecateGetByTagOnCacheFrontends.rst',
],
],
// Deprecated public properties
];
......@@ -39,9 +39,6 @@
<trans-unit id="cache_clearLevels">
<source>Clear levels</source>
</trans-unit>
<trans-unit id="cache_cacheEntries">
<source>Cache entries</source>
</trans-unit>
<trans-unit id="publish">
<source>Publish</source>
</trans-unit>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment