Advertisement
cmptrwz

Update Templates?

Jul 31st, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. DO LANGUAGE plperlu $fixheaders$
  2. my $update = spi_prepare('UPDATE action_trigger.event_definition SET template = $2 WHERE id = $1', 'INTEGER', 'TEXT');
  3. my $sth = spi_query("SELECT id, template FROM action_trigger.event_definition WHERE reactor = 'SendEmail'");
  4. my $template;
  5. while (defined ($template = spi_fetchrow($sth))) {
  6. my $orig_template = $template->{template};
  7. my $new_template = '';
  8. my $found_blank = 0;
  9. my $found_non_blank = 0;
  10. foreach my $line (split /\n/, $orig_template) {
  11. if (!$found_non_blank) {
  12. if ($line =~ m/^(\[%-.*-?%])?$/) {
  13. $new_template .= "$line\n";
  14. next;
  15. } else {
  16. $found_non_blank = 1;
  17. }
  18. }
  19. $found_blank = 1 if ($line =~ m/^$/);
  20. if ($found_blank) {
  21. $new_template .= "$line\n";
  22. next;
  23. }
  24. if ($line =~ /^([!-9;-~]+: *\[%-?)(.*?)(-?%])$/ and not $line =~ /helpers\.escape_email_header/) {
  25. $new_template .= "$1 helpers.escape_email_header($2) $3\n";
  26. } else {
  27. $new_template .= "$line\n";
  28. }
  29. }
  30. if ($orig_template ne $new_template) {
  31. spi_exec_prepared($update, {}, $template->{id}, $new_template);
  32. }
  33. }
  34. $fixheaders$;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement