lib/RT/Ticket.pm introspection callback for Kanban 4.2.12 rt-extension-kanban

hey,

jbrandt recommended to ‘override’ Ticket.pm to get to the data which we
require for the RESTful Kanban-view. that is:

Ticket.pm:

  • sub Create { … }
  • sub _Set { … }
  • sub MergeInto { … }

so we can either override Ticket.pm as a whole or only have the 3 prior
mentioned functions in our version of Ticket.pm’. this is a nice HACK
but won’t work well with different versions.

i propose this:

for 4.2.12+ and 4.4.x we have added a simple callback, like this:

================= current way ================
sub Create {
my $self = shift;

my %args = (
    id                 => undef,
    ... many more values ...
    _RecordTransaction => 1,
    DryRun             => 0,
    @_
);

system(“redis-cli”, “PUBLISH”, “rt-ticket-activity”, $self->Id);

================= /current way ================

but instead we should have done this:

================= proposed way ================

this is the Ticket.pm from rt-4.2.12 with the ‘generalized’

callback interface

pseudo-code

sub RT_WebSocket_Callback {

with no implementation

}

sub Create {
my $self = shift;

my %args = (
id => undef,
… many more values …
RecordTransaction => 1,
DryRun => 0,
@

);
RT_WebSocket_Callback( with a array of IDs )

this is the Ticket.pm from rt-extension-kanban

sub RT_WebSocket_Callback {
foreach supplied ID
system(“redis-cli”, “PUBLISH”, “rt-ticket-activity”, $foo->Id);
}

note: once alco could use Mojo::Redis2 with the sync interface but not
the CPAN Redis as this can’t reconnect on redis restarts/crashes and
thus will make RT fail and forces RT to be restarted. this is why we
decided to use the ugly system(…) call for the moment. we are using
Mojo::Redis2 with the async interface in the rt4-websocket mojolicious
server though.

================= /proposed way ================

our motivation for this change is that we have a callback interface to
the Ticket.pm code paths we are interested in, while not forcing any
plugin specific code into RT. if the rt-extension-kanban + rt4-websocket
is used with different versions of Ticket.pm it would unify the API
required to be implemented.

note:
we are planning to release the Kanban view / mojolicious RT::WebSocket
server + rt-extension-kanban this week.

@RT-team
please let us know what you think about this proposal.

regards,
paul & joachim

Hi Joachim,

actually this isn’t necessary.
You can overwrite the Create method and call inside your Create method
the original Create method.

Have a look at this:

ChrisAm 02.03.2016 um 13:52 schrieb Joachim Schiele:

sub RT_WebSocket_Callback {

with no implementation

}

sub Create {
my $self = shift;

my %args = (
id => undef,
… many more values …
RecordTransaction => 1,
DryRun => 0,
@

);
RT_WebSocket_Callback( with a array of IDs )

i understand this like that:
complete functions can be overriden like this but not single sections of
a function as in a patch.

if my understanding is correct, then the method you proposed would
require us to supply 3 Ticket.pm functions for each individual rt
release as these implementations might change over time.

correct?On 02.03.2016 14:19, Christian Loos wrote:

Hi Joachim,

actually this isn’t necessary.
You can overwrite the Create method and call inside your Create method
the original Create method.

Have a look at this:
https://github.com/bestpractical/rt-extension-repliestoresolved/blob/master/lib/RT/Extension/RepliesToResolved.pm#L102-L146

Chris

Am 02.03.2016 um 13:52 schrieb Joachim Schiele:

sub RT_WebSocket_Callback {

with no implementation

}

sub Create {
my $self = shift;

my %args = (
id => undef,
… many more values …
RecordTransaction => 1,
DryRun => 0,
@

);
RT_WebSocket_Callback( with a array of IDs )


RT 4.4 and RTIR Training Sessions (http://bestpractical.com/services/training.html)

  • Hamburg Germany - March 14 & 15, 2016
  • Washington DC - May 23 & 24, 2016

You can’t overwrite parts of a method in Perl, you can only overwrite
the whole method.

But you actually don’t want to override a method, you want to call a
custom method, or additional code, inside an existing function.

When you overwrite the RT::Ticket Create method and then call inside
this the original Create method, the Create method from the installed RT
is called.
So if you install your extension in RT 4.2.0, the 4.2.0 version of the
Create method is called, if you install your extension in RT 4.2.12, the
4.2.12 version of the Create method is called.

With this solution you can provide your extension for a wider range of
RT version.

Have you looked at the example link from my previous mail?
They overwrite there the RT::Interface::Email->ExtractTicketId method,
and call the original method inside this on line 114.

ChrisAm 02.03.2016 um 14:41 schrieb Joachim Schiele:

i understand this like that:
complete functions can be overriden like this but not single sections of
a function as in a patch.

if my understanding is correct, then the method you proposed would
require us to supply 3 Ticket.pm functions for each individual rt
release as these implementations might change over time.

correct?

On 02.03.2016 14:19, Christian Loos wrote:

Hi Joachim,

actually this isn’t necessary.
You can overwrite the Create method and call inside your Create method
the original Create method.

Have a look at this:
https://github.com/bestpractical/rt-extension-repliestoresolved/blob/master/lib/RT/Extension/RepliesToResolved.pm#L102-L146

You can’t overwrite parts of a method in Perl, you can only overwrite
the whole method.

But you actually don’t want to override a method, you want to call a
custom method, or additional code, inside an existing function.

When you overwrite the RT::Ticket Create method and then call inside
this the original Create method, the Create method from the installed RT
is called.
So if you install your extension in RT 4.2.0, the 4.2.0 version of the
Create method is called, if you install your extension in RT 4.2.12, the
4.2.12 version of the Create method is called.

With this solution you can provide your extension for a wider range of
RT version.

Have you looked at the example link from my previous mail?
They overwrite there the RT::Interface::Email->ExtractTicketId method,
and call the original method inside this on line 114.

of course we were looking at the provided code but at first we didn’t
understand what it meant to us. we also had to analyze, if calling the
comoplete implementation and then do something with the IDs would work
for us, but we are now confident it probably will.

thanks so much for your help! this is actually ‘exactly’ what we wanted.

we will now experiment with the implementation details!

Am 02.03.2016 um 14:41 schrieb Joachim Schiele:

i understand this like that:
complete functions can be overriden like this but not single sections of
a function as in a patch.

if my understanding is correct, then the method you proposed would
require us to supply 3 Ticket.pm functions for each individual rt
release as these implementations might change over time.

correct?

Hi Joachim,

actually this isn’t necessary.
You can overwrite the Create method and call inside your Create method
the original Create method.

Have a look at this:

Joachim Schiele

blog: http://blog.lastlog.de
wiki: http://lastlog.de
jabber: josh@jabber.ccc.de
GPG: C6AC8770