]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/common/agendav_plugin.rb
187df6e92a695a85aba3091bded527a8ac751038
1 require 'common/plugin'
4 # Code that all Agendav plugins ({AgendavPrune}, {AgendavRm},
8 # We implement the Plugin "interface."
12 # Initialize this Agendav {Plugin} with values in *cfg*.
14 # @param cfg [Configuration] the configuration for this plugin.
18 :host => cfg
.agendav_dbhost
,
19 :port => cfg
.agendav_dbport
,
20 :options => cfg
.agendav_dbopts
,
21 :dbname => cfg
.agendav_dbname
,
22 :user => cfg
.agendav_dbuser
,
23 :password => cfg
.agendav_dbpass
}
27 # Return a list of Agendav users.
29 # @return [Array<User>] a list of users contained in the
35 connection
= PG
::Connection.new(@db_hash)
37 # There are also "owner" and "with" fields in the "shares" table,
38 # but they contains principal URLs and not a bare username. Thus
39 # their format depends on the CalDAV server configuration, and
41 sql_query
= 'SELECT username FROM prefs;'
44 connection
.sync_exec(sql_query
) do |result
|
45 users
= result
.field_values('username')
48 # Make sure the connection gets closed even if the query explodes.
52 return users
.map
{ |u
| User
.new(u
) }
56 # Count the number of rows in the "shares" table. Used only for
59 # @return [Fixnum] the number of rows in the "shares" table.
63 connection
= PG
::Connection.new(@db_hash)
65 sql_query
= 'SELECT count(*) FROM shares;'
67 connection
.sync_exec(sql_query
) do |result
|
68 count
= result
.getvalue(0,0).to_i()
71 # Make sure the connection gets closed even if the query explodes.