我试图按照菜谱上的示例创建内容:
https://github.com/ezsystems/CookbookBundle/blob/master/Command/CreateContentCommand.php
目前,我只是尝试创建“文件夹”内容,在执行脚本时出现了以下错误:
/vagrant/application/ezpublish_legacy/kernel/search/plugins/ezsearchengine/ezsearchengine.php中的致命错误:调用第53行中非对象的成员函数属性()
以下是代码:
foreach ($tabPreImportData as $object) {
$output->writeln('<info> Object ID: ' . $object['id_object'] . '</info>');
$objectToMigrate = eZContentObject::fetch($object['id_object']);
$contentType = $contentTypeService->loadContentTypeByIdentifier('folder');
$contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
foreach ($objectToMigrate->dataMap() as $attrIdentifier => $attrValue) {
$contentCreateStruct->setField($attrIdentifier, $attrValue->DataText);
}
$locationCreateStruct = $locationService->newLocationCreateStruct(2);
// create a draft using the content and location create struct and publish it
$draft = $contentService->createContent($contentCreateStruct, array($locationCreateStruct));
$content = $contentService->publishVersion($draft->versionInfo);
}最后一行:
$content = $contentService->publishVersion($draft->versionInfo);在我检查堆栈跟踪时会导致问题。
更多信息:
谢谢。
发布于 2015-05-20 13:50:39
您正在将遗留代码混合到新的堆栈代码中,Re:'eZContentObject::fetch‘。
我不认为这是必要的或正确的,因为您似乎正在运行遗留环境之外的遗留代码。您应该能够不使用遗留代码来编写代码。从您所共享的代码中,我认为不需要任何遗留代码,如果我是您,我将根本不会在此任务中使用遗留代码。
如果您坚持在新的堆栈代码中使用遗留代码,那么必须只在遗留内核外壳中运行它,否则许多不可预测的事情可能会出错或简单,根本无法工作。
https://doc.ez.no/display/EZP/Legacy+code+and+features#Legacycodeandfeatures-Runninglegacycode
我认为这是您所引用的错误行,https://github.com/ezsystems/ezpublish-legacy/blob/master/kernel/search/plugins/ezsearchengine/ezsearchengine.php#L53
我也不再信任正在运行您共享的代码的数据库。您应该删除数据库非常可能损坏,从生产备份中安装一个新的副本,重写您的代码以避免使用遗留代码,因为它不是必需的,然后再试一次。
还请记住,eZ平台与eZ发布兼容数据,这意味着新堆栈代码可以读取(和更改)用eZ发布创建的数据库内容,因为它们在新堆栈中没有任何区别。这也意味着它们不需要使用'eZContentObject::fetch‘,即使它在遗留的外壳中。
PS。这个线程是从:http://share.ez.no/forums/ez-publish-5-platform/creating-content-with-ez-5-api-error交叉发布的。
https://stackoverflow.com/questions/30208844
复制相似问题