Duplicating a scrip in code

Here’s a poser for you.

I have a Scrip/Template combo that creates a ticket.

Now I want to duplicate that code in custom code.

I could try to duplicate that as $Ticket->Create() code,
but as soon as I start looking for the Parent and DependsOn
params (which don’t seem to be there!) I hit a wall.

Then I think why can’t I just load the already existing
Scrip and Template, and execute them? This would prevent
any discrepancy creeping in between the coded action and
the scrip.

But… how do I do this? I see the $Scrip->Apply() method,
but there’s no $Scrip->Load() method.

So how do I bring up the scrip I want, so that I can then
execute it?

Suggestions or other ways of looking at this most appreciated.

Thanks,

Jens

Here’s a poser for you.

I have a Scrip/Template combo that creates a ticket.

Now I want to duplicate that code in custom code.

I could try to duplicate that as $Ticket->Create() code,
but as soon as I start looking for the Parent and DependsOn
params (which don’t seem to be there!) I hit a wall.

Then I think why can’t I just load the already existing
Scrip and Template, and execute them? This would prevent
any discrepancy creeping in between the coded action and
the scrip.

But… how do I do this? I see the $Scrip->Apply() method,
but there’s no $Scrip->Load() method.

So how do I bring up the scrip I want, so that I can then
execute it?

Suggestions or other ways of looking at this most appreciated.

Thanks,

Jens

Normally a transaction triggers a scrip, so I would look at
the Transaction code (probably the Create method) and see
how it loads and runs a scrip. This may not work though
because a scrip may expect to run in the context of a
transaction.

It would be better to write the code to do what you want
and then have the scrip call that code. That avoids the
duplication problem.

-Todd

Here’s a poser for you.

I have a Scrip/Template combo that creates a ticket.

Now I want to duplicate that code in custom code.

I could try to duplicate that as $Ticket->Create() code,
but as soon as I start looking for the Parent and DependsOn
params (which don’t seem to be there!) I hit a wall.

Then I think why can’t I just load the already existing
Scrip and Template, and execute them? This would prevent
any discrepancy creeping in between the coded action and
the scrip.

But… how do I do this? I see the $Scrip->Apply() method,
but there’s no $Scrip->Load() method.

So how do I bring up the scrip I want, so that I can then
execute it?

Suggestions or other ways of looking at this most appreciated.

Thanks,

Jens

Normally a transaction triggers a scrip, so I would look at
the Transaction code (probably the Create method) and see
how it loads and runs a scrip. This may not work though
because a scrip may expect to run in the context of a
transaction.

Hmmmm…

The perldoc for Transaction_Overlay says:

Create

   Create a new transaction.

   This routine should _never_ be called anything other Than
   RT::Ticket. It should not be called from client code. Ever. Not
   ever. If you do this, we will hunt you down. and break your
   kneecaps. Then the unpleasant stuff will start.

…I’m not sure what this means, but I don’t think I want to go there.

It would be better to write the code to do what you want
and then have the scrip call that code. That avoids the
duplication problem.

Maybe I should be a bit clearer.

My scrip creates a ticket using a template. That’s all.

The reason the idea of executing the scrip from code occurred
to me is that I can’t figure out how to pass the template parameters
to my $Ticket-Create() call, like Parents, and DependsOn, things
like that.

Do you see what I mean? The entire “action” of the scrip is already
contained in the scrip itself and the template associated with it.
It makes sense for it to stay there.

I just want to execute it from code.

But how?

Thanks,

Jens

Here’s a poser for you.

I have a Scrip/Template combo that creates a ticket.

Now I want to duplicate that code in custom code.

I could try to duplicate that as $Ticket->Create() code,
but as soon as I start looking for the Parent and DependsOn
params (which don’t seem to be there!) I hit a wall.

Then I think why can’t I just load the already existing
Scrip and Template, and execute them? This would prevent
any discrepancy creeping in between the coded action and
the scrip.

But… how do I do this? I see the $Scrip->Apply() method,
but there’s no $Scrip->Load() method.

So how do I bring up the scrip I want, so that I can then
execute it?

Suggestions or other ways of looking at this most appreciated.

Thanks,

Jens

Normally a transaction triggers a scrip, so I would look at
the Transaction code (probably the Create method) and see
how it loads and runs a scrip. This may not work though
because a scrip may expect to run in the context of a
transaction.

