eZ Publish 5 API - CreateContent 命令错误

eZ Publish 5 API - CreateContent Command error

我正在尝试按照食谱上的这个示例创建内容:

https://github.com/ezsystems/CookbookBundle/blob/master/Command/CreateContentCommand.php

目前我只是想创建 'folder' 内容,但在执行脚本时出现以下错误:

PHP 致命错误:在第 53[=36= 行 /vagrant/application/ezpublish_legacy/kernel/search/plugins/ezsearchengine/ezsearchengine.php 中的非对象上调用成员函数 attribute() ]

这是代码:

     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);

是我检查堆栈跟踪时出现问题的原因。

更多信息:

  • 对象是从 eZ 4 数据库中获得的
  • 将在 eZ 5 数据库中重新创建。

谢谢。

您正在将遗留代码混合到新的堆栈代码中,回复:'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 Publish 数据兼容,这意味着新堆栈代码可以读取(和更改)使用 eZ Publish 创建的数据库内容,因为它们在新堆栈中完全没有区别。这也意味着他们不需要使用 'eZContentObject::fetch',即使它在旧版机箱中也是如此。

PS。此线程交叉发布自:http://share.ez.no/forums/ez-publish-5-platform/creating-content-with-ez-5-api-error