File indexing completed on 2024-05-05 04:49:36

0001 #!/usr/bin/env ruby
0002 #
0003 # script to remove stale entries in some database tables (album)
0004 #
0005 # (c) 2006 Roland Gigler <rolandg@web.de>
0006 # License: GNU General Public License V2
0007 
0008 class String
0009     def shellquote
0010         return "'" + self.gsub("'", "'\\\\''") + "'"
0011     end
0012 end
0013 
0014 system("dcop", "amarok", "playlist", "shortStatusMessage", "Removing stale 'album' entries from the database")
0015 
0016 qresult = `dcop amarok collection query #{"SELECT id FROM album;".shellquote}`
0017 result = qresult.split( "\n" )
0018 
0019 i = 0
0020 
0021 result.each do |id|
0022     print "Checking: #{id}, "
0023     qresult2 = `dcop amarok collection query #{"SELECT COUNT(*) FROM tags where album = #{id};".shellquote}`
0024     count = qresult2.chomp()
0025     printf "count: %s", count
0026     if  count == "0"
0027         i = i + 1
0028         qresult3 = `dcop amarok collection query #{"SELECT name FROM album where id = #{id} ;".shellquote}`
0029         result3 = qresult3.split( "\n" )
0030         puts "==>: Deleting: #{id}, #{result3}"
0031         system("dcop", "amarok", "collection", "query", "DELETE FROM album WHERE id = '#{id}'")
0032     end
0033     print "\n"
0034 end
0035 puts "removed #{i} albums."
0036 
0037 if i > 0
0038     system("dcop", "amarok", "playlist", "popupMessage", "Removed #{i.shellquote} stale 'album' entries from the database")
0039 end
0040