[rt-users] Using RT library from outside
Craig Ringer
craig at 2ndquadrant.com
Mon Apr 15 07:06:33 EDT 2013
On 04/15/2013 06:23 PM, Jean-Christophe Boggio wrote:
>
> 1) Is it possible to use RT::* from "outside" ? Is there a
> documentation somewhere with guidelines (like dealing with sessions)
> or some examples ?
It certainly is, you just load them in a script. I've now written
scripts to do things like scan users out of an SQL database and feed
them into RT for import (kind of like RT::LDAPImport for SQL, but custom
for our environment) among other things.
Here's the prologue I use to get things set up:
use 5.10.1;
use strict;
use warnings;
# Customise to fit your environment
use lib qw(/opt/rt4/lib /usr/share/request-tracker4/lib
/usr/local/share/request-tracker4/lib);
use RT;
use RT::Interface::CLI qw( CleanEnv );
use DBI;
use Text::CSV;
say "Setting up rt...";
CleanEnv();
RT::LoadConfig( );
RT::Init( );
I'm not at all certain that CleanEnv() is necessary; I started off with
an RT CLI script and never got around to tidying it properly. This is
probably far from the perfect way to do the job.
You can use RT::SystemUser when you need a privileged user, or you can
use RT::Interface::CLI::GetCurrentUser to find a user with `gecos` field
matching the current unix user name.
> 2) Is it possible to use the plugins library (explicitly AT's
> functions) the same way ?
I've used my own plugin code from scripts with a simple 'use
RT::Extension::SMSNotify' or whatever, but those have been designed not
to make assumptions about the calling context. Whether you can use a
plugin would depend on how the code expects to be called; you can't just
invoke a Mason callback as simple Perl code, for example.
--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
More information about the rt-users
mailing list