From 2fadaf0c74710c74d03ae4b6e2ff85620bf52812 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Wed, 13 Apr 2016 22:14:17 -0400
Subject: [PATCH] queue: Fix crash on queue preview (again)

---
 include/ajax.search.php | 2 +-
 include/class.orm.php   | 6 +++---
 include/class.queue.php | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/ajax.search.php b/include/ajax.search.php
index 2fd01bfe9..eb1ef6ed3 100644
--- a/include/ajax.search.php
+++ b/include/ajax.search.php
@@ -277,7 +277,7 @@ class SearchAjaxAPI extends AjaxController {
         // Ensure `name` is preserved
         $field_name = $_GET['field'];
         $id = $_GET['id'];
-        $column = QueueColumn::create(array('id' => $_GET['colid']));
+        $column = new QueueColumn(array('id' => $_GET['colid']));
         $condition = new QueueColumnCondition();
         include STAFFINC_DIR . 'templates/queue-column-condition.tmpl.php';
     }
diff --git a/include/class.orm.php b/include/class.orm.php
index 67b92c7dd..662349227 100644
--- a/include/class.orm.php
+++ b/include/class.orm.php
@@ -1995,7 +1995,7 @@ extends ModelResultSet {
         $this->queryset = $queryset;
     }
 
-    function add($object, $at=false) {
+    function add($object, $save=true, $at=false) {
         // NOTE: Attempting to compare $object to $this->model will likely
         // be problematic, and limits creative applications of the ORM
         if (!$object) {
@@ -2008,7 +2008,7 @@ extends ModelResultSet {
         foreach ($this->key as $field=>$value)
             $object->set($field, $value);
 
-        if (!$object->__new__)
+        if (!$object->__new__ && $save)
             $object->save();
 
         if ($at !== false)
@@ -2111,7 +2111,7 @@ extends ModelResultSet {
         $this->fillTo($a);
         if ($obj = $this->storage[$a])
             $obj->delete();
-        $this->add($b, $a);
+        $this->add($b, true, $a);
     }
 
     // QuerySet overriedes
diff --git a/include/class.queue.php b/include/class.queue.php
index 4f782f097..09ece8de0 100644
--- a/include/class.queue.php
+++ b/include/class.queue.php
@@ -1704,7 +1704,7 @@ extends InstrumentedList {
         $glue = $glue ?: new QueueColumnGlue();
         $glue->column = $column;
         $anno = AnnotatedModel::wrap($column, $glue);
-        parent::add($anno);
+        parent::add($anno, false);
         return $anno;
     }
 }
-- 
GitLab