We use the Casetracker module to keep track of hours spent on different projects. Hours worked are updated through cases (we call them project updates). Our Projects have a computed field that tallies up hours worked when new cases are prepared. We have this set to happen through rules.

For example:
A collaborator creates a project update with their hours worked.
"After Saving New Content" or "After Updating Existing Content" triggers a php snippet to run via Rules.
The php snippet causes the project to be resaved, thus recomputing the total hours worked.

I created a triggered rule for "After deleting content" with the same php that works in the above example. However, either the rule does not trigger or the php itself is incorrect. When manually resaving, the computed fields are updated.

My immediate guess is that since the case is being deleted, there is some issue in accessing the database via the node ID (though this could be totally wrong). Can anyone offer any suggestions?

/**
 * To update the project hours, we have to load the associated Project node, and
 * then save the node again.  Here, we grab the node from the database, and do the
 * update.
 */


//Get the current project case ID.
$nodeID = $node->nid;

//Create query to get the Project ID.
$res = db_query("SELECT pid FROM {casetracker_case} WHERE nid = '$nodeID'");

//Retrieve the Project details.
while ($newN = db_fetch_object($res)) {

   //Update computed fields by loading node, and then save it.
   $nodeNew = node_load( (string)$newN->pid );
   node_save($nodeNew);

}

Comments

TR’s picture

Status: Active » Closed (outdated)