Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DO LANGUAGE plperlu $fixheaders$
- my $update = spi_prepare('UPDATE action_trigger.event_definition SET template = $2 WHERE id = $1', 'INTEGER', 'TEXT');
- my $sth = spi_query("SELECT id, template FROM action_trigger.event_definition WHERE reactor = 'SendEmail'");
- my $template;
- while (defined ($template = spi_fetchrow($sth))) {
- my $orig_template = $template->{template};
- my $new_template = '';
- my $found_blank = 0;
- my $found_non_blank = 0;
- foreach my $line (split /\n/, $orig_template) {
- if (!$found_non_blank) {
- if ($line =~ m/^(\[%-.*-?%])?$/) {
- $new_template .= "$line\n";
- next;
- } else {
- $found_non_blank = 1;
- }
- }
- $found_blank = 1 if ($line =~ m/^$/);
- if ($found_blank) {
- $new_template .= "$line\n";
- next;
- }
- if ($line =~ /^([!-9;-~]+: *\[%-?)(.*?)(-?%])$/ and not $line =~ /helpers\.escape_email_header/) {
- $new_template .= "$1 helpers.escape_email_header($2) $3\n";
- } else {
- $new_template .= "$line\n";
- }
- }
- if ($orig_template ne $new_template) {
- spi_exec_prepared($update, {}, $template->{id}, $new_template);
- }
- }
- $fixheaders$;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement