[Rt-commit] rt branch, 4.2/rt-crontool-reminders, updated. rt-4.0.5-284-ga5cd093

Jim Brandt jbrandt at bestpractical.com
Thu Apr 19 16:07:03 EDT 2012


The branch, 4.2/rt-crontool-reminders has been updated
       via  a5cd09361df231856be25379233084c69a4580a6 (commit)
      from  b55378c5c09ab02402861b2555631ba0ac03d2ea (commit)

Summary of changes:
 bin/rt-crontool.in        |   14 ++++++++------
 docs/reminders.pod        |   10 ++++++++--
 etc/initialdata           |    5 ++---
 etc/upgrade/4.1.0/content |    5 ++---
 lib/RT/Action/Notify.pm   |   17 ++++++++++++-----
 lib/RT/Interface/Email.pm |    9 +++++++--
 6 files changed, 39 insertions(+), 21 deletions(-)

- Log -----------------------------------------------------------------
commit a5cd09361df231856be25379233084c69a4580a6
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Thu Apr 19 15:33:07 2012 -0400

    Reworked Notify options passing args in the action_arg option.

diff --git a/bin/rt-crontool.in b/bin/rt-crontool.in
index a15c0b1..8c43a87 100755
--- a/bin/rt-crontool.in
+++ b/bin/rt-crontool.in
@@ -47,6 +47,8 @@
 #
 # END BPS TAGGED BLOCK }}}
 use strict;
+use warnings;
+no warnings qw(redefine); # For loc
 use Carp;
 
 # fix lib paths, some may be relative
@@ -145,19 +147,19 @@ my $void_scrip_action = RT::ScripAction->new( $CurrentUser );
 
 #find a bunch of tickets
 my $tickets = RT::Tickets->new($CurrentUser);
