eZ Community » Forums » eZ Publish 5 Platform » Creating content with eZ 5 API error
expandshrink

Creating content with eZ 5 API error

Creating content with eZ 5 API error

Tuesday 12 May 2015 5:01:27 pm - 5 replies

Hi there,

I'm trying to create content following this example on the cookbook :

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

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
- To be recreated in a eZ 5 Database.

Thanks.

Modified on Tuesday 12 May 2015 5:26:49 pm by Task Mikaël

Wednesday 13 May 2015 10:58:52 am

Anyone ? it would really help !

For more info : it is completely weird ... the script is passing "sometimes" through 5 objets and then crashes, but most of the time it is after the first object creation. I guess I have to "flush" some var, but i don't know which one.

Thanks !

Thursday 14 May 2015 6:00:23 am

Hello Task,

I'm curious, why you are mixing legacy code within new stack code, 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

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

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. Which also means that their is no need to use 'eZContentObject::fetch' even if it was within a legacy enclosure.

If all your doing is copying (via content object recreation) why not follow this new stack example instead?

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

Apologies if I have miss-understood your desired use case, it is very late for me this evening big-smile.gif Emoticon

I hope this helps!

Cheers,
Heath

Thursday 14 May 2015 4:21:32 pm

Do you have a full stack trace for this?

Sunday 17 May 2015 11:49:59 am

Hi Task,

I had quite a similar issue not long ago and in my case it was the $contentService->createContent() "failing".

I'd recommend wrapping the code inside the foreach() in a try/catch and looking at the eventual exception(s) thrown for more clues. (nice example with transaction here: http://share.ez.no/forums/ez-publish-5-platform/how-to-handle-errors/comment85789 )

In my case the issue was triggered by aborting the command "at the wrong time" leaving "stray" drafts with remoteIds I was trying to use at a later run. Cleaning up my drafts was a quick fix helping me move forward.

--Jørn
 

Monday 18 May 2015 9:33:27 am

Hi,

Thanks guys for answers.

The reason why i'm using the Legacy code is because the new stack (as you said few weeks ago) is not fit to have multiple instance of database, like setInstance(). My website (import/export app) has to be connected to 3 databases and copy "some data" that are needed.

For this part, I will try to get rid of the legacy code, or else i will try to include it as you mentioned.

Anyway, thanks for you help.

I will try to put more info (exceptions, stack trace ...) for future posts.

EDIT : And as I said in my second post, the first object is create correctly, sometimes 5 objects can be created, but the command is crashing.

Cheers.

Modified on Monday 18 May 2015 1:12:15 pm by Task Mikaël

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from