Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The flag plugin for Heartbeat doesn't clean up the database properly which can lead to issues. Specifically, when a heartbeat activity is deleted it deletes the flag (from the flag_content table) but not the entry in the flag_counts table.
Compare the behaviour of the hook_node_delete() in flag module with the corresponding code in the heartbeat flag plugin:
/**
* Implements hook_node_delete().
*/
function flag_node_delete($node) {
foreach (flag_get_flags('node') as $flag) {
// If the flag is being tracked by translation set and the node is part
// of a translation set, don't delete the flagging record.
// Instead, data will be updated in the 'translation_change' op, below.
if (!$flag->i18n || empty($node->tnid)) {
db_delete('flag_content')
->condition('fid', $flag->fid)
->condition('content_id', $node->nid);
db_delete('flag_counts')
->condition('fid', $flag->fid)
->condition('content_id', $node->nid);
}
}
}
/**
* activityRemoved()
*/
public function activityRemoved($uaids, $all) {
$query = db_delete('flag_content');
$query->condition('content_type', 'heartbeat_activity');
if (!empty($uaids) && $all == FALSE) {
$query->condition('content_id', $uaids, 'IN');
}
$query->execute();
}
Note that when nodes are deleted, it cleans up the flag_counts table too.
Patch to follow shortly.
Comment | File | Size | Author |
---|---|---|---|
#1 | heartbeat-flag_count_delete-1679426-1.patch | 1013 bytes | seddonym |
Comments
Comment #1
seddonym CreditAttribution: seddonym commentedHere it is.
Comment #1.0
seddonym CreditAttribution: seddonym commentedClarification.