Using Drupal 6 to collect history on nodes

This is pretty simple, but maybe not completely obvious as the default settings in Drupal 6 are turned off. So basically you just turn on create revision on save (check the box on the content type you want to collect history for) Administer > Content management > Workflow settings > Create new revision Now if you save a change to an existing node look at the database table you will notice that a new record is created with a VID (Version ID) reference in the content type table. So that was pretty easy, now maybe you normally have an SQL query that does a join using nid, a bit like the following to get the data in a node: SELECT n.nid as nid, n.title as title, field_my_nodedata as nodedata FROM node n INNER JOIN content_type_myct myct ON n.nid = myct.nid But now that will return all the history values! Maybe you just wanted the last saved node so the query changes slightly to use VID to do the join this: SELECT n.nid as nid, n.title as title, field_my_nodedata as nodedata FROM node n INNER JOIN content_type_myct myct ON n.vid = myct.vid Best of all it doesn't create a new node in the nodes table, so it doesn't affect site performance. Hope this helps someone out. References: http://drupal.org/node/320614

Comments

Popular posts from this blog

PHP timezones explained

iPhone Internet Tethering settings