Skip to content
Snippets Groups Projects
Commit fe7e00da authored by Markus Klein's avatar Markus Klein
Browse files

Revert "[TASK] FrontendContentAdapterService processes record repeatedly"

This reverts commit 3adf7835

This patch breaks section menus as it introduces invalid caching.
The original patch has not yet been backported.

Resolves: #56209
Resolves: #54953
Releases: 6.2
Change-Id: Ia3fc8718ed3907913a5538eee102260425f2cf16
Reviewed-on: https://review.typo3.org/27788
Reviewed-by: Markus Klein
Tested-by: Markus Klein
parent 40200bd1
No related branches found
No related tags found
No related merge requests found
......@@ -65,11 +65,6 @@ class FrontendContentAdapterService {
)
);
/**
* @var array
*/
protected static $migrationCache = array();
/**
* Modifies the DB row in the CONTENT cObj of tslib_content for supplying
* backwards compatibility for some file fields which have switched to using
......@@ -83,77 +78,62 @@ class FrontendContentAdapterService {
* @return void
*/
static public function modifyDBRow(&$row, $table) {
// Only consider records with uid set, that have
// not been processed yet ("migrated")
if (!isset($row['uid']) || isset($row['_MIGRATED']) && $row['_MIGRATED'] === TRUE) {
return;
}
// Only consider records of table pages and tt_content
if ($table !== 'pages' && $table !== 'tt_content') {
return;
}
// Use cached result, if available
if (!empty(static::$migrationCache[$table][$row['uid']])) {
$row = static::$migrationCache[$table][$row['uid']];
if (isset($row['_MIGRATED']) && $row['_MIGRATED'] === TRUE) {
return;
}
// Process fields and execute "migration"
if (!isset(static::$migrationCache[$table])) {
static::$migrationCache[$table] = array();
}
foreach (static::$migrateFields[$table] as $migrateFieldName => $oldFieldNames) {
if (isset($row[$migrateFieldName]) && self::fieldIsInType($migrateFieldName, $table, $row)) {
/** @var $fileRepository \TYPO3\CMS\Core\Resource\FileRepository */
$fileRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
if ($table === 'pages' && isset($row['_LOCALIZED_UID']) && (int)$row['sys_language_uid'] > 0) {
$table = 'pages_language_overlay';
}
$files = $fileRepository->findByRelation($table, $migrateFieldName, isset($row['_LOCALIZED_UID']) ? (int)$row['_LOCALIZED_UID'] : (int)$row['uid']);
$fileFieldContents = array(
'paths' => array(),
'titleTexts' => array(),
'captions' => array(),
'links' => array(),
'alternativeTexts' => array(),
$migrateFieldName . '_fileUids' => array(),
$migrateFieldName . '_fileReferenceUids' => array(),
);
$oldFieldNames[$migrateFieldName . '_fileUids'] = $migrateFieldName . '_fileUids';
$oldFieldNames[$migrateFieldName . '_fileReferenceUids'] = $migrateFieldName . '_fileReferenceUids';
if (array_key_exists($table, static::$migrateFields)) {
foreach (static::$migrateFields[$table] as $migrateFieldName => $oldFieldNames) {
if ($row !== NULL && isset($row[$migrateFieldName]) && self::fieldIsInType($migrateFieldName, $table, $row)) {
/** @var $fileRepository \TYPO3\CMS\Core\Resource\FileRepository */
$fileRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
if ($table === 'pages' && isset($row['_LOCALIZED_UID']) && intval($row['sys_language_uid']) > 0) {
$table = 'pages_language_overlay';
}
$files = $fileRepository->findByRelation($table, $migrateFieldName, isset($row['_LOCALIZED_UID']) ? intval($row['_LOCALIZED_UID']) : intval($row['uid']));
$fileFieldContents = array(
'paths' => array(),
'titleTexts' => array(),
'captions' => array(),
'links' => array(),
'alternativeTexts' => array(),
$migrateFieldName . '_fileUids' => array(),
$migrateFieldName . '_fileReferenceUids' => array(),
);
$oldFieldNames[$migrateFieldName . '_fileUids'] = $migrateFieldName . '_fileUids';
$oldFieldNames[$migrateFieldName . '_fileReferenceUids'] = $migrateFieldName . '_fileReferenceUids';
foreach ($files as $file) {
/** @var $file \TYPO3\CMS\Core\Resource\FileReference */
$fileProperties = $file->getProperties();
$fileFieldContents['paths'][] = '../../' . $file->getPublicUrl();
$fileFieldContents['titleTexts'][] = $fileProperties['title'];
$fileFieldContents['captions'][] = $fileProperties['description'];
$fileFieldContents['links'][] = $fileProperties['link'];
$fileFieldContents['alternativeTexts'][] = $fileProperties['alternative'];
$fileFieldContents[$migrateFieldName . '_fileUids'][] = $file->getOriginalFile()->getUid();
$fileFieldContents[$migrateFieldName . '_fileReferenceUids'][] = $file->getUid();
}
foreach ($oldFieldNames as $oldFieldType => $oldFieldName) {
if ($oldFieldType === '__typeMatch') {
continue;
foreach ($files as $file) {
/** @var $file \TYPO3\CMS\Core\Resource\FileReference */
$fileProperties = $file->getProperties();
$fileFieldContents['paths'][] = '../../' . $file->getPublicUrl();
$fileFieldContents['titleTexts'][] = $fileProperties['title'];
$fileFieldContents['captions'][] = $fileProperties['description'];
$fileFieldContents['links'][] = $fileProperties['link'];
$fileFieldContents['alternativeTexts'][] = $fileProperties['alternative'];
$fileFieldContents[$migrateFieldName . '_fileUids'][] = $file->getOriginalFile()->getUid();
$fileFieldContents[$migrateFieldName . '_fileReferenceUids'][] = $file->getUid();
}
if ($oldFieldType === 'paths' || substr($oldFieldType, -9) == '_fileUids' || substr($oldFieldType, -18) == '_fileReferenceUids') {
// For paths and uids, make comma separated list
$fieldContents = implode(',', $fileFieldContents[$oldFieldType]);
} else {
// For all other fields, separate by newline
$fieldContents = implode(chr(10), $fileFieldContents[$oldFieldType]);
foreach ($oldFieldNames as $oldFieldType => $oldFieldName) {
if ($oldFieldType === '__typeMatch') {
continue;
}
if ($oldFieldType === 'paths' || substr($oldFieldType, -9) == '_fileUids' || substr($oldFieldType, -18) == '_fileReferenceUids') {
// For paths and uids, make comma separated list
$fieldContents = implode(',', $fileFieldContents[$oldFieldType]);
} else {
// For all other fields, separate by newline
$fieldContents = implode(chr(10), $fileFieldContents[$oldFieldType]);
}
$row[$oldFieldName] = $fieldContents;
}
$row[$oldFieldName] = $fieldContents;
}
}
}
$row['_MIGRATED'] = TRUE;
static::$migrationCache[$table][$row['uid']] = $row;
}
/**
* Checks whether field is in type
* Check if fieldis in type
*
* @param string $fieldName
* @param string $table
......@@ -165,10 +145,7 @@ class FrontendContentAdapterService {
if (empty($fieldConfiguration['__typeMatch'])) {
return TRUE;
} else {
return in_array(
$row[$fieldConfiguration['__typeMatch']['typeField']],
$fieldConfiguration['__typeMatch']['types']
);
return in_array($row[$fieldConfiguration['__typeMatch']['typeField']], $fieldConfiguration['__typeMatch']['types']);
}
}
}
......@@ -37,16 +37,10 @@ class FrontendContentAdapterServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCa
*/
protected $singletonInstances = array();
/**
* @var string
*/
protected $accessibleFixtureName;
/**
* Saving the singletons
*/
public function setUp() {
$this->accessibleFixtureName = $this->buildAccessibleProxy('TYPO3\\CMS\\Core\\Resource\\Service\\FrontendContentAdapterService');
$this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
$this->fileRepositoryMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileRepository');
\TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository', $this->fileRepositoryMock);
......@@ -56,33 +50,10 @@ class FrontendContentAdapterServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCa
* Restoring the singletons
*/
public function tearDown() {
call_user_func_array($this->accessibleFixtureName . '::_setStatic', array('migrationCache', array()));
\TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
parent::tearDown();
}
/**
* @test
*/
public function customTableIsNotConsidered() {
$dbRow = array(
'uid' => uniqid(),
);
/* @see \TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow */
$result = call_user_func_array($this->accessibleFixtureName . '::modifyDBRow', array(&$dbRow, uniqid('tx_testtable')));
$this->assertNull($result);
}
/**
* @test
*/
public function recordWithoutUidIsNotConsidered() {
$dbRow = array();
/* @see \TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow */
$result = call_user_func_array($this->accessibleFixtureName . '::modifyDBRow', array(&$dbRow, 'tt_content'));
$this->assertNull($result);
}
/**
* @test
*/
......@@ -91,47 +62,14 @@ class FrontendContentAdapterServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCa
->method('findByRelation')
->will($this->returnValue(array()));
$dbRow = array(
'uid' => uniqid(),
'CType' => 'image',
'image' => '1'
);
/* @see \TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow */
call_user_func_array($this->accessibleFixtureName . '::modifyDBRow', array(&$dbRow, 'tt_content'));
\TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow($dbRow, 'tt_content');
$this->assertEmpty($dbRow['image']);
}
/**
* @test
*/
public function processedRecordsAreCached() {
// Asserting that this is only called once,
// since second call shall be delivered from cache
$this->fileRepositoryMock->expects($this->once())
->method('findByRelation')
->will($this->returnValue(array()));
$testUid = uniqid();
$dbRow = array(
'uid' => $testUid,
'CType' => 'image',
'image' => '1',
);
/* @see \TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow */
call_user_func_array($this->accessibleFixtureName . '::modifyDBRow', array(&$dbRow, 'tt_content'));
$dbRow = array(
'uid' => $testUid,
'CType' => 'image',
'image' => '1',
);
/* @see \TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow */
call_user_func_array($this->accessibleFixtureName . '::modifyDBRow', array(&$dbRow, 'tt_content'));
}
/**
* @test
*/
......@@ -147,17 +85,15 @@ class FrontendContentAdapterServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCa
->method('findByRelation')
->will($this->returnValue(array($fileReference)));
$dbRow = array(
'uid' => uniqid(),
'CType' => 'image',
'image' => '1'
);
/* @see \TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow */
call_user_func_array($this->accessibleFixtureName . '::modifyDBRow', array(&$dbRow, 'tt_content'));
\TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow($dbRow, 'tt_content');
$this->assertSame('../../path/to/file', $dbRow['image']);
}
public function contentRowsOfDifferentTypesDataProvider() {
public function conteRowsOfDifferentTypesDataProvider() {
$filePropertiesImage = array(
'title' => 'Image',
'description' => 'IMAGE DESCRIPTION',
......@@ -171,7 +107,6 @@ class FrontendContentAdapterServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCa
return array(
'Image Element' => array(
array(
'uid' => uniqid(),
'CType' => 'image',
'image' => '',
'media' => '',
......@@ -181,7 +116,6 @@ class FrontendContentAdapterServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCa
),
'Textpic Element' => array(
array(
'uid' => uniqid(),
'CType' => 'textpic',
'image' => '',
'media' => '',
......@@ -191,7 +125,6 @@ class FrontendContentAdapterServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCa
),
'Uploads Element' => array(
array(
'uid' => uniqid(),
'CType' => 'uploads',
'image' => '',
'media' => '',
......@@ -204,7 +137,7 @@ class FrontendContentAdapterServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCa
/**
* @test
* @dataProvider contentRowsOfDifferentTypesDataProvider
* @dataProvider conteRowsOfDifferentTypesDataProvider
*/
public function migrationOfLegacyFieldsIsOnlyDoneWhenRelationFieldIsVisibleInType($dbRow, $expectedCaption, $fileProperties) {
$fileReference = $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileReference', array(), array(), '', FALSE);
......@@ -221,8 +154,7 @@ class FrontendContentAdapterServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCa
->method('findByRelation')
->will($this->returnValue(array($fileReference)));
/* @see \TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow */
call_user_func_array($this->accessibleFixtureName . '::modifyDBRow', array(&$dbRow, 'tt_content'));
\TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow($dbRow, 'tt_content');
$this->assertSame($expectedCaption, $dbRow['imagecaption']);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment