2 use FS::UID 'adminsuidsetup';
6 my $fieldname = 'Support time';
7 my $queue = 0; #global; change to a queue id if desired
9 my $fsuser = shift @ARGV or die "Usage: rt-setup-support-time user\n";
11 my $dbh = adminsuidsetup($fsuser);
12 FS::TicketSystem->init;
13 my $session = FS::TicketSystem->session();
14 my $CurrentUser = $session->{CurrentUser}
15 or die "rt-setup-support-time must run as a valid RT user.\n";
17 $RT::Handle->BeginTransaction;
22 $RT::Handle->Rollback;
23 die "$msg (reverted changes)\n";
27 my $TicketCF = RT::CustomField->new($CurrentUser);
28 $TicketCF->LoadByCols(
30 LookupType => 'RT::Queue-RT::Ticket',
32 if (!defined($TicketCF->Id)) {
33 print "Creating ticket custom field.\n";
34 try( $TicketCF->Create(
38 LookupType => 'RT::Queue-RT::Ticket',
40 my $OCF = RT::ObjectCustomField->new($CurrentUser);
42 CustomField => $TicketCF->Id,
47 my $TxnCF = RT::CustomField->new($CurrentUser);
50 LookupType => 'RT::Queue-RT::Ticket-RT::Transaction',
52 if (!defined($TxnCF->Id)) {
53 print "Creating transaction custom field.\n";
58 LookupType => 'RT::Queue-RT::Ticket-RT::Transaction',
59 UILocation => 'TimeWorked',
61 my $OCF = RT::ObjectCustomField->new($CurrentUser);
63 CustomField => $TxnCF->Id,
68 my $ScripCondition = RT::ScripCondition->new($CurrentUser);
69 $ScripCondition->Load('On Update');
70 if (!defined($ScripCondition->Id)) {
71 print "Creating On Update condition.\n";
72 try( $ScripCondition->Create(
74 Description => 'Whenever a ticket is updated',
75 ExecModule => 'AnyTransaction',
76 ApplicableTransTypes => 'Any',
80 my $ScripAction = RT::ScripAction->new($CurrentUser);
81 $ScripAction->Load("Update $fieldname");
82 if (!defined($ScripAction->Id)) {
83 print "Creating Update $fieldname action.\n";
84 try( $ScripAction->Create(
85 Name => "Update $fieldname",
86 Description => 'Increment ticket time',
87 ExecModule => 'Accumulate',
88 Argument => $fieldname,
92 my $Template = RT::Template->new($CurrentUser);
93 $Template->Load('Blank');
94 try(0, "No blank template found") if !$Template->Id;
96 my $Scrip = RT::Scrip->new($CurrentUser);
98 ScripCondition => $ScripCondition->Id,
99 ScripAction => $ScripAction->Id,
101 if (!defined($Scrip->Id)) {
102 print "Creating scrip.\n";
104 Description => "On Transaction Update $fieldname",
105 ScripCondition => $ScripCondition->Id,
106 ScripAction => $ScripAction->Id,
107 Stage => 'TransactionCreate',
109 Template => $Template->Id,