
############
TicketUpdate
############


****
NAME
****


Kernel::GenericInterface::Operation::Ticket::TicketUpdate - GenericInterface Ticket TicketUpdate Operation backend


****************
PUBLIC INTERFACE
****************


new()
=====


usually, you want to create an instance of this
by using Kernel::GenericInterface::Operation->new();


Run()
=====


perform TicketUpdate Operation. This will return the updated TicketID and
if applicable the created ArticleID.


.. code-block:: perl

     my $Result = $OperationObject->Run(
         Data => {
             UserLogin         => 'some agent login',                            # UserLogin or CustomerUserLogin or SessionID is
                                                                                 #   required
             CustomerUserLogin => 'some customer login',
             SessionID         => 123,
 
             Password  => 'some password',                                       # if UserLogin or customerUserLogin is sent then
                                                                                 #   Password is required
 
             TicketID     => 123,                                                # TicketID or TicketNumber is required
             TicketNumber => '2004040510440485',
 
             Ticket {                                                            # optional
                 Title      => 'some ticket title',
 
                 QueueID       => 123,                                           # Optional
                 Queue         => 'some queue name',                             # Optional
                 LockID        => 123,                                           # optional
                 Lock          => 'some lock name',                              # optional
                 TypeID        => 123,                                           # optional
                 Type          => 'some type name',                              # optional
                 ServiceID     => 123,                                           # optional
                 Service       => 'some service name',                           # optional
                 SLAID         => 123,                                           # optional
                 SLA           => 'some SLA name',                               # optional
                 StateID       => 123,                                           # optional
                 State         => 'some state name',                             # optional
                 PriorityID    => 123,                                           # optional
                 Priority      => 'some priority name',                          # optional
                 OwnerID       => 123,                                           # optional
                 Owner         => 'some user login',                             # optional
                 ResponsibleID => 123,                                           # optional
                 Responsible   => 'some user login',                             # optional
                 CustomerUser  => 'some customer user login',
 
                 PendingTime {       # optional
                     Year   => 2011,
                     Month  => 12,
                     Day    => 03,
                     Hour   => 23,
                     Minute => 05,
                 },
                 # or
                 # PendingTime {
                 #     Diff => 10080, # Pending time in minutes
                 #},
             },
             Article => {                                                          # optional
                 CommunicationChannel            => 'Email',                    # optional
                 CommunicationChannelID          => 1,                          # optional
                 IsVisibleForCustomer            => 1,                          # optional
                 SenderTypeID                    => 123,                        # optional
                 SenderType                      => 'some sender type name',    # optional
                 AutoResponseType                => 'some auto response type',  # optional
                 ArticleSend                     => 1,                          # optional
                 From                            => 'some from string',         # optional
                 To                              => 'some to address',          # optional, required if ArticleSend => 1
                 Cc                              => 'some Cc address',          # optional
                 Bcc                             => 'some Bcc address',         # optional
                 Subject                         => 'some subject',
                 Body                            => 'some body',
 
                 ContentType                     => 'some content type',        # ContentType or MimeType and Charset is required
                 MimeType                        => 'some mime type',
                 Charset                         => 'some charset',
 
                 HistoryType                     => 'some history type',        # optional
                 HistoryComment                  => 'Some  history comment',    # optional
                 TimeUnit                        => 123,                        # optional
                 NoAgentNotify                   => 1,                          # optional
                 ForceNotificationToUserID       => [1, 2, 3]                   # optional
                 ExcludeNotificationToUserID     => [1, 2, 3]                   # optional
                 ExcludeMuteNotificationToUserID => [1, 2, 3]                   # optional
                 AppendSignatureToBody           => 1,                          # optional, defaults to 1
                 Attachment => [
                     {
                         Content     => 'content'                                 # base64 encoded
                         ContentType => 'some content type'
                         Filename    => 'some fine name'
                     },
                     # ...
                 ],
                 # or:
                 Attachment => {
                     Content     => 'content'                                 # base64 encoded
                     ContentType => 'some content type'
                     Filename    => 'some fine name'
                 },
 
                 # Signing and encryption, only used when ArticleSend is set to 1
                 Sign => {
                     Type    => 'PGP',
                     SubType => 'Inline|Detached',
                     Key     => '81877F5E',
                     Type    => 'SMIME',
                     Key     => '3b630c80',
                 },
                 Crypt => {
                     Type    => 'PGP',
                     SubType => 'Inline|Detached',
                     Key     => '81877F5E',
                     Type    => 'SMIME',
                     Key     => '3b630c80',
                 },
             },
 
             DynamicField => [                                                  # optional
                 {
                     Name   => 'some name',
                     Value  => $Value,                                          # value type depends on the dynamic field
                 },
                 # ...
             ],
             # or
             # DynamicField {
             #    Name   => 'some name',
             #    Value  => $Value,
             #},
 
             Attachment => [
                 {
                     Content     => 'content',                                # base64 encoded
                     ContentType => 'some content type',
                     Filename    => 'some fine name'
                 },
                 # ...
             ],
             #or
             #Attachment => {
             #    Content     => 'content',
             #    ContentType => 'some content type',
             #    Filename    => 'some fine name'
             #},
         },
     );
 
     $Result = {
         Success         => 1,                       # 0 or 1
         ErrorMessage    => '',                      # in case of error
         Data            => {                        # result data payload after Operation
             TicketID    => 123,                     # Ticket ID in Znuny
             ArticleID   => 43,                      # Article ID in Znuny
             Error => {                              # should not return errors
                     ErrorCode    => 'TicketUpdate.ErrorCode',
                     ErrorMessage => 'Error Description'
             },
 
             # If IncludeTicketData is enabled
             Ticket => [
                 {
                     TicketNumber       => '20101027000001',
                     Title              => 'some title',
                     TicketID           => 123,
                     State              => 'some state',
                     StateID            => 123,
                     StateType          => 'some state type',
                     Priority           => 'some priority',
                     PriorityID         => 123,
                     Lock               => 'lock',
                     LockID             => 123,
                     Queue              => 'some queue',
                     QueueID            => 123,
                     CustomerID         => 'customer_id_123',
                     CustomerUserID     => 'customer_user_id_123',
                     Owner              => 'some_owner_login',
                     OwnerID            => 123,
                     Type               => 'some ticket type',
                     TypeID             => 123,
                     SLA                => 'some sla',
                     SLAID              => 123,
                     Service            => 'some service',
                     ServiceID          => 123,
                     Responsible        => 'some_responsible_login',
                     ResponsibleID      => 123,
                     Age                => 3456,
                     Created            => '2010-10-27 20:15:00',
                     CreateBy           => 123,
                     Changed            => '2010-10-27 20:15:15',
                     ChangeBy           => 123,
                     ArchiveFlag        => 'y',
 
                     DynamicField => [
                         {
                             Name  => 'some name',
                             Value => 'some value',
                         },
                     ],
 
                     # (time stamps of expected escalations)
                     EscalationResponseTime           (unix time stamp of response time escalation)
                     EscalationUpdateTime             (unix time stamp of update time escalation)
                     EscalationSolutionTime           (unix time stamp of solution time escalation)
 
                     # (general escalation info of nearest escalation type)
                     EscalationDestinationIn          (escalation in e. g. 1h 4m)
                     EscalationDestinationTime        (date of escalation in unix time, e. g. 72193292)
                     EscalationDestinationDate        (date of escalation, e. g. "2009-02-14 18:00:00")
                     EscalationTimeWorkingTime        (seconds of working/service time till escalation, e. g. "1800")
                     EscalationTime                   (seconds total till escalation of nearest escalation time type - response, update or solution time, e. g. "3600")
 
                     # (detailed escalation info about first response, update and solution time)
                     FirstResponseTimeEscalation      (if true, ticket is escalated)
                     FirstResponseTimeNotification    (if true, notify - x% of escalation has reached)
                     FirstResponseTimeDestinationTime (date of escalation in unix time, e. g. 72193292)
                     FirstResponseTimeDestinationDate (date of escalation, e. g. "2009-02-14 18:00:00")
                     FirstResponseTimeWorkingTime     (seconds of working/service time till escalation, e. g. "1800")
                     FirstResponseTime                (seconds total till escalation, e. g. "3600")
 
                     UpdateTimeEscalation             (if true, ticket is escalated)
                     UpdateTimeNotification           (if true, notify - x% of escalation has reached)
                     UpdateTimeDestinationTime        (date of escalation in unix time, e. g. 72193292)
                     UpdateTimeDestinationDate        (date of escalation, e. g. "2009-02-14 18:00:00")
                     UpdateTimeWorkingTime            (seconds of working/service time till escalation, e. g. "1800")
                     UpdateTime                       (seconds total till escalation, e. g. "3600")
 
                     SolutionTimeEscalation           (if true, ticket is escalated)
                     SolutionTimeNotification         (if true, notify - x% of escalation has reached)
                     SolutionTimeDestinationTime      (date of escalation in unix time, e. g. 72193292)
                     SolutionTimeDestinationDate      (date of escalation, e. g. "2009-02-14 18:00:00")
                     SolutionTimeWorkingTime          (seconds of working/service time till escalation, e. g. "1800")
                     SolutionTime                     (seconds total till escalation, e. g. "3600")
 
                     Article => [
                         {
                             ArticleID
                             From
                             To
                             Cc
                             Subject
                             Body
                             ReplyTo
                             MessageID
                             InReplyTo
                             References
                             SenderType
                             SenderTypeID
                             CommunicationChannelID
                             IsVisibleForCustomer
                             ContentType
                             Charset
                             MimeType
                             IncomingTime
 
                             DynamicField => [
                                 {
                                     Name  => 'some name',
                                     Value => 'some value',
                                 },
                             ],
 
                             Attachment => [
                                 {
                                     Content            => "xxxx",     # actual attachment contents, base64 enconded
                                     ContentAlternative => "",
                                     ContentID          => "",
                                     ContentType        => "application/pdf",
                                     Filename           => "StdAttachment-Test1.pdf",
                                     Filesize           => "4.6 KBytes",
                                     FilesizeRaw        => 4722,
                                 },
                             ],
                         },
                     ],
                 },
             ],
         },
     };



