From b499890e86cd24b811307da8062e062eae9d90dd Mon Sep 17 00:00:00 2001 From: Michael J Rubinsky Date: Tue, 26 Nov 2013 13:03:41 -0500 Subject: [PATCH] Simplify getting timer hash values. --- hermes/lib/Ajax/Application/Handler.php | 5 +---- hermes/lib/Hermes.php | 15 +++++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/hermes/lib/Ajax/Application/Handler.php b/hermes/lib/Ajax/Application/Handler.php index 4195adb3017..39a555dd356 100644 --- a/hermes/lib/Ajax/Application/Handler.php +++ b/hermes/lib/Ajax/Application/Handler.php @@ -27,7 +27,6 @@ public function addTimer() { $id = Hermes::newTimer($this->vars->desc, $this->vars); $timer = Hermes::getTimer($id); - $timer['id'] = $id; return $timer; } @@ -439,9 +438,7 @@ public function stopTimer() $timer['time'] = $now; Hermes::updateTimer($this->vars->t, $timer); } - $text = Hermes::getCostObjectByID($timer['deliverable_id']); - $results['_deliverable_text'] = $text['name']; - $results['id'] = $this->vars->t; + return $results; } diff --git a/hermes/lib/Hermes.php b/hermes/lib/Hermes.php index 8c5962ee0b2..5a3b39221dd 100644 --- a/hermes/lib/Hermes.php +++ b/hermes/lib/Hermes.php @@ -393,9 +393,10 @@ public static function listTimers($running_only = false) $elapsed = (!$timer['paused'] ? time() - $timer['time'] : 0 ) + $timer['elapsed']; $timer['elapsed'] = round((float)$elapsed / 3600, 2); $timer['id'] = $id; - unset($timer['elapsed']); - $text = Hermes::getCostObjectByID($timer['deliverable_id']); - $timer['_deliverable_text'] = $text['name']; + try { + $text = Hermes::getCostObjectByID($timer['deliverable_id']); + $timer['deliverable_text'] = $text['name']; + } catch (Horde_Exception_NotFound $e) {} $return[] = $timer; } @@ -450,13 +451,15 @@ public static function getTimer($id) $timers = $GLOBALS['prefs']->getValue('running_timers'); if (!empty($timers)) { $timers = @unserialize($timers); - } else { - $timers = array(); } - if (empty($timers[$id])) { throw new Horde_Exception_NotFound(_("The requested timer was not found.")); } + $timers[$id]['id'] = $id; + + try { + $timers[$id]['deliverable_text'] = Hermes::getCostObjectByID($timers[$id]['deliverable_id']); + } catch (Horde_Exception_NotFound $e) {} return $timers[$id]; }