Index: blog_reactions.module =================================================================== --- blog_reactions.module (Revision 125) +++ blog_reactions.module (Revision 126) @@ -207,6 +207,75 @@ } /** + * Removes all duplicate entries. + */ +function blog_reactions_remove_duplicates() { + // get all items with duplicate entries. + $query = "SELECT href, brid, count( * ) AS n + FROM {meine_blog_reactions} + GROUP BY href + HAVING n >1 + ORDER BY `n` DESC"; + $result = db_query($result); + + while ($item = db_fetch_object($result)) { + // load one of the items. + $my_item = blog_reactions_get_item($item->brid); + + // removes all with the same href. + $delete_item = new stdClass(); + $delete_item->href = $item->href; + blog_reactions_delete_item($delete_item); + + // and add the loaded item back again. + blog_reactions_set_item($my_item); + } +} + +/** + * Removes a certain item form the datebase. + * + * @return boolean was the deletion sucessfull. + **/ +function blog_reactions_delete_item($item) { + if (!is_array($item)) { + $item = (array) $item; + } + + $args = array(); + $where = ''; + // generate the sql remove query. + foreach ($item as $key => $value) { + switch ($key) { + case 'nid': + case 'published': + case 'updated': + case 'timestamp': + $where[] = "$key = %d"; + $args[] = $value; + break; + case 'brid': + case 'service': + case 'title': + case 'rel': + case 'href': + case 'content_type': + case 'content': + case 'author': + case 'uri': + $where[] = "$key = '%s'"; + $args[] = $value; + break; + } + } + if ($where) { + $where = implode(' AND ', $where); + $query = "DELETE FROM {blog_reactions} WHERE ". $where; + return db_query($query, $args); + } +} + +/** * Fetch XML-feed from Technorati, Blogsearch and Bloglines */ function blog_reactions_fetch($nid, $uri = NULL) {