_CheckTicket()
==============


checks if the given ticket parameters are valid.


.. code-block:: perl

     my $TicketCheck = $OperationObject->_CheckTicket(
         Ticket => $Ticket,                          # all ticket parameters
     );
 
     returns:
 
     $TicketCheck = {
         Success => 1,                               # if everything is OK
     }
 
     $TicketCheck = {
         ErrorCode    => 'Function.Error',           # if error
         ErrorMessage => 'Error description',
     }



_CheckArticle()
===============


checks if the given article parameter is valid.


.. code-block:: perl

     my $ArticleCheck = $OperationObject->_CheckArticle(
         Article => $Article,                        # all article parameters
     );
 
     returns:
 
     $ArticleCheck = {
         Success => 1,                               # if everything is OK
     }
 
     $ArticleCheck = {
         ErrorCode    => 'Function.Error',           # if error
         ErrorMessage => 'Error description',
     }



MakeArrayRef
============


Returns its argument unmodified if it is a listref, otherwise returns a
reference to a new single-element list containing the argument.

Simple functionn, not a method!


_ValidateDynamicFields()
========================


Validate a list of dynamic field specs. Also removes leading and trailing
spaces from DF values.  Set C<$IsArticle> to 1 to validate an Article dynamic
field.


.. code-block:: perl

     $Check = $OperationObject->_ValidateDynamicFields($DynamicField);
     $Check = $OperationObject->_ValidateDynamicFields($DynamicField, 1);


