Skip to content
Snippets Groups Projects
Commit 99ddf6dc authored by Alexander Stehlik's avatar Alexander Stehlik Committed by Stefan Neufeind
Browse files

[BUGFIX] Manipulation of file field migration config

This patch introduces new methods to the FrontendContentAdapterServer
that allow the manipulation of the file field migration configuration.
It is now possible to add additional (content) types for which the
migration should be active and to add custom migration configurations.

Releases: 6.2
Resolves: #46067
Documentation: #56365
Change-Id: Ibc23be8a414192c8795d9bb4f09316cf608e240b
Reviewed-on: https://review.typo3.org/23360
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Tested-by: Tom Peters
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
parent 0624ab85
Branches
Tags
No related merge requests found
......@@ -31,6 +31,19 @@ namespace TYPO3\CMS\Core\Resource\Service;
*/
class FrontendContentAdapterService {
/**
* Array containing all keys that are allowed in the migrateFields array.
*
* @var array
*/
static protected $availableMigrationFields = array(
'paths',
'titleTexts',
'captions',
'links',
'alternativeTexts'
);
/**
* The name of the table
*
......@@ -132,6 +145,53 @@ class FrontendContentAdapterService {
$row['_MIGRATED'] = TRUE;
}
/**
* Registers an additional record type for an existing migration configuration.
*
* For use in ext_localconf.php files.
*
* @param string $table Name of the table in the migration configuration
* @param string $field Name of the field in the migration configuration
* @param string $additionalType The additional type for which the migration should be applied
* @throws \RuntimeException
* @return void
*/
static public function registerAdditionalTypeForMigration($table, $field, $additionalType) {
if (!isset(static::$migrateFields[$table][$field]['__typeMatch'])) {
throw new \RuntimeException('Additional types can only be added when there is already an existing type match configuration for the given table and field.', 1377600978);
}
self::$migrateFields[$table][$field]['__typeMatch']['types'][] = $additionalType;
}
/**
* Registers an additional field for migration.
*
* For use in ext_localconf.php files
*
* @param string $table Name of the table in the migration configuration
* @param string $field Name of the field in the migration configuration
* @param string $migrationField The file property that should be migrated, see $availableMigrateFields for available settings
* @param string $oldFieldName The name of the field in which the file property should be available
* @param string $typeField Optional field that switches the record type, will only have an effect if $types array is provided
* @param array $types The record types for which the migration should be active
* @throws \InvalidArgumentException
*/
static public function registerFieldForMigration($table, $field, $migrationField, $oldFieldName, $typeField = NULL, array $types = array()) {
if (array_search($migrationField, static::$availableMigrationFields) === FALSE) {
throw new \InvalidArgumentException('The value for $migrationField is invalid. Valid values can be found in the $availableMigrationFields array.', 1377600978);
}
self::$migrateFields[$table][$field][$migrationField] = $oldFieldName;
if (isset($typeField) && (count($types) > 0)) {
self::$migrateFields[$table][$field]['__typeMatch']['types'] = $types;
self::$migrateFields[$table][$field]['__typeMatch']['typeField'] = (string)$typeField;
}
}
/**
* Check if fieldis in type
*
......
......@@ -158,4 +158,142 @@ class FrontendContentAdapterServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCa
$this->assertSame($expectedCaption, $dbRow['imagecaption']);
}
/**
* @test
*/
public function registerAdditionalTypeForMigrationAddsTypeToArray() {
$migrateFields = array(
'testtable' => array(
'testfield' => array(
'paths' => 'oldfield',
'__typeMatch' => array(
'typeField' => 'mytypefield',
'types' => array('mytype'),
)
)
),
);
$expectedResult = array(
'testtable' => array(
'testfield' => array(
'paths' => 'oldfield',
'__typeMatch' => array(
'typeField' => 'mytypefield',
'types' => array('mytype', 'mytype2'),
)
)
),
);
$frontendContentAdapterService = $this->getAccessibleFrontendContentAdapterServiceWithEmptyConfiguration();
$frontendContentAdapterService->_setStatic('migrateFields', $migrateFields);
$frontendContentAdapterService->registerAdditionalTypeForMigration('testtable', 'testfield', 'mytype2');
$this->assertEquals($expectedResult, $frontendContentAdapterService->_getStatic('migrateFields'));
}
/**
* @test
* @expectedException \RuntimeException
*/
public function registerAdditionalTypeForMigrationThrowsExceptionIfNoConfigurationAvailable() {
$frontendContentAdapterService = $this->getAccessibleFrontendContentAdapterServiceWithEmptyConfiguration();
$frontendContentAdapterService->registerAdditionalTypeForMigration('testtable', 'testfield', 'mytype2');
}
/**
* @test
* @expectedException \RuntimeException
*/
public function registerAdditionalTypeForMigrationThrowsExceptionIfNoTypeConfigurationAvailable() {
$migrateFields = array(
'testtable' => array(
'testfield' => array(
'paths' => 'oldfield',
)
),
);
$frontendContentAdapterService = $this->getAccessibleFrontendContentAdapterServiceWithEmptyConfiguration();
$frontendContentAdapterService->_setStatic('migrateFields', $migrateFields);
$frontendContentAdapterService->registerAdditionalTypeForMigration('testtable', 'testfield', 'mytype2');
}
/**
* @test
* @dataProvider registerFieldForMigrationAddsCorrectConfigurationDataProvider
*/
public function registerFieldForMigrationAddsCorrectConfiguration($expectedResult, $table, $field, $migrationFields, $oldFieldName, $typeField, $types) {
$frontendContentAdapterService = $this->getAccessibleFrontendContentAdapterServiceWithEmptyConfiguration();
$frontendContentAdapterService::registerFieldForMigration($table, $field, $migrationFields, $oldFieldName, $typeField, $types);
$newConfiguration = $frontendContentAdapterService->_getStatic('migrateFields');
$this->assertEquals($expectedResult, $newConfiguration);
}
/**
* Data provider for registerFieldForMigrationAddsCorrectConfiguration
*
* @return array
*/
public function registerFieldForMigrationAddsCorrectConfigurationDataProvider() {
return array(
'table without type column' => array(
array(
'tablename' => array(
'newfield' => array(
'paths' => 'oldfield',
),
),
),
'tablename',
'newfield',
'paths',
'oldfield',
NULL,
array()
),
'table with type column' => array(
array(
'tablename' => array(
'newfield' => array(
'paths' => 'oldfield',
'__typeMatch' => array(
'typeField' => 'typecolumn',
'types' => array('firsttype'),
)
),
),
),
'tablename',
'newfield',
'paths',
'oldfield',
'typecolumn',
array('firsttype'),
),
);
}
/**
* @test
* @expectedException \InvalidArgumentException
*/
public function registerFieldForMigrationThrowsExceptionForInvalidMigrationField() {
$frontendContentAdapterService = $this->getAccessibleFrontendContentAdapterServiceWithEmptyConfiguration();
$frontendContentAdapterService::registerFieldForMigration('table', 'field', 'invalidfield', 'oldfield');
}
/**
* Creates an accessible mock of the FrontendContentAdapterService class
* and sets the migrateFields property to an empty array.
*
* @return \TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
*/
protected function getAccessibleFrontendContentAdapterServiceWithEmptyConfiguration() {
$frontendContentAdapterService = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Resource\\Service\\FrontendContentAdapterService', array('dummy'));
$frontendContentAdapterService->_setStatic('migrateFields', array());
return $frontendContentAdapterService;
}
}
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