I want to move the body of around 1200 nodes for better re-usage into cck text fields with multiple values.
To this point no problem with some preparation and the following db query:

create the new field in all needed content types and name it newnotes (or change the query if you need it named differently)
and in phpmyadmin (or whatever you use for queries) insert this

INSERT INTO content_field_newnotes( vid, nid, field_newnotes_value )
SELECT vid, nid, body
FROM node_revisions

*notice that u might have to empty the table of the new field if you get the duplicate error! worked for me but ...

My Problem with this is, I need every line from the body as a new value.
Anybody with an idea how to formulate this???
thx in advance

Comments

stevenc’s picture

The MySQL query can't parse the body value in the way that you need (at least I'm not aware of how you could do that).

My solution would be to write a function that reads each node in a loop. Then, for each node parse the body field and call the insert.

Note: This is pseudo-code just to illustrate the technique.

$nodes = (results of this query) "SELECT vid, nid, body FROM node_revisions";
foreach($nodes as $node){
  $newnotes = explode("\n", trim($node->body));
  foreach($newnotes as $newnote){
    (execute) "INSERT INTO content_field_newnotes( $node->vid, $node->nid, $newnote)";
  }
}

The "explode" function in PHP converts a string into an array, based on the first argument - in this case, the newline character "\n". The "trim" function ensures that you won't have an empty value as the result of the final newline.

---------------------------------
Steven Wright

Slalom