I have an issue with the new comment tag always displays for answers when viewing the questions with associated answers page. I found that when one views a question and answers page the history table is updated only for the answers_question type, and not for the associated answers_answer type.
I added this code to answers module, answers_node_view()
global $user;
if ($user->uid) {
$result = db_select('field_data_answers_related_question', 'rq')
->fields('rq', array('entity_id'))
->condition('answers_related_question_target_id', $node->nid)
->execute()
->fetchAssoc();
foreach($result as $row) {
db_merge('history')
->key(array(
'uid' => $user->uid,
'nid' => $result,
))
->fields(array('timestamp' => REQUEST_TIME))
->execute();
}
}
It updates the history table for the answers_answer type correctly, yet the new comment marker now does not display at all. I suspect that I am on the right track, but that the history table should be updated later in the request.
Using hook_exit() seems to work:
function answers_exit() {
$router_item = menu_get_object();
if (isset($router_item) && $router_item->type == "answers_question") {
global $user;
if ($user->uid) {
$result = db_select('field_data_answers_related_question', 'rq')
->fields('rq', array('entity_id'))
->condition('answers_related_question_target_id', $router_item->nid)
->execute()
->fetchAssoc();
foreach($result as $row) {
db_merge('history')
->key(array(
'uid' => $user->uid,
'nid' => $result,
))
->fields(array('timestamp' => REQUEST_TIME))
->execute();
}
}
}
}| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 0001-Issue-2323139-by-WillowDigit-chipcleary-New-Comment-.patch | 2.34 KB | chipcleary |
Comments
Comment #1
willowdigit commentedComment #2
willowdigit commentedIs hook_exit the right way to do this?
Comment #3
chipcleary commentedSorry for the long delay.
It looks like there was a helpful discussion of this on drupal.stackexchange.
http://drupal.stackexchange.com/questions/126955/what-hook-to-use-to-upd...
That uses hook_exit and a refined version of getting the same effect as above. Unless you suggest otherwise, I'll test that refinement to the module.
Thanks for the work on this!
Comment #5
chipcleary commentedHi thanks for this.
I've taken the refined version of what you've done from here:
http://drupal.stackexchange.com/questions/126955/what-hook-to-use-to-upd...
Plus I found I needed to eliminate a bug in that I used module_load_include in a global context. Needed to fix that after I implemented hook_exit. (Though still not sure *why* implementing hook_exit, even if empty, triggered a problem).
Patch attached and committed to 7.x-4.x-dev.
Comment #6
bluegeek9 commentedI removed answer_exit 7.x-4.x because it was causing issues. hook_exit gets called on every page, even cached pages and should be avoid if possible. I am looking for another solution to fix the new tags.
Comment #7
bluegeek9 commentedI implemented hook_views_post_render to update the New tag.
Comment #9
bluegeek9 commented