'captions' => 'imagecaption',
'links' => 'image_link',
'alternativeTexts' => 'altText',
+ 'typeMatch' => array(
+ 'typeField' => 'CType',
+ 'types' => array('image', 'textpic'),
+ )
),
'media' => array(
'paths' => 'media',
- 'captions' => 'imagecaption'
+ 'captions' => 'imagecaption',
+ 'typeMatch' => array(
+ 'typeField' => 'CType',
+ 'types' => array('uploads'),
+ )
)
),
'pages' => array(
}
if (array_key_exists($table, static::$migrateFields)) {
foreach (static::$migrateFields[$table] as $migrateFieldName => $oldFieldNames) {
- if ($row !== NULL && isset($row[$migrateFieldName])) {
+ 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) {
foreach ($files as $file) {
/** @var $file \TYPO3\CMS\Core\Resource\FileReference */
+ $fileProperties = $file->getProperties();
$fileFieldContents['paths'][] = '../../' . $file->getPublicUrl();
- $fileFieldContents['titleTexts'][] = $file->getProperty('title');
- $fileFieldContents['captions'][] = $file->getProperty('description');
- $fileFieldContents['links'][] = $file->getProperty('link');
- $fileFieldContents['alternativeTexts'][] = $file->getProperty('alternative');
+ $fileFieldContents['titleTexts'][] = $fileProperties['title'];
+ $fileFieldContents['captions'][] = $fileProperties['description'];
+ $fileFieldContents['links'][] = $fileProperties['link'];
+ $fileFieldContents['alternativeTexts'][] = $fileProperties['alternative'];
$fileFieldContents[$migrateFieldName . '_fileUids'][] = $file->getOriginalFile()->getUid();
}
foreach ($oldFieldNames as $oldFieldType => $oldFieldName) {
$row['_MIGRATED'] = TRUE;
}
+ /**
+ * Check if fieldis in type
+ *
+ * @param string $fieldName
+ * @param string $table
+ * @param array $row
+ * @return boolean
+ */
+ static protected function fieldIsInType($fieldName, $table, array $row) {
+ $fieldConfiguration = static::$migrateFields[$table][$fieldName];
+ if (empty($fieldConfiguration['typeMatch'])) {
+ return TRUE;
+ } else {
+ return in_array($row[$fieldConfiguration['typeMatch']['typeField']], $fieldConfiguration['typeMatch']['types']);
+ }
+ }
}
->method('findByRelation')
->will($this->returnValue(array()));
$dbRow = array(
+ 'CType' => 'image',
'image' => '1'
);
*/
public function imageFieldIsFilledWithPathOfImage() {
$fileReference = $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileReference', array(), array(), '', FALSE);
- $fileReference->expects($this->any())
- ->method('getProperty')
- ->will($this->returnArgument(0));
$fileReference->expects($this->any())
->method('getOriginalFile')
->will($this->returnValue($this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE)));
->method('findByRelation')
->will($this->returnValue(array($fileReference)));
$dbRow = array(
+ 'CType' => 'image',
'image' => '1'
);
\TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow($dbRow, 'tt_content');
$this->assertSame('../../path/to/file', $dbRow['image']);
}
+
+ public function conteRowsOfDifferentTypesDataProvider() {
+ $filePropertiesImage = array(
+ 'title' => 'Image',
+ 'description' => 'IMAGE DESCRIPTION',
+ );
+
+ $filePropertiesMedia = array(
+ 'title' => 'Media',
+ 'description' => 'MEDIA DESCRIPTION',
+ );
+
+ return array(
+ 'Image Element' => array(
+ array(
+ 'CType' => 'image',
+ 'image' => '',
+ 'media' => '',
+ ),
+ 'IMAGE DESCRIPTION',
+ $filePropertiesImage
+ ),
+ 'Textpic Element' => array(
+ array(
+ 'CType' => 'textpic',
+ 'image' => '',
+ 'media' => '',
+ ),
+ 'IMAGE DESCRIPTION',
+ $filePropertiesImage
+ ),
+ 'Uploads Element' => array(
+ array(
+ 'CType' => 'uploads',
+ 'image' => '',
+ 'media' => '',
+ ),
+ 'MEDIA DESCRIPTION',
+ $filePropertiesMedia
+ ),
+ );
+ }
+
+ /**
+ * @test
+ * @dataProvider conteRowsOfDifferentTypesDataProvider
+ */
+ public function migrationOfLegacyFieldsIsOnlyDoneWhenRelationFieldIsVisibleInType($dbRow, $expectedCaption, $fileProperties) {
+ $fileReference = $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileReference', array(), array(), '', FALSE);
+ $fileReference->expects($this->once())
+ ->method('getProperties')
+ ->will($this->returnValue($fileProperties));
+ $fileReference->expects($this->any())
+ ->method('getOriginalFile')
+ ->will($this->returnValue($this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE)));
+ $fileReference->expects($this->any())
+ ->method('getPublicUrl')
+ ->will($this->returnValue('path/to/file'));
+ $this->fileRepositoryMock->expects($this->any())
+ ->method('findByRelation')
+ ->will($this->returnValue(array($fileReference)));
+
+ \TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow($dbRow, 'tt_content');
+ $this->assertSame($expectedCaption, $dbRow['imagecaption']);
+ }
+
}