SYNOPSIS

  use RT::Ticket;
  my $ticket = new RT::Ticket($CurrentUser);
  $ticket->Load($ticket_id);

DESCRIPTION

This module lets you manipulate RT\'s ticket object.

METHODS

Load

Takes a single argument. This can be a ticket id, ticket alias or local ticket uri. If the ticket can't be loaded, returns undef. Otherwise, returns the ticket id.

LoadByURI

Given a local ticket URI, loads the specified ticket.

Create (ARGS)

Arguments: ARGS is a hash of named parameters. Valid parameters are:

  id 
  Queue  - Either a Queue object or a Queue Name
  Requestor -  A reference to a list of RT::User objects, email addresses or RT user Names
  Cc  - A reference to a list of RT::User objects, email addresses or Names
  AdminCc  - A reference to a  list of RT::User objects, email addresses or Names
  Type -- The ticket\'s type. ignore this for now
  Owner -- This ticket\'s owner. either an RT::User object or this user\'s id
  Subject -- A string describing the subject of the ticket
  InitialPriority -- an integer from 0 to 99
  FinalPriority -- an integer from 0 to 99
  Status -- any valid status (Defined in RT::Queue)
  TimeEstimated -- an integer. estimated time for this task in minutes
  TimeWorked -- an integer. time worked so far in minutes
  TimeLeft -- an integer. time remaining in minutes
  Starts -- an ISO date describing the ticket\'s start date and time in GMT
  Due -- an ISO date describing the ticket\'s due date and time in GMT
  MIMEObj -- a MIME::Entity object with the content of the initial ticket request.
  CustomField-<n> -- a scalar or array of values for the customfield with the id <n>

Returns: TICKETID, Transaction Object, Error Message

CreateFromEmailMessage { Message, Queue, ExtractActorFromHeaders }

This code replaces what was once a large part of the email gateway. It takes an email message as a parameter, parses out the sender, subject and a MIME object. It then creates a ticket based on those attributes

FORMAT

CreateTickets uses the template as a template for an ordered set of tickets to create. The basic format is as follows:

 ===Create-Ticket: identifier
 Param: Value
 Param2: Value
 Param3: Value
 Content: Blah
 blah
 blah
 ENDOFCONTENT
=head2 Acceptable fields

A complete list of acceptable fields for this beastie:

    *  Queue           => Name or id# of a queue
       Subject         => A text string
       Status          => A valid status. defaults to 'new'
       Due             => Dates can be specified in seconds since the epoch
                          to be handled literally or in a semi-free textual
                          format which RT will attempt to parse.
       Starts          => 
       Started         => 
       Resolved        => 
       Owner           => Username or id of an RT user who can and should own 
                          this ticket
   +   Requestor       => Email address
   +   Cc              => Email address 
   +   AdminCc         => Email address 
       TimeWorked      => 
       TimeEstimated   => 
       TimeLeft        => 
       InitialPriority => 
       FinalPriority   => 
       Type            => 
    +  DependsOn       => 
    +  DependedOnBy    =>
    +  RefersTo        =>
    +  ReferredToBy    => 
    +  Members         =>
    +  MemberOf        => 
       Content         => content. Can extend to multiple lines. Everything
                          within a template after a Content: header is treated
                          as content until we hit a line containing only 
                          ENDOFCONTENT
       ContentType     => the content-type of the Content field
       CustomField-<id#> => custom field value

Fields marked with an * are required.

Fields marked with a + man have multiple values, simply by repeating the fieldname on a new line with an additional value.

When parsed, field names are converted to lowercase and have -s stripped. Refers-To, RefersTo, refersto, refers-to and r-e-f-er-s-tO will all be treated as the same thing.

UpdateFrom822 $MESSAGE

Takes an RFC822 format message as a string and uses it to make a bunch of changes to a ticket. Returns an um. ask me again when the code exists

_Parse822HeadersForAttributes Content

Takes an RFC822 style message and parses its attributes into a hash.

Import PARAMHASH

Import a ticket. Doesn\'t create a transaction. Doesn\'t supply queue defaults, etc.

Returns: TICKETID

_CreateTicketGroups

Create the ticket groups and relationships for this ticket. This routine expects to be called from Ticket->Create _inside of a transaction_

It will create four groups for this ticket: Requestor, Cc, AdminCc and Owner.

