summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics_reporting
diff options
context:
space:
mode:
authorSimon Rettberg2021-05-06 10:26:09 +0200
committerSimon Rettberg2021-05-11 14:51:13 +0200
commit8dc2b92d667f1401ab9f1315a36add61658f899c (patch)
tree452c5fe040055884cf9d9ee834415db84999a9a1 /modules-available/statistics_reporting
parent[session] Add simple session overview table (diff)
downloadslx-admin-8dc2b92d667f1401ab9f1315a36add61658f899c.tar.gz
slx-admin-8dc2b92d667f1401ab9f1315a36add61658f899c.tar.xz
slx-admin-8dc2b92d667f1401ab9f1315a36add61658f899c.zip
Moderize Database handling
* Auto-convert to utf8mb4_unicode_520_ci * Use foreach instead of while to loop over results * Drop useless statement caching * Keep emulated prepares, as we sometimes loop over nested queries
Diffstat (limited to 'modules-available/statistics_reporting')
-rw-r--r--modules-available/statistics_reporting/inc/getdata.inc.php4
-rw-r--r--modules-available/statistics_reporting/inc/queries.inc.php6
2 files changed, 5 insertions, 5 deletions
diff --git a/modules-available/statistics_reporting/inc/getdata.inc.php b/modules-available/statistics_reporting/inc/getdata.inc.php
index 13d39502..90af0c58 100644
--- a/modules-available/statistics_reporting/inc/getdata.inc.php
+++ b/modules-available/statistics_reporting/inc/getdata.inc.php
@@ -105,7 +105,7 @@ class GetData
$anonymize = 0 !== ($flags & GETDATA_ANONYMOUS);
$res = Queries::getUserStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound);
$data = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($anonymize && $row['name'] !== 'anonymous') {
$row['name'] = md5($row['name'] . self::$salt);
}
@@ -120,7 +120,7 @@ class GetData
$anonymize = 0 !== ($flags & GETDATA_ANONYMOUS);
$res = Queries::getVMStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound);
$data = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
self::nullToZero($row);
if ($anonymize) {
$row['name'] = md5($row['name'] . self::$salt);
diff --git a/modules-available/statistics_reporting/inc/queries.inc.php b/modules-available/statistics_reporting/inc/queries.inc.php
index 128d8e7d..8c6ff9a8 100644
--- a/modules-available/statistics_reporting/inc/queries.inc.php
+++ b/modules-available/statistics_reporting/inc/queries.inc.php
@@ -106,7 +106,7 @@ class Queries
$bounds = [$lowerTimeBound, $upperTimeBound];
}
$machines = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['firstseen'] = max($row['firstseen'], $from);
$row += array(
'totalTime' => self::timeDiff($row['firstseen'], $to, $bounds),
@@ -132,7 +132,7 @@ class Queries
ORDER BY dateline ASC LIMIT 1000", compact('last', 'to'));
$last = false;
$count = 0;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$count += 1; // Update count first, as we use it as a condition in outer loop. No continue before this
settype($row['logid'], 'int');
// Update for next query
@@ -375,7 +375,7 @@ class Queries
LEFT JOIN exams_x_location exl USING (examid)
WHERE starttime < $to AND endtime > $from
GROUP BY examid");
- while ($row = $eres->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($eres as $row) {
// Get all boot events
$data = ['from' => $row['starttime'], 'to' => $row['endtime']];
if (empty($row['locs'])) {