diff options
author | Simon Rettberg | 2021-05-06 10:26:09 +0200 |
---|---|---|
committer | Simon Rettberg | 2021-05-11 14:51:13 +0200 |
commit | 8dc2b92d667f1401ab9f1315a36add61658f899c (patch) | |
tree | 452c5fe040055884cf9d9ee834415db84999a9a1 /modules-available/dnbd3 | |
parent | [session] Add simple session overview table (diff) | |
download | slx-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/dnbd3')
-rw-r--r-- | modules-available/dnbd3/baseconfig/getconfig.inc.php | 2 | ||||
-rw-r--r-- | modules-available/dnbd3/hooks/main-warning.inc.php | 2 | ||||
-rw-r--r-- | modules-available/dnbd3/inc/dnbd3util.inc.php | 8 | ||||
-rw-r--r-- | modules-available/dnbd3/page.inc.php | 4 |
4 files changed, 8 insertions, 8 deletions
diff --git a/modules-available/dnbd3/baseconfig/getconfig.inc.php b/modules-available/dnbd3/baseconfig/getconfig.inc.php index e4f84d81..6a3aec25 100644 --- a/modules-available/dnbd3/baseconfig/getconfig.inc.php +++ b/modules-available/dnbd3/baseconfig/getconfig.inc.php @@ -29,7 +29,7 @@ $res = Database::simpleQuery('SELECT s.fixedip, m.clientip, sxl.locationid FROM $locationsAssoc = array_flip($locationIds); $servers = array(); $fallback = array(); -while ($row = $res->fetch(PDO::FETCH_ASSOC)) { +foreach ($res as $row) { if ($row['fixedip'] === '<self>') { $row['fixedip'] = Property::getServerIp(); $defPrio = 2000; diff --git a/modules-available/dnbd3/hooks/main-warning.inc.php b/modules-available/dnbd3/hooks/main-warning.inc.php index 5f8a844f..bee0a258 100644 --- a/modules-available/dnbd3/hooks/main-warning.inc.php +++ b/modules-available/dnbd3/hooks/main-warning.inc.php @@ -6,7 +6,7 @@ if (Dnbd3::isEnabled() && User::hasPermission('.dnbd3.access-page')) { LEFT JOIN machine m USING (machineuuid) WHERE errormsg IS NOT NULL'); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $error = $row['errormsg'] ? $row['errormsg'] : '<unknown error>'; $lastSeen = Util::prettyTime($row['dnbd3lastseen']); if ($row['fixedip'] === '<self>') { diff --git a/modules-available/dnbd3/inc/dnbd3util.inc.php b/modules-available/dnbd3/inc/dnbd3util.inc.php index 8e355370..d9bfaeee 100644 --- a/modules-available/dnbd3/inc/dnbd3util.inc.php +++ b/modules-available/dnbd3/inc/dnbd3util.inc.php @@ -12,7 +12,7 @@ class Dnbd3Util { $res = Database::simpleQuery('SELECT s.serverid, s.machineuuid, s.fixedip, s.lastup, s.lastdown, m.clientip FROM dnbd3_server s LEFT JOIN machine m USING (machineuuid)'); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { if (!empty($row['machineuuid'])) { $allUuids[$row['machineuuid']] = true; } @@ -121,7 +121,7 @@ class Dnbd3Util { WHERE machineuuid = :uuid', array('uuid' => $machineUuid)); $assignedLocs = array(); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $assignedLocs[] = $row['locationid']; } $modeData = (array)json_decode($modeData, true) + self::defaultRunmodeConfig(); @@ -142,7 +142,7 @@ class Dnbd3Util { $floatIp = (float)sprintf('%u', $floatIp); // Float for 32bit php :/ } $ranges = [['startaddr' => $floatIp, 'endaddr' => $floatIp]]; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { settype($row['startaddr'], PHP_INT_SIZE === 4 ? 'float' : 'int'); settype($row['endaddr'], PHP_INT_SIZE === 4 ? 'float' : 'int'); self::mergeRanges($ranges, $row); @@ -164,7 +164,7 @@ class Dnbd3Util { $public = array(); $private = array(); $public[$self] = $self; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $ip = $row['fixedip'] ? $row['fixedip'] : $row['clientip']; if ($ip === '<self>') { continue; diff --git a/modules-available/dnbd3/page.inc.php b/modules-available/dnbd3/page.inc.php index d0842c23..a58f6fcc 100644 --- a/modules-available/dnbd3/page.inc.php +++ b/modules-available/dnbd3/page.inc.php @@ -174,7 +174,7 @@ class Page_Dnbd3 extends Page $NOW = time(); $externalAllowed = User::hasPermission('configure.external'); $locsRunmode = User::getAllowedLocations('configure.proxy'); - while ($server = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $server) { if (!is_null($server['machineuuid'])) { // Auto proxy if (!isset($dynClients[$server['machineuuid']])) { @@ -355,7 +355,7 @@ class Page_Dnbd3 extends Page $loc['recCount'] = 0; } $showLocs = false; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { settype($row['locationid'], 'int'); $loc =& $locCount[$row['locationid']]; $loc['clientCount'] = $row['cnt']; |