? userpoints_nc-939950.patch
Index: userpoints_nc.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/userpoints_nc/userpoints_nc.module,v
retrieving revision 1.3.2.2
diff -u -p -r1.3.2.2 userpoints_nc.module
--- userpoints_nc.module	2 Mar 2010 22:27:46 -0000	1.3.2.2
+++ userpoints_nc.module	13 Oct 2010 02:21:29 -0000
@@ -27,7 +27,7 @@ function userpoints_nc_userpoints($op, $
         '#collapsed'   => TRUE,
         '#title'       => t('!Points for posting nodes', userpoints_translation()),
       );
-      
+
       $form[$group][USERPOINTS_POST . '_undo_points_on_delete'] = array(
         '#type'          => 'checkbox',
         '#title'         => t('Take away !points on node delete', array_merge(userpoints_translation())),
@@ -57,7 +57,7 @@ function userpoints_nc_userpoints($op, $
           '#options'       => $category_options,
           '#default_value' => variable_get(USERPOINTS_POST . $type . '_category', 0),
           );
-    
+
       }
       $group = 'comment';
       $form[$group] = array(
@@ -105,16 +105,16 @@ function userpoints_nc_userpoints($op, $
         '#description' => t('If you have used userpoints_basic prior to version 2.14 you may need to enable this fix.<br />
                              If you have not used userpoints_basic prior to v3 you do NOT need to (nor should) enable this fix. <br />
                              This fix only affects the behavior of how !points are handled when ownership of a node/comment
-                             changes. In version 2 data on the original owner was not kept and a static variable was used to 
+                             changes. In version 2 data on the original owner was not kept and a static variable was used to
                              store this information. Unfortunately people have experienced unusual side effects such as
                              !points moving from one owner to a completely random user. All !points accrued with version 3 will
-                             not exhibit this behavior thus this fix is unnecessary. 
+                             not exhibit this behavior thus this fix is unnecessary.
                              Only check this box under the following conditions <br />
                              1) You have existing !points granted by a userpoints version prior to version 3 <br />
                              2) If ownership changes on a node/comment you want points to follow ownership <br />
                              <i>All !points accrued by version 3 will move ownership automatically this setting only affects !points accrued with v2</i>
                              <br />
-                             3) You have read <a href="http://drupal.org/node/183520">Article 183520</a> on drupal.org and 
+                             3) You have read <a href="http://drupal.org/node/183520">Article 183520</a> on drupal.org and
                                 understand that there could be unusual issues with ownership moves', userpoints_translation()),
       );
       $form[$group][USERPOINTS_USE_V2BUG] = array(
@@ -127,9 +127,9 @@ function userpoints_nc_userpoints($op, $
       break;
   }
 }
-  
+
 function userpoints_nodeapi(&$node, $op, $teaser, $page) {
-  //static up_orig_uid please read drupal.org/node/183520 
+  //static up_orig_uid please read drupal.org/node/183520
   static $up_orig_uid;
   $points = variable_get(USERPOINTS_POST . $node->type, 0);
   $tid = variable_get(USERPOINTS_POST . $node->type . '_category', 0);
@@ -164,17 +164,17 @@ function userpoints_nodeapi(&$node, $op,
       break;
     case 'update':
       //Find the last points granted on this node inserts and ownership gains
-      $sql = "SELECT points, uid 
-              FROM {userpoints_txn} 
-              WHERE entity_id = %d AND entity_type = '%s' 
+      $sql = "SELECT points, uid
+              FROM {userpoints_txn}
+              WHERE entity_id = %d AND entity_type = '%s'
               AND (operation = '%s' OR operation ='%s')
               ORDER BY time_stamp DESC
               LIMIT 1
               ";
       $last_owner = db_fetch_object(db_query($sql, $node->nid, 'node', 'insert', 'Ownership gain'));
-      
+
       //Check the UID of the original to this user, if different add/substract points
-      if ($node->uid != $last_owner->uid && is_numeric($last_owner->uid) ) {
+      if (!empty($last_owner->uid) && $node->uid != $last_owner->uid && is_numeric($last_owner->uid)) {
         //Check to see if this user has already lost the points for
         // Add to the new node owner
         $params = array(
@@ -279,9 +279,9 @@ function userpoints_comment($comment, $o
       break;
     case 'update':
       //Find the last points granted on this node inserts and ownership gains
-      $sql = "SELECT points, uid 
-              FROM {userpoints_txn} 
-              WHERE entity_id = %d AND entity_type = '%s' 
+      $sql = "SELECT points, uid
+              FROM {userpoints_txn}
+              WHERE entity_id = %d AND entity_type = '%s'
               AND (operation = '%s' OR operation ='%s')
               ORDER BY time_stamp DESC
               LIMIT 1
