By joegml on
I've got a piece of code and if I place a die statement in that code at the bottom at the normal return location, it seems to work (before dying of course!). Without the die, the code seems not to work. Anybody have any ideas.
Thanks 'yall!
if ( $last_month<=$date and $date<$this_month ){
pegevent_set_term_entry( $nid, $terms[6] );
} elseif ( $this_month<=$date and $date<$next_month ){
pegevent_set_term_entry( $nid, $terms[7] );
} elseif ( $next_month<=$date and $date<$n_n_month ){
pegevent_set_term_entry( $nid, $terms[8] );
}
if($dbg){ die( "dbg>> pegevent_set_time_terms called w/ nid $nid, post clear." ); }
} // end of function
function pegevent_set_term_entry( $nid, $tid ){
# check to see if already marked: avoid duplicate error
$qs = "select * from term_node where nid = $nid and tid = $tid";
$qr = db_query( $qs );
while( $row = mysql_fetch_array( $qr )){
return; # already marked
}
#$qs = "insert into term_node set nid=$nid, tid=$tid";
$qs = "INSERT INTO term_node (nid, tid) VALUES ($nid, $tid)";
return( db_query( $qs ) );
}
Comments
More context needed, what
More context needed, what invokes the code on top and what does "the code seems not to work" mean?
More Detail
See more detail below. "Code seems not to work" means term_node table is not modified as intended.
If I put in the die statement, term_node gets modified, without the die, no modification in term_node.
Thanks.
--
Joe Golden
www.triangul.us : People, Ideas, Connections
This may or may not be the
This may or may not be the problem, but you probably should bracket your table names with {} because that's how db_query handles table prefixing. Like the other person said, we need more context to help. Try placing some print statements in your code to see what the variables are. Anything strange in the logs?
http://www.trailheadinteractive.com
More Detail
I'm testing w/ table names in brackets. That's not doing the trick.
Print statements will not be shown, perhaps because of the calling from hook_nodeapi. I had to put in a die because I was pretty sure the code was being accessed, but wasn't seeing debug print messages. I think the call from hook_nodeapi is important.
Thanks a lot for any insight or ideas. Hope this is sufficient detail.
--
Joe Golden
www.triangul.us : People, Ideas, Connections
Ok, I see the problem
Problem is you are modifying the term_node table directly (generally not approriate) and in this the die "short circtuits" other code which may allow your code to work but could cause problems.
So to change how it works, change
to
Note you will need to change the call(s) to pegevent_set_time_terms() and in the function change any uses of $nid to $node->nid.
Then change
to
Now change each line like (there are several)
to
Some Success
I'm trying this out and parts seem to work and others don't. The code is firing at the correct time. I'm only testing at node modification at present.
I'm getting a persistent entry in term_node for term 199, that doesn't seem to be cleared by
Also, the date recognition seems off now, whereas before, it was fine. I'm not sure where this is coming from.
Thanx.
--
Joe Golden : www.triangul.us : People, Ideas, Connections
Do other tems clear
Do other tems clear correctly?
As for the date recognition, did you change
to
and change
to
Dates confused
Dates don't clear correctly. The 199 doesn't seem to be sticking anymore, but the date recognition is confused. The *old version* (prior to your recommended changes) of the function works correctly when called as a php page (not in the nodeapi context). So I'm pretty sure the date recognition logic is good.
The new version ... I'm not sure.
Yes I changed to $node->nid in both places you mentioned.
When I change the date to 2007, which should match NO terms for pdate, I get
Is there a way to check that the term clearing is working?
I'm gonna try a direct call via php to the new version and see if that works smoothly. That might help isolate the nodeapi part.
--
Joe Golden : www.triangul.us : People, Ideas, Connections
Simple test
Right after the loop that is suppose to clear any terms add a return statement. Edit a node and save, it should not have terms from the ones you have listed.
Seems to leave one term dangling
My previous clearing code works correctly for this test, but I know it may be too brutish ;-) *wait*, no it doesn't. the 198 seems to keep dangling there w/ pegevent_clear_term_entry( $node->nid, $term ); code as well.
taxo term assignment
The problem could be related to the taxo term assignment, as this seems to be confused rather than the date recognition code.
Any links for how to assign the taxo terms as the node is built or modified?
--
Joe Golden
www.triangul.us : People, Ideas, Connections
What does that part of the
What does that part of the code look like after your changes?
Something else to try
Change
to
What to the before and after results look like?
Same Taxo Dump
both the same:
Misformed Taxonomy
Almost nailed it. Crux of the solution shown below for general edification. Thanx Nevets!