import torrus 1.0.9
[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
33   my ($class, %opts) = @_;
34   my ($t, $exec, @fields) = map { driver_name =~ /^mysql/i ? $_ : lc($_) }
35   (qw( ScripConditions ExecModule
36     Name Description ExecModule ApplicableTransTypes
37     Creator Created LastUpdatedBy LastUpdated));
38   my $count_sql = "SELECT COUNT(*) FROM $t WHERE $exec = 'CustomFieldChange'";
39   my $sth = dbh->prepare($count_sql) or die dbh->errstr;
40   $sth->execute or die $sth->errstr;
41   my $total = $sth->fetchrow_arrayref->[0];
42   return if $total > 0;
43
44   my $insert_sql = "INSERT INTO $t (".join(',',@fields).") VALUES (".
45   "'On Custom Field Change', 'When a custom field is changed to some value',
46   'CustomFieldChange', 'Any', 1, CURRENT_DATE, 1, CURRENT_DATE )";
47   $sth = dbh->prepare($insert_sql) or die dbh->errstr;
48   $sth->execute or die $sth->errstr;
49   return;
50 }
51
52 1;