[Rt-commit] r15589 - in rt/branches/3.999-DANGEROUS: sbin
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Wed Aug 27 23:46:26 EDT 2008
Author: sunnavy
Date: Wed Aug 27 23:46:25 2008
New Revision: 15589
Modified:
rt/branches/3.999-DANGEROUS/ (props changed)
rt/branches/3.999-DANGEROUS/sbin/rt-email-digest
Log:
r16235 at sunnavys-mb: sunnavy | 2008-08-28 11:43:35 +0800
make sbin/rt-email-digest usable in 3.999
Modified: rt/branches/3.999-DANGEROUS/sbin/rt-email-digest
==============================================================================
--- rt/branches/3.999-DANGEROUS/sbin/rt-email-digest (original)
+++ rt/branches/3.999-DANGEROUS/sbin/rt-email-digest Wed Aug 27 23:46:25 2008
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
# BEGIN BPS TAGGED BLOCK {{{
#
# COPYRIGHT:
@@ -49,58 +49,36 @@
use warnings;
use strict;
-BEGIN {
- require File::Spec;
- my @libs = ("@RT_LIB_PATH@", "@LOCAL_LIB_PATH@");
- my $bin_path;
-
- for my $lib (@libs) {
- unless ( File::Spec->file_name_is_absolute($lib) ) {
- unless ($bin_path) {
- if ( File::Spec->file_name_is_absolute(__FILE__) ) {
- $bin_path = ( File::Spec->splitpath(__FILE__) )[1];
- }
- else {
- require FindBin;
- no warnings "once";
- $bin_path = $FindBin::Bin;
- }
- }
- $lib = File::Spec->catfile( $bin_path, File::Spec->updir, $lib );
- }
- unshift @INC, $lib;
- }
-
-}
-
use Date::Format qw( strftime );
use Getopt::Long;
use RT;
-use RT::Interface::CLI qw( CleanEnv loc );
+BEGIN { RT->init_jifty }
+
+use RT::Interface::CLI qw( clean_env );
use RT::Interface::Email;
-CleanEnv();
-RT::LoadConfig();
-RT::Init();
+clean_env();
+RT::load_config();
+RT::init();
sub usage {
my ($error) = @_;
- print loc("Usage: ") . "$0 -m (daily|weekly) [--print] [--help]\n";
- print loc(
+ print _("Usage: ") . "$0 -m (daily|weekly) [--print] [--help]\n";
+ print _(
"%1 is a utility, meant to be run from cron, that dispatches all deferred RT notifications as a per-user digest.",
$0
) . "\n";
print "\n\t-m, --mode\t"
- . loc("Specify whether this is a daily or weekly run.") . "\n";
+ . _("Specify whether this is a daily or weekly run.") . "\n";
print "\t-p, --print\t"
- . loc("Print the resulting digest messages to STDOUT; don't mail them. Do not mark them as sent")
+ . _("Print the resulting digest messages to STDOUT; don't mail them. Do not mark them as sent")
. "\n";
- print "\t-h, --help\t" . loc("Print this message") . "\n";
+ print "\t-h, --help\t" . _("Print this message") . "\n";
if ( $error eq 'help' ) {
exit 0;
} else {
- print loc("Error") . ": " . loc($error) . "\n";
+ print _("Error") . ": " . _($error) . "\n";
exit 1;
}
}
@@ -160,10 +138,10 @@
# Load our template. If we cannot load the template, abort
# immediately rather than failing through many loops.
- my $digest_template = RT::Model::Template->new( RT->system_user );
+ my $digest_template = RT::Model::Template->new( current_user => RT->system_user );
my ( $ret, $msg ) = $digest_template->load('Email Digest');
unless ($ret) {
- print loc("Failed to load template")
+ print _("Failed to load template")
. " 'Email Digest': "
. $msg
. ". Cannot continue.\n";
@@ -171,20 +149,21 @@
}
( $ret, $msg ) = $digest_template->parse( Argument => $body );
unless ($ret) {
- print loc("Failed to parse template")
+ print _("Failed to parse template")
. " 'Email Digest'. Cannot continue.\n";
exit 1;
}
# Set our sender and recipient.
- $digest_template->MIMEObj->head->replace( 'From', RT->config->get('CorrespondAddress') );
- $digest_template->MIMEObj->head->replace( 'To', $to );
+ $digest_template->mime_obj->head->replace( 'From', RT->config->get('CorrespondAddress') );
+ $digest_template->mime_obj->head->replace( 'To', $to );
if ($print) {
- $digest_template->MIMEObj->print;
+ $digest_template->mime_obj->print;
return 1;
} else {
- return RT::Interface::Email::SendEmail( Entity => $digest_template->MIMEObj)
+ return RT::Interface::Email::send_email( entity =>
+ $digest_template->mime_obj)
}
}
@@ -208,9 +187,9 @@
my $deferred = $attr->content;
$deferred->{$freq}->{$user}->{'_sent'} = 1;
$txn->set_attribute(
- Name => 'DeferredRecipients',
+ name => 'DeferredRecipients',
description => 'Deferred recipients for this message',
- Content => $deferred,
+ content => $deferred,
);
}
}
@@ -223,8 +202,8 @@
# this process exactly on time.
my $OVERLAP_HEDGE = -30;
- my $since_date = RT::Date->new( RT->system_user );
- $since_date->set( Format => 'unix', Value => time() );
+ my $since_date = RT::Date->new( current_user => RT->system_user );
+ $since_date->set( format => 'unix', value => time() );
if ( $frequency eq 'daily' ) {
$since_date->add_days(-1);
} else {
@@ -240,21 +219,21 @@
my $frequency = shift;
my $since_date = since_date($frequency);
- my $txns = RT::Model::TransactionCollection->new( RT->system_user );
+ my $txns = RT::Model::TransactionCollection->new( current_user => RT->system_user );
# First limit to recent transactions.
$txns->limit(
- field => 'Created',
- OPERATOR => '>',
- VALUE => $since_date->iso
+ column => 'created',
+ operator => '>',
+ value => $since_date->iso
);
# Next limit to ticket transactions.
$txns->limit(
- field => 'ObjectType',
- OPERATOR => '=',
- VALUE => 'RT::Model::Ticket',
- ENTRYAGGREGATOR => 'AND'
+ column => 'object_type',
+ operator => '=',
+ value => 'RT::Model::Ticket',
+ entry_aggregator => 'AND'
);
my $all_digest = {};
my $sent_transactions = {};
@@ -281,20 +260,20 @@
# Has the user been disabled since a message was deferred on his/her
# behalf?
- my $user_obj = RT::Model::User->new( RT->system_user );
+ my $user_obj = RT::Model::User->new( current_user => RT->system_user );
$user_obj->load_by_email($user);
if ( $user_obj->principal_object->disabled ) {
- print STDERR loc("Skipping disabled user") . " $user\n";
+ print STDERR _("Skipping disabled user") . " $user\n";
next;
}
- print loc("Message for user") . " $user:\n\n" if $print;
+ print _("Message for user") . " $user:\n\n" if $print;
foreach my $queue ( keys %$user_digest ) {
$contents_list .= "Queue $queue:\n";
$contents_body .= "Queue $queue:\n";
foreach my $ticket ( sort keys %{ $user_digest->{$queue} } ) {
my $tkt_txns = $user_digest->{$queue}->{$ticket};
- my $ticket_obj = RT::Model::Ticket->new( RT->system_user );
+ my $ticket_obj = RT::Model::Ticket->new( current_user => RT->system_user );
$ticket_obj->load($ticket);
# Spit out the index entry for this ticket.
@@ -315,12 +294,12 @@
$contents_body .= "From: " . $msg->get_header('From') . "\n";
my $date = $msg->get_header('Date ');
unless ($date) {
- my $txn_obj = RT::Model::Transaction->new( RT->system_user );
+ my $txn_obj = RT::Model::Transaction->new( current_user => RT->system_user );
$txn_obj->load($txn);
- my $date_obj = RT::Date->new( RT->system_user );
+ my $date_obj = RT::Date->new( current_user => RT->system_user );
$date_obj->set(
- Format => 'sql',
- Value => $txn_obj->created
+ format => 'sql',
+ value => $txn_obj->created
);
$date = strftime( '%a, %d %b %Y %H:%M:%S %z',
@{ [ localtime( $date_obj->unix ) ] } );
More information about the Rt-commit
mailing list