From 97a39bdbee014777743af7c2c87e3c3e8537da8e Mon Sep 17 00:00:00 2001
From: JediKev <kevin@enhancesoft.com>
Date: Wed, 24 Oct 2018 10:32:34 -0500
Subject: [PATCH] issue: Export Event State Error

This addresses an issue where export does not work due to a fatal error
"Unknown column 'R0.state' in 'where clause'". This was caused by 4558 due
to the removal of enums and the `state` column. This updates the filter to
match the `event_id` instead of `state`.
---
 include/class.export.php | 2 +-
 include/class.queue.php  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/class.export.php b/include/class.export.php
index 85f021328..b30ceb858 100644
--- a/include/class.export.php
+++ b/include/class.export.php
@@ -76,7 +76,7 @@ class Export {
                     ->aggregate(array('count' => SqlAggregate::COUNT('entries__attachments__id'))),
                 'reopen_count' => TicketThread::objects()
                     ->filter(array('ticket__ticket_id' => new SqlField('ticket_id', 1)))
-                    ->filter(array('events__annulled' => 0, 'events__state' => 'reopened'))
+                    ->filter(array('events__annulled' => 0, 'events__event_id' => Event::getIdByName('reopened')))
                     ->aggregate(array('count' => SqlAggregate::COUNT('events__id'))),
                 'thread_count' => TicketThread::objects()
                     ->filter(array('ticket__ticket_id' => new SqlField('ticket_id', 1)))
diff --git a/include/class.queue.php b/include/class.queue.php
index e3212c502..6397d34d7 100644
--- a/include/class.queue.php
+++ b/include/class.queue.php
@@ -1637,7 +1637,7 @@ extends QueueColumnAnnotation {
         return $query->annotate(array(
             $name => TicketThread::objects()
             ->filter(array('ticket__ticket_id' => new SqlField('ticket_id', 1)))
-            ->filter(array('events__annulled' => 0, 'events__state' => 'reopened'))
+            ->filter(array('events__annulled' => 0, 'events__event_id' => Event::getIdByName('reopened')))
             ->aggregate(array('count' => SqlAggregate::COUNT('events__id')))
         ));
     }
-- 
GitLab