[rt-users] Scrip question...Getting there slowly...Time Worked

Ruslan Zakirov ruz at bestpractical.com
Fri Feb 8 19:10:16 EST 2008


On Feb 9, 2008 2:57 AM, Greg Evans <gevans at hcc.net> wrote:
> following up on my own post to the list...The following code is *mostly*
> working but there is a GLARING ERROR that makes it unusable
>
> Please NOTE THE ABOVE because if you use it as is, it will require a restart
> of httpd each time you try to update a ticket.
>
> #code begin
> if ($self->TicketObj->Type eq "Correspond" || $self->TicketObj->Type eq
> "Comment" || $self->TicketObj->Type eq "ticket")

This is wrong. you're mixing transactions' types and tickets' Ticket's
type almost always is 'ticket', so this if condition is true all the
time.

What condition are you using for this scrip?


> # Why it has to be "ticket" to work I don't understand yet
> {
>
> # Saw something similar somewhere that I was looking at RT stuff.
> # Looked like it may work, it does.
>
> my $date_update=$self->TicketObj->LastUpdatedObj->Unix;
> my $date_create=$self->TicketObj->CreatedObj->Unix;
>
> my $ticket_check = $self->TicketObj->TimeWorked; #tells us the current value
> of TimeWorked
> my $ticket_Worked = (($date_update - $date_create)/60); #time in minutes
>
> #this was the problem before and seems to be the problem again!!!
> $self->TicketObj->SetTimeWorked($ticket_Worked);
> return 1;
>
> } else {
>  return undef;
> }
>
>
> Here is what happens when I run it as is just a quick copy/paste job of the
> ticket:
>
> Fri Feb 08 15:39:22 2008 gevans - Comments added    [Reply] [Comment]
> Download (untitled) [text/plain 1.2k] On Fri Feb 08 15:37:16 2008, gevans
> wrote:
> [snipped]
>
>
> #    Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from (no value)
> to '19.1'
> #    Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from '19' to ''
>
> #    Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from (no value)
> to '21.2166666666667'
> #    Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from '21' to ''
>
> #    Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from (no value)
> to '21.2166666666667'
> #    Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from '21' to ''
>
> #    Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from (no value)
> to '21.2166666666667'
> #    Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from '21' to ''
>
> ...
> ...
> #    Fri Feb 08 15:42:39 2008 RT_System - TimeWorked changed from (no value)
> to '24.4833333333333'
> #    Fri Feb 08 15:42:39 2008 RT_System - TimeWorked changed from '24' to ''
>
> #    Fri Feb 08 15:42:39 2008 RT_System - TimeWorked changed from (no value)
> to '24.4833333333333'
> #    Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from '24' to ''
>
> #    Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)
> to '24.4833333333333'
> #    Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from '24' to ''
>
> #    Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)
> to '24.5'
> #    Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from '24' to ''
>
> #    Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)
> to '24.5'
> #    Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from '24' to ''
>
> #    Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)
> to '24.5'
> #    Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from '24' to ''
>
> #    Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)
> to '24.5'
> #    Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from '24' to ''
>
> #    Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)
> to '24.5'
>
> It will continue adding time until you kill httpd.  This has got to be
> something simple that I am missing. At least I think so...  Ideas?
>
> Thanks,
>
> Greg Evans
>
>
>
> ________________________________
>
>         From: rt-users-bounces at lists.bestpractical.com
> [mailto:rt-users-bounces at lists.bestpractical.com] On Behalf Of Greg Evans
>         Sent: Friday, February 08, 2008 2:09 PM
>         To: rt-users at lists.bestpractical.com
>         Subject: [rt-users] Scrip question...Getting there slowly...Time
> Worked
>
>
>
>         As has been mentioned I am working on trying to get a time worked
> scrip up and running. So far everything is going well except for one thing,
> I can retrieve dates from the ticket without problem and they come through
> like:
>
>         2008-02-08 21:24:49
>
>         This seems like a fine format, but once I have 2 of them, I can't
> figure out how to calculate the difference. It was suggest that I might need
> to convert them to unix time and back, but I am not sure how to do that. I
> see that Time::Local could possibly be used or maybe Date::Manip but my
> admittedly novice Perl skills don't particularly help me out here.
>
>         Here is the scrip as it sits, and after using RT::Logger->debug it
> appears that all I need is to get the date difference calculation to work
>
>         if ($self->TicketObj->Type eq "Correspond" || $self->TicketObj->Type
> eq "Comment" || $self->TicketObj->Type eq "ticket")
>         {
>
>         #This is the part that is not working.
>         my $ticket_Worked = ($self->TicketObj->LastUpdated -
> $self->TicketObj->Created);
>         #End part that is not working
>
>         $self->TicketObj->SetTimeWorked($ticket_Worked);
>         } else {
>          return undef;
>         }
>
>
>         The other thing that I thought was weird when I looked in my rt.log
> was that when I would comment on the ticket, the returned result of the if
> test that I start with was "ticket" which seems strange to me, but what do I
> know. Maybe someone could explain that to me as well?
>
>         Greg Evans
>         Internet Support
>         Hood Canal Communications
>         (360) 898-2481 ext.212
>
>
> _______________________________________________
> 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
>



-- 
Best regards, Ruslan.



More information about the rt-users mailing list