This commit was generated by cvs2svn to compensate for changes in r11022,
[freeside.git] / FS / FS / TicketSystem.pm
1 package FS::TicketSystem;
2
3 use strict;
4 use vars qw( $conf $system $AUTOLOAD );
5 use FS::Conf;
6 use FS::UID qw( dbh driver_name );
7
8 FS::UID->install_callback( sub { 
9   $conf = new FS::Conf;
10   $system = $conf->config('ticket_system');
11 } );
12
13 sub AUTOLOAD {
14   my $self = shift;
15
16   my($sub)=$AUTOLOAD;
17   $sub =~ s/.*://;
18
19   my $conf = new FS::Conf;
20   die "FS::TicketSystem::$AUTOLOAD called, but no ticket system configured\n"
21     unless $system;
22
23   eval "use FS::TicketSystem::$system;";
24   die $@ if $@;
25
26   $self .= "::$system";
27   $self->$sub(@_);
28 }
29
30 sub _upgrade_data {
31   return if $system ne 'RT_Internal';
32   my ($class, %opts) = @_;
33
34   # go ahead and use the RT API for this
35   
36   FS::TicketSystem->init;
37   my $session = FS::TicketSystem->session();
38   my $CurrentUser = $session->{'CurrentUser'}
39     or die 'freeside-upgrade must run as a valid RT user';
40
41   # CustomFieldChange scrip condition
42   my $ScripCondition = RT::ScripCondition->new($CurrentUser);
43   $ScripCondition->LoadByCols('ExecModule' => 'CustomFieldChange');
44   if (!defined($ScripCondition->Id)) {
45     my ($val, $msg) = $ScripCondition->Create(
46       'Name' => 'On Custom Field Change',
47       'Description' => 'When a custom field is changed to some value',
48       'ExecModule' => 'CustomFieldChange',
49       'ApplicableTransTypes' => 'Any',
50     );
51     die $msg if !$val;
52   }
53
54   # SetPriority scrip action
55   my $ScripAction = RT::ScripAction->new($CurrentUser);
56   $ScripAction->LoadByCols('ExecModule' => 'SetPriority');
57   if (!defined($ScripAction->Id)) {
58     my ($val, $msg) = $ScripAction->Create(
59       'Name' => 'Set Priority',
60       'Description' => 'Set ticket priority',
61       'ExecModule' => 'SetPriority',
62       'Argument' => '',
63     );
64     die $msg if !$val;
65   }
66
67   # EscalateQueue custom field and friends
68   my $CF = RT::CustomField->new($CurrentUser);
69   $CF->Load('EscalateQueue');
70   if (!defined($CF->Id)) {
71     my ($val, $msg) = $CF->Create(
72       'Name' => 'EscalateQueue',
73       'Type' => 'Select',
74       'MaxValues' => 1,
75       'LookupType' => 'RT::Queue',
76       'Description' => 'Escalate to Queue',
77       'ValuesClass' => 'RT::CustomFieldValues::Queues', #magic!
78     );
79     die $msg if !$val;
80     my $OCF = RT::ObjectCustomField->new($CurrentUser);
81     ($val, $msg) = $OCF->Create(
82       'CustomField' => $CF->Id,
83       'ObjectId' => 0,
84     );
85     die $msg if !$val;
86   }
87   return;
88 }
89
90 1;