Maybe I'm missing something but...I have this module setup for ex. a logged in user can purchase and create 3 nodes. They create all 3 nodes and now they are past the limit cool... The user now goes in to view the nodes using workspace, they delete they nodes/content they create. They pay per node balance still states: 3 - Purchased, 3-created, 0 - available. Why doesn't the balance reset back to 3 purchases, 0 -created, 3- available? The user purchased 3 nodes.

Comments

maurizio.ganovelli’s picture

Assigned: Unassigned » maurizio.ganovelli
Category: bug » feature

Hi martinwillb,

This feature (current behaviour is "by design") can be implemented in nodeapi hook on paypernode.module adding these lines of code:

else if ($op == 'delete') {
    $check=db_fetch_object(db_query("select node_type from {paypernode_tracker} where nid=%d", $node->nid));
    if ($check->node_type){ // check if node has been created by paypernode
       paypernode_user_update($node->uid, $check->node_type, 0, -1, 'add'); // restore 1 unit  
       drupal_set_message(t('Node has been re-charged into system.'));
    }
  } 

at line 491. I haven't checked this code yet, so please report here if it's buggy.

Bye!

martinwillb’s picture

Blackice78,

Thanks for the code entry but when I add it, I get the following error:

Parse error: syntax error, unexpected T_ELSE in /htdocs/arc/sites/all/modules/paypernode/paypernode.module on line 495

The code you recommended is below. This is a piece of the paypernode.module code, look for the comment with your name in it:

if ($op == 'insert' && isset($node->paypernode_type)) {
// Decrease user balance for this node type
// Get uid from node
//if ($node->type=='ad') $node->type=$node->type.':'.$node->adtype.':'.$node->taxonomy[_ad_get_vid()];

paypernode_user_update($node->uid, $node->paypernode_type, 0, 1);
$typename = node_get_types("name", $node);
$left = paypernode_user_can_create($node->paypernode_type, TRUE); // Last argument to refresh cache
// Log event and display additional user message.
watchdog('paypernode', 'Pay per node %typename node created. %number nodes left.', array('%number' => $left, '%typename' => $typename));
drupal_set_message(t("The node has been charged into the Pay per node system. You have %number nodes of type %typename left.", array('%number' => $left, '%typename' => $typename)));

/** Blackice78 suggested code below after my comments
*/
/**added to calculate the adding and subtracting of nodes and reseting them when used or deleted and added backin 11/06/2010
*/

else if ($op == 'delete') {
$check=db_fetch_object(db_query("select node_type from {paypernode_tracker} where nid=%d", $node->nid));
if ($check->node_type){ // check if node has been created by paypernode
paypernode_user_update($node->uid, $check->node_type, 0, -1, 'add'); // restore 1 unit
drupal_set_message(t('Node has been re-charged into system.'));
}
}
/** added code above 11/6/2010

}
}

/**
* Implementation of hook_perm().
*/
function paypernode_perm() {
return array(
// Product permissions
'create pay-per-node products', 'edit own pay-per-node products',

maurizio.ganovelli’s picture

Hi,

the code goes immediately after line 491 (after the curly bracket), sorry for mistake!

function paypernode_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  if ($op == 'insert' && isset($node->paypernode_type))  {
    paypernode_user_update($node->uid, $node->paypernode_type, 0, 1);
    $typename = node_get_types("name", $node);
    $left = paypernode_user_can_create($node->paypernode_type, TRUE);
    watchdog('paypernode', 'Pay per node %typename node created. %number nodes left.', array('%number' => $left, '%typename' => $typename));
    drupal_set_message(t("The node has been charged into the Pay per node system. You have %number nodes of type %typename left.", array('%number' => $left, '%typename' => $typename)));
  } else if ($op == 'delete') {
    $check=db_fetch_object(db_query("select node_type from {paypernode_tracker} where nid=%d", $node->nid));
    if ($check->node_type){ // check if node has been created by paypernode
       paypernode_user_update($node->uid, $check->node_type, 0, -1, 'add'); // restore 1 unit  
       drupal_set_message(t('Node has been re-charged into system.'));
    }
  } 
}

The code above is how the paypernode_nodeapi looks like after the patch. Please try it and let me know!

martinwillb’s picture

Thanks.. I made the change it works great.. Just what I needed.

maurizio.ganovelli’s picture

Status: Active » Fixed

Thanks to you for testing! I'll try to insert this patch in next release, allowing administrators to decide whether or not to re-charge an unit to ppn user's balance after deletion.

Bye!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.