简体   繁体   English

eZ Publish 5 API-CreateContent命令错误

[英]eZ Publish 5 API - CreateContent Command error

I'm trying to create content following this example on the cookbook : 我正在尝试按照食谱上的这个示例创建内容:

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

For the moment i'm just trying to create 'folder' content, i have the following error while executing the script : 目前,我只是尝试创建“文件夹”内容,执行脚本时出现以下错误:

PHP Fatal error: Call to a member function attribute() on a non-object in /vagrant/application/ezpublish_legacy/kernel/search/plugins/ezsearchengine/ezsearchengine.php on line 53 PHP致命错误:在第53行的/vagrant/application/ezpublish_legacy/kernel/search/plugins/ezsearchengine/ezsearchengine.php中的非对象上调用成员函数attribute()

Here is the code : 这是代码:

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

The last line : 最后一行:

$content = $contentService->publishVersion($draft->versionInfo);

is causing the problem when i check the stack trace. 当我检查堆栈跟踪时导致问题。

More info : 更多信息 :

  • The Object is obtained from an eZ 4 Database 该对象是从eZ 4数据库获得的
  • To be recreated in a eZ 5 Database. 在eZ 5数据库中重新创建。

Thanks. 谢谢。

You are mixing legacy code within new stack code, Re: 'eZContentObject::fetch'. 您正在将旧代码混入新的堆栈代码中,例如Re:'eZContentObject :: fetch'。

I do not think this is necessary or correct as you seem to be running legacy code outside of a legacy context. 我认为这不是必需的或正确的,因为您似乎在遗留上下文之外运行遗留代码。 You should be able to write your code without using legacy code. 您应该能够在不使用旧版代码的情况下编写代码。 From what code you have shared, I do not see any need for legacy code and if I were you I would not use legacy code at all for this task. 从您共享的代码来看,我看不到需要任何遗留代码,如果您是我,则根本不会使用遗留代码来完成此任务。

If you insist on using legacy code within new stack code you must only run it within a legacy kernel enclosure or else a great many unpredictable things may go wrong or plain not work at all. 如果你坚持使用中的新栈代码遗留代码必须只有一个旧版的内核机箱内运行,否则一个伟大的很多不可测的事情可能出错或纯根本无法工作。

https://doc.ez.no/display/EZP/Legacy+code+and+features#Legacycodeandfeatures-Runninglegacycode https://doc.ez.no/display/EZP/Legacy+code+and+features#Legacycodeandfeatures-Runninglegacycode

This I think is the line which is erroring that you made reference to, https://github.com/ezsystems/ezpublish-legacy/blob/master/kernel/search/plugins/ezsearchengine/ezsearchengine.php#L53 我认为这是您提到的错误行, https://github.com/ezsystems/ezpublish-legacy/blob/master/kernel/search/plugins/ezsearchengine/ezsearchengine.php#L53

I would also no longer trust the database you are running the code you shared. 我也不再相信正在运行共享代码的数据库。 You should drop the database as very likely corrupt, install a fresh copy from production backups, rewrite your code to not use legacy code since it's not required and try again. 您应该将数据库删除为极有可能损坏的数据库,从生产备份中安装新副本,重写代码以不使用遗留代码,因为这不是必需的,然后重试。

Also remember that eZ Platform is Data Compatible with eZ Publish meaning that the new stack code can read (and alter) database content created with eZ Publish since their is no difference at all in the new stack. 还请记住,eZ平台与eZ Publish具有数据兼容性,这意味着新的堆栈代码可以读取(和更改)使用eZ Publish创建的数据库内容,因为它们在新堆栈中完全没有区别。 Which also means that their is no need to use 'eZContentObject::fetch' even if it was within a legacy enclosure. 这也意味着他们无需使用“ eZContentObject :: fetch”,即使它在旧式机箱中也是如此。

PS. PS。 This thread is cross-posted from: http://share.ez.no/forums/ez-publish-5-platform/creating-content-with-ez-5-api-error 该线程交叉发布于: http : //share.ez.no/forums/ez-publish-5-platform/creating-content-with-ez-5-api-error

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM