【问题标题】:eZ Publish 5 API - CreateContent Command erroreZ Publish 5 API - CreateContent 命令错误
【发布时间】:2015-05-13 07:54:05
【问题描述】:

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

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

目前我只是尝试创建“文件夹”内容,执行脚本时出现以下错误:

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

代码如下:

     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 数据库中重新创建。

谢谢。

【问题讨论】:

    标签: php symfony command ezpublish


    【解决方案1】:

    您在新堆栈代码中混合旧代码,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 Publish 数据兼容,这意味着新堆栈代码可以读取(和更改)使用 eZ Publish 创建的数据库内容,因为它们在新堆栈中完全没有区别。这也意味着他们不需要使用“eZContentObject::fetch”,即使它位于旧版附件中。

    PS。此主题是交叉发布的:http://share.ez.no/forums/ez-publish-5-platform/creating-content-with-ez-5-api-error

    【讨论】:

    • 谢谢,我会找到另一种方式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-02
    • 1970-01-01
    • 2018-05-15
    • 1970-01-01
    • 1970-01-01
    • 2018-02-03
    • 2017-09-08
    相关资源
    最近更新 更多