eZ Community » Forums » eZ Platform » Change content types
expandshrink

Change content types

Change content types

Tuesday 22 March 2016 1:12:52 pm - 2 replies

Is there anyway to change an existing content item's content type? The initial ezplatform creates the homepage as a folder content type. If I delete it to create a new home page based off a content type I created then everything breaks. I want to create my own home page content type and replace what is installed out of the box. Any help would be appreciated. 

Tuesday 29 March 2016 12:40:15 pm

In the old legacy admin there was a function to switch the content objects of existing tree nodes (locations). I've not found a similar function in the new platform admin. You could try to hack it manually in the database:

 

  1. Make a backup of your database (this is not just an empty warning, errors in the content tree will brake your installation!)
  2. In the admin UI, create your new startpage directly located under the homepage folder. In the details tab remember the "Content id" of your new page.
  3. Go to the database and take a look at the "ezcontentobject_tree" table. Look for the row with node_id=2 (this is the home location), and remember the contentobject_id of this row (most likely it will have a contentobject_id of 1).
     select contentobject_id from ezcontentobject_tree where node_id = 2
  4. Look for a 2nd row with "contentobject_id=<content_id_from_point_2>" and remember it's node_id
     select node_id from ezcontentobject_tree where contentobject_id = <content_id_from_point_2>
  5. Now flip the contentobject_id values of those two rows:
    update ezcontentobject_tree set contentobject_id = <contentobject_id_from_point_2> where node_id=2
    update ezcontentobject_tree set contentobject_id = <contentobject_id_from_point_3> where node_id=<node_if_from_point_4>  
  6. Now clear the cache (See https://doc.ez.no/display/TECHDOC/Cache+clearing) - Most likley this will do it:
     php -d memory_limit=-1 app/console --env=prod cache:clear
  7. Your content tree tree should now be updated and show the new startpage. Either delete the old home folder or - if you want to keep the old home folder - edit and save the old home folder so the node_path is updated in the database,

Modified on Tuesday 29 March 2016 12:41:22 pm by Reinhard Hutter

Monday 04 April 2016 1:19:59 am

Hi Travis,

the by Reinhard proposed way is ok in and of itself. Though this is advanced stuff to work with.

To keep the consistency, I'd suggest to build kind of a "migration" to handle such tasks as long as the new UI does not support this.
The public-api does more than just give you the tools you need.

While using the public-api you can ensure that you don't wreck your system into a wall. At least not that easily.

I have currently embedded all my classes, sections and basically everything my system needs into a "script" to take care of it (on initial setup).

This way you can actually automate the whole process (an be sure that it works, ones it does) that Rainhard explained to you. You will probably learn a thing or two about the public-api, which you will encounter anyhow.

For your needs

1) you would require to create the content you want as your root-page.
2) use the swapLocation-method of the location-service, using location-2 for the first and your new location for the second parameter.

Thats actually all you need.

If you want to run the script again, and make sure it does not break anything, you might want to set some remote-ids to check, if the script already ran. Or something like that.

Hope this helps with your task.

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from