I have an action set on an operations view. When I run the action with a node selected, it appears to run successfully, but doesn't update the database as I expect.
Here's the action function, with debugging statements inside. It's a little sloppy since I've redone sections of it over and over trying to figure out the problem (I stripped out formatting and such in the sql statement to eliminate that as a possibility), but maybe someone can see something obvious that I'm missing.
function notsearch_enroll_student_action(&$node, $context = array()) {
dpm($node);
dpm($context);
if (isset($context['nid'])) {
$nid = $context['nid'];
}
if (isset($node->type)) {
if ($node->type = 'content_enrollment_application') {
$nid = $node->nid;
}
}
if (isset($nid)) {
$enrolled = db_result(db_query('SELECT field_enrolled_value from {content_type_content_enrollment_application} WHERE nid = %d', $nid));
if ($enrolled !== 'Has Been Enrolled') {
$date = date('Y-m-d\TH:i:s');
$sql="UPDATE {content_type_content_enrollment_application} SET field_enrolled_value='Has Been Enrolled', field_enrolled_by_value='Enrolled Form', field_enrollment_date_value='$date' WHERE nid = $nid";
dpm($sql);
dpm($date);
db_query($sql);
dpm(db_affected_rows());
drupal_set_message('Student Enrolled ','status');
notsearch_clear_cache();
}
}
}
The debug output has the entire node (which I won't list here for length and privacy reasons) and the following output from the other statements:
Array
(
)
UPDATE {content_type_content_enrollment_application} SET field_enrolled_value='Has Been Enrolled', field_enrolled_by_value='Enrolled Form', field_enrollment_date_value='2008-08-01T00:03:37' WHERE nid = 1667
2008-08-01T00:03:37
1
The query:
select * from content_type_content_enrollment_application where nid=1667;
Shows no change in the database entry.
If I run the sql update statement above manually (removing the {}) from the mysql client, it works without error.
I've spent about 6 hours on this debugging it every way I can think of and it's driving me crazy. There's got to be something obvious I'm missing, but from everything I can tell the update statement should be running and yet the database isn't getting updated.
Any suggestions for how to further debug or anything you notice that may be the problem, please let me know.
Comments
Changed directions
I never could find the problem, so I switched to using node_save() instead. Probably better that way anyway.
1) enable devel module, and
1) enable devel module, and turn on query-logging, to see exactly what SQL drupal is executing
2) FWIW, you should probably be using variable substitution rather than literally embedding variables in the SQL. This will allow Drupal to properly escape values to avoid SQL injection, and may make your code tidier. Something like: (totally untested)