It will return true on success and undef on failure.

OwnerGroup

A constructor which returns an RT::Group object containing the owner of this ticket.

AddWatcher

AddWatcher takes a parameter hash. The keys are as follows:

Type One of Requestor, Cc, AdminCc

PrinicpalId The RT::Principal id of the user or group that's being added as a watcher

Email The email address of the new watcher. If a user with this email address can't be found, a new nonprivileged user will be created.

If the watcher you\'re trying to set has an RT account, set the Owner paremeter to their User Id. Otherwise, set the Email parameter to their Email address.

DeleteWatcher { Type => TYPE, PrincipalId => PRINCIPAL_ID, Email => EMAIL_ADDRESS }

Deletes a Ticket watcher. Takes two arguments:

Type (one of Requestor,Cc,AdminCc)

and one of

PrincipalId (an RT::Principal Id of the watcher you want to remove) OR Email (the email address of an existing wathcer)

RequestorAddresses

 B<Returns> String: All Ticket Requestor email addresses as a string.

AdminCcAddresses

returns String: All Ticket AdminCc email addresses as a string

CcAddresses

returns String: All Ticket Ccs as a string of email addresses

Requestors

Takes nothing. Returns this ticket's Requestors as an RT::Group object

Cc

Takes nothing. Returns an RT::Group object which contains this ticket's Ccs. If the user doesn't have "ShowTicket" permission, returns an empty group

AdminCc

Takes nothing. Returns an RT::Group object which contains this ticket's AdminCcs. If the user doesn't have "ShowTicket" permission, returns an empty group

IsWatcher { Type => TYPE, PrincipalId => PRINCIPAL_ID, Email => EMAIL }

Takes a param hash with the attributes Type and either PrincipalId or Email

Type is one of Requestor, Cc, AdminCc and Owner

PrincipalId is an RT::Principal id, and Email is an email address.

Returns true if the specified principal (or the one corresponding to the specified address) is a member of the group Type for this ticket.

IsRequestor PRINCIPAL_ID Takes an RT::Principal id Returns true if the principal is a requestor of the current ticket.

IsCc PRINCIPAL_ID

  Takes an RT::Principal id.
  Returns true if the principal is a requestor of the current ticket.

IsAdminCc PRINCIPAL_ID

  Takes an RT::Principal id.
  Returns true if the principal is a requestor of the current ticket.

IsOwner

  Takes an RT::User object. Returns true if that user is this ticket's owner.
returns undef otherwise

QueueObj

Takes nothing. returns this ticket's queue object

DueObj

  Returns an RT::Date object containing this ticket's due date

DueAsString

Returns this ticket's due date as a human readable string

ResolvedObj

  Returns an RT::Date object of this ticket's 'resolved' time.

SetStarted

Takes a date in ISO format or undef Returns a transaction id and a message The client calls "Start" to note that the project was started on the date in $date. A null date means "now"

StartedObj

  Returns an RT::Date object which contains this ticket's 
'Started' time.

StartsObj

  Returns an RT::Date object which contains this ticket's 
'Starts' time.

ToldObj

  Returns an RT::Date object which contains this ticket's 
'Told' time.

ToldAsString

A convenience method that returns ToldObj->AsString

TODO: This should be deprecated

TimeWorkedAsString

Returns the amount of time worked on this ticket as a Text String

Comment

Comment on this ticket. Takes a hashref with the following attributes: If MIMEObj is undefined, Content will be used to build a MIME::Entity for this commentl

MIMEObj, TimeTaken, CcMessageTo, BccMessageTo, Content.

Correspond

Correspond on this ticket. Takes a hashref with the following attributes:

MIMEObj, TimeTaken, CcMessageTo, BccMessageTo, Content

if there's no MIMEObj, Content is used to build a MIME::Entity object

Members

  This returns an RT::Links object which references all the tickets 
which are 'MembersOf' this ticket

MemberOf

  This returns an RT::Links object which references all the tickets that this
ticket is a 'MemberOf'

RefersTo

  This returns an RT::Links object which shows all references for which this ticket is a base

ReferredToBy

  This returns an RT::Links object which shows all references for which this ticket is a target

DependedOnBy

  This returns an RT::Links object which references all the tickets that depend on this one

HasUnresolvedDependencies

  Takes a paramhash of Type (default to '__any').  Returns true if
