Add a bunch more crap and rewrite a bunch more crap. Now the 'rm' mode at least runs.
[mailshears.git] / lib / prune / plugins / davical.rb
1 require 'pg'
2
3 require 'common/davical_plugin'
4 require 'prune/prune_plugin'
5 require 'rm/plugins/davical'
6
7 class DavicalPrune < DavicalRm
8 #
9 # DAViCal only supports Postgres, so even if we ever are
10 # database-agnostic, this plugin can't be.
11 #
12 include DavicalPlugin
13 include PrunePlugin
14
15
16 def get_leftover_domains(db_domains)
17 # AgenDAV doesn't have a concept of domains.
18 return []
19 end
20
21
22 def get_leftover_accounts(db_accounts)
23 # Get a list of all users who have logged in to DAViCal.
24 davical_accounts = self.get_davical_usernames()
25 return davical_accounts - db_accounts
26 end
27
28
29 protected;
30
31 def get_davical_usernames()
32 usernames = []
33
34 begin
35 connection = PGconn.connect(@db_host,
36 @db_port,
37 @db_opts,
38 @db_tty,
39 @db_name,
40 @db_user,
41 @db_pass)
42
43 # User #1 is the super-user, and not tied to an email address.
44 sql_query = 'SELECT username FROM usr WHERE user_no > 1;'
45
46 connection.query(sql_query) do |result|
47 usernames = result.field_values('username')
48 end
49
50 connection.close()
51 rescue PGError => e
52 # Pretend like we're database-agnostic in case we ever are.
53 raise DatabaseError.new(e)
54 end
55
56 return usernames
57 end
58
59
60 end