File: populate-database

package info (click to toggle)
rtfm 2.0.3-1.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 808 kB
  • ctags: 220
  • sloc: perl: 3,426; sh: 153; makefile: 144
file content (76 lines) | stat: -rw-r--r-- 1,947 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl -w
# BEGIN LICENSE BLOCK
# 
#  Copyright (c) 2002-2003 Jesse Vincent <jesse@bestpractical.com>
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of version 2 of the GNU General Public License 
#  as published by the Free Software Foundation.
# 
#  A copy of that license should have arrived with this
#  software, but in any event can be snarfed from www.gnu.org.
# 
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
# 
# END LICENSE BLOCK

use strict;

use lib qw(/opt/rt3/lib/);

use RT;
RT::LoadConfig();
RT::Init();

use RT::FM::ClassCollection;
use RT::FM::CustomFieldCollection;

use vars qw/ @Classes @CustomFields @ClassCFs/;

my $datafile = shift;

require "$datafile";


# Create classes
print "Creating classes: ";
foreach my $class (@Classes) {
        my $obj = RT::FM::Class->new($RT::SystemUser);
        my ($val, $msg) = $obj->Create(%$class);
        if ( $val  ) { 
                print $val .".";
        } else {
                die $msg;
        }       
}
        print "\n";


# Create custom fields
foreach my $CustomField (@CustomFields) {
        my $obj = RT::FM::CustomField->new($RT::SystemUser);

        my $Classes = $CustomField->{'Classes'};
        delete $CustomField->{'Classes'};
        my $values = $CustomField->{'Values'};
        delete $CustomField->{'Values'};

        my ($val, $msg) = $obj->Create(%$CustomField);
        if ( $val  ) { 
                print $val .".";
        } else {
                die $msg;
        }       


        foreach my $value (@$values) {
                $obj->AddValue(%$value);
        }
        foreach my $class (@$Classes) {
                $obj->AddToClass($class);
        }
        print "\n";
}