Skip to content

Commit

Permalink
Merge branch 'xml-twig'
Browse files Browse the repository at this point in the history
OK, nobody screamed bloody murder at me, so apparently I didn't blow
up the entire website or anything. Merging my cleanup into master.
  • Loading branch information
jhannah committed Jun 29, 2013
2 parents 00260b9 + 6ac993b commit 42a935d
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 146 deletions.
85 changes: 74 additions & 11 deletions bin/deactivate.pl
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,42 +1,105 @@
#! env perl

use 5.18.0;
use Email::Stuffer;
use XML::Twig;

my $xml = 'perl_mongers.xml';
my $name = $ARGV[0] || usage();

my ($elt) = update_xml($name);
send_email($elt);
say "Deactivated in XML. Email sent.";

exit;

# ------------
# END MAIN
# ------------

sub usage {
print <<EOT;
$0 Omaha.pm
send_email('Omaha.pm', 'http://omaha.pm.org', 'jay@jays.net');
EOT
exit;
}


sub update_xml {
my ($name) = @_;
my $found_it = 0;
my $elt;
my $twig = XML::Twig->new(
pretty_print => 'indented',
# output_text_filter => 'html',
twig_handlers => {
group => sub {
if ($_->first_child('name')->text eq $name) {
$_->{att}->{status} = 'inactive';
$found_it++;
$elt = $_;
}
},
},
);
$twig->parsefile($xml);
unless ($found_it) {
die "Didn't find group '$name'";
}
open my $new, '>:utf8', 'new.xml' or die;
print $new $twig->sprint;
close $new;
rename('new.xml', $xml);
return $elt;
}


sub send_email {
my ($group, $homepage, $leader_email) = @_;
my ($elt) = @_;

$leader_email = 'jay@jays.net'; # temporary
my $group_name = $elt->first_child('name')->text;
my $tsar = $elt->first_child('tsar')->first_child('name')->text;
my $e = $elt->first_child('tsar')->first_child('email');
my $tsar_email =
$e->first_child('user')->text . '@' .
$e->first_child('domain')->text;
my $web = $elt->first_child('web')->text;

my $body = <<EOT;
<p>
$group leader,
$tsar,
</p><p>
It appears that your Perl Mongers group configuration is broken,
badly out of date, or has been overrun with spam:
</p><p>
$homepage
$web
</p><p>
Your group has been deactivated.
</p><p>
When you have resolved the problem(s), please reply to this email
informing us of your resolutions so that we can re-activate you.
</p><p>
If we have made a mistake, we apologize. Please reply so we know something
has gone wrong on our side.
</p><p>
Thank you for your attention!
</p><p>
pm.org support staff<br/>
support\@pm.org
pm.org support staff &lt;support\@pm.org&gt;<br/>
Group hosting FAQ: http://www.pm.org/faq/hosting_faq.html
</p>
EOT

# Create and send the email in one shot
say "Sending to $tsar_email";
Email::Stuffer
->from ('support@pm.org')
->to ($leader_email)
->subject ("$group deactivated")
->to ($tsar_email)
->cc ('jay@jays.net')
->subject ("$group_name deactivated")
->html_body($body)
->send;
->send || die $!;
}


Expand Down
Loading

0 comments on commit 42a935d

Please sign in to comment.