Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在TYPO3中使用DataHandler创建内联记录(IRE)?_Typo3_Typo3 6.2.x_Datahandler - Fatal编程技术网

如何在TYPO3中使用DataHandler创建内联记录(IRE)?

如何在TYPO3中使用DataHandler创建内联记录(IRE)?,typo3,typo3-6.2.x,datahandler,Typo3,Typo3 6.2.x,Datahandler,在本例中,我们有一个表a,其中包含使用表B的IRE记录。在后端模块中,我们导入一个XML文件以导入表B的这些记录 表A的所有记录/数据均可用。 除新的UID/标识符外,表B的所有数据均可用 基于此,我必须为所有新创建的记录设置标识符NEWxxxx 我正在一次导入大量记录。我可以在循环中生成这些标识符并一次处理所有记录,还是必须逐个记录运行整个datamap处理记录 除了标识符之外,在包含IRE记录的父记录上是否还需要设置任何字段 不涉及翻译/工作区/其他关系 感谢您的帮助。TYPO3中的Data

在本例中,我们有一个表a,其中包含使用表B的IRE记录。在后端模块中,我们导入一个XML文件以导入表B的这些记录

表A的所有记录/数据均可用。 除新的UID/标识符外,表B的所有数据均可用

基于此,我必须为所有新创建的记录设置标识符
NEWxxxx

我正在一次导入大量记录。我可以在循环中生成这些标识符并一次处理所有记录,还是必须逐个记录运行整个datamap处理记录

除了标识符之外,在包含IRE记录的父记录上是否还需要设置任何字段

不涉及翻译/工作区/其他关系


感谢您的帮助。

TYPO3中的DataHandler正在使用以下数组结构创建新记录或更新现有记录-这在TYPO3 CMS 8之前有效:

$dataMap = ['<table-name>' => [
    '<record-uid>' => ['<field-name>' => '<field-value>']
];

准备数据映射 仔细看一下
tt_content.image
,这实际上是定义(新的)内联引用,由新记录或现有记录的逗号分隔值定义-这可以是
NEWabc,NEWdef
123234345
NEWabc,123,NEWdef
,混合了新的和现有的记录引用

$dataMap = [
  'tt_content' => [
    'NEW58d5079c8741c822627844' => [
      'title' => 'My new content element',
      'bodytext' => 'Look at the following images...',
      'CType' => 'textpic',
      // $fileRefId1st & $fileRefId2nd, the sorting order is defined by this as well
      'image' => 'NEW58d506f3cd0c4159344142,NEW58d50714c1226092562338',
    ],
  ],
  'sys_file_reference' => [
    'NEW58d506f3cd0c4159344142' => [
      'uid_local' => 123,
      'title' => 'Image #123',
    ],
    'NEW58d50714c1226092562338' => [
      'uid_local' => 234,
      'title' => 'Image #234',
    ],
  ]
];
准备命令映射 执行数据处理程序 如果需要所创建记录的
uid
,可以通过内部DataHandler记录映射来解决。例如,以下代码解析所创建的
tt_内容
记录的新
uid

// fetching the actual record ID, e.g. results in 333
$ttContentId = $dataHandler->substNEWwithIDs['NEW58d5079c8741c822627844'];
笔记 在上面的示例中,直接为字段
tt_content.image
定义引用,该字段可以包含
NEW…
ID以及现有整数ID。对于类型3中的所有引用类型,其行为相同:

  • TCA类型
    内联
    ,适用于所有变体(普通,
    外来字段
    MM
  • TCA类型
    选择
    ,适用于所有车型(普通,
    MM
  • TCA类型
    ,适用于所有变体(普通,
    MM
通过
DataHandler
传递数据可以确保创建日志条目,并且在大多数情况下,可以使用TYPO3的历史记录/回滚模块还原修改

除此之外,还可以执行大量操作,
DataHandler
的调用不仅限于聚合(上面示例中的
tt_content
记录)。但是,
新…
ID必须是唯一的,并且在大规模执行期间不得重复使用,以避免副作用

转换为
表a
表b
场景 将其转换为初始问题的
表a
表b
场景,
$dataMap
可能如下所示。当然,您必须确定对
表b
的哪些引用绑定到
表a

$dataMap = [
  // existing records of table_a, thus using the real ids
  'table_a' => [
    '11' => [ 'reference_field' => 'NEWb1,NEWb2' ],
    '22' => [ 'reference_field' => 'NEWb3,NEWb4' ],
    '33' => [ 'reference_field' => 'NEWb5,NEWb6' ],
  ],
  // new records to be references for table_b, thus using NEW... ids
  'table_b' => [
    'NEWb1' => [ ... field values of this particular table_b record ... ],
    'NEWb2' => [ ... field values of this particular table_b record ... ],
    'NEWb3' => [ ... field values of this particular table_b record ... ],
    'NEWb4' => [ ... field values of this particular table_b record ... ],
    'NEWb5' => [ ... field values of this particular table_b record ... ],
    'NEWb6' => [ ... field values of this particular table_b record ... ],
  ],
];
  
关于标识符的说明 像
NEWb1
这样的标识符故意保持简单-通常这些标识符由前缀
NEW
和(伪)随机十六进制字符串
abdc…
组成


TYPO3核心用于创建这些唯一标识符。然而,这也可以通过使用
$id='NEW'来实现。bin2hex(随机字节(10)
-标识符对于这个特定的过程必须是唯一的。

您不必逐个记录创建数据记录,但是对于大规模执行,您必须确保这些
新的…
ID是唯一的,并且不会重复用于不同的记录数据。感谢您的彻底编写!在v9中,我必须用更多数据填充sys\u文件参考:
['table\u local'=>'sys\u file','uid\u local'=>$\u file->getUid(),'tablenames'=>'tx\u slider\u domain\u model\u layer','uid\u foreign'=>$\u newL',fieldname'=>'media','pid'=>1,]
-uid\u local在我的例子中是不够的。如果标识符有下划线,它就不起作用。因此,例如
NEW\u b\u 1
不起作用,但是
NEWb1
很好。
NEW\u b\u 1
等都是示例-如前所述,这些值必须是唯一的,并使用
StringUtility::getUniqueId('NEW')生成
。无论如何,我已经删除了下划线,并添加了另一个关于标识符的注释部分。。。
$dataHandler = new \TYPO3\CMS\Core\DataHandling\DataHandler();
$dataHandler->start($dataMap, $commandMap);
$dataHandler->process_datamap();
// $dataHandler->process_cmdmap(); // if $commandMap should be processed as well
// fetching the actual record ID, e.g. results in 333
$ttContentId = $dataHandler->substNEWwithIDs['NEW58d5079c8741c822627844'];
$dataMap = [
  // existing records of table_a, thus using the real ids
  'table_a' => [
    '11' => [ 'reference_field' => 'NEWb1,NEWb2' ],
    '22' => [ 'reference_field' => 'NEWb3,NEWb4' ],
    '33' => [ 'reference_field' => 'NEWb5,NEWb6' ],
  ],
  // new records to be references for table_b, thus using NEW... ids
  'table_b' => [
    'NEWb1' => [ ... field values of this particular table_b record ... ],
    'NEWb2' => [ ... field values of this particular table_b record ... ],
    'NEWb3' => [ ... field values of this particular table_b record ... ],
    'NEWb4' => [ ... field values of this particular table_b record ... ],
    'NEWb5' => [ ... field values of this particular table_b record ... ],
    'NEWb6' => [ ... field values of this particular table_b record ... ],
  ],
];