Returns undef on success, a hash with an error message otherwise.


_CheckDynamicField()
====================


Checks if the given dynamic field parameter is valid. Set C<$IsArticle> to 1 to
validate an Article dynamic field.


.. code-block:: perl

     my $DynamicFieldCheck = $OperationObject->_CheckDynamicField($DynamicField);


Returns undef on success, a hash with an error message otherwise.


_CheckAttachment()
==================


checks if the given attachment parameter is valid.


.. code-block:: perl

     my $AttachmentCheck = $OperationObject->_CheckAttachment(
         Attachment => $Attachment,                  # all attachment parameters
     );
 
     returns:
 
     $AttachmentCheck = {
         Success => 1,                               # if everything is OK
     }
 
     $AttachmentCheck = {
         ErrorCode    => 'Function.Error',           # if error
         ErrorMessage => 'Error description',
     }



_CheckUpdatePermissions()
=========================


check if user has permissions to update ticket attributes.


.. code-block:: perl

     my $Response = $OperationObject->_CheckUpdatePermissions(
         TicketID     => 123,
         Ticket       => $Ticket,                  # all ticket parameters
         Article      => $Ticket,                  # all attachment parameters
         DynamicField => $Ticket,                  # all dynamic field parameters
         Attachment   => $Ticket,                  # all attachment parameters
         UserID       => 123,
     );
 
     returns:
 
     $Response = {
         Success => 1,                               # if everything is OK
     }
 
     $Response = {
         Success      => 0,
         ErrorCode    => "function.error",           # if error
         ErrorMessage => "Error description"
     }



_TicketUpdate()
===============


updates a ticket and creates an article and sets dynamic fields and attachments if specified.


.. code-block:: perl

     my $Response = $OperationObject->_TicketUpdate(
         TicketID         => 123,
         Ticket           => $Ticket,                  # all ticket parameters
         Articles         => @Articles,                # all article parameters, optionally with dynamic fields
         DynamicField     => $DynamicField,            # all ticket dynamic field parameters
         Attachment       => $Attachment,              # all attachment parameters
         UserID           => 123,
         PermissionUserID => 201,                      # User for which permissions will be checked
         UserType         => 'Agent'                   # || 'Customer
     );
 
     returns:
 
     $Response = {
         Success => 1,                               # if everything is OK
         Data => {
             TicketID     => 123,
             TicketNumber => 'TN3422332',
             ArticleID    => 123,                    # if new article was created, or
             ArticleIDs   => [ 123, 456 ],           # if multiple articles were created
         }
     }
 
     $Response = {
         Success      => 0,                         # if unexpected error
         ErrorMessage => "$Param{ErrorCode}: $Param{ErrorMessage}",
     }





