From 979e48840622b856774fb5cfa55376089873b8a7 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Fri, 13 Feb 2015 10:12:42 -0600
Subject: [PATCH] oops: Fix empty export in some cases

If the ticket details form has an extra field of type "Priority Level"
(beyond the one built in), exports of tickets will be empty.

This patch addresses the issue in the exporter which uses an older version
of the custom data materialized view (__cdata table), which created separate
columns for selection and ID values. The current cdata system only creates a
single column and stores the ID value. It also addresses an issue where the
ID column was passed to the PriorityField::to_php() as the first argument.
---
 include/class.export.php | 4 ----
 include/class.forms.php  | 5 ++++-
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/include/class.export.php b/include/class.export.php
index 521eb7cef..1743d3f72 100644
--- a/include/class.export.php
+++ b/include/class.export.php
@@ -53,10 +53,6 @@ class Export {
 
             $name = $f->get('name') ? $f->get('name') : 'field_'.$f->get('id');
             $key = '__field_'.$f->get('id');
-            // Fetch ID values for ID-based data
-            if ($f->hasIdValue()) {
-                $name .= '_id';
-            }
             $cdata[$key] = $f->get('label');
             $fields[$key] = $f;
             $select[] = "cdata.`$name` AS __field_".$f->get('id');
diff --git a/include/class.forms.php b/include/class.forms.php
index e242a44ba..2ed396a1c 100644
--- a/include/class.forms.php
+++ b/include/class.forms.php
@@ -1205,7 +1205,10 @@ class PriorityField extends ChoiceField {
             reset($id);
             $id = key($id);
         }
-        return Priority::lookup($id);
+        elseif ($id === false)
+            $id = $value;
+        if ($id)
+            return Priority::lookup($id);
     }
 
     function to_database($prio) {
-- 
GitLab