Ejemplo n.º 1
0
 /**
  * @param Model_DevblocksEvent $event
  */
 function handleEvent(Model_DevblocksEvent $event)
 {
     switch ($event->id) {
         case 'cron.maint':
             DAO_TicketAuditLog::maint();
             break;
         case 'ticket.merge':
             // Listen for ticket merges and update our internal ticket_id records
             @($new_ticket_id = $event->params['new_ticket_id']);
             @($old_ticket_ids = $event->params['old_ticket_ids']);
             if (empty($new_ticket_id) || empty($old_ticket_ids)) {
                 return;
             }
             $fields = array(DAO_TicketAuditLog::TICKET_ID => $new_ticket_id);
             DAO_TicketAuditLog::updateWhere($fields, sprintf("%s IN (%s)", DAO_TicketAuditLog::TICKET_ID, implode(',', $old_ticket_ids)));
             break;
         case 'ticket.property.pre_change':
             @($ticket_ids = $event->params['ticket_ids']);
             @($changed_fields = $event->params['changed_fields']);
             // Filter out any mandatory changes we could care less about
             unset($changed_fields[DAO_Ticket::UPDATED_DATE]);
             unset($changed_fields[DAO_Ticket::MASK]);
             unset($changed_fields[DAO_Ticket::FIRST_MESSAGE_ID]);
             unset($changed_fields[DAO_Ticket::FIRST_WROTE_ID]);
             unset($changed_fields[DAO_Ticket::LAST_WROTE_ID]);
             unset($changed_fields[DAO_Ticket::INTERESTING_WORDS]);
             @($tickets = DAO_Ticket::getTickets($ticket_ids));
             // Is a worker around to invoke this change?  0 = automatic
             @($worker_id = null != ($active_worker = CerberusApplication::getActiveWorker()) && !empty($active_worker->id) ? $active_worker->id : 0);
             if (is_array($tickets) && !empty($tickets) && is_array($changed_fields) && !empty($changed_fields)) {
                 foreach ($tickets as $ticket_id => $ticket) {
                     /* @var $ticket CerberusTicket */
                     foreach ($changed_fields as $changed_field => $changed_value) {
                         if (is_array($changed_value)) {
                             $changed_value = implode("\r\n", $changed_value);
                         }
                         // If different
                         if (isset($ticket->{$changed_field}) && 0 != strcmp($ticket->{$changed_field}, $changed_value)) {
                             $fields = array(DAO_TicketAuditLog::TICKET_ID => $ticket_id, DAO_TicketAuditLog::WORKER_ID => $worker_id, DAO_TicketAuditLog::CHANGE_DATE => time(), DAO_TicketAuditLog::CHANGE_FIELD => $changed_field, DAO_TicketAuditLog::CHANGE_VALUE => substr($changed_value, 0, 128));
                             $log_id = DAO_TicketAuditLog::create($fields);
                         }
                     }
                 }
             }
             break;
     }
 }
Ejemplo n.º 2
0
 private function mergeTicket($event)
 {
     // Listen for ticket merges and update our internal ticket_id records
     @($new_ticket_id = $event->params['new_ticket_id']);
     @($old_ticket_ids = $event->params['old_ticket_ids']);
     $translate = DevblocksPlatform::getTranslationService();
     if (empty($new_ticket_id) || empty($old_ticket_ids)) {
         return;
     }
     $settings = DevblocksPlatform::getPluginSettingsService();
     $al_merge_enabled = intval($settings->get('cerb5blog.last_action_and_audit_log', 'al_merge_enabled', 0));
     $uf_merge_enabled = intval($settings->get('cerb5blog.last_action_and_audit_log', 'uf_merge_enabled', 0));
     if (!($al_merge_enabled || $uf_merge_enabled)) {
         return;
     }
     $active_worker = CerberusApplication::getActiveWorker();
     $worker_id = $active_worker->id;
     if (class_exists('DAO_TicketAuditLog', true)) {
         if ($al_merge_enabled) {
             foreach ($old_ticket_ids as $old_id) {
                 $old_ticket = DAO_Ticket::get($old_id);
                 $translate_str = $translate->_('cerb5blog.last_action_and_audit_log.post.merge.new_ticket');
                 $translated = sprintf($translate_str, $old_id, $old_ticket->mask);
                 $fields = array(DAO_TicketAuditLog::TICKET_ID => $new_ticket_id, DAO_TicketAuditLog::WORKER_ID => $worker_id, DAO_TicketAuditLog::CHANGE_DATE => time(), DAO_TicketAuditLog::CHANGE_FIELD => "cerb5blog.last_action_and_audit_log.type.merge", DAO_TicketAuditLog::CHANGE_VALUE => substr($translated, 0, 128));
                 $log_id = DAO_TicketAuditLog::create($fields);
             }
             unset($fields);
         }
     }
     if ($uf_merge_enabled) {
         $new_change_fields[DAO_Ticket::UPDATED_DATE] = time();
         DAO_Ticket::update($new_ticket_id, $new_change_fields);
         unset($new_change_fields);
     }
 }