From 74bdc0237fcf0369e52b11ecb95ae391c9fade46 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Fri, 17 Jun 2016 14:16:42 +0000 Subject: [PATCH] Forced SetValue When issue summary is disabled for a specific help topic, the system uses help topic name as the subject line. Due to validation error on disabled subject field the setValue fails to take in the help topic. The change here allows for forced value set. --- include/class.dynamic_forms.php | 20 ++++++++++++-------- include/class.orm.php | 12 +++++++----- include/class.ticket.php | 8 +++----- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 7bb040814..074549584 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -951,15 +951,11 @@ class DynamicFormEntry extends VerySimpleModel { } function setAnswer($name, $value, $id=false) { - foreach ($this->getAnswers() as $ans) { + + if ($ans=$this->getAnswer($name)) { $f = $ans->getField(); - if ($f->isStorable() && $f->get('name') == $name) { - $f->reset(); - $ans->set('value', $value); - if ($id !== false) - $ans->set('value_id', $id); - break; - } + if ($f->isStorable()) + $ans->setValue($value, $id); } } @@ -1359,6 +1355,14 @@ class DynamicFormEntryAnswer extends VerySimpleModel { return $this->_value; } + function setValue($value, $id=false) { + $this->getField()->reset(); + $this->_value = null; + $this->set('value', $value); + if ($id !== false) + $this->set('value_id', $id); + } + function getLocal($tag) { return $this->field->getLocal($tag); } diff --git a/include/class.orm.php b/include/class.orm.php index 3e7dc64df..a928f222c 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -1468,6 +1468,13 @@ implements IteratorAggregate, Countable, ArrayAccess { } } + function reset() { + $this->eoi = false; + $this->cache = array(); + // XXX: Should the inner be recreated to refetch? + $this->inner->rewind(); + } + function asArray() { $this->fillTo(PHP_INT_MAX); return $this->getCache(); @@ -1908,11 +1915,6 @@ extends ModelResultSet { $object->set($field, null); } - function reset() { - $this->cache = array(); - unset($this->resource); - } - /** * Slight edit to the standard iteration method which will skip deleted * items. diff --git a/include/class.ticket.php b/include/class.ticket.php index d126259da..2afbe818f 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -3373,11 +3373,9 @@ implements RestrictedAccess, Threadable { // Save the (common) dynamic form // Ensure we have a subject $subject = $form->getAnswer('subject'); - if ($subject && !$subject->getValue()) { - if ($topic) { - $form->setAnswer('subject', $topic->getFullName()); - } - } + if ($subject && !$subject->getValue() && $topic) + $subject->setValue($topic->getFullName()); + $form->setTicketId($ticket->getId()); $form->save(); -- GitLab