diff options
author | Paul Arthur <paul.arthur@flowerysong.com> | 2013-01-25 20:49:16 -0500 |
---|---|---|
committer | Paul Arthur <paul.arthur@flowerysong.com> | 2013-01-25 20:49:16 -0500 |
commit | cad1380737f7ffcfa82d46ab3066823435a48a5d (patch) | |
tree | e64277b52b26bc549c66e08f8f662279da08fa6e /lib/class/song.class.php | |
parent | 80f4859712b433d8cee1158951efc19e939224f4 (diff) | |
download | ampache-cad1380737f7ffcfa82d46ab3066823435a48a5d.tar.gz ampache-cad1380737f7ffcfa82d46ab3066823435a48a5d.tar.bz2 ampache-cad1380737f7ffcfa82d46ab3066823435a48a5d.zip |
Move duplicate searching from Catalog to Song
Catalog::get_duplicate_songs() -> Song::find_duplicates()
Catalog::get_duplicate_info() -> Song::get_duplicate_info()
Diffstat (limited to 'lib/class/song.class.php')
-rw-r--r-- | lib/class/song.class.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/class/song.class.php b/lib/class/song.class.php index 6b92ea68..72ab88f9 100644 --- a/lib/class/song.class.php +++ b/lib/class/song.class.php @@ -252,6 +252,63 @@ class Song extends database_object implements media { } /** + * find_duplicates + * + * This function takes a search type and returns a list of probable + * duplicates + */ + public static function find_duplicates($search_type) { + $where_sql = $_REQUEST['search_disabled'] ? '' : "WHERE `enabled` != '0'"; + $sql = 'SELECT `id`, `artist`, `album`, `title`, ' . + 'COUNT(`title`) FROM `song` ' . $where_sql . + ' GROUP BY `title`'; + + if ($search_type == 'artist_title' || + $search_type == 'artist_album_title') { + $sql .= ',`artist`'; + } + if ($search_type == 'artist_album_title') { + $sql .= ',`album`'; + } + + $sql .= ' HAVING COUNT(`title`) > 1 ORDER BY `title`'; + + $db_results = Dba::read($sql); + + $results = array(); + + while ($item = Dba::fetch_assoc($db_results)) { + $results[] = $item; + } // end while + + return $results; + } + + public static function get_duplicate_info($dupe, $search_type) { + $sql = 'SELECT `id` FROM `song` ' . + "WHERE `title`='" . Dba::escape($item['title']) . "' "; + + if ($search_type == 'artist_title' || + $search_type == 'artist_album_title') { + $sql .= "AND `artist`='" . Dba::escape($item['artist']) . "' "; + } + if ($search_type == 'artist_album_title') { + $sql .= "AND `album` = '" . Dba::escape($item['album']) . "' "; + } + + $sql .= 'ORDER BY `time`,`bitrate`,`size`'; + $db_results = Dba::read($sql); + + $results = array(); + + while ($item = Dba::fetch_assoc($db_results)) { + $results[] = $item['id']; + } // end while + + return $results; + } + + /** * get_album_name * gets the name of $this->album, allows passing of id */ |