Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: modules/discourse/manifests/sitesetting.pp

Issue 9351210: Define Discourse admins and site settings in Puppet, separate private data from other settings (Closed)
Patch Set: Created Feb. 19, 2013, 3:08 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 define discourse::sitesetting(
2 $setting = $title,
3 $value = undef,
4 $type = 1,
5 $ensure = 'present'
6 ) {
7 # Attempt some escaping
8 $escaped_value = regsubst($value, '[\'\\]', '\\\1', 'G')
9 $escaped_setting = regsubst($setting, '[\'\\]', '\\\1', 'G')
10 $escaped_type = regsubst($type, '\D', '', 'G')
11
12 case $ensure {
13 default: {
14 err("unknown ensure value ${ensure}")
15 }
16 present: {
17 # This is apparently how you do a conditional INSERT in PostgreSQL - sorry
Felix Dahlke 2013/02/21 15:27:40 Looked a bit into this myself, your method is quit
18 $update_sql = "UPDATE site_settings SET value = '$escaped_value', data_typ e = $escaped_type WHERE name = '$escaped_setting' RETURNING 1"
19 $columns = "name, data_type, value, created_at, updated_at"
20 $values = "SELECT '$escaped_setting', $escaped_type, '$escaped_value', CUR RENT_TIMESTAMP, CURRENT_TIMESTAMP"
21
22 postgresql_psql {"WITH upd AS ($update_sql) INSERT INTO site_settings ($co lumns) $values WHERE NOT EXISTS (SELECT * FROM upd)":
23 db => 'discourse',
24 psql_user => 'discourse',
25 unless => 'SELECT false'
26 }
27 }
28 absent: {
29 postgresql_psql {"DELETE FROM site_settings WHERE name = '$escaped_setting '":
30 db => 'discourse',
31 psql_user => 'discourse',
32 unless => 'SELECT false'
33 }
34 }
35 }
36 }
OLDNEW

Powered by Google App Engine
This is Rietveld