Changeset 14771
- Timestamp:
- 05/08/12 00:19:38 (13 months ago)
- File:
-
- 1 edited
-
trunk/core/tools/develop/plague.pl (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/tools/develop/plague.pl
r13286 r14771 2 2 # Analyses the Waiting for Feedback tasks, Waiting For field, extracts 3 3 # wikiname, maps to email address, sends mail. 4 5 # usage: plague.pl [--topics "Item123,Item456"] [--nomail] 6 # with no arguments, searches thru Item* 4 7 use strict; 5 8 use warnings; 9 10 my $itemTopics = "Item*"; 11 my $sendMail = 1; 12 13 while (@ARGV) { 14 my $arg = shift @ARGV; 15 if ( $arg eq "--topics" ) { 16 $itemTopics = shift @ARGV; 17 } 18 elsif ( $arg eq '--nomail' ) { 19 $sendMail = undef; 20 } 21 } 22 print "Searching items $itemTopics\n"; 6 23 7 24 BEGIN { … … 18 35 my $session = new Foswiki( $Foswiki::cfg{AdminUserLogin}, $request ); 19 36 20 # Search for Waiting for Feedback, and load a struct with the results 21 my $d etails = '[' . Foswiki::Func::expandCommonVariables(<<'SEARCH') . ']';22 %SEARCH{23 " name~'Item*' ANDCurrentState='Waiting for Feedback'"37 my $sep = "JENNY8675309xyzzy"; 38 my $data = Foswiki::Func::expandCommonVariables(<<"SEARCH"); 39 \%SEARCH{ 40 "CurrentState='Waiting for Feedback'" 24 41 type="query" 42 topic="$itemTopics" 43 web="Tasks" 25 44 nonoise="on" 26 format="$percntFORMAT{\"$percntENCODE{\"$formfield(WaitingFor)\" 27 old=\"Main.,Foswiki:,TWiki:\" new=\",,\"}$percnt\" type=\"string\" 28 format=\"{topic=>'$topic',who=>'$dollaritem'}\" separator=\",\"}$percnt" 29 separator=","}% 45 format="topic='\$topic' WaitingFor='\$formfield(WaitingFor)' Summary='\$formfield(Summary)'" 46 separator="$sep"}\% 30 47 SEARCH 31 my $data = eval($details);32 48 33 # Process the struct, collating items according to the recipient email49 # collate search results into %send, keyed by mail address to be notified. 34 50 my %send; 35 foreach my $entry (@$data) { 36 next unless $entry->{who}; 37 my @emails = Foswiki::Func::wikinameToEmails( $entry->{who} ); 51 for my $itemData ( split $sep, $data ) { 52 my ( $topic, $waitingFor, $summary ) = 53 $itemData =~ m/topic='(.*?)' WaitingFor='(.*?)' Summary='(.*)'/; 54 next unless $waitingFor; 55 $waitingFor =~ s/^\s+//; 56 $waitingFor =~ s/\s+$//; 57 my @emails; 58 foreach my $waitname ( split( /[,\s]/, $waitingFor ) ) { 59 $waitname =~ s/Foswiki://; 60 my @waitemails = Foswiki::Func::wikinameToEmails($waitname); 61 push @emails, @waitemails; 62 } 38 63 unless ( scalar(@emails) ) { 39 print STDERR 40 "$0: $entry->{topic}: $entry->{who} has no email address\n"; 64 print STDERR "$0: $topic: $waitingFor has no email address\n"; 41 65 next; 42 66 } 43 67 foreach my $email (@emails) { 44 push( @{ $send{$email} }, $entry->{topic} );68 push( @{ $send{$email} }, { topic => $topic, summary => $summary } ); 45 69 } 46 70 } … … 50 74 my $template = <DATA>; 51 75 while ( my ( $email, $items ) = each %send ) { 52 my $list = join( "\n", map { 'http://foswiki.org/Tasks/' . $_ } @$items ); 76 my $list = join( "\n\n", 77 map { $_->{summary} . "\nhttp://foswiki.org/Tasks/" . $_->{topic} } 78 @$items ); 53 79 my $mail = $template; 54 80 $mail =~ s/%EMAILTO%/$email/g; 55 81 $mail =~ s/%TASK_LIST%/$list/g; 56 82 $mail = Foswiki::Func::expandCommonVariables($mail); 57 my $e = Foswiki::Func::sendEmail($mail); 58 print STDERR "$0: error sending mail: $e\n" if $e; 83 if ($sendMail) { 84 my $e = Foswiki::Func::sendEmail($mail); 85 print STDERR "$0: error sending mail: $e\n" if $e; 86 } 87 else { 88 print "$mail\n"; 89 } 59 90 } 60 91 1; … … 66 97 Content-Type: text/plain 67 98 Content-Transfer-Encoding: 8bit 99 68 100 69 101 This is an automated e-mail from Foswiki.org
Note: See TracChangeset
for help on using the changeset viewer.
