Closed (fixed)
Project:
Case Tracker
Version:
5.x-1.3
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
4 Jun 2009 at 09:53 UTC
Updated:
19 Sep 2009 at 12:10 UTC
The problem is casetracker expects to get a username from the node form, but update is also called when a node is being saved so something like:
$node = node_load(123);
node_save($node);
will remove the assign_to field
case 'update':
// cases: update our case with the latest data.
if (in_array($node->type, variable_get('casetracker_case_node_types', array('casetracker_basic_case')), TRUE)) {
$result = $node->revision
? db_query("INSERT INTO {casetracker_case} (nid, vid, pid, case_priority_id, case_type_id, case_status_id, assign_to, case_number) VALUES (%d, %d, %d, %d, %d, %d, %d, %d)", $node->nid, $node->vid, $node->pid, $node->case_priority_id, $node->case_type_id, $node->cas
e_status_id, casetracker_get_uid($node->assign_to), $node->case_number)
We ran a database update which used nodesave and it removed all the assigned_to's in our live DB :(
This patch is a hack, but fixes the issue.
--- casetracker.module 2 Apr 2009 00:03:50 -0000 1.111.2.16
+++ casetracker.module 4 Jun 2009 09:51:11 -0000
@@ -1412,6 +1412,10 @@ function casetracker_get_name($uid) {
* See also casetracker_get_name().
*/
function casetracker_get_uid($name = NULL) {
+ //hack, but if it looks like a uid, it is a uid
+ if (is_numeric($name)) {
+ return $name;
+ }
$uid = db_result(db_query("SELECT uid FROM {users} WHERE name = '%s'", $name));
return $uid ? $uid : 0;
}
Now to restore that data from a backup.
| Comment | File | Size | Author |
|---|---|---|---|
| casetracker_get_uid_node_save_.patch | 852 bytes | JacobSingh |
Comments
Comment #1
jmiccolis commentedHey Jacob,
Thanks for the bug report. A question about the update you ran, what is it something that core did, or a specific contrib module? I'd really like to know just how many installs this could effect and how I can test and reproduce.
Thanks
Comment #2
JacobSingh commentedHey Jeff,
This is based on a custom update hook we have. But it should happen every time you run node_load and then node_save() because the assign_to property is an int, and the casetracker expects a string (username).
To reproduce, do something like this:
Create a node and assign it to a user.
Then run this:
$node = node_load($nid);
$original_assigned = $node->assign_to;
node_save($node);
//Will call casetracker_nodeapi($op = "update");
$node = node_load($nid,null, true);
if ($original_assigned != $node->assign_to) {
print "NODEAPI FAIL";
dpr($node->assign_to);
dpr($original_assigned);
}
Best,
Jacob
Comment #3
sreynen commentedI ran into this same issue when writing a module to extend casetracker. The underlying problem is the use of one field (assign_to) to hold two different types of data (name and UID). Adding another admitted hack on top of the existing hack, forcing the field into a standard type before saving, is a poor solution. The field should either *always* be a UID or *always* be a name.
Comment #4
jmiccolis commentedJust committed this fix. Sorry it took so long.