From a7f123c17dbc69dd20d06f1620d325ef9df729e1 Mon Sep 17 00:00:00 2001
From: aydreeihn <adriane@enhancesoft.com>
Date: Mon, 12 Mar 2018 16:45:00 -0500
Subject: [PATCH] fix minor dashboard statistics errors caused by new features
 + sql cleanup file

---
 include/class.orm.php                                      | 6 ++++--
 include/class.report.php                                   | 2 +-
 include/staff/dashboard.inc.php                            | 3 ++-
 .../upgrader/streams/core/86707325-526c601b.cleanup.sql    | 7 +++++++
 4 files changed, 14 insertions(+), 4 deletions(-)
 create mode 100644 include/upgrader/streams/core/86707325-526c601b.cleanup.sql

diff --git a/include/class.orm.php b/include/class.orm.php
index 3e8f9830c..08c2f209c 100644
--- a/include/class.orm.php
+++ b/include/class.orm.php
@@ -2753,8 +2753,10 @@ class MySqlCompiler extends SqlCompiler {
     }
 
     function __range($a, $b) {
-        // XXX: Crash if $b is not array of two items
-        return sprintf('%s BETWEEN %s AND %s', $a, $this->input($b[0]), $this->input($b[1]));
+      return sprintf('%s BETWEEN %s AND %s',
+        $a,
+        $b[2] ? $b[0] : $this->input($b[0]),
+        $b[2] ? $b[1] : $this->input($b[1]));
     }
 
     function compileJoin($tip, $model, $alias, $info, $extra=false) {
diff --git a/include/class.report.php b/include/class.report.php
index fb284fc62..179dd8e13 100644
--- a/include/class.report.php
+++ b/include/class.report.php
@@ -165,7 +165,7 @@ class OverviewReport {
             $stats = ThreadEvent::objects()
                 ->filter(array(
                         'annulled' => 0,
-                        'timestamp__range' => array($start, $stop),
+                        'timestamp__range' => array($start, $stop, true),
                         'thread__object_type' => 'T',
                    ))
                 ->aggregate(array(
diff --git a/include/staff/dashboard.inc.php b/include/staff/dashboard.inc.php
index 3409726e5..8bf119595 100644
--- a/include/staff/dashboard.inc.php
+++ b/include/staff/dashboard.inc.php
@@ -75,7 +75,8 @@ $plots = $report->getPlotData();
     $date = str_ireplace('FROM_UNIXTIME(', '',$date);
     $date = str_ireplace(')', '',$date);
     $date = new DateTime('@'.$date);
-    $date->setTimeZone(new DateTimeZone($thisstaff->getTimezone()));
+    if ($thisstaff->getTimezone())
+      $date->setTimeZone(new DateTimeZone($thisstaff->getTimezone()));
     $range[] = $date->format('F j, Y');
   }
   echo __($range[0] . ' - ' . $range[1]);
diff --git a/include/upgrader/streams/core/86707325-526c601b.cleanup.sql b/include/upgrader/streams/core/86707325-526c601b.cleanup.sql
new file mode 100644
index 000000000..caa1687c5
--- /dev/null
+++ b/include/upgrader/streams/core/86707325-526c601b.cleanup.sql
@@ -0,0 +1,7 @@
+-- set thread entry pid's to show Service/Response time in Dashboard
+UPDATE `%TABLE_PREFIX%thread_entry` AS this
+INNER JOIN (
+	SELECT `%TABLE_PREFIX%thread_entry`.`id`,`%TABLE_PREFIX%thread_entry`.`thread_id`,`%TABLE_PREFIX%thread_entry`.`type`
+	FROM `%TABLE_PREFIX%thread_entry` WHERE `%TABLE_PREFIX%thread_entry`.`type` = 'M') AS that
+SET this.`pid` = that.`id`
+WHERE this.`thread_id` = that.`thread_id` AND that.`type` = 'M' AND this.type = 'R' AND this.`id` > that.`id` AND this.`pid` = 0
-- 
GitLab