我已将Silverstripe网站从3.x升级到4.x.
3.x正在使用Multilingual进行翻译,现在是4.x我用Silverstripe Fluent模块取代了Multilingual,但我想知道如何将数据(已翻译的字段)导入到具有Fluent的新系统中。
更确切地说,我想用编程方式更新SiteTree_Localised表和翻译的数据
$record = SiteTree_Localised::get()->filter(array(
'RecordID' => 16,
'Locale' => 'de_DE'
))->first();
$record->Title = 'Some title';
$record->write();
但是这不起作用,因为SiteTree_Localised对象不存在?我如何更新以上记录?
SiteTree_Localised
数据库表不能通过ORM直接访问,但是在Fluent的ORM操作下被包含在钩子下面。您可以通过更改“FluentState”来访问和修改此表中的记录,然后像在SilverStripe中一样编写记录。
这是您在SilverStripe 4中的特定Fluent上下文中编写对象的方法:
FluentState::singleton()->withState(function (FluentState $newState) {
$newState->setLocale('de_DE');
$record = SiteTree::get()->byID(16);
$record->Title = 'Some title';
$record->write();
});
您可以在循环(例如数据转储)中执行此操作,并将您需要的数据通过use ($data, $locale)
传递给withState回调。
还有一个BuiltTask for migrating from translatable to fluent不会直接帮助你,但可能会提供一些见解。