[freeside-commits] freeside/FS/FS TicketSystem.pm,1.4,1.5
Mark Wells
mark at wavetail.420.am
Tue Jan 25 02:13:18 PST 2011
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv14078/FS/FS
Modified Files:
TicketSystem.pm
Log Message:
ticket escalation, part 2, RT#8254
Index: TicketSystem.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/TicketSystem.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -d -r1.4 -r1.5
--- TicketSystem.pm 30 Nov 2010 20:24:02 -0000 1.4
+++ TicketSystem.pm 25 Jan 2011 10:13:15 -0000 1.5
@@ -29,23 +29,61 @@
sub _upgrade_data {
return if $system ne 'RT_Internal';
-
my ($class, %opts) = @_;
- my ($t, $exec, @fields) = map { driver_name =~ /^mysql/i ? $_ : lc($_) }
- (qw( ScripConditions ExecModule
- Name Description ExecModule ApplicableTransTypes
- Creator Created LastUpdatedBy LastUpdated));
- my $count_sql = "SELECT COUNT(*) FROM $t WHERE $exec = 'CustomFieldChange'";
- my $sth = dbh->prepare($count_sql) or die dbh->errstr;
- $sth->execute or die $sth->errstr;
- my $total = $sth->fetchrow_arrayref->[0];
- return if $total > 0;
- my $insert_sql = "INSERT INTO $t (".join(',', at fields).") VALUES (".
- "'On Custom Field Change', 'When a custom field is changed to some value',
- 'CustomFieldChange', 'Any', 1, CURRENT_DATE, 1, CURRENT_DATE )";
- $sth = dbh->prepare($insert_sql) or die dbh->errstr;
- $sth->execute or die $sth->errstr;
+ # go ahead and use the RT API for this
+
+ FS::TicketSystem->init;
+ my $session = FS::TicketSystem->session();
+ my $CurrentUser = $session->{'CurrentUser'}
+ or die 'freeside-upgrade must run as a valid RT user';
+
+ # CustomFieldChange scrip condition
+ my $ScripCondition = RT::ScripCondition->new($CurrentUser);
+ $ScripCondition->LoadByCols('ExecModule' => 'CustomFieldChange');
+ if (!defined($ScripCondition->Id)) {
+ my ($val, $msg) = $ScripCondition->Create(
+ 'Name' => 'On Custom Field Change',
+ 'Description' => 'When a custom field is changed to some value',
+ 'ExecModule' => 'CustomFieldChange',
+ 'ApplicableTransTypes' => 'Any',
+ );
+ die $msg if !$val;
+ }
+
+ # SetPriority scrip action
+ my $ScripAction = RT::ScripAction->new($CurrentUser);
+ $ScripAction->LoadByCols('ExecModule' => 'SetPriority');
+ if (!defined($ScripAction->Id)) {
+ my ($val, $msg) = $ScripAction->Create(
+ 'Name' => 'Set Priority',
+ 'Description' => 'Set ticket priority',
+ 'ExecModule' => 'SetPriority',
+ 'Argument' => '',
+ );
+ die $msg if !$val;
+ }
+
+ # EscalateQueue custom field and friends
+ my $CF = RT::CustomField->new($CurrentUser);
+ $CF->Load('EscalateQueue');
+ if (!defined($CF->Id)) {
+ my ($val, $msg) = $CF->Create(
+ 'Name' => 'EscalateQueue',
+ 'Type' => 'Select',
+ 'MaxValues' => 1,
+ 'LookupType' => 'RT::Queue',
+ 'Description' => 'Escalate to Queue',
+ 'ValuesClass' => 'RT::CustomFieldValues::Queues', #magic!
+ );
+ die $msg if !$val;
+ my $OCF = RT::ObjectCustomField->new($CurrentUser);
+ ($val, $msg) = $OCF->Create(
+ 'CustomField' => $CF->Id,
+ 'ObjectId' => 0,
+ );
+ die $msg if !$val;
+ }
return;
}
More information about the freeside-commits
mailing list