function flag_lists_update_7000 in Flag Lists 7
Same name and namespace in other branches
- 7.3 flag_lists.install \flag_lists_update_7000()
Get rid of garbage list entries that are orphaned from a list
File
- ./
flag_lists.install, line 212 - The Flag lists module install file.
Code
function flag_lists_update_7000() {
$orphans = db_query("SELECT flc.fcid, flc.fid, flc.content_id, flc.uid, flcounts.content_type, count\n FROM {flag_lists_content} flc\n JOIN {flag_lists_counts} flcounts ON flcounts.fid=flc.fid AND flc.content_id=flcounts.content_id\n LEFT JOIN {flag_lists_flags} flf ON flf.fid=flc.fid\n WHERE flf.fid IS NULL");
foreach ($orphans as $orphan) {
$num_deleted = db_delete('flag_lists_content')
->condition('fid', $orphan->fid)
->condition('fcid', $orphan->fcid)
->condition('uid', $orphan->uid)
->execute();
if (!empty($num_deleted)) {
drupal_set_message("Deleting flag_id: {$orphan->fid} flag_content_id: {$orphan->fcid}");
db_update('flag_lists_counts')
->fields(array(
'count' => $orphan->count <= 1 ? 0 : $orphan->count - 1,
))
->condition('content_type', $orphan->content_type)
->condition('fid', $orphan->fid)
->condition('content_id', $orphan->content_id)
->execute();
}
}
}