-my $search  = $search->new(
+
+# $search_obj is just to differentiate from
+# the $search value provided as input
+my $search_obj  = $search->new(
     TicketsObj  => $tickets,
     Argument    => $search_arg,
     CurrentUser => $CurrentUser
 );
 
-$search->Prepare();
-
-# TicketsFound is an RT::Tickets object
-my $tickets = $search->TicketsObj;
+$search_obj->Prepare();
 
 #for each ticket we've found
-while ( my $ticket = $tickets->Next() ) {
+while ( my $ticket = $search_obj->TicketsObj->Next() ) {
     print $ticket->Id() . ":\n" if ($verbose);
 
     my $template_obj = get_template( $ticket );
diff --git a/docs/reminders.pod b/docs/reminders.pod
index 6845203..c2588a1 100644
--- a/docs/reminders.pod
+++ b/docs/reminders.pod
@@ -46,8 +46,8 @@ To schedule the reminders, add a line like the following to your RT crontab:
                    --search-arg 'Type = "reminder" and (Status = "open" or Status = "new")' \
                    --condition RT::Condition::BeforeDue \
                    --condition-arg 2d \
-                   --action RT::Action::SendEmail \
-                   --action-arg Owner \
+                   --action RT::Action::Notify \
+                   --action-arg Owner,AlwaysNotifyActor \
                    --transaction first \
                    --template 'Reminder'
 
@@ -62,6 +62,12 @@ The argument to C<RT::Condition::BeforeDue> is an amount of time in the form
 example, single values can also be passed. The run frequency in your crontab
 should be consistent with the time period you set to avoid missing reminders.
 
+The action argument tells Notify to send email to the owner of the reminder.
+The AlwaysNotifyActor argument tells Notify to send email even if
+RT's C<NotifyActor> setting is off (the default). If you don't include this,
+users won't see email for reminders they created for themselves since
+they are the actor on the transaction.
+
 The template value refers to a Template in your RT system. You can use the
 default Reminder template or create your own in Tools > Configuration >
 Global > Templates > Create. You can look at the default template for some
diff --git a/etc/initialdata b/etc/initialdata
index fb0e842..cc23bcc 100755
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -307,10 +307,9 @@ This is a comment.  It is not sent to the Requestor(s):
        Name        => 'Reminder',                           # loc
        Description => 'Default reminder template',          # loc
        Content     =>
-'To: { $Target = $Ticket->RefersTo->First->TargetObj; ($Argument eq \'TicketOwner\' ? $Target : $Ticket)->OwnerObj->EmailAddress }
-Subject: {$Ticket->Subject} is due {$Ticket->DueAsString}
+'Subject:{$Ticket->Subject} is due {$Ticket->DueAsString}
 
-This reminder is for ticket #{$Target->Id}.
+This reminder is for ticket #{$Target = $Ticket->RefersTo->First->TargetObj;$Target->Id}.
 
 {RT->Config->Get(\'WebURL\')}Ticket/Display.html?id={$Target->Id}
 '
diff --git a/etc/upgrade/4.1.0/content b/etc/upgrade/4.1.0/content
index 6625550..7ff1c82 100644
--- a/etc/upgrade/4.1.0/content
+++ b/etc/upgrade/4.1.0/content
@@ -27,10 +27,9 @@
        Name        => 'Reminder',                           # loc
        Description => 'Default reminder template',          # loc
        Content     =>
-'To: { $Target = $Ticket->RefersTo->First->TargetObj; ($Argument eq \'TicketOwner\' ? $Target : $Ticket)->OwnerObj->EmailAddress }
-Subject: {$Ticket->Subject} is due {$Ticket->DueAsString}
+'Subject:{$Ticket->Subject} is due {$Ticket->DueAsString}
 
-This reminder is for ticket #{$Target->Id}.
+This reminder is for ticket #{$Target = $Ticket->RefersTo->First->TargetObj;$Target->Id}.
 
 {RT->Config->Get(\'WebURL\')}Ticket/Display.html?id={$Target->Id}
 '
diff --git a/lib/RT/Action/Notify.pm b/lib/RT/Action/Notify.pm
index f1aef40..4dd10a7 100644
--- a/lib/RT/Action/Notify.pm
+++ b/lib/RT/Action/Notify.pm
@@ -71,8 +71,11 @@ sub Prepare {
 
 =head2 SetRecipients
 
-Sets the recipients of this meesage to Owner, Requestor, AdminCc, Cc or All. 
-Explicitly B<does not> notify the creator of the transaction by default
+Sets the recipients of this message to Owner, Requestor, AdminCc, Cc or All. 
+Explicitly B<does not> notify the creator of the transaction by default.
+
+To send email to the selected receipients regardless of RT's NotifyActor
+configuration, include AlwaysNotifyActor in the recipients passed in.
 
 =cut
 
@@ -134,12 +137,16 @@ sub SetRecipients {
     my $creatorObj = $self->TransactionObj->CreatorObj;
     my $creator = $creatorObj->EmailAddress() || '';
 
-    #Strip the sender out of the To, Cc and AdminCc and set the 
+    # Strip the sender out of the To, Cc and AdminCc and set the 
     # recipients fields used to build the message by the superclass.
-    # unless a flag is set 
+
+    # Don't strip if AlwaysNotifyActor passed.
+
     my $TransactionCurrentUser = RT::CurrentUser->new;
     $TransactionCurrentUser->LoadByName($creatorObj->Name);
-    if (RT->Config->Get('NotifyActor',$TransactionCurrentUser)) {
+
+    if ( RT->Config->Get('NotifyActor',$TransactionCurrentUser)
+	 || $arg =~ /\bAlwaysNotifyActor\b/ ) {
         @{ $self->{'To'} }  = @To;
         @{ $self->{'Cc'} }  = @Cc;
         @{ $self->{'Bcc'} } = @Bcc;
diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index 3edb3d7..7c29cdd 100644
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -401,8 +401,13 @@ sub SendEmail {
     my $mail_command = RT->Config->Get('MailCommand');
 
     if ($mail_command eq 'testfile' and not $Mail::Mailer::testfile::config{outfile}) {
-        $Mail::Mailer::testfile::config{outfile} = File::Temp->new;
-        $RT::Logger->info("Storing outgoing emails in $Mail::Mailer::testfile::config{outfile}");
+
+      # File::Temp default is to remove temp files (UNLINK => 1)
+      # This keeps files around when in debug mode (UNLINK => 0)
+      my $unlink = !(RT->Config->Get('LogToScreen') eq 'debug');
+
+      $Mail::Mailer::testfile::config{outfile} = File::Temp->new ( UNLINK => $unlink );
+      $RT::Logger->info("Storing outgoing emails in $Mail::Mailer::testfile::config{outfile}");
     }
 
     # if it is a sub routine, we just return it;

-----------------------------------------------------------------------


More information about the Rt-commit mailing list