[rt-commit] [svn] r497 - in rt/branches/rt-3.1/lib/RT: . Action
Interface
leira at fsck.com
leira at fsck.com
Sun Mar 7 23:57:13 EST 2004
Author: leira
Date: Sun Mar 7 23:57:12 2004
New Revision: 497
Added:
rt/branches/rt-3.1/lib/RT/Record_Overlay.pm
Modified:
rt/branches/rt-3.1/lib/RT/Action/CreateTickets.pm
rt/branches/rt-3.1/lib/RT/Interface/Web.pm
rt/branches/rt-3.1/lib/RT/Record.pm
Log:
Support for offline ticket creation/update.
Modified: rt/branches/rt-3.1/lib/RT/Action/CreateTickets.pm
==============================================================================
--- rt/branches/rt-3.1/lib/RT/Action/CreateTickets.pm (original)
+++ rt/branches/rt-3.1/lib/RT/Action/CreateTickets.pm Sun Mar 7 23:57:12 2004
@@ -25,6 +25,7 @@
require RT::Action::Generic;
use strict;
+use warnings;
use vars qw/@ISA/;
@ISA = qw(RT::Action::Generic);
@@ -39,7 +40,7 @@
=head1 SYNOPSIS
- ===Create-Ticket: codereview
+ ===Create-Ticket codereview
Subject: Code review for {$Tickets{'TOP'}->Subject}
Depended-On-By: TOP
Content: Someone has created a ticket. you should review and approve it,
@@ -307,153 +308,214 @@
#Do what we need to do and send it out.
sub Commit {
my $self = shift;
- my (@links, @postponed);
-
- # XXX: cargo cult programming that works. i'll be back.
- use bytes;
# Create all the tickets we care about
return(1) unless $self->TicketObj->Type eq 'ticket';
+ $self->CreateByTemplate($self->TicketObj);
+ $self->UpdateByTemplate($self->TicketObj);
+ return(1);
+}
+# }}}
+
+# {{{ sub Prepare
+
+sub Prepare {
+ my $self = shift;
+
+ unless ($self->TemplateObj) {
+ $RT::Logger->warning("No template object handed to $self\n");
+ }
+
+ unless ($self->TransactionObj) {
+ $RT::Logger->warning("No transaction object handed to $self\n");
+
+ }
+
+ unless ($self->TicketObj) {
+ $RT::Logger->warning("No ticket object handed to $self\n");
+
+ }
+
+ $self->Parse($self->TemplateObj->Content);
+ return 1;
+
+}
+
+# }}}
+
+# }}}
+
+sub CreateByTemplate {
+ my $self = shift;
+ my $top = shift;
+
+ # XXX: cargo cult programming that works. i'll be back.
+ use bytes;
+
%T::Tickets = ();
- foreach my $template_id ( @{ $self->{'template_order'} } ) {
- $T::Tickets{'TOP'} = $T::TOP = $self->TicketObj;
+ my $ticketargs;
+ my (@links, @postponed);
+ foreach my $template_id ( @{ $self->{'create_tickets'} } ) {
+ $T::Tickets{'TOP'} = $T::TOP = $top if $top;
$RT::Logger->debug("Workflow: processing $template_id of $T::TOP");
$T::ID = $template_id;
- @T::AllID = @{ $self->{'template_order'} };
+ @T::AllID = @{ $self->{'create_tickets'} };
- my $template = Text::Template->new(
- TYPE => 'STRING',
- SOURCE => $self->{'templates'}->{$template_id}
- );
-
- $RT::Logger->debug("Workflow: evaluating\n$self->{templates}{$template_id}");
-
- my $err;
- my $filled_in = $template->fill_in( PACKAGE => 'T', BROKEN => sub {
- $err = { @_ }->{error};
- } );
-
- $RT::Logger->debug("Workflow: yielding\n$filled_in");
-
- if ($err) {
- $RT::Logger->error("Ticket creation failed for ".$self->TicketObj->Id." ".$err);
- while (my ($k, $v) = each %T::X) {
- $RT::Logger->debug("Eliminating $template_id from ${k}'s parents.");
- delete $v->{$template_id};
+ ($T::Tickets{$template_id}, $ticketargs) = $self->ParseLines($template_id,
+ \@links, \@postponed);
+
+ # Now we have a %args to work with.
+ # Make sure we have at least the minimum set of
+ # reasonable data and do our thang
+
+ my ($id, $transid, $msg) = $T::Tickets{$template_id}->Create(%$ticketargs);
+ if (!$id) {
+ if ($self->TicketObj) {
+ $msg = "Couldn't create related ticket $template_id for ".
+ $self->TicketObj->Id ." ".$msg;
+ } else {
+ $msg = "Couldn't create ticket $template_id " . $msg;
}
+
+ $RT::Logger->error($msg);
next;
}
- my %args;
- my @lines = ( split ( /\n/, $filled_in ) );
- while ( defined(my $line = shift @lines) ) {
- if ( $line =~ /^(.*?):(?:\s+(.*))?$/ ) {
- my $value = $2;
- my $tag = lc ($1);
- $tag =~ s/-//g;
+ $RT::Logger->debug("Assigned $template_id with $id");
+ $T::Tickets{$template_id}->SetOriginObj($self->TicketObj)
+ if $self->TicketObj &&
+ $T::Tickets{$template_id}->can('SetOriginObj');
+ }
- if (ref($args{$tag})) { #If it's an array, we want to push the value
- push @{$args{$tag}}, $value;
- }
- elsif (defined ($args{$tag})) { #if we're about to get a second value, make it an array
- $args{$tag} = [$args{$tag}, $value];
- }
- else { #if there's nothing there, just set the value
- $args{ $tag } = $value;
- }
+ # postprocessing: add links
- if ( $tag eq 'content' ) { #just build up the content
- # convert it to an array
- $args{$tag} = defined($value) ? [ $value."\n" ] : [];
- while ( defined(my $l = shift @lines) ) {
- last if ($l =~ /^ENDOFCONTENT\s*$/) ;
- push @{$args{'content'}}, $l."\n";
- }
- }
- }
- }
+ while (my $ticket = shift(@links)) {
+ $RT::Logger->debug("Handling links for " . $ticket->Id);
+ my %args = %{shift(@links)};
- foreach my $date qw(due starts started resolved) {
- my $dateobj = RT::Date->new($RT::SystemUser);
- next unless $args{$date};
- if ($args{$date} =~ /^\d+$/) {
- $dateobj->Set(Format => 'unix', Value => $args{$date});
- } else {
- $dateobj->Set(Format => 'unknown', Value => $args{$date});
+ foreach my $type ( keys %LINKTYPEMAP ) {
+ next unless (defined $args{$type});
+ foreach my $link (
+ ref( $args{$type} ) ? @{ $args{$type} } : ( $args{$type} ) )
+ {
+ if ($link !~ m/\d+/) {
+ if (!exists $T::Tickets{$link}) {
+ $RT::Logger->debug("Skipping $type link for $link (non-existent)");
+ next;
+ }
+ $link = $T::Tickets{$link}->Id;
+ $RT::Logger->debug("Building $type link for $link: " . $T::Tickets{$link}->Id);
+ } else {
+ $RT::Logger->debug("Building $type link for $link")
+ }
+
+ my ( $wval, $wmsg ) = $ticket->AddLink(
+ Type => $LINKTYPEMAP{$type}->{'Type'},
+ $LINKTYPEMAP{$type}->{'Mode'} => $link,
+ Silent => 1
+ );
+
+ $RT::Logger->warning("AddLink thru $link failed: $wmsg") unless $wval;
+ # push @non_fatal_errors, $wmsg unless ($wval);
}
- $args{$date} = $dateobj->ISO;
+
}
- my $mimeobj = MIME::Entity->new();
- $mimeobj->build(Type => $args{'contenttype'},
- Data => $args{'content'});
- # Now we have a %args to work with.
- # Make sure we have at least the minimum set of
- # reasonable data and do our thang
- $T::Tickets{$template_id} ||= RT::Ticket->new($RT::SystemUser);
+ }
- # Deferred processing
- push @links, (
- $T::Tickets{$template_id}, {
- DependsOn => $args{'dependson'},
- DependedOnBy => $args{'dependedonby'},
- RefersTo => $args{'refersto'},
- ReferredToBy => $args{'referredtoby'},
- Members => $args{'members'},
- MemberOf => $args{'memberof'},
- }
- );
+ # postponed actions -- Status only, currently
+ while (my $ticket = shift(@postponed)) {
+ $RT::Logger->debug("Handling postponed actions for $ticket");
+ my %args = %{shift(@postponed)};
- push @postponed, (
- # Status is postponed so we don't violate dependencies
- $T::Tickets{$template_id}, {
- Status => $args{'status'},
- }
- );
+ $ticket->SetStatus($args{Status}) if defined $args{Status};
+ }
+}
- $args{'requestor'} ||= $self->TicketObj->Requestors->MemberEmailAddresses;
+sub UpdateByTemplate {
+ my $self = shift;
+ my $top = shift;
- $args{'type'} ||= 'ticket';
+ # XXX: cargo cult programming that works. i'll be back.
+ use bytes;
- my %ticketargs = ( Queue => $args{'queue'},
- Subject=> $args{'subject'},
- Status => 'new',
- Due => $args{'due'},
- Starts => $args{'starts'},
- Started => $args{'started'},
- Resolved => $args{'resolved'},
- Owner => $args{'owner'},
- Requestor => $args{'requestor'},
- Cc => $args{'cc'},
- AdminCc=> $args{'admincc'},
- TimeWorked =>$args{'timeworked'},
- TimeEstimated =>$args{'timeestimated'},
- TimeLeft =>$args{'timeleft'},
- InitialPriority => $args{'initialpriority'},
- FinalPriority => $args{'finalpriority'},
- Type => $args{'type'},
- MIMEObj => $mimeobj);
-
-
- foreach my $key (keys(%args)) {
- $key =~ /^customfield(\d+)$/ or next;
- $ticketargs{ "CustomField-" . $1 } = $args{$key};
- }
+ %T::Tickets = ();
- my ($id, $transid, $msg) = $T::Tickets{$template_id}->Create(%ticketargs);
- if (!$id) {
- $RT::Logger->error(
- "Couldn't create related ticket $template_id for ".
- $self->TicketObj->Id." ".$msg
- );
+ my $ticketargs;
+ my (@links, @postponed);
+ foreach my $template_id ( @{ $self->{'update_tickets'} } ) {
+ $RT::Logger->debug("Update Workflow: processing $template_id");
+
+ $T::ID = $template_id;
+ @T::AllID = @{ $self->{'update_tickets'} };
+
+ ($T::Tickets{$template_id}, $ticketargs) = $self->ParseLines($template_id,
+ \@links, \@postponed);
+
+ # Now we have a %args to work with.
+ # Make sure we have at least the minimum set of
+ # reasonable data and do our thang
+
+ my @attribs = qw(
+ Subject
+ FinalPriority
+ Priority
+ TimeEstimated
+ TimeWorked
+ TimeLeft
+ Status
+ Queue
+ );
+
+ my $id = $template_id;
+ $id =~ s/update-(\d+).*/$1/;
+ $T::Tickets{$template_id}->Load($id);
+
+ my $msg;
+ if (!$T::Tickets{$template_id}->Id) {
+ if ($self->TicketObj) {
+ $msg = "Couldn't create related ticket $template_id for ".
+ $self->TicketObj->Id ." ".$msg;
+ } else {
+ $msg = "Couldn't create ticket $template_id " . $msg;
+ }
+
+ $RT::Logger->error($msg);
next;
}
- $RT::Logger->debug("Assigned $template_id with $id");
- $T::Tickets{$template_id}->SetOriginObj($self->TicketObj)
- if $T::Tickets{$template_id}->can('SetOriginObj');
+ my (@results) =
+ $T::Tickets{$template_id}->Update(AttributesRef => \@attribs,
+ ARGSRef => $ticketargs);
+
+ next unless $ticketargs->{'UpdateType'};
+ if ( $ticketargs->{'UpdateType'} =~ /^(private|public)$/ ) {
+ my ( $Transaction, $Description, $Object ) = $T::Tickets{$template_id}->Comment(
+ CcMessageTo => $ticketargs->{'Cc'},
+ BccMessageTo => $ticketargs->{'Bcc'},
+ MIMEObj => $ticketargs->{'MIMEObj'},
+ TimeTaken => $ticketargs->{'TimeWorked'}
+ );
+ push ( @results, $Description );
+ }
+ elsif ( $ticketargs->{'UpdateType'} eq 'response' ) {
+ my ( $Transaction, $Description, $Object ) = $T::Tickets{$template_id}->Correspond(
+ CcMessageTo => $ticketargs->{'Cc'},
+ BccMessageTo => $ticketargs->{'Bcc'},
+ MIMEObj => $ticketargs->{'MIMEObj'},
+ TimeTaken => $ticketargs->{'TimeWorked'}
+ );
+ push ( @results, $Description );
+ }
+ else {
+ push ( @results,
+ $T::Tickets{$template_id}->loc("Update type was neither correspondence nor comment.").
+ " ".
+ $T::Tickets{$template_id}->loc("Update not recorded.")
+ );
+ }
}
# postprocessing: add links
@@ -467,13 +529,17 @@
foreach my $link (
ref( $args{$type} ) ? @{ $args{$type} } : ( $args{$type} ) )
{
- if (!exists $T::Tickets{$link}) {
- $RT::Logger->debug("Skipping $type link for $link (non-existent)");
- next;
+ if ($link !~ m/\d+/) {
+ if (!exists $T::Tickets{$link}) {
+ $RT::Logger->debug("Skipping $type link for $link (non-existent)");
+ next;
+ }
+ $link = $T::Tickets{$link}->Id;
+ $RT::Logger->debug("Building $type link for $link: " . $T::Tickets{$link}->Id);
+ } else {
+ $RT::Logger->debug("Building $type link for $link")
}
- $RT::Logger->debug("Building $type link for $link: " . $T::Tickets{$link}->Id);
- $link = $T::Tickets{$link}->Id;
-
+
my ( $wval, $wmsg ) = $ticket->AddLink(
Type => $LINKTYPEMAP{$type}->{'Type'},
$LINKTYPEMAP{$type}->{'Mode'} => $link,
@@ -494,52 +560,165 @@
$ticket->SetStatus($args{Status}) if defined $args{Status};
}
-
- return(1);
}
-# }}}
-# {{{ sub Prepare
+sub Parse {
+ my $self = shift;
+ my $content = shift;
-sub Prepare {
- my $self = shift;
-
- unless ($self->TemplateObj) {
- $RT::Logger->warning("No template object handed to $self\n");
- }
-
- unless ($self->TransactionObj) {
- $RT::Logger->warning("No transaction object handed to $self\n");
+ my @template_order;
+ my $template_id;
+ foreach my $line (split(/\n/, $content)) {
+ if ($line =~ /^===Create-Ticket: (.*)$/) {
+ $template_id = "create-$1";
+ push @{$self->{'create_tickets'}},$template_id;
+ } elsif ($line =~ /^===Update-Ticket: (.*)$/) {
+ $template_id = "update-$1";
+ push @{$self->{'update_tickets'}},$template_id;
+ } else {
+ $self->{'templates'}->{$template_id} .= $line."\n";
+ }
+ }
+}
+
+sub ParseLines {
+ my $self = shift;
+ my $template_id = shift;
+ my $links = shift;
+ my $postponed = shift;
+
+ $RT::Logger->debug("Workflow: evaluating\n$self->{templates}{$template_id}");
+
+ my $template = Text::Template->new(
+ TYPE => 'STRING',
+ SOURCE => $self->{'templates'}->{$template_id}
+ );
+
+ my $err;
+ my $filled_in = $template->fill_in( PACKAGE => 'T', BROKEN => sub {
+ $err = { @_ }->{error};
+ } );
- }
-
- unless ($self->TicketObj) {
- $RT::Logger->warning("No ticket object handed to $self\n");
-
- }
-
+ $RT::Logger->debug("Workflow: yielding\n$filled_in");
+
+ if ($err) {
+ $RT::Logger->error("Ticket creation failed: ".$err);
+ while (my ($k, $v) = each %T::X) {
+ $RT::Logger->debug("Eliminating $template_id from ${k}'s parents.");
+ delete $v->{$template_id};
+ }
+ next;
+ }
+
+ my $TicketObj ||= RT::Ticket->new($RT::SystemUser);
+ my %args;
+ my @lines = ( split ( /\n/, $filled_in ) );
+ while ( defined(my $line = shift @lines) ) {
+ if ( $line =~ /^(.*?):(?:\s+(.*))?$/ ) {
+ my $value = $2;
+ my $tag = lc ($1);
+ $tag =~ s/-//g;
+
+ $value =~ s/\r$//;
+
+ if (ref($args{$tag})) { #If it's an array, we want to push the value
+ push @{$args{$tag}}, $value;
+ }
+ elsif (defined ($args{$tag})) { #if we're about to get a second value, make it an array
+ $args{$tag} = [$args{$tag}, $value];
+ }
+ else { #if there's nothing there, just set the value
+ $args{ $tag } = $value;
+ }
+
+ if ( $tag eq 'content' ) { #just build up the content
+ # convert it to an array
+ $args{$tag} = defined($value) ? [ $value."\n" ] : [];
+ while ( defined(my $l = shift @lines) ) {
+ last if ($l =~ /^ENDOFCONTENT\s*$/) ;
+ push @{$args{'content'}}, $l."\n";
+ }
+ }
+ }
+ }
+
+ foreach my $date qw(due starts started resolved) {
+ my $dateobj = RT::Date->new($RT::SystemUser);
+ next unless $args{$date};
+ if ($args{$date} =~ /^\d+$/) {
+ $dateobj->Set(Format => 'unix', Value => $args{$date});
+ } else {
+ $dateobj->Set(Format => 'unknown', Value => $args{$date});
+ }
+ $args{$date} = $dateobj->ISO;
+ }
+
+ $args{'requestor'} ||= $self->TicketObj->Requestors->MemberEmailAddresses
+ if $self->TicketObj;
+
+ $args{'type'} ||= 'ticket';
+
+ my $mimeobj = MIME::Entity->new();
+ $mimeobj->build(Type => $args{'contenttype'},
+ Data => $args{'content'});
+ my %ticketargs = ( Queue => $args{'queue'},
+ Subject=> $args{'subject'},
+ Status => 'new',
+ Due => $args{'due'},
+ Starts => $args{'starts'},
+ Started => $args{'started'},
+ Resolved => $args{'resolved'},
+ Owner => $args{'owner'},
+ Requestor => $args{'requestor'},
+ Cc => $args{'cc'},
+ AdminCc=> $args{'admincc'},
+ TimeWorked =>$args{'timeworked'},
+ TimeEstimated =>$args{'timeestimated'},
+ TimeLeft =>$args{'timeleft'},
+ InitialPriority => $args{'initialpriority'},
+ FinalPriority => $args{'finalpriority'},
+ Type => $args{'type'},
+ UpdateType => $args{'updatetype'},
+ MIMEObj => $mimeobj);
+
+ foreach my $key (keys(%args)) {
+ $key =~ /^customfield(\d+)$/ or next;
+ $ticketargs{ "CustomField-" . $1 } = $args{$key};
+ }
-my $template_id;
-foreach my $line (split(/\n/,$self->TemplateObj->Content)) {
- if ($line =~ /^===Create-Ticket: (.*)$/) {
- $template_id = $1;
- push @{$self->{'template_order'}},$template_id;
- } else {
- $self->{'templates'}->{$template_id} .= $line."\n";
- }
-
-
-}
-
- return 1;
-
-}
+ $self->GetDeferred(\%args, $TicketObj->Id, $links, $postponed);
-# }}}
+ return $TicketObj, \%ticketargs;
+}
-# }}}
+sub GetDeferred {
+ my $self = shift;
+ my $args = shift;
+ my $id = shift;
+ my $links = shift;
+ my $postponed = shift;
+
+ # Deferred processing
+ push @$links, (
+ $id, {
+ DependsOn => $args->{'dependson'},
+ DependedOnBy => $args->{'dependedonby'},
+ RefersTo => $args->{'refersto'},
+ ReferredToBy => $args->{'referredtoby'},
+ Members => $args->{'members'},
+ MemberOf => $args->{'memberof'},
+ }
+ );
+
+ push @$postponed, (
+ # Status is postponed so we don't violate dependencies
+ $id, {
+ Status => $args->{'status'},
+ }
+ );
+}
eval "require RT::Action::CreateTickets_Vendor";
die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/CreateTickets_Vendor.pm});
Modified: rt/branches/rt-3.1/lib/RT/Interface/Web.pm
==============================================================================
--- rt/branches/rt-3.1/lib/RT/Interface/Web.pm (original)
+++ rt/branches/rt-3.1/lib/RT/Interface/Web.pm Sun Mar 7 23:57:12 2004
@@ -921,52 +921,12 @@
@_
);
- my (@results);
+ my $Object = $args{'Object'};
+ my @results = $Object->Update(AttributesRef => $args{'AttributesRef'},
+ ARGSRef => $args{'ARGSRef'},
+ AttributePrefix => undef,
+ );
- my $object = $args{'Object'};
- my $attributes = $args{'AttributesRef'};
- my $ARGSRef = $args{'ARGSRef'};
- foreach my $attribute (@$attributes) {
- my $value;
- if ( defined $ARGSRef->{$attribute} ) {
- $value = $ARGSRef->{$attribute};
- }
- elsif (
- defined( $args{'AttributePrefix'} )
- && defined(
- $ARGSRef->{ $args{'AttributePrefix'} . "-" . $attribute }
- )
- ) {
- $value = $ARGSRef->{ $args{'AttributePrefix'} . "-" . $attribute };
-
- } else {
- next;
- }
-
- $value =~ s/\r\n/\n/gs;
-
- if ($value ne $object->$attribute()){
-
- my $method = "Set$attribute";
- my ( $code, $msg ) = $object->$method($value);
-
- push @results, loc($attribute) . ': ' . loc_fuzzy($msg);
-=for loc
- "[_1] could not be set to [_2].", # loc
- "That is already the current value", # loc
- "No value sent to _Set!\n", # loc
- "Illegal value for [_1]", # loc
- "The new value has been set.", # loc
- "No column specified", # loc
- "Immutable field", # loc
- "Nonexistant field?", # loc
- "Invalid data", # loc
- "Couldn't find row", # loc
- "Missing a primary key?: [_1]", # loc
- "Found Object", # loc
-=cut
- };
- }
return (@results);
}
Modified: rt/branches/rt-3.1/lib/RT/Record.pm
==============================================================================
--- rt/branches/rt-3.1/lib/RT/Record.pm (original)
+++ rt/branches/rt-3.1/lib/RT/Record.pm Sun Mar 7 23:57:12 2004
@@ -586,6 +586,8 @@
}
+eval "require RT::Record_Overlay";
+die $@ if ($@ && $@ !~ qr{^Can't locate RT/Record_Overlay.pm});
eval "require RT::Record_Vendor";
die $@ if ($@ && $@ !~ qr{^Can't locate RT/Record_Vendor.pm});
eval "require RT::Record_Local";
Added: rt/branches/rt-3.1/lib/RT/Record_Overlay.pm
==============================================================================
--- (empty file)
+++ rt/branches/rt-3.1/lib/RT/Record_Overlay.pm Sun Mar 7 23:57:12 2004
@@ -0,0 +1,123 @@
+use strict;
+no warnings qw(redefine);
+
+sub Update {
+ my $self = shift;
+
+ my %args = (
+ ARGSRef => undef,
+ AttributesRef => undef,
+ AttributePrefix => undef,
+ @_
+ );
+
+ my $attributes = $args{'AttributesRef'};
+ my $ARGSRef = $args{'ARGSRef'};
+ my @results;
+
+ foreach my $attribute (@$attributes) {
+ my $value;
+ if ( defined $ARGSRef->{$attribute} ) {
+ $value = $ARGSRef->{$attribute};
+ }
+ elsif (
+ defined( $args{'AttributePrefix'} )
+ && defined(
+ $ARGSRef->{ $args{'AttributePrefix'} . "-" . $attribute }
+ )
+ ) {
+ $value = $ARGSRef->{ $args{'AttributePrefix'} . "-" . $attribute };
+
+ } else {
+ next;
+ }
+
+ $value =~ s/\r\n/\n/gs;
+
+ if ($value ne $self->$attribute()){
+
+ my $method = "Set$attribute";
+ my ( $code, $msg ) = $self->$method($value);
+
+ push @results, $self->loc($attribute) . ': ' . $self->loc_fuzzy($msg);
+=for loc
+ "[_1] could not be set to [_2].", # loc
+ "That is already the current value", # loc
+ "No value sent to _Set!\n", # loc
+ "Illegal value for [_1]", # loc
+ "The new value has been set.", # loc
+ "No column specified", # loc
+ "Immutable field", # loc
+ "Nonexistant field?", # loc
+ "Invalid data", # loc
+ "Couldn't find row", # loc
+ "Missing a primary key?: [_1]", # loc
+ "Found Object", # loc
+=cut
+ };
+
+ }
+
+ return @results;
+}
+
+# {{{ loc_fuzzy
+
+=head2 loc_fuzzy STRING
+
+loc_fuzzy is for handling localizations of messages that may already
+contain interpolated variables, typically returned from libraries
+outside RT's control. It takes the message string and extracts the
+variable array automatically by matching against the candidate entries
+inside the lexicon file.
+
+=cut
+
+sub loc_fuzzy {
+ my $self = shift;
+ my $msg = shift;
+
+ if ($self->CurrentUser &&
+ UNIVERSAL::can($self->CurrentUser, 'loc')){
+ return($self->CurrentUser->loc_fuzzy($msg));
+ }
+ else {
+ my $u = RT::CurrentUser->new($RT::SystemUser->Id);
+ return ($u->loc_fuzzy($msg));
+ }
+}
+
+# }}}
+
+
+# {{{ loc
+
+=head2 loc ARRAY
+
+loc is a nice clean global routine which calls $session{'CurrentUser'}->loc()
+with whatever it's called with. If there is no $session{'CurrentUser'},
+it creates a temporary user, so we have something to get a localisation handle
+through
+
+=cut
+
+sub loc {
+ my $self = shift;
+
+ if ($self->CurrentUser &&
+ UNIVERSAL::can($self->CurrentUser, 'loc')){
+ return($self->CurrentUser->loc(@_));
+ }
+ elsif ( my $u = eval { RT::CurrentUser->new($RT::SystemUser->Id) } ) {
+ return ($u->loc(@_));
+ }
+ else {
+ # pathetic case -- SystemUser is gone.
+ return $_[0];
+ }
+}
+
+# }}}
+
+
+1;
More information about the Rt-commit
mailing list