[rt-users] RT tool & RecordTransaction => 0

Bart bart at pleh.info
Thu Dec 8 05:46:36 EST 2011


Damn, this really is kinda cool ^_^ (learn something new every day)

To recap what I did.

# Go to the place where all the actions are located

cd /opt/rt4/lib/RT/Action

# Copy EscalatePriority to TEST.pm, I needed an example ;)

cp EscalatePriority.pm TEST.pm

# Edit TEST.pm to look like this (full content)

=head1 NAME

  RT::Action::TEST

=head1 DESCRIPTION

Some test script, will increase the value of a CF by 5.

    CF = CF +  5
=cut


package RT::Action::TEST;
use base 'RT::Action';

use strict;

sub Describe  {
  my $self = shift;
  return (ref $self . " will increase the value of a CF by 5..");
}

sub Prepare  {
    my $self = shift;
    my $new_value = $self->TicketObj-> FirstCustomFieldValue( 'Teller New'
) + 5;
    $self->TicketObj->AddCustomFieldValue(Field => 'Teller New', Value =>
$new_value, RecordTransaction => 0 );
    return 1;
}

sub Commit {
    # ---- I'll see if I can add some error logging here ----
}

# ---- Is this one needed? ----
RT::Base->_ImportOverlays();

1;

# Then launch rt-crontool like this as a test for all new tickets: (it
should edit roughly 6000 tickets in my test environment)

/opt/rt4/bin/rt-crontool --search RT::Search::FromSQL --search-arg "status
= 'new'" --action RT::Action::TEST

The last bit takes a while to complete but I find that understandable (it's
a slow test server, it's swapping memory like crazy and CPU load is rather
high, production has more memory and more CPU's / stronger CPU's so it
shouldn't be much of a problem there ^_~)

One last question though, this custom action is only loaded when I
explicitly call for it? (I assume yes, but want to be sure if it)

Other then that this is allot "cleaner" then hacking the SQL database. (and
it's silent ^_^)

-- Bart


Op 8 december 2011 11:17 schreef Ruslan Zakirov <ruz at bestpractical.com> het
volgende:

> On Thu, Dec 8, 2011 at 14:01, Bart <bart at pleh.info> wrote:
> > Can the rt-crontool launch an internal RT scrip (e.g. a global scrip or
> > something like that) as action instead of the actions that I come across
> at
> > the examples?
>
> It's exactly what it does - replays custom condition, scrip and
> template combination on every ticket returned by a custom search.
>
> You need RT::Action::IncreaseCustomField module and there do something
> like:
>
> my ($status, $msg) = $ticket->AddCustomFieldValue(
>    Field => "CF",
>    Value => $ticket->FirstCustomFieldValue("CF") + 5,
> );
>
>
> --
> Best regards, Ruslan.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20111208/fdfee9d7/attachment.htm>


More information about the rt-users mailing list