3 # $Header: /home/cvs/cvsroot/freeside/rt/tools/Attic/insertdata,v 1.1 2002-08-12 06:17:08 ivan Exp $
4 # RT is (c) 1996-2002 Jesse Vincent (jesse@bestpractical.com);
8 use vars qw($VERSION $Handle $Nobody $SystemUser $item);
10 use lib "!!RT_LIB_PATH!!";
11 use lib "!!RT_ETC_PATH!!";
13 #This drags in RT's config.pm
22 my $LastVersion = shift || undef;
23 my $LastMinorVersion = undef;
26 $RT::Handle = new RT::Handle($RT::DatabaseType);
27 $RT::Handle->Connect();
29 #Put together a current user object so we can create a User object
30 my $CurrentUser = new RT::CurrentUser();
33 if ( $LastVersion =~ /^2.0.(\d+)$/ ) {
34 $LastMinorVersion = $1;
35 print "Looking for new objects to add to the database"
36 . " since $LastVersion\n\n";
39 print "This tool does not support upgrades from development releases "
40 . "or non 2.0.x versions";
43 else { # this is a virgin install
44 print "Checking for existing system user...";
45 my $test_user = RT::User->new($CurrentUser);
46 $test_user->Load('RT_System');
47 if ( $test_user->id ) {
48 print "Found!\n\nYou appear to have already run insertdata.\n"
49 . "Exiting, so as not to clobber your existing data. To ERASE your\n"
50 . "RT database and start over, type 'make dropdb; make install' in\n"
51 . "the RT installation directory. If you just meant to upgrade the\n"
52 . "content of your database, rerun this program as: \n",
54 . "where <version> is the last RELEASED version of RT you installed\n"
55 . "for example, if you're upgrading from 2.0.4, you'd type:\n"
61 print "not found. This appears to be a new installation";
64 print "Creating system user...";
65 my $RT_System = new RT::User($CurrentUser);
67 my ( $val, $msg ) = $RT_System->_BootstrapCreate(
69 RealName => 'The RT System itself',
71 'Do not delete or modify this user. It is integral to RT\'s internal database structures',
86 #now that we bootstrapped that little bit, we can use the standard RT cli
87 # helpers to do what we need
89 use RT::Interface::CLI qw(CleanEnv LoadConfig DBConnect
90 GetCurrentUser GetMessageContent);
92 #Clean out all the nasties from the environment
95 #Load etc/config.pm and drop privs
98 #Connect to the database and get RT::SystemUser and RT::Nobody loaded
101 $CurrentUser->LoadByName('RT_System');
107 unless ($LastVersion) {
111 RealName => 'Nobody in particular',
112 Comments => 'Do not delete or modify this user. It is integral '
113 . 'to RT\'s internal data structures',
120 RealName => 'Enoch Root',
121 Password => 'password',
122 EmailAddress => "root\@localhost",
123 Comments => 'SuperUser',
134 unless ($LastVersion) {
138 Description => 'Pseudogroup for internal use',
143 Description => 'Pseudogroup for internal use',
148 Description => 'Pseudogroup for internal use',
153 Description => 'Pseudogroup for internal use',
158 Description => 'Pseudogroup for internal use',
169 unless ($LastVersion) {
170 @acl = ( #TODO: make this actually take the serial # granted to root.
173 PrincipalType => 'User',
174 RightName => 'SuperUser',
175 RightScope => 'System',
176 RightAppliesTo => '0'
180 PrincipalType => 'User',
181 RightName => 'SuperUser',
182 RightScope => 'System',
183 RightAppliesTo => '0'
188 PrincipalType => 'User',
189 RightName => 'SuperUser',
190 RightScope => 'System',
191 RightAppliesTo => '0'
202 unless ($LastVersion) {
206 Description => 'The default queue',
207 CorrespondAddress => "rt\@localhost",
208 CommentAddress => "rt-comment\@localhost"
219 unless ($LastVersion) {
223 Name => 'AutoreplyToRequestors',
225 'Always sends a message to the requestors independent of message sender',
226 ExecModule => 'Autoreply',
227 Argument => 'Requestor'
230 Name => 'NotifyRequestors',
231 Description => 'Sends a message to the requestors',
232 ExecModule => 'Notify',
233 Argument => 'Requestor'
236 Name => 'NotifyOwnerAsComment',
237 Description => 'Sends mail to the owner',
238 ExecModule => 'NotifyAsComment',
242 Name => 'NotifyOwner',
243 Description => 'Sends mail to the owner',
244 ExecModule => 'Notify',
248 Name => 'NotifyAdminCcsAsComment',
249 Description => 'Sends mail to the administrative Ccs as a comment',
250 ExecModule => 'NotifyAsComment',
251 Argument => 'AdminCc'
254 Name => 'NotifyAdminCcs',
255 Description => 'Sends mail to the administrative Ccs',
256 ExecModule => 'Notify',
257 Argument => 'AdminCc'
261 Name => 'NotifyRequestorsAndCcsAsComment',
262 Description => 'Send mail to requestors and Ccs as a comment',
263 ExecModule => 'NotifyAsComment',
264 Argument => 'Requestor,Cc'
268 Name => 'NotifyRequestorsAndCcs',
269 Description => 'Send mail to requestors and Ccs',
270 ExecModule => 'Notify',
271 Argument => 'Requestor,Cc'
275 Name => 'NotifyAllWatchersAsComment',
276 Description => 'Send mail to all watchers',
277 ExecModule => 'NotifyAsComment',
281 Name => 'NotifyAllWatchers',
282 Description => 'Send mail to all watchers',
283 ExecModule => 'Notify',
289 if ( $LastMinorVersion < 12 ) {
293 Name => 'NotifyOtherRecipientsAsComment',
294 Description => 'Sends mail to explicitly listed Ccs and Bccs',
295 ExecModule => 'NotifyAsComment',
296 Argument => 'OtherRecipients'
299 Name => 'NotifyOtherRecipients',
300 Description => 'Sends mail to explicitly listed Ccs and Bccs',
301 ExecModule => 'Notify',
302 Argument => 'OtherRecipients'
309 # {{{ ScripConditions
312 unless ($LastVersion) {
316 Description => 'When a ticket is created',
317 ApplicableTransTypes => 'Create',
318 ExecModule => 'AnyTransaction',
322 Name => 'OnTransaction',
323 Description => 'When anything happens',
324 ApplicableTransTypes => 'Any',
325 ExecModule => 'AnyTransaction',
329 Name => 'OnCorrespond',
330 Description => 'Whenever correspondence comes in',
331 ApplicableTransTypes => 'Correspond',
332 ExecModule => 'AnyTransaction',
338 Description => 'Whenever comments come in',
339 ApplicableTransTypes => 'Comment',
340 ExecModule => 'AnyTransaction'
345 Description => 'Whenever a ticket\'s status changes',
346 ApplicableTransTypes => 'Status',
347 ExecModule => 'AnyTransaction',
352 Description => 'Whenever a ticket is resolved.',
353 ApplicableTransTypes => 'Status',
354 ExecModule => 'StatusChange',
355 Argument => 'resolved'
367 unless ($LastVersion) {
372 Description => 'Default Autoresponse Template',
373 Content => 'Subject: AutoReply: {$Ticket->Subject}
378 This message has been automatically generated in response to the
379 creation of a trouble ticket regarding:
380 "{$Ticket->Subject()}",
381 a summary of which appears below.
383 There is no need to reply to this message right now. Your ticket has been
384 assigned an ID of [{$rtname} #{$Ticket->id()}].
386 Please include the string:
388 [{$rtname} #{$Ticket->id}]
390 in the subject line of all future correspondence about this issue. To do so,
391 you may reply to this message.
394 {$Ticket->QueueObj->CorrespondAddress()}
396 -------------------------------------------------------------------------
397 {$Transaction->Content()}
405 Name => 'Transaction',
406 Description => 'Default transaction template',
410 {$Transaction->CreatedAsString}: Request {$Ticket->id} was acted upon.
411 Transaction: {$Transaction->Description}
412 Queue: {$Ticket->QueueObj->Name}
413 Subject: {$Transaction->Subject || $Ticket->Subject || "(No subject given)"}
414 Owner: {$Ticket->OwnerObj->Name}
415 Requestors: {$Ticket->Requestors->EmailsAsString()}
416 Status: {$Ticket->Status}
417 Ticket <URL: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id} >
418 -------------------------------------------------------------------------
419 {$Transaction->Content()}'
425 Name => 'AdminCorrespondence',
426 Description => 'Default admin correspondence template',
430 <URL: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id} >
432 {$Transaction->Content()}'
437 Name => 'Correspondence',
438 Description => 'Default correspondence template',
441 {$Transaction->Content()}'
446 Name => 'AdminComment',
447 Description => 'Default admin comment template',
449 'Subject: [Comment] {my $s=($Transaction->Subject||$Ticket->Subject); $s =~ s/\\[Comment\\]//g; $comment =~ s/^Re//i; $s;}
452 {$RT::WebURL}Ticket/Display.html?id={$Ticket->id}
453 This is a comment. It is not sent to the Requestor(s):
455 {$Transaction->Content()}
461 Name => 'StatusChange',
462 Description => 'Ticket status changed',
463 Content => 'Subject: Status Changed to: {$Transaction->NewValue}
466 {$RT::WebURL}Ticket/Display.html?id={$Ticket->id}
468 {$Transaction->Content()}
476 Description => 'Ticket Resolved',
477 Content => 'Subject: Ticket Resolved
479 According to our records, your request has been resolved. If you have any
480 further questions or concerns, please respond to this message.
491 unless ($LastVersion) {
494 ScripCondition => 'OnCreate',
495 ScripAction => 'AutoreplyToRequestors',
496 Template => 'Autoreply'
499 ScripCondition => 'OnCreate',
500 ScripAction => 'NotifyAdminCcs',
501 Template => 'Transaction',
504 ScripCondition => 'OnCorrespond',
505 ScripAction => 'NotifyAllWatchers',
506 Template => 'Correspondence',
509 ScripCondition => 'OnComment',
510 ScripAction => 'NotifyAdminCcsAsComment',
511 Template => 'AdminComment',
515 if ( $LastMinorVersion < 12 ) {
519 ScripCondition => 'OnComment',
520 ScripAction => 'NotifyOtherRecipientsAsComment',
521 Template => 'Correspondence',
524 ScripCondition => 'OnCorrespond',
525 ScripAction => 'NotifyOtherRecipients',
526 Template => 'Correspondence',
532 print "Creating ACL...";
535 my $new_entry = new RT::ACE($CurrentUser);
537 #Using an internal function. this should never be used outside of the bootstrap script
538 my $return = $new_entry->_BootstrapRight(%$item);
543 print "Creating users...";
545 foreach $item (@users) {
546 my $new_entry = new RT::User($CurrentUser);
547 my ( $return, $msg ) = $new_entry->Create(%$item);
548 print "(Error: $msg)" unless ($return);
553 print "Creating groups...";
555 foreach $item (@groups) {
556 my $new_entry = new RT::Group($CurrentUser);
557 my $return = $new_entry->Create(%$item);
562 print "Creating queues...";
564 for $item (@queues) {
565 my $new_entry = new RT::Queue($CurrentUser);
566 my ( $return, $msg ) = $new_entry->Create(%$item);
567 print "(Error: $msg)" unless ($return);
572 print "Creating ScripActions...";
575 for $item (@ScripActions) {
576 my $new_entry = new RT::ScripAction($CurrentUser);
577 my $return = $new_entry->Create(%$item);
582 print "Creating ScripConditions...";
584 use RT::ScripCondition;
585 for $item (@ScripConditions) {
586 my $new_entry = new RT::ScripCondition($CurrentUser);
587 my $return = $new_entry->Create(%$item);
593 print "Creating templates...";
596 for $item (@templates) {
597 my $new_entry = new RT::Template($CurrentUser);
598 my $return = $new_entry->Create(%$item);
603 print "Creating Scrips...";
606 for $item (@scrips) {
607 my $new_entry = RT::Scrip->new($CurrentUser);
608 my ($return,$msg) = $new_entry->Create(%$item);
609 print "(Error: $msg)" unless ($return);
615 $RT::Handle->Disconnect();