OLD | NEW |
1 define discourse::postactiontype( | 1 define discourse::postactiontype( |
2 $id, | 2 $id, |
3 $key = $title, | 3 $key = $title, |
4 $is_flag = false, | 4 $is_flag = false, |
5 $icon = undef, | 5 $icon = undef, |
6 $position = 0, | 6 $position = 0, |
7 $ensure = 'present' | 7 $ensure = 'present' |
8 ) { | 8 ) { |
9 # Attempt some escaping | 9 # Attempt some escaping |
10 $escaped_id = regsubst($id, '\D', '', 'G') | 10 $escaped_id = regsubst($id, '\D', '', 'G') |
(...skipping 18 matching lines...) Expand all Loading... |
29 err("unknown ensure value ${ensure}") | 29 err("unknown ensure value ${ensure}") |
30 } | 30 } |
31 present: { | 31 present: { |
32 # This is apparently how you do a conditional INSERT in PostgreSQL - sorry | 32 # This is apparently how you do a conditional INSERT in PostgreSQL - sorry |
33 $update_sql = "UPDATE post_action_types SET name_key = '$escaped_key', is_
flag = $escaped_flag, icon = $escaped_icon, position = $escaped_position WHERE i
d = $escaped_id RETURNING 1" | 33 $update_sql = "UPDATE post_action_types SET name_key = '$escaped_key', is_
flag = $escaped_flag, icon = $escaped_icon, position = $escaped_position WHERE i
d = $escaped_id RETURNING 1" |
34 $columns = "id, name_key, is_flag, icon, position, created_at, updated_at" | 34 $columns = "id, name_key, is_flag, icon, position, created_at, updated_at" |
35 $values = "SELECT $escaped_id, '$escaped_key', $escaped_flag, $escaped_ico
n, $escaped_position, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP" | 35 $values = "SELECT $escaped_id, '$escaped_key', $escaped_flag, $escaped_ico
n, $escaped_position, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP" |
36 | 36 |
37 postgresql_psql {"WITH upd AS ($update_sql) INSERT INTO post_action_types
($columns) $values WHERE NOT EXISTS (SELECT * FROM upd)": | 37 postgresql_psql {"WITH upd AS ($update_sql) INSERT INTO post_action_types
($columns) $values WHERE NOT EXISTS (SELECT * FROM upd)": |
38 db => 'discourse', | 38 db => 'discourse', |
39 psql_user => 'discourse', | 39 psql_user => 'discourse' |
40 unless => 'SELECT false' | |
41 } | 40 } |
42 } | 41 } |
43 absent: { | 42 absent: { |
44 postgresql_psql {"DELETE FROM post_action_types WHERE id = $escaped_id": | 43 postgresql_psql {"DELETE FROM post_action_types WHERE id = $escaped_id": |
45 db => 'discourse', | 44 db => 'discourse', |
46 psql_user => 'discourse', | 45 psql_user => 'discourse' |
47 unless => 'SELECT false' | |
48 } | 46 } |
49 } | 47 } |
50 } | 48 } |
51 } | 49 } |
OLD | NEW |