Site visitors seeing your ugly error messages on the screen (along with details of your Drupal installation path)? Once your site goes from dev to launch, you probably want to have errors recorded in the log but not splashed across the screen. Head to the handy Error Reporting settings found at admin/settings/error-reporting.
How to change a node's type?
Hide your eyes, conservatives: it's a node-change operation, the shocking switch from Blog Entry to Page, or Story to Review, whatever your desires demand. Call it a miracle or call it a travesty, modern Drupal science makes it possible... and seductively easy.
I'll answer this question as quickly as I ask it – because I just tested it out while moving Drupally questions of various breed into a single node type on this site, the node type called "Drupal Questions" I created for my Question Bank. (It's a nice CCK-created node type with fields for the question, for the answer if available, and for a related URL.)
I had an old blog entry on a certain Drupal puzzle, and thought that node should be reworked into a Drupal Question. I was prepared to simply copy its content into a brand new node. But lo, that blog entry had a couple of comments, and I'd hate to lose those. How would I also move the comments from the old node to the new node I'd be creating? I dunno.
Hmm, a better idea: instead of making a new node, how about transforming the old blog entry node into a new type? I seemed to recall a module claiming that transfigurational wherewithal...
And here it is: Nodetype. http://drupal.org/project/nodetype
I downloaded the module and, before touching anything else, backed up my site database! That done, I installed Nodetype. It offers no admin options, and only shows up when you edit a node: you see a simple drop-down list of node types into which you can change the current node (complete with nice warning to only change the node type if you "know what you are doing"!)
In my case, I selected my custom node type "Drupal Questions" from the list. Doing a Preview of the node showed no changes, but hitting Submit put the change into effect. It worked great, and – the thing I was most hoping for – left the node's comments attached and intact. Nodetype, you swinging switch-hitter, you're all right by me!
You can see my results here:
http://www.drupalace.com/blog_entry_trick_bin_hiding_node_title_2007_07_03
That node was a Blog Entry but is no longer; only its URL alias hints at its original configuration. (Kind of like the Adam's apple on "Lucy" in that Phuket night clu... no, the Ace is speaking too much here. Full stop.)
Now, I haven't used Nodetype enough to give out any handy tips, but the following safety procedures would seem wise:
1) Back up your database before dabbling in node DNA like this.
2) Your target node type may have different fields from your original node type, and I would imagine that data gets lost when a field gets dropped. Copy all major text field data from your original node before changing its type, to avoid loss.
3) Experiment first with a dummy node, if you really want to be safe before operating on the real thing.
If you've ever agonized over what node type to use for some piece of content, worried about getting "stuck with" the wrong decision, you can relax a bit with Nodetype in your arsenal. Bring out the tranny in your nodes! Good stuff.
Relevant Content
The Drupal Ace logo has dealt these content suggestions from the deck.
- Working with Menus: Administration Form (Drupal 6)
- Drupal beginner documentation picking up steam
- Working with Menus: Administration Form (Drupal 5)
- Updating Easy Drupal Admin Manual
- Drupal for Beginners
- Why would Color-enabled themes work for all sites but one?
- Limiting node access: three quick'n'easy tools
Learn Drupal, hands-on
Get the beginner-friendly ebook that teaches community site building via a live case study.







Nodelist enhancement?
Seems to me info can be lost where the two node types are different in more than name.
I think it would be useful if one could see a comparison of the fields of the old and new node types. I came here because I misconfigured freelinking, and had the default new document type set to "story" where I intended "wiki." I don't think the differences are great, but they might be significant. And, from this description, nodelink will do its thing and all might seem good when, in face, not all is good.
Node type change and risk
Indeed, letting an automated procedure change a node's type does sound like a risk of data loss, especially if the two types' fields don't match. If the source type has more fields than the target type, do those extra fields simply get stripped off and their data lost forever? I don't know!
Your suggestion is a good one: It'd be great if the module displayed a pre-change list of what changes it will make. As it is, the workings are a black box. So for now, all I can suggest to users of Nodetype is: Make sure the target node type has all the fields you want to keep from the original type (and that those fields share the same field names); test the procedure on a dummy node or two before hitting the real nodes; and, ABSOLUTELY back up that database before letting Nodetype touch a thing!
With those precautions taken, I've found it a nice tool.
Thanks for the comment!
Re: How to change a node's type?
the nodetype.module comes quite handy thanks to the developer. it would be perfect though, if its part of the content bulk actions + a feature for cck per field operation.
Re: How to change a node's type?
I was curious if this could also be done by poking the database directly to change, say, nodes of type "blog" into nodes of type "question" (a custom content type)?
Oh, the danger.
Charlie
Re: How to change a node's type?
Ah, the hubris of a Frankenstein! Actually, I would think it's quite possible to manhandle the database directly, as you suggest. In fact, what else could the nodetype module be doing, but performing some database surgery that one could also perform manually?
I don't know what the SQL commands would be; I expect that dissecting the nodetype module would yield clues. I've got too much on my to-do list, so for now will stick to letting nodetype do the heavy gravedigging for me. But who knows, maybe some night when the moon is full and the Van de Graaf spheres are crackling, it'd be illuminating to strap down a node and take scalpel in hand...
Re: How to change a node's type?
I just had a first look at this module. It seems that its only task is to change the type. And because the module is doing that not directly by modifying the database but using ordinary drupal functions the cache will be updated probably.
As far as I can see the module (implicitly) does:
update node set type='NEWTYPE' where nid=NODEID;
(where NEWTYPE is one of the values in table node_type column type: select type from node_type; )
And the node should also be moved from table content_type_ to content_type_
Now some thoughts about what can be done to extend the nodetype module
When you have an node (NID) of type 'image', there is always one image attached to it.
Name and path of this image is stored in table 'files'. When you have versioning activated (VID) a query to pick up the image will look like:
select f.fid, n.nid, filename, filepath from node n, file_revisions r, files f where n.vid=r.vid and r.fid=f.fid and n.nid=NID;
You can see that the image module has created several additional derivative images with names (column filename) as
thumbnail
preview
If you want to change the node type from 'image' to 'story' all the derivative images (all filenames but '_original') can be purged.
The '_original' image can be attached to the story if there is e.g. a CCK field of type image. To check this try
select type_name, widget_type from node_field_instance where type_name='story' and widget_type='image';
Column type_name will show (all) CCK field name of type 'image' attached to node of type 'story'. It looks like
'field_attach_image'
where attach_image is the name for the field used when the CCK field was set up.
Prepending this type_name with 'content_' yields to
'content_field_attach_image'
which is the name of the table to put the image in:
insert into content_field_attach_image values (VID, delta?, NID, FID, '', '');
I hope this helps somebody
Regards
Schildi
Re: How to change a node's type?
I can't help but think it'll help somebody! I pitch this page on the drupal.org forums whenever someone asks about changing a node type, so I'm certain future seekers of transformational knowledge will see your post and learn. Thank you, Schildi!
Re: How to change a node's type?
wow, thanks for posting this. i wanted to do it, but searching google didnt bring up very good results.
you rocked it tho
Re: How to change a node's type?
Glad it helped! Thanks, and drop by any time.
Post new comment