I have two content types from 4.7 cck which have a textfield called "article" and no body field. I'd like to merge these with another content type, that uses the "body" field - otherwise they're identical.

What I'm not sure about is the best way to take the information from the content_field_myfield table and put it into node_revisions. I don't need teasers (we have another text field which provides that), and not that worried about uid, although it'd be nice. The main thing is getting the data into body, and updating with the relevant title from the node table.

I should note there's about 1,800 nodes in these content types, so manual isn't an option. I think it's just be a select from with a join to node for the title, uid etc., then an insert into node_revisions with that data, but can't get my head around how it'd work.

Comments

yched’s picture

Well, this is more a question of how to correctly fill core node and node_revisions tables than a strictly cck-related question, am i right ?

I guess I'd brute-force change the node.type column to your_target_type, and copy the text field's _value and _format columns to node_revisions.body and node_revisions.format columns.

in pseudo code, something like :

SELECT n.vid, cck.field_article_value AS value, cck.field_article_format AS format FROM node n WHERE n.type = 'your_source_type' LEFT JOIN content_field_article.cck ON n.vid = cck.vid
foreach ($result as $row) {
  UPDATE node SET type = 'your_target_type' WHERE vid = $row->vid
  UPDATE node_revisions SET body = $row->value, format = $row->format WHERE vid = $row->vid
  DELETE FROM content_field_article WHERE vid = $row->vid
}
TRUNCATE TABLE cache_content

Completely untested, of course :-)

catch’s picture

Thanks for this yched, I won't be able to get this going for a couple of weeks yet, but will report back when I've got it working (or got stuck). Yes it's as much a question about how to fill those tables as cck, but I figured it was (possibly) a common issue for people who've been using it for a while.

yched’s picture

Status: Active » Fixed

OK, marking as fixed for now, then.

Anonymous’s picture

Status: Fixed » Closed (fixed)
catch’s picture

Status: Closed (fixed) » Fixed

OK so I tried to do this with db_query / db_fetch_array and got confused.

Ended up doing it with brute force SQL which turned out to be incredibly straightforward and fine for my purposes, also saved having to worry about a foreach loop through a couple thousand records.

After this you need to hide article in content types -> display, for each type that uses it, and also edit each one to use the body field.

Obviously you'd have to change content_field_article and field_article_value to whatever they are for your field.

yched thanks for your help with this!

UPDATE node_revisions, content_field_article SET node_revisions.body = content_field_article.field_article_value WHERE node_revisions.vid = content_field_article.vid;
UPDATE node_revisions, content_field_article SET node_revisions.format = content_field_article.field_article_format WHERE node_revisions.vid = content_field_article.vid;
Anonymous’s picture

Status: Fixed » Closed (fixed)