function casetracker_node_delete in Case Tracker 7
Implements hook_node_delete().
File
- ./
casetracker.module, line 155 - Enables the handling of projects and their cases.
Code
function casetracker_node_delete($node) {
if (casetracker_is_case($node->type)) {
// delete case and its comments.
$comment_results = db_select('comment', 'c')
->fields('c', array(
'cid',
))
->condition('c.nid', $node->nid)
->execute();
foreach ($comment_results as $comment_result) {
db_delete('casetracker_comment_status')
->condition('cid', $comment_result->cid)
->execute();
}
db_delete('casetracker_case')
->condition('nid', $node->nid)
->execute();
}
if (casetracker_is_project($node->type)) {
// projects: delete all the cases under the project and all the comments under each case.
$case_results = db_select('casetracker_case', 'c')
->fields('c', array(
'nid',
))
->condition('c.pid', $node->nid)
->execute();
foreach ($case_results as $case_result) {
db_delete('casetracker_case')
->condition('nid', $case_result->nid)
->execute();
$comment_results = db_select('comment', 'c')
->fields('c', array(
'cid',
))
->condition('c.nid', $case_result->nid)
->execute();
foreach ($comment_results as $comment_result) {
db_delete('casetracker_comment_status')
->condition('cid', $comment_result->cid)
->execute();
}
node_delete($case_result->nid);
// this'll handle comment deletion too.
}
}
}