summaryrefslogtreecommitdiffstats
path: root/modules-available/locations
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/locations
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/locations')
-rw-r--r--modules-available/locations/baseconfig/getconfig.inc.php2
-rw-r--r--modules-available/locations/inc/autolocation.inc.php2
-rw-r--r--modules-available/locations/inc/location.inc.php4
-rw-r--r--modules-available/locations/inc/locationutil.inc.php2
-rw-r--r--modules-available/locations/pages/details.inc.php4
-rw-r--r--modules-available/locations/pages/locations.inc.php8
-rw-r--r--modules-available/locations/pages/subnets.inc.php2
7 files changed, 12 insertions, 12 deletions
diff --git a/modules-available/locations/baseconfig/getconfig.inc.php b/modules-available/locations/baseconfig/getconfig.inc.php
index 26e43ed8..f2aa2b46 100644
--- a/modules-available/locations/baseconfig/getconfig.inc.php
+++ b/modules-available/locations/baseconfig/getconfig.inc.php
@@ -31,7 +31,7 @@ if (!empty($matchingLocations)) {
FROM setting_location WHERE locationid IN (:list)",
['list' => $matchingLocations]);
$tmp = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$tmp[(int)$row['locationid']][$row['setting']] = $row; // Put whole row so we have value and displayvalue
}
// Callback for pretty printing
diff --git a/modules-available/locations/inc/autolocation.inc.php b/modules-available/locations/inc/autolocation.inc.php
index 82c61251..f77cf714 100644
--- a/modules-available/locations/inc/autolocation.inc.php
+++ b/modules-available/locations/inc/autolocation.inc.php
@@ -22,7 +22,7 @@ class AutoLocation
}
$updates = array();
$nulls = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$loc = Location::mapIpToLocation($row['clientip']);
if ($loc === false) {
$nulls[] = $row['machineuuid'];
diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php
index 700edaf8..e4bce313 100644
--- a/modules-available/locations/inc/location.inc.php
+++ b/modules-available/locations/inc/location.inc.php
@@ -21,7 +21,7 @@ class Location
{
$res = Database::simpleQuery("SELECT locationid, parentlocationid, locationname FROM location");
$rows = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$rows[] = $row;
}
return $rows;
@@ -390,7 +390,7 @@ class Location
{
$res = Database::simpleQuery("SELECT startaddr, endaddr, locationid FROM subnet");
$subnets = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
settype($row['locationid'], 'int');
$subnets[] = $row;
}
diff --git a/modules-available/locations/inc/locationutil.inc.php b/modules-available/locations/inc/locationutil.inc.php
index 708cc8a2..960eefa8 100644
--- a/modules-available/locations/inc/locationutil.inc.php
+++ b/modules-available/locations/inc/locationutil.inc.php
@@ -124,7 +124,7 @@ class LocationUtil
$res = Database::simpleQuery($query, $params);
$return = [];
$locs = false;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (Location::isFixedLocationValid($row['fixedlocationid'], $row['subnetlocationid']))
continue;
$lid = (int)$row['fixedlocationid'];
diff --git a/modules-available/locations/pages/details.inc.php b/modules-available/locations/pages/details.inc.php
index 356620d3..86bfebd6 100644
--- a/modules-available/locations/pages/details.inc.php
+++ b/modules-available/locations/pages/details.inc.php
@@ -322,7 +322,7 @@ class SubPage
$res = Database::simpleQuery("SELECT subnetid, startaddr, endaddr FROM subnet WHERE locationid = :lid",
array('lid' => $locationId));
$rows = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['startaddr'] = long2ip($row['startaddr']);
$row['endaddr'] = long2ip($row['endaddr']);
$rows[] = $row;
@@ -360,7 +360,7 @@ class SubPage
if (Module::get('statistics') !== false) {
$mres = Database::simpleQuery("SELECT state FROM machine"
. " WHERE machine.locationid = :lid", array('lid' => $locationId));
- while ($row = $mres->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($mres as $row) {
$count++;
if ($row['state'] === 'IDLE') {
$online++;
diff --git a/modules-available/locations/pages/locations.inc.php b/modules-available/locations/pages/locations.inc.php
index 8afb454a..ce08e597 100644
--- a/modules-available/locations/pages/locations.inc.php
+++ b/modules-available/locations/pages/locations.inc.php
@@ -121,7 +121,7 @@ class SubPage
$res = Database::simpleQuery("SELECT m.locationid, Count(*) AS cnt,
Sum(If(m.state = 'OCCUPIED', 1, 0)) AS used, Sum(If(m.state = 'IDLE', 1, 0)) AS idle
FROM machine m WHERE (locationid IN (:allowedLocationIds) $extra) GROUP BY locationid", compact('allowedLocationIds'));
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$locId = (int)$row['locationid'];
if (isset($locationList[$locId])) {
$locationList[$locId]['clientCount'] = $row['cnt'];
@@ -135,7 +135,7 @@ class SubPage
}
$res = Database::simpleQuery("SELECT m.locationid, Count(DISTINCT sm.machineuuid) AS cnt FROM setting_machine sm
INNER JOIN machine m USING (machineuuid) GROUP BY m.locationid");
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$locId = (int)$row['locationid'];
if (isset($locationList[$locId])) {
$locationList[$locId]['machineVarsOverrideCount'] = $row['cnt'];
@@ -188,7 +188,7 @@ class SubPage
if (Module::get('baseconfig') !== false) {
$res = Database::simpleQuery("SELECT locationid, Count(*) AS cnt FROM `setting_location`
WHERE locationid IN (:allowedLocationIds) GROUP BY locationid", compact('allowedLocationIds'));
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$lid = (int)$row['locationid'];
if (isset($locationList[$lid])) {
$locationList[$lid]['overriddenVars'] = $row['cnt'];
@@ -202,7 +202,7 @@ class SubPage
$res = Database::simpleQuery("SELECT ml.locationid, m.title, ml.defaultentryid FROM serversetup_menu m
INNER JOIN serversetup_menu_location ml USING (menuid)
WHERE locationid IN (:allowedLocationIds) GROUP BY locationid", compact('allowedLocationIds'));
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$lid = (int)$row['locationid'];
if (isset($locationList[$lid])) {
if ($row['defaultentryid'] !== null) {
diff --git a/modules-available/locations/pages/subnets.inc.php b/modules-available/locations/pages/subnets.inc.php
index fb1e1e80..e568c655 100644
--- a/modules-available/locations/pages/subnets.inc.php
+++ b/modules-available/locations/pages/subnets.inc.php
@@ -67,7 +67,7 @@ class SubPage
FROM subnet
ORDER BY startaddr ASC, endaddr DESC");
$rows = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['startaddr'] = long2ip($row['startaddr']);
$row['endaddr'] = long2ip($row['endaddr']);
$row['locations'] = Location::getLocations($row['locationid']);