X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Fdocs%2Finitialdata.pod;fp=rt%2Fdocs%2Finitialdata.pod;h=6445fb0cda2af0a32003a74bd5db18264a92d048;hp=0000000000000000000000000000000000000000;hb=ed1f84b4e8f626245995ecda5afcf83092c153b2;hpb=fe9ea9183e8a16616d6d04a7b5c7498d28e78248 diff --git a/rt/docs/initialdata.pod b/rt/docs/initialdata.pod new file mode 100644 index 000000000..6445fb0cd --- /dev/null +++ b/rt/docs/initialdata.pod @@ -0,0 +1,486 @@ +=head1 Summary of initialdata files + +It's often useful to be able to test configuration/database changes and then +apply the same changes in production without manually clicking around. It's +also helpful if you're developing customizations or extensions to be able to +get a fresh database back to the state you want for testing/development. + +This documentation applies to careful and thorough sysadmins as well as +extension authors who need to make database changes easily and repeatably for +new installs or upgrades. + +=head1 Examples + +RT ships with many initialdata files, only one of which is used to +configure a fresh install; the rest are used for upgrades, but function +the same despite being named differently. + + etc/initialdata + etc/upgrade/*/content + +The upgrade "content" files are meant to be incremental changes applied on top +of one another while the top level initialdata file is for fresh RT installs. + +Extensions may also ship with database changes in such files. You may find +some in your install with: + + find local/plugins -name initialdata -or -name content + +=head1 What can be in an initialdata file? + +initialdata files are Perl, but often consist primarily of a bunch of data +structures defining the new records you want and not much extra code. There's +nothing stopping you from writing a bunch of code, however! + +The basic template of a new initialdata file should look something like this: + + use strict; + use warnings; + + our @Queues = ( + # some definitions here + ); + + our @Groups = ( + # some other definitions here + ); + + 1; + +The C<@Queues> and C<@Groups> arrays are expected by RT and should contain +hashref definitions. There are many other arrays RT will look for and act on, +described below. None are required, all may be used. Keep in mind that since +they're just normal Perl arrays, you can C onto them from a loop or +C out definitions based on conditionals or generate their content with +C, etc. + +The complete list of possible arrays which can be used, along with +descriptions of the values to place in them, is below. + +=head2 C<@Users> + + push @Users, { + Name => 'john.doe', + Password => 'changethis', + Language => 'fr', + Timezone => 'America/Vancouver', + Privileged => 1, + Disabled => 0, + }; + +Each hashref in C<@Users> is treated as a new user to create and passed +straight into C<< RT::User->Create >>. All of the normal user fields are +available, as well as C and C (both booleans) which will +do the appropriate internal group/flag handling. + +For a full list of fields, read the documentation for L. + +=head2 C<@Groups> + + push @Groups, { + Domain => 'UserDefined', + Name => 'Example Employees', + Description => 'All of the employees of my company', + }; + +Creates a new L for each hashref. In almost all cases you'll want +to follow the example above to create a group just as if you had done it from +the admin interface. B omit the C<< Domain => 'UserDefined' >> line. + +Additionally, the C field is specially handled to make it easier to +add the new group to other groups. C may be a single value or an +array ref. Each value should be a user-defined group name or hashref to pass +into L<< RT::Group->LoadByCols >>. Each group found will have the new group +added as a member. + +Unfortunately you can't specify the I of a group at this time. As a +workaround, you can push a subref into C<@Final> which adds members to your new +groups. An example, using a convenience function to avoid repeating yourself: + + push @Final, sub { + add_members('My New Group Name' => qw(trs alex ruslan)); + add_members('My Second Group' => qw(jesse kevin sunnavy jim)); + }; + + sub add_members { + my $group_name = shift; + my @members = @_; + + my $group = RT::Group->new( RT->SystemUser ); + $group->LoadUserDefinedGroup($group_name); + + if ($group->id) { + for my $name (@members) { + my $member = RT::User->new( RT->SystemUser ); + $member->LoadByCols( Name => $name ); + + unless ($member->Id) { + RT->Logger->error("Unable to find user '$name'"); + next; + } + + my ($ok, $msg) = $group->AddMember( $member->PrincipalObj->Id ); + if ($ok) { + RT->Logger->info("Added member $name to $group_name"); + } else { + RT->Logger->error("Unable to AddMember $name to $group_name: $msg"); + } + } + } else { + RT->Logger->error("Unable to find group '$group_name'!"); + } + } + +=head2 C<@Queues> + + push @Queues, { + Name => 'Helpdesk', + CorrespondAddress => 'help@example.com', + CommentAddress => 'help-comment@example.com', + }; + +Creates a new L for each hashref. Refer to the documentation of +L for the fields you can use. + +=head2 C<@CustomFields> + + push @CustomFields, { + Queue => 0, + Name => 'Favorite color', + Type => 'FreeformSingle', + LookupType => 'RT::Queue-RT::Ticket', + }; + +Creates a new L for each hashref. It is the most complex of +the initialdata structures. The most commonly used fields are: + +=over 4 + +=item C + +The name of this CF as displayed in RT. + +=item C + +A short summary of what this CF is for. + +=item C + +May be a Name or ID. The single queue or array ref of queues to apply this CF +to. This does not apply when C does not start with C. + +=item C + +One of the following on the left hand side: + + SelectSingle # Select one value + SelectMultiple # Select multiple values + + FreeformSingle # Enter one value + FreeformMultiple # Enter multiple values + + Text # Fill in one text area + Wikitext # Fill in one wikitext area + + BinarySingle # Upload one file + BinaryMultiple # Upload multiple files + + ImageSingle # Upload one image + ImageMultiple # Upload multiple images + + Combobox # Combobox: Select or enter one value + + AutocompleteSingle # Enter one value with autocompletion + AutocompleteMultiple # Enter multiple values with autocompletion + + Date # Select date + DateTime # Select datetime + + IPAddressSingle # Enter one IP address + IPAddressMultiple # Enter multiple IP addresses + + IPAddressRangeSingle # Enter one IP address range + IPAddressRangeMultiple # Enter multiple IP address ranges + +If you don't specify "Single" or "Multiple" in the type, you must specify +C. + +=item C + +Labeled in the CF admin page as "Applies to". This determines whether your CF +is for Tickets, Transactions, Users, Groups, or Queues. Possible values: + + RT::Queue-RT::Ticket # Tickets + RT::Queue-RT::Ticket-RT::Transaction # Transactions + RT::User # Users + RT::Group # Groups + RT::Queue # Queues + +Ticket CFs are the most common, meaning C is the most +common C. + +=item C + +Only valid when C is "Select". Controls how the CF is displayed when +editing it. Valid values are: C