Guest User

Untitled

a guest
Oct 30th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. # Sample usage
  2. # for a in /home/linguamatica/root/locale/*/emailTemplates.xml; do perl emailTemplates.pl $a notification; done
  3.  
  4. #!/usr/bin/perl
  5. use XML::DT;
  6. use warnings;
  7. use strict;
  8. use v5.26;
  9. use utf8;
  10. my $filename = shift;
  11.  
  12. my $db = {
  13. username => 'XXX',
  14. password => 'XXX',
  15. database => 'ojs',
  16. };
  17.  
  18. use DBI;
  19. my $DB = DBI->connect("DBI:mysql:database=$db->{database};host=localhost", $db->{username}, $db->{password});
  20.  
  21. my $key = shift;
  22. my $locale = undef;
  23. my $subject = undef;
  24. my $body = undef;
  25. my $description = undef;
  26.  
  27. my %handler=(
  28. 'body' => sub{ father->{body} = $c; },
  29. 'description' => sub{ father->{description} = $c; },
  30. 'email_text' => sub{
  31. if (uc($key) eq $v{key}) {
  32. $body = $v{body};
  33. $description = $v{description};
  34. $subject = $v{subject};
  35. }
  36. },
  37. 'email_texts' => sub{ $locale = $v{locale}; },
  38. 'subject' => sub{ father->{subject} = $c; },
  39. );
  40. dt($filename, %handler);
  41.  
  42. if (defined $subject and defined $body) {
  43. utf8::decode($subject);
  44. utf8::decode($body);
  45. utf8::decode($description);
  46. my $dbh = $DB->prepare("INSERT INTO email_templates_default_data VALUES (?,?,?,?,?);");
  47. $dbh->execute(uc($key), $locale, $subject, $body, $description);
  48. say "DONE $locale!";
  49. } else {
  50. say "Not found for $locale!"
  51. }
Add Comment
Please, Sign In to add comment