Hmmmm…

The perldoc for Transaction_Overlay says:

Create

   Create a new transaction.

   This routine should _never_ be called anything other Than
   RT::Ticket. It should not be called from client code. Ever. Not
   ever. If you do this, we will hunt you down. and break your
   kneecaps. Then the unpleasant stuff will start.

…I’m not sure what this means, but I don’t think I want to go there.

It would be better to write the code to do what you want
and then have the scrip call that code. That avoids the
duplication problem.

Maybe I should be a bit clearer.

My scrip creates a ticket using a template. That’s all.

The reason the idea of executing the scrip from code occurred
to me is that I can’t figure out how to pass the template parameters
to my $Ticket-Create() call, like Parents, and DependsOn, things
like that.

Do you see what I mean? The entire “action” of the scrip is already
contained in the scrip itself and the template associated with it.
It makes sense for it to stay there.

I just want to execute it from code.

But how?

Thanks,

Jens

I understand want you want but it’s just not the right way
and will probably not work. Adding links during ticket creation
is not documented, but it’s not hard. Just pass an option
with the link type and the id of the ticket you are linking
to. For example:

$ticket->Create(
Queue => 5,
Subject => ‘test’,
Parent => 234,
DependsOn => [ 189, 190 ]
.
.
.

As you see you can link to multiple ticket by passing
and array ref instead of a single ticket id.

-Todd

I understand want you want but it’s just not the right way
and will probably not work. Adding links during ticket creation
is not documented, but it’s not hard. Just pass an option
with the link type and the id of the ticket you are linking
to. For example:

I’d happily take a doc patch from someone to make it official :wink:

Attached.On Thu, Jan 05, 2006 at 10:33:53AM -0500, Jesse Vincent wrote:

I understand want you want but it’s just not the right way
and will probably not work. Adding links during ticket creation
is not documented, but it’s not hard. Just pass an option
with the link type and the id of the ticket you are linking
to. For example:

I’d happily take a doc patch from someone to make it official :wink:

LinkDoc.patch (2.62 KB)

I understand want you want but it’s just not the right way
and will probably not work. Adding links during ticket creation
is not documented, but it’s not hard. Just pass an option
with the link type and the id of the ticket you are linking
to. For example:

$ticket->Create(
Queue => 5,
Subject => ‘test’,
Parent => 234,
DependsOn => [ 189, 190 ]

Ok… Thanks! This helps.

But what about getter and setter methods, though, after ticket
creation? Like:

    $Ticket->SetParent('123');
    $Ticket->SetChildren('234');

This is because after I set the Parent value for the child ticket,
I now have to set the Children value for the parent ticket, but
there doesn’t seem to be a subroutine in the Ticket*.pm modules
to do that.

Another tack:

Where is the code that takes a create ticket template and sets
up all the reciprocal relationships? Is there really no way
for me to plugin to that code, and have it set up all this
stuff for me?

Thanks,

Jens

Is it legal to use RT::Action::CreateTickets, and would this
solve the problem I’ve described?

Thanks,

Jens

I understand want you want but it’s just not the right way
and will probably not work. Adding links during ticket creation
is not documented, but it’s not hard. Just pass an option
with the link type and the id of the ticket you are linking
to. For example:

$ticket->Create(
Queue => 5,
Subject => ‘test’,
Parent => 234,
DependsOn => [ 189, 190 ]

Ok… Thanks! This helps.

But what about getter and setter methods, though, after ticket
creation? Like:

    $Ticket->SetParent('123');
    $Ticket->SetChildren('234');

See Ticket::AddLink

This is because after I set the Parent value for the child ticket,
I now have to set the Children value for the parent ticket, but
there doesn’t seem to be a subroutine in the Ticket*.pm modules
to do that.

No you don’t. By definition link are bi-directional.

Another tack:

Where is the code that takes a create ticket template and sets
up all the reciprocal relationships? Is there really no way
for me to plugin to that code, and have it set up all this
stuff for me?

Good luck on doing it the hard way.

But what about getter and setter methods, though, after ticket
creation? Like:

    $Ticket->SetParent('123');
    $Ticket->SetChildren('234');

See Ticket::AddLink

This is because after I set the Parent value for the child ticket,
I now have to set the Children value for the parent ticket, but
there doesn’t seem to be a subroutine in the Ticket*.pm modules
to do that.

No you don’t. By definition link are bi-directional.

After further testing, it looks like

    $TicketObj->Create(
                        Queue => "Inventory",
                        Owner => $creator,
                        Parent => $id, #parent bit fails
                    );

does not work.

No Parent link is being created, nor reciprocal Children links created.

Hence my question about creating links.

Another tack:

Where is the code that takes a create ticket template and sets
up all the reciprocal relationships? Is there really no way
for me to plugin to that code, and have it set up all this
stuff for me?

Good luck on doing it the hard way.

I’m trying to do it the obvious way. That the RT API does not provide
an interface for me to do it the obvious way is a reflection on the code base,
not on me.

If done properly, what I’m asking how to do should be one line of code:

$Ticket->RunScrip()

with a possible optional parameter of an associated template.

Jens

But what about getter and setter methods, though, after ticket
creation? Like:

    $Ticket->SetParent('123');
    $Ticket->SetChildren('234');

See Ticket::AddLink

This is because after I set the Parent value for the child ticket,
I now have to set the Children value for the parent ticket, but
there doesn’t seem to be a subroutine in the Ticket*.pm modules
to do that.

No you don’t. By definition link are bi-directional.

After further testing, it looks like

    $TicketObj->Create(
                        Queue => "Inventory",
                        Owner => $creator,
                        Parent => $id, #parent bit fails
                    );

does not work.

No Parent link is being created, nor reciprocal Children links created.

Hence my question about creating links.

Try “MemberOf” instead of “Parent”. They are synonyms so it should
work.

But what about getter and setter methods, though, after ticket
creation? Like:

    $Ticket->SetParent('123');
    $Ticket->SetChildren('234');

See Ticket::AddLink

This is because after I set the Parent value for the child ticket,
I now have to set the Children value for the parent ticket, but
there doesn’t seem to be a subroutine in the Ticket*.pm modules
to do that.

No you don’t. By definition link are bi-directional.

After further testing, it looks like

    $TicketObj->Create(
                        Queue => "Inventory",
                        Owner => $creator,
                        Parent => $id, #parent bit fails
                    );

does not work.

No Parent link is being created, nor reciprocal Children links created.

Hence my question about creating links.

Another tack:

Where is the code that takes a create ticket template and sets
up all the reciprocal relationships? Is there really no way
for me to plugin to that code, and have it set up all this
stuff for me?

Good luck on doing it the hard way.

I’m trying to do it the obvious way. That the RT API does not provide
an interface for me to do it the obvious way is a reflection on the code base,
not on me.

If done properly, what I’m asking how to do should be one line of code:

$Ticket->RunScrip()

with a possible optional parameter of an associated template.

Scrips are only run as a result of a transaction, so that
wouldn’t make sense.

Hi folks!

I wrote the attached patch to force user authentication through https
instead of being clear. After authentication the user can be back to http
to reduce the cost of SSL encryption if we are not dealing with sensitive
information.

I would like to receive some comments on the code, since this might not
cover all the cases and/or won’t be the best way to do it.

I found a related patch on the archives, that goes further and if you have
a https only instalation cookies are only sent by the browser when a
secure connection is established, see more at:

rt3: secure cookie patch [3.2.2] (Pavel Ruzicka, 2005-06-24 13:22)
http://archives.free.net.ph/message/20050624.122213.6583ec22.en.html

This could be combined with a set of configuration options, like:

  • Stay on secure mode after authentication;
  • Force secure login;
  • Secure mode only;

Regards,

Paulo Matos

|Sys & Net Admin | Centro de Inform�tica |
|Faculdade de Ci�ncias e Tecnologia | Tel: +351-21-2948596 |
|Universidade Nova de Lisboa | Fax: +351-21-2948548 |
|P-2829-516 Caparica | e-Mail: pjsm@fct.unl.pt |


rt-3.4.4-ForceHTTPSLogin.patch (1.94 KB)

Try “MemberOf” instead of “Parent”. They are synonyms so it should
work.

MemberOf works.

Thanks,

Jens

Is it legal to use RT::Action::CreateTickets, and would this
solve the problem I’ve described?

As to the former: certainly. We do it from the "Offline ticket creation"
tool.