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

Kevin Falcone falcone at bestpractical.com
Wed Apr 30 12:25:32 EDT 2008


On Apr 30, 2008, at 11:29 AM, Morten Guldager wrote:

> Right above the two use statements I had to add:
> use lib '/usr/share/request-tracker3.6/lib';
>
> But when running the program it complains:
> [Wed Apr 30 15:24:54 2008] [crit]: Can't call method "new" on an  
> undefined value at ./test5 line 12. (/usr/share/request-tracker3.6/ 
> lib/RT.pm:317)
> Can't call method "new" on an undefined value at ./test5 line 12.
>
> Is my RT installation broken?
> It's an out of the box Debian-4.0 install,  request-tracker3.6  
> (3.6.1-4)

Try
my $ticket = RT::Ticket->new( $RT::SystemUser );

>
>
>
> /Morten %-)
>
> On Wed, Apr 30, 2008 at 4:08 PM, Todd Chapman <todd at chaka.net> wrote:
> 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
>
>
> _______________________________________________
> 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/ac27fe22/attachment.htm>


More information about the rt-users mailing list