3 use vars qw($PROMPT $VERSION $Handle $Nobody $SystemUser $item);
5 qw(@Groups @Users @ACL @Queues @Watchers @ScripActions @ScripConditions @Templates @CustomFields @Scrips @Attributes);
7 use lib "/usr/local/lib/rt3/lib";
8 use lib "/usr/lib/perl5/vendor_perl/5.8.8";
10 #This drags in RT's config.pm
11 # We do it in a begin block because RT::Handle needs to know the type to do its
23 use RT::ScripCondition;
35 'prompt-for-dba-password', 'force', 'debug',
36 'action=s', 'dba=s', 'dba-password=s', 'datafile=s',
40 unless ( $args{'action'} ) {
45 $| = 1; #unbuffer that output.
48 my $Handle = RT::Handle->new($RT::DatabaseType);
52 if ( $args{'prompt-for-dba-password'} ) {
53 $args{'dba-password'} = get_dba_password();
54 chomp( $args{'dba-password'} );
57 if ( $args{'action'} eq 'insert' ) {
58 insert_data( $args{'datafile'} || ($args{'datadir'}."/content") );
61 print STDERR "$0 called with an invalid --action parameter\n";
68 #Connect to the database and get RT::SystemUser and RT::Nobody loaded
71 my $CurrentUser = RT::CurrentUser->new();
72 $CurrentUser->LoadByName('RT_System');
74 # Slurp in stuff to insert from the datafile. Possible things to go in here:-
75 # @groups, @users, @acl, @queues, @ScripActions, @ScripConditions, @templates
77 print "LBLALDLJDLDKJ " . "\n";
78 print $datafile . "\n";
81 || die "Couldn't find initial data for import\n" . $@;
84 print "Creating Watchers...";
85 for $item (@Watchers) {
86 my $queue_entry = new RT::Queue($CurrentUser);
87 my $watchers = $item->{'Watchers'};
88 delete $item->{'Watchers'};
89 my ( $return, $msg ) = $queue_entry->Load($item->{'Queue'});
92 print $return. " ". $msg . "\n";
93 foreach my $watcher ( @{$watchers} ) {
94 my ( $eval, $emsg ) = $queue_entry->AddWatcher(%$watcher);
95 print "(Error: $emsg)\n" unless $eval;
98 print "(Error: $msg)" unless $return;
103 $RT::Handle->Disconnect() unless $RT::DatabaseType eq 'SQLite';
104 print "Done setting up database content.\n";
111 $0: Set up RT's database
113 --action init Initialize the database
114 drop Drop the database.
115 This will ERASE ALL YOUR DATA
116 insert Insert data into RT's database.
117 By default, will use RT's installation data.
118 To use a local or supplementary datafile, specify it
119 using the '--datafile' option below.
121 acl Initialize only the database ACLs
122 To use a local or supplementary datafile, specify it
123 using the '--datadir' option below.
125 schema Initialize only the database schema
126 To use a local or supplementary datafile, specify it
127 using the '--datadir' option below.
129 --datafile /path/to/datafile
130 --datadir /path/to/ Used to specify a path to find the local
131 database schema and acls to be installed.
135 --dba-password dba's password
136 --prompt-for-dba-password Ask for the database administrator's password interactively