<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>No Mind &#187; No category</title>
	<atom:link href="http://www.vivekkhurana.net/no-mind/category/no-category/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vivekkhurana.net/no-mind</link>
	<description>It's the mind that makes you miss the shot</description>
	<lastBuildDate>Fri, 22 Jul 2011 18:03:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Revisioning in custom drupal module</title>
		<link>http://www.vivekkhurana.net/no-mind/revisioning-in-custom-drupal-module/</link>
		<comments>http://www.vivekkhurana.net/no-mind/revisioning-in-custom-drupal-module/#comments</comments>
		<pubDate>Mon, 15 Nov 2010 17:23:19 +0000</pubDate>
		<dc:creator>Vivek Khurana</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[FOSS]]></category>
		<category><![CDATA[No category]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[cusotm module]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[revision]]></category>

		<guid isPermaLink="false">http://www.vivekkhurana.net/no-mind/?p=82</guid>
		<description><![CDATA[Today I was faced a problem with revision handling in Drupal. I was developing a custom module which had some data stored in separate DB table.  The second requirement was to be able to do revisioning on the additional data.  All was fine till I got stuck in one place. When you revert to an [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was faced a problem with revision handling in Drupal. I was developing a custom module which had some data stored in separate DB table.  The second requirement was to be able to do revisioning on the additional data.  All was fine till I got stuck in one place. When you revert to an older revision, Drupal invokes &#8216;update&#8217; op for nodeapi. In both cases, revision revert as well as &#8216;update&#8217;, &#8216;presave&#8217; op is also called. My requirement  was to be able to pull the data for the previous version and store it as new version. But the question is how do I come to know if the &#8216;presave&#8217; is called for new node, a node being edited or a revision being reverted ?</p>
<p>After some debugging I found, that when &#8216;presave&#8217; op for nodeapi is called for node revert,  the $node object has vid for the version to be reverted to and when the node is being updated, the vid is the latest vid. So, fetching the current vid of the $node in &#8216;presave&#8217; op and comparing it with the vid of the $node passed to presave operation, solved the problem. If the vid of the$node passed is same as the vid in the node table, then it is an update, else it is a node revert.</p>
<p>What about new node creation ? Well in case of new node creation the vid for $node is not set. <img src='http://www.vivekkhurana.net/no-mind/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here is the code snippet explaining the above logic</p>
<p><code><br />
 function mymodule_nodeapi(&#038;$node, $op, $arg = 0){<br />
 &nbsp;  switch($op){<br />
 &nbsp; &nbsp;case 'presave':<br />
 &nbsp; &nbsp;    if($node->vid){<br />
 &nbsp; &nbsp; &nbsp;      //node vid is set, means a this is edit or revision revert.<br />
 &nbsp; &nbsp; &nbsp;       $sql = 'select vid from {node} where  nid=%d';<br />
 &nbsp; &nbsp; &nbsp;      $vid_db = db_fetch_array(db_query($sql,$node->vid));<br />
 &nbsp; &nbsp; &nbsp;      if($node->vid == $vid_db['vid']){<br />
 &nbsp; &nbsp; &nbsp; &nbsp;         //Execute edit logic.<br />
 &nbsp; &nbsp; &nbsp;       }else{<br />
 &nbsp; &nbsp; &nbsp; &nbsp;        //Execute revision revert logic.<br />
 &nbsp; &nbsp; &nbsp;        }<br />
   &nbsp; &nbsp;   }<br />
  &nbsp;   }<br />
}<br />
</code></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.vivekkhurana.net%2Fno-mind%2Frevisioning-in-custom-drupal-module%2F&amp;title=Revisioning%20in%20custom%20drupal%20module" id="wpa2a_2"><img src="http://www.vivekkhurana.net/no-mind/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.vivekkhurana.net/no-mind/revisioning-in-custom-drupal-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lets get rolling&#8230;</title>
		<link>http://www.vivekkhurana.net/no-mind/lets-get-rolling/</link>
		<comments>http://www.vivekkhurana.net/no-mind/lets-get-rolling/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 09:27:10 +0000</pubDate>
		<dc:creator>Vivek Khurana</dc:creator>
				<category><![CDATA[No category]]></category>
		<category><![CDATA[nothing]]></category>

		<guid isPermaLink="false">http://www.vivekkhurana.net/no-mind/?p=3</guid>
		<description><![CDATA[So I was thinking of restarting writing on the web and I thought hard for the topic of the first post. After spending some time I relaized the first post need to have nothing&#8230; let me not set any kind of trend.. let things roll on there own&#8230;]]></description>
			<content:encoded><![CDATA[<p>So I was thinking of restarting writing on the web and I thought hard for the topic of the first post. After spending some time I relaized the first post need to have nothing&#8230; let me not set any kind of trend.. let things roll on there own&#8230;</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.vivekkhurana.net%2Fno-mind%2Flets-get-rolling%2F&amp;title=Lets%20get%20rolling%26%238230%3B" id="wpa2a_4"><img src="http://www.vivekkhurana.net/no-mind/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.vivekkhurana.net/no-mind/lets-get-rolling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

