This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » Developer » Import object from a serialized...

Import object from a serialized contentObjet

Import object from a serialized contentObjet

Wednesday 15 October 2014 1:50:51 am - 8 replies

Hi all,
I'm trying to import a ContentObject after serialized it.
The goal is to synchronise specifics objects on 2 differents servers and to change the owner when importing on server 2:

On first server :

 // Fetching my object
$object = eZContentObject::fetch( $objectID );
// Just to have a log
var_dump( $object ); // Give me an eZContentObject
// Store objet in a file
eZFile::create("MyFile", "/tmp/", serialize($object));

On second server :

// Import objet from file
$Object =  unserialize(file_get_contents("/tmp/MyFile")); // That's work find, I've  got something looking like an eZContentObject.
var_dump( $Object ); // Give me a the same eZContentObject as in server 1, well that's smell nice...
// If I tried to change the owner :
$l_OBJ_User = eZUser::fetchByName( "MyUserName" );
$Object->setAttribute('OwnerID', $l_OBJ_User->attribute( 'contentobject_id' ));
var_dump( $Object ); // Give me a the same eZContentObject as in server 1 ( Owner have no been changed ! ), Mmmmm not so nice !
$Object->addLocation(2);    // Attach object to the root's object
//.... but when I'm trying to store it
$Object->store();    // ... nothing happens ( The object is not visible from the Back office ).

How can I import a serialized object ? Is it possible ? Did I miss something ?
Any help or exemple will be nice.


Modified on Wednesday 15 October 2014 1:57:15 am by Peretjatko Alexandre

Wednesday 15 October 2014 3:18:03 am

Hello Peretjatko,

I am in a rush to get to dinner but you prolly should publish the object version (hint use the version system too to keep track of your changes).

Here are some links (bad examples i know..)

This is just what i could find quickly via google:


Let me know if this helps, I'll try to post again once I hear back from you or when I get home again.

Also eZContentObject class is different from eZContentTreeNode class :\


I hope this helps


Wednesday 15 October 2014 5:05:02 am

Hello Peretjatko,

I'm back. Here are couple more notes on thoughts I had during dinner.

1. In your owner ID code example you should try using this instead as this has just been tested as a working solution: 

$ContentObject->setAttribute( 'owner_id', $UserObject->attribute( 'contentobject_id' ) );

2. You prolly do not want to use eZContentObject->addLocation(2) as this does not create a main node location only a secondary location. Use the following tested working solution instead:

$object->createNodeAssignment( 2, true );
$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $object->attribute( 'id' ),
                                                                                 'version' => $object->attribute('current_version') ) );

3. Remember that eZContentObject is not all inclusive so when you do what your suggesting your loosing a -whole lot of related data- (stored in other tables; like content object attribute data) and it's generally the wrong way to do syndication because it will result in database corruption on a grand scale.

I will wait to hear from you more about just what your trying to do before making more suggestions.

I hope this helps!


Modified on Wednesday 15 October 2014 7:53:19 am by // Heath

Wednesday 15 October 2014 10:13:29 am

Hello Heath,

Many thanks for your answers, unfortunately it does not help my problem.

Indeed, when I try :

eZOperationHandler::execute ....

The cli give me a "Fatal error:  Call to a member function translations() on a non-object" and that point me again on my first problem, When I trie to import my object from a serialized one, my contenObject is somewhere in the ezpublish system but "alone", not attached to the others nodes, and I'm not sure it is a "real" EzContentObject.

By the way, I'm concerned with your remarks 3 ... I guess you are right : if I got so many problems to import my object with my solution that means it's not the good one and I have to thinking about an other way to achieve my goal.

Let me explain a bit longer my problem, maybe that can help : I have to synchronise content between 2 servers. Contents can be Folders, Articles, or specifics objects". Both servers have the same treenodes ( only names can be changed, that means that they both have the same nodes IDs ). -> OK, versions are not the same ( due to name's change on some objects ).

Well, my first solution was to dump ContentObject (with the serialize PHP function ) from server 1 and to import it in server 2 (with unserialize). But.... it doesn't work !

Just before to start in an other direction : what do you think about :

  • On server 1 : dump all the attibutes of my object (with my serialize function, I love the serialize solution because I got a hashcode hand-check to download the dump file from server 1 to server 2, and that drive me crazy to abandon  ).
  • On server 2 : Import all the attributes and as params, build a new object to inject in ez-Publish Content as a real EZContentObject.

Any suggestions or corrections will be great.



Modified on Wednesday 15 October 2014 10:32:46 am by Peretjatko Alexandre

Wednesday 15 October 2014 11:08:54 am

Hello Peretjatko,

I think you should seriously try this ..

I hope this helps (not awake yet blunk.gif Emoticon


Modified on Wednesday 15 October 2014 11:11:20 am by // Heath

Wednesday 15 October 2014 5:09:57 pm

Nice extension indeed !

I've forget to said : my ezpublish version is 4.4, that's too bad... ( the stagging extension work with version 5.2 ). And ... no, I can't upgrade yet.

Well, many thanks for the link ! I will examinate the source code to get a solution for mine.

Wednesday 15 October 2014 11:36:29 pm

Hello Peretjatko,

Unlike most software systems .. eZ Publish upgrades for the most part bring new features, bug fixes and other improvements and not new problems.

So what I'm saying is as long as your not kernel hacking eZ Publish. eZ Publish upgrades are different from almost any other software upgrade I've ever seen. eZ Publish upgrades are painless, quick and reliable to do.

I strongly recommend you try doing a 'direct upgrade'. All you have to do is move your settings, custom extensions and var directory into the new version, run the sql upgrades and php upgrade scripts and your done.

It's so simple ... there is no good reason not to do the upgrade. Right now you are missing out on many many years of improvements and bug fixes, we are talking thousands upon thousands.

No one should be running 4.4 anymore :\

Just think, in less than 1 hour you could be running the latest stable version and have full compatibility with ezcontentstaging extension!

I hope this helps convince you.


Modified on Wednesday 15 October 2014 11:37:19 pm by // Heath

Thursday 16 October 2014 9:24:49 am

Hi Heath,

Yes I understand your point of view, but trust me this server is a big one ( more than 70 Go of data, and more than 10 000 objects + around 50 differents version of them ). So I'm not sure that the upgrade will take me only 1 hour... specially becaus it takes more than a week to bring it to version 4.4... Maybe 4.4 -> 5.2 will be easier, but at this time I prefer to deal will this.

But I will trie on a "developpement place" the upgrade just to have my own opinion of the painless happy.gif Emoticon



Friday 17 October 2014 3:35:31 am


But, just to remind you ... You only have to do -one- upgrade, -one- time, to the latest community release.

You do not need to do per release or per version upgrades (multiple upgrades; multiple times in a row).

Doing the 'direct upgrade' will save you a lot of time.

I hope this helps.



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

36 542 Users on board!

Forums menu

Proudly Developed with from