InitialData: Difference between revisions
m (3 revisions imported) |
(No difference)
|
Revision as of 15:11, 6 April 2016
Adding new records into RT's database
This might be helpful if you want to add a record in the RT DB and don't want to mess things by SQL INSERT queries and don't want to write code.
This is especially helpful when you write custom scrip actions/conditions as module files instead of using User Defined
and want to register them in the DB.
rt-setup-database and initialdata
RT comes with etc/initialdata
file that is parsed and inserted into newly created DB when you install for the first time. When you upgrade RT, database changes comes in similar file.
Basic idea is that you can write such files and use sbin/rt-setup-database
script to insert the data:
/path/to/rt3/sbin/rt-setup-database --action insert --datafile /path/to/data-file
Example
@ScripConditions = ( { Name => 'On Some Event', Description => 'When some event happens', ExecModule => 'SomeEvent', Argument => 'some argument', ApplicableTransTypes => 'Any' }, );
How it works
File should be a valid perl scrip that fill a bunch of arrays with data that should be inserted, for example: @Queues, @Scrips, @Groups and so on. Full list of available arrays you can find in method InsertData that is in lib/RT/Handle.pm
file.
You put hashes with key/value pairs into these arrays. So it looks like this:
@SomeArray = ( { key => 'value', key => 'value', ... }, { key => 'value', key => 'value', ... }, ... ); @AnotherArray = ( { ... }, ... );
Usually you don't write any code, but this doesn't mean you can not. Sometimes you do want to write a bit of code, for example to load a bunch of data from a text file.
Where to find more info
There is no much to document about it and there are plenty of examples in RT itself. Start from etc/initialdata
then look at etc/upgrade/*/content
files, then look at the same set in RTIR extension or any other extension.
See also
WriteCustomAction and WriteCustomCondition for details on @ScripActions and @ScripConditions