[rt-users] Using the RT Codebase in a stand alone program (perl)

Todd Chapman todd at chaka.net
Wed Apr 30 10:08:31 EDT 2008


use RT;
use RT::Ticket;

RT::LoadConfig();
RT::Init();

$ticket = $RT::Ticket->new( $RT::SystemUser );
$ticket->Load( 123 );

print $ticket->Subject;

On Wed, Apr 30, 2008 at 9:50 AM, Morten Guldager <morten.guldager at gmail.com>
wrote:

> 'Aloha!
>
> Below you see the text book example (from RT Essentials) using
> DBIx::SearchBuilder to accessing the Tickets table from a stand alone perl
> program.
> Since I need restricting access to what a specific user would be allowed
> to do, I think I have to transform this code into something using RT::Record
> (or should it be RT::Ticket?)
>
> Simply replacing DBIx::SearchBuilder with RT did not work. (well I sorta
> did not expect that either..)
>  - and where do I feed it the username/password?
>
> This must have been done a million times before, but google refuses to
> help me :-(
>
> Anyone?
>
> --
> /Morten %-)
>
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my $X = tkt->new;
> $X->Load(123);
> printf STDERR "%s: %s (%s)\n",  $X->id,  $X->Subject,  $X->Status;
>
> package tkt;
> use strict;
> use warnings;
> use DBIx::SearchBuilder::Handle;
> use base qw(DBIx::SearchBuilder::Record);
>
> sub _Init
> {
>   my $self = shift;
>   my $handle= DBIx::SearchBuilder::Handle->new;
>   $handle->Connect(Driver   => 'mysql',
>                    Database => 'rtdb',
>                    User     => 'rtuser',
>                    Password => $ENV{RTDBPW});
>   $self->_Handle($handle);
>   $self->Table('Tickets');
> }
>
> sub _ClassAccessible
> {
>   return { Id      => {read => 1},
>            Status  => {read => 1},
>            Subject => {read => 1}
>          };
> }
>
>
> _______________________________________________
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>
> Community help: http://wiki.bestpractical.com
> Commercial support: sales at bestpractical.com
>
>
> Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
> Buy a copy at http://rtbook.bestpractical.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20080430/462adb48/attachment.htm>


More information about the rt-users mailing list