From 82219a864bd3427f10211d0b0214b9d24c450068 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Tue, 22 Dec 2015 09:20:27 -0600 Subject: [PATCH] queue: Fix SQL email viewing queue with default columns This fixes a problem where viewing a queue with no defined columns would result in attempting to add columns to the queue, which would result in an incorrect SQL statement and an email sent to the administrator. This was ultimately moot because columns are not added directly to the queue anymore. --- include/class.orm.php | 21 ++++++++++--------- include/class.queue.php | 18 +++------------- include/class.search.php | 19 ++--------------- .../staff/templates/queue-tickets.tmpl.php | 2 +- 4 files changed, 17 insertions(+), 43 deletions(-) diff --git a/include/class.orm.php b/include/class.orm.php index 6b343982c..e22b09e72 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -901,7 +901,7 @@ class SqlExpr extends SqlFunction { $O = array(); foreach ($this->args as $field=>$value) { if ($value instanceof Q) { - $ex = $compiler->compileQ($value, $model); + $ex = $compiler->compileQ($value, $model, false); $O[] = $ex->text; } else { @@ -923,13 +923,11 @@ class SqlExpression extends SqlFunction { function toSql($compiler, $model=false, $alias=false) { $O = array(); foreach ($this->args as $operand) { - if ($operand instanceof SqlFunction) - $O[] = $operand->toSql($compiler, $model); - else - $O[] = $compiler->input($operand); + $O[] = $this->input($operand, $compiler, $model); } - return implode(' '.$this->func.' ', $O) - . ($alias ? ' AS '.$compiler->quote($alias) : ''); + return '('.implode(' '.$this->func.' ', $O) + . ($alias ? ' AS '.$compiler->quote($alias) : '') + . ')'; } static function __callStatic($operator, $operands) { @@ -952,7 +950,7 @@ class SqlExpression extends SqlFunction { function __call($operator, $operands) { array_unshift($operands, $this); - return static::__callStatic($operator, $operands); + return SqlExpression::__callStatic($operator, $operands); } } @@ -979,7 +977,7 @@ class SqlInterval extends SqlFunction { } } -class SqlField extends SqlFunction { +class SqlField extends SqlExpression { var $level; function __construct($field, $level=0) { @@ -2477,7 +2475,10 @@ class SqlCompiler { $constraints = array(); $prev = $parens = false; foreach ($where as $Q) { - $parens = $parens || !($prev && $prev->isCompatibleWith($Q)); + if ($prev && !$prev->isCompatibleWith($Q)) { + $parens = true; + break; + } $prev = $Q; } foreach ($where as $Q) { diff --git a/include/class.queue.php b/include/class.queue.php index 7fc7df986..0acca703c 100644 --- a/include/class.queue.php +++ b/include/class.queue.php @@ -43,12 +43,10 @@ class CustomQueue extends SavedSearch { ) { return $this->parent->getColumns(); } - - if (!count($this->columns)) { - foreach (parent::getColumns() as $c) - $this->addColumn($c); + elseif (count($this->columns)) { + return $this->columns; } - return $this->columns; + return parent::getColumns(); } function addColumn(QueueColumn $col) { @@ -956,16 +954,6 @@ extends VerySimpleModel { return $this->_conditions; } - /** - * Create a CustomQueueColumn from vars (_POST) received from an - * update request. - */ - static function create($vars=array()) { - $inst = parent::create($vars); - // TODO: Convert annotations and conditions - return $inst; - } - static function __create($vars) { $c = static::create($vars); $c->save(); diff --git a/include/class.search.php b/include/class.search.php index 7fd631ffe..59fff7df7 100644 --- a/include/class.search.php +++ b/include/class.search.php @@ -1070,28 +1070,22 @@ class SavedSearch extends VerySimpleModel { return $this->parent->getColumns(); } - if (isset($this->columns)) - return $this->columns; - // Last resort — use standard columns - $this->columns = array( + return array( QueueColumn::create(array( - "id" => 1, "heading" => "Number", "primary" => 'number', - "width" => 100, + "width" => 85, "filter" => "link:ticketP", "annotations" => '[{"c":"TicketSourceDecoration","p":"b"}]', "conditions" => '[{"crit":["isanswered","set",null],"prop":{"font-weight":"bold"}}]', )), QueueColumn::create(array( - "id" => 2, "heading" => "Created", "primary" => 'created', "width" => 100, )), QueueColumn::create(array( - "id" => 3, "heading" => "Subject", "primary" => 'cdata__subject', "width" => 250, @@ -1100,30 +1094,21 @@ class SavedSearch extends VerySimpleModel { "truncate" => 'ellipsis', )), QueueColumn::create(array( - "id" => 4, "heading" => "From", "primary" => 'user__name', "width" => 150, )), QueueColumn::create(array( - "id" => 5, "heading" => "Priority", "primary" => 'cdata__priority', "width" => 120, )), QueueColumn::create(array( - "id" => 6, "heading" => "Assignee", "primary" => 'assignee', - "secondary" => 'team__name', "width" => 100, )), ); - - foreach ($this->columns as $c) - $c->queue = $this; - - return $this->columns; } /** diff --git a/include/staff/templates/queue-tickets.tmpl.php b/include/staff/templates/queue-tickets.tmpl.php index 80e3f51dd..dff0083d7 100644 --- a/include/staff/templates/queue-tickets.tmpl.php +++ b/include/staff/templates/queue-tickets.tmpl.php @@ -160,7 +160,7 @@ foreach ($columns as $C) { $C->getWidth(), $C->id, $heading); // Sort by this column ? - if ($sort['col'] == $C->id) { + if (isset($sort['col']) && $sort['col'] == $C->id) { $col = SavedSearch::getOrmPath($C->primary, $query); if ($sort['dir']) $col = '-' . $col; -- GitLab