$self->UnresolvedDependencies returns an object with one or more members
of that type.  Returns false otherwise

UnresolvedDependencies

Returns an RT::Tickets object of tickets which this ticket depends on and which have a status of new, open or stalled. (That list comes from RT::Queue->ActiveStatusArray

AllDependedOnBy

Returns an array of RT::Ticket objects which (directly or indirectly) depends on this ticket; takes an optional 'Type' argument in the param hash, which will limit returned tickets to that type, as well as cause tickets with that type to serve as 'leaf' nodes that stops the recursive dependency search.

DependsOn

  This returns an RT::Links object which references all the tickets that this ticket depends on

DeleteLink

Delete a link. takes a paramhash of Base, Target and Type. Either Base or Target must be null. The null value will be replaced with this ticket\'s id

AddLink

Takes a paramhash of Type and one of Base or Target. Adds that link to this ticket.

URI

Returns this ticket's URI

MergeInto MergeInto take the id of the ticket to merge this ticket into.

OwnerObj

Takes nothing and returns an RT::User object of this ticket's owner

OwnerAsString

Returns the owner's email address

SetOwner

Takes two arguments: the Id or Name of the owner and (optionally) the type of the SetOwner Transaction. It defaults to 'Give'. 'Steal' is also a valid option.

Take

A convenince method to set the ticket's owner to the current user

Untake

Convenience method to set the owner to 'nobody' if the current user is the owner.

Steal

A convenience method to change the owner of the current ticket to the current user. Even if it's owned by another user.

ValidateStatus STATUS

Takes a string. Returns true if that status is a valid status for this ticket. Returns false otherwise.

SetStatus STATUS

Set this ticket\'s status. STATUS can be one of: new, open, stalled, resolved, rejected or deleted.

Alternatively, you can pass in a list of named parameters (Status => STATUS, Force => FORCE). If FORCE is true, ignore unresolved dependencies and force a status change.

Kill

Takes no arguments. Marks this ticket for garbage collection

Stall

Sets this ticket's status to stalled

Reject

Sets this ticket's status to rejected

Open

Sets this ticket\'s status to Open

Resolve

Sets this ticket\'s status to Resolved

FirstCustomFieldValue FIELD

Return the content of the first value of CustomField FIELD for this ticket Takes a field id or name

CustomFieldValues FIELD

Return a TicketCustomFieldValues object of all values of CustomField FIELD for this ticket. Takes a field id or name.

AddCustomFieldValue { Field => FIELD, Value => VALUE }

VALUE should be a string. FIELD can be a CustomField object OR a CustomField ID.

Adds VALUE as a value of CustomField FIELD. If this is a single-value custom field, deletes the old value. If VALUE isn't a valid value for the custom field, returns (0, 'Error message' ) otherwise, returns (1, 'Success Message')

DeleteCustomFieldValue { Field => FIELD, Value => VALUE }

Deletes VALUE as a value of CustomField FIELD.

VALUE can be a string, a CustomFieldValue or a TicketCustomFieldValue.

If VALUE isn't a valid value for the custom field, returns (0, 'Error message' ) otherwise, returns (1, 'Success Message')

SetTold ISO [TIMETAKEN]

Updates the told and records a transaction

_SetTold

Updates the told without a transaction or acl check. Useful when we're sending replies.

Transactions

  Returns an RT::Transactions object of all transactions on this ticket

TransactionBatch

  Returns an array reference of all transactions created on this ticket during
  this ticket object's lifetime, or undef if there were none.
  Only works when the $RT::UseTransactionBatch config variable is set to true.

_Value

Takes the name of a table column. Returns its value as a string, if the user passes an ACL check

_UpdateTimeTaken

This routine will increment the timeworked counter. it should only be called from _NewTransaction

CurrentUserHasRight

  Takes the textual name of a Ticket scoped right (from RT::ACE) and returns
1 if the user has that right. It returns 0 if the user doesn't have that right.

HasRight

 Takes a paramhash with the attributes 'Right' and 'Principal'
  'Right' is a ticket-scoped textual right from RT::ACE 
  'Principal' is an RT::User object
  Returns 1 if the principal has the right. Returns undef if not.

AUTHOR

Jesse Vincent, jesse@bestpractical.com

SEE ALSO

RT