In our case we have a table A which contains IRRE records using table B. Inside a backend module we import an XML file to import those records for table B.
All records/data for table A is available. All data for table B is available, except the new uids/identifiers.
Based on https://docs.typo3.org/typo3cms/CoreApiReference/6.2/ApiOverview/Typo3CoreEngine/Database/ I have to set the identifier NEWxxxx for all new created records.
I'm importing a large number of records at once. Can I generate those identifiers in a loop and process all records at once or do I have to run the whole datamap-handling record by record ?
Besides the identifier, is there any field i have to set on the parent record which contains the IRRE record ?
No translations/workspaces/other relations are involved.
Thanks for your help.
The DataHandler in TYPO3 is using the following array structure to create new or update existing records - this is valid up to and including TYPO3 CMS 8:
Existing records use the integer value of the record's
uidfield, e.g.123, new records use some random but unique identifier that are prefixed withNEW, e.g.NEWa2b3c4f8created byuniqid('NEW', true)- since TYPO3 CMS 7StringUtility::getUniqueId('NEW')can and should be used for that.Generic Example
Let's assume the following records shall be created:
tt_contentsys_file_referencefor fieldtt_content.imagesys_filerecord with uid123sys_filerecord with uid234Preparing data-map
Hava a close look to
tt_content.image, this is actually defining the (new) inline references, defined by a comma separated values of new records or existing records - this could either beNEWabc,NEWdef,123,234,345orNEWabc,123,NEWdef, mixing new and existing record references.Preparing command-map
Executing DataHandler
If you need the
uidof the created records, this can be resolved from the internal DataHandler record mapping. For example, the following code resolves the newuidof the createdtt_contentrecord:Notes
Defining the references happens in the example above directly for the field
tt_content.image, which can containNEW...ids as well as existing integer ids. The behaviour for the is the same for all reference types in TYPO3:inline, for all variants (plain,foreign_field,MM)select, for all variants (plain,MM)group, for all variants (plain,MM)Passing data through
DataHandlerensures that log entries are created, and the in most cases modifications can be reverted using TYPO3's history/rollback module.Besides that, it's possible to execute mass actions - the invocation of
DataHandleris not limited to just on aggregate (thett_contentrecord in the example above). However, theNEW...ids have to be unique and must not be re-used during mass-executions to avoid side-effects.Transformed to
table_a&table_bscenarioTransforming this to the
table_aandtable_bscenario of the initial question, the$dataMapmight look like the following. Of course you have to determine which references totable_bare bound totable_a.Notes on identifiers
Identifiers like
NEWb1are kept simple intentionally - usually those identifiers are composed by prefixNEWand a (pseudo-)random hexadecimal stringabdc....The TYPO3 core is using
$id = StringUtility::getUniqueId('NEW')to create those unique identifiers. However, that also can be achieved using$id = 'NEW' . bin2hex(random_bytes(10);- identifiers just have to be unique